Skip to content

Commit

Permalink
implement IClientBase interface
Browse files Browse the repository at this point in the history
  • Loading branch information
mverch67 committed Mar 4, 2024
1 parent e802126 commit 0484843
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 14 deletions.
5 changes: 2 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -874,7 +874,6 @@ void setup()

#ifdef HAS_TFT
MeshPacketServer::init();
PacketClient::init();
#endif

// Start airtime logger thread.
Expand Down
39 changes: 39 additions & 0 deletions src/mesh/sharedMem/MeshPacketClient.cpp
Original file line number Diff line number Diff line change
@@ -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<meshtastic_ToRadio>(++id, to));
}

meshtastic_FromRadio MeshPacketClient::receive(void)
{
auto p = receivePacket()->move();
if (p) {
return static_cast<DataPacket<meshtastic_FromRadio> *>(p.get())->getData();
} else {
return meshtastic_FromRadio();
}
}
22 changes: 22 additions & 0 deletions src/mesh/sharedMem/MeshPacketClient.h
Original file line number Diff line number Diff line change
@@ -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);
};
2 changes: 2 additions & 0 deletions src/mesh/sharedMem/MeshPacketServer.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

#include "mesh-pb-constants.h"
#include "sharedMem/PacketServer.h"

Expand Down
23 changes: 17 additions & 6 deletions src/mesh/sharedMem/PacketClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 14 additions & 5 deletions src/mesh/sharedMem/PacketClient.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "IClientBase.h"
#include "Packet.h"

class SharedQueue;
Expand All @@ -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;
1 change: 1 addition & 0 deletions variants/t-deck/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0484843

Please sign in to comment.