aqhome: implemented IPC client, fixed some bugs.

sending a PING request and retrieving the PONG response works now.
This commit is contained in:
Martin Preuss
2023-04-16 23:22:03 +02:00
parent c00b90bf28
commit d53b061aed
34 changed files with 549 additions and 158 deletions

View File

@@ -27,6 +27,33 @@ static uint8_t _calcXorChecksum(const uint8_t *ptr, uint8_t len);
#endif
GWEN_MSG *AQH_NodeMsg_new(uint8_t destAddr, uint8_t srcAddr, uint8_t code, uint8_t payloadLen, const uint8_t *payload)
{
GWEN_MSG *msg;
uint32_t len;
uint8_t *ptr;
len=AQH_MSG_OFFS_ALL_DATA_BEGIN+payloadLen+1; /* dest, len, code, src, payload, crc8 */
msg=GWEN_Msg_new(len);
if (msg==NULL)
return NULL;
ptr=GWEN_Msg_GetBuffer(msg);
ptr[AQH_MSG_OFFS_ALL_DEST_ADDRESS]=destAddr & 0xff;
ptr[AQH_MSG_OFFS_ALL_PAYLOAD_LEN]=6;
ptr[AQH_MSG_OFFS_ALL_MSG_TYPE]=code;
ptr[AQH_MSG_OFFS_ALL_SRC_ADDRESS]=srcAddr;
if (payloadLen && payload)
memmove(ptr+AQH_MSG_OFFS_ALL_DATA_BEGIN, payload, payloadLen);
GWEN_Msg_SetBytesInBuffer(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+payloadLen);
GWEN_Msg_IncCurrentPos(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+payloadLen);
return msg;
}
uint8_t AQH_NodeMsg_GetDestAddress(const GWEN_MSG *msg)
{
if (msg && GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_OFFS_ALL_DATA_BEGIN) {
@@ -142,45 +169,6 @@ int AQH_NodeMsg_AddChecksum(GWEN_MSG *msg)
uint32_t AQH_NodeMsg_GetUint32At(const GWEN_MSG *msg, int offs, int defaultValue)
{
if ((GWEN_Msg_GetBytesInBuffer(msg)>=offs+4)) {
const uint8_t *ptr;
ptr=GWEN_Msg_GetConstBuffer(msg)+offs;
return (uint32_t)(ptr[0])+(ptr[1]<<8)+(ptr[2]<<16)+(ptr[3]<<24);
}
return defaultValue;
}
uint16_t AQH_NodeMsg_GetUint16At(const GWEN_MSG *msg, int offs, int defaultValue)
{
if ((GWEN_Msg_GetBytesInBuffer(msg)>=offs+2)) {
const uint8_t *ptr;
ptr=GWEN_Msg_GetConstBuffer(msg)+offs;
return (uint16_t)(ptr[0])+(ptr[1]<<8);
}
return defaultValue;
}
uint8_t AQH_NodeMsg_GetUint8At(const GWEN_MSG *msg, int offs, int defaultValue)
{
if ((GWEN_Msg_GetBytesInBuffer(msg)>=offs+1)) {
const uint8_t *ptr;
ptr=GWEN_Msg_GetConstBuffer(msg)+offs;
return ptr[0];
}
return defaultValue;
}
void AQH_NodeMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
{
GWEN_Buffer_AppendArgs(dbuf,