/**************************************************************************** * 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 #define AQH_MSGDATA_DATAPOINTS_OFFS_FLAGS 0 /* 4 bytes */ #define AQH_MSGDATA_DATAPOINTS_OFFS_NUMVALUES 4 /* 4 bytes */ #define AQH_MSGDATA_DATAPOINTS_OFFS_VALUEID 8 /* 8 byte */ #define AQH_MSGDATA_DATAPOINTS_OFFS_VALUENAME 16 /* 104 byte */ # define AQH_MSGDATA_DATAPOINTS_SIZE_VALUENAME 104 #define AQH_MSGDATA_DATAPOINTS_OFFS_VALUEUNITS 120 /* 16 byte */ # define AQH_MSGDATA_DATAPOINTS_SIZE_VALUEUNITS 16 #define AQH_MSGDATA_DATAPOINTS_OFFS_VALUES 136 #define AQH_MSGDATA_DATAPOINTS_PAYLOADSIZE (AQH_MSGDATA_DATAPOINTS_OFFS_VALUES) #define AQH_MSGDATA_DATAPOINTS_MINSIZE (GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_DATAPOINTS_PAYLOADSIZE) GWEN_MSG *AQH_DataPointsDataIpcMsg_new(uint16_t code, uint32_t msgId, uint32_t refMsgId, uint32_t flags, uint64_t valueId, const char *valueName, const char *units, const uint64_t *i64Ptr, int numOfDataPoints) { GWEN_MSG *msg; int i; msg=GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId, 0, NULL); GWEN_Msg_AddUint32(msg, flags); GWEN_Msg_AddUint32(msg, numOfDataPoints); GWEN_Msg_AddUint64(msg, valueId); GWEN_Msg_AddStringWithTrailingNull(msg, valueName, AQH_MSGDATA_DATAPOINTS_SIZE_VALUENAME, 0); GWEN_Msg_AddStringWithTrailingNull(msg, units, AQH_MSGDATA_DATAPOINTS_SIZE_VALUEUNITS, 0); for (i=0; i=AQH_MSGDATA_DATAPOINTS_MINSIZE) return (const char*) (GWEN_Msg_GetConstBuffer(msg)+GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_DATAPOINTS_OFFS_VALUENAME); return NULL; } const char *AQH_DataPointsDataIpcMsg_GetUnits(const GWEN_MSG *msg) { if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGDATA_DATAPOINTS_MINSIZE) return (const char*) (GWEN_Msg_GetConstBuffer(msg)+GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_DATAPOINTS_OFFS_VALUEUNITS); return NULL; } const uint64_t *AQH_DataPointsDataIpcMsg_GetDataPoints(const GWEN_MSG *msg) { if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGDATA_DATAPOINTS_MINSIZE) return (const uint64_t*) (GWEN_Msg_GetConstBuffer(msg)+GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_DATAPOINTS_OFFS_VALUES); return NULL; } int AQH_DataPointsDataIpcMsg_IsValid(const GWEN_MSG *msg) { int msgLen; int numValues; const uint8_t *ptr; msgLen=GWEN_Msg_GetBytesInBuffer(msg); if (msgLen=AQH_MSGDATA_DATAPOINTS_MINSIZE) { const char *valueName; valueName=AQH_DataPointsDataIpcMsg_GetValueName(msg); GWEN_Buffer_AppendArgs(dbuf, "DATAPOINTS %s (code=%d, proto=%d, proto version=%d, flags=0x%08x, valueName=%s, values=%d)\n", sText?sText:"", GWEN_IpcMsg_GetCode(msg), GWEN_IpcMsg_GetProtoId(msg), GWEN_IpcMsg_GetProtoVersion(msg), (unsigned int)AQH_DataPointsDataIpcMsg_GetFlags(msg), valueName?valueName:"", AQH_DataPointsDataIpcMsg_GetNumValues(msg)); } }