Introduces tag16 ipc messages.
This commit is contained in:
102
aqhome/ipc/msg_ipc_tag16.c
Normal file
102
aqhome/ipc/msg_ipc_tag16.c
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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/msg_ipc_tag16.h>
|
||||||
|
|
||||||
|
#include <gwenhywfar/msg_ipc.h>
|
||||||
|
#include <gwenhywfar/debug.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
GWEN_MSG *AQH_Tag16IpcMsg_new(uint8_t protoId, uint8_t protoVer, uint16_t code, const GWEN_TAG16_LIST *tagList)
|
||||||
|
{
|
||||||
|
GWEN_MSG *msg;
|
||||||
|
const GWEN_TAG16 *tag;
|
||||||
|
GWEN_BUFFER *buf;
|
||||||
|
|
||||||
|
buf=GWEN_Buffer_new(0, 256, 0, 1);
|
||||||
|
tag=GWEN_Tag16_List_First(tagList);
|
||||||
|
while(tag) {
|
||||||
|
GWEN_Tag16_DirectlyToBuffer(GWEN_Tag16_GetTagType(tag),
|
||||||
|
GWEN_Tag16_GetTagData(tag),
|
||||||
|
GWEN_Tag16_GetTagLength(tag),
|
||||||
|
buf);
|
||||||
|
tag=GWEN_Tag16_List_Next(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
msg=GWEN_IpcMsg_new(protoId, protoVer, code, GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf));
|
||||||
|
GWEN_Buffer_free(buf);
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
GWEN_TAG16_LIST *AQH_Tag16IpcMsg_ParseTags(const GWEN_MSG *msg, int doCopy)
|
||||||
|
{
|
||||||
|
uint32_t msgSize;
|
||||||
|
|
||||||
|
msgSize=GWEN_Msg_GetBytesInBuffer(msg);
|
||||||
|
if (msgSize>GWEN_MSGIPC_OFFS_PAYLOAD) {
|
||||||
|
const uint8_t *ptr;
|
||||||
|
uint32_t payloadSize;
|
||||||
|
GWEN_TAG16_LIST *tagList;
|
||||||
|
|
||||||
|
ptr=GWEN_Msg_GetConstBuffer(msg)+GWEN_MSGIPC_OFFS_PAYLOAD;
|
||||||
|
payloadSize=msgSize-GWEN_MSGIPC_OFFS_PAYLOAD;
|
||||||
|
tagList=GWEN_Tag16_List_new();
|
||||||
|
while(payloadSize) {
|
||||||
|
GWEN_TAG16 *tag;
|
||||||
|
unsigned int tagSize;
|
||||||
|
|
||||||
|
tag=GWEN_Tag16_fromBuffer2(ptr, payloadSize, doCopy);
|
||||||
|
if (tag==NULL)
|
||||||
|
break;
|
||||||
|
tagSize=GWEN_Tag16_GetTagSize(tag);
|
||||||
|
if (payloadSize>tagSize) {
|
||||||
|
DBG_ERROR(AQH_LOGDOMAIN, "Error in tag size");
|
||||||
|
GWEN_Tag16_List_free(tagList);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
GWEN_Tag16_List_Add(tag, tagList);
|
||||||
|
ptr+=tagSize;
|
||||||
|
payloadSize-=tagSize;
|
||||||
|
} /* while */
|
||||||
|
if (GWEN_Tag16_List_GetCount(tagList)<1) {
|
||||||
|
GWEN_Tag16_List_free(tagList);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return tagList;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void AQH_Tag16IpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
|
||||||
|
{
|
||||||
|
if (GWEN_Msg_GetBytesInBuffer(msg)>=GWEN_MSGIPC_OFFS_PAYLOAD) {
|
||||||
|
GWEN_Buffer_AppendArgs(dbuf,
|
||||||
|
"Tag16 (code=%d, proto=%d, proto version=%d)\n",
|
||||||
|
GWEN_IpcMsg_GetCode(msg),
|
||||||
|
GWEN_IpcMsg_GetProtoId(msg),
|
||||||
|
GWEN_IpcMsg_GetProtoVersion(msg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
28
aqhome/ipc/msg_ipc_tag16.h
Normal file
28
aqhome/ipc/msg_ipc_tag16.h
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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_TAG16_H
|
||||||
|
#define AQH_MSG_IPC_TAG16_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <aqhome/api.h>
|
||||||
|
|
||||||
|
#include <gwenhywfar/msg.h>
|
||||||
|
#include <gwenhywfar/buffer.h>
|
||||||
|
#include <gwenhywfar/tag16.h>
|
||||||
|
|
||||||
|
|
||||||
|
AQHOME_API GWEN_MSG *AQH_Tag16IpcMsg_new(uint8_t protoId, uint8_t protoVer, uint16_t code, const GWEN_TAG16_LIST *tagList);
|
||||||
|
AQHOME_API GWEN_TAG16_LIST *AQH_Tag16IpcMsg_ParseTags(const GWEN_MSG *msg, int doCopy);
|
||||||
|
AQHOME_API void AQH_Tag16IpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user