/**************************************************************************** * 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 #endif #include "aqhome/msg/msg_device.h" #include #include #include #include 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"); } }