diff --git a/aqhome/ipc/0BUILD b/aqhome/ipc/0BUILD index 5b8e0db..50feba4 100644 --- a/aqhome/ipc/0BUILD +++ b/aqhome/ipc/0BUILD @@ -48,7 +48,8 @@ endpoint_node_ipc.h endpoint_node_ipc_tcp.h msg_ipc.h - msg_forward.h + msg_ipc_forward.h + msg_ipc_value.h @@ -62,7 +63,8 @@ endpoint_node_ipc.c endpoint_node_ipc_tcp.c msg_ipc.c - msg_forward.c + msg_ipc_forward.c + msg_ipc_value.c diff --git a/aqhome/ipc/endpoint_node_ipc.c b/aqhome/ipc/endpoint_node_ipc.c index 778d311..507741c 100644 --- a/aqhome/ipc/endpoint_node_ipc.c +++ b/aqhome/ipc/endpoint_node_ipc.c @@ -14,7 +14,9 @@ #include "aqhome/ipc/endpoint_node_ipc.h" #include "aqhome/msg/endpoint_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 #include @@ -27,6 +29,8 @@ 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) +{ + 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; - 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_Msg_free(nodeMsg); } diff --git a/aqhome/ipc/endpoint_node_ipc_tcp.c b/aqhome/ipc/endpoint_node_ipc_tcp.c index 84db0c8..f980f86 100644 --- a/aqhome/ipc/endpoint_node_ipc_tcp.c +++ b/aqhome/ipc/endpoint_node_ipc_tcp.c @@ -15,7 +15,6 @@ #include "aqhome/ipc/endpoint_node_ipc.h" #include "aqhome/msg/endpoint_node.h" #include "aqhome/msg/msg_node.h" -#include "aqhome/ipc/msg_forward.h" #include #include diff --git a/aqhome/ipc/msg_ipc.h b/aqhome/ipc/msg_ipc.h index 28c1d21..f908564 100644 --- a/aqhome/ipc/msg_ipc.h +++ b/aqhome/ipc/msg_ipc.h @@ -21,6 +21,7 @@ #define AQH_MSGTYPE_IPC_FORWARD 0x100 +#define AQH_MSGTYPE_IPC_VALUE 0x200 diff --git a/aqhome/ipc/msg_forward.c b/aqhome/ipc/msg_ipc_forward.c similarity index 73% rename from aqhome/ipc/msg_forward.c rename to aqhome/ipc/msg_ipc_forward.c index fb079d3..8add94c 100644 --- a/aqhome/ipc/msg_forward.c +++ b/aqhome/ipc/msg_ipc_forward.c @@ -10,7 +10,7 @@ # include #endif -#include +#include #include #include @@ -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); } -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) 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; @@ -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) { const uint8_t *ptr; uint32_t len; - ptr=AQH_ForwardMsg_GetMsgPtr(msg); - len=AQH_ForwardMsg_GetMsgLen(msg); + ptr=AQH_ForwardIpcMsg_GetMsgPtr(msg); + len=AQH_ForwardIpcMsg_GetMsgLen(msg); GWEN_Buffer_AppendArgs(dbuf, "FORWARD (code=%d, protocol=%d, protocol version=%d)\n", GWEN_IpcMsg_GetCode(msg), diff --git a/aqhome/ipc/msg_forward.h b/aqhome/ipc/msg_ipc_forward.h similarity index 50% rename from aqhome/ipc/msg_forward.h rename to aqhome/ipc/msg_ipc_forward.h index ac315b9..c9103b7 100644 --- a/aqhome/ipc/msg_forward.h +++ b/aqhome/ipc/msg_ipc_forward.h @@ -6,8 +6,8 @@ * should have received along with this file. ****************************************************************************/ -#ifndef AQH_MSG_FORWARD_H -#define AQH_MSG_FORWARD_H +#ifndef AQH_MSG_IPC_FORWARD_H +#define AQH_MSG_IPC_FORWARD_H #include @@ -19,16 +19,10 @@ -#define AQH_MSG_OFFS_FORWARD_MSG (GWEN_MSGIPC_OFFS_PAYLOAD+0) - -#define AQH_MSG_FORWARD_MINSIZE (AQH_MSG_OFFS_FORWARD_MSG+AQH_MSG_OFFS_ALL_DATA_BEGIN) - - - -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); +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); +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); #endif diff --git a/aqhome/ipc/msg_ipc_value.c b/aqhome/ipc/msg_ipc_value.c new file mode 100644 index 0000000..9b08a88 --- /dev/null +++ b/aqhome/ipc/msg_ipc_value.c @@ -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 +#endif + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + + +#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)); + } +} + + + + + + + diff --git a/aqhome/ipc/msg_ipc_value.h b/aqhome/ipc/msg_ipc_value.h new file mode 100644 index 0000000..2af8a69 --- /dev/null +++ b/aqhome/ipc/msg_ipc_value.h @@ -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 +#include +#include + +#include +#include + + + +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 + + +