added devices, added command getdevices.
This commit is contained in:
@@ -47,6 +47,7 @@
|
||||
<headers dist="true" install="$(pkgincludedir)/ipc" >
|
||||
ipc_data.h
|
||||
msg_data_values.h
|
||||
msg_data_devices.h
|
||||
msg_data_datapoints.h
|
||||
msg_data_connect.h
|
||||
msg_data_multidata.h
|
||||
@@ -63,6 +64,7 @@
|
||||
|
||||
ipc_data.c
|
||||
msg_data_values.c
|
||||
msg_data_devices.c
|
||||
msg_data_datapoints.c
|
||||
msg_data_connect.c
|
||||
msg_data_multidata.c
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
|
||||
#include <aqhome/ipc/data/ipc_data.h>
|
||||
#include <aqhome/ipc/msg_ipc_tag16.h>
|
||||
#include <aqhome/data/value.h>
|
||||
|
||||
#include <gwenhywfar/debug.h>
|
||||
#include <gwenhywfar/tag16.h>
|
||||
@@ -24,15 +23,28 @@
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define AQH_IPCDATA_VALUE_TAGS_ID 0x01
|
||||
#define AQH_IPCDATA_VALUE_TAGS_DRIVER 0x02
|
||||
#define AQH_IPCDATA_VALUE_TAGS_NAMEFORDRIVER 0x03
|
||||
#define AQH_IPCDATA_VALUE_TAGS_NAMEFORSYSTEM 0x04
|
||||
#define AQH_IPCDATA_VALUE_TAGS_TYPE 0x05
|
||||
#define AQH_IPCDATA_VALUE_TAGS_UNITS 0x06
|
||||
#define AQH_IPCDATA_VALUE_TAGS_TIMEOFCREATION 0x07
|
||||
#define AQH_IPCDATA_VALUE_TAGS_DEVFORDRIVER 0x08
|
||||
#define AQH_IPCDATA_VALUE_TAGS_DEVFORSYSTEM 0x09
|
||||
#define AQH_IPCDATA_VALUE_TAGS_ID 0x01
|
||||
#define AQH_IPCDATA_VALUE_TAGS_DRIVER 0x02
|
||||
#define AQH_IPCDATA_VALUE_TAGS_NAMEFORDRIVER 0x03
|
||||
#define AQH_IPCDATA_VALUE_TAGS_NAMEFORSYSTEM 0x04
|
||||
#define AQH_IPCDATA_VALUE_TAGS_TYPE 0x05
|
||||
#define AQH_IPCDATA_VALUE_TAGS_UNITS 0x06
|
||||
#define AQH_IPCDATA_VALUE_TAGS_TIMEOFCREATION 0x07
|
||||
#define AQH_IPCDATA_VALUE_TAGS_DEVFORDRIVER 0x08
|
||||
#define AQH_IPCDATA_VALUE_TAGS_DEVFORSYSTEM 0x09
|
||||
|
||||
#define AQH_IPCDATA_DEVICE_TAGS_ID 0x01
|
||||
#define AQH_IPCDATA_DEVICE_TAGS_DRIVER 0x02
|
||||
#define AQH_IPCDATA_DEVICE_TAGS_ROOMNAME 0x03
|
||||
#define AQH_IPCDATA_DEVICE_TAGS_NAMEFORDRIVER 0x04
|
||||
#define AQH_IPCDATA_DEVICE_TAGS_NAMEFORSYSTEM 0x05
|
||||
#define AQH_IPCDATA_DEVICE_TAGS_NAMEFORGUI 0x06
|
||||
#define AQH_IPCDATA_DEVICE_TAGS_LOCATION 0x07
|
||||
#define AQH_IPCDATA_DEVICE_TAGS_DESCRIPTION 0x08
|
||||
#define AQH_IPCDATA_DEVICE_TAGS_DEVTYPE 0x09
|
||||
#define AQH_IPCDATA_DEVICE_TAGS_MANUFACTURER 0x0a
|
||||
#define AQH_IPCDATA_DEVICE_TAGS_TIMEOFCREATION 0x0b
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -43,6 +55,8 @@
|
||||
|
||||
static void _writeValueFieldsAsTagsToBuffer(const AQH_VALUE *value, GWEN_BUFFER *buf);
|
||||
static AQH_VALUE *_readValueFromTag(const uint8_t *ptr, uint32_t len);
|
||||
static void _writeDeviceFieldsAsTagsToBuffer(const AQH_DEVICE *device, GWEN_BUFFER *buf);
|
||||
static AQH_DEVICE *_readDeviceFromTag(const uint8_t *ptr, uint32_t len);
|
||||
|
||||
|
||||
|
||||
@@ -101,6 +115,54 @@ int AQH_DataIpc_WriteValueAsTagToBuffer(unsigned int tagType, const AQH_VALUE *v
|
||||
|
||||
|
||||
|
||||
int AQH_DataIpc_WriteDeviceListAsTagsToBuffer(unsigned int tagType, const AQH_DEVICE_LIST *deviceList, GWEN_BUFFER *buf)
|
||||
{
|
||||
if (deviceList) {
|
||||
const AQH_DEVICE *device;
|
||||
|
||||
device=AQH_Device_List_First(deviceList);
|
||||
while(device) {
|
||||
int rv;
|
||||
|
||||
rv=AQH_DataIpc_WriteDeviceAsTagToBuffer(tagType, device, buf);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
GWEN_Buffer_free(buf);
|
||||
return rv;
|
||||
}
|
||||
|
||||
device=AQH_Device_List_Next(device);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_DataIpc_WriteDeviceAsTagToBuffer(unsigned int tagType, const AQH_DEVICE *device, GWEN_BUFFER *buf)
|
||||
{
|
||||
int startPos;
|
||||
int rv;
|
||||
|
||||
startPos=GWEN_Tag16_StartTagInBuffer(tagType, buf);
|
||||
if (startPos<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", startPos);
|
||||
return startPos;
|
||||
}
|
||||
|
||||
_writeDeviceFieldsAsTagsToBuffer(device, buf);
|
||||
|
||||
rv=GWEN_Tag16_EndTagInBuffer(startPos, buf);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _writeValueFieldsAsTagsToBuffer(const AQH_VALUE *value, GWEN_BUFFER *buf)
|
||||
{
|
||||
const char *s;
|
||||
@@ -185,6 +247,50 @@ AQH_VALUE *AQH_DataIpc_ReadValueFromTagList(const GWEN_TAG16_LIST *tagList, unsi
|
||||
|
||||
|
||||
|
||||
AQH_DEVICE_LIST *AQH_DataIpc_ReadDevicesFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType)
|
||||
{
|
||||
AQH_DEVICE_LIST *deviceList;
|
||||
const GWEN_TAG16 *tag;
|
||||
|
||||
deviceList=AQH_Device_List_new();
|
||||
tag=GWEN_Tag16_List_First(tagList);
|
||||
while(tag) {
|
||||
unsigned int tagType;
|
||||
AQH_DEVICE *device;
|
||||
|
||||
tagType=GWEN_Tag16_GetTagType(tag);
|
||||
if (tagType==wantedTagType) {
|
||||
device=_readDeviceFromTag((const uint8_t*) GWEN_Tag16_GetTagData(tag), (uint32_t) GWEN_Tag16_GetTagLength(tag));
|
||||
if (device)
|
||||
AQH_Device_List_Add(device, deviceList);
|
||||
}
|
||||
|
||||
tag=GWEN_Tag16_List_Next(tag);
|
||||
}
|
||||
|
||||
if (AQH_Device_List_GetCount(deviceList)<1) {
|
||||
AQH_Device_List_free(deviceList);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return deviceList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_DEVICE *AQH_DataIpc_ReadDeviceFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType)
|
||||
{
|
||||
if (tagList) {
|
||||
const GWEN_TAG16 *tag;
|
||||
|
||||
tag=GWEN_Tag16_List_FindFirstByTagType(tagList, wantedTagType);
|
||||
return tag?_readDeviceFromTag((const uint8_t*) GWEN_Tag16_GetTagData(tag), (uint32_t) GWEN_Tag16_GetTagLength(tag)):NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_VALUE *_readValueFromTag(const uint8_t *ptr, uint32_t len)
|
||||
{
|
||||
GWEN_TAG16_LIST *tagList;
|
||||
@@ -256,3 +362,134 @@ AQH_VALUE *_readValueFromTag(const uint8_t *ptr, uint32_t len)
|
||||
|
||||
|
||||
|
||||
void _writeDeviceFieldsAsTagsToBuffer(const AQH_DEVICE *device, GWEN_BUFFER *buf)
|
||||
{
|
||||
const char *s;
|
||||
|
||||
GWEN_Tag16_WriteUint64TagToBuffer(AQH_IPCDATA_DEVICE_TAGS_ID, AQH_Device_GetId(device), buf);
|
||||
|
||||
s=AQH_Device_GetDriver(device);
|
||||
if (s && *s)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_DRIVER, s, buf);
|
||||
|
||||
s=AQH_Device_GetRoomName(device);
|
||||
if (s && *s)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_ROOMNAME, s, buf);
|
||||
|
||||
s=AQH_Device_GetNameForDriver(device);
|
||||
if (s && *s)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_NAMEFORDRIVER, s, buf);
|
||||
|
||||
s=AQH_Device_GetNameForSystem(device);
|
||||
if (s && *s)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_NAMEFORSYSTEM, s, buf);
|
||||
|
||||
s=AQH_Device_GetNameForGui(device);
|
||||
if (s && *s)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_NAMEFORGUI, s, buf);
|
||||
|
||||
s=AQH_Device_GetLocation(device);
|
||||
if (s && *s)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_LOCATION, s, buf);
|
||||
|
||||
s=AQH_Device_GetDescription(device);
|
||||
if (s && *s)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_DESCRIPTION, s, buf);
|
||||
|
||||
s=AQH_Device_GetDeviceType(device);
|
||||
if (s && *s)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_DEVTYPE, s, buf);
|
||||
|
||||
s=AQH_Device_GetManufacturer(device);
|
||||
if (s && *s)
|
||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_MANUFACTURER, s, buf);
|
||||
|
||||
GWEN_Tag16_WriteUint64TagToBuffer(AQH_IPCDATA_DEVICE_TAGS_TIMEOFCREATION, AQH_Device_GetTimestampCreation(device), buf);
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_DEVICE *_readDeviceFromTag(const uint8_t *ptr, uint32_t len)
|
||||
{
|
||||
GWEN_TAG16_LIST *tagList;
|
||||
|
||||
tagList=GWEN_Tag16_List_fromBuffer(ptr, len, 0);
|
||||
if (tagList) {
|
||||
GWEN_TAG16 *tag;
|
||||
AQH_DEVICE *device;
|
||||
|
||||
device=AQH_Device_new();
|
||||
tag=GWEN_Tag16_List_First(tagList);
|
||||
while(tag) {
|
||||
unsigned int tagType;
|
||||
char *s;
|
||||
|
||||
tagType=GWEN_Tag16_GetTagType(tag);
|
||||
switch(tagType) {
|
||||
case AQH_IPCDATA_DEVICE_TAGS_ID:
|
||||
AQH_Device_SetId(device, GWEN_Tag16_GetTagDataAsUint64(tag, 0));
|
||||
break;
|
||||
case AQH_IPCDATA_DEVICE_TAGS_DRIVER:
|
||||
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
|
||||
AQH_Device_SetDriver(device, s);
|
||||
free(s);
|
||||
break;
|
||||
case AQH_IPCDATA_DEVICE_TAGS_ROOMNAME:
|
||||
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
|
||||
AQH_Device_SetRoomName(device, s);
|
||||
free(s);
|
||||
break;
|
||||
case AQH_IPCDATA_DEVICE_TAGS_NAMEFORDRIVER:
|
||||
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
|
||||
AQH_Device_SetNameForDriver(device, s);
|
||||
free(s);
|
||||
break;
|
||||
case AQH_IPCDATA_DEVICE_TAGS_NAMEFORSYSTEM:
|
||||
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
|
||||
AQH_Device_SetNameForSystem(device, s);
|
||||
free(s);
|
||||
break;
|
||||
case AQH_IPCDATA_DEVICE_TAGS_NAMEFORGUI:
|
||||
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
|
||||
AQH_Device_SetNameForGui(device, s);
|
||||
free(s);
|
||||
break;
|
||||
case AQH_IPCDATA_DEVICE_TAGS_LOCATION:
|
||||
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
|
||||
AQH_Device_SetLocation(device, s);
|
||||
free(s);
|
||||
break;
|
||||
case AQH_IPCDATA_DEVICE_TAGS_DESCRIPTION:
|
||||
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
|
||||
AQH_Device_SetDescription(device, s);
|
||||
free(s);
|
||||
break;
|
||||
case AQH_IPCDATA_DEVICE_TAGS_DEVTYPE:
|
||||
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
|
||||
AQH_Device_SetDeviceType(device, s);
|
||||
free(s);
|
||||
break;
|
||||
case AQH_IPCDATA_DEVICE_TAGS_MANUFACTURER:
|
||||
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
|
||||
AQH_Device_SetManufacturer(device, s);
|
||||
free(s);
|
||||
break;
|
||||
case AQH_IPCDATA_DEVICE_TAGS_TIMEOFCREATION:
|
||||
AQH_Device_SetTimestampCreation(device, GWEN_Tag16_GetTagDataAsUint64(tag, 0));
|
||||
break;
|
||||
default:
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Unhandled tag typ %d (%02x)", tagType, tagType);
|
||||
break;
|
||||
}
|
||||
tag=GWEN_Tag16_List_Next(tag);
|
||||
}
|
||||
GWEN_Tag16_List_free(tagList);
|
||||
return device;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include <aqhome/api.h>
|
||||
#include <aqhome/data/value.h>
|
||||
#include <aqhome/data/device.h>
|
||||
|
||||
#include <gwenhywfar/msg_ipc.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
@@ -30,18 +31,23 @@
|
||||
#define AQH_MSGTYPE_IPC_DATA_UPDATEDATA 0x100 /* AQH_MultiDataDataIpcMsg */
|
||||
#define AQH_MSGTYPE_IPC_DATA_DATACHANGED 0x200 /* AQH_MultiDataDataIpcMsg */
|
||||
|
||||
#define AQH_MSGTYPE_IPC_DATA_SETDATA 0x300 /* AQH_SingleDataDataIpcMsg */
|
||||
#define AQH_MSGTYPE_IPC_DATA_SETDATA 0x300 /* AQH_MultiDataDataIpcMsg */
|
||||
|
||||
#define AQH_MSGTYPE_IPC_DATA_ADDVALUE 0x400 /* AQH_AddValueDataIpcMsg */
|
||||
|
||||
#define AQH_MSGTYPE_IPC_DATA_GETDATA_REQ 0x500 /* AQH_GetDataDataIpcMsg */
|
||||
#define AQH_MSGTYPE_IPC_DATA_GETDATA_RSP 0x600 /* AQH_DataPointsDataIpcMsg */ /* TODO */
|
||||
#define AQH_MSGTYPE_IPC_DATA_GETDATA_RSP 0x600 /* AQH_MultiDataDataIpcMsg */
|
||||
|
||||
#define AQH_MSGTYPE_IPC_DATA_GETLASTDATA_REQ 0x700 /* AQH_ValueDataIpcMsg */
|
||||
#define AQH_MSGTYPE_IPC_DATA_GETLASTDATA_RSP 0x800 /* AQH_SingleDataDataIpcMsg */
|
||||
#define AQH_MSGTYPE_IPC_DATA_GETLASTDATA_REQ 0x700 /* AQH_GetDataDataIpcMsg */
|
||||
#define AQH_MSGTYPE_IPC_DATA_GETLASTDATA_RSP 0x800 /* AQH_MultiDataDataIpcMsg */
|
||||
|
||||
#define AQH_MSGTYPE_IPC_DATA_GETVALUES_REQ 0x900 /* GWEN_IpcMsg */
|
||||
#define AQH_MSGTYPE_IPC_DATA_GETVALUES_RSP 0xa00 /* AQH_ValuesDataIpcMsg */ /* TODO */
|
||||
#define AQH_MSGTYPE_IPC_DATA_GETVALUES_RSP 0xa00 /* AQH_ValuesDataIpcMsg */
|
||||
|
||||
#define AQH_MSGTYPE_IPC_DATA_GETDEVICES_REQ 0xb00 /* GWEN_IpcMsg */
|
||||
#define AQH_MSGTYPE_IPC_DATA_GETDEVICES_RSP 0xc00 /* AQH_DevicesDataIpcMsg */
|
||||
|
||||
#define AQH_MSGTYPE_IPC_DATA_MODDEVICES_REQ 0xd00 /* AQH_DevicesDataIpcMsg */
|
||||
|
||||
|
||||
|
||||
@@ -53,6 +59,11 @@ AQHOME_API int AQH_DataIpc_WriteValueAsTagToBuffer(unsigned int tagType, const A
|
||||
AQHOME_API AQH_VALUE_LIST *AQH_DataIpc_ReadValuesFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType);
|
||||
AQHOME_API AQH_VALUE *AQH_DataIpc_ReadValueFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType);
|
||||
|
||||
AQHOME_API int AQH_DataIpc_WriteDeviceListAsTagsToBuffer(unsigned int tagType, const AQH_DEVICE_LIST *deviceList, GWEN_BUFFER *buf);
|
||||
AQHOME_API int AQH_DataIpc_WriteDeviceAsTagToBuffer(unsigned int tagType, const AQH_DEVICE *device, GWEN_BUFFER *buf);
|
||||
AQHOME_API AQH_DEVICE_LIST *AQH_DataIpc_ReadDevicesFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType);
|
||||
AQHOME_API AQH_DEVICE *AQH_DataIpc_ReadDeviceFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
150
aqhome/ipc/data/msg_data_devices.c
Normal file
150
aqhome/ipc/data/msg_data_devices.c
Normal file
@@ -0,0 +1,150 @@
|
||||
/****************************************************************************
|
||||
* 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 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,
|
||||
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 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,
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
52
aqhome/ipc/data/msg_data_devices.h
Normal file
52
aqhome/ipc/data/msg_data_devices.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/****************************************************************************
|
||||
* 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.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef AQH_MSG_IPC_DATA_DEVICES_H
|
||||
#define AQH_MSG_IPC_DATA_DEVICES_H
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
|
||||
#include <aqhome/data/device.h>
|
||||
|
||||
#include <gwenhywfar/msg_ipc.h>
|
||||
|
||||
|
||||
/**
|
||||
* This message is used in request AQH_MSGTYPE_IPC_DATA_ADDDEVICES_REQ and in response AQH_MSGTYPE_IPC_DATA_GETDEVICES_RSP.
|
||||
*/
|
||||
|
||||
#define AQH_MSGDATA_DEVICES_FLAGS_LASTMSG 0x0001
|
||||
|
||||
#define AQH_MSGDATA_DEVICES_TAGS_FLAGS 0x01
|
||||
#define AQH_MSGDATA_DEVICES_TAGS_DEVICE 0xc2
|
||||
|
||||
|
||||
AQHOME_API GWEN_MSG *AQH_DevicesDataIpcMsg_new(uint16_t code, uint32_t flags, const AQH_DEVICE_LIST *deviceList);
|
||||
AQHOME_API GWEN_MSG *AQH_DevicesDataIpcMsg_newForOneDevice(uint16_t code, uint32_t flags, const AQH_DEVICE *device);
|
||||
|
||||
AQHOME_API void AQH_DevicesDataIpcMsg_Parse(GWEN_MSG *msg, int doCopy);
|
||||
|
||||
AQHOME_API AQH_DEVICE_LIST *AQH_DevicesDataIpcMsg_ReadDeviceList(const GWEN_MSG *msg);
|
||||
AQHOME_API AQH_DEVICE *AQH_DevicesDataIpcMsg_ReadFirstDevice(const GWEN_MSG *msg);
|
||||
|
||||
|
||||
AQHOME_API uint32_t AQH_DevicesDataIpcMsg_GetFlags(const GWEN_MSG *msg);
|
||||
|
||||
AQHOME_API void AQH_DevicesDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user