aqhome: completed adapting to msgio2 interface.
This commit is contained in:
@@ -13,9 +13,9 @@
|
||||
#include "./flash.h"
|
||||
#include "./utils.h"
|
||||
|
||||
#include "aqhome/ipc/endpoint2_ipc.h"
|
||||
#include "aqhome/ipc/msg_ipc_setaccmsggrps.h"
|
||||
#include "aqhome/ipc/msg_ipc_forward.h"
|
||||
#include "aqhome/ipc/endpoint_ipc_tcpc.h"
|
||||
#include "aqhome/msg/msg_node.h"
|
||||
#include "aqhome/msg/msg_flashready.h"
|
||||
#include "aqhome/msg/msg_flashstart.h"
|
||||
@@ -29,7 +29,6 @@
|
||||
#include <gwenhywfar/args.h>
|
||||
#include <gwenhywfar/i18n.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
#include <gwenhywfar/endpoint_tcpc.h>
|
||||
#include <gwenhywfar/text.h>
|
||||
|
||||
#include <time.h>
|
||||
@@ -48,30 +47,28 @@ static int _doFlash(GWEN_DB_NODE *dbArgs);
|
||||
|
||||
static AQH_FLASHRECORD_LIST *_readHexfileIntoFlashRecordList(const char *hexFilename);
|
||||
|
||||
static int _rebootNode(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *epTcp, unsigned int uid, int timeoutInSeconds);
|
||||
static int _performFlashProcedure(GWEN_MSG_ENDPOINT_MGR *emgr,
|
||||
GWEN_MSG_ENDPOINT *epTcp,
|
||||
static int _rebootNode(GWEN_MSG_ENDPOINT2 *epTcp, unsigned int uid, int timeoutInSeconds);
|
||||
static int _performFlashProcedure(GWEN_MSG_ENDPOINT2 *epTcp,
|
||||
unsigned int uid,
|
||||
const AQH_FLASHRECORD_LIST *flashRecordList,
|
||||
int pageSize,
|
||||
int timeoutInSeconds);
|
||||
|
||||
|
||||
static int _flashStart(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *epTcp, unsigned int uid, int timeoutInSeconds);
|
||||
static int _flashStart(GWEN_MSG_ENDPOINT2 *epTcp, unsigned int uid, int timeoutInSeconds);
|
||||
|
||||
|
||||
static GWEN_MSG *_waitForFlashReadyMessageForUid(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *epTcp,
|
||||
static GWEN_MSG *_waitForFlashReadyMessageForUid(GWEN_MSG_ENDPOINT2 *epTcp,
|
||||
unsigned int uid, int timeoutInSeconds);
|
||||
static int _sendRebootRequest(GWEN_MSG_ENDPOINT *epTcp, unsigned int uid);
|
||||
static int _sendFlashStart(GWEN_MSG_ENDPOINT *epTcp, unsigned int uid);
|
||||
static int _waitForFlashResponseMessage(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds);
|
||||
static int _waitForRebootResponseMessage(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds);
|
||||
static int _sendFlashRecord(GWEN_MSG_ENDPOINT_MGR *emgr,
|
||||
GWEN_MSG_ENDPOINT *epTcp,
|
||||
static int _sendRebootRequest(GWEN_MSG_ENDPOINT2 *epTcp, unsigned int uid);
|
||||
static int _sendFlashStart(GWEN_MSG_ENDPOINT2 *epTcp, unsigned int uid);
|
||||
static int _waitForFlashResponseMessage(GWEN_MSG_ENDPOINT2 *epTcp, int timeoutInSeconds);
|
||||
static int _waitForRebootResponseMessage(GWEN_MSG_ENDPOINT2 *epTcp, int timeoutInSeconds);
|
||||
static int _sendFlashRecord(GWEN_MSG_ENDPOINT2 *epTcp,
|
||||
const AQH_FLASHRECORD *flashRecord,
|
||||
uint16_t pageSize,
|
||||
int timeoutInSeconds);
|
||||
static int _sendFlashEnd(GWEN_MSG_ENDPOINT *epTcp, int reason);
|
||||
static int _sendFlashEnd(GWEN_MSG_ENDPOINT2 *epTcp, int reason);
|
||||
|
||||
|
||||
|
||||
@@ -188,8 +185,7 @@ int AQH_Tool_Flash(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
||||
|
||||
int _doFlash(GWEN_DB_NODE *dbArgs)
|
||||
{
|
||||
GWEN_MSG_ENDPOINT_MGR *emgr;
|
||||
GWEN_MSG_ENDPOINT *epTcp;
|
||||
GWEN_MSG_ENDPOINT2 *epTcp;
|
||||
int rv;
|
||||
int timeoutInSeconds;
|
||||
int doReboot;
|
||||
@@ -216,28 +212,26 @@ int _doFlash(GWEN_DB_NODE *dbArgs)
|
||||
}
|
||||
|
||||
/* setup client connection */
|
||||
emgr=GWEN_MsgEndpointMgr_new();
|
||||
|
||||
epTcp=Utils_SetupIpcEndpoint(emgr, dbArgs);
|
||||
epTcp=Utils_SetupIpcEndpoint(dbArgs);
|
||||
if (epTcp==NULL) {
|
||||
DBG_ERROR(NULL, "ERROR creating TCP connection");
|
||||
return 3;
|
||||
}
|
||||
GWEN_MsgEndpointMgr_AddEndpoint(emgr, epTcp);
|
||||
|
||||
/* declare accepted message type groups */
|
||||
rv=Utils_SendAcceptedMsgGroups(epTcp, AQH_MSG_TYPEGROUP_FLASH);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
GWEN_MsgEndpoint2_free(epTcp);
|
||||
return 3;
|
||||
}
|
||||
|
||||
if (doReboot) {
|
||||
fprintf(stdout, "Sending REBOOT request\n");
|
||||
rv=_rebootNode(emgr, epTcp, uid, timeoutInSeconds);
|
||||
rv=_rebootNode(epTcp, uid, timeoutInSeconds);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
GWEN_MsgEndpointMgr_free(emgr);
|
||||
GWEN_MsgEndpoint2_free(epTcp);
|
||||
return 3;
|
||||
}
|
||||
fprintf(stdout, "Reboot in progress\n");
|
||||
@@ -245,10 +239,10 @@ int _doFlash(GWEN_DB_NODE *dbArgs)
|
||||
|
||||
/* wait for FLASH_READY message */
|
||||
fprintf(stdout, "Waiting for node to become ready for flashing\n");
|
||||
msg=_waitForFlashReadyMessageForUid(emgr, epTcp, uid, timeoutInSeconds);
|
||||
msg=_waitForFlashReadyMessageForUid(epTcp, uid, timeoutInSeconds);
|
||||
if (msg==NULL) {
|
||||
DBG_INFO(NULL, "No FLASH_READY message received.");
|
||||
GWEN_MsgEndpointMgr_free(emgr);
|
||||
GWEN_MsgEndpoint2_free(epTcp);
|
||||
return 3;
|
||||
}
|
||||
DBG_INFO(NULL, "FLASH_READY message received");
|
||||
@@ -257,18 +251,18 @@ int _doFlash(GWEN_DB_NODE *dbArgs)
|
||||
GWEN_Msg_free(msg);
|
||||
|
||||
/* perform flash */
|
||||
rv=_performFlashProcedure(emgr, epTcp, uid, flashRecordList, pageSize, timeoutInSeconds);
|
||||
rv=_performFlashProcedure(epTcp, uid, flashRecordList, pageSize, timeoutInSeconds);
|
||||
if (rv<0) {
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
GWEN_MsgEndpointMgr_free(emgr);
|
||||
GWEN_MsgEndpoint2_free(epTcp);
|
||||
AQH_FlashRecord_List_free(flashRecordList);
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
AQH_FlashRecord_List_free(flashRecordList);
|
||||
GWEN_MsgEndpointMgr_free(emgr);
|
||||
GWEN_MsgEndpoint2_free(epTcp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -299,7 +293,7 @@ AQH_FLASHRECORD_LIST *_readHexfileIntoFlashRecordList(const char *hexFilename)
|
||||
|
||||
|
||||
|
||||
int _rebootNode(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *epTcp, unsigned int uid, int timeoutInSeconds)
|
||||
int _rebootNode(GWEN_MSG_ENDPOINT2 *epTcp, unsigned int uid, int timeoutInSeconds)
|
||||
{
|
||||
int rv;
|
||||
|
||||
@@ -311,7 +305,7 @@ int _rebootNode(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *epTcp, unsigned
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv=_waitForRebootResponseMessage(emgr, epTcp, timeoutInSeconds);
|
||||
rv=_waitForRebootResponseMessage(epTcp, timeoutInSeconds);
|
||||
if (rv!=0) {
|
||||
DBG_INFO(NULL, "Bad or no reboot response received (%d).", rv);
|
||||
return rv;
|
||||
@@ -322,8 +316,7 @@ int _rebootNode(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *epTcp, unsigned
|
||||
|
||||
|
||||
|
||||
int _performFlashProcedure(GWEN_MSG_ENDPOINT_MGR *emgr,
|
||||
GWEN_MSG_ENDPOINT *epTcp,
|
||||
int _performFlashProcedure(GWEN_MSG_ENDPOINT2 *epTcp,
|
||||
unsigned int uid,
|
||||
const AQH_FLASHRECORD_LIST *flashRecordList,
|
||||
int pageSize,
|
||||
@@ -333,7 +326,7 @@ int _performFlashProcedure(GWEN_MSG_ENDPOINT_MGR *emgr,
|
||||
const AQH_FLASHRECORD *flashRecord;
|
||||
|
||||
fprintf(stdout, "Sending FLASH_START\n");
|
||||
rv=_flashStart(emgr, epTcp, uid, timeoutInSeconds);
|
||||
rv=_flashStart(epTcp, uid, timeoutInSeconds);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
return rv;
|
||||
@@ -343,7 +336,7 @@ int _performFlashProcedure(GWEN_MSG_ENDPOINT_MGR *emgr,
|
||||
flashRecord=AQH_FlashRecord_List_First(flashRecordList);
|
||||
while(flashRecord) {
|
||||
DBG_ERROR(NULL, "Sending flash record at %08x", AQH_FlashRecord_GetAddress(flashRecord));
|
||||
rv=_sendFlashRecord(emgr, epTcp, flashRecord, pageSize, timeoutInSeconds);
|
||||
rv=_sendFlashRecord(epTcp, flashRecord, pageSize, timeoutInSeconds);
|
||||
if (rv!=0) {
|
||||
DBG_ERROR(NULL, "Error sending flash data (%d)", rv);
|
||||
return rv;
|
||||
@@ -357,7 +350,7 @@ int _performFlashProcedure(GWEN_MSG_ENDPOINT_MGR *emgr,
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv=Utils_FlushOutMessageQueue(emgr, epTcp, timeoutInSeconds);
|
||||
rv=Utils_FlushOutMessageQueue(epTcp, timeoutInSeconds);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
return rv;
|
||||
@@ -368,7 +361,7 @@ int _performFlashProcedure(GWEN_MSG_ENDPOINT_MGR *emgr,
|
||||
|
||||
|
||||
|
||||
int _flashStart(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *epTcp, unsigned int uid, int timeoutInSeconds)
|
||||
int _flashStart(GWEN_MSG_ENDPOINT2 *epTcp, unsigned int uid, int timeoutInSeconds)
|
||||
{
|
||||
int rv;
|
||||
int i;
|
||||
@@ -385,7 +378,7 @@ int _flashStart(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *epTcp, unsigned
|
||||
}
|
||||
|
||||
/* wait for response */
|
||||
rv=_waitForFlashResponseMessage(emgr, epTcp, timeoutInSeconds);
|
||||
rv=_waitForFlashResponseMessage(epTcp, timeoutInSeconds);
|
||||
if (rv!=0) {
|
||||
DBG_INFO(NULL, "Bad or no response received (%d).", rv);
|
||||
return rv;
|
||||
@@ -406,8 +399,7 @@ int _flashStart(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *epTcp, unsigned
|
||||
|
||||
|
||||
|
||||
GWEN_MSG *_waitForFlashReadyMessageForUid(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *epTcp,
|
||||
unsigned int uid, int timeoutInSeconds)
|
||||
GWEN_MSG *_waitForFlashReadyMessageForUid(GWEN_MSG_ENDPOINT2 *epTcp, unsigned int uid, int timeoutInSeconds)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -415,7 +407,7 @@ GWEN_MSG *_waitForFlashReadyMessageForUid(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_
|
||||
GWEN_MSG *msg;
|
||||
unsigned int receivedUid;
|
||||
|
||||
msg=Utils_WaitForSpecificNodeMessage(emgr, epTcp, AQH_MSG_TYPE_FLASH_READY, 0, timeoutInSeconds);
|
||||
msg=Utils_WaitForSpecificNodeMessage(epTcp, AQH_MSG_TYPE_FLASH_READY, 0, timeoutInSeconds);
|
||||
if (msg==NULL) {
|
||||
DBG_INFO(NULL, "No FLASH_READY message received.");
|
||||
return NULL;
|
||||
@@ -436,11 +428,11 @@ GWEN_MSG *_waitForFlashReadyMessageForUid(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_
|
||||
|
||||
|
||||
|
||||
int _waitForRebootResponseMessage(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds)
|
||||
int _waitForRebootResponseMessage(GWEN_MSG_ENDPOINT2 *epTcp, int timeoutInSeconds)
|
||||
{
|
||||
GWEN_MSG *msg;
|
||||
|
||||
msg=Utils_WaitForSpecificNodeMessage(emgr, epTcp, AQH_MSG_TYPE_REBOOT_RSP, 0, timeoutInSeconds);
|
||||
msg=Utils_WaitForSpecificNodeMessage(epTcp, AQH_MSG_TYPE_REBOOT_RSP, 0, timeoutInSeconds);
|
||||
if (msg==NULL) {
|
||||
DBG_INFO(NULL, "No REBOOT_RSP message received.");
|
||||
return GWEN_ERROR_IO;
|
||||
@@ -451,12 +443,12 @@ int _waitForRebootResponseMessage(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT
|
||||
|
||||
|
||||
|
||||
int _waitForFlashResponseMessage(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds)
|
||||
int _waitForFlashResponseMessage(GWEN_MSG_ENDPOINT2 *epTcp, int timeoutInSeconds)
|
||||
{
|
||||
GWEN_MSG *msg;
|
||||
int responseCode;
|
||||
|
||||
msg=Utils_WaitForSpecificNodeMessage(emgr, epTcp, AQH_MSG_TYPE_FLASH_RSP, 0, timeoutInSeconds);
|
||||
msg=Utils_WaitForSpecificNodeMessage(epTcp, AQH_MSG_TYPE_FLASH_RSP, 0, timeoutInSeconds);
|
||||
if (msg==NULL) {
|
||||
DBG_INFO(NULL, "No FLASH_RSP message received.");
|
||||
return GWEN_ERROR_IO;
|
||||
@@ -468,7 +460,7 @@ int _waitForFlashResponseMessage(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT
|
||||
|
||||
|
||||
|
||||
int _sendRebootRequest(GWEN_MSG_ENDPOINT *epTcp, unsigned int uid)
|
||||
int _sendRebootRequest(GWEN_MSG_ENDPOINT2 *epTcp, unsigned int uid)
|
||||
{
|
||||
GWEN_MSG *msgNode;
|
||||
GWEN_MSG *msgOut;
|
||||
@@ -480,14 +472,14 @@ int _sendRebootRequest(GWEN_MSG_ENDPOINT *epTcp, unsigned int uid)
|
||||
}
|
||||
|
||||
msgOut=AQH_ForwardIpcMsg_new(AQH_MSGTYPE_IPC_FORWARD, GWEN_Msg_GetConstBuffer(msgNode), GWEN_Msg_GetBytesInBuffer(msgNode));
|
||||
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
|
||||
GWEN_MsgEndpoint2_AddSendMessage(epTcp, msgOut);
|
||||
GWEN_Msg_free(msgNode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _sendFlashStart(GWEN_MSG_ENDPOINT *epTcp, unsigned int uid)
|
||||
int _sendFlashStart(GWEN_MSG_ENDPOINT2 *epTcp, unsigned int uid)
|
||||
{
|
||||
GWEN_MSG *msgNode;
|
||||
GWEN_MSG *msgOut;
|
||||
@@ -499,14 +491,14 @@ int _sendFlashStart(GWEN_MSG_ENDPOINT *epTcp, unsigned int uid)
|
||||
}
|
||||
|
||||
msgOut=AQH_ForwardIpcMsg_new(AQH_MSGTYPE_IPC_FORWARD, GWEN_Msg_GetConstBuffer(msgNode), GWEN_Msg_GetBytesInBuffer(msgNode));
|
||||
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
|
||||
GWEN_MsgEndpoint2_AddSendMessage(epTcp, msgOut);
|
||||
GWEN_Msg_free(msgNode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _sendFlashEnd(GWEN_MSG_ENDPOINT *epTcp, int reason)
|
||||
int _sendFlashEnd(GWEN_MSG_ENDPOINT2 *epTcp, int reason)
|
||||
{
|
||||
GWEN_MSG *msgNode;
|
||||
GWEN_MSG *msgOut;
|
||||
@@ -518,15 +510,14 @@ int _sendFlashEnd(GWEN_MSG_ENDPOINT *epTcp, int reason)
|
||||
}
|
||||
|
||||
msgOut=AQH_ForwardIpcMsg_new(AQH_MSGTYPE_IPC_FORWARD, GWEN_Msg_GetConstBuffer(msgNode), GWEN_Msg_GetBytesInBuffer(msgNode));
|
||||
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
|
||||
GWEN_MsgEndpoint2_AddSendMessage(epTcp, msgOut);
|
||||
GWEN_Msg_free(msgNode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _sendFlashRecord(GWEN_MSG_ENDPOINT_MGR *emgr,
|
||||
GWEN_MSG_ENDPOINT *epTcp,
|
||||
int _sendFlashRecord(GWEN_MSG_ENDPOINT2 *epTcp,
|
||||
const AQH_FLASHRECORD *flashRecord,
|
||||
uint16_t pageSize,
|
||||
int timeoutInSeconds)
|
||||
@@ -565,10 +556,10 @@ int _sendFlashRecord(GWEN_MSG_ENDPOINT_MGR *emgr,
|
||||
}
|
||||
|
||||
msgOut=AQH_ForwardIpcMsg_new(AQH_MSGTYPE_IPC_FORWARD, GWEN_Msg_GetConstBuffer(msgNode), GWEN_Msg_GetBytesInBuffer(msgNode));
|
||||
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
|
||||
GWEN_MsgEndpoint2_AddSendMessage(epTcp, msgOut);
|
||||
GWEN_Msg_free(msgNode);
|
||||
|
||||
rv=_waitForFlashResponseMessage(emgr, epTcp, timeoutInSeconds);
|
||||
rv=_waitForFlashResponseMessage(epTcp, timeoutInSeconds);
|
||||
if (rv==0)
|
||||
break;
|
||||
else {
|
||||
|
||||
@@ -13,10 +13,10 @@
|
||||
#include "./getdevices.h"
|
||||
#include "./utils.h"
|
||||
|
||||
#include "aqhome/ipc/endpoint2_ipc.h"
|
||||
#include "aqhome/ipc/msg_ipc_getdevices_req.h"
|
||||
#include "aqhome/ipc/msg_ipc_getdevices_rsp.h"
|
||||
#include "aqhome/ipc/msg_ipc_error.h"
|
||||
#include "aqhome/ipc/endpoint_ipc_tcpc.h"
|
||||
#include "aqhome/msg/msg_node.h"
|
||||
|
||||
#include <gwenhywfar/args.h>
|
||||
@@ -35,7 +35,7 @@
|
||||
|
||||
|
||||
static int _doGetDevices(GWEN_DB_NODE *dbArgs);
|
||||
static int _sendGetDevices(GWEN_MSG_ENDPOINT *epTcp);
|
||||
static int _sendGetDevices(GWEN_MSG_ENDPOINT2 *epTcp);
|
||||
|
||||
|
||||
|
||||
@@ -119,19 +119,15 @@ int AQH_Tool_GetDevices(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
||||
|
||||
int _doGetDevices(GWEN_DB_NODE *dbArgs)
|
||||
{
|
||||
GWEN_MSG_ENDPOINT_MGR *emgr;
|
||||
GWEN_MSG_ENDPOINT *epTcp;
|
||||
GWEN_MSG_ENDPOINT2 *epTcp;
|
||||
int rv;
|
||||
int timeoutInSeconds;
|
||||
|
||||
emgr=GWEN_MsgEndpointMgr_new();
|
||||
|
||||
epTcp=Utils_SetupIpcEndpoint(emgr, dbArgs);
|
||||
epTcp=Utils_SetupIpcEndpoint(dbArgs);
|
||||
if (epTcp==NULL) {
|
||||
DBG_ERROR(NULL, "ERROR creating TCP connection");
|
||||
return 2;
|
||||
}
|
||||
GWEN_MsgEndpointMgr_AddEndpoint(emgr, epTcp);
|
||||
|
||||
timeoutInSeconds=GWEN_DB_GetIntValue(dbArgs, "timeout", 0, 5);
|
||||
|
||||
@@ -151,10 +147,10 @@ int _doGetDevices(GWEN_DB_NODE *dbArgs)
|
||||
GWEN_MSG *msg;
|
||||
uint16_t code;
|
||||
|
||||
msg=Utils_WaitForSpecificIpcMessage(emgr, epTcp, AQH_MSGTYPE_IPC_GETDEVICES_RSP, timeoutInSeconds);
|
||||
msg=Utils_WaitForSpecificIpcMessage(epTcp, AQH_MSGTYPE_IPC_GETDEVICES_RSP, timeoutInSeconds);
|
||||
if (msg==NULL) {
|
||||
DBG_INFO(NULL, "No GET_DEVICE response received.");
|
||||
GWEN_MsgEndpointMgr_free(emgr);
|
||||
GWEN_MsgEndpoint2_free(epTcp);
|
||||
return 2;
|
||||
}
|
||||
code=GWEN_IpcMsg_GetCode(msg);
|
||||
@@ -201,13 +197,13 @@ int _doGetDevices(GWEN_DB_NODE *dbArgs)
|
||||
}
|
||||
}
|
||||
|
||||
GWEN_MsgEndpointMgr_free(emgr);
|
||||
GWEN_MsgEndpoint2_free(epTcp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _sendGetDevices(GWEN_MSG_ENDPOINT *epTcp)
|
||||
int _sendGetDevices(GWEN_MSG_ENDPOINT2 *epTcp)
|
||||
{
|
||||
GWEN_MSG *msgOut;
|
||||
|
||||
@@ -216,7 +212,7 @@ int _sendGetDevices(GWEN_MSG_ENDPOINT *epTcp)
|
||||
DBG_ERROR(NULL, "Error creating message");
|
||||
return GWEN_ERROR_GENERIC;
|
||||
}
|
||||
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
|
||||
GWEN_MsgEndpoint2_AddSendMessage(epTcp, msgOut);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include "aqhome/ipc/msg_ipc_setaccmsggrps.h"
|
||||
#include "aqhome/ipc/msg_ipc_ping.h"
|
||||
#include "aqhome/ipc/msg_ipc_forward.h"
|
||||
#include "aqhome/ipc/endpoint_ipc_tcpc.h"
|
||||
#include "aqhome/ipc/endpoint2_ipc.h"
|
||||
#include "aqhome/msg/msg_node.h"
|
||||
|
||||
#include <gwenhywfar/args.h>
|
||||
@@ -35,7 +35,7 @@
|
||||
|
||||
|
||||
static int _doPing(GWEN_DB_NODE *dbArgs);
|
||||
static int _sendPing(GWEN_MSG_ENDPOINT *epTcp, int nodeAddr);
|
||||
static int _sendPing(GWEN_MSG_ENDPOINT2 *epTcp, int nodeAddr);
|
||||
|
||||
|
||||
|
||||
@@ -130,21 +130,17 @@ int AQH_Tool_Ping(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
||||
|
||||
int _doPing(GWEN_DB_NODE *dbArgs)
|
||||
{
|
||||
GWEN_MSG_ENDPOINT_MGR *emgr;
|
||||
GWEN_MSG_ENDPOINT *epTcp;
|
||||
GWEN_MSG_ENDPOINT2 *epTcp;
|
||||
int rv;
|
||||
int nodeAddr;
|
||||
int timeoutInSeconds;
|
||||
GWEN_MSG *msg;
|
||||
|
||||
emgr=GWEN_MsgEndpointMgr_new();
|
||||
|
||||
epTcp=Utils_SetupIpcEndpoint(emgr, dbArgs);
|
||||
epTcp=Utils_SetupIpcEndpoint(dbArgs);
|
||||
if (epTcp==NULL) {
|
||||
DBG_ERROR(NULL, "ERROR creating TCP connection");
|
||||
return 2;
|
||||
}
|
||||
GWEN_MsgEndpointMgr_AddEndpoint(emgr, epTcp);
|
||||
|
||||
nodeAddr=GWEN_DB_GetIntValue(dbArgs, "nodeAddr", 0, 0);
|
||||
timeoutInSeconds=GWEN_DB_GetIntValue(dbArgs, "timeout", 0, 5);
|
||||
@@ -163,21 +159,20 @@ int _doPing(GWEN_DB_NODE *dbArgs)
|
||||
return 2;
|
||||
}
|
||||
|
||||
msg=Utils_WaitForSpecificNodeMessage(emgr, epTcp, AQH_MSG_TYPE_PONG, nodeAddr, timeoutInSeconds);
|
||||
msg=Utils_WaitForSpecificNodeMessage(epTcp, AQH_MSG_TYPE_PONG, nodeAddr, timeoutInSeconds);
|
||||
if (msg==NULL) {
|
||||
DBG_INFO(NULL, "No PONG response received.");
|
||||
GWEN_MsgEndpointMgr_free(emgr);
|
||||
return 2;
|
||||
}
|
||||
|
||||
fprintf(stdout, "PONG response received\n");
|
||||
GWEN_MsgEndpointMgr_free(emgr);
|
||||
GWEN_MsgEndpoint2_free(epTcp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _sendPing(GWEN_MSG_ENDPOINT *epTcp, int nodeAddr)
|
||||
int _sendPing(GWEN_MSG_ENDPOINT2 *epTcp, int nodeAddr)
|
||||
{
|
||||
GWEN_MSG *msgOut;
|
||||
|
||||
@@ -186,7 +181,7 @@ int _sendPing(GWEN_MSG_ENDPOINT *epTcp, int nodeAddr)
|
||||
DBG_ERROR(NULL, "Error creating message");
|
||||
return GWEN_ERROR_GENERIC;
|
||||
}
|
||||
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
|
||||
GWEN_MsgEndpoint2_AddSendMessage(epTcp, msgOut);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,10 +13,11 @@
|
||||
|
||||
#include "./utils.h"
|
||||
|
||||
#include "aqhome/ipc/endpoint_ipc_tcpc.h"
|
||||
#include "aqhome/ipc/endpoint2_ipc.h"
|
||||
#include "aqhome/ipc/msg_ipc_setaccmsggrps.h"
|
||||
#include "aqhome/ipc/msg_ipc_forward.h"
|
||||
|
||||
#include <gwenhywfar/endpoint2_tcpc.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
#include <time.h>
|
||||
@@ -25,28 +26,35 @@
|
||||
|
||||
|
||||
|
||||
GWEN_MSG_ENDPOINT *Utils_SetupIpcEndpoint(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_DB_NODE *dbArgs)
|
||||
GWEN_MSG_ENDPOINT2 *Utils_SetupIpcEndpoint(GWEN_DB_NODE *dbArgs)
|
||||
{
|
||||
GWEN_MSG_ENDPOINT *epTcp;
|
||||
GWEN_MSG_ENDPOINT2 *epTcp;
|
||||
const char *tcpAddress;
|
||||
int tcpPort;
|
||||
int rv;
|
||||
|
||||
tcpAddress=GWEN_DB_GetCharValue(dbArgs, "tcpAddress", 0, "127.0.0.1");
|
||||
tcpPort=GWEN_DB_GetIntValue(dbArgs, "tcpPort", 0, 45454);
|
||||
|
||||
DBG_INFO(NULL, "Setup tcp client endpoint to %s:%d", tcpAddress, tcpPort);
|
||||
epTcp=AQH_IpcTcpClientEndpoint_new(tcpAddress, tcpPort, "aqhome-tool-IPC", 0);
|
||||
epTcp=AQH_IpcEndpoint2_CreateIpcTcpClient(tcpAddress, tcpPort, "aqhome-tool-IPC", 0);
|
||||
if (epTcp==NULL) {
|
||||
DBG_ERROR(NULL, "Error creating endpoint TCPc");
|
||||
return NULL;
|
||||
}
|
||||
rv=GWEN_TcpcEndpoint2_StartConnect(epTcp);
|
||||
if (rv<0 && rv!=GWEN_ERROR_IN_PROGRESS) {
|
||||
DBG_ERROR(NULL, "Error connecting (%d)", rv);
|
||||
GWEN_MsgEndpoint2_free(epTcp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return epTcp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *epTcp,
|
||||
GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT2 *epTcp,
|
||||
int msgCode,
|
||||
int nodeAddr,
|
||||
int timeoutInSeconds)
|
||||
@@ -59,9 +67,8 @@ GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG
|
||||
GWEN_MSG *msg;
|
||||
time_t now;
|
||||
|
||||
GWEN_MsgEndpointMgr_RunAllEndpoints(emgr);
|
||||
GWEN_MsgEndpointMgr_IoLoopOnce(emgr);
|
||||
msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epTcp);
|
||||
GWEN_MsgEndpoint2_IoLoop(epTcp, 2000); /* 2000 ms */
|
||||
msg=GWEN_MsgEndpoint2_TakeFirstReceivedMessage(epTcp);
|
||||
if (msg) {
|
||||
if (GWEN_IpcMsg_GetCode(msg)==AQH_MSGTYPE_IPC_FORWARD) {
|
||||
GWEN_MSG *nodeMsg;
|
||||
@@ -79,6 +86,9 @@ GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_INFO(NULL, "Received IPC message %d, ignoring", GWEN_IpcMsg_GetCode(msg));
|
||||
}
|
||||
GWEN_Msg_free(msg);
|
||||
}
|
||||
now=time(NULL);
|
||||
@@ -93,7 +103,7 @@ GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG
|
||||
|
||||
|
||||
|
||||
GWEN_MSG *Utils_WaitForSpecificIpcMessage(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *epTcp,
|
||||
GWEN_MSG *Utils_WaitForSpecificIpcMessage(GWEN_MSG_ENDPOINT2 *epTcp,
|
||||
int msgCode,
|
||||
int timeoutInSeconds)
|
||||
{
|
||||
@@ -105,9 +115,8 @@ GWEN_MSG *Utils_WaitForSpecificIpcMessage(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_
|
||||
GWEN_MSG *msg;
|
||||
time_t now;
|
||||
|
||||
GWEN_MsgEndpointMgr_RunAllEndpoints(emgr);
|
||||
GWEN_MsgEndpointMgr_IoLoopOnce(emgr);
|
||||
msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epTcp);
|
||||
GWEN_MsgEndpoint2_IoLoop(epTcp, 2000); /* 2000 ms */
|
||||
msg=GWEN_MsgEndpoint2_TakeFirstReceivedMessage(epTcp);
|
||||
if (msg) {
|
||||
uint16_t code;
|
||||
|
||||
@@ -134,17 +143,16 @@ GWEN_MSG *Utils_WaitForSpecificIpcMessage(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_
|
||||
|
||||
|
||||
|
||||
int Utils_FlushOutMessageQueue(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds)
|
||||
int Utils_FlushOutMessageQueue(GWEN_MSG_ENDPOINT2 *epTcp, int timeoutInSeconds)
|
||||
{
|
||||
time_t startTime;
|
||||
|
||||
startTime=time(NULL);
|
||||
|
||||
while(GWEN_MsgEndpoint_HaveMessageToSend(epTcp)) {
|
||||
while(GWEN_MsgEndpoint2_HaveMessageToSend(epTcp)) {
|
||||
time_t now;
|
||||
|
||||
GWEN_MsgEndpointMgr_RunAllEndpoints(emgr);
|
||||
GWEN_MsgEndpointMgr_IoLoopOnce(emgr);
|
||||
GWEN_MsgEndpoint2_IoLoop(epTcp, 2000); /* 2000 ms */
|
||||
now=time(NULL);
|
||||
if (now-startTime>timeoutInSeconds) {
|
||||
DBG_INFO(NULL, "Timeout");
|
||||
@@ -157,7 +165,7 @@ int Utils_FlushOutMessageQueue(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *e
|
||||
|
||||
|
||||
|
||||
int Utils_SendAcceptedMsgGroups(GWEN_MSG_ENDPOINT *epTcp, uint32_t groups)
|
||||
int Utils_SendAcceptedMsgGroups(GWEN_MSG_ENDPOINT2 *epTcp, uint32_t groups)
|
||||
{
|
||||
GWEN_MSG *msgOut;
|
||||
|
||||
@@ -166,7 +174,7 @@ int Utils_SendAcceptedMsgGroups(GWEN_MSG_ENDPOINT *epTcp, uint32_t groups)
|
||||
DBG_ERROR(NULL, "Error creating message");
|
||||
return GWEN_ERROR_GENERIC;
|
||||
}
|
||||
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
|
||||
GWEN_MsgEndpoint2_AddSendMessage(epTcp, msgOut);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,24 +11,24 @@
|
||||
|
||||
|
||||
#include <gwenhywfar/db.h>
|
||||
#include <gwenhywfar/endpointmgr.h>
|
||||
#include <gwenhywfar/endpoint2.h>
|
||||
|
||||
|
||||
|
||||
GWEN_MSG_ENDPOINT *Utils_SetupIpcEndpoint(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_DB_NODE *dbArgs);
|
||||
GWEN_MSG_ENDPOINT2 *Utils_SetupIpcEndpoint(GWEN_DB_NODE *dbArgs);
|
||||
|
||||
GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *epTcp,
|
||||
GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT2 *epTcp,
|
||||
int msgCode,
|
||||
int nodeAddr,
|
||||
int timeoutInSeconds);
|
||||
|
||||
GWEN_MSG *Utils_WaitForSpecificIpcMessage(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *epTcp,
|
||||
GWEN_MSG *Utils_WaitForSpecificIpcMessage(GWEN_MSG_ENDPOINT2 *epTcp,
|
||||
int msgCode,
|
||||
int timeoutInSeconds);
|
||||
|
||||
int Utils_FlushOutMessageQueue(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds);
|
||||
int Utils_FlushOutMessageQueue(GWEN_MSG_ENDPOINT2 *epTcp, int timeoutInSeconds);
|
||||
|
||||
int Utils_SendAcceptedMsgGroups(GWEN_MSG_ENDPOINT *epTcp, uint32_t groups);
|
||||
int Utils_SendAcceptedMsgGroups(GWEN_MSG_ENDPOINT2 *epTcp, uint32_t groups);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user