Files
Manuel 405ca49532 feat: ethernet client support for MUI (#129)
* preliminary impl

* update initialization

* adapt to limited Portduino Ethernet(WiFi)Client

* fixed space left calculation

* inherit from SerialClient

* updates Eth/SerialClient

* update cmake files

* protected declaration (for unit tests)

* fix warning

* tryfix: call lv_tick_inc() directly instead of lv_tick_set_cb()

* added isStandalone() to determine use case

* add reboot/shutdown for standalone; suppress animations during startup

* add debug log

* add error log

* revert lv_tick_inc / lv_tick_set_cb

* fix debug log

* workaround sporadic map error

* connection status handling

* define pure virtual functions

* adapt dimensions to allow map resize

* replace [] by .at() when erasing

* fix all communication issues; add thread names for logging

* fix warnings

* trunk fmt

* cleanup

* fix lv_tick interface for esp32 (revert to previous one as Indicator is frozen)

* added client connection states to boot screen

* fix reboot for standalone case

* fix warning

* fix UART connection timeout
2025-05-22 18:07:39 +02:00

83 lines
1.7 KiB
C++

#include "comms/PacketClient.h"
#include "util/ILog.h"
#include "util/Packet.h"
#include "util/SharedQueue.h"
#include <assert.h>
const uint32_t max_packet_queue_size = 25;
void PacketClient::init(void)
{
// sharedQueue is currently defined external, it is not shared between processes
connect(sharedQueue);
}
PacketClient::PacketClient() : queue(nullptr) {}
bool PacketClient::connect(void)
{
is_connected = true;
return is_connected;
}
bool PacketClient::disconnect(void)
{
is_connected = false;
return is_connected;
}
bool PacketClient::isConnected(void)
{
return is_connected;
}
bool PacketClient::isStandalone(void)
{
return false;
}
int PacketClient::connect(SharedQueue *_queue)
{
if (!queue) {
queue = _queue;
} else if (_queue != queue) {
ILOG_WARN("Client already connected.");
}
is_connected = true;
return queue->serverQueueSize();
}
bool PacketClient::send(meshtastic_ToRadio &&to)
{
if (available()) {
static uint32_t id = 0;
return queue->clientSend(DataPacket<meshtastic_ToRadio>(++id, to));
} else {
ILOG_WARN("Cannot send DataPacket");
return false;
}
}
meshtastic_FromRadio PacketClient::receive(void)
{
if (hasData()) {
auto p = queue->clientReceive();
if (p) {
return static_cast<DataPacket<meshtastic_FromRadio> *>(p->move().get())->getData();
}
}
return meshtastic_FromRadio();
}
bool PacketClient::hasData() const
{
assert(queue);
return queue->serverQueueSize() > 0;
}
bool PacketClient::available() const
{
assert(queue);
return queue->clientQueueSize() < max_packet_queue_size;
}