/**************************************************************************** * 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 #include #include #include #include #include #include #include #include #define AQH_MSGIPC_GETDEVICES_RSP_OFFS_FLAGS 0 /* 1 bytes */ #define AQH_MSGIPC_GETDEVICES_RSP_OFFS_BUSADDR 1 /* 1 bytes */ #define AQH_MSGIPC_GETDEVICES_RSP_OFFS_UID 2 /* 4 bytes */ #define AQH_MSGIPC_GETDEVICES_RSP_OFFS_MANUF 6 /* 4 bytes */ #define AQH_MSGIPC_GETDEVICES_RSP_OFFS_DEVTYPE 10 /* 2 bytes */ #define AQH_MSGIPC_GETDEVICES_RSP_OFFS_DEVVER 12 /* 2 bytes */ #define AQH_MSGIPC_GETDEVICES_RSP_OFFS_FWVER 14 /* 4 bytes */ #define AQH_MSGIPC_GETDEVICES_RSP_OFFS_LASTCHG 18 /* 8 bytes */ #define AQH_MSGIPC_GETDEVICES_RSP_OFFS_PKGOUT 26 /* 2 bytes */ #define AQH_MSGIPC_GETDEVICES_RSP_OFFS_PKGIN 28 /* 2 bytes */ #define AQH_MSGIPC_GETDEVICES_RSP_OFFS_COLLISIONS 30 /* 2 bytes */ #define AQH_MSGIPC_GETDEVICES_RSP_OFFS_BUSY 32 /* 2 bytes */ #define AQH_MSGIPC_GETDEVICES_RSP_OFFS_CRC 34 /* 2 bytes */ #define AQH_MSGIPC_GETDEVICES_RSP_OFFS_IO 36 /* 2 bytes */ #define AQH_MSGIPC_GETDEVICES_RSP_MINSIZE (GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_IO+2) GWEN_MSG *AQH_GetDevicesResponseIpcMsg_new(uint16_t code, uint32_t msgId, uint32_t refMsgId, uint8_t flags, const AQH_NODE_INFO *ni) { GWEN_MSG *msg; const GWEN_TIMESTAMP *t; msg=GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_NODES_ID, AQH_IPC_PROTOCOL_NODES_VERSION, code, msgId, refMsgId, 0, NULL); GWEN_Msg_AddUint8(msg, flags & 0xff); GWEN_Msg_AddUint8(msg, AQH_NodeInfo_GetBusAddress(ni)); GWEN_Msg_AddUint32(msg, AQH_NodeInfo_GetUid(ni)); GWEN_Msg_AddUint32(msg, AQH_NodeInfo_GetManufacturer(ni)); GWEN_Msg_AddUint16(msg, AQH_NodeInfo_GetDeviceType(ni)); GWEN_Msg_AddUint16(msg, AQH_NodeInfo_GetDeviceVersion(ni)); GWEN_Msg_AddUint32(msg, AQH_NodeInfo_GetFirmwareVersion(ni)); t=AQH_NodeInfo_GetTimestampLastChange(ni); GWEN_Msg_AddUint64(msg, t?((uint64_t)GWEN_Timestamp_toInt64(t)):0L); GWEN_Msg_AddUint16(msg, AQH_NodeInfo_GetStatsPacketsOut(ni)); GWEN_Msg_AddUint16(msg, AQH_NodeInfo_GetStatsPacketsIn(ni)); GWEN_Msg_AddUint16(msg, AQH_NodeInfo_GetStatsCollisions(ni)); GWEN_Msg_AddUint16(msg, AQH_NodeInfo_GetStatsBusy(ni)); GWEN_Msg_AddUint16(msg, AQH_NodeInfo_GetStatsCrcErrors(ni)); GWEN_Msg_AddUint16(msg, AQH_NodeInfo_GetStatsIoErrors(ni)); GWEN_IpcMsg_AdjustMsgSize(msg); return msg; } uint8_t AQH_GetDevicesResponseIpcMsg_GetFlags(const GWEN_MSG *msg) { return GWEN_Msg_GetUint8At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_FLAGS, 0); } uint8_t AQH_GetDevicesResponseIpcMsg_GetBusAddress(const GWEN_MSG *msg) { return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_BUSADDR, 0); } uint32_t AQH_GetDevicesResponseIpcMsg_GetUid(const GWEN_MSG *msg) { return GWEN_Msg_GetUint32At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_UID, 0); } uint32_t AQH_GetDevicesResponseIpcMsg_GetManufacturer(const GWEN_MSG *msg) { return GWEN_Msg_GetUint32At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_MANUF, 0); } uint16_t AQH_GetDevicesResponseIpcMsg_GetDeviceType(const GWEN_MSG *msg) { return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_DEVTYPE, 0); } uint16_t AQH_GetDevicesResponseIpcMsg_GetDeviceVersion(const GWEN_MSG *msg) { return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_DEVVER, 0); } uint32_t AQH_GetDevicesResponseIpcMsg_GetFirmwareVersion(const GWEN_MSG *msg) { return GWEN_Msg_GetUint32At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_FWVER, 0); } int64_t AQH_GetDevicesResponseIpcMsg_GetTimestamp(const GWEN_MSG *msg) { return GWEN_Msg_GetUint64At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_LASTCHG, 0); } uint16_t AQH_GetDevicesResponseIpcMsg_GetPkgOut(const GWEN_MSG *msg) { return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_PKGOUT, 0); } uint16_t AQH_GetDevicesResponseIpcMsg_GetPkgIn(const GWEN_MSG *msg) { return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_PKGIN, 0); } uint16_t AQH_GetDevicesResponseIpcMsg_GetCollisions(const GWEN_MSG *msg) { return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_COLLISIONS, 0); } uint16_t AQH_GetDevicesResponseIpcMsg_GetBusy(const GWEN_MSG *msg) { return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_BUSY, 0); } uint16_t AQH_GetDevicesResponseIpcMsg_GetCrcErrors(const GWEN_MSG *msg) { return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_CRC, 0); } uint16_t AQH_GetDevicesResponseIpcMsg_GetIoErrors(const GWEN_MSG *msg) { return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_IO, 0); } void AQH_GetDevicesResponseIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) { if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGIPC_GETDEVICES_RSP_MINSIZE) { GWEN_Buffer_AppendArgs(dbuf, "GET_DEVICES_RSP %s (code=%d, proto=%d, proto version=%d, uid=0x%08x, bus addr=0x%02x, flags=0x%02x)\n", sText, GWEN_IpcMsg_GetCode(msg), GWEN_IpcMsg_GetProtoId(msg), GWEN_IpcMsg_GetProtoVersion(msg), (unsigned int) AQH_GetDevicesResponseIpcMsg_GetUid(msg), AQH_GetDevicesResponseIpcMsg_GetBusAddress(msg), AQH_GetDevicesResponseIpcMsg_GetFlags(msg)); } }