Rebooting and flashing a node now works!
This commit is contained in:
@@ -21,6 +21,8 @@
|
||||
#include "aqhome/msg/msg_flashstart.h"
|
||||
#include "aqhome/msg/msg_flashresponse.h"
|
||||
#include "aqhome/msg/msg_flashdata.h"
|
||||
#include "aqhome/msg/msg_flashend.h"
|
||||
#include "aqhome/msg/msg_reboot.h"
|
||||
#include "aqhome/hexfile/hexfile.h"
|
||||
#include "aqhome/hexfile/flashrecord.h"
|
||||
|
||||
@@ -39,19 +41,22 @@
|
||||
|
||||
#define FLASH_TOOL_MAX_REPEAT 16
|
||||
|
||||
#define DEBUG_FLASH
|
||||
/*#define DEBUG_FLASH*/
|
||||
|
||||
|
||||
static int _doFlash(GWEN_DB_NODE *dbArgs);
|
||||
static GWEN_MSG *_waitForFlashReadyMessageForUid(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *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 _sendFlashData(GWEN_MSG_ENDPOINT_MGR *emgr,
|
||||
GWEN_MSG_ENDPOINT *epTcp,
|
||||
const AQH_FLASHRECORD *flashRecord,
|
||||
uint16_t pageSize,
|
||||
int timeoutInSeconds);
|
||||
static int _sendFlashEnd(GWEN_MSG_ENDPOINT *epTcp, int reason);
|
||||
|
||||
|
||||
|
||||
@@ -115,6 +120,17 @@ int AQH_Tool_Flash(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
||||
I18S("Specify timeout in seconds for PONG response"),
|
||||
I18S("Specify timeout in seconds for PONG response")
|
||||
},
|
||||
{
|
||||
0, /* flags */
|
||||
GWEN_ArgsType_Int, /* type */
|
||||
"reboot", /* name */
|
||||
0, /* minnum */
|
||||
1, /* maxnum */
|
||||
"R", /* short option */
|
||||
NULL, /* long option */
|
||||
I18S("Request node reboot before trying to flash"),
|
||||
I18S("Request node reboot before trying to flash")
|
||||
},
|
||||
{
|
||||
GWEN_ARGS_FLAGS_HELP | GWEN_ARGS_FLAGS_LAST, /* flags */
|
||||
GWEN_ArgsType_Int, /* type */
|
||||
@@ -161,6 +177,7 @@ int _doFlash(GWEN_DB_NODE *dbArgs)
|
||||
GWEN_MSG_ENDPOINT *epTcp;
|
||||
int rv;
|
||||
int timeoutInSeconds;
|
||||
int doReboot;
|
||||
const char *s;
|
||||
unsigned int uid;
|
||||
const char *hexFilename;
|
||||
@@ -171,6 +188,7 @@ int _doFlash(GWEN_DB_NODE *dbArgs)
|
||||
|
||||
/* read data */
|
||||
timeoutInSeconds=GWEN_DB_GetIntValue(dbArgs, "timeout", 0, 30);
|
||||
doReboot=GWEN_DB_GetIntValue(dbArgs, "reboot", 0, 0);
|
||||
s=GWEN_DB_GetCharValue(dbArgs, "uid", 0, NULL);
|
||||
if (1!=sscanf(s, "%x", &uid)) {
|
||||
DBG_ERROR(NULL, "Bad uid \"%s\"", s);
|
||||
@@ -215,6 +233,25 @@ int _doFlash(GWEN_DB_NODE *dbArgs)
|
||||
return 3;
|
||||
}
|
||||
|
||||
if (doReboot) {
|
||||
/* send REBOOT_REQUEST message */
|
||||
DBG_INFO(NULL, "Sending REBOOT REQUEST message");
|
||||
rv=_sendRebootRequest(epTcp, uid);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
GWEN_MsgEndpointMgr_free(emgr);
|
||||
return 3;
|
||||
}
|
||||
|
||||
rv=_waitForRebootResponseMessage(emgr, epTcp, timeoutInSeconds);
|
||||
if (rv!=0) {
|
||||
DBG_INFO(NULL, "Bad or no reboot response received (%d).", rv);
|
||||
GWEN_MsgEndpointMgr_free(emgr);
|
||||
return 3;
|
||||
}
|
||||
DBG_INFO(NULL, "REBOOT_RESPONSE message received");
|
||||
}
|
||||
|
||||
/* wait for FLASH_READY message */
|
||||
msg=_waitForFlashReadyMessageForUid(emgr, epTcp, uid, timeoutInSeconds);
|
||||
if (msg==NULL) {
|
||||
@@ -259,6 +296,14 @@ int _doFlash(GWEN_DB_NODE *dbArgs)
|
||||
flashRecord=AQH_FlashRecord_List_Next(flashRecord);
|
||||
}
|
||||
|
||||
rv=_sendFlashEnd(epTcp, 0);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
GWEN_MsgEndpointMgr_free(emgr);
|
||||
return 4;
|
||||
}
|
||||
|
||||
|
||||
GWEN_MsgEndpointMgr_free(emgr);
|
||||
return 0;
|
||||
}
|
||||
@@ -295,6 +340,21 @@ GWEN_MSG *_waitForFlashReadyMessageForUid(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_
|
||||
|
||||
|
||||
|
||||
int _waitForRebootResponseMessage(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds)
|
||||
{
|
||||
GWEN_MSG *msg;
|
||||
|
||||
msg=Utils_WaitForSpecificNodeMessage(emgr, epTcp, AQH_MSG_TYPE_REBOOT_RSP, 0, timeoutInSeconds);
|
||||
if (msg==NULL) {
|
||||
DBG_INFO(NULL, "No REBOOT_RSP message received.");
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
GWEN_Msg_free(msg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _waitForFlashResponseMessage(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds)
|
||||
{
|
||||
GWEN_MSG *msg;
|
||||
@@ -312,6 +372,25 @@ int _waitForFlashResponseMessage(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT
|
||||
|
||||
|
||||
|
||||
int _sendRebootRequest(GWEN_MSG_ENDPOINT *epTcp, unsigned int uid)
|
||||
{
|
||||
GWEN_MSG *msgNode;
|
||||
GWEN_MSG *msgOut;
|
||||
|
||||
msgNode=AQH_RebootRequestMsg_new(0, 0xff, AQH_MSG_TYPE_REBOOT_REQ, uid);
|
||||
if (msgNode==NULL) {
|
||||
DBG_ERROR(NULL, "Error creating message");
|
||||
return GWEN_ERROR_GENERIC;
|
||||
}
|
||||
|
||||
msgOut=AQH_ForwardIpcMsg_new(AQH_MSGTYPE_IPC_FORWARD, GWEN_Msg_GetConstBuffer(msgNode), GWEN_Msg_GetBytesInBuffer(msgNode));
|
||||
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
|
||||
GWEN_Msg_free(msgNode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _sendFlashStart(GWEN_MSG_ENDPOINT *epTcp, unsigned int uid)
|
||||
{
|
||||
GWEN_MSG *msgNode;
|
||||
@@ -331,6 +410,25 @@ int _sendFlashStart(GWEN_MSG_ENDPOINT *epTcp, unsigned int uid)
|
||||
|
||||
|
||||
|
||||
int _sendFlashEnd(GWEN_MSG_ENDPOINT *epTcp, int reason)
|
||||
{
|
||||
GWEN_MSG *msgNode;
|
||||
GWEN_MSG *msgOut;
|
||||
|
||||
msgNode=AQH_FlashEndMsg_new(0, 0xc1, AQH_MSG_TYPE_FLASH_END, reason);
|
||||
if (msgNode==NULL) {
|
||||
DBG_ERROR(NULL, "Error creating message");
|
||||
return GWEN_ERROR_GENERIC;
|
||||
}
|
||||
|
||||
msgOut=AQH_ForwardIpcMsg_new(AQH_MSGTYPE_IPC_FORWARD, GWEN_Msg_GetConstBuffer(msgNode), GWEN_Msg_GetBytesInBuffer(msgNode));
|
||||
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
|
||||
GWEN_Msg_free(msgNode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _sendFlashData(GWEN_MSG_ENDPOINT_MGR *emgr,
|
||||
GWEN_MSG_ENDPOINT *epTcp,
|
||||
const AQH_FLASHRECORD *flashRecord,
|
||||
|
||||
@@ -69,10 +69,10 @@ GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG
|
||||
DBG_INFO(NULL, "Received IPC FORWARD message");
|
||||
nodeMsg=AQH_ForwardIpcMsg_GetCopyOfNodeMsg(msg);
|
||||
if (nodeMsg) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN,
|
||||
"Received node msg from %d (%d)",
|
||||
AQH_NodeMsg_GetSourceAddress(nodeMsg),
|
||||
AQH_NodeMsg_GetMsgType(nodeMsg));
|
||||
DBG_INFO(AQH_LOGDOMAIN,
|
||||
"Received node msg from %d (%d)",
|
||||
AQH_NodeMsg_GetSourceAddress(nodeMsg),
|
||||
AQH_NodeMsg_GetMsgType(nodeMsg));
|
||||
if (AQH_NodeMsg_GetMsgType(nodeMsg)==msgCode && (nodeAddr==0 || AQH_NodeMsg_GetSourceAddress(nodeMsg)==nodeAddr)) {
|
||||
GWEN_Msg_free(msg);
|
||||
return nodeMsg;
|
||||
|
||||
Reference in New Issue
Block a user