aqhome: implemented new node messages, adapted to firmware changes.
This commit is contained in:
148
aqhome/msg/msg_value2.c
Normal file
148
aqhome/msg/msg_value2.c
Normal file
@@ -0,0 +1,148 @@
|
||||
/****************************************************************************
|
||||
* 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 <config.h>
|
||||
#endif
|
||||
|
||||
#include "aqhome/msg/msg_value2.h"
|
||||
|
||||
#include <gwenhywfar/misc.h>
|
||||
#include <gwenhywfar/list.h>
|
||||
#include <gwenhywfar/error.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_Value2Msg_GetUid(const GWEN_MSG *msg)
|
||||
{
|
||||
if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_VALUE2) &&
|
||||
(GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_VALUE2_MINSIZE)) {
|
||||
const uint8_t *ptr;
|
||||
|
||||
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE2_TIMESTAMP;
|
||||
return (uint32_t)(ptr[0])+(ptr[1]<<8)+(ptr[2]<<16)+(ptr[3]<<24);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t AQH_Value2Msg_GetValueId(const GWEN_MSG *msg)
|
||||
{
|
||||
if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_VALUE2) &&
|
||||
(GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_VALUE2_MINSIZE)) {
|
||||
const uint8_t *ptr;
|
||||
|
||||
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE2_VALUEID;
|
||||
return ptr[0];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t AQH_Value2Msg_GetValueType(const GWEN_MSG *msg)
|
||||
{
|
||||
if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_VALUE2) &&
|
||||
(GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_VALUE2_MINSIZE)) {
|
||||
const uint8_t *ptr;
|
||||
|
||||
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE2_VALUETYPE;
|
||||
return ptr[0];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int16_t AQH_Value2Msg_GetValueNom(const GWEN_MSG *msg)
|
||||
{
|
||||
if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_VALUE2) &&
|
||||
(GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_VALUE2_MINSIZE)) {
|
||||
const uint8_t *ptr;
|
||||
|
||||
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE2_VALUE;
|
||||
return (int16_t)((uint16_t)((ptr[0])+(ptr[1]<<8)));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int16_t AQH_Value2Msg_GetValueDenom(const GWEN_MSG *msg)
|
||||
{
|
||||
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_VALUE2_MINSIZE) {
|
||||
const uint8_t *ptr;
|
||||
|
||||
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE2_DENOM;
|
||||
return (int16_t)((uint16_t)((ptr[0])+(ptr[1]<<8)));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const char *AQH_Value2Msg_GetValueTypeName(const GWEN_MSG *msg)
|
||||
{
|
||||
uint8_t t;
|
||||
|
||||
t=AQH_Value2Msg_GetValueType(msg);
|
||||
switch(t) {
|
||||
case AQH_MSG_VALUE2_TYPE_TEMP: return "temperature";
|
||||
case AQH_MSG_VALUE2_TYPE_HUMIDITY: return "humidity";
|
||||
default: break;
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
|
||||
|
||||
double AQH_Value2Msg_GetValue(const GWEN_MSG *msg)
|
||||
{
|
||||
if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_VALUE2) &&
|
||||
(GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_VALUE2_MINSIZE)) {
|
||||
const uint8_t *ptr;
|
||||
double value;
|
||||
double denom;
|
||||
uint16_t intDenom;
|
||||
|
||||
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN;
|
||||
value=(double)((ptr[AQH_MSG_OFFS_VALUE2_VALUE])+(ptr[AQH_MSG_OFFS_VALUE2_VALUE+1]<<8));
|
||||
intDenom=(ptr[AQH_MSG_OFFS_VALUE2_DENOM])+(ptr[AQH_MSG_OFFS_VALUE2_DENOM+1]<<8);
|
||||
denom=(double)(intDenom);
|
||||
if (intDenom==0)
|
||||
denom=1.0;
|
||||
return (double)(value/denom);
|
||||
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Value2Msg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
|
||||
{
|
||||
if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_VALUE2) &&
|
||||
(GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_VALUE2_MINSIZE)) {
|
||||
GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: VALUE2 %s (uid=0x%08x, value_id=0x%02x type=%s value=%f)\n",
|
||||
AQH_NodeMsg_GetSourceAddress(msg),
|
||||
AQH_NodeMsg_GetDestAddress(msg),
|
||||
sText,
|
||||
(unsigned int) AQH_Value2Msg_GetUid(msg),
|
||||
AQH_Value2Msg_GetValueId(msg),
|
||||
AQH_Value2Msg_GetValueTypeName(msg),
|
||||
AQH_Value2Msg_GetValue(msg));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user