aqhome: added IPC messages (FORWARD, VALUE)

This commit is contained in:
Martin Preuss
2023-03-19 23:21:02 +01:00
parent c41d6fa45a
commit 796869fc3c
8 changed files with 272 additions and 25 deletions

View File

@@ -48,7 +48,8 @@
endpoint_node_ipc.h endpoint_node_ipc.h
endpoint_node_ipc_tcp.h endpoint_node_ipc_tcp.h
msg_ipc.h msg_ipc.h
msg_forward.h msg_ipc_forward.h
msg_ipc_value.h
</headers> </headers>
@@ -62,7 +63,8 @@
endpoint_node_ipc.c endpoint_node_ipc.c
endpoint_node_ipc_tcp.c endpoint_node_ipc_tcp.c
msg_ipc.c msg_ipc.c
msg_forward.c msg_ipc_forward.c
msg_ipc_value.c
</sources> </sources>

View File

@@ -14,7 +14,9 @@
#include "aqhome/ipc/endpoint_node_ipc.h" #include "aqhome/ipc/endpoint_node_ipc.h"
#include "aqhome/msg/endpoint_node.h" #include "aqhome/msg/endpoint_node.h"
#include "aqhome/msg/msg_node.h" #include "aqhome/msg/msg_node.h"
#include "aqhome/ipc/msg_forward.h" #include "aqhome/msg/msg_value2.h"
#include "aqhome/ipc/msg_ipc_forward.h"
#include "aqhome/ipc/msg_ipc_value.h"
#include <gwenhywfar/list.h> #include <gwenhywfar/list.h>
#include <gwenhywfar/debug.h> #include <gwenhywfar/debug.h>
@@ -27,6 +29,8 @@
static void _processOutMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *m); static void _processOutMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *m);
static void _processValue2Message(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg);
static void _forwardAnyMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg);
@@ -49,12 +53,42 @@ GWEN_MSG_ENDPOINT *AQH_IpcNodeEndpoint_new(const char *name, int groupId)
void _processOutMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg) void _processOutMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg)
{
switch(AQH_NodeMsg_GetMsgType(nodeMsg)) {
case AQH_MSG_TYPE_VALUE2:
_processValue2Message(ep, nodeMsg);
break;
default:
_forwardAnyMessage(ep, nodeMsg);
break;
}
GWEN_Msg_free(nodeMsg);
}
void _processValue2Message(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg)
{ {
GWEN_MSG *ipcMsg; GWEN_MSG *ipcMsg;
ipcMsg=AQH_ForwardMsg_new(AQH_MSGTYPE_IPC_FORWARD, GWEN_Msg_GetConstBuffer(nodeMsg), GWEN_Msg_GetBytesInBuffer(nodeMsg)); ipcMsg=AQH_ValueIpcMsg_new(AQH_MSGTYPE_IPC_VALUE,
AQH_Value2Msg_GetUid(nodeMsg),
AQH_Value2Msg_GetValueId(nodeMsg),
AQH_Value2Msg_GetValueType(nodeMsg),
AQH_Value2Msg_GetValueNom(nodeMsg),
AQH_Value2Msg_GetValueDenom(nodeMsg));
GWEN_MsgEndpoint_AddSendMessage(ep, ipcMsg);
}
void _forwardAnyMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg)
{
GWEN_MSG *ipcMsg;
ipcMsg=AQH_ForwardIpcMsg_new(AQH_MSGTYPE_IPC_FORWARD, GWEN_Msg_GetConstBuffer(nodeMsg), GWEN_Msg_GetBytesInBuffer(nodeMsg));
GWEN_MsgEndpoint_AddSendMessage(ep, ipcMsg); GWEN_MsgEndpoint_AddSendMessage(ep, ipcMsg);
GWEN_Msg_free(nodeMsg);
} }

View File

@@ -15,7 +15,6 @@
#include "aqhome/ipc/endpoint_node_ipc.h" #include "aqhome/ipc/endpoint_node_ipc.h"
#include "aqhome/msg/endpoint_node.h" #include "aqhome/msg/endpoint_node.h"
#include "aqhome/msg/msg_node.h" #include "aqhome/msg/msg_node.h"
#include "aqhome/ipc/msg_forward.h"
#include <gwenhywfar/list.h> #include <gwenhywfar/list.h>
#include <gwenhywfar/debug.h> #include <gwenhywfar/debug.h>

View File

@@ -21,6 +21,7 @@
#define AQH_MSGTYPE_IPC_FORWARD 0x100 #define AQH_MSGTYPE_IPC_FORWARD 0x100
#define AQH_MSGTYPE_IPC_VALUE 0x200

View File

@@ -10,7 +10,7 @@
# include <config.h> # include <config.h>
#endif #endif
#include <aqhome/ipc/msg_forward.h> #include <aqhome/ipc/msg_ipc_forward.h>
#include <gwenhywfar/msg.h> #include <gwenhywfar/msg.h>
#include <gwenhywfar/buffer.h> #include <gwenhywfar/buffer.h>
@@ -24,15 +24,20 @@
#define AQH_MSG_OFFS_FORWARD_MSG (GWEN_MSGIPC_OFFS_PAYLOAD+0)
GWEN_MSG *AQH_ForwardMsg_new(uint16_t code, const uint8_t *ptr, uint32_t len) #define AQH_MSG_FORWARD_MINSIZE (AQH_MSG_OFFS_FORWARD_MSG+AQH_MSG_OFFS_ALL_DATA_BEGIN)
GWEN_MSG *AQH_ForwardIpcMsg_new(uint16_t code, const uint8_t *ptr, uint32_t len)
{ {
return GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_ID, AQH_IPC_PROTOCOL_VERSION, code, len, ptr); return GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_ID, AQH_IPC_PROTOCOL_VERSION, code, len, ptr);
} }
const uint8_t *AQH_ForwardMsg_GetMsgPtr(const GWEN_MSG *msg) const uint8_t *AQH_ForwardIpcMsg_GetMsgPtr(const GWEN_MSG *msg)
{ {
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_FORWARD_MINSIZE) if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_FORWARD_MINSIZE)
return GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_FORWARD_MSG; return GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_FORWARD_MSG;
@@ -41,7 +46,7 @@ const uint8_t *AQH_ForwardMsg_GetMsgPtr(const GWEN_MSG *msg)
uint32_t AQH_ForwardMsg_GetMsgLen(const GWEN_MSG *msg) uint32_t AQH_ForwardIpcMsg_GetMsgLen(const GWEN_MSG *msg)
{ {
uint32_t len; uint32_t len;
@@ -54,14 +59,14 @@ uint32_t AQH_ForwardMsg_GetMsgLen(const GWEN_MSG *msg)
void AQH_ForwardMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) void AQH_ForwardIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
{ {
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_FORWARD_MINSIZE) { if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_FORWARD_MINSIZE) {
const uint8_t *ptr; const uint8_t *ptr;
uint32_t len; uint32_t len;
ptr=AQH_ForwardMsg_GetMsgPtr(msg); ptr=AQH_ForwardIpcMsg_GetMsgPtr(msg);
len=AQH_ForwardMsg_GetMsgLen(msg); len=AQH_ForwardIpcMsg_GetMsgLen(msg);
GWEN_Buffer_AppendArgs(dbuf, "FORWARD (code=%d, protocol=%d, protocol version=%d)\n", GWEN_Buffer_AppendArgs(dbuf, "FORWARD (code=%d, protocol=%d, protocol version=%d)\n",
GWEN_IpcMsg_GetCode(msg), GWEN_IpcMsg_GetCode(msg),

View File

@@ -6,8 +6,8 @@
* should have received along with this file. * should have received along with this file.
****************************************************************************/ ****************************************************************************/
#ifndef AQH_MSG_FORWARD_H #ifndef AQH_MSG_IPC_FORWARD_H
#define AQH_MSG_FORWARD_H #define AQH_MSG_IPC_FORWARD_H
#include <aqhome/api.h> #include <aqhome/api.h>
@@ -19,16 +19,10 @@
#define AQH_MSG_OFFS_FORWARD_MSG (GWEN_MSGIPC_OFFS_PAYLOAD+0) AQHOME_API GWEN_MSG *AQH_ForwardIpcMsg_new(uint16_t code, const uint8_t *ptr, uint32_t len);
AQHOME_API const uint8_t *AQH_ForwardIpcMsg_GetMsgPtr(const GWEN_MSG *msg);
#define AQH_MSG_FORWARD_MINSIZE (AQH_MSG_OFFS_FORWARD_MSG+AQH_MSG_OFFS_ALL_DATA_BEGIN) AQHOME_API uint32_t AQH_ForwardIpcMsg_GetMsgLen(const GWEN_MSG *msg);
AQHOME_API void AQH_ForwardIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);
AQHOME_API GWEN_MSG *AQH_ForwardMsg_new(uint16_t code, const uint8_t *ptr, uint32_t len);
AQHOME_API const uint8_t *AQH_ForwardMsg_GetMsgPtr(const GWEN_MSG *msg);
AQHOME_API uint32_t AQH_ForwardMsg_GetMsgLen(const GWEN_MSG *msg);
AQHOME_API void AQH_ForwardMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif #endif

173
aqhome/ipc/msg_ipc_value.c Normal file
View File

@@ -0,0 +1,173 @@
/****************************************************************************
* 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_value.h>
#include <gwenhywfar/msg.h>
#include <gwenhywfar/buffer.h>
#include <gwenhywfar/misc.h>
#include <gwenhywfar/list.h>
#include <gwenhywfar/error.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/text.h>
#include <gwenhywfar/msg_ipc.h>
#define AQH_MSGIPC_VALUE_OFFS_UID 0 /* 4 bytes */
#define AQH_MSGIPC_VALUE_OFFS_VALUEID 4 /* 1 byte */
#define AQH_MSGIPC_VALUE_OFFS_VALUETYPE 5 /* 1 byte */
#define AQH_MSGIPC_VALUE_OFFS_VALUE_NOM 6 /* 2 bytes */
#define AQH_MSGIPC_VALUE_OFFS_VALUE_DENOM 8 /* 2 bytes */
#define AQH_MSGIPC_VALUE_MINSIZE (GWEN_MSGIPC_OFFS_PAYLOAD+10)
GWEN_MSG *AQH_ValueIpcMsg_new(uint16_t code,
uint32_t uid,
uint8_t valueId,
uint8_t valueType,
int16_t valueNom,
int16_t valueDenom)
{
GWEN_MSG *msg;
uint8_t *ptr;
msg=GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_ID, AQH_IPC_PROTOCOL_VERSION, code, AQH_MSGIPC_VALUE_MINSIZE, NULL);
ptr=GWEN_Msg_GetBuffer(msg);
ptr[GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_VALUE_OFFS_UID+0]=uid & 0xff;
ptr[GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_VALUE_OFFS_UID+1]=(uid>>8) & 0xff;
ptr[GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_VALUE_OFFS_UID+2]=(uid>>16) & 0xff;
ptr[GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_VALUE_OFFS_UID+3]=(uid>>24) & 0xff;
ptr[GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_VALUE_OFFS_VALUEID]=valueId;
ptr[GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_VALUE_OFFS_VALUETYPE]=valueType;
ptr[GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_VALUE_OFFS_VALUE_NOM+0]=valueNom & 0xff;
ptr[GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_VALUE_OFFS_VALUE_NOM+1]=(valueNom>>8) & 0xff;
ptr[GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_VALUE_OFFS_VALUE_DENOM+0]=valueDenom & 0xff;
ptr[GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_VALUE_OFFS_VALUE_DENOM+1]=(valueDenom>>8) & 0xff;
return msg;
}
uint32_t AQH_ValueIpcMsg_GetUid(const GWEN_MSG *msg)
{
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGIPC_VALUE_MINSIZE) {
const uint8_t *ptr;
ptr=GWEN_Msg_GetConstBuffer(msg)+GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_VALUE_OFFS_UID;
return (uint32_t)(ptr[0])+(ptr[1]<<8)+(ptr[2]<<16)+(ptr[3]<<24);
}
return 0;
}
uint8_t AQH_ValueIpcMsg_GetValueId(const GWEN_MSG *msg)
{
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGIPC_VALUE_MINSIZE) {
const uint8_t *ptr;
ptr=GWEN_Msg_GetConstBuffer(msg)+GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_VALUE_OFFS_VALUEID;
return (uint8_t)(ptr[0]);
}
return 0;
}
uint8_t AQH_ValueIpcMsg_GetValueType(const GWEN_MSG *msg)
{
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGIPC_VALUE_MINSIZE) {
const uint8_t *ptr;
ptr=GWEN_Msg_GetConstBuffer(msg)+GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_VALUE_OFFS_VALUETYPE;
return (uint8_t)(ptr[0]);
}
return 0;
}
int16_t AQH_ValueIpcMsg_GetValueNom(const GWEN_MSG *msg)
{
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGIPC_VALUE_MINSIZE) {
const uint8_t *ptr;
ptr=GWEN_Msg_GetConstBuffer(msg)+GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_VALUE_OFFS_VALUE_NOM;
return (int16_t)((uint16_t)((ptr[0])+(ptr[1]<<8)));
}
return 0;
}
int16_t AQH_ValueIpcMsg_GetValueDenom(const GWEN_MSG *msg)
{
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGIPC_VALUE_MINSIZE) {
const uint8_t *ptr;
ptr=GWEN_Msg_GetConstBuffer(msg)+GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_VALUE_OFFS_VALUE_DENOM;
return (int16_t)((uint16_t)((ptr[0])+(ptr[1]<<8)));
}
return 0;
}
double AQH_ValueIpcMsg_GetValueAsDouble(const GWEN_MSG *msg)
{
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGIPC_VALUE_MINSIZE) {
double nom;
int16_t rawDenom;
double denom;
nom=(double) AQH_ValueIpcMsg_GetValueNom(msg);
rawDenom=AQH_ValueIpcMsg_GetValueDenom(msg);
if (rawDenom==0)
denom=1.0;
else
denom=(double) rawDenom;
return (double)(nom/denom);
}
return 0.0;
}
void AQH_ValueIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
{
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGIPC_VALUE_MINSIZE) {
GWEN_Buffer_AppendArgs(dbuf,
"VALUE (code=%d, proto=%d, proto version=%d, uid=0x%08x, value_id=0x%02x, type=0x%02x, value=%f)\n",
GWEN_IpcMsg_GetCode(msg),
GWEN_IpcMsg_GetProtoId(msg),
GWEN_IpcMsg_GetProtoVersion(msg),
(unsigned int) AQH_ValueIpcMsg_GetUid(msg),
AQH_ValueIpcMsg_GetValueId(msg),
AQH_ValueIpcMsg_GetValueType(msg),
AQH_ValueIpcMsg_GetValueAsDouble(msg));
}
}

View File

@@ -0,0 +1,39 @@
/****************************************************************************
* 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_VALUE_H
#define AQH_MSG_IPC_VALUE_H
#include <aqhome/api.h>
#include <aqhome/ipc/msg_ipc.h>
#include <aqhome/msg/msg_node.h>
#include <gwenhywfar/msg.h>
#include <gwenhywfar/buffer.h>
AQHOME_API GWEN_MSG *AQH_ValueIpcMsg_new(uint16_t code,
uint32_t uid,
uint8_t valueId,
uint8_t valueType,
int16_t valueNom,
int16_t valueDenom);
AQHOME_API uint32_t AQH_ValueIpcMsg_GetUid(const GWEN_MSG *msg);
AQHOME_API uint8_t AQH_ValueIpcMsg_GetValueId(const GWEN_MSG *msg);
AQHOME_API uint8_t AQH_ValueIpcMsg_GetValueType(const GWEN_MSG *msg);
AQHOME_API int16_t AQH_ValueIpcMsg_GetValueNom(const GWEN_MSG *msg);
AQHOME_API int16_t AQH_ValueIpcMsg_GetValueDenom(const GWEN_MSG *msg);
AQHOME_API double AQH_ValueIpcMsg_GetValueAsDouble(const GWEN_MSG *msg);
#endif