122 lines
3.7 KiB
C
122 lines
3.7 KiB
C
/****************************************************************************
|
|
* 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>
|
|
|
|
|
|
#define AQH_MSG_OFFS_DEVICE_UID 0 /* 4 bytes */
|
|
#define AQH_MSG_OFFS_DEVICE_MANUF 4 /* 4 bytes */
|
|
#define AQH_MSG_OFFS_DEVICE_DEVTYPE 8 /* 2 bytes */
|
|
#define AQH_MSG_OFFS_DEVICE_DEVVERSION 10 /* 1 byte */
|
|
#define AQH_MSG_OFFS_DEVICE_DEVREVISION 11 /* 1 byte */
|
|
#define AQH_MSG_OFFS_DEVICE_FWVARIANT 12 /* 1 byte */
|
|
#define AQH_MSG_OFFS_DEVICE_FWVMAJOR 13 /* 1 byte */
|
|
#define AQH_MSG_OFFS_DEVICE_FWVMINOR 14 /* 1 byte */
|
|
#define AQH_MSG_OFFS_DEVICE_FWVPATCH 15 /* 1 byte */
|
|
|
|
|
|
#define AQH_MSG_DEVICE_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWVPATCH+1)
|
|
|
|
|
|
|
|
uint32_t AQH_DeviceMsg_GetUid(const GWEN_MSG *msg)
|
|
{
|
|
return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_UID, 0);
|
|
}
|
|
|
|
|
|
|
|
uint32_t AQH_DeviceMsg_GetManufacturer(const GWEN_MSG *msg)
|
|
{
|
|
return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_MANUF, 0);
|
|
}
|
|
|
|
|
|
|
|
uint16_t AQH_DeviceMsg_GetDeviceType(const GWEN_MSG *msg)
|
|
{
|
|
return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_DEVTYPE, 0);
|
|
}
|
|
|
|
|
|
|
|
uint8_t AQH_DeviceMsg_GetDeviceVersion(const GWEN_MSG *msg)
|
|
{
|
|
return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_DEVVERSION, 0);
|
|
}
|
|
|
|
|
|
|
|
uint8_t AQH_DeviceMsg_GetDeviceRevision(const GWEN_MSG *msg)
|
|
{
|
|
return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_DEVREVISION, 0);
|
|
}
|
|
|
|
|
|
|
|
uint8_t AQH_DeviceMsg_GetFirmwareVariant(const GWEN_MSG *msg)
|
|
{
|
|
return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWVARIANT, 0);
|
|
}
|
|
|
|
|
|
uint8_t AQH_DeviceMsg_GetFirmwareVersionMajor(const GWEN_MSG *msg)
|
|
{
|
|
return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWVMAJOR, 0);
|
|
}
|
|
|
|
|
|
|
|
uint8_t AQH_DeviceMsg_GetFirmwareVersionMinor(const GWEN_MSG *msg)
|
|
{
|
|
return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWVMINOR, 0);
|
|
}
|
|
|
|
|
|
|
|
uint8_t AQH_DeviceMsg_GetFirmwareVersionPatchlevel(const GWEN_MSG *msg)
|
|
{
|
|
return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWVPATCH, 0);
|
|
}
|
|
|
|
|
|
|
|
void AQH_DeviceMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
|
|
{
|
|
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_DEVICE_MINSIZE) {
|
|
GWEN_Buffer_AppendArgs(dbuf,
|
|
"0x%02x->0x%02x: DEVICE %s (uid=0x%08x, dev=%08x:%04x v%d.%d, fw=%d.%d.%d (%d))\n",
|
|
AQH_NodeMsg_GetSourceAddress(msg),
|
|
AQH_NodeMsg_GetDestAddress(msg),
|
|
sText,
|
|
(unsigned int) AQH_DeviceMsg_GetUid(msg),
|
|
AQH_DeviceMsg_GetManufacturer(msg),
|
|
AQH_DeviceMsg_GetDeviceType(msg),
|
|
AQH_DeviceMsg_GetDeviceVersion(msg),
|
|
AQH_DeviceMsg_GetDeviceRevision(msg),
|
|
AQH_DeviceMsg_GetFirmwareVersionMajor(msg),
|
|
AQH_DeviceMsg_GetFirmwareVersionMinor(msg),
|
|
AQH_DeviceMsg_GetFirmwareVersionPatchlevel(msg),
|
|
AQH_DeviceMsg_GetFirmwareVariant(msg));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|