fix: Spit working again also with linux

This commit is contained in:
2025-11-14 23:29:44 +01:00
parent 66140ea823
commit 0ecd846183
12 changed files with 40 additions and 22 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
idf_component_register(
SRC_DIRS "src" "src/esp"
INCLUDE_DIRS "include"
REQUIRES esp_system esp_netif freeRtosApi
REQUIRES esp_system esp_netif freeRtosApi sockets
)
+4 -1
View File
@@ -10,6 +10,7 @@
#include <memory>
#include <vector>
#include <functional>
#include "syslog.hpp"
using namespace std;
@@ -86,6 +87,7 @@ class SClient : ISadClient {
Callbacks mCallbacks;
fos::TaskT<SClient &> *mThreadReceive{};
fos::TaskT<SClient &> *mThreadProcess{};
bool mStopReceiveMessages{};
Connection mConnectionStatus{Connection::None};
@@ -151,7 +153,8 @@ class SClient : ISadClient {
private:
bool startReceiveSPITMessages();
void stopReceiveSPITMessages();
static void receiveSPITMessage(SClient &rM);
static void receiveSpitMessage(SClient &rM);
static void processSpitMessage(SClient &rM);
// Reconnect to the server when connection is lost see eventConnectionStatus and eventServerDetected
bool _doReconnect{}; // true = on eventServerDetected connect to the server identified by mServerID
public:
+19 -6
View File
@@ -2,8 +2,12 @@
#include "spit_client.hpp"
#include "esp_log.h"
#include "Queue.hpp"
namespace spit {
static const char *TAG = "SPIT";
static fos::Queue<vector<char>> incommingSpit(64);
/**
* Create a new SPIT_client instance, should be done once by the user app.
@@ -225,7 +229,8 @@ bool SClient::startReceiveSPITMessages() {
if (!mSocket.getIsBound())
return false;
mStopReceiveMessages = false;
mThreadReceive = new fos::TaskT<SClient &>(receiveSPITMessage, *this, "receiveTask", fos::Task::DefaultStackSize * 4);
mThreadReceive = new fos::TaskT<SClient &>(receiveSpitMessage, *this, "receiveTask", fos::Task::DefaultStackSize, fos::Task::MAX_PRIORITY-3);
mThreadProcess = new fos::TaskT<SClient &>(processSpitMessage, *this, "processTask", fos::Task::DefaultStackSize);
return true;
}
@@ -233,7 +238,7 @@ void SClient::stopReceiveSPITMessages() {
mStopReceiveMessages = true;
}
void SClient::receiveSPITMessage(SClient &rM) {
void SClient::receiveSpitMessage(SClient &rM) {
char buffer[MAXSPITMESSAGEBYTECOUNT + 1];
int rdLen;
while (rM.mStopReceiveMessages == false) {
@@ -244,13 +249,21 @@ void SClient::receiveSPITMessage(SClient &rM) {
}
continue;
}
auto vec = vector<char>(buffer, buffer + rdLen);
auto spitMsg = make_unique<Message>(vec);
rM.parseMessage(move(spitMsg));
// rM.checkParseMessage(move(spitMsg));
auto vec = make_unique<vector<char>>(buffer, buffer + rdLen);
incommingSpit.enqueue(std::move(vec));
}
}
void SClient::processSpitMessage(SClient &rM) {
while (true) {
auto data = *incommingSpit.dequeue();
auto spitMsg = make_unique<Message>(data);
rM.parseMessage(move(spitMsg));
}
}
void SClient::resetMessageNumberReceived() {
mMessageNumberReceived = -1;
mOvertakingMessages.clear();