added the healthcheck command
This commit is contained in:
@@ -12,6 +12,7 @@ typedef enum : uint8_t {
|
|||||||
CmdUpdateWinDims = 5, // NOTE: change this to a move cmd instead
|
CmdUpdateWinDims = 5, // NOTE: change this to a move cmd instead
|
||||||
CmdUpdateWin = 6,
|
CmdUpdateWin = 6,
|
||||||
CMDData = 7,
|
CMDData = 7,
|
||||||
|
CMDHealthCheck = 9,
|
||||||
} Command;
|
} Command;
|
||||||
|
|
||||||
char* CommandToStr(Command id);
|
char* CommandToStr(Command id);
|
||||||
|
|||||||
@@ -24,3 +24,11 @@ void initWindowIDReply(WindowIDReply* pkt, int16_t id) {
|
|||||||
pkt->EndMarker = 0x03;
|
pkt->EndMarker = 0x03;
|
||||||
pkt->wID = id;
|
pkt->wID = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void initHealthCheckReply(HealthCheckReply* pkt) {
|
||||||
|
memset(pkt, 0, sizeof(*pkt));
|
||||||
|
|
||||||
|
pkt->StartMarker = 0x02;
|
||||||
|
pkt->reply = 0x06;
|
||||||
|
pkt->EndMarker = 0x03;
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define __PACKETS__
|
#define __PACKETS__
|
||||||
|
|
||||||
#include "UIDimensions.h"
|
#include "UIDimensions.h"
|
||||||
|
#include <cstdint>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
typedef uint8_t PacketType;
|
typedef uint8_t PacketType;
|
||||||
@@ -36,4 +37,12 @@ struct __attribute__((packed)) WindowIDReply {
|
|||||||
|
|
||||||
void initWindowIDReply(WindowIDReply* pkt, int16_t id);
|
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
|
#endif
|
||||||
|
|||||||
@@ -21,11 +21,15 @@ namespace WalkieTalkie {
|
|||||||
resetBuffer();
|
resetBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool validCmd(uint8_t* cmd) {
|
||||||
|
return !(*cmd == 0 || *cmd > CMDHealthCheck);
|
||||||
|
}
|
||||||
|
|
||||||
static inline void RecvCMDRoutine(byte *b) {
|
static inline void RecvCMDRoutine(byte *b) {
|
||||||
LOG_TRACE(F("Reading the command byte\n"));
|
LOG_TRACE(F("Reading the command byte\n"));
|
||||||
|
|
||||||
uint8_t cmdVal = Command(*b);
|
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);
|
LOG_TRACE(F("Invalid CMD byte: 0x%02x. Resetting parser.\n"), cmdVal);
|
||||||
ResetStateMachine();
|
ResetStateMachine();
|
||||||
return;
|
return;
|
||||||
|
|||||||
+104
-103
@@ -133,120 +133,121 @@ void loop(void) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_DEBUG(F("Command: %s\n"), CommandToStr(cmd));
|
LOG_WARN(F("Command: %s\r\n"), CommandToStr(cmd));
|
||||||
LOG_DEBUG(F("Response Payload Len: %d\n"), resp);
|
LOG_DEBUG(F("Response Payload Len: %d\r\n"), resp);
|
||||||
|
|
||||||
// print_memory_stats();
|
// print_memory_stats();
|
||||||
|
|
||||||
// If its not connected the only command we can receive is the CmdRequestID
|
switch(cmd) {
|
||||||
if (!connected) {
|
case CmdRequestID:
|
||||||
if (cmd != CmdRequestID) {
|
IdentificationPacket papers;
|
||||||
return;
|
initIdentificationPacket(&papers, ESLABS_DEVICE_NAME, ESLABS_DEVICE_ID);
|
||||||
}
|
WalkieTalkie::SendData(&papers);
|
||||||
|
|
||||||
// Handle the ID request, it should connect us. TODO: Improve this
|
LOG_INFO(F("Connection request came in\r\n"));
|
||||||
IdentificationPacket papers;
|
LOG_INFO(F("Replied with something \r\n\n"));
|
||||||
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 CmdCreateWindow: {
|
||||||
|
int8_t newWindowID = Window::Create(payload, &mainScreen);
|
||||||
|
if (newWindowID < 0) {
|
||||||
|
LOG_WARN(F("Failed to add new window!\n"));
|
||||||
break;
|
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"));
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
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);
|
LOG_INFO(F("Successfully added a new window: %d\n"), newWindowID);
|
||||||
|
|
||||||
break;
|
// Now we return the ID of this new window - esdi should expect it
|
||||||
}
|
WindowIDReply wID;
|
||||||
case CMDData: {
|
initWindowIDReply(&wID, newWindowID);
|
||||||
LOG_DEBUG(F("Data Received: %d bytes\r\n"), resp);
|
WalkieTalkie::SendData(&wID);
|
||||||
|
|
||||||
// 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;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user