153 lines
4.3 KiB
C
153 lines
4.3 KiB
C
/****************************************************************************
|
|
* 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 <config.h>
|
|
#endif
|
|
|
|
#include <aqhome/ipc/data/msg_data_devices.h>
|
|
#include <aqhome/ipc/data/ipc_data.h>
|
|
#include <aqhome/ipc/msg_ipc_tag16.h>
|
|
|
|
#include <gwenhywfar/msg.h>
|
|
#include <gwenhywfar/buffer.h>
|
|
|
|
#include <gwenhywfar/debug.h>
|
|
#include <gwenhywfar/msg_ipc.h>
|
|
#include <gwenhywfar/text.h>
|
|
#include <gwenhywfar/tag16.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
#define AQH_MSGDATA_DEVICES_MINSIZE GWEN_MSGIPC_OFFS_PAYLOAD
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
* forward declarations
|
|
* ------------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
* code
|
|
* ------------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
GWEN_MSG *AQH_DevicesDataIpcMsg_new(uint16_t code, uint32_t msgId, uint32_t refMsgId,
|
|
uint32_t flags, const AQH_DEVICE_LIST *deviceList)
|
|
{
|
|
GWEN_MSG *msg;
|
|
GWEN_BUFFER *buf;
|
|
int rv;
|
|
|
|
buf=GWEN_Buffer_new(0, 256, 0, 1);
|
|
GWEN_Tag16_WriteUint32TagToBuffer(AQH_MSGDATA_DEVICES_TAGS_FLAGS, flags, buf);
|
|
rv=AQH_DataIpc_WriteDeviceListAsTagsToBuffer(AQH_MSGDATA_DEVICES_TAGS_DEVICE, deviceList, buf);
|
|
if (rv<0) {
|
|
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
|
GWEN_Buffer_free(buf);
|
|
return NULL;
|
|
}
|
|
|
|
msg=AQH_Tag16IpcMsg_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId,
|
|
GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf));
|
|
GWEN_Buffer_free(buf);
|
|
return msg;
|
|
}
|
|
|
|
|
|
|
|
GWEN_MSG *AQH_DevicesDataIpcMsg_newForOneDevice(uint16_t code, uint32_t msgId, uint32_t refMsgId,
|
|
uint32_t flags, const AQH_DEVICE *device)
|
|
{
|
|
GWEN_MSG *msg;
|
|
GWEN_BUFFER *buf;
|
|
int rv;
|
|
|
|
buf=GWEN_Buffer_new(0, 256, 0, 1);
|
|
GWEN_Tag16_WriteUint32TagToBuffer(AQH_MSGDATA_DEVICES_TAGS_FLAGS, flags, buf);
|
|
rv=AQH_DataIpc_WriteDeviceAsTagToBuffer(AQH_MSGDATA_DEVICES_TAGS_DEVICE, device, buf);
|
|
if (rv<0) {
|
|
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
|
GWEN_Buffer_free(buf);
|
|
return NULL;
|
|
}
|
|
|
|
msg=AQH_Tag16IpcMsg_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId,
|
|
GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf));
|
|
GWEN_Buffer_free(buf);
|
|
return msg;
|
|
}
|
|
|
|
|
|
|
|
void AQH_DevicesDataIpcMsg_Parse(GWEN_MSG *msg, int doCopy)
|
|
{
|
|
AQH_Tag16IpcMsg_ExtendAndParse(msg, doCopy);
|
|
}
|
|
|
|
|
|
|
|
AQH_DEVICE_LIST *AQH_DevicesDataIpcMsg_ReadDeviceList(const GWEN_MSG *msg)
|
|
{
|
|
const GWEN_TAG16_LIST *tagList;
|
|
|
|
tagList=AQH_Tag16IpcMsg_GetTags(msg);
|
|
if (tagList) {
|
|
AQH_DEVICE_LIST *deviceList;
|
|
|
|
deviceList=AQH_DataIpc_ReadDevicesFromTagList(tagList, AQH_MSGDATA_DEVICES_TAGS_DEVICE);
|
|
if (deviceList==NULL) {
|
|
DBG_INFO(AQH_LOGDOMAIN, "No device list received");
|
|
}
|
|
return deviceList;
|
|
}
|
|
else {
|
|
DBG_INFO(AQH_LOGDOMAIN, "No tag16 list received");
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
AQH_DEVICE *AQH_DevicesDataIpcMsg_ReadFirstDevice(const GWEN_MSG *msg)
|
|
{
|
|
return AQH_DataIpc_ReadDeviceFromTagList(AQH_Tag16IpcMsg_GetTags(msg), AQH_MSGDATA_DEVICES_TAGS_DEVICE);
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t AQH_DevicesDataIpcMsg_GetFlags(const GWEN_MSG *msg)
|
|
{
|
|
return AQH_Tag16IpcMsg_GetTagDataAsUint32(msg, AQH_MSGDATA_DEVICES_TAGS_FLAGS, 0);
|
|
}
|
|
|
|
|
|
|
|
void AQH_DevicesDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
|
|
{
|
|
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGDATA_DEVICES_MINSIZE) {
|
|
GWEN_Buffer_AppendArgs(dbuf,
|
|
"DEVICES (code=%d, proto=%d, proto version=%d, flags=0x%08x)\n",
|
|
GWEN_IpcMsg_GetCode(msg),
|
|
GWEN_IpcMsg_GetProtoId(msg),
|
|
GWEN_IpcMsg_GetProtoVersion(msg),
|
|
(unsigned int)AQH_DevicesDataIpcMsg_GetFlags(msg));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|