From 6fe2f893f099fbe69673636092dd45fce26758f5 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 4 Feb 2023 16:02:40 +0100 Subject: [PATCH] aqhome: Added parser for needaddr message. --- aqhome/0BUILD | 2 ++ aqhome/libtest.c | 7 +++++- aqhome/msg_needaddr.c | 53 +++++++++++++++++++++++++++++++++++++++++++ aqhome/msg_needaddr.h | 36 +++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 aqhome/msg_needaddr.c create mode 100644 aqhome/msg_needaddr.h diff --git a/aqhome/0BUILD b/aqhome/0BUILD index b4d4d4f..9d30c55 100644 --- a/aqhome/0BUILD +++ b/aqhome/0BUILD @@ -52,6 +52,7 @@ msg_value.h msg_sendstats.h msg_ping.h + msg_needaddr.h @@ -62,6 +63,7 @@ msg_value.c msg_sendstats.c msg_ping.c + msg_needaddr.c diff --git a/aqhome/libtest.c b/aqhome/libtest.c index 4c71251..46a172f 100644 --- a/aqhome/libtest.c +++ b/aqhome/libtest.c @@ -7,6 +7,7 @@ #include "aqhome/msg_value.h" #include "aqhome/msg_sendstats.h" #include "aqhome/msg_ping.h" +#include "aqhome/msg_needaddr.h" #include #include @@ -152,8 +153,12 @@ void _packetReceived(AQH_SERIAL *sr, AQH_MSG *msg) AQH_MsgValue_DumpToBuffer(msg, dbuf, "received"); fprintf(stdout, "%s", GWEN_Buffer_GetStart(dbuf)); } + else if (msgType==AQH_MSG_TYPE_NEED_ADDRESS) { + AQH_MsgNeedAddr_DumpToBuffer(msg, dbuf, "received"); + fprintf(stdout, "%s", GWEN_Buffer_GetStart(dbuf)); + } else { - fprintf(stdout, " %s: Received (%s):\n", GWEN_Buffer_GetStart(dbuf), msgIsValid?"valid":"invalid"); + fprintf(stdout, " %s: Received (%d):\n", GWEN_Buffer_GetStart(dbuf), msgType); GWEN_Text_DumpString(ptr, len, 6); } GWEN_Buffer_free(dbuf); diff --git a/aqhome/msg_needaddr.c b/aqhome/msg_needaddr.c new file mode 100644 index 0000000..f564de8 --- /dev/null +++ b/aqhome/msg_needaddr.c @@ -0,0 +1,53 @@ +/**************************************************************************** + * 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_needaddr.h" + +#include +#include +#include +#include + + + +uint32_t AQH_MsgNeedAddr_GetUid(const AQH_MSG *msg) +{ + if ((AQH_Msg_GetMsgType(msg)==AQH_MSG_TYPE_NEED_ADDRESS) && + (AQH_Msg_GetBytesInBuffer(msg)>=AQH_MSG_NEEDADDR_MINSIZE)) { + const uint8_t *ptr; + + ptr=AQH_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_NEEDADDR_UID; + return (uint32_t)(ptr[0])+(ptr[1]<<8)+(ptr[2]<<16)+(ptr[3]<<24); + } + return 0; +} + + + +void AQH_MsgNeedAddr_DumpToBuffer(const AQH_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) +{ + if ((AQH_Msg_GetMsgType(msg)==AQH_MSG_TYPE_NEED_ADDRESS) && + (AQH_Msg_GetBytesInBuffer(msg)>=AQH_MSG_NEEDADDR_MINSIZE)) { + GWEN_Buffer_AppendArgs(dbuf, + "0x%02x->0x%02x: NEED_ADDRESS %s (uid=0x%08x)\n", + AQH_Msg_GetSourceAddress(msg), + AQH_Msg_GetDestAddress(msg), + sText, + (unsigned int) AQH_MsgNeedAddr_GetUid(msg)); + } +} + + + + + + diff --git a/aqhome/msg_needaddr.h b/aqhome/msg_needaddr.h new file mode 100644 index 0000000..dde4377 --- /dev/null +++ b/aqhome/msg_needaddr.h @@ -0,0 +1,36 @@ +/**************************************************************************** + * 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_NEEDADDR_H +#define AQH_MSG_NEEDADDR_H + + +#include + +#include "aqhome/msg.h" + +#include +#include + + + +#define AQH_MSG_OFFS_NEEDADDR_UID 0 + +#define AQH_MSG_NEEDADDR_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_NEEDADDR_UID+4) + + + + +AQHOME_API uint32_t AQH_MsgNeedAddr_GetUid(const AQH_MSG *msg); +AQHOME_API void AQH_MsgNeedAddr_DumpToBuffer(const AQH_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); + + +#endif + + +