aqhome: add constructor for VALUE3 messages.

This commit is contained in:
Martin Preuss
2024-09-22 21:23:53 +02:00
parent 7e4977f472
commit a624331166
2 changed files with 59 additions and 11 deletions

View File

@@ -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));
}
}

View File

@@ -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);