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;
|
||||||
|
|||||||
+16
-15
@@ -133,28 +133,21 @@ 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) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle the ID request, it should connect us. TODO: Improve this
|
|
||||||
IdentificationPacket papers;
|
IdentificationPacket papers;
|
||||||
initIdentificationPacket(&papers, ESLABS_DEVICE_NAME, ESLABS_DEVICE_ID);
|
initIdentificationPacket(&papers, ESLABS_DEVICE_NAME, ESLABS_DEVICE_ID);
|
||||||
WalkieTalkie::SendData(&papers);
|
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;
|
break;
|
||||||
|
|
||||||
} else {
|
|
||||||
switch(cmd) {
|
|
||||||
case CmdCreateWindow: {
|
case CmdCreateWindow: {
|
||||||
int8_t newWindowID = Window::Create(payload, &mainScreen);
|
int8_t newWindowID = Window::Create(payload, &mainScreen);
|
||||||
if (newWindowID < 0) {
|
if (newWindowID < 0) {
|
||||||
@@ -224,6 +217,15 @@ void loop(void) {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case CMDHealthCheck: {
|
||||||
|
LOG_INFO(F("HealthCheck request came in \r\n"));
|
||||||
|
|
||||||
|
HealthCheckReply packet;
|
||||||
|
initHealthCheckReply(&packet);
|
||||||
|
WalkieTalkie::SendData(&packet);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
LOG_ERROR(F("Command: %s\n"), CommandToStr(cmd));
|
LOG_ERROR(F("Command: %s\n"), CommandToStr(cmd));
|
||||||
LOG_ERROR(F("Unknown Command: `%02X` has not been implemented yet.\n"), cmd);
|
LOG_ERROR(F("Unknown Command: `%02X` has not been implemented yet.\n"), cmd);
|
||||||
@@ -248,5 +250,4 @@ void loop(void) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user