aqhome: implemented IPC client, fixed some bugs.
sending a PING request and retrieving the PONG response works now.
This commit is contained in:
@@ -47,9 +47,12 @@
|
||||
<headers dist="true" install="$(pkgincludedir)/ipc" >
|
||||
endpoint_node_ipc.h
|
||||
endpoint_node_ipc_tcpd.h
|
||||
endpoint_ipc_tcpc.h
|
||||
endpoint_ipc_tcpc_p.h
|
||||
msg_ipc.h
|
||||
msg_ipc_forward.h
|
||||
msg_ipc_value.h
|
||||
msg_ipc_ping.h
|
||||
</headers>
|
||||
|
||||
|
||||
@@ -62,9 +65,11 @@
|
||||
|
||||
endpoint_node_ipc.c
|
||||
endpoint_node_ipc_tcpd.c
|
||||
endpoint_ipc_tcpc.c
|
||||
msg_ipc.c
|
||||
msg_ipc_forward.c
|
||||
msg_ipc_value.c
|
||||
msg_ipc_ping.c
|
||||
</sources>
|
||||
|
||||
|
||||
|
||||
84
aqhome/ipc/endpoint_ipc_tcpc.c
Normal file
84
aqhome/ipc/endpoint_ipc_tcpc.c
Normal file
@@ -0,0 +1,84 @@
|
||||
/****************************************************************************
|
||||
* 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/endpoint_ipc_tcpc_p.h"
|
||||
|
||||
#include <gwenhywfar/endpoint_tcpc.h>
|
||||
#include <gwenhywfar/endpoint_ipc.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
|
||||
|
||||
|
||||
#define AQH_MSG_ENDPOINT_IPCC_NAME "ipc_tcpc"
|
||||
|
||||
|
||||
GWEN_INHERIT(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_IPCC)
|
||||
|
||||
|
||||
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
|
||||
static void _run(GWEN_MSG_ENDPOINT *ep);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
GWEN_MSG_ENDPOINT *AQH_IpcTcpClientEndpoint_new(const char *host, int port, const char *name, int groupId)
|
||||
{
|
||||
GWEN_MSG_ENDPOINT *ep;
|
||||
AQH_ENDPOINT_IPCC *xep;
|
||||
|
||||
ep=GWEN_TcpcEndpoint_new(host, port, name?name:AQH_MSG_ENDPOINT_IPCC_NAME, groupId);
|
||||
if (ep==NULL) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here");
|
||||
return NULL;
|
||||
}
|
||||
GWEN_IpcEndpoint_Extend(ep);
|
||||
|
||||
GWEN_NEW_OBJECT(AQH_ENDPOINT_IPCC, xep);
|
||||
GWEN_INHERIT_SETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_IPCC, ep, xep, _freeData);
|
||||
|
||||
xep->previousRunFn=GWEN_MsgEndpoint_SetRunFn(ep, _run);
|
||||
|
||||
return ep;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _freeData(void *bp, void *p)
|
||||
{
|
||||
AQH_ENDPOINT_IPCC *xep;
|
||||
|
||||
xep=(AQH_ENDPOINT_IPCC*) p;
|
||||
GWEN_FREE_OBJECT(xep);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _run(GWEN_MSG_ENDPOINT *ep)
|
||||
{
|
||||
AQH_ENDPOINT_IPCC *xep;
|
||||
|
||||
xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_IPCC, ep);
|
||||
if (xep) {
|
||||
if (xep->previousRunFn)
|
||||
xep->previousRunFn(ep);
|
||||
/* TODO: send CONNECT_REQ message, check for CONNECT_RSP */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
27
aqhome/ipc/endpoint_ipc_tcpc.h
Normal file
27
aqhome/ipc/endpoint_ipc_tcpc.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/****************************************************************************
|
||||
* 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_ENDPOINT_IPCC_TCPC_H
|
||||
#define AQH_ENDPOINT_IPCC_TCPC_H
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
|
||||
#include <gwenhywfar/endpoint.h>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
AQHOME_API GWEN_MSG_ENDPOINT *AQH_IpcTcpClientEndpoint_new(const char *host, int port, const char *name, int groupId);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
39
aqhome/ipc/endpoint_ipc_tcpc_p.h
Normal file
39
aqhome/ipc/endpoint_ipc_tcpc_p.h
Normal 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_ENDPOINT_IPCC_TCPC_P_H
|
||||
#define AQH_ENDPOINT_IPCC_TCPC_P_H
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
|
||||
#include <gwenhywfar/endpoint.h>
|
||||
|
||||
#include "aqhome/ipc/endpoint_ipc_tcpc.h"
|
||||
|
||||
|
||||
typedef struct AQH_ENDPOINT_IPCC AQH_ENDPOINT_IPCC;
|
||||
struct AQH_ENDPOINT_IPCC {
|
||||
|
||||
GWEN_MSG_ENDPOINT_RUN_FN previousRunFn;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "aqhome/ipc/endpoint_node_ipc.h"
|
||||
#include "aqhome/msg/endpoint_node.h"
|
||||
#include "aqhome/msg/msg_node.h"
|
||||
#include "aqhome/msgmanager.h"
|
||||
|
||||
#include <gwenhywfar/list.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
@@ -38,6 +39,7 @@ GWEN_MSG_ENDPOINT *AQH_TcpdIpcNodeEndpoint_new(const char *host, int port, const
|
||||
GWEN_MSG_ENDPOINT *ep;
|
||||
|
||||
ep=GWEN_IpcTcpdEndpoint_new(host, port, name?name:AQH_MSG_ENDPOINT_NODEIPCTCP_NAME, groupId);
|
||||
AQH_NodeEndpoint_Extend(ep);
|
||||
GWEN_MsgEndpoint_AddFlags(ep, AQH_MSGEP_NODE_FLAGS_NOMESSAGES);
|
||||
GWEN_MsgEndpoint_SetCreateChildFn(ep, _createChild);
|
||||
|
||||
@@ -48,8 +50,13 @@ GWEN_MSG_ENDPOINT *AQH_TcpdIpcNodeEndpoint_new(const char *host, int port, const
|
||||
|
||||
GWEN_MSG_ENDPOINT *_createChild(GWEN_MSG_ENDPOINT *ep)
|
||||
{
|
||||
GWEN_MSG_ENDPOINT *epNew;
|
||||
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Creating child endpoint for %s", GWEN_MsgEndpoint_GetName(ep));
|
||||
return AQH_IpcNodeEndpoint_new(NULL, GWEN_MsgEndpoint_GetGroupId(ep));
|
||||
epNew=AQH_IpcNodeEndpoint_new(NULL, AQH_MSGMGR_ENDPOINTGROUP_IPC);
|
||||
GWEN_MsgEndpoint_AddFlags(epNew, GWEN_MSG_ENDPOINT_FLAGS_DELONDISCONNECT);
|
||||
GWEN_MsgEndpoint_SetAcceptedGroupIds(epNew, GWEN_MsgEndpoint_GetAcceptedGroupIds(ep));
|
||||
return epNew;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#define AQH_MSGTYPE_IPC_FORWARD 0x100
|
||||
#define AQH_MSGTYPE_IPC_VALUE 0x200
|
||||
#define AQH_MSGTYPE_IPC_PING 0x300
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -58,6 +58,12 @@ uint32_t AQH_ForwardIpcMsg_GetMsgLen(const GWEN_MSG *msg)
|
||||
}
|
||||
|
||||
|
||||
GWEN_MSG *AQH_ForwardIpcMsg_GetCopyOfNodeMsg(const GWEN_MSG *msg)
|
||||
{
|
||||
return GWEN_Msg_fromBytes(AQH_ForwardIpcMsg_GetMsgPtr(msg), AQH_ForwardIpcMsg_GetMsgLen(msg));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_ForwardIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
|
||||
{
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
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 GWEN_MSG *AQH_ForwardIpcMsg_GetCopyOfNodeMsg(const GWEN_MSG *msg);
|
||||
AQHOME_API void AQH_ForwardIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);
|
||||
|
||||
|
||||
|
||||
69
aqhome/ipc/msg_ipc_ping.c
Normal file
69
aqhome/ipc/msg_ipc_ping.c
Normal file
@@ -0,0 +1,69 @@
|
||||
/****************************************************************************
|
||||
* 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_ping.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_PING_OFFS_DESTADDR 0 /* 1 bytes */
|
||||
|
||||
#define AQH_MSGIPC_PING_MINSIZE (GWEN_MSGIPC_OFFS_PAYLOAD+1)
|
||||
|
||||
|
||||
|
||||
|
||||
GWEN_MSG *AQH_PingIpcMsg_new(uint16_t code, uint8_t destAddr)
|
||||
{
|
||||
GWEN_MSG *msg;
|
||||
uint8_t *ptr;
|
||||
|
||||
msg=GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_ID, AQH_IPC_PROTOCOL_VERSION, code, AQH_MSGIPC_PING_MINSIZE, NULL);
|
||||
ptr=GWEN_Msg_GetBuffer(msg);
|
||||
ptr[GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_PING_OFFS_DESTADDR]=destAddr & 0xff;
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t AQH_PingIpcMsg_GetDestAddr(const GWEN_MSG *msg)
|
||||
{
|
||||
return GWEN_Msg_GetUint8At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_PING_OFFS_DESTADDR, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_PingIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
|
||||
{
|
||||
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGIPC_PING_MINSIZE) {
|
||||
GWEN_Buffer_AppendArgs(dbuf,
|
||||
"PING (code=%d, proto=%d, proto version=%d, dest addr=%02x)\n",
|
||||
GWEN_IpcMsg_GetCode(msg),
|
||||
GWEN_IpcMsg_GetProtoId(msg),
|
||||
GWEN_IpcMsg_GetProtoVersion(msg),
|
||||
AQH_PingIpcMsg_GetDestAddr(msg));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
31
aqhome/ipc/msg_ipc_ping.h
Normal file
31
aqhome/ipc/msg_ipc_ping.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/****************************************************************************
|
||||
* 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_PING_H
|
||||
#define AQH_MSG_IPC_PING_H
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
#include <aqhome/ipc/msg_ipc.h>
|
||||
|
||||
#include <gwenhywfar/msg.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
|
||||
|
||||
AQHOME_API GWEN_MSG *AQH_PingIpcMsg_new(uint16_t code, uint8_t destAddr);
|
||||
|
||||
AQHOME_API uint8_t AQH_PingIpcMsg_GetDestAddr(const GWEN_MSG *msg);
|
||||
|
||||
AQHOME_API void AQH_PingIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -67,65 +67,35 @@ GWEN_MSG *AQH_ValueIpcMsg_new(uint16_t code,
|
||||
|
||||
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;
|
||||
return GWEN_Msg_GetUint32At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_VALUE_OFFS_UID, 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;
|
||||
return GWEN_Msg_GetUint8At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_VALUE_OFFS_VALUEID, 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;
|
||||
return GWEN_Msg_GetUint8At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_VALUE_OFFS_VALUETYPE, 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;
|
||||
return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_VALUE_OFFS_VALUE_NOM, 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;
|
||||
return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_VALUE_OFFS_VALUE_DENOM, 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user