added the healthcheck command

This commit is contained in:
2026-09-22 16:30:19 +01:00
parent cceafe027c
commit d7d421c6f2
5 changed files with 127 additions and 104 deletions
+1
View File
@@ -12,6 +12,7 @@ typedef enum : uint8_t {
CmdUpdateWinDims = 5, // NOTE: change this to a move cmd instead
CmdUpdateWin = 6,
CMDData = 7,
CMDHealthCheck = 9,
} Command;
char* CommandToStr(Command id);
+8
View File
@@ -24,3 +24,11 @@ void initWindowIDReply(WindowIDReply* pkt, int16_t id) {
pkt->EndMarker = 0x03;
pkt->wID = id;
}
void initHealthCheckReply(HealthCheckReply* pkt) {
memset(pkt, 0, sizeof(*pkt));
pkt->StartMarker = 0x02;
pkt->reply = 0x06;
pkt->EndMarker = 0x03;
}
+9
View File
@@ -2,6 +2,7 @@
#define __PACKETS__
#include "UIDimensions.h"
#include <cstdint>
#include <stdint.h>
typedef uint8_t PacketType;
@@ -36,4 +37,12 @@ struct __attribute__((packed)) WindowIDReply {
void initWindowIDReply(WindowIDReply* pkt, int16_t id);
struct __attribute__((packed)) HealthCheckReply {
uint8_t StartMarker;
uint8_t reply;
uint8_t EndMarker;
};
void initHealthCheckReply(HealthCheckReply* pkt);
#endif
+5 -1
View File
@@ -21,11 +21,15 @@ namespace WalkieTalkie {
resetBuffer();
}
static inline bool validCmd(uint8_t* cmd) {
return !(*cmd == 0 || *cmd > CMDHealthCheck);
}
static inline void RecvCMDRoutine(byte *b) {
LOG_TRACE(F("Reading the command byte\n"));
uint8_t cmdVal = Command(*b);
if (cmdVal == 0 || cmdVal > CMDData) {
if (!validCmd(&cmdVal)) {
LOG_TRACE(F("Invalid CMD byte: 0x%02x. Resetting parser.\n"), cmdVal);
ResetStateMachine();
return;
+16 -15
View File
@@ -133,28 +133,21 @@ void loop(void) {
return;
}
LOG_DEBUG(F("Command: %s\n"), CommandToStr(cmd));
LOG_DEBUG(F("Response Payload Len: %d\n"), resp);
LOG_WARN(F("Command: %s\r\n"), CommandToStr(cmd));
LOG_DEBUG(F("Response Payload Len: %d\r\n"), resp);
// print_memory_stats();
// If its not connected the only command we can receive is the CmdRequestID
if (!connected) {
if (cmd != CmdRequestID) {
return;
}
// Handle the ID request, it should connect us. TODO: Improve this
switch(cmd) {
case CmdRequestID:
IdentificationPacket papers;
initIdentificationPacket(&papers, ESLABS_DEVICE_NAME, ESLABS_DEVICE_ID);
WalkieTalkie::SendData(&papers);
LOG_INFO(F("Connection request came in"));
LOG_INFO(F("Connection request came in\r\n"));
LOG_INFO(F("Replied with something \r\n\n"));
connected = true;
} else {
switch(cmd) {
break;
case CmdCreateWindow: {
int8_t newWindowID = Window::Create(payload, &mainScreen);
if (newWindowID < 0) {
@@ -224,6 +217,15 @@ void loop(void) {
break;
}
case CMDHealthCheck: {
LOG_INFO(F("HealthCheck request came in \r\n"));
HealthCheckReply packet;
initHealthCheckReply(&packet);
WalkieTalkie::SendData(&packet);
break;
}
default:
LOG_ERROR(F("Command: %s\n"), CommandToStr(cmd));
LOG_ERROR(F("Unknown Command: `%02X` has not been implemented yet.\n"), cmd);
@@ -249,4 +251,3 @@ void loop(void) {
}
}
}
}