121 lines
3.7 KiB
C
121 lines
3.7 KiB
C
/****************************************************************************
|
|
* This file is part of the project AqHome.
|
|
* AqHome (c) by 2025 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/msg/ipc/data/m_ipcd_setdata.h"
|
|
#include "aqhome/msg/ipc/m_ipc_tag16.h"
|
|
#include "aqhome/msg/ipc/data/m_ipcd.h"
|
|
#include "aqhome/msg/ipc/m_ipc.h"
|
|
|
|
#include <gwenhywfar/text.h>
|
|
#include <gwenhywfar/tag16.h>
|
|
#include <gwenhywfar/buffer.h>
|
|
#include <gwenhywfar/debug.h>
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
* forward declarations
|
|
* ------------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
* implementation
|
|
* ------------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
AQH_MESSAGE *AQH_IpcdMessageSetData_new(uint16_t code,
|
|
uint32_t msgId, uint32_t refMsgId,
|
|
const AQH_VALUE *value, const char *data)
|
|
{
|
|
AQH_MESSAGE *msg;
|
|
GWEN_BUFFER *buf;
|
|
int rv;
|
|
|
|
buf=GWEN_Buffer_new(0, 256, 0, 1);
|
|
|
|
rv=AQH_Tag16_WriteValueAsTagToBuffer(AQH_MSGDATA_SET_TAGS_VALUE, value, buf);
|
|
if (rv<0) {
|
|
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
|
GWEN_Buffer_free(buf);
|
|
return NULL;
|
|
}
|
|
if (data && *data)
|
|
GWEN_Tag16_WriteStringTagToBuffer(AQH_MSGDATA_SET_TAGS_DATA, data, buf);
|
|
|
|
msg=AQH_IpcMessage_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;
|
|
}
|
|
|
|
|
|
|
|
AQH_VALUE *AQH_IpcdMessageSetData_ReadValue(const GWEN_TAG16_LIST *tagList)
|
|
{
|
|
if (tagList) {
|
|
AQH_VALUE *value;
|
|
|
|
value=AQH_Tag16_ReadValueFromTagList(tagList, AQH_MSGDATA_SET_TAGS_VALUE);
|
|
if (value==NULL) {
|
|
DBG_INFO(AQH_LOGDOMAIN, "No value received");
|
|
}
|
|
return value;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
|
|
|
|
char *AQH_IpcdMessageSetData_ReadData(const GWEN_TAG16_LIST *tagList)
|
|
{
|
|
return AQH_Tag16_GetTagDataAsNewString(tagList, AQH_MSGDATA_SET_TAGS_DATA, NULL);
|
|
}
|
|
|
|
|
|
|
|
void AQH_IpcdMessageSetData_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
|
|
GWEN_BUFFER *dbuf, const char *sText)
|
|
{
|
|
AQH_VALUE *value;
|
|
const char *valueName;
|
|
const char *valueUnits;
|
|
int valueType;
|
|
char *data;
|
|
|
|
value=tagList?AQH_IpcdMessageSetData_ReadValue(tagList):NULL;
|
|
valueName=value?AQH_Value_GetNameForSystem(value):NULL;
|
|
valueUnits=value?AQH_Value_GetValueUnits(value):NULL;
|
|
valueType=value?AQH_Value_GetValueType(value):0;
|
|
data=tagList?AQH_IpcdMessageSetData_ReadData(tagList):NULL;
|
|
|
|
GWEN_Buffer_AppendArgs(dbuf,
|
|
"SETDATA(%s) %s (code=%d, proto=%d, proto version=%d, name=%s, units=%s, type=%d, value=%s)\n",
|
|
AQH_IpcdMessage_MsgTypeToChar(AQH_IpcMessage_GetCode(msg)),
|
|
sText?sText:"",
|
|
AQH_IpcMessage_GetCode(msg),
|
|
AQH_IpcMessage_GetProtoId(msg),
|
|
AQH_IpcMessage_GetProtoVersion(msg),
|
|
valueName?valueName:"<empty>",
|
|
valueUnits?valueUnits:"<empty>",
|
|
valueType,
|
|
data?data:"<empty>");
|
|
free(data);
|
|
AQH_Value_free(value);
|
|
}
|
|
|
|
|
|
|
|
|