diff --git a/src/main.cpp b/src/main.cpp index 1291a73c65..aa174ae052 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -91,8 +91,8 @@ AudioThread *audioThread; #ifdef HAS_TFT #include "DeviceScreen.h" +#include "sharedMem/MeshPacketClient.h" #include "sharedMem/MeshPacketServer.h" -#include "sharedMem/PacketClient.h" DeviceScreen *deviceScreen = nullptr; #endif @@ -365,7 +365,7 @@ void setup() #endif #ifdef HAS_TFT deviceScreen = &DeviceScreen::create(); - deviceScreen->init(); + deviceScreen->init(new MeshPacketClient); #endif // Currently only the tbeam has a PMU @@ -874,7 +874,6 @@ void setup() #ifdef HAS_TFT MeshPacketServer::init(); - PacketClient::init(); #endif // Start airtime logger thread. diff --git a/src/mesh/sharedMem/MeshPacketClient.cpp b/src/mesh/sharedMem/MeshPacketClient.cpp new file mode 100644 index 0000000000..7560a16041 --- /dev/null +++ b/src/mesh/sharedMem/MeshPacketClient.cpp @@ -0,0 +1,39 @@ +#include "MeshPacketClient.h" + +void MeshPacketClient::init(void) +{ + PacketClient::init(); +} + +MeshPacketClient::MeshPacketClient() {} + +bool MeshPacketClient::connect(void) +{ + PacketClient::connect(); +} + +bool MeshPacketClient::disconnect(void) +{ + PacketClient::disconnect(); +} + +bool MeshPacketClient::isConnected(void) +{ + return PacketClient::isConnected(); +} + +bool MeshPacketClient::send(meshtastic_ToRadio &&to) +{ + static uint32_t id = 0; + PacketClient::sendPacket(DataPacket(++id, to)); +} + +meshtastic_FromRadio MeshPacketClient::receive(void) +{ + auto p = receivePacket()->move(); + if (p) { + return static_cast *>(p.get())->getData(); + } else { + return meshtastic_FromRadio(); + } +} diff --git a/src/mesh/sharedMem/MeshPacketClient.h b/src/mesh/sharedMem/MeshPacketClient.h new file mode 100644 index 0000000000..48ef8cb1ee --- /dev/null +++ b/src/mesh/sharedMem/MeshPacketClient.h @@ -0,0 +1,22 @@ +#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); +}; diff --git a/src/mesh/sharedMem/MeshPacketServer.h b/src/mesh/sharedMem/MeshPacketServer.h index 858f968df9..2d29db503d 100644 --- a/src/mesh/sharedMem/MeshPacketServer.h +++ b/src/mesh/sharedMem/MeshPacketServer.h @@ -1,3 +1,5 @@ +#pragma once + #include "mesh-pb-constants.h" #include "sharedMem/PacketServer.h" diff --git a/src/mesh/sharedMem/PacketClient.cpp b/src/mesh/sharedMem/PacketClient.cpp index 4ef7b0c9dc..2a819d1554 100644 --- a/src/mesh/sharedMem/PacketClient.cpp +++ b/src/mesh/sharedMem/PacketClient.cpp @@ -5,18 +5,29 @@ const uint32_t max_packet_queue_size = 10; -PacketClient *packetClient = nullptr; - void PacketClient::init(void) { - // for now we hard-code (only) one client task, but in principle one could - // create as many PacketServer/PacketClient pairs as desired. - packetClient = new PacketClient(); - packetClient->connect(sharedQueue); + // sharedQueue is currently defined external, it is not shared between processes + connect(sharedQueue); } PacketClient::PacketClient() : queue(nullptr) {} +bool PacketClient::connect(void) +{ + is_connected = true; +} + +bool PacketClient::disconnect(void) +{ + is_connected = false; +} + +bool PacketClient::isConnected(void) +{ + return is_connected; +} + int PacketClient::connect(SharedQueue *_queue) { if (!queue) { diff --git a/src/mesh/sharedMem/PacketClient.h b/src/mesh/sharedMem/PacketClient.h index 4da3c34ec0..3a8654d03f 100644 --- a/src/mesh/sharedMem/PacketClient.h +++ b/src/mesh/sharedMem/PacketClient.h @@ -1,5 +1,6 @@ #pragma once +#include "IClientBase.h" #include "Packet.h" class SharedQueue; @@ -9,19 +10,27 @@ class SharedQueue; * send packets to the shared queue * */ -class PacketClient +class PacketClient : public IClientBase { public: PacketClient(); - static void init(void); - virtual int connect(SharedQueue *_queue); + virtual void init(void); + virtual bool connect(void); + virtual bool disconnect(void); + virtual bool isConnected(void); + virtual bool sendPacket(Packet &&p); virtual Packet::PacketPtr receivePacket(); + virtual bool hasData() const; virtual bool available() const; + virtual ~PacketClient() = default; + + protected: + virtual int connect(SharedQueue *_queue); + private: + bool is_connected = false; SharedQueue *queue; }; - -extern PacketClient *packetClient; diff --git a/variants/t-deck/platformio.ini b/variants/t-deck/platformio.ini index b727b29d49..21acca9f25 100644 --- a/variants/t-deck/platformio.ini +++ b/variants/t-deck/platformio.ini @@ -2,6 +2,7 @@ [env:t-deck] extends = esp32s3_base board = t-deck +board_build.partitions = default_16MB.csv ; just for test upload_protocol = esp-builtin build_flags = ${esp32_base.build_flags} -D T_DECK