aqhome: implemented IPC client, fixed some bugs.

sending a PING request and retrieving the PONG response works now.
This commit is contained in:
Martin Preuss
2023-04-16 23:22:03 +02:00
parent c00b90bf28
commit d53b061aed
34 changed files with 549 additions and 158 deletions

View File

@@ -9,6 +9,9 @@
#include "aqhome/msg/endpoint_log.h"
#include "aqhome/msg/endpoint_tty.h"
#include "aqhome/ipc/endpoint_node_ipc_tcpd.h"
#include "aqhome/ipc/endpoint_ipc_tcpc.h"
#include "aqhome/ipc/msg_ipc_ping.h"
#include "aqhome/ipc/msg_ipc_forward.h"
#include "aqhome/mqtt/endpoint_mqttc.h"
#include "aqhome/mqtt/msg_mqtt_connect.h"
#include "aqhome/mqtt/msg_mqtt_connack.h"
@@ -265,13 +268,78 @@ int testMqttConnection()
int testIpcConnection()
{
int rv;
GWEN_MSG_ENDPOINT_MGR *emgr;
GWEN_MSG_ENDPOINT *epTcp;
GWEN_MSG *msgOut;
rv=AQH_Init();
if (rv<0) {
}
//emgr=AQH_MsgManager_new(0xc0);
emgr=GWEN_MsgEndpointMgr_new();
epTcp=AQH_IpcTcpClientEndpoint_new("127.0.0.1", 45454, "IPCClient", 0);
if (epTcp==NULL) {
DBG_ERROR(NULL, "Error creating endpoint TCPc");
return 2;
}
GWEN_MsgEndpointMgr_AddEndpoint(emgr, epTcp);
fprintf(stdout, "Sending PING\n");
msgOut=AQH_PingIpcMsg_new(AQH_MSGTYPE_IPC_PING, 1);
if (msgOut==NULL) {
DBG_ERROR(NULL, "Error creating message");
return 2;
}
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
fprintf(stdout, "Waiting for response\n");
for (;;) {
GWEN_MSG *msg;
DBG_DEBUG(AQH_LOGDOMAIN, "Next loop");
//GWEN_MsgManager_LoopOnce(emgr);
GWEN_MsgEndpointMgr_RunAllEndpoints(emgr);
GWEN_MsgEndpointMgr_IoLoopOnce(emgr);
msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epTcp);
if (msg) {
DBG_ERROR(NULL, "Received this message:");
GWEN_Text_DumpString((const char*) GWEN_Msg_GetConstBuffer(msg), GWEN_Msg_GetBytesInBuffer(msg), 2);
if (GWEN_IpcMsg_GetCode(msg)==AQH_MSGTYPE_IPC_FORWARD) {
GWEN_MSG *nodeMsg;
DBG_ERROR(AQH_LOGDOMAIN, "Received FORWARD msg");
nodeMsg=AQH_ForwardIpcMsg_GetCopyOfNodeMsg(msg);
if (nodeMsg) {
DBG_ERROR(AQH_LOGDOMAIN, "Received node msg (%d)", AQH_NodeMsg_GetMsgType(nodeMsg));
if (AQH_NodeMsg_GetMsgType(nodeMsg)==AQH_MSG_TYPE_PONG) {
DBG_ERROR(AQH_LOGDOMAIN, "Received PONG");
GWEN_Msg_free(msg);
break;
}
}
}
GWEN_Msg_free(msg);
}
}
return 0;
}
int main(int argc, char **argv)
{
//return testEndpoints();
//return testMsgMqttConnect();
return testMqttConnection();
//return testMqttConnection();
return testIpcConnection();
}