From 290967a7c5a4fe615fc2f1061a1d32d1552baaf1 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sun, 13 Aug 2023 17:56:00 +0200 Subject: [PATCH] added generic IPC result message. --- apps/aqhome-tool/getdevices.c | 4 +-- apps/aqhomed/loop_ipc.c | 4 +-- aqhome/ipc/0BUILD | 4 +++ .../msg_ipc_error.c => msg_ipc_result.c} | 25 ++++++++++--------- .../msg_ipc_error.h => msg_ipc_result.h} | 16 +++++++----- aqhome/ipc/nodes/0BUILD | 2 -- 6 files changed, 31 insertions(+), 24 deletions(-) rename aqhome/ipc/{nodes/msg_ipc_error.c => msg_ipc_result.c} (56%) rename aqhome/ipc/{nodes/msg_ipc_error.h => msg_ipc_result.h} (57%) diff --git a/apps/aqhome-tool/getdevices.c b/apps/aqhome-tool/getdevices.c index 12b27d4..8893c5f 100644 --- a/apps/aqhome-tool/getdevices.c +++ b/apps/aqhome-tool/getdevices.c @@ -16,7 +16,7 @@ #include "aqhome/ipc/endpoint_ipc.h" #include "aqhome/ipc/nodes/msg_ipc_getdevices_req.h" #include "aqhome/ipc/nodes/msg_ipc_getdevices_rsp.h" -#include "aqhome/ipc/nodes/msg_ipc_error.h" +#include "aqhome/ipc/msg_ipc_result.h" #include "aqhome/msg/msg_node.h" #include @@ -154,7 +154,7 @@ int _doGetDevices(GWEN_DB_NODE *dbArgs) } code=GWEN_IpcMsg_GetCode(msg); if (code==AQH_MSGTYPE_IPC_NODES_ERROR) { - fprintf(stdout, "No device list (%d)\n", AQH_ErrorIpcMsg_GetErrorCode(msg)); + fprintf(stdout, "No device list (%d)\n", AQH_ResultIpcMsg_GetResultCode(msg)); GWEN_Msg_free(msg); break; } diff --git a/apps/aqhomed/loop_ipc.c b/apps/aqhomed/loop_ipc.c index 3f4887b..87da781 100644 --- a/apps/aqhomed/loop_ipc.c +++ b/apps/aqhomed/loop_ipc.c @@ -28,7 +28,7 @@ #include "aqhome/ipc/nodes/msg_ipc_ping.h" #include "aqhome/ipc/nodes/msg_ipc_setaccmsggrps.h" #include "aqhome/ipc/nodes/msg_ipc_getdevices_rsp.h" -#include "aqhome/ipc/nodes/msg_ipc_error.h" +#include "aqhome/ipc/msg_ipc_result.h" #include #include @@ -176,7 +176,7 @@ void _handleIpcMsgGetDevicesReq(AQHOMED *aqh, GWEN_MSG_ENDPOINT *ep, const GWEN_ GWEN_MSG *msgOut; DBG_INFO(AQH_LOGDOMAIN, "No nodes"); - msgOut=AQH_ErrorIpcMsg_new(AQH_MSGTYPE_IPC_NODES_ERROR, AQH_MSG_IPC_ERROR_NODATA); + msgOut=AQH_ResultIpcMsg_new(AQH_MSGTYPE_IPC_NODES_ERROR, AQH_MSG_IPC_ERROR_NODATA); GWEN_MsgEndpoint_AddSendMessage(ep, msgOut); } } diff --git a/aqhome/ipc/0BUILD b/aqhome/ipc/0BUILD index 39c1e70..226d2b2 100644 --- a/aqhome/ipc/0BUILD +++ b/aqhome/ipc/0BUILD @@ -46,6 +46,7 @@ endpoint_ipc.h + msg_ipc_result.h @@ -58,6 +59,7 @@ $(local/typefiles) endpoint_ipc.c + msg_ipc_result.c @@ -67,10 +69,12 @@ aqhipcnodes + aqhipcdata nodes + data diff --git a/aqhome/ipc/nodes/msg_ipc_error.c b/aqhome/ipc/msg_ipc_result.c similarity index 56% rename from aqhome/ipc/nodes/msg_ipc_error.c rename to aqhome/ipc/msg_ipc_result.c index 31baf0e..2510f3f 100644 --- a/aqhome/ipc/nodes/msg_ipc_error.c +++ b/aqhome/ipc/msg_ipc_result.c @@ -10,7 +10,7 @@ # include #endif -#include +#include #include #include @@ -23,46 +23,47 @@ #include -#define AQH_MSGIPC_ERROR_OFFS_ERRORCODE 0 /* 2 bytes */ -#define AQH_MSGIPC_ERROR_MINSIZE (GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_ERROR_OFFS_ERRORCODE+2) +#define AQH_MSGIPC_RESULT_OFFS_RESULTCODE 0 /* 2 bytes */ + +#define AQH_MSGIPC_RESULT_MINSIZE (GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_RESULT_OFFS_RESULTCODE+2) -GWEN_MSG *AQH_ErrorIpcMsg_new(uint16_t code, uint16_t errorCode) +GWEN_MSG *AQH_ResultIpcMsg_new(uint16_t code, uint16_t errorCode) { GWEN_MSG *msg; uint8_t *ptr; - msg=GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_NODES_ID, AQH_IPC_PROTOCOL_NODES_VERSION, code, AQH_MSGIPC_ERROR_MINSIZE, NULL); + msg=GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_RESULT_ID, AQH_IPC_PROTOCOL_RESULT_VERSION, code, AQH_MSGIPC_RESULT_MINSIZE, NULL); ptr=GWEN_Msg_GetBuffer(msg); - ptr[GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_ERROR_OFFS_ERRORCODE+0]=errorCode & 0xff; - ptr[GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_ERROR_OFFS_ERRORCODE+1]=errorCode & 0xff; + ptr[GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_RESULT_OFFS_RESULTCODE+0]=errorCode & 0xff; + ptr[GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_RESULT_OFFS_RESULTCODE+1]=errorCode & 0xff; return msg; } -uint16_t AQH_ErrorIpcMsg_GetErrorCode(const GWEN_MSG *msg) +uint16_t AQH_ResultIpcMsg_GetResultCode(const GWEN_MSG *msg) { - return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_ERROR_OFFS_ERRORCODE, 0); + return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_RESULT_OFFS_RESULTCODE, 0); } -void AQH_ErrorIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) +void AQH_ResultIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) { - if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGIPC_ERROR_MINSIZE) { + if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGIPC_RESULT_MINSIZE) { GWEN_Buffer_AppendArgs(dbuf, "ERROR (code=%d, proto=%d, proto version=%d, error=%d)\n", GWEN_IpcMsg_GetCode(msg), GWEN_IpcMsg_GetProtoId(msg), GWEN_IpcMsg_GetProtoVersion(msg), - AQH_ErrorIpcMsg_GetErrorCode(msg)); + AQH_ResultIpcMsg_GetResultCode(msg)); } } diff --git a/aqhome/ipc/nodes/msg_ipc_error.h b/aqhome/ipc/msg_ipc_result.h similarity index 57% rename from aqhome/ipc/nodes/msg_ipc_error.h rename to aqhome/ipc/msg_ipc_result.h index 29d2123..0b54916 100644 --- a/aqhome/ipc/nodes/msg_ipc_error.h +++ b/aqhome/ipc/msg_ipc_result.h @@ -6,8 +6,8 @@ * should have received along with this file. ****************************************************************************/ -#ifndef AQH_MSG_IPC_ERROR_H -#define AQH_MSG_IPC_ERROR_H +#ifndef AQH_MSG_IPC_RESULT_H +#define AQH_MSG_IPC_RESULT_H #include @@ -18,13 +18,17 @@ #include -#define AQH_MSG_IPC_ERROR_OK 0 +#define AQH_IPC_PROTOCOL_RESULT_ID 0 +#define AQH_IPC_PROTOCOL_RESULT_VERSION 1 + + +#define AQH_MSG_IPC_SUCCESS 0 #define AQH_MSG_IPC_ERROR_NODATA 1 -AQHOME_API GWEN_MSG *AQH_ErrorIpcMsg_new(uint16_t code, uint16_t errorCode); -AQHOME_API uint16_t AQH_ErrorIpcMsg_GetErrorCode(const GWEN_MSG *msg); -AQHOME_API void AQH_ErrorIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); +AQHOME_API GWEN_MSG *AQH_ResultIpcMsg_new(uint16_t code, uint16_t errorCode); +AQHOME_API uint16_t AQH_ResultIpcMsg_GetResultCode(const GWEN_MSG *msg); +AQHOME_API void AQH_ResultIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); #endif diff --git a/aqhome/ipc/nodes/0BUILD b/aqhome/ipc/nodes/0BUILD index 7b08d63..dfd7f0c 100644 --- a/aqhome/ipc/nodes/0BUILD +++ b/aqhome/ipc/nodes/0BUILD @@ -49,7 +49,6 @@ msg_ipc_forward.h msg_ipc_value.h msg_ipc_ping.h - msg_ipc_error.h msg_ipc_setaccmsggrps.h msg_ipc_getdevices_req.h msg_ipc_getdevices_rsp.h @@ -68,7 +67,6 @@ msg_ipc_forward.c msg_ipc_value.c msg_ipc_ping.c - msg_ipc_error.c msg_ipc_setaccmsggrps.c msg_ipc_getdevices_req.c msg_ipc_getdevices_rsp.c