aqhome: completed adapting to msgio2 interface.

This commit is contained in:
Martin Preuss
2023-07-12 13:33:04 +02:00
parent 39987b31c7
commit 08c3875a26
66 changed files with 1765 additions and 3914 deletions

View File

@@ -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 {