aqhome: implemented new node messages, adapted to firmware changes.
This commit is contained in:
@@ -57,7 +57,10 @@
|
||||
msg_haveaddr.h
|
||||
msg_needaddr.h
|
||||
msg_sendstats.h
|
||||
msg_recvstats.h
|
||||
msg_value.h
|
||||
msg_value2.h
|
||||
msg_device.h
|
||||
</headers>
|
||||
|
||||
|
||||
@@ -85,7 +88,10 @@
|
||||
msg_haveaddr.c
|
||||
msg_needaddr.c
|
||||
msg_sendstats.c
|
||||
msg_recvstats.c
|
||||
msg_value.c
|
||||
msg_value2.c
|
||||
msg_device.c
|
||||
</sources>
|
||||
|
||||
|
||||
|
||||
@@ -15,13 +15,16 @@
|
||||
#include "aqhome/msg/endpoint_node.h"
|
||||
|
||||
#include "aqhome/msg/msg_value.h"
|
||||
#include "aqhome/msg/msg_value2.h"
|
||||
#include "aqhome/msg/msg_sendstats.h"
|
||||
#include "aqhome/msg/msg_recvstats.h"
|
||||
#include "aqhome/msg/msg_ping.h"
|
||||
#include "aqhome/msg/msg_pong.h"
|
||||
#include "aqhome/msg/msg_needaddr.h"
|
||||
#include "aqhome/msg/msg_claimaddr.h"
|
||||
#include "aqhome/msg/msg_haveaddr.h"
|
||||
#include "aqhome/msg/msg_denyaddr.h"
|
||||
#include "aqhome/msg/msg_device.h"
|
||||
|
||||
#include <gwenhywfar/list.h>
|
||||
#include <gwenhywfar/inherit.h>
|
||||
@@ -125,14 +128,17 @@ void _logMessage(GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg)
|
||||
case AQH_MSG_TYPE_PING: AQH_PingMsg_DumpToBuffer(msg, dbuf, "received"); break;
|
||||
case AQH_MSG_TYPE_PONG: AQH_PongMsg_DumpToBuffer(msg, dbuf, "received"); break;
|
||||
case AQH_MSG_TYPE_COMSENDSTATS: AQH_SendStatsMsg_DumpToBuffer(msg, dbuf, "received"); break;
|
||||
case AQH_MSG_TYPE_COMRECVSTATS: AQH_RecvStatsMsg_DumpToBuffer(msg, dbuf, "received"); break;
|
||||
case AQH_MSG_TYPE_TWIBUSMEMBER: AQH_NodeMsg_DumpToBuffer(msg, dbuf, "received"); break;
|
||||
case AQH_MSG_TYPE_DEBUG: AQH_NodeMsg_DumpToBuffer(msg, dbuf, "received"); break;
|
||||
case AQH_MSG_TYPE_VALUE: AQH_ValueMsg_DumpToBuffer(msg, dbuf, "received"); break;
|
||||
case AQH_MSG_TYPE_VALUE2: AQH_Value2Msg_DumpToBuffer(msg, dbuf, "received"); break;
|
||||
case AQH_MSG_TYPE_NEED_ADDRESS: AQH_NeedAddrMsg_DumpToBuffer(msg, dbuf, "received"); break;
|
||||
case AQH_MSG_TYPE_CLAIM_ADDRESS: AQH_ClaimAddrMsg_DumpToBuffer(msg, dbuf, "received"); break;
|
||||
case AQH_MSG_TYPE_HAVE_ADDRESS: AQH_HaveAddrMsg_DumpToBuffer(msg, dbuf, "received"); break;
|
||||
case AQH_MSG_TYPE_DENY_ADDRESS: AQH_DenyAddrMsg_DumpToBuffer(msg, dbuf, "received"); break;
|
||||
default: AQH_ValueMsg_DumpToBuffer(msg, dbuf, "received"); break;
|
||||
case AQH_MSG_TYPE_DEVICE: AQH_DeviceMsg_DumpToBuffer(msg, dbuf, "received"); break;
|
||||
default: AQH_NodeMsg_DumpToBuffer(msg, dbuf, "received"); break;
|
||||
}
|
||||
_writeToLogFile(xep->filename, GWEN_Buffer_GetStart(dbuf));
|
||||
GWEN_Buffer_free(dbuf);
|
||||
|
||||
139
aqhome/msg/msg_device.c
Normal file
139
aqhome/msg/msg_device.c
Normal file
@@ -0,0 +1,139 @@
|
||||
/****************************************************************************
|
||||
* 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_device.h"
|
||||
|
||||
#include <gwenhywfar/misc.h>
|
||||
#include <gwenhywfar/list.h>
|
||||
#include <gwenhywfar/error.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_DeviceMsg_GetUid(const GWEN_MSG *msg)
|
||||
{
|
||||
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_DEVICE_MINSIZE) {
|
||||
const uint8_t *ptr;
|
||||
|
||||
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_UID;
|
||||
return (uint32_t)(ptr[0])+(ptr[1]<<8)+(ptr[2]<<16)+(ptr[3]<<24);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint16_t AQH_DeviceMsg_GetFirmwareType(const GWEN_MSG *msg)
|
||||
{
|
||||
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_DEVICE_MINSIZE) {
|
||||
const uint8_t *ptr;
|
||||
|
||||
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWTYPE;
|
||||
return (uint16_t)((ptr[0])+(ptr[1]<<8));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t AQH_DeviceMsg_GetFirmwareLow(const GWEN_MSG *msg)
|
||||
{
|
||||
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_DEVICE_MINSIZE) {
|
||||
const uint8_t *ptr;
|
||||
|
||||
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWLOW;
|
||||
return ptr[0];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t AQH_DeviceMsg_GetFirmwareHigh(const GWEN_MSG *msg)
|
||||
{
|
||||
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_DEVICE_MINSIZE) {
|
||||
const uint8_t *ptr;
|
||||
|
||||
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWHIGH;
|
||||
return ptr[0];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t AQH_DeviceMsg_GetModuleMaskLow(const GWEN_MSG *msg)
|
||||
{
|
||||
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_DEVICE_MINSIZE) {
|
||||
const uint8_t *ptr;
|
||||
|
||||
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_MODULESLOW;
|
||||
return ptr[0];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t AQH_DeviceMsg_GetModuleMaskHigh(const GWEN_MSG *msg)
|
||||
{
|
||||
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_DEVICE_MINSIZE) {
|
||||
const uint8_t *ptr;
|
||||
|
||||
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_MODULESHIGH;
|
||||
return ptr[0];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_DeviceMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
|
||||
{
|
||||
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_DEVICE_MINSIZE) {
|
||||
uint16_t modules;
|
||||
|
||||
modules=(AQH_DeviceMsg_GetModuleMaskHigh(msg)<<8) | AQH_DeviceMsg_GetModuleMaskLow(msg);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: DEVICE %s (uid=0x%08x, fw type=%d, fw ver=%d.%d, mods=0x%04x",
|
||||
AQH_NodeMsg_GetSourceAddress(msg),
|
||||
AQH_NodeMsg_GetDestAddress(msg),
|
||||
sText,
|
||||
(unsigned int) AQH_DeviceMsg_GetUid(msg),
|
||||
AQH_DeviceMsg_GetFirmwareType(msg),
|
||||
AQH_DeviceMsg_GetFirmwareHigh(msg),
|
||||
AQH_DeviceMsg_GetFirmwareLow(msg),
|
||||
modules);
|
||||
if (modules) {
|
||||
GWEN_Buffer_AppendString(dbuf, "[");
|
||||
if (modules & AQH_MSG_DEVICE_MASK_TIMER)
|
||||
GWEN_Buffer_AppendString(dbuf, " TIMER");
|
||||
if (modules & AQH_MSG_DEVICE_MASK_COM)
|
||||
GWEN_Buffer_AppendString(dbuf, " COM");
|
||||
if (modules & AQH_MSG_DEVICE_MASK_LED)
|
||||
GWEN_Buffer_AppendString(dbuf, " LED");
|
||||
if (modules & AQH_MSG_DEVICE_MASK_TWIMASTER)
|
||||
GWEN_Buffer_AppendString(dbuf, " TWIMASTER");
|
||||
if (modules & AQH_MSG_DEVICE_MASK_LCD)
|
||||
GWEN_Buffer_AppendString(dbuf, " LCD");
|
||||
if (modules & AQH_MSG_DEVICE_MASK_SI7021)
|
||||
GWEN_Buffer_AppendString(dbuf, " SI7021");
|
||||
GWEN_Buffer_AppendString(dbuf, " ]");
|
||||
}
|
||||
GWEN_Buffer_AppendString(dbuf, ")\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
54
aqhome/msg/msg_device.h
Normal file
54
aqhome/msg/msg_device.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/****************************************************************************
|
||||
* 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_DEVICE_H
|
||||
#define AQH_MSG_DEVICE_H
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
#include <aqhome/msg/msg_node.h>
|
||||
|
||||
#include <gwenhywfar/msg.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
|
||||
|
||||
|
||||
#define AQH_MSG_OFFS_DEVICE_UID 0 /* 4 bytes */
|
||||
#define AQH_MSG_OFFS_DEVICE_FWTYPE 4 /* 2 bytes */
|
||||
#define AQH_MSG_OFFS_DEVICE_FWLOW 6 /* 1 byte */
|
||||
#define AQH_MSG_OFFS_DEVICE_FWHIGH 7 /* 1 byte */
|
||||
#define AQH_MSG_OFFS_DEVICE_MODULESLOW 8 /* 1 byte */
|
||||
#define AQH_MSG_OFFS_DEVICE_MODULESHIGH 9 /* 1 byte */
|
||||
|
||||
#define AQH_MSG_DEVICE_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_MODULESHIGH+1)
|
||||
|
||||
#define AQH_MSG_DEVICE_MASK_TIMER 0x02
|
||||
#define AQH_MSG_DEVICE_MASK_COM 0x04
|
||||
#define AQH_MSG_DEVICE_MASK_LED 0x08
|
||||
#define AQH_MSG_DEVICE_MASK_TWIMASTER 0x10
|
||||
#define AQH_MSG_DEVICE_MASK_LCD 0x20
|
||||
#define AQH_MSG_DEVICE_MASK_SI7021 0x40
|
||||
|
||||
|
||||
|
||||
AQHOME_API uint32_t AQH_DeviceMsg_GetUid(const GWEN_MSG *msg);
|
||||
AQHOME_API uint16_t AQH_DeviceMsg_GetFirmwareType(const GWEN_MSG *msg);
|
||||
AQHOME_API uint8_t AQH_DeviceMsg_GetFirmwareLow(const GWEN_MSG *msg);
|
||||
AQHOME_API uint8_t AQH_DeviceMsg_GetFirmwareHigh(const GWEN_MSG *msg);
|
||||
AQHOME_API uint8_t AQH_DeviceMsg_GetModuleMaskLow(const GWEN_MSG *msg);
|
||||
AQHOME_API uint8_t AQH_DeviceMsg_GetModuleMaskHigh(const GWEN_MSG *msg);
|
||||
|
||||
|
||||
AQHOME_API void AQH_DeviceMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -150,8 +150,10 @@ uint32_t AQH_NodeMsg_GetMsgGroup(uint8_t msgType)
|
||||
case AQH_MSG_TYPE_COMRECVSTATS:
|
||||
case AQH_MSG_TYPE_TWIBUSMEMBER:
|
||||
case AQH_MSG_TYPE_DEBUG:
|
||||
case AQH_MSG_TYPE_DEVICE:
|
||||
return AQH_MSG_TYPEGROUP_INFO;
|
||||
case AQH_MSG_TYPE_VALUE:
|
||||
case AQH_MSG_TYPE_VALUE2:
|
||||
return AQH_MSG_TYPEGROUP_VALUES;
|
||||
case AQH_MSG_TYPE_NEED_ADDRESS:
|
||||
case AQH_MSG_TYPE_HAVE_ADDRESS:
|
||||
|
||||
@@ -34,12 +34,16 @@
|
||||
#define AQH_MSG_TYPE_TWIBUSMEMBER 30
|
||||
#define AQH_MSG_TYPE_DEBUG 40
|
||||
#define AQH_MSG_TYPE_VALUE 50
|
||||
#define AQH_MSG_TYPE_VALUE2 51
|
||||
#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
|
||||
|
||||
#define AQH_MSG_TYPE_DEVICE 80
|
||||
|
||||
|
||||
/* internal msg types via NET interface */
|
||||
#define AQH_MSG_TYPE_NET_SET_ACCEPTED_MSGGROUPS 200
|
||||
|
||||
|
||||
104
aqhome/msg/msg_recvstats.c
Normal file
104
aqhome/msg/msg_recvstats.c
Normal file
@@ -0,0 +1,104 @@
|
||||
/****************************************************************************
|
||||
* 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_recvstats.h"
|
||||
|
||||
#include <gwenhywfar/misc.h>
|
||||
#include <gwenhywfar/list.h>
|
||||
#include <gwenhywfar/error.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
|
||||
|
||||
#define AQH_MSG_OFFS_RECVSTATS_UID 0
|
||||
#define AQH_MSG_OFFS_RECVSTATS_PACKETSIN 4
|
||||
#define AQH_MSG_OFFS_RECVSTATS_ERRORS 6
|
||||
#define AQH_MSG_OFFS_RECVSTATS_HANDLED 8
|
||||
|
||||
#define AQH_MSG_RECVSTATS_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_RECVSTATS_HANDLED+2)
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_RecvStatsMsg_GetUid(const GWEN_MSG *msg)
|
||||
{
|
||||
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_RECVSTATS_MINSIZE) {
|
||||
const uint8_t *ptr;
|
||||
|
||||
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_RECVSTATS_UID;
|
||||
return (uint32_t)(ptr[0])+(ptr[1]<<8)+(ptr[2]<<16)+(ptr[3]<<24);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint16_t AQH_RecvStatsMsg_GetPacketsIn(const GWEN_MSG *msg)
|
||||
{
|
||||
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_RECVSTATS_MINSIZE) {
|
||||
const uint8_t *ptr;
|
||||
|
||||
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_RECVSTATS_PACKETSIN;
|
||||
return (uint16_t)(ptr[0])+(ptr[1]<<8);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint16_t AQH_RecvStatsMsg_GetErrors(const GWEN_MSG *msg)
|
||||
{
|
||||
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_RECVSTATS_MINSIZE) {
|
||||
const uint8_t *ptr;
|
||||
|
||||
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_RECVSTATS_ERRORS;
|
||||
return (uint16_t)(ptr[0])+(ptr[1]<<8);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint16_t AQH_RecvStatsMsg_GetHandled(const GWEN_MSG *msg)
|
||||
{
|
||||
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_RECVSTATS_MINSIZE) {
|
||||
const uint8_t *ptr;
|
||||
|
||||
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_RECVSTATS_HANDLED;
|
||||
return (uint16_t)(ptr[0])+(ptr[1]<<8);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_RecvStatsMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
|
||||
{
|
||||
if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_COMRECVSTATS) &&
|
||||
(GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_RECVSTATS_MINSIZE)) {
|
||||
GWEN_Buffer_AppendArgs(dbuf,
|
||||
"0x%02x->0x%02x: RECVSTATS %s (uid=0x%08x, in=%d, errors=%d, handled=%d)\n",
|
||||
AQH_NodeMsg_GetSourceAddress(msg),
|
||||
AQH_NodeMsg_GetDestAddress(msg),
|
||||
sText,
|
||||
(unsigned int) AQH_RecvStatsMsg_GetUid(msg),
|
||||
AQH_RecvStatsMsg_GetPacketsIn(msg),
|
||||
AQH_RecvStatsMsg_GetErrors(msg),
|
||||
AQH_RecvStatsMsg_GetHandled(msg));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
34
aqhome/msg/msg_recvstats.h
Normal file
34
aqhome/msg/msg_recvstats.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/****************************************************************************
|
||||
* 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_RECVSTATS_H
|
||||
#define AQH_MSG_RECVSTATS_H
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
#include <aqhome/msg/msg_node.h>
|
||||
|
||||
#include <gwenhywfar/msg.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
|
||||
|
||||
|
||||
AQHOME_API uint32_t AQH_RecvStatsMsg_GetUid(const GWEN_MSG *msg);
|
||||
AQHOME_API uint16_t AQH_RecvStatsMsg_GetPacketsIn(const GWEN_MSG *msg);
|
||||
AQHOME_API uint16_t AQH_RecvStatsMsg_GetErrors(const GWEN_MSG *msg);
|
||||
AQHOME_API uint16_t AQH_RecvStatsMsg_GetHandled(const GWEN_MSG *msg);
|
||||
|
||||
|
||||
AQHOME_API void AQH_RecvStatsMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -18,14 +18,22 @@
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
|
||||
#define AQH_MSG_OFFS_SENDSTATS_UID 0
|
||||
#define AQH_MSG_OFFS_SENDSTATS_PACKETSOUT 4
|
||||
#define AQH_MSG_OFFS_SENDSTATS_COLLISIONS 6
|
||||
#define AQH_MSG_OFFS_SENDSTATS_ABORTED 8
|
||||
|
||||
uint32_t AQH_SendStatsMsg_GetTimestamp(const GWEN_MSG *msg)
|
||||
#define AQH_MSG_SENDSTATS_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_ABORTED+2)
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_SendStatsMsg_GetUid(const GWEN_MSG *msg)
|
||||
{
|
||||
if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_COMSENDSTATS) &&
|
||||
(GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_SENDSTATS_MINSIZE)) {
|
||||
const uint8_t *ptr;
|
||||
|
||||
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_TIMESTAMP;
|
||||
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_UID;
|
||||
return (uint32_t)(ptr[0])+(ptr[1]<<8)+(ptr[2]<<16)+(ptr[3]<<24);
|
||||
}
|
||||
return 0;
|
||||
@@ -80,11 +88,11 @@ void AQH_SendStatsMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const
|
||||
if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_COMSENDSTATS) &&
|
||||
(GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_SENDSTATS_MINSIZE)) {
|
||||
GWEN_Buffer_AppendArgs(dbuf,
|
||||
"0x%02x->0x%02x: SENDSTATS %s (timestamp=0x%08x, out=%d, collisions=%d, aborted=%d)\n",
|
||||
"0x%02x->0x%02x: SENDSTATS %s (uid=0x%08x, out=%d, collisions=%d, aborted=%d)\n",
|
||||
AQH_NodeMsg_GetSourceAddress(msg),
|
||||
AQH_NodeMsg_GetDestAddress(msg),
|
||||
sText,
|
||||
(unsigned int) AQH_SendStatsMsg_GetTimestamp(msg),
|
||||
(unsigned int) AQH_SendStatsMsg_GetUid(msg),
|
||||
AQH_SendStatsMsg_GetPacketsOut(msg),
|
||||
AQH_SendStatsMsg_GetCollisions(msg),
|
||||
AQH_SendStatsMsg_GetAborted(msg));
|
||||
|
||||
@@ -18,17 +18,7 @@
|
||||
|
||||
|
||||
|
||||
#define AQH_MSG_OFFS_SENDSTATS_TIMESTAMP 0
|
||||
#define AQH_MSG_OFFS_SENDSTATS_PACKETSOUT 4
|
||||
#define AQH_MSG_OFFS_SENDSTATS_COLLISIONS 6
|
||||
#define AQH_MSG_OFFS_SENDSTATS_ABORTED 8
|
||||
|
||||
#define AQH_MSG_SENDSTATS_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_ABORTED+2)
|
||||
|
||||
|
||||
|
||||
|
||||
AQHOME_API uint32_t AQH_SendStatsMsg_GetTimestamp(const GWEN_MSG *msg);
|
||||
AQHOME_API uint32_t AQH_SendStatsMsg_GetUid(const GWEN_MSG *msg);
|
||||
AQHOME_API uint16_t AQH_SendStatsMsg_GetPacketsOut(const GWEN_MSG *msg);
|
||||
AQHOME_API uint16_t AQH_SendStatsMsg_GetCollisions(const GWEN_MSG *msg);
|
||||
AQHOME_API uint16_t AQH_SendStatsMsg_GetAborted(const GWEN_MSG *msg);
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
50
aqhome/msg/msg_value2.h
Normal file
50
aqhome/msg/msg_value2.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/****************************************************************************
|
||||
* 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_VALUE2_H
|
||||
#define AQH_MSG_VALUE2_H
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
#include <aqhome/msg/msg_node.h>
|
||||
|
||||
#include <gwenhywfar/msg.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
|
||||
|
||||
|
||||
#define AQH_MSG_OFFS_VALUE2_TIMESTAMP 0
|
||||
#define AQH_MSG_OFFS_VALUE2_VALUEID 4
|
||||
#define AQH_MSG_OFFS_VALUE2_VALUETYPE 5
|
||||
#define AQH_MSG_OFFS_VALUE2_VALUE 6
|
||||
#define AQH_MSG_OFFS_VALUE2_DENOM 8
|
||||
|
||||
#define AQH_MSG_VALUE2_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE2_DENOM+2)
|
||||
|
||||
#define AQH_MSG_VALUE2_TYPE_TEMP 1
|
||||
#define AQH_MSG_VALUE2_TYPE_HUMIDITY 2
|
||||
|
||||
|
||||
|
||||
AQHOME_API uint32_t AQH_Value2Msg_GetUid(const GWEN_MSG *msg);
|
||||
AQHOME_API uint8_t AQH_Value2Msg_GetValueId(const GWEN_MSG *msg);
|
||||
AQHOME_API uint8_t AQH_Value2Msg_GetValueType(const GWEN_MSG *msg);
|
||||
AQHOME_API int16_t AQH_Value2Msg_GetValueNom(const GWEN_MSG *msg);
|
||||
AQHOME_API int16_t AQH_Value2Msg_GetValueDenom(const GWEN_MSG *msg);
|
||||
|
||||
AQHOME_API double AQH_Value2Msg_GetValue(const GWEN_MSG *msg);
|
||||
|
||||
|
||||
AQHOME_API void AQH_Value2Msg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user