mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-16 18:12:07 +00:00
implement IClientBase interface
This commit is contained in:
parent
e802126960
commit
04848439b9
@ -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.
|
||||
|
39
src/mesh/sharedMem/MeshPacketClient.cpp
Normal file
39
src/mesh/sharedMem/MeshPacketClient.cpp
Normal file
@ -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
src/mesh/sharedMem/MeshPacketClient.h
Normal file
22
src/mesh/sharedMem/MeshPacketClient.h
Normal file
@ -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);
|
||||
};
|
@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "mesh-pb-constants.h"
|
||||
#include "sharedMem/PacketServer.h"
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user