diff --git a/apps/aqhome-nodes/db.c b/apps/aqhome-nodes/db.c index 7635d01..339737b 100644 --- a/apps/aqhome-nodes/db.c +++ b/apps/aqhome-nodes/db.c @@ -192,9 +192,7 @@ void _handleMsgDevice(AQHOMED *aqh, const GWEN_MSG *msg) uid=AQH_DeviceMsg_GetUid(msg); ni=_getOrCreateNodeAndUpdateUidAddr(aqh, msg, uid); if (ni) { - AQH_NodeInfo_SetFirmwareType(ni, AQH_DeviceMsg_GetFirmwareType(msg)); - AQH_NodeInfo_SetFirmwareVersion(ni, (AQH_DeviceMsg_GetFirmwareHigh(msg)<<8) | AQH_DeviceMsg_GetFirmwareLow(msg)); - AQH_NodeInfo_SetModules(ni, AQH_DeviceMsg_GetModuleMask(msg)); + // TODO _updateTimestampLastChange(ni); AQH_NodeDb_SetModified(aqh->nodeDb); } @@ -213,8 +211,14 @@ void _handleMsgFlashReady(AQHOMED *aqh, const GWEN_MSG *msg) uid=AQH_FlashReadyMsg_GetUid(msg); ni=_getOrCreateNodeAndUpdateUidAddr(aqh, msg, uid); if (ni) { - AQH_NodeInfo_SetFirmwareType(ni, AQH_FlashReadyMsg_GetFirmwareType(msg)); - AQH_NodeInfo_SetFirmwareVersion(ni, AQH_FlashReadyMsg_GetFirmwareVersion(msg)); + AQH_NodeInfo_SetManufacturer(ni, AQH_FlashReadyMsg_GetManufacturer(msg)); + AQH_NodeInfo_SetDeviceType(ni, AQH_FlashReadyMsg_GetDeviceType(msg)); + AQH_NodeInfo_SetDeviceVersion(ni, (AQH_FlashReadyMsg_GetDeviceVersion(msg)<<8)+AQH_FlashReadyMsg_GetDeviceRevision(msg)); + AQH_NodeInfo_SetFirmwareVersion(ni, + (AQH_FlashReadyMsg_GetFirmwareVariant(msg)<<24) | + (AQH_FlashReadyMsg_GetFirmwareVersionMajor(msg)<<16) | + (AQH_FlashReadyMsg_GetFirmwareVersionMinor(msg)<<8) | + AQH_FlashReadyMsg_GetFirmwareVersionPatchlevel(msg)); _updateTimestampLastChange(ni); AQH_NodeDb_SetModified(aqh->nodeDb); } diff --git a/apps/aqhome-nodes/loop_tty_broker.c b/apps/aqhome-nodes/loop_tty_broker.c index 7ed5f07..c5108b5 100644 --- a/apps/aqhome-nodes/loop_tty_broker.c +++ b/apps/aqhome-nodes/loop_tty_broker.c @@ -19,6 +19,7 @@ #include "aqhome/msg/endpoint_tty.h" #include "aqhome/msg/msg_node.h" #include "aqhome/msg/msg_value2.h" +#include "aqhome/msg/msg_value3.h" #include "aqhome/msg/msg_sendstats.h" #include "aqhome/msg/msg_recvstats.h" #include "aqhome/ipc/endpoint_ipc.h" @@ -48,6 +49,7 @@ */ static void _processValue2Message(AQHOMED *aqh, const GWEN_MSG *nodeMsg); +static void _processValue3Message(AQHOMED *aqh, const GWEN_MSG *nodeMsg); static void _processSendStatsMessage(AQHOMED *aqh, const GWEN_MSG *nodeMsg); static void _processRecvStatsMessage(AQHOMED *aqh, const GWEN_MSG *nodeMsg); static void _publishInt(AQHOMED *aqh, uint32_t uid, int valueId, const char *valueUnits, const char *valuePath, int v); @@ -70,6 +72,12 @@ void AqHomed_ForwardTtyMsgToBroker(AQHOMED *aqh, const GWEN_MSG *nodeMsg) case AQH_MSG_TYPE_VALUE2: _processValue2Message(aqh, nodeMsg); break; + case AQH_MSG_TYPE_VALUE_REPORT: + case AQH_MSG_TYPE_VALUE_SET: + case AQH_MSG_TYPE_VALUE_SET_ACK: + case AQH_MSG_TYPE_VALUE_SET_NACK: + _processValue3Message(aqh, nodeMsg); + break; case AQH_MSG_TYPE_COMSENDSTATS: _processSendStatsMessage(aqh, nodeMsg); break; @@ -96,6 +104,18 @@ void _processValue2Message(AQHOMED *aqh, const GWEN_MSG *nodeMsg) +void _processValue3Message(AQHOMED *aqh, const GWEN_MSG *nodeMsg) +{ + _publishDouble(aqh, + AQH_Value3Msg_GetUid(nodeMsg), + AQH_Value3Msg_GetValueId(nodeMsg), + AQH_Value3Msg_GetValueTypeUnits(nodeMsg), + AQH_Value3Msg_GetValueTypeName(nodeMsg), + AQH_Value3Msg_GetValue(nodeMsg)); +} + + + void _processSendStatsMessage(AQHOMED *aqh, const GWEN_MSG *nodeMsg) { uint16_t packetsOutInt; diff --git a/apps/aqhome-tool/nodes/getnodes.c b/apps/aqhome-tool/nodes/getnodes.c index 816aa95..1e21ec9 100644 --- a/apps/aqhome-tool/nodes/getnodes.c +++ b/apps/aqhome-tool/nodes/getnodes.c @@ -26,6 +26,7 @@ #include #include +#include #define I18S(msg) msg @@ -35,6 +36,8 @@ static int _doGetNodes(GWEN_DB_NODE *dbArgs); static int _sendGetDevices(GWEN_MSG_ENDPOINT *epTcp); +static void _printNodeFromMsg(const GWEN_MSG *msg); +static void _printUintAsTextOrHex(uint32_t u, int bits); @@ -159,31 +162,11 @@ int _doGetNodes(GWEN_DB_NODE *dbArgs) break; } else if (code==AQH_MSGTYPE_IPC_NODES_GETDEVICES_RSP) { - uint16_t fwVersion; - int64_t ts64; - GWEN_TIMESTAMP *ts; uint8_t flags; flags=AQH_GetDevicesResponseIpcMsg_GetFlags(msg); - fwVersion=AQH_GetDevicesResponseIpcMsg_GetFirmwareVersion(msg); - ts64=AQH_GetDevicesResponseIpcMsg_GetTimestamp(msg); - ts=GWEN_Timestamp_fromInt64(ts64); /* TODO: fix timestamp */ + _printNodeFromMsg(msg); - fprintf(stdout, "- node: %02x (uid=%04x, fw type=%02x, fw version=%d.%d, timeStamp: %016lx" - ", pkg out: %d, pkg in: %d, collisions: %d, busy: %d, crc: %d, io: %d)\n", - AQH_GetDevicesResponseIpcMsg_GetBusAddress(msg), - AQH_GetDevicesResponseIpcMsg_GetUid(msg), - AQH_GetDevicesResponseIpcMsg_GetFirmwareType(msg), - (fwVersion>>8) & 0xff, - fwVersion & 0xff, - (unsigned long int)ts64, - AQH_GetDevicesResponseIpcMsg_GetPkgOut(msg), - AQH_GetDevicesResponseIpcMsg_GetPkgIn(msg), - AQH_GetDevicesResponseIpcMsg_GetCollisions(msg), - AQH_GetDevicesResponseIpcMsg_GetBusy(msg), - AQH_GetDevicesResponseIpcMsg_GetCrcErrors(msg), - AQH_GetDevicesResponseIpcMsg_GetIoErrors(msg)); - GWEN_Timestamp_free(ts); GWEN_Msg_free(msg); if (flags & AQH_MSGIPC_GETDEVICES_RSP_FLAGS_LAST) { DBG_INFO(NULL, "Last"); @@ -202,6 +185,71 @@ int _doGetNodes(GWEN_DB_NODE *dbArgs) +void _printNodeFromMsg(const GWEN_MSG *msg) +{ + uint32_t u; + int64_t ts64; + GWEN_TIMESTAMP *ts; + + ts64=AQH_GetDevicesResponseIpcMsg_GetTimestamp(msg); + ts=GWEN_Timestamp_fromInt64(ts64); /* TODO: fix timestamp */ + + fprintf(stdout, "- node: addr=%d, uid=0x%08x, device=", + AQH_GetDevicesResponseIpcMsg_GetBusAddress(msg), + (unsigned int) AQH_GetDevicesResponseIpcMsg_GetUid(msg)); + u=AQH_GetDevicesResponseIpcMsg_GetManufacturer(msg); + _printUintAsTextOrHex(u, 32); + fprintf(stdout, ":"); + u=AQH_GetDevicesResponseIpcMsg_GetDeviceType(msg); + _printUintAsTextOrHex(u, 16); + u=AQH_GetDevicesResponseIpcMsg_GetDeviceVersion(msg); + fprintf(stdout, " v%d.%d", (u>>8) & 0xff, u & 0xff); + u=AQH_GetDevicesResponseIpcMsg_GetFirmwareVersion(msg); + fprintf(stdout, ", firmware=%d.%d.%d (%d), ", + (u>>16) & 0xff, (u>>8) & 0xff, u & 0xff, (u>>24) & 0xff); + if (ts) { + fprintf(stdout, "last seen %s, ", GWEN_Timestamp_GetString(ts)); + GWEN_Timestamp_free(ts); + } + fprintf(stdout, "pkg out: %d, pkg in: %d, collisions: %d, busy: %d, crc: %d, io: %d\n", + AQH_GetDevicesResponseIpcMsg_GetPkgOut(msg), + AQH_GetDevicesResponseIpcMsg_GetPkgIn(msg), + AQH_GetDevicesResponseIpcMsg_GetCollisions(msg), + AQH_GetDevicesResponseIpcMsg_GetBusy(msg), + AQH_GetDevicesResponseIpcMsg_GetCrcErrors(msg), + AQH_GetDevicesResponseIpcMsg_GetIoErrors(msg)); +} + + + +void _printUintAsTextOrHex(uint32_t u, int bits) +{ + int i; + uint8_t d; + int hasNonPrintable=0; + int hasPrintable=0; + + for (i=0; i>i) & 0xff); + if (d==0) { /* undecided */ + } + else if (isalnum(d)) + hasPrintable=1; + else + hasNonPrintable=1; + } + if (hasNonPrintable || !hasPrintable) + fprintf(stdout, "%08x", u); + else { + for (i=0; i>i) & 0xff); + + fprintf(stdout, "%c", d?d:' '); + } + } +} + + int _sendGetDevices(GWEN_MSG_ENDPOINT *epTcp) { GWEN_MSG *msgOut; diff --git a/aqhome/ipc/nodes/msg_ipc_getdevices_rsp.c b/aqhome/ipc/nodes/msg_ipc_getdevices_rsp.c index 8ae2f18..17db8bb 100644 --- a/aqhome/ipc/nodes/msg_ipc_getdevices_rsp.c +++ b/aqhome/ipc/nodes/msg_ipc_getdevices_rsp.c @@ -23,32 +23,35 @@ #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_FWTYPE 6 /* 2 bytes */ -#define AQH_MSGIPC_GETDEVICES_RSP_OFFS_FWVER 8 /* 2 bytes */ -#define AQH_MSGIPC_GETDEVICES_RSP_OFFS_MODULES 10 /* 2 bytes */ -#define AQH_MSGIPC_GETDEVICES_RSP_OFFS_LASTCHG 12 /* 8 bytes */ -#define AQH_MSGIPC_GETDEVICES_RSP_OFFS_PKGOUT 20 /* 2 bytes */ -#define AQH_MSGIPC_GETDEVICES_RSP_OFFS_PKGIN 22 /* 2 bytes */ -#define AQH_MSGIPC_GETDEVICES_RSP_OFFS_COLLISIONS 24 /* 2 bytes */ -#define AQH_MSGIPC_GETDEVICES_RSP_OFFS_BUSY 26 /* 2 bytes */ -#define AQH_MSGIPC_GETDEVICES_RSP_OFFS_CRC 28 /* 2 bytes */ -#define AQH_MSGIPC_GETDEVICES_RSP_OFFS_IO 30 /* 2 bytes */ +#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_LASTCHG+8) +static void _addU16t(uint8_t **pPtr, uint16_t i); +static void _addU32t(uint8_t **pPtr, uint32_t i); +static void _addU64t(uint8_t **pPtr, uint64_t i); + GWEN_MSG *AQH_GetDevicesResponseIpcMsg_new(uint16_t code, uint8_t flags, const AQH_NODE_INFO *ni) { GWEN_MSG *msg; uint8_t *ptr; - uint32_t u32; - uint64_t u64=0; const GWEN_TIMESTAMP *t; msg=GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_NODES_ID, AQH_IPC_PROTOCOL_NODES_VERSION, code, AQH_MSGIPC_GETDEVICES_RSP_MINSIZE, NULL); @@ -57,60 +60,21 @@ GWEN_MSG *AQH_GetDevicesResponseIpcMsg_new(uint16_t code, uint8_t flags, const A *(ptr++)=flags & 0xff; *(ptr++)=AQH_NodeInfo_GetBusAddress(ni); + _addU32t(&ptr, AQH_NodeInfo_GetUid(ni)); - u32=AQH_NodeInfo_GetUid(ni); - *(ptr++)=u32 & 0xff; - *(ptr++)=(u32>>8) & 0xff; - *(ptr++)=(u32>>16) & 0xff; - *(ptr++)=(u32>>24) & 0xff; - - u32=AQH_NodeInfo_GetFirmwareType(ni); - *(ptr++)=u32 & 0xff; - *(ptr++)=(u32>>8) & 0xff; - - u32=AQH_NodeInfo_GetFirmwareVersion(ni); - *(ptr++)=u32 & 0xff; - *(ptr++)=(u32>>8) & 0xff; - - u32=AQH_NodeInfo_GetModules(ni); - *(ptr++)=u32 & 0xff; - *(ptr++)=(u32>>8) & 0xff; - + _addU32t(&ptr, AQH_NodeInfo_GetManufacturer(ni)); + _addU16t(&ptr, AQH_NodeInfo_GetDeviceType(ni)); + _addU16t(&ptr, AQH_NodeInfo_GetDeviceVersion(ni)); + _addU32t(&ptr, AQH_NodeInfo_GetFirmwareVersion(ni)); t=AQH_NodeInfo_GetTimestampLastChange(ni); - if (t) - u64=(uint64_t)GWEN_Timestamp_toInt64(t); - *(ptr++)=u64 & 0xff; - *(ptr++)=(u64>>8) & 0xff; - *(ptr++)=(u64>>16) & 0xff; - *(ptr++)=(u64>>24) & 0xff; - *(ptr++)=(u64>>32) & 0xff; - *(ptr++)=(u64>>40) & 0xff; - *(ptr++)=(u64>>48) & 0xff; - *(ptr++)=(u64>>56) & 0xff; + _addU64t(&ptr, t?((uint64_t)GWEN_Timestamp_toInt64(t)):0L); - u32=AQH_NodeInfo_GetStatsPacketsOut(ni); - *(ptr++)=u32 & 0xff; - *(ptr++)=(u32>>8) & 0xff; - - u32=AQH_NodeInfo_GetStatsPacketsIn(ni); - *(ptr++)=u32 & 0xff; - *(ptr++)=(u32>>8) & 0xff; - - u32=AQH_NodeInfo_GetStatsCollisions(ni); - *(ptr++)=u32 & 0xff; - *(ptr++)=(u32>>8) & 0xff; - - u32=AQH_NodeInfo_GetStatsBusy(ni); - *(ptr++)=u32 & 0xff; - *(ptr++)=(u32>>8) & 0xff; - - u32=AQH_NodeInfo_GetStatsCrcErrors(ni); - *(ptr++)=u32 & 0xff; - *(ptr++)=(u32>>8) & 0xff; - - u32=AQH_NodeInfo_GetStatsIoErrors(ni); - *(ptr++)=u32 & 0xff; - *(ptr++)=(u32>>8) & 0xff; + _addU16t(&ptr, AQH_NodeInfo_GetStatsPacketsOut(ni)); + _addU16t(&ptr, AQH_NodeInfo_GetStatsPacketsIn(ni)); + _addU16t(&ptr, AQH_NodeInfo_GetStatsCollisions(ni)); + _addU16t(&ptr, AQH_NodeInfo_GetStatsBusy(ni)); + _addU16t(&ptr, AQH_NodeInfo_GetStatsCrcErrors(ni)); + _addU16t(&ptr, AQH_NodeInfo_GetStatsIoErrors(ni)); return msg; } @@ -138,23 +102,30 @@ uint32_t AQH_GetDevicesResponseIpcMsg_GetUid(const GWEN_MSG *msg) -uint16_t AQH_GetDevicesResponseIpcMsg_GetFirmwareType(const GWEN_MSG *msg) +uint32_t AQH_GetDevicesResponseIpcMsg_GetManufacturer(const GWEN_MSG *msg) { - return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_FWTYPE, 0); + return GWEN_Msg_GetUint32At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_MANUF, 0); } -uint16_t AQH_GetDevicesResponseIpcMsg_GetFirmwareVersion(const GWEN_MSG *msg) +uint16_t AQH_GetDevicesResponseIpcMsg_GetDeviceType(const GWEN_MSG *msg) { - return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_FWVER, 0); + return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_DEVTYPE, 0); } -uint16_t AQH_GetDevicesResponseIpcMsg_GetModules(const GWEN_MSG *msg) +uint16_t AQH_GetDevicesResponseIpcMsg_GetDeviceVersion(const GWEN_MSG *msg) { - return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_MODULES, 0); + 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); } @@ -216,7 +187,8 @@ void AQH_GetDevicesResponseIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER { if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGIPC_GETDEVICES_RSP_MINSIZE) { GWEN_Buffer_AppendArgs(dbuf, - "GET_DEVICES_RSP (code=%d, proto=%d, proto version=%d, uid=0x%08x, bus addr=0x%02x, flags=0x%02x)\n", + "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), @@ -228,6 +200,47 @@ void AQH_GetDevicesResponseIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER +void _addU16t(uint8_t **pPtr, uint16_t i) +{ + uint8_t *ptr=*pPtr; + + *(ptr++)=i & 0xff; + *(ptr++)=(i>>8) & 0xff; + *pPtr=ptr; +} + + + +void _addU32t(uint8_t **pPtr, uint32_t i) +{ + uint8_t *ptr=*pPtr; + + *(ptr++)=i & 0xff; + *(ptr++)=(i>>8) & 0xff; + *(ptr++)=(i>>16) & 0xff; + *(ptr++)=(i>>24) & 0xff; + *pPtr=ptr; +} + + + +void _addU64t(uint8_t **pPtr, uint64_t i) +{ + uint8_t *ptr=*pPtr; + + *(ptr++)=i & 0xff; + *(ptr++)=(i>>8) & 0xff; + *(ptr++)=(i>>16) & 0xff; + *(ptr++)=(i>>24) & 0xff; + *(ptr++)=(i>>32) & 0xff; + *(ptr++)=(i>>40) & 0xff; + *(ptr++)=(i>>48) & 0xff; + *(ptr++)=(i>>56) & 0xff; + *pPtr=ptr; +} + + + diff --git a/aqhome/ipc/nodes/msg_ipc_getdevices_rsp.h b/aqhome/ipc/nodes/msg_ipc_getdevices_rsp.h index b694d2e..1146e0b 100644 --- a/aqhome/ipc/nodes/msg_ipc_getdevices_rsp.h +++ b/aqhome/ipc/nodes/msg_ipc_getdevices_rsp.h @@ -27,9 +27,12 @@ AQHOME_API uint8_t AQH_GetDevicesResponseIpcMsg_GetFlags(const GWEN_MSG *msg); AQHOME_API uint8_t AQH_GetDevicesResponseIpcMsg_GetBusAddress(const GWEN_MSG *msg); AQHOME_API uint32_t AQH_GetDevicesResponseIpcMsg_GetUid(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_GetDevicesResponseIpcMsg_GetFirmwareType(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_GetDevicesResponseIpcMsg_GetFirmwareVersion(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_GetDevicesResponseIpcMsg_GetModules(const GWEN_MSG *msg); + +AQHOME_API uint32_t AQH_GetDevicesResponseIpcMsg_GetManufacturer(const GWEN_MSG *msg); +AQHOME_API uint16_t AQH_GetDevicesResponseIpcMsg_GetDeviceType(const GWEN_MSG *msg); +AQHOME_API uint16_t AQH_GetDevicesResponseIpcMsg_GetDeviceVersion(const GWEN_MSG *msg); +AQHOME_API uint32_t AQH_GetDevicesResponseIpcMsg_GetFirmwareVersion(const GWEN_MSG *msg); + AQHOME_API int64_t AQH_GetDevicesResponseIpcMsg_GetTimestamp(const GWEN_MSG *msg); AQHOME_API uint16_t AQH_GetDevicesResponseIpcMsg_GetPkgOut(const GWEN_MSG *msg); diff --git a/aqhome/msg/0BUILD b/aqhome/msg/0BUILD index 45a5296..5f4fce8 100644 --- a/aqhome/msg/0BUILD +++ b/aqhome/msg/0BUILD @@ -91,6 +91,7 @@ msg_sysstats.c msg_value.c msg_value2.c + msg_value3.c msg_device.c msg_flashready.c msg_flashstart.c diff --git a/aqhome/msg/msg_device.c b/aqhome/msg/msg_device.c index 39a7b3f..b87d63b 100644 --- a/aqhome/msg/msg_device.c +++ b/aqhome/msg/msg_device.c @@ -18,13 +18,18 @@ #include -#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_MODULES 8 /* 2 byte */ +#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_MODULES+2) + +#define AQH_MSG_DEVICE_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWVPATCH+1) @@ -35,30 +40,57 @@ uint32_t AQH_DeviceMsg_GetUid(const GWEN_MSG *msg) -uint16_t AQH_DeviceMsg_GetFirmwareType(const GWEN_MSG *msg) +uint32_t AQH_DeviceMsg_GetManufacturer(const GWEN_MSG *msg) { - return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWTYPE, 0); + return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_MANUF, 0); } -uint8_t AQH_DeviceMsg_GetFirmwareLow(const GWEN_MSG *msg) +uint16_t AQH_DeviceMsg_GetDeviceType(const GWEN_MSG *msg) { - return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWLOW, 0); + return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_DEVTYPE, 0); } -uint8_t AQH_DeviceMsg_GetFirmwareHigh(const GWEN_MSG *msg) +uint8_t AQH_DeviceMsg_GetDeviceVersion(const GWEN_MSG *msg) { - return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWHIGH, 0); + return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_DEVVERSION, 0); } -uint16_t AQH_DeviceMsg_GetModuleMask(const GWEN_MSG *msg) +uint8_t AQH_DeviceMsg_GetDeviceRevision(const GWEN_MSG *msg) { - return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_MODULES, 0); + 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); } @@ -66,36 +98,20 @@ uint16_t AQH_DeviceMsg_GetModuleMask(const GWEN_MSG *msg) 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_GetModuleMask(msg); - GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: DEVICE %s (uid=0x%08x, fw type=%d, fw ver=%d.%d, mods=0x%04x", + 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_GetFirmwareType(msg), - AQH_DeviceMsg_GetFirmwareHigh(msg), - AQH_DeviceMsg_GetFirmwareLow(msg), - modules); - if (modules) { - GWEN_Buffer_AppendString(dbuf, "["); - if (modules & AQH_MSG_MODULES_MASK_TIMER) - GWEN_Buffer_AppendString(dbuf, " TIMER"); - if (modules & AQH_MSG_MODULES_MASK_COM) - GWEN_Buffer_AppendString(dbuf, " COM"); - if (modules & AQH_MSG_MODULES_MASK_LED) - GWEN_Buffer_AppendString(dbuf, " LED"); - if (modules & AQH_MSG_MODULES_MASK_TWIMASTER) - GWEN_Buffer_AppendString(dbuf, " TWIMASTER"); - if (modules & AQH_MSG_MODULES_MASK_LCD) - GWEN_Buffer_AppendString(dbuf, " LCD"); - if (modules & AQH_MSG_MODULES_MASK_SI7021) - GWEN_Buffer_AppendString(dbuf, " SI7021"); - if (modules & AQH_MSG_MODULES_MASK_STATS) - GWEN_Buffer_AppendString(dbuf, " STATS"); - GWEN_Buffer_AppendString(dbuf, " ]"); - } + 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)); GWEN_Buffer_AppendString(dbuf, ")\n"); } } diff --git a/aqhome/msg/msg_device.h b/aqhome/msg/msg_device.h index 4b65855..47fb421 100644 --- a/aqhome/msg/msg_device.h +++ b/aqhome/msg/msg_device.h @@ -19,11 +19,14 @@ 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 uint16_t AQH_DeviceMsg_GetModuleMask(const GWEN_MSG *msg); - +AQHOME_API uint32_t AQH_DeviceMsg_GetManufacturer(const GWEN_MSG *msg); +AQHOME_API uint16_t AQH_DeviceMsg_GetDeviceType(const GWEN_MSG *msg); +AQHOME_API uint8_t AQH_DeviceMsg_GetDeviceVersion(const GWEN_MSG *msg); +AQHOME_API uint8_t AQH_DeviceMsg_GetDeviceRevision(const GWEN_MSG *msg); +AQHOME_API uint8_t AQH_DeviceMsg_GetFirmwareVariant(const GWEN_MSG *msg); +AQHOME_API uint8_t AQH_DeviceMsg_GetFirmwareVersionMajor(const GWEN_MSG *msg); +AQHOME_API uint8_t AQH_DeviceMsg_GetFirmwareVersionMinor(const GWEN_MSG *msg); +AQHOME_API uint8_t AQH_DeviceMsg_GetFirmwareVersionPatchlevel(const GWEN_MSG *msg); AQHOME_API void AQH_DeviceMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); diff --git a/aqhome/msg/msg_flashready.c b/aqhome/msg/msg_flashready.c index 5ce037d..51015cc 100644 --- a/aqhome/msg/msg_flashready.c +++ b/aqhome/msg/msg_flashready.c @@ -18,10 +18,16 @@ #include -#define AQH_MSG_OFFS_FLASHREADY_UID 0 /* 4 bytes */ -#define AQH_MSG_OFFS_FLASHREADY_FWTYPE 4 /* 2 bytes */ -#define AQH_MSG_OFFS_FLASHREADY_FWVER 6 /* 2 bytes */ -#define AQH_MSG_OFFS_FLASHREADY_PAGESIZE 8 /* 2 bytes */ +#define AQH_MSG_OFFS_FLASHREADY_UID 0 /* 4 bytes */ +#define AQH_MSG_OFFS_FLASHREADY_MANUF 4 /* 4 bytes */ +#define AQH_MSG_OFFS_FLASHREADY_DEVTYPE 8 /* 2 bytes */ +#define AQH_MSG_OFFS_FLASHREADY_DEVVERSION 10 /* 1 byte */ +#define AQH_MSG_OFFS_FLASHREADY_DEVREVISION 11 /* 1 byte */ +#define AQH_MSG_OFFS_FLASHREADY_FWVARIANT 12 /* 1 byte */ +#define AQH_MSG_OFFS_FLASHREADY_FWVMAJOR 13 /* 1 byte */ +#define AQH_MSG_OFFS_FLASHREADY_FWVMINOR 14 /* 1 byte */ +#define AQH_MSG_OFFS_FLASHREADY_FWVPATCH 15 /* 1 byte */ +#define AQH_MSG_OFFS_FLASHREADY_PAGESIZE 16 /* 2 bytes */ #define AQH_MSG_FLASHREADY_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_PAGESIZE+2) @@ -34,16 +40,57 @@ uint32_t AQH_FlashReadyMsg_GetUid(const GWEN_MSG *msg) -uint16_t AQH_FlashReadyMsg_GetFirmwareType(const GWEN_MSG *msg) +uint32_t AQH_FlashReadyMsg_GetManufacturer(const GWEN_MSG *msg) { - return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_FWTYPE, 0); + return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_MANUF, 0); } -uint16_t AQH_FlashReadyMsg_GetFirmwareVersion(const GWEN_MSG *msg) +uint16_t AQH_FlashReadyMsg_GetDeviceType(const GWEN_MSG *msg) { - return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_FWVER, 0); + return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_DEVTYPE, 0); +} + + + +uint8_t AQH_FlashReadyMsg_GetDeviceVersion(const GWEN_MSG *msg) +{ + return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_DEVVERSION, 0); +} + + + +uint8_t AQH_FlashReadyMsg_GetDeviceRevision(const GWEN_MSG *msg) +{ + return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_DEVREVISION, 0); +} + + + +uint8_t AQH_FlashReadyMsg_GetFirmwareVariant(const GWEN_MSG *msg) +{ + return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_FWVARIANT, 0); +} + + +uint8_t AQH_FlashReadyMsg_GetFirmwareVersionMajor(const GWEN_MSG *msg) +{ + return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_FWVMAJOR, 0); +} + + + +uint8_t AQH_FlashReadyMsg_GetFirmwareVersionMinor(const GWEN_MSG *msg) +{ + return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_FWVMINOR, 0); +} + + + +uint8_t AQH_FlashReadyMsg_GetFirmwareVersionPatchlevel(const GWEN_MSG *msg) +{ + return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_FWVPATCH, 0); } @@ -62,17 +109,21 @@ void AQH_FlashReadyMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, cons { if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_FLASH_READY) && (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_FLASHREADY_MINSIZE)) { - uint16_t fwVersion; - fwVersion=AQH_FlashReadyMsg_GetFirmwareVersion(msg); - GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: FLASHREADY %s (uid=0x%08x, fw type=%d, fw ver=%d.%d, pagesize=%d)\n", + GWEN_Buffer_AppendArgs(dbuf, + "0x%02x->0x%02x: FLASHREADY %s (uid=0x%08x, dev=%08x:%04x v%d.%d, fw=%d.%d.%d (%d) pagesize=%d)\n", AQH_NodeMsg_GetSourceAddress(msg), AQH_NodeMsg_GetDestAddress(msg), sText, (unsigned int) AQH_FlashReadyMsg_GetUid(msg), - AQH_FlashReadyMsg_GetFirmwareType(msg), - (fwVersion>>8) & 0xff, - fwVersion & 0xff, + AQH_FlashReadyMsg_GetManufacturer(msg), + AQH_FlashReadyMsg_GetDeviceType(msg), + AQH_FlashReadyMsg_GetDeviceVersion(msg), + AQH_FlashReadyMsg_GetDeviceRevision(msg), + AQH_FlashReadyMsg_GetFirmwareVersionMajor(msg), + AQH_FlashReadyMsg_GetFirmwareVersionMinor(msg), + AQH_FlashReadyMsg_GetFirmwareVersionPatchlevel(msg), + AQH_FlashReadyMsg_GetFirmwareVariant(msg), AQH_FlashReadyMsg_GetPagesize(msg)); } } diff --git a/aqhome/msg/msg_flashready.h b/aqhome/msg/msg_flashready.h index 95b5a06..170297b 100644 --- a/aqhome/msg/msg_flashready.h +++ b/aqhome/msg/msg_flashready.h @@ -18,8 +18,14 @@ AQHOME_API uint32_t AQH_FlashReadyMsg_GetUid(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_FlashReadyMsg_GetFirmwareType(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_FlashReadyMsg_GetFirmwareVersion(const GWEN_MSG *msg); +AQHOME_API uint32_t AQH_FlashReadyMsg_GetManufacturer(const GWEN_MSG *msg); +AQHOME_API uint16_t AQH_FlashReadyMsg_GetDeviceType(const GWEN_MSG *msg); +AQHOME_API uint8_t AQH_FlashReadyMsg_GetDeviceVersion(const GWEN_MSG *msg); +AQHOME_API uint8_t AQH_FlashReadyMsg_GetDeviceRevision(const GWEN_MSG *msg); +AQHOME_API uint8_t AQH_FlashReadyMsg_GetFirmwareVariant(const GWEN_MSG *msg); +AQHOME_API uint8_t AQH_FlashReadyMsg_GetFirmwareVersionMajor(const GWEN_MSG *msg); +AQHOME_API uint8_t AQH_FlashReadyMsg_GetFirmwareVersionMinor(const GWEN_MSG *msg); +AQHOME_API uint8_t AQH_FlashReadyMsg_GetFirmwareVersionPatchlevel(const GWEN_MSG *msg); AQHOME_API uint16_t AQH_FlashReadyMsg_GetPagesize(const GWEN_MSG *msg); AQHOME_API void AQH_FlashReadyMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); diff --git a/aqhome/msg/msg_node.h b/aqhome/msg/msg_node.h index ad62b54..85d377a 100644 --- a/aqhome/msg/msg_node.h +++ b/aqhome/msg/msg_node.h @@ -27,32 +27,37 @@ #define AQH_MSG_OFFS_ALL_DATA_BEGIN 4 -#define AQH_MSG_TYPE_PING 10 -#define AQH_MSG_TYPE_PONG 11 -#define AQH_MSG_TYPE_COMSENDSTATS 20 -#define AQH_MSG_TYPE_COMRECVSTATS 21 -#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_PING 10 +#define AQH_MSG_TYPE_PONG 11 +#define AQH_MSG_TYPE_COMSENDSTATS 20 +#define AQH_MSG_TYPE_COMRECVSTATS 21 +#define AQH_MSG_TYPE_TWIBUSMEMBER 30 +#define AQH_MSG_TYPE_DEBUG 40 +#define AQH_MSG_TYPE_VALUE 50 /* deprecated */ +#define AQH_MSG_TYPE_VALUE2 51 /* deprecated */ +#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_FLASH_START 70 -#define AQH_MSG_TYPE_FLASH_END 71 -#define AQH_MSG_TYPE_FLASH_READY 72 -#define AQH_MSG_TYPE_FLASH_DATA 73 -#define AQH_MSG_TYPE_FLASH_RSP 74 +#define AQH_MSG_TYPE_FLASH_START 70 +#define AQH_MSG_TYPE_FLASH_END 71 +#define AQH_MSG_TYPE_FLASH_READY 72 +#define AQH_MSG_TYPE_FLASH_DATA 73 +#define AQH_MSG_TYPE_FLASH_RSP 74 -#define AQH_MSG_TYPE_DEVICE 80 -#define AQH_MSG_TYPE_MEMSTATS 81 -#define AQH_MSG_TYPE_SYSSTATS 82 +#define AQH_MSG_TYPE_DEVICE 80 +#define AQH_MSG_TYPE_MEMSTATS 81 +#define AQH_MSG_TYPE_SYSSTATS 82 -#define AQH_MSG_TYPE_REBOOT_REQ 90 -#define AQH_MSG_TYPE_REBOOT_RSP 91 +#define AQH_MSG_TYPE_REBOOT_REQ 90 +#define AQH_MSG_TYPE_REBOOT_RSP 91 + +#define AQH_MSG_TYPE_VALUE_REPORT 100 +#define AQH_MSG_TYPE_VALUE_SET 101 +#define AQH_MSG_TYPE_VALUE_SET_ACK 102 +#define AQH_MSG_TYPE_VALUE_SET_NACK 103 /* internal msg types via NET interface */ diff --git a/aqhome/msg/msg_value3.c b/aqhome/msg/msg_value3.c new file mode 100644 index 0000000..7eeac65 --- /dev/null +++ b/aqhome/msg/msg_value3.c @@ -0,0 +1,170 @@ +/**************************************************************************** + * 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_value3.h" + +#include +#include +#include +#include + + + +#define AQH_MSG_OFFS_VALUE3_UID 0 /* 4 bytes */ +#define AQH_MSG_OFFS_VALUE3_MSGID 4 /* 2 bytes */ +#define AQH_MSG_OFFS_VALUE3_VALUEID 6 /* 1 byte */ +#define AQH_MSG_OFFS_VALUE3_VALUETYPE 7 /* 1 byte */ +#define AQH_MSG_OFFS_VALUE3_VALUE 8 /* 2 bytes */ +#define AQH_MSG_OFFS_VALUE3_DENOM 10 /* 2 bytes */ + +#define AQH_MSG_VALUE3_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE3_DENOM+2) + + + +uint32_t AQH_Value3Msg_GetUid(const GWEN_MSG *msg) +{ + return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE3_UID, 0); +} + + + +int16_t AQH_Value3Msg_GetMsgId(const GWEN_MSG *msg) +{ + return (int16_t) GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE3_MSGID, 0); +} + + + +uint8_t AQH_Value3Msg_GetValueId(const GWEN_MSG *msg) +{ + return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE3_VALUEID, 0); +} + + + +uint8_t AQH_Value3Msg_GetValueType(const GWEN_MSG *msg) +{ + return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE3_VALUETYPE, 0); +} + + + +int16_t AQH_Value3Msg_GetValueNom(const GWEN_MSG *msg) +{ + return (int16_t) GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE3_VALUE, 0); +} + + + +int16_t AQH_Value3Msg_GetValueDenom(const GWEN_MSG *msg) +{ + return (int16_t) GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE3_DENOM, 0); +} + + + +const char *AQH_Value3Msg_GetValueTypeName(const GWEN_MSG *msg) +{ + uint8_t t; + + t=AQH_Value3Msg_GetValueType(msg); + switch(t) { + case AQH_MSG_VALUE3_TYPE_TEMP: return "temperature"; + case AQH_MSG_VALUE3_TYPE_HUMIDITY: return "humidity"; + case AQH_MSG_VALUE3_TYPE_DOOR: return "door_window"; + default: break; + } + return "unknown"; +} + + + +const char *AQH_Value3Msg_GetValueAsWindowStateString(const GWEN_MSG *msg) +{ + switch(AQH_Value3Msg_GetValueNom(msg)) { + case 0: return "closed"; + case 128: return "tilted"; + case 255: return "open"; + default: break; + } + return "unknown"; +} + + + +const char *AQH_Value3Msg_GetValueTypeUnits(const GWEN_MSG *msg) +{ + uint8_t t; + + t=AQH_Value3Msg_GetValueType(msg); + switch(t) { + case AQH_MSG_VALUE3_TYPE_TEMP: return "Celsius"; + case AQH_MSG_VALUE3_TYPE_HUMIDITY: return "%"; + case AQH_MSG_VALUE3_TYPE_DOOR: return NULL; + default: break; + } + return NULL; +} + + + +double AQH_Value3Msg_GetValue(const GWEN_MSG *msg) +{ + if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_VALUE3_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_VALUE3_VALUE])+(ptr[AQH_MSG_OFFS_VALUE3_VALUE+1]<<8)); + intDenom=(ptr[AQH_MSG_OFFS_VALUE3_DENOM])+(ptr[AQH_MSG_OFFS_VALUE3_DENOM+1]<<8); + denom=(double)(intDenom); + if (intDenom==0) + denom=1.0; + return (double)(value/denom); + + } + return 0.0; +} + + + +void AQH_Value3Msg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) +{ + if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_VALUE3_MINSIZE) { + if (AQH_Value3Msg_GetValueType(msg)==AQH_MSG_VALUE3_TYPE_DOOR) + GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: VALUE3 %s (uid=0x%08x, msgId=%u, value_id=0x%02x type=%s value=%s)\n", + AQH_NodeMsg_GetSourceAddress(msg), + AQH_NodeMsg_GetDestAddress(msg), + sText, + (unsigned int) AQH_Value3Msg_GetUid(msg), + (unsigned int)AQH_Value3Msg_GetMsgId(msg), + AQH_Value3Msg_GetValueId(msg), + AQH_Value3Msg_GetValueTypeName(msg), + AQH_Value3Msg_GetValueAsWindowStateString(msg)); + else + GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: VALUE3 %s (uid=0x%08x, msgId=%u, value_id=0x%02x type=%s value=%f)\n", + AQH_NodeMsg_GetSourceAddress(msg), + AQH_NodeMsg_GetDestAddress(msg), + sText, + (unsigned int) AQH_Value3Msg_GetUid(msg), + (unsigned int)AQH_Value3Msg_GetMsgId(msg), + AQH_Value3Msg_GetValueId(msg), + AQH_Value3Msg_GetValueTypeName(msg), + AQH_Value3Msg_GetValue(msg)); + } +} + + + + diff --git a/aqhome/msg/msg_value3.h b/aqhome/msg/msg_value3.h new file mode 100644 index 0000000..7ee7c50 --- /dev/null +++ b/aqhome/msg/msg_value3.h @@ -0,0 +1,47 @@ +/**************************************************************************** + * This file is part of the project AqHome. + * AqHome (c) by 2024 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_VALUE3_H +#define AQH_MSG_VALUE3_H + + +#include +#include + +#include +#include + + + +#define AQH_MSG_VALUE3_TYPE_TEMP 1 +#define AQH_MSG_VALUE3_TYPE_HUMIDITY 2 +#define AQH_MSG_VALUE3_TYPE_DOOR 3 + + + +AQHOME_API uint32_t AQH_Value3Msg_GetUid(const GWEN_MSG *msg); +AQHOME_API int16_t AQH_Value3Msg_GetMsgId(const GWEN_MSG *msg); +AQHOME_API uint8_t AQH_Value3Msg_GetValueId(const GWEN_MSG *msg); +AQHOME_API uint8_t AQH_Value3Msg_GetValueType(const GWEN_MSG *msg); +AQHOME_API int16_t AQH_Value3Msg_GetValueNom(const GWEN_MSG *msg); +AQHOME_API int16_t AQH_Value3Msg_GetValueDenom(const GWEN_MSG *msg); + +AQHOME_API double AQH_Value3Msg_GetValue(const GWEN_MSG *msg); + +AQHOME_API const char *AQH_Value3Msg_GetValueAsWindowStateString(const GWEN_MSG *msg); +AQHOME_API const char *AQH_Value3Msg_GetValueTypeName(const GWEN_MSG *msg); +AQHOME_API const char *AQH_Value3Msg_GetValueTypeUnits(const GWEN_MSG *msg); + +AQHOME_API void AQH_Value3Msg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); + + + +#endif + + + diff --git a/aqhome/nodes/nodedb.c b/aqhome/nodes/nodedb.c index c8e51cf..3627d2f 100644 --- a/aqhome/nodes/nodedb.c +++ b/aqhome/nodes/nodedb.c @@ -116,29 +116,6 @@ AQH_NODE_INFO *AQH_NodeDb_GetNodeInfoByUid(AQH_NODE_DB *ndb, uint32_t uid) -AQH_NODE_INFO_LIST *AQH_NodeDb_GetNodeInfosByFirmwareType(AQH_NODE_DB *ndb, int t) -{ - AQH_NODE_INFO_LIST *resultList; - AQH_NODE_INFO *ni; - - resultList=AQH_NodeInfo_List_new(); - ni=AQH_NodeInfo_List_First(ndb->nodeList); - while(ni) { - if (t==0 || t==AQH_NodeInfo_GetFirmwareType(ni)) - AQH_NodeInfo_List_Add(AQH_NodeInfo_dup(ni), resultList); - ni=AQH_NodeInfo_List_Next(ni); - } - - if (AQH_NodeInfo_List_GetCount(resultList)<1) { - AQH_NodeInfo_List_free(resultList); - return NULL; - } - - return resultList; -} - - - void AQH_NodeDb_toDb(AQH_NODE_DB *ndb, GWEN_DB_NODE *dbDatabase) { if (ndb->nodeList) { diff --git a/aqhome/nodes/nodedb.h b/aqhome/nodes/nodedb.h index 0c52613..56fc488 100644 --- a/aqhome/nodes/nodedb.h +++ b/aqhome/nodes/nodedb.h @@ -29,7 +29,6 @@ AQHOME_API int AQH_NodeDb_AddNodeInfo(AQH_NODE_DB *ndb, AQH_NODE_INFO *ni); AQHOME_API AQH_NODE_INFO *AQH_NodeDb_GetNodeInfoByBusAddr(AQH_NODE_DB *ndb, uint8_t busAddr); AQHOME_API AQH_NODE_INFO *AQH_NodeDb_GetNodeInfoByUid(AQH_NODE_DB *ndb, uint32_t uid); -AQHOME_API AQH_NODE_INFO_LIST *AQH_NodeDb_GetNodeInfosByFirmwareType(AQH_NODE_DB *ndb, int t); AQHOME_API void AQH_NodeDb_toDb(AQH_NODE_DB *ndb, GWEN_DB_NODE *dbDatabase); AQHOME_API void AQH_NodeDb_fromDb(AQH_NODE_DB *ndb, GWEN_DB_NODE *dbDatabase); diff --git a/aqhome/nodes/nodeinfo.t2d b/aqhome/nodes/nodeinfo.t2d index 84db14b..dc669ff 100644 --- a/aqhome/nodes/nodeinfo.t2d +++ b/aqhome/nodes/nodeinfo.t2d @@ -32,86 +32,95 @@ - + 0 0 sortByMember with_getbymember public - + 0 0 public with_getbymember - + 0 0 public - + 0 0 public - - 0 - 0 - public - - - - - - + + 15-8: version, 7-0:revision 0 0 public - + + bits 31-24: variant, 23-16: vmajor, 15-8: vminor, 7-0:vpatchlevel 0 0 public - + + + 0 0 public - + 0 0 public - + 0 0 public - + 0 0 public - + + 0 + 0 + public + + + + + 0 + 0 + public + + + + 0 0 public