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;
+108 -107
View File
@@ -133,120 +133,121 @@ 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;
switch(cmd) {
case CmdRequestID:
IdentificationPacket papers;
initIdentificationPacket(&papers, ESLABS_DEVICE_NAME, ESLABS_DEVICE_ID);
WalkieTalkie::SendData(&papers);
LOG_INFO(F("Connection request came in\r\n"));
LOG_INFO(F("Replied with something \r\n\n"));
break;
case CmdCreateWindow: {
int8_t newWindowID = Window::Create(payload, &mainScreen);
if (newWindowID < 0) {
LOG_WARN(F("Failed to add new window!\n"));
break;
}
LOG_INFO(F("Successfully added a new window: %d\n"), newWindowID);
// Now we return the ID of this new window - esdi should expect it
WindowIDReply wID;
initWindowIDReply(&wID, newWindowID);
WalkieTalkie::SendData(&wID);
break;
}
// Handle the ID request, it should connect us. TODO: Improve this
IdentificationPacket papers;
initIdentificationPacket(&papers, ESLABS_DEVICE_NAME, ESLABS_DEVICE_ID);
WalkieTalkie::SendData(&papers);
LOG_INFO(F("Connection request came in"));
connected = true;
} else {
switch(cmd) {
case CmdCreateWindow: {
int8_t newWindowID = Window::Create(payload, &mainScreen);
if (newWindowID < 0) {
LOG_WARN(F("Failed to add new window!\n"));
break;
}
LOG_INFO(F("Successfully added a new window: %d\n"), newWindowID);
// Now we return the ID of this new window - esdi should expect it
WindowIDReply wID;
initWindowIDReply(&wID, newWindowID);
WalkieTalkie::SendData(&wID);
break;
case CmdUpdateWinDims: {
LOG_INFO(F("Updating Win DIMS\n"));
bool res = Window::UpdateDims(payload, &mainScreen);
if (!res) {
LOG_WARN(F("Failed to update window dims\n"));
}
case CmdUpdateWinDims: {
LOG_INFO(F("Updating Win DIMS\n"));
bool res = Window::UpdateDims(payload, &mainScreen);
if (!res) {
LOG_WARN(F("Failed to update window dims\n"));
}
break;
};
case CmdUpdateWin: {
LOG_INFO(F("UPDATEING WINDOW\n"));
bool res = Window::UpdateWindow(payload, &mainScreen);
if (!res) {
LOG_WARN(F("Failed to update window\n"));
}
break;
break;
};
case CmdUpdateWin: {
LOG_INFO(F("UPDATEING WINDOW\n"));
bool res = Window::UpdateWindow(payload, &mainScreen);
if (!res) {
LOG_WARN(F("Failed to update window\n"));
}
case CmdDestroyWindow: {
uint8_t destroyedWinID = Window::Destroy(payload, &mainScreen);
if (destroyedWinID < 0) {
LOG_WARN(F("Failed to destroy window\n"));
break;
}
LOG_INFO(F("Succesfully destroyed window: %d\n"), destroyedWinID);
break;
}
case CMDData: {
LOG_DEBUG(F("Data Received: %d bytes\r\n"), resp);
// int pos = 0;
// for (int k = 0; k < resp; k++) {
// // Write 2 hex digits and a space to our local buffer
// // %02X ensures leading zeros (e.g., 0A instead of A)
// pos += sprintf(lineBuffer + pos, "%02X ", payload[k]);
//
// // Every 8 bytes OR if it's the very last byte in the payload
// if ((k + 1) % 8 == 0 || k == resp - 1) {
// // Send the completed line to the logger
// // We use LOG_DEBUG or similar so we don't spam [WARN] on every line
// LOG_DEBUG(F("%s\r\n"), lineBuffer);
//
// // Reset buffer position for the next line
// pos = 0;
// memset(lineBuffer, 0, sizeof(lineBuffer));
// }
// }
// LOG_DEBUG(F("\r\n"));
Data::Parse(payload, resp, &mainScreen);
break;
}
default:
LOG_ERROR(F("Command: %s\n"), CommandToStr(cmd));
LOG_ERROR(F("Unknown Command: `%02X` has not been implemented yet.\n"), cmd);
int pos = 0;
for (int k = 0; k < resp; k++) {
// Write 2 hex digits and a space to our local buffer
// %02X ensures leading zeros (e.g., 0A instead of A)
pos += sprintf(lineBuffer + pos, "%02X ", payload[k]);
// Every 8 bytes OR if it's the very last byte in the payload
if ((k + 1) % 8 == 0 || k == resp - 1) {
// Send the completed line to the logger
// We use LOG_DEBUG or similar so we don't spam [WARN] on every line
LOG_WARN(F("%s\r\n"), lineBuffer);
// Reset buffer position for the next line
pos = 0;
memset(lineBuffer, 0, sizeof(lineBuffer));
}
}
LOG_WARN(F("\r\n"));
break;
break;
}
case CmdDestroyWindow: {
uint8_t destroyedWinID = Window::Destroy(payload, &mainScreen);
if (destroyedWinID < 0) {
LOG_WARN(F("Failed to destroy window\n"));
break;
}
LOG_INFO(F("Succesfully destroyed window: %d\n"), destroyedWinID);
break;
}
case CMDData: {
LOG_DEBUG(F("Data Received: %d bytes\r\n"), resp);
// int pos = 0;
// for (int k = 0; k < resp; k++) {
// // Write 2 hex digits and a space to our local buffer
// // %02X ensures leading zeros (e.g., 0A instead of A)
// pos += sprintf(lineBuffer + pos, "%02X ", payload[k]);
//
// // Every 8 bytes OR if it's the very last byte in the payload
// if ((k + 1) % 8 == 0 || k == resp - 1) {
// // Send the completed line to the logger
// // We use LOG_DEBUG or similar so we don't spam [WARN] on every line
// LOG_DEBUG(F("%s\r\n"), lineBuffer);
//
// // Reset buffer position for the next line
// pos = 0;
// memset(lineBuffer, 0, sizeof(lineBuffer));
// }
// }
// LOG_DEBUG(F("\r\n"));
Data::Parse(payload, resp, &mainScreen);
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);
int pos = 0;
for (int k = 0; k < resp; k++) {
// Write 2 hex digits and a space to our local buffer
// %02X ensures leading zeros (e.g., 0A instead of A)
pos += sprintf(lineBuffer + pos, "%02X ", payload[k]);
// Every 8 bytes OR if it's the very last byte in the payload
if ((k + 1) % 8 == 0 || k == resp - 1) {
// Send the completed line to the logger
// We use LOG_DEBUG or similar so we don't spam [WARN] on every line
LOG_WARN(F("%s\r\n"), lineBuffer);
// Reset buffer position for the next line
pos = 0;
memset(lineBuffer, 0, sizeof(lineBuffer));
}
}
LOG_WARN(F("\r\n"));
break;
}
}
}