mirror of
https://github.com/meshtastic/firmware.git
synced 2025-09-22 01:24:05 +00:00
refactoring part 1: remove MeshPacketClient/Server layer
This commit is contained in:
parent
e045e862e8
commit
cedb0067b2
@ -116,11 +116,6 @@ AudioThread *audioThread = nullptr;
|
|||||||
float tcxoVoltage = SX126X_DIO3_TCXO_VOLTAGE; // if TCXO is optional, put this here so it can be changed further down.
|
float tcxoVoltage = SX126X_DIO3_TCXO_VOLTAGE; // if TCXO is optional, put this here so it can be changed further down.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_PACKET_API
|
|
||||||
#include "sharedMem/MeshPacketServer.h"
|
|
||||||
#include "sharedMem/PacketClient.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using namespace concurrency;
|
using namespace concurrency;
|
||||||
|
|
||||||
volatile static const char slipstreamTZString[] = USERPREFS_TZ_STRING;
|
volatile static const char slipstreamTZString[] = USERPREFS_TZ_STRING;
|
||||||
|
@ -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,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,20 +0,0 @@
|
|||||||
#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;
|
|
@ -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