mirror of
https://github.com/meshtastic/firmware.git
synced 2025-10-10 16:11:05 +00:00
refactoring part 1: remove MeshPacketClient/Server layer
This commit is contained in:
parent
dd638499b6
commit
25d8be327d
@ -106,8 +106,8 @@ AudioThread *audioThread;
|
|||||||
|
|
||||||
#if HAS_TFT
|
#if HAS_TFT
|
||||||
#include "DeviceScreen.h"
|
#include "DeviceScreen.h"
|
||||||
#include "sharedMem/MeshPacketClient.h"
|
#include "sharedMem/PacketClient.h"
|
||||||
#include "sharedMem/MeshPacketServer.h"
|
#include "sharedMem/PacketServer.h"
|
||||||
|
|
||||||
void tft_task_handler(void *);
|
void tft_task_handler(void *);
|
||||||
|
|
||||||
@ -674,9 +674,9 @@ void setup()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAS_TFT
|
#if HAS_TFT
|
||||||
MeshPacketServer::init();
|
PacketServer::init();
|
||||||
deviceScreen = &DeviceScreen::create();
|
deviceScreen = &DeviceScreen::create();
|
||||||
deviceScreen->init(new MeshPacketClient);
|
deviceScreen->init(new PacketClient);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Initialize the screen first so we can show the logo while we start up everything else.
|
// Initialize the screen first so we can show the logo while we start up everything else.
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#include "api/PacketAPI.h"
|
#include "api/PacketAPI.h"
|
||||||
#include "MeshService.h"
|
#include "MeshService.h"
|
||||||
#include "RadioInterface.h"
|
#include "RadioInterface.h"
|
||||||
#include "sharedMem/MeshPacketServer.h"
|
|
||||||
|
|
||||||
PacketAPI *packetAPI = nullptr;
|
PacketAPI *packetAPI = nullptr;
|
||||||
|
|
||||||
@ -23,18 +22,11 @@ bool PacketAPI::receivePacket(void)
|
|||||||
isConnected = true;
|
isConnected = true;
|
||||||
data_received = true;
|
data_received = true;
|
||||||
|
|
||||||
// TODO: think about redesign or drop class MeshPacketServer
|
|
||||||
meshtastic_ToRadio *mr;
|
meshtastic_ToRadio *mr;
|
||||||
// if (typeid(*server) == typeid(MeshPacketServer)) {
|
|
||||||
// dynamic_cast<MeshPacketServer*>(server)->receivePacket(*mr);
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
auto p = server->receivePacket()->move();
|
auto p = server->receivePacket()->move();
|
||||||
int id = p->getPacketId();
|
int id = p->getPacketId();
|
||||||
LOG_DEBUG("Received packet id=%u\n", id);
|
LOG_DEBUG("Received packet id=%u\n", id);
|
||||||
// mr = (meshtastic_ToRadio*)&dynamic_cast<DataPacket<meshtastic_ToRadio>*>(p.get())->getData();
|
|
||||||
mr = (meshtastic_ToRadio *)&static_cast<DataPacket<meshtastic_ToRadio> *>(p.get())->getData();
|
mr = (meshtastic_ToRadio *)&static_cast<DataPacket<meshtastic_ToRadio> *>(p.get())->getData();
|
||||||
//}
|
|
||||||
|
|
||||||
switch (mr->which_payload_variant) {
|
switch (mr->which_payload_variant) {
|
||||||
case meshtastic_ToRadio_packet_tag: {
|
case meshtastic_ToRadio_packet_tag: {
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
#include "MeshPacketClient.h"
|
|
||||||
|
|
||||||
void MeshPacketClient::init(void)
|
|
||||||
{
|
|
||||||
PacketClient::init();
|
|
||||||
}
|
|
||||||
|
|
||||||
MeshPacketClient::MeshPacketClient() {}
|
|
||||||
|
|
||||||
bool MeshPacketClient::connect(void)
|
|
||||||
{
|
|
||||||
return PacketClient::connect();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MeshPacketClient::disconnect(void)
|
|
||||||
{
|
|
||||||
return PacketClient::disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MeshPacketClient::isConnected(void)
|
|
||||||
{
|
|
||||||
return PacketClient::isConnected();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MeshPacketClient::send(meshtastic_ToRadio &&to)
|
|
||||||
{
|
|
||||||
static uint32_t id = 0;
|
|
||||||
return PacketClient::sendPacket(DataPacket<meshtastic_ToRadio>(++id, to));
|
|
||||||
}
|
|
||||||
|
|
||||||
meshtastic_FromRadio MeshPacketClient::receive(void)
|
|
||||||
{
|
|
||||||
if (hasData()) {
|
|
||||||
auto p = receivePacket();
|
|
||||||
if (p) {
|
|
||||||
return static_cast<DataPacket<meshtastic_FromRadio> *>(p->move().get())->getData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return meshtastic_FromRadio();
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "mesh-pb-constants.h"
|
|
||||||
#include "sharedMem/PacketClient.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This is a wrapper class for the PaketClient to avoid dealing with DataPackets
|
|
||||||
* in the application code.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class MeshPacketClient : public PacketClient
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
MeshPacketClient();
|
|
||||||
virtual void init(void);
|
|
||||||
virtual bool connect(void);
|
|
||||||
virtual bool disconnect(void);
|
|
||||||
virtual bool isConnected(void);
|
|
||||||
|
|
||||||
virtual bool send(meshtastic_ToRadio &&to);
|
|
||||||
virtual meshtastic_FromRadio receive(void);
|
|
||||||
};
|
|
@ -1,44 +0,0 @@
|
|||||||
#include "sharedMem/MeshPacketServer.h"
|
|
||||||
#include "api/PacketAPI.h"
|
|
||||||
#include "sharedMem/SharedQueue.h"
|
|
||||||
|
|
||||||
SharedQueue *sharedQueue = nullptr;
|
|
||||||
|
|
||||||
MeshPacketServer *meshPacketServer = nullptr;
|
|
||||||
|
|
||||||
void MeshPacketServer::init(void)
|
|
||||||
{
|
|
||||||
meshPacketServer = new MeshPacketServer;
|
|
||||||
packetAPI = new PacketAPI(meshPacketServer);
|
|
||||||
meshPacketServer->begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
MeshPacketServer::MeshPacketServer() {}
|
|
||||||
|
|
||||||
void MeshPacketServer::begin(void)
|
|
||||||
{
|
|
||||||
sharedQueue = new SharedQueue;
|
|
||||||
PacketServer::begin(sharedQueue);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MeshPacketServer::receivePacket(meshtastic_ToRadio &to)
|
|
||||||
{
|
|
||||||
// auto p = PacketServer::receivePacket<Packet::PacketPtr>()->move();
|
|
||||||
auto p = PacketServer::receivePacket()->move();
|
|
||||||
if (p) {
|
|
||||||
// TODO: avoid data copy :(
|
|
||||||
// to = dynamic_cast<DataPacket<meshtastic_ToRadio>*>(p.get())->getData();
|
|
||||||
to = static_cast<DataPacket<meshtastic_ToRadio> *>(p.get())->getData();
|
|
||||||
}
|
|
||||||
return p != nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MeshPacketServer::sendPacket(meshtastic_FromRadio &from)
|
|
||||||
{
|
|
||||||
return PacketServer::sendPacket(DataPacket<meshtastic_FromRadio>(from.id, from));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MeshPacketServer::sendPacket(meshtastic_FromRadio &&from)
|
|
||||||
{
|
|
||||||
return PacketServer::sendPacket(DataPacket<meshtastic_FromRadio>(from.id, from));
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "mesh-pb-constants.h"
|
|
||||||
#include "sharedMem/PacketServer.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This is a wrapper class for the PaketServer to avoid dealing with DataPackets
|
|
||||||
* in the application code.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class MeshPacketServer : public PacketServer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
MeshPacketServer();
|
|
||||||
static void init(void);
|
|
||||||
virtual void begin(void);
|
|
||||||
virtual bool receivePacket(meshtastic_ToRadio &to);
|
|
||||||
virtual bool sendPacket(meshtastic_FromRadio &from);
|
|
||||||
virtual bool sendPacket(meshtastic_FromRadio &&from);
|
|
||||||
};
|
|
||||||
|
|
||||||
extern MeshPacketServer *meshPacketServer;
|
|
@ -41,21 +41,25 @@ int PacketClient::connect(SharedQueue *_queue)
|
|||||||
return queue->serverQueueSize();
|
return queue->serverQueueSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
Packet::PacketPtr PacketClient::receivePacket()
|
bool PacketClient::send(meshtastic_ToRadio &&to)
|
||||||
{
|
{
|
||||||
assert(queue);
|
if (available()) {
|
||||||
if (queue->serverQueueSize() == 0)
|
static uint32_t id = 0;
|
||||||
return {nullptr};
|
return queue->clientSend(DataPacket<meshtastic_ToRadio>(++id, to));
|
||||||
return queue->clientReceive();
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PacketClient::sendPacket(Packet &&p)
|
meshtastic_FromRadio PacketClient::receive(void)
|
||||||
{
|
{
|
||||||
assert(queue);
|
if (hasData()) {
|
||||||
if (queue->clientQueueSize() >= max_packet_queue_size)
|
auto p = queue->clientReceive();
|
||||||
return false;
|
if (p) {
|
||||||
queue->clientSend(std::move(p));
|
return static_cast<DataPacket<meshtastic_FromRadio> *>(p->move().get())->getData();
|
||||||
return true;
|
}
|
||||||
|
}
|
||||||
|
return meshtastic_FromRadio();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PacketClient::hasData() const
|
bool PacketClient::hasData() const
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
class SharedQueue;
|
class SharedQueue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Generic client implementation to receive from and
|
* @brief Client implementation to receive packets from and
|
||||||
* send packets to the shared queue
|
* send packets to the shared queue
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -14,13 +14,12 @@ class PacketClient : public IClientBase
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PacketClient();
|
PacketClient();
|
||||||
virtual void init(void);
|
void init(void) override;
|
||||||
virtual bool connect(void);
|
bool connect(void) override;
|
||||||
virtual bool disconnect(void);
|
bool disconnect(void) override;
|
||||||
virtual bool isConnected(void);
|
bool isConnected(void) override;
|
||||||
|
bool send(meshtastic_ToRadio &&to) override;
|
||||||
virtual bool sendPacket(Packet &&p);
|
meshtastic_FromRadio receive(void) override;
|
||||||
virtual Packet::PacketPtr receivePacket();
|
|
||||||
|
|
||||||
virtual bool hasData() const;
|
virtual bool hasData() const;
|
||||||
virtual bool available() const;
|
virtual bool available() const;
|
||||||
|
@ -1,11 +1,24 @@
|
|||||||
#include "sharedMem/PacketServer.h"
|
#include "sharedMem/PacketServer.h"
|
||||||
|
#include "api/PacketAPI.h"
|
||||||
#include "sharedMem/SharedQueue.h"
|
#include "sharedMem/SharedQueue.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
const uint32_t max_packet_queue_size = 50;
|
const uint32_t max_packet_queue_size = 50;
|
||||||
|
|
||||||
|
SharedQueue *sharedQueue = nullptr;
|
||||||
|
|
||||||
|
PacketServer *packetServer = nullptr;
|
||||||
|
|
||||||
PacketServer::PacketServer() : queue(nullptr) {}
|
PacketServer::PacketServer() : queue(nullptr) {}
|
||||||
|
|
||||||
|
void PacketServer::init(void)
|
||||||
|
{
|
||||||
|
packetServer = new PacketServer;
|
||||||
|
packetAPI = new PacketAPI(packetServer);
|
||||||
|
sharedQueue = new SharedQueue;
|
||||||
|
packetServer->begin(sharedQueue);
|
||||||
|
}
|
||||||
|
|
||||||
void PacketServer::begin(SharedQueue *_queue)
|
void PacketServer::begin(SharedQueue *_queue)
|
||||||
{
|
{
|
||||||
queue = _queue;
|
queue = _queue;
|
||||||
|
@ -7,12 +7,13 @@ class SharedQueue;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Generic server implementation (base class) for bidirectional task communication
|
* Generic server implementation (base class) for bidirectional task communication
|
||||||
* Uses a queue that is shared with the
|
* Uses a queue that is shared with the client
|
||||||
*/
|
*/
|
||||||
class PacketServer
|
class PacketServer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PacketServer();
|
PacketServer();
|
||||||
|
static void init(void);
|
||||||
virtual void begin(SharedQueue *_queue);
|
virtual void begin(SharedQueue *_queue);
|
||||||
virtual bool sendPacket(Packet &&p);
|
virtual bool sendPacket(Packet &&p);
|
||||||
virtual Packet::PacketPtr receivePacket(void);
|
virtual Packet::PacketPtr receivePacket(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user