From a624331166cae396cb8208bfc3b42c14c7ed4554 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sun, 22 Sep 2024 21:23:53 +0200 Subject: [PATCH] aqhome: add constructor for VALUE3 messages. --- aqhome/msg/msg_value3.c | 60 +++++++++++++++++++++++++++++++++++------ aqhome/msg/msg_value3.h | 10 ++++--- 2 files changed, 59 insertions(+), 11 deletions(-) diff --git a/aqhome/msg/msg_value3.c b/aqhome/msg/msg_value3.c index de0158f..0399426 100644 --- a/aqhome/msg/msg_value3.c +++ b/aqhome/msg/msg_value3.c @@ -30,6 +30,47 @@ +GWEN_MSG *AQH_Value3Msg_new(uint8_t srcAddr, uint8_t destAddr, + uint8_t code, uint16_t msgId, + uint8_t valueId, + uint16_t value, uint16_t denom) +{ + GWEN_MSG *msg; + uint8_t *ptr; + int rv; + + msg=AQH_NodeMsg_new(destAddr, srcAddr, code, AQH_MSG_VALUE3_MINSIZE, NULL); + ptr=GWEN_Msg_GetBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN; + + *(ptr++)=0; /* uid (empty) */ + *(ptr++)=0; + *(ptr++)=0; + *(ptr++)=0; + + *(ptr++)=msgId & 0xff; /* msgid */ + *(ptr++)=(msgId>>8) & 0xff; + + *(ptr++)=valueId; /* valueid */ + *(ptr++)=0; /* valuetype (empty) */ + + *(ptr++)=value & 0xff; /* value */ + *(ptr++)=(value>>8) & 0xff; + + *(ptr++)=denom & 0xff; /* denom */ + *(ptr++)=(denom>>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_Value3Msg_GetUid(const GWEN_MSG *msg) { return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE3_UID, 0); @@ -37,9 +78,9 @@ uint32_t AQH_Value3Msg_GetUid(const GWEN_MSG *msg) -int16_t AQH_Value3Msg_GetMsgId(const GWEN_MSG *msg) +uint16_t AQH_Value3Msg_GetMsgId(const GWEN_MSG *msg) { - return (int16_t) GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE3_MSGID, 0); + return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE3_MSGID, 0); } @@ -58,16 +99,16 @@ uint8_t AQH_Value3Msg_GetValueType(const GWEN_MSG *msg) -int16_t AQH_Value3Msg_GetValueNom(const GWEN_MSG *msg) +uint16_t AQH_Value3Msg_GetValueNom(const GWEN_MSG *msg) { - return (int16_t) GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE3_VALUE, 0); + return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE3_VALUE, 0); } -int16_t AQH_Value3Msg_GetValueDenom(const GWEN_MSG *msg) +uint16_t AQH_Value3Msg_GetValueDenom(const GWEN_MSG *msg) { - return (int16_t) GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE3_DENOM, 0); + return (uint16_t) GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE3_DENOM, 0); } @@ -164,7 +205,8 @@ void AQH_Value3Msg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const ch AQH_Value3Msg_GetValueTypeName(msg), AQH_Value3Msg_GetValueAsWindowStateString(msg)); else - GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: VALUE3(%s) %s (uid=0x%08x, msgId=%u, value_id=0x%02x type=%s value=%f)\n", + GWEN_Buffer_AppendArgs(dbuf, + "0x%02x->0x%02x: VALUE3(%s) %s (uid=0x%08x, msgId=%u, value_id=0x%02x type=%s value=%f [%04x/%04x])\n", AQH_NodeMsg_GetSourceAddress(msg), AQH_NodeMsg_GetDestAddress(msg), sCmd, @@ -173,7 +215,9 @@ void AQH_Value3Msg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const ch (unsigned int)AQH_Value3Msg_GetMsgId(msg), AQH_Value3Msg_GetValueId(msg), AQH_Value3Msg_GetValueTypeName(msg), - AQH_Value3Msg_GetValue(msg)); + AQH_Value3Msg_GetValue(msg), + AQH_Value3Msg_GetValueNom(msg), + AQH_Value3Msg_GetValueDenom(msg)); } } diff --git a/aqhome/msg/msg_value3.h b/aqhome/msg/msg_value3.h index 7ee7c50..f59f15a 100644 --- a/aqhome/msg/msg_value3.h +++ b/aqhome/msg/msg_value3.h @@ -23,13 +23,17 @@ #define AQH_MSG_VALUE3_TYPE_DOOR 3 +AQHOME_API GWEN_MSG *AQH_Value3Msg_new(uint8_t srcAddr, uint8_t destAddr, + uint8_t code, uint16_t msgId, + uint8_t valueId, + uint16_t value, uint16_t denom); AQHOME_API uint32_t AQH_Value3Msg_GetUid(const GWEN_MSG *msg); -AQHOME_API int16_t AQH_Value3Msg_GetMsgId(const GWEN_MSG *msg); +AQHOME_API uint16_t AQH_Value3Msg_GetMsgId(const GWEN_MSG *msg); AQHOME_API uint8_t AQH_Value3Msg_GetValueId(const GWEN_MSG *msg); AQHOME_API uint8_t AQH_Value3Msg_GetValueType(const GWEN_MSG *msg); -AQHOME_API int16_t AQH_Value3Msg_GetValueNom(const GWEN_MSG *msg); -AQHOME_API int16_t AQH_Value3Msg_GetValueDenom(const GWEN_MSG *msg); +AQHOME_API uint16_t AQH_Value3Msg_GetValueNom(const GWEN_MSG *msg); +AQHOME_API uint16_t AQH_Value3Msg_GetValueDenom(const GWEN_MSG *msg); AQHOME_API double AQH_Value3Msg_GetValue(const GWEN_MSG *msg);