From fd2c4da9ce89a9e10434006c8defb75ee0b03307 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Wed, 19 Apr 2023 15:39:51 +0200 Subject: [PATCH] aqhome: added FLASH_READY msg. --- aqhome/msg/0BUILD | 2 + aqhome/msg/endpoint_log.c | 2 + aqhome/msg/msg_device.c | 14 +++--- aqhome/msg/msg_device.h | 10 ----- aqhome/msg/msg_flashready.c | 85 +++++++++++++++++++++++++++++++++++++ aqhome/msg/msg_flashready.h | 32 ++++++++++++++ aqhome/msg/msg_node.c | 2 + aqhome/msg/msg_node.h | 10 +++++ 8 files changed, 140 insertions(+), 17 deletions(-) create mode 100644 aqhome/msg/msg_flashready.c create mode 100644 aqhome/msg/msg_flashready.h diff --git a/aqhome/msg/0BUILD b/aqhome/msg/0BUILD index 7e11fd0..905c187 100644 --- a/aqhome/msg/0BUILD +++ b/aqhome/msg/0BUILD @@ -63,6 +63,7 @@ msg_value.h msg_value2.h msg_device.h + msg_flashready.h @@ -96,6 +97,7 @@ msg_value.c msg_value2.c msg_device.c + msg_flashready.c diff --git a/aqhome/msg/endpoint_log.c b/aqhome/msg/endpoint_log.c index 5fabd5d..62fd325 100644 --- a/aqhome/msg/endpoint_log.c +++ b/aqhome/msg/endpoint_log.c @@ -27,6 +27,7 @@ #include "aqhome/msg/msg_haveaddr.h" #include "aqhome/msg/msg_denyaddr.h" #include "aqhome/msg/msg_device.h" +#include "aqhome/msg/msg_flashready.h" #include #include @@ -139,6 +140,7 @@ void _logMessage(GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg) case AQH_MSG_TYPE_DEVICE: AQH_DeviceMsg_DumpToBuffer(msg, dbuf, "received"); break; 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; default: AQH_NodeMsg_DumpToBuffer(msg, dbuf, "received"); break; } } diff --git a/aqhome/msg/msg_device.c b/aqhome/msg/msg_device.c index 78ccf1a..39a7b3f 100644 --- a/aqhome/msg/msg_device.c +++ b/aqhome/msg/msg_device.c @@ -80,19 +80,19 @@ void AQH_DeviceMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const ch modules); if (modules) { GWEN_Buffer_AppendString(dbuf, "["); - if (modules & AQH_MSG_DEVICE_MASK_TIMER) + if (modules & AQH_MSG_MODULES_MASK_TIMER) GWEN_Buffer_AppendString(dbuf, " TIMER"); - if (modules & AQH_MSG_DEVICE_MASK_COM) + if (modules & AQH_MSG_MODULES_MASK_COM) GWEN_Buffer_AppendString(dbuf, " COM"); - if (modules & AQH_MSG_DEVICE_MASK_LED) + if (modules & AQH_MSG_MODULES_MASK_LED) GWEN_Buffer_AppendString(dbuf, " LED"); - if (modules & AQH_MSG_DEVICE_MASK_TWIMASTER) + if (modules & AQH_MSG_MODULES_MASK_TWIMASTER) GWEN_Buffer_AppendString(dbuf, " TWIMASTER"); - if (modules & AQH_MSG_DEVICE_MASK_LCD) + if (modules & AQH_MSG_MODULES_MASK_LCD) GWEN_Buffer_AppendString(dbuf, " LCD"); - if (modules & AQH_MSG_DEVICE_MASK_SI7021) + if (modules & AQH_MSG_MODULES_MASK_SI7021) GWEN_Buffer_AppendString(dbuf, " SI7021"); - if (modules & AQH_MSG_DEVICE_MASK_STATS) + if (modules & AQH_MSG_MODULES_MASK_STATS) GWEN_Buffer_AppendString(dbuf, " STATS"); GWEN_Buffer_AppendString(dbuf, " ]"); } diff --git a/aqhome/msg/msg_device.h b/aqhome/msg/msg_device.h index fad1aa5..4b65855 100644 --- a/aqhome/msg/msg_device.h +++ b/aqhome/msg/msg_device.h @@ -18,16 +18,6 @@ -#define AQH_MSG_DEVICE_MASK_TIMER 0x02 -#define AQH_MSG_DEVICE_MASK_COM 0x04 -#define AQH_MSG_DEVICE_MASK_LED 0x08 -#define AQH_MSG_DEVICE_MASK_TWIMASTER 0x10 -#define AQH_MSG_DEVICE_MASK_LCD 0x20 -#define AQH_MSG_DEVICE_MASK_SI7021 0x40 -#define AQH_MSG_DEVICE_MASK_STATS 0x80 - - - AQHOME_API uint32_t AQH_DeviceMsg_GetUid(const GWEN_MSG *msg); AQHOME_API uint16_t AQH_DeviceMsg_GetFirmwareType(const GWEN_MSG *msg); AQHOME_API uint8_t AQH_DeviceMsg_GetFirmwareLow(const GWEN_MSG *msg); diff --git a/aqhome/msg/msg_flashready.c b/aqhome/msg/msg_flashready.c new file mode 100644 index 0000000..5ce037d --- /dev/null +++ b/aqhome/msg/msg_flashready.c @@ -0,0 +1,85 @@ +/**************************************************************************** + * 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_flashready.h" + +#include +#include +#include +#include + + +#define AQH_MSG_OFFS_FLASHREADY_UID 0 /* 4 bytes */ +#define AQH_MSG_OFFS_FLASHREADY_FWTYPE 4 /* 2 bytes */ +#define AQH_MSG_OFFS_FLASHREADY_FWVER 6 /* 2 bytes */ +#define AQH_MSG_OFFS_FLASHREADY_PAGESIZE 8 /* 2 bytes */ + +#define AQH_MSG_FLASHREADY_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_PAGESIZE+2) + + + +uint32_t AQH_FlashReadyMsg_GetUid(const GWEN_MSG *msg) +{ + return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_UID, 0); +} + + + +uint16_t AQH_FlashReadyMsg_GetFirmwareType(const GWEN_MSG *msg) +{ + return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_FWTYPE, 0); +} + + + +uint16_t AQH_FlashReadyMsg_GetFirmwareVersion(const GWEN_MSG *msg) +{ + return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_FWVER, 0); +} + + + +uint16_t AQH_FlashReadyMsg_GetPagesize(const GWEN_MSG *msg) +{ + return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_PAGESIZE, 0); +} + + + + + + +void AQH_FlashReadyMsg_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_FLASHREADY_MINSIZE)) { + uint16_t fwVersion; + + fwVersion=AQH_FlashReadyMsg_GetFirmwareVersion(msg); + GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: FLASHREADY %s (uid=0x%08x, fw type=%d, fw ver=%d.%d, pagesize=%d)\n", + AQH_NodeMsg_GetSourceAddress(msg), + AQH_NodeMsg_GetDestAddress(msg), + sText, + (unsigned int) AQH_FlashReadyMsg_GetUid(msg), + AQH_FlashReadyMsg_GetFirmwareType(msg), + (fwVersion>>8) & 0xff, + fwVersion & 0xff, + AQH_FlashReadyMsg_GetPagesize(msg)); + } +} + + + + + + + diff --git a/aqhome/msg/msg_flashready.h b/aqhome/msg/msg_flashready.h new file mode 100644 index 0000000..d26c492 --- /dev/null +++ b/aqhome/msg/msg_flashready.h @@ -0,0 +1,32 @@ +/**************************************************************************** + * 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_FLASHREADY_H +#define AQH_MSG_FLASHREADY_H + + +#include +#include + +#include +#include + + +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 void AQH_FlashReadyMsg_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 8d5378d..cdfc732 100644 --- a/aqhome/msg/msg_node.c +++ b/aqhome/msg/msg_node.c @@ -14,6 +14,7 @@ #include "aqhome/msg/msg_node.h" #include +#include #define COM_USE_CRC8 1 @@ -177,6 +178,7 @@ void AQH_NodeMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char AQH_NodeMsg_GetDestAddress(msg), AQH_NodeMsg_GetMsgType(msg), sText); + GWEN_Text_DumpString2Buffer((const char*)GWEN_Msg_GetConstBuffer(msg), GWEN_Msg_GetBytesInBuffer(msg), dbuf, 34); } diff --git a/aqhome/msg/msg_node.h b/aqhome/msg/msg_node.h index c942d71..2aaacac 100644 --- a/aqhome/msg/msg_node.h +++ b/aqhome/msg/msg_node.h @@ -64,6 +64,16 @@ #define AQH_MSG_TYPEGROUP_ALL 0xffffffff +#define AQH_MSG_MODULES_MASK_TIMER 0x02 +#define AQH_MSG_MODULES_MASK_COM 0x04 +#define AQH_MSG_MODULES_MASK_LED 0x08 +#define AQH_MSG_MODULES_MASK_TWIMASTER 0x10 +#define AQH_MSG_MODULES_MASK_LCD 0x20 +#define AQH_MSG_MODULES_MASK_SI7021 0x40 +#define AQH_MSG_MODULES_MASK_STATS 0x80 + + + AQHOME_API GWEN_MSG *AQH_NodeMsg_new(uint8_t destAddr, uint8_t srcAddr, uint8_t code, uint8_t payloadLen, const uint8_t *payload);