From c65bd60bc5c8b6f88043e187930b97a5549c20df Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Thu, 20 Apr 2023 00:43:07 +0200 Subject: [PATCH] avr: added flash-related messages. --- aqhome/msg/0BUILD | 8 +++ aqhome/msg/endpoint_log.c | 8 +++ aqhome/msg/msg_flashdata.c | 111 +++++++++++++++++++++++++++++++++ aqhome/msg/msg_flashdata.h | 34 ++++++++++ aqhome/msg/msg_flashend.c | 76 ++++++++++++++++++++++ aqhome/msg/msg_flashend.h | 31 +++++++++ aqhome/msg/msg_flashready.h | 2 +- aqhome/msg/msg_flashresponse.c | 50 +++++++++++++++ aqhome/msg/msg_flashresponse.h | 28 +++++++++ aqhome/msg/msg_flashstart.c | 107 +++++++++++++++++++++++++++++++ aqhome/msg/msg_flashstart.h | 33 ++++++++++ aqhome/msg/msg_node.c | 38 ++++++++++- aqhome/msg/msg_node.h | 2 +- aqhome/msg/msg_ping.c | 2 - aqhome/msgmanager.c | 24 ++++++- 15 files changed, 545 insertions(+), 9 deletions(-) create mode 100644 aqhome/msg/msg_flashdata.c create mode 100644 aqhome/msg/msg_flashdata.h create mode 100644 aqhome/msg/msg_flashend.c create mode 100644 aqhome/msg/msg_flashend.h create mode 100644 aqhome/msg/msg_flashresponse.c create mode 100644 aqhome/msg/msg_flashresponse.h create mode 100644 aqhome/msg/msg_flashstart.c create mode 100644 aqhome/msg/msg_flashstart.h diff --git a/aqhome/msg/0BUILD b/aqhome/msg/0BUILD index 905c187..6e5b74e 100644 --- a/aqhome/msg/0BUILD +++ b/aqhome/msg/0BUILD @@ -64,6 +64,10 @@ msg_value2.h msg_device.h msg_flashready.h + msg_flashstart.h + msg_flashresponse.h + msg_flashend.h + msg_flashdata.h @@ -98,6 +102,10 @@ msg_value2.c msg_device.c msg_flashready.c + msg_flashstart.c + msg_flashresponse.c + msg_flashend.c + msg_flashdata.c diff --git a/aqhome/msg/endpoint_log.c b/aqhome/msg/endpoint_log.c index 62fd325..0fe0045 100644 --- a/aqhome/msg/endpoint_log.c +++ b/aqhome/msg/endpoint_log.c @@ -28,6 +28,10 @@ #include "aqhome/msg/msg_denyaddr.h" #include "aqhome/msg/msg_device.h" #include "aqhome/msg/msg_flashready.h" +#include "aqhome/msg/msg_flashstart.h" +#include "aqhome/msg/msg_flashresponse.h" +#include "aqhome/msg/msg_flashend.h" +#include "aqhome/msg/msg_flashdata.h" #include #include @@ -141,6 +145,10 @@ void _logMessage(GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg) case AQH_MSG_TYPE_MEMSTATS: AQH_MemStatsMsg_DumpToBuffer(msg, dbuf, "received"); break; case AQH_MSG_TYPE_SYSSTATS: AQH_SysStatsMsg_DumpToBuffer(msg, dbuf, "received"); break; case AQH_MSG_TYPE_FLASH_READY: AQH_FlashReadyMsg_DumpToBuffer(msg, dbuf, "received"); break; + case AQH_MSG_TYPE_FLASH_START: AQH_FlashStartMsg_DumpToBuffer(msg, dbuf, "received"); break; + case AQH_MSG_TYPE_FLASH_RSP: AQH_FlashResponseMsg_DumpToBuffer(msg, dbuf, "received"); break; + case AQH_MSG_TYPE_FLASH_END: AQH_FlashEndMsg_DumpToBuffer(msg, dbuf, "received"); break; + case AQH_MSG_TYPE_FLASH_DATA: AQH_FlashDataMsg_DumpToBuffer(msg, dbuf, "received"); break; default: AQH_NodeMsg_DumpToBuffer(msg, dbuf, "received"); break; } } diff --git a/aqhome/msg/msg_flashdata.c b/aqhome/msg/msg_flashdata.c new file mode 100644 index 0000000..16408ca --- /dev/null +++ b/aqhome/msg/msg_flashdata.c @@ -0,0 +1,111 @@ +/**************************************************************************** + * This file is part of the project AqHome. + * AqHome (c) by 2023 Martin Preuss, all rights reserved. + * + * The license for this file can be found in the file COPYING which you + * should have received along with this file. + ****************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "aqhome/msg/msg_flashdata.h" + +#include +#include +#include +#include + + +#define AQH_MSG_OFFS_FLASHDATA_ADDRESS 0 /* 4 bytes */ +#define AQH_MSG_OFFS_FLASHDATA_DATA 4 /* x bytes */ + + +#define AQH_MSG_FLASHEND_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHDATA_DATA) + + + +GWEN_MSG *AQH_FlashDataMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint32_t addr, + const uint8_t *dataPtr, uint32_t dataLen) +{ + GWEN_MSG *msg; + uint8_t *ptr; + int rv; + uint32_t i; + + msg=AQH_NodeMsg_new(destAddr, srcAddr, code, dataLen+4, NULL); + ptr=GWEN_Msg_GetBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHDATA_ADDRESS; + + *(ptr++)=addr & 0xff; + *(ptr++)=(addr>>8) & 0xff; + *(ptr++)=(addr>>16) & 0xff; + *(ptr++)=(addr>>24) & 0xff; + + for (i=0; iAQH_MSG_FLASHEND_MINSIZE) + return msgDataLen-AQH_MSG_OFFS_ALL_DATA_BEGIN-AQH_MSG_OFFS_FLASHDATA_DATA; + return 0; +} + + + +const uint8_t *AQH_FlashDataMsg_GetDataPtr(const GWEN_MSG *msg) +{ + const uint8_t *ptr; + + ptr=GWEN_Msg_GetConstBuffer(msg); + if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_FLASHEND_MINSIZE) + return ptr+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHDATA_DATA; + return NULL; +} + + + +void AQH_FlashDataMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) +{ + if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_FLASH_READY) && + (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_FLASHEND_MINSIZE)) { + GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: FLASHDATA %s (data address=0x%04x, data length=%d)\n", + AQH_NodeMsg_GetSourceAddress(msg), + AQH_NodeMsg_GetDestAddress(msg), + sText, + AQH_FlashDataMsg_GetAddress(msg), + AQH_FlashDataMsg_GetDataLen(msg)); + } +} + + + + + + + diff --git a/aqhome/msg/msg_flashdata.h b/aqhome/msg/msg_flashdata.h new file mode 100644 index 0000000..f91d23e --- /dev/null +++ b/aqhome/msg/msg_flashdata.h @@ -0,0 +1,34 @@ +/**************************************************************************** + * This file is part of the project AqHome. + * AqHome (c) by 2023 Martin Preuss, all rights reserved. + * + * The license for this file can be found in the file COPYING which you + * should have received along with this file. + ****************************************************************************/ + +#ifndef AQH_MSG_FLASHDATA_H +#define AQH_MSG_FLASHDATA_H + + +#include +#include + +#include +#include + + +AQHOME_API GWEN_MSG *AQH_FlashDataMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint32_t addr, + const uint8_t *dataPtr, uint32_t dataLen); + +AQHOME_API uint32_t AQH_FlashDataMsg_GetAddress(const GWEN_MSG *msg); +AQHOME_API uint8_t AQH_FlashDataMsg_GetDataLen(const GWEN_MSG *msg); +AQHOME_API const uint8_t *AQH_FlashDataMsg_GetDataPtr(const GWEN_MSG *msg); +AQHOME_API void AQH_FlashDataMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); + + + + +#endif + + + diff --git a/aqhome/msg/msg_flashend.c b/aqhome/msg/msg_flashend.c new file mode 100644 index 0000000..4184f44 --- /dev/null +++ b/aqhome/msg/msg_flashend.c @@ -0,0 +1,76 @@ +/**************************************************************************** + * This file is part of the project AqHome. + * AqHome (c) by 2023 Martin Preuss, all rights reserved. + * + * The license for this file can be found in the file COPYING which you + * should have received along with this file. + ****************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "aqhome/msg/msg_flashend.h" + +#include +#include +#include +#include + + +#define AQH_MSG_OFFS_FLASHEND_REASON 0 /* 1 byte */ + +#define AQH_MSG_FLASHEND_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHEND_REASON+1) + + + +GWEN_MSG *AQH_FlashEndMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint8_t reason) +{ + GWEN_MSG *msg; + uint8_t *ptr; + int rv; + + msg=AQH_NodeMsg_new(destAddr, srcAddr, code, 5, NULL); + ptr=GWEN_Msg_GetBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHEND_REASON; + + *(ptr++)=reason & 0xff; /* reason */ + GWEN_Msg_IncCurrentPos(msg, 5); + + rv=AQH_NodeMsg_AddChecksum(msg); + if (rv<0) { + DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); + GWEN_Msg_free(msg); + return NULL; + } + + return msg; + +} + + + +uint8_t AQH_FlashEndMsg_GetReason(const GWEN_MSG *msg) +{ + return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHEND_REASON, 0); +} + + + +void AQH_FlashEndMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) +{ + if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_FLASH_READY) && + (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_FLASHEND_MINSIZE)) { + GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: FLASHEND %s (reason=%d)\n", + AQH_NodeMsg_GetSourceAddress(msg), + AQH_NodeMsg_GetDestAddress(msg), + sText, + AQH_FlashEndMsg_GetReason(msg)); + } +} + + + + + + + diff --git a/aqhome/msg/msg_flashend.h b/aqhome/msg/msg_flashend.h new file mode 100644 index 0000000..c48901f --- /dev/null +++ b/aqhome/msg/msg_flashend.h @@ -0,0 +1,31 @@ +/**************************************************************************** + * This file is part of the project AqHome. + * AqHome (c) by 2023 Martin Preuss, all rights reserved. + * + * The license for this file can be found in the file COPYING which you + * should have received along with this file. + ****************************************************************************/ + +#ifndef AQH_MSG_FLASHEND_H +#define AQH_MSG_FLASHEND_H + + +#include +#include + +#include +#include + + +AQHOME_API GWEN_MSG *AQH_FlashEndMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint8_t reason); + +AQHOME_API uint8_t AQH_FlashEndMsg_GetReason(const GWEN_MSG *msg); + +AQHOME_API void AQH_FlashEndMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); + + + +#endif + + + diff --git a/aqhome/msg/msg_flashready.h b/aqhome/msg/msg_flashready.h index d26c492..95b5a06 100644 --- a/aqhome/msg/msg_flashready.h +++ b/aqhome/msg/msg_flashready.h @@ -20,7 +20,7 @@ AQHOME_API uint32_t AQH_FlashReadyMsg_GetUid(const GWEN_MSG *msg); AQHOME_API uint16_t AQH_FlashReadyMsg_GetFirmwareType(const GWEN_MSG *msg); AQHOME_API uint16_t AQH_FlashReadyMsg_GetFirmwareVersion(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_FlashReadyMsg_GetModules(const GWEN_MSG *msg); +AQHOME_API uint16_t AQH_FlashReadyMsg_GetPagesize(const GWEN_MSG *msg); AQHOME_API void AQH_FlashReadyMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); diff --git a/aqhome/msg/msg_flashresponse.c b/aqhome/msg/msg_flashresponse.c new file mode 100644 index 0000000..6d23a10 --- /dev/null +++ b/aqhome/msg/msg_flashresponse.c @@ -0,0 +1,50 @@ +/**************************************************************************** + * This file is part of the project AqHome. + * AqHome (c) by 2023 Martin Preuss, all rights reserved. + * + * The license for this file can be found in the file COPYING which you + * should have received along with this file. + ****************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "aqhome/msg/msg_flashresponse.h" + +#include +#include +#include +#include + + +#define AQH_MSG_OFFS_FLASHRESPONSE_CODE 0 /* 1 byte */ + +#define AQH_MSG_FLASHRESPONSE_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHRESPONSE_CODE+1) + + + +uint8_t AQH_FlashResponseMsg_GetCode(const GWEN_MSG *msg) +{ + return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHRESPONSE_CODE, 0); +} + + + +void AQH_FlashResponseMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) +{ + if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_FLASHRESPONSE_MINSIZE) { + GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: FLASHRESPONSE %s (code=%d)\n", + AQH_NodeMsg_GetSourceAddress(msg), + AQH_NodeMsg_GetDestAddress(msg), + sText, + AQH_FlashResponseMsg_GetCode(msg)); + } +} + + + + + + + diff --git a/aqhome/msg/msg_flashresponse.h b/aqhome/msg/msg_flashresponse.h new file mode 100644 index 0000000..bd9b023 --- /dev/null +++ b/aqhome/msg/msg_flashresponse.h @@ -0,0 +1,28 @@ +/**************************************************************************** + * This file is part of the project AqHome. + * AqHome (c) by 2023 Martin Preuss, all rights reserved. + * + * The license for this file can be found in the file COPYING which you + * should have received along with this file. + ****************************************************************************/ + +#ifndef AQH_MSG_FLASHRESPONSE_H +#define AQH_MSG_FLASHRESPONSE_H + + +#include +#include + +#include +#include + + +AQHOME_API uint8_t AQH_FlashResponseMsg_GetCode(const GWEN_MSG *msg); +AQHOME_API void AQH_FlashResponseMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); + + + +#endif + + + diff --git a/aqhome/msg/msg_flashstart.c b/aqhome/msg/msg_flashstart.c new file mode 100644 index 0000000..5221fc4 --- /dev/null +++ b/aqhome/msg/msg_flashstart.c @@ -0,0 +1,107 @@ +/**************************************************************************** + * This file is part of the project AqHome. + * AqHome (c) by 2023 Martin Preuss, all rights reserved. + * + * The license for this file can be found in the file COPYING which you + * should have received along with this file. + ****************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "aqhome/msg/msg_flashstart.h" + +#include +#include +#include +#include + + +#define AQH_MSG_OFFS_FLASHSTART_UID 0 /* 4 bytes */ +#define AQH_MSG_OFFS_FLASHSTART_FWTYPE 4 /* 2 bytes */ +#define AQH_MSG_OFFS_FLASHSTART_FWVER 6 /* 2 bytes */ + +#define AQH_MSG_FLASHSTART_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHSTART_FWVER+2) + + + +GWEN_MSG *AQH_FlashStartMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, + uint32_t uid, uint16_t firmwareType, uint16_t firmwareVersion) +{ + GWEN_MSG *msg; + uint8_t *ptr; + int rv; + + msg=AQH_NodeMsg_new(destAddr, srcAddr, code, 8, NULL); + ptr=GWEN_Msg_GetBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHSTART_UID; + + *(ptr++)=uid & 0xff; /* uid */ + *(ptr++)=(uid>>8) & 0xff; + *(ptr++)=(uid>>16) & 0xff; + *(ptr++)=(uid>>24) & 0xff; + + *(ptr++)=firmwareType & 0xff; /* fw type */ + *(ptr++)=(firmwareType>>8) & 0xff; + + *(ptr++)=firmwareVersion & 0xff; /* fw ver */ + *(ptr++)=(firmwareVersion>>8) & 0xff; + + rv=AQH_NodeMsg_AddChecksum(msg); + if (rv<0) { + DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); + GWEN_Msg_free(msg); + return NULL; + } + + return msg; + +} + + + +uint32_t AQH_FlashStartMsg_GetUid(const GWEN_MSG *msg) +{ + return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHSTART_UID, 0); +} + + + +uint16_t AQH_FlashStartMsg_GetFirmwareType(const GWEN_MSG *msg) +{ + return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHSTART_FWTYPE, 0); +} + + + +uint16_t AQH_FlashStartMsg_GetFirmwareVersion(const GWEN_MSG *msg) +{ + return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHSTART_FWVER, 0); +} + + + + +void AQH_FlashStartMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) +{ + if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_FLASHSTART_MINSIZE) { + uint16_t fwVersion; + + fwVersion=AQH_FlashStartMsg_GetFirmwareVersion(msg); + GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: FLASHSTART %s (uid=0x%08x, fw type=%d, fw ver=%d.%d)\n", + AQH_NodeMsg_GetSourceAddress(msg), + AQH_NodeMsg_GetDestAddress(msg), + sText, + (unsigned int) AQH_FlashStartMsg_GetUid(msg), + AQH_FlashStartMsg_GetFirmwareType(msg), + (fwVersion>>8) & 0xff, + fwVersion & 0xff); + } +} + + + + + + + diff --git a/aqhome/msg/msg_flashstart.h b/aqhome/msg/msg_flashstart.h new file mode 100644 index 0000000..4e8f704 --- /dev/null +++ b/aqhome/msg/msg_flashstart.h @@ -0,0 +1,33 @@ +/**************************************************************************** + * This file is part of the project AqHome. + * AqHome (c) by 2023 Martin Preuss, all rights reserved. + * + * The license for this file can be found in the file COPYING which you + * should have received along with this file. + ****************************************************************************/ + +#ifndef AQH_MSG_FLASHSTART_H +#define AQH_MSG_FLASHSTART_H + + +#include +#include + +#include +#include + +AQHOME_API GWEN_MSG *AQH_FlashStartMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, + uint32_t uid, uint16_t firmwareType, uint16_t firmwareVersion); + +AQHOME_API uint32_t AQH_FlashStartMsg_GetUid(const GWEN_MSG *msg); +AQHOME_API uint16_t AQH_FlashStartMsg_GetFirmwareType(const GWEN_MSG *msg); +AQHOME_API uint16_t AQH_FlashStartMsg_GetFirmwareVersion(const GWEN_MSG *msg); + +AQHOME_API void AQH_FlashStartMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); + + + +#endif + + + diff --git a/aqhome/msg/msg_node.c b/aqhome/msg/msg_node.c index cdfc732..5d65764 100644 --- a/aqhome/msg/msg_node.c +++ b/aqhome/msg/msg_node.c @@ -42,7 +42,7 @@ GWEN_MSG *AQH_NodeMsg_new(uint8_t destAddr, uint8_t srcAddr, uint8_t code, uint8 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_PAYLOAD_LEN]=payloadLen+2; ptr[AQH_MSG_OFFS_ALL_MSG_TYPE]=code; ptr[AQH_MSG_OFFS_ALL_SRC_ADDRESS]=srcAddr; @@ -123,8 +123,10 @@ int AQH_NodeMsg_IsMsgComplete(const GWEN_MSG *msg) ptr=GWEN_Msg_GetConstBuffer(msg); len=ptr[AQH_MSG_OFFS_ALL_PAYLOAD_LEN]+AQH_MSG_OFFS_ALL_PAYLOAD_BEGIN+1; - if (len>AQH_MAXMSGSIZE) - return -1; + if (len>AQH_MAXMSGSIZE) { + DBG_ERROR(AQH_LOGDOMAIN, "Total length > max length (%d > %d)", len, AQH_MAXMSGSIZE); + return -1; + } else if (msgLen>=len) return 1; } @@ -259,5 +261,35 @@ uint8_t _calcXorChecksum(const uint8_t *ptr, uint8_t len) +const char *AQH_NodeMsg_MsgTypeToChar(uint8_t i) +{ + switch(i) { + case AQH_MSG_TYPE_PING: return "Ping"; + case AQH_MSG_TYPE_PONG: return "Pong"; + case AQH_MSG_TYPE_COMSENDSTATS: return "SendStats"; + case AQH_MSG_TYPE_COMRECVSTATS: return "RecvStats"; + case AQH_MSG_TYPE_TWIBUSMEMBER: return "TwiBusMember"; + case AQH_MSG_TYPE_DEBUG: return "Debug"; + case AQH_MSG_TYPE_VALUE: return "Value"; + case AQH_MSG_TYPE_VALUE2: return "Value2"; + case AQH_MSG_TYPE_NEED_ADDRESS: return "NeedAddress"; + case AQH_MSG_TYPE_HAVE_ADDRESS: return "HaveAddress"; + case AQH_MSG_TYPE_CLAIM_ADDRESS: return "ClaimAddress"; + case AQH_MSG_TYPE_DENY_ADDRESS: return "DenyAddress"; + case AQH_MSG_TYPE_ADDRESS_RANGE: return "Range"; + + case AQH_MSG_TYPE_FLASH_START: return "FlashStart"; + case AQH_MSG_TYPE_FLASH_END: return "FlashEnd"; + case AQH_MSG_TYPE_FLASH_READY: return "FlashReady"; + case AQH_MSG_TYPE_FLASH_DATA: return "FlashData"; + case AQH_MSG_TYPE_FLASH_RSP: return "FlashResponse"; + + case AQH_MSG_TYPE_DEVICE: return "Device"; + case AQH_MSG_TYPE_MEMSTATS: return "MemStats"; + case AQH_MSG_TYPE_SYSSTATS: return "SysStats"; + default: return "(unknown)"; + } +} + diff --git a/aqhome/msg/msg_node.h b/aqhome/msg/msg_node.h index 2aaacac..3d1f3ee 100644 --- a/aqhome/msg/msg_node.h +++ b/aqhome/msg/msg_node.h @@ -92,7 +92,7 @@ AQHOME_API void AQH_NodeMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, AQHOME_API uint32_t AQH_NodeMsg_GetMsgGroup(uint8_t msgType); - +AQHOME_API const char *AQH_NodeMsg_MsgTypeToChar(uint8_t i); #endif diff --git a/aqhome/msg/msg_ping.c b/aqhome/msg/msg_ping.c index b7a5c02..4621e45 100644 --- a/aqhome/msg/msg_ping.c +++ b/aqhome/msg/msg_ping.c @@ -41,8 +41,6 @@ GWEN_MSG *AQH_PingMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code) *(ptr++)=0; *ptr=0; - GWEN_Msg_IncCurrentPos(msg, 4); - rv=AQH_NodeMsg_AddChecksum(msg); if (rv<0) { DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); diff --git a/aqhome/msgmanager.c b/aqhome/msgmanager.c index 14b6299..89e2257 100644 --- a/aqhome/msgmanager.c +++ b/aqhome/msgmanager.c @@ -28,6 +28,7 @@ #include "aqhome/ipc/msg_ipc.h" #include "aqhome/ipc/msg_ipc_ping.h" #include "aqhome/ipc/msg_ipc_setaccmsggrps.h" +#include "aqhome/ipc/msg_ipc_forward.h" #include #include @@ -56,6 +57,7 @@ static void _handleMsgDevice(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep, static void _handleIpcMsgPing(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg); static void _handleIpcMsgSetAccMsgGrps(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg); +static void _handleIpcMsgForward(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg); static AQH_NODE_INFO *_getOrCreateNodeAndUpdateUidAddr(GWEN_MSG_ENDPOINT_MGR *emgr, const GWEN_MSG *msg, uint32_t uid); @@ -207,8 +209,11 @@ void _handleNodeMsg(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep, const GW uint8_t msgType; DBG_INFO(AQH_LOGDOMAIN, - " - msg %d from %d to %d", - AQH_NodeMsg_GetMsgType(msg), AQH_NodeMsg_GetSourceAddress(msg), AQH_NodeMsg_GetDestAddress(msg)); + " - msg %d (%s) from %d to %d", + AQH_NodeMsg_GetMsgType(msg), + AQH_NodeMsg_MsgTypeToChar(AQH_NodeMsg_GetMsgType(msg)), + AQH_NodeMsg_GetSourceAddress(msg), + AQH_NodeMsg_GetDestAddress(msg)); AQH_MsgEndpointMgr_DistributeMsgFromNodeEndpoint(emgr, ep, msg, AQH_MSGMGR_ENDPOINTGROUP_NODE, NULL); @@ -242,6 +247,7 @@ void _handleIpcMsg(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep, const GWE switch(code) { case AQH_MSGTYPE_IPC_PING: _handleIpcMsgPing(emgr, ep, msg); break; case AQH_MSGTYPE_IPC_SETACCMSGGRPS: _handleIpcMsgSetAccMsgGrps(emgr, ep, msg); break; + case AQH_MSGTYPE_IPC_FORWARD: _handleIpcMsgForward(emgr, ep, msg); break; default: break; } } @@ -281,6 +287,20 @@ void _handleIpcMsgSetAccMsgGrps(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT * +void _handleIpcMsgForward(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg) +{ + GWEN_MSG *msgOut; + + DBG_ERROR(AQH_LOGDOMAIN, "Received IPC FORWARD message"); + msgOut=AQH_ForwardIpcMsg_GetCopyOfNodeMsg(msg); + if (msgOut) { + AQH_MsgEndpointMgr_DistributeMsgFromNodeEndpoint(emgr, ep, msgOut, AQH_MSGMGR_ENDPOINTGROUP_NODE, AQH_MSG_ENDPOINT_TTY_NAME); + GWEN_Msg_free(msgOut); + } +} + + + void _handleMsgValue2(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg) { AQH_MSG_MANAGER *xmgr;