/**************************************************************************** * 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 #define AQH_MSGDATA_QWORDS_OFFS_FLAGS 0 /* 4 bytes */ #define AQH_MSGDATA_QWORDS_OFFS_NUMVALUES 4 /* 4 bytes */ #define AQH_MSGDATA_QWORDS_OFFS_VALUES 8 /* 8 byte */ #define AQH_MSGDATA_QWORDS_MINSIZE (GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_QWORDS_OFFS_VALUES) static void _writeQword(uint64_t i64, uint8_t *ptr); GWEN_MSG *AQH_QwordsIpcMsg_new(uint8_t protoId, uint8_t protoVer, uint16_t code, uint32_t flags, const uint64_t *i64Ptr, int count) { GWEN_MSG *msg; uint8_t *ptr; int payloadSize; int i; payloadSize=AQH_MSGDATA_QWORDS_OFFS_VALUES+(count*8); msg=GWEN_IpcMsg_new(protoId, protoVer, code, payloadSize, NULL); ptr=GWEN_Msg_GetBuffer(msg)+GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_QWORDS_OFFS_VALUES; *(ptr++)=flags & 0xff; *(ptr++)=(flags>>8) & 0xff; *(ptr++)=(flags>>16) & 0xff; *(ptr++)=(flags>>24) & 0xff; *(ptr++)=count & 0xff; *(ptr++)=(count>>8) & 0xff; *(ptr++)=(count>>16) & 0xff; *(ptr++)=(count>>24) & 0xff; for(i=0; i>8) & 0xff; *(ptr++)=(i64>>16) & 0xff; *(ptr++)=(i64>>24) & 0xff; *(ptr++)=(i64>>32) & 0xff; *(ptr++)=(i64>>40) & 0xff; *(ptr++)=(i64>>48) & 0xff; *(ptr++)=(i64>>56) & 0xff; } uint32_t AQH_QwordsIpcMsg_GetFlags(const GWEN_MSG *msg) { return GWEN_Msg_GetUint32At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_QWORDS_OFFS_FLAGS, 0); } uint32_t AQH_QwordsIpcMsg_GetNumValues(const GWEN_MSG *msg) { return GWEN_Msg_GetUint32At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_QWORDS_OFFS_NUMVALUES, 0); } uint64_t AQH_QwordsIpcMsg_GetValue(const GWEN_MSG *msg, int idx) { uint32_t pos; pos=AQH_MSGDATA_QWORDS_OFFS_VALUES+(idx*8); return GWEN_Msg_GetUint64At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+pos, 0); } int AQH_QwordsIpcMsg_IsValid(const GWEN_MSG *msg) { int msgLen; int numValues; msgLen=GWEN_Msg_GetBytesInBuffer(msg); if (msgLen=AQH_MSGDATA_QWORDS_MINSIZE) { GWEN_Buffer_AppendArgs(dbuf, "QWORDS (code=%d, proto=%d, proto version=%d, flags=0x%08x, values=%d)\n", GWEN_IpcMsg_GetCode(msg), GWEN_IpcMsg_GetProtoId(msg), GWEN_IpcMsg_GetProtoVersion(msg), (unsigned int)AQH_QwordsIpcMsg_GetFlags(msg), AQH_QwordsIpcMsg_GetNumValues(msg)); } }