From 9f45b70e3601e9cccba3a02f749e3321f9b08694 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sun, 5 Feb 2023 23:43:43 +0100 Subject: [PATCH] aqhome: added more parsers. --- aqhome/0BUILD | 8 +++++ aqhome/libtest.c | 24 +++++++++++++-- aqhome/msg.h | 4 +++ aqhome/msg_claimaddr.c | 68 ++++++++++++++++++++++++++++++++++++++++++ aqhome/msg_claimaddr.h | 38 +++++++++++++++++++++++ aqhome/msg_denyaddr.c | 68 ++++++++++++++++++++++++++++++++++++++++++ aqhome/msg_denyaddr.h | 38 +++++++++++++++++++++++ aqhome/msg_haveaddr.c | 68 ++++++++++++++++++++++++++++++++++++++++++ aqhome/msg_haveaddr.h | 38 +++++++++++++++++++++++ aqhome/msg_pong.c | 53 ++++++++++++++++++++++++++++++++ aqhome/msg_pong.h | 37 +++++++++++++++++++++++ 11 files changed, 442 insertions(+), 2 deletions(-) create mode 100644 aqhome/msg_claimaddr.c create mode 100644 aqhome/msg_claimaddr.h create mode 100644 aqhome/msg_denyaddr.c create mode 100644 aqhome/msg_denyaddr.h create mode 100644 aqhome/msg_haveaddr.c create mode 100644 aqhome/msg_haveaddr.h create mode 100644 aqhome/msg_pong.c create mode 100644 aqhome/msg_pong.h diff --git a/aqhome/0BUILD b/aqhome/0BUILD index 9d30c55..9477712 100644 --- a/aqhome/0BUILD +++ b/aqhome/0BUILD @@ -52,7 +52,11 @@ msg_value.h msg_sendstats.h msg_ping.h + msg_pong.h msg_needaddr.h + msg_haveaddr.h + msg_claimaddr.h + msg_denyaddr.h @@ -63,7 +67,11 @@ msg_value.c msg_sendstats.c msg_ping.c + msg_pong.c msg_needaddr.c + msg_haveaddr.c + msg_claimaddr.c + msg_denyaddr.c diff --git a/aqhome/libtest.c b/aqhome/libtest.c index 63ce2bf..fa00f46 100644 --- a/aqhome/libtest.c +++ b/aqhome/libtest.c @@ -7,7 +7,11 @@ #include "aqhome/msg_value.h" #include "aqhome/msg_sendstats.h" #include "aqhome/msg_ping.h" +#include "aqhome/msg_pong.h" #include "aqhome/msg_needaddr.h" +#include "aqhome/msg_claimaddr.h" +#include "aqhome/msg_haveaddr.h" +#include "aqhome/msg_denyaddr.h" #include #include @@ -129,6 +133,10 @@ void _packetReceived(AQH_SERIAL *sr, AQH_MSG *msg) AQH_MsgPing_DumpToBuffer(msg, dbuf, "received"); fprintf(stdout, "%s", GWEN_Buffer_GetStart(dbuf)); } + else if (msgType==AQH_MSG_TYPE_PONG) { + AQH_MsgPong_DumpToBuffer(msg, dbuf, "received"); + fprintf(stdout, "%s", GWEN_Buffer_GetStart(dbuf)); + } else if (msgType==AQH_MSG_TYPE_COMSENDSTATS) { /* CPRO_CMD_COMSENDSTATS */ AQH_MsgSendStats_DumpToBuffer(msg, dbuf, "received"); fprintf(stdout, "%s", GWEN_Buffer_GetStart(dbuf)); @@ -157,6 +165,18 @@ void _packetReceived(AQH_SERIAL *sr, AQH_MSG *msg) AQH_MsgNeedAddr_DumpToBuffer(msg, dbuf, "received"); fprintf(stdout, "%s", GWEN_Buffer_GetStart(dbuf)); } + else if (msgType==AQH_MSG_TYPE_CLAIM_ADDRESS) { + AQH_MsgClaimAddr_DumpToBuffer(msg, dbuf, "received"); + fprintf(stdout, "%s", GWEN_Buffer_GetStart(dbuf)); + } + else if (msgType==AQH_MSG_TYPE_HAVE_ADDRESS) { + AQH_MsgHaveAddr_DumpToBuffer(msg, dbuf, "received"); + fprintf(stdout, "%s", GWEN_Buffer_GetStart(dbuf)); + } + else if (msgType==AQH_MSG_TYPE_DENY_ADDRESS) { + AQH_MsgDenyAddr_DumpToBuffer(msg, dbuf, "received"); + fprintf(stdout, "%s", GWEN_Buffer_GetStart(dbuf)); + } else { fprintf(stdout, " %s: Received (%d):\n", GWEN_Buffer_GetStart(dbuf), msgType); GWEN_Text_DumpString(ptr, len, 6); @@ -186,7 +206,7 @@ AQH_MSG *createPingMsg(AQH_SERIAL *sr, uint8_t destAddr) AQH_Msg_free(msg); return NULL; } - rv=AQH_Msg_AddByte(msg, 10); /* ping */ + rv=AQH_Msg_AddByte(msg, AQH_MSG_TYPE_PING); /* ping */ if (rv<0) { fprintf(stderr, "ERROR3: %d\n", rv); AQH_Msg_free(msg); @@ -267,7 +287,7 @@ int testLoop() break; } t=time(NULL); - if (difftime(t, tLast)>10) { + if (difftime(t, tLast)>61) { AQH_MSG *msg; msg=createPingMsg(sr, 1); diff --git a/aqhome/msg.h b/aqhome/msg.h index e72de7a..b21d34a 100644 --- a/aqhome/msg.h +++ b/aqhome/msg.h @@ -35,6 +35,10 @@ #define AQH_MSG_TYPE_VALUE 50 #define AQH_MSG_TYPE_NEED_ADDRESS 60 #define AQH_MSG_TYPE_HAVE_ADDRESS 61 +#define AQH_MSG_TYPE_CLAIM_ADDRESS 62 +#define AQH_MSG_TYPE_DENY_ADDRESS 63 +#define AQH_MSG_TYPE_ADDRESS_RANGE 64 + diff --git a/aqhome/msg_claimaddr.c b/aqhome/msg_claimaddr.c new file mode 100644 index 0000000..9841270 --- /dev/null +++ b/aqhome/msg_claimaddr.c @@ -0,0 +1,68 @@ +/**************************************************************************** + * 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_claimaddr.h" + +#include +#include +#include +#include + + + +uint32_t AQH_MsgClaimAddr_GetUid(const AQH_MSG *msg) +{ + if ((AQH_Msg_GetMsgType(msg)==AQH_MSG_TYPE_CLAIM_ADDRESS) && + (AQH_Msg_GetBytesInBuffer(msg)>=AQH_MSG_CLAIMADDR_MINSIZE)) { + const uint8_t *ptr; + + ptr=AQH_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_CLAIMADDR_UID; + return (uint32_t)(ptr[0])+(ptr[1]<<8)+(ptr[2]<<16)+(ptr[3]<<24); + } + return 0; +} + + + +uint8_t AQH_MsgClaimAddr_GetAddress(const AQH_MSG *msg) +{ + if ((AQH_Msg_GetMsgType(msg)==AQH_MSG_TYPE_CLAIM_ADDRESS) && + (AQH_Msg_GetBytesInBuffer(msg)>=AQH_MSG_CLAIMADDR_MINSIZE)) { + const uint8_t *ptr; + + ptr=AQH_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_CLAIMADDR_ADDR; + return ptr[0]; + } + return 0; +} + + + +void AQH_MsgClaimAddr_DumpToBuffer(const AQH_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) +{ + if ((AQH_Msg_GetMsgType(msg)==AQH_MSG_TYPE_CLAIM_ADDRESS) && + (AQH_Msg_GetBytesInBuffer(msg)>=AQH_MSG_CLAIMADDR_MINSIZE)) { + GWEN_Buffer_AppendArgs(dbuf, + "0x%02x->0x%02x: CLAIM_ADDRESS %s (uid=0x%08x, address=0x%02x)\n", + AQH_Msg_GetSourceAddress(msg), + AQH_Msg_GetDestAddress(msg), + sText, + (unsigned int) AQH_MsgClaimAddr_GetUid(msg), + AQH_MsgClaimAddr_GetAddress(msg)); + } +} + + + + + + diff --git a/aqhome/msg_claimaddr.h b/aqhome/msg_claimaddr.h new file mode 100644 index 0000000..eb6bb25 --- /dev/null +++ b/aqhome/msg_claimaddr.h @@ -0,0 +1,38 @@ +/**************************************************************************** + * 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_CLAIMADDR_H +#define AQH_MSG_CLAIMADDR_H + + +#include + +#include "aqhome/msg.h" + +#include +#include + + + +#define AQH_MSG_OFFS_CLAIMADDR_UID 0 +#define AQH_MSG_OFFS_CLAIMADDR_ADDR 4 + +#define AQH_MSG_CLAIMADDR_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_CLAIMADDR_ADDR+1) + + + + +AQHOME_API uint32_t AQH_MsgClaimAddr_GetUid(const AQH_MSG *msg); +AQHOME_API uint8_t AQH_MsgClaimAddr_GetAddress(const AQH_MSG *msg); +AQHOME_API void AQH_MsgClaimAddr_DumpToBuffer(const AQH_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); + + +#endif + + + diff --git a/aqhome/msg_denyaddr.c b/aqhome/msg_denyaddr.c new file mode 100644 index 0000000..f494bcf --- /dev/null +++ b/aqhome/msg_denyaddr.c @@ -0,0 +1,68 @@ +/**************************************************************************** + * 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_denyaddr.h" + +#include +#include +#include +#include + + + +uint32_t AQH_MsgDenyAddr_GetUid(const AQH_MSG *msg) +{ + if ((AQH_Msg_GetMsgType(msg)==AQH_MSG_TYPE_DENY_ADDRESS) && + (AQH_Msg_GetBytesInBuffer(msg)>=AQH_MSG_DENYADDR_MINSIZE)) { + const uint8_t *ptr; + + ptr=AQH_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DENYADDR_UID; + return (uint32_t)(ptr[0])+(ptr[1]<<8)+(ptr[2]<<16)+(ptr[3]<<24); + } + return 0; +} + + + +uint8_t AQH_MsgDenyAddr_GetAddress(const AQH_MSG *msg) +{ + if ((AQH_Msg_GetMsgType(msg)==AQH_MSG_TYPE_DENY_ADDRESS) && + (AQH_Msg_GetBytesInBuffer(msg)>=AQH_MSG_DENYADDR_MINSIZE)) { + const uint8_t *ptr; + + ptr=AQH_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DENYADDR_ADDR; + return ptr[0]; + } + return 0; +} + + + +void AQH_MsgDenyAddr_DumpToBuffer(const AQH_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) +{ + if ((AQH_Msg_GetMsgType(msg)==AQH_MSG_TYPE_DENY_ADDRESS) && + (AQH_Msg_GetBytesInBuffer(msg)>=AQH_MSG_DENYADDR_MINSIZE)) { + GWEN_Buffer_AppendArgs(dbuf, + "0x%02x->0x%02x: DENY_ADDRESS %s (uid=0x%08x, address=0x%02x)\n", + AQH_Msg_GetSourceAddress(msg), + AQH_Msg_GetDestAddress(msg), + sText, + (unsigned int) AQH_MsgDenyAddr_GetUid(msg), + AQH_MsgDenyAddr_GetAddress(msg)); + } +} + + + + + + diff --git a/aqhome/msg_denyaddr.h b/aqhome/msg_denyaddr.h new file mode 100644 index 0000000..cb0893d --- /dev/null +++ b/aqhome/msg_denyaddr.h @@ -0,0 +1,38 @@ +/**************************************************************************** + * 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_DENYADDR_H +#define AQH_MSG_DENYADDR_H + + +#include + +#include "aqhome/msg.h" + +#include +#include + + + +#define AQH_MSG_OFFS_DENYADDR_UID 0 +#define AQH_MSG_OFFS_DENYADDR_ADDR 4 + +#define AQH_MSG_DENYADDR_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DENYADDR_ADDR+1) + + + + +AQHOME_API uint32_t AQH_MsgDenyAddr_GetUid(const AQH_MSG *msg); +AQHOME_API uint8_t AQH_MsgDenyAddr_GetAddress(const AQH_MSG *msg); +AQHOME_API void AQH_MsgDenyAddr_DumpToBuffer(const AQH_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); + + +#endif + + + diff --git a/aqhome/msg_haveaddr.c b/aqhome/msg_haveaddr.c new file mode 100644 index 0000000..c6653cc --- /dev/null +++ b/aqhome/msg_haveaddr.c @@ -0,0 +1,68 @@ +/**************************************************************************** + * 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_haveaddr.h" + +#include +#include +#include +#include + + + +uint32_t AQH_MsgHaveAddr_GetUid(const AQH_MSG *msg) +{ + if ((AQH_Msg_GetMsgType(msg)==AQH_MSG_TYPE_HAVE_ADDRESS) && + (AQH_Msg_GetBytesInBuffer(msg)>=AQH_MSG_HAVEADDR_MINSIZE)) { + const uint8_t *ptr; + + ptr=AQH_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_HAVEADDR_UID; + return (uint32_t)(ptr[0])+(ptr[1]<<8)+(ptr[2]<<16)+(ptr[3]<<24); + } + return 0; +} + + + +uint8_t AQH_MsgHaveAddr_GetAddress(const AQH_MSG *msg) +{ + if ((AQH_Msg_GetMsgType(msg)==AQH_MSG_TYPE_HAVE_ADDRESS) && + (AQH_Msg_GetBytesInBuffer(msg)>=AQH_MSG_HAVEADDR_MINSIZE)) { + const uint8_t *ptr; + + ptr=AQH_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_HAVEADDR_ADDR; + return ptr[0]; + } + return 0; +} + + + +void AQH_MsgHaveAddr_DumpToBuffer(const AQH_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) +{ + if ((AQH_Msg_GetMsgType(msg)==AQH_MSG_TYPE_HAVE_ADDRESS) && + (AQH_Msg_GetBytesInBuffer(msg)>=AQH_MSG_HAVEADDR_MINSIZE)) { + GWEN_Buffer_AppendArgs(dbuf, + "0x%02x->0x%02x: HAVE_ADDRESS %s (uid=0x%08x, address=0x%02x)\n", + AQH_Msg_GetSourceAddress(msg), + AQH_Msg_GetDestAddress(msg), + sText, + (unsigned int) AQH_MsgHaveAddr_GetUid(msg), + AQH_MsgHaveAddr_GetAddress(msg)); + } +} + + + + + + diff --git a/aqhome/msg_haveaddr.h b/aqhome/msg_haveaddr.h new file mode 100644 index 0000000..f1af20e --- /dev/null +++ b/aqhome/msg_haveaddr.h @@ -0,0 +1,38 @@ +/**************************************************************************** + * 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_HAVEADDR_H +#define AQH_MSG_HAVEADDR_H + + +#include + +#include "aqhome/msg.h" + +#include +#include + + + +#define AQH_MSG_OFFS_HAVEADDR_UID 0 +#define AQH_MSG_OFFS_HAVEADDR_ADDR 4 + +#define AQH_MSG_HAVEADDR_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_HAVEADDR_ADDR+1) + + + + +AQHOME_API uint32_t AQH_MsgHaveAddr_GetUid(const AQH_MSG *msg); +AQHOME_API uint8_t AQH_MsgHaveAddr_GetAddress(const AQH_MSG *msg); +AQHOME_API void AQH_MsgHaveAddr_DumpToBuffer(const AQH_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); + + +#endif + + + diff --git a/aqhome/msg_pong.c b/aqhome/msg_pong.c new file mode 100644 index 0000000..f171ae9 --- /dev/null +++ b/aqhome/msg_pong.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_pong.h" + +#include +#include +#include +#include + + + +uint32_t AQH_MsgPong_GetTimestamp(const AQH_MSG *msg) +{ + if ((AQH_Msg_GetMsgType(msg)==AQH_MSG_TYPE_PONG) && + (AQH_Msg_GetBytesInBuffer(msg)>=AQH_MSG_PONG_MINSIZE)) { + const uint8_t *ptr; + + ptr=AQH_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_PONG_TIMESTAMP; + return (uint32_t)(ptr[0])+(ptr[1]<<8)+(ptr[2]<<16)+(ptr[3]<<24); + } + return 0; +} + + + +void AQH_MsgPong_DumpToBuffer(const AQH_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) +{ + if ((AQH_Msg_GetMsgType(msg)==AQH_MSG_TYPE_PONG) && + (AQH_Msg_GetBytesInBuffer(msg)>=AQH_MSG_PONG_MINSIZE)) { + GWEN_Buffer_AppendArgs(dbuf, + "0x%02x->0x%02x: PONG %s (timestamp=0x%08x)\n", + AQH_Msg_GetSourceAddress(msg), + AQH_Msg_GetDestAddress(msg), + sText, + (unsigned int) AQH_MsgPong_GetTimestamp(msg)); + } +} + + + + + + diff --git a/aqhome/msg_pong.h b/aqhome/msg_pong.h new file mode 100644 index 0000000..a20916b --- /dev/null +++ b/aqhome/msg_pong.h @@ -0,0 +1,37 @@ +/**************************************************************************** + * 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_PONG_H +#define AQH_MSG_PONG_H + + +#include + +#include "aqhome/msg.h" + +#include +#include + + + +#define AQH_MSG_OFFS_PONG_TIMESTAMP 0 + +#define AQH_MSG_PONG_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_PONG_TIMESTAMP+4) + + + + +AQHOME_API uint32_t AQH_MsgPong_GetTimestamp(const AQH_MSG *msg); +AQHOME_API void AQH_MsgPong_DumpToBuffer(const AQH_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); + + + +#endif + + +