aqhome: finished transformation of aqhome-data and aqhome-tool.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* This file is part of the project AqHome.
|
* This file is part of the project AqHome.
|
||||||
* AqHome (c) by 2023 Martin Preuss, all rights reserved.
|
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
|
||||||
*
|
*
|
||||||
* The license for this file can be found in the file COPYING which you
|
* The license for this file can be found in the file COPYING which you
|
||||||
* should have received along with this file.
|
* should have received along with this file.
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
#include "aqhome/ipc2/endpoint.h"
|
#include "aqhome/ipc2/endpoint.h"
|
||||||
#include "aqhome/msg/ipc/m_ipc.h"
|
#include "aqhome/msg/ipc/m_ipc.h"
|
||||||
#include "aqhome/msg/ipc/data/m_ipcd.h"
|
#include "aqhome/msg/ipc/data/m_ipcd.h"
|
||||||
#include "aqhome/msg/ipc/data/m_ipcd_connect.h"
|
#include "aqhome/msg/ipc/m_ipc_connect.h"
|
||||||
#include "aqhome/msg/ipc/m_ipc_result.h"
|
#include "aqhome/msg/ipc/m_ipc_result.h"
|
||||||
#include "aqhome/msg/ipc/m_ipc_tag16.h"
|
#include "aqhome/msg/ipc/m_ipc_tag16.h"
|
||||||
|
|
||||||
@@ -40,17 +40,17 @@ void AqHomeDataServer_HandleConnect(GWEN_UNUSED AQH_OBJECT *o, AQH_OBJECT *ep, c
|
|||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
|
|
||||||
tagList=AQH_IpcMessageTag16_ParsePayload(msg, 0);
|
tagList=AQH_IpcMessageTag16_ParsePayload(msg, 0);
|
||||||
clientId=AQH_Tag16_GetTagDataAsNewString(tagList, AQH_MSGDATA_CONNECT_TAGS_CLIENTID, NULL);
|
clientId=AQH_Tag16_GetTagDataAsNewString(tagList, AQH_MSG_CONNECT_TAGS_CLIENTID, NULL);
|
||||||
userId=AQH_Tag16_GetTagDataAsNewString(tagList, AQH_MSGDATA_CONNECT_TAGS_USERID, NULL);
|
userId=AQH_Tag16_GetTagDataAsNewString(tagList, AQH_MSG_CONNECT_TAGS_USERID, NULL);
|
||||||
flags=AQH_Tag16_GetTagDataAsUint32(tagList, AQH_MSGDATA_CONNECT_TAGS_FLAGS, 0);
|
flags=AQH_Tag16_GetTagDataAsUint32(tagList, AQH_MSG_CONNECT_TAGS_FLAGS, 0);
|
||||||
passw=AQH_Tag16_GetTagDataAsNewString(tagList, AQH_MSGDATA_CONNECT_TAGS_PASSWORD, NULL);
|
passw=AQH_Tag16_GetTagDataAsNewString(tagList, AQH_MSG_CONNECT_TAGS_PASSWORD, NULL);
|
||||||
|
|
||||||
if (clientId)
|
if (clientId)
|
||||||
AQH_Endpoint_SetServiceName(ep, clientId);
|
AQH_Endpoint_SetServiceName(ep, clientId);
|
||||||
if (userId)
|
if (userId)
|
||||||
AQH_Endpoint_SetUserName(ep, userId);
|
AQH_Endpoint_SetUserName(ep, userId);
|
||||||
|
|
||||||
if (flags & AQH_MSGDATA_CONNECT_FLAGS_WANTUPDATES)
|
if (flags & AQH_MSG_CONNECT_FLAGS_WANTUPDATES)
|
||||||
AQH_Endpoint_AddFlags(ep, AQH_ENDPOINT_FLAGS_WANTUPDATES);
|
AQH_Endpoint_AddFlags(ep, AQH_ENDPOINT_FLAGS_WANTUPDATES);
|
||||||
|
|
||||||
/* TODO: add user management, for now we allow all */
|
/* TODO: add user management, for now we allow all */
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
devicesread.h
|
devicesread.h
|
||||||
devicesdump.h
|
devicesdump.h
|
||||||
r_setdata.h
|
r_setdata.h
|
||||||
|
r_connect.h
|
||||||
</headers>
|
</headers>
|
||||||
|
|
||||||
<sources>
|
<sources>
|
||||||
@@ -49,6 +50,7 @@
|
|||||||
devicesread.c
|
devicesread.c
|
||||||
devicesdump.c
|
devicesdump.c
|
||||||
r_setdata.c
|
r_setdata.c
|
||||||
|
r_connect.c
|
||||||
main.c
|
main.c
|
||||||
</sources>
|
</sources>
|
||||||
|
|
||||||
|
|||||||
82
apps/aqhome-nodes/r_connect.c
Normal file
82
apps/aqhome-nodes/r_connect.c
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* This file is part of the project AqHome.
|
||||||
|
* AqHome (c) by 2025 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 "./r_connect.h"
|
||||||
|
#include "./server_p.h"
|
||||||
|
#include "aqhome/ipc2/endpoint.h"
|
||||||
|
#include "aqhome/msg/ipc/m_ipc.h"
|
||||||
|
#include "aqhome/msg/ipc/nodes/m_ipcn.h"
|
||||||
|
#include "aqhome/msg/ipc/m_ipc_connect.h"
|
||||||
|
#include "aqhome/msg/ipc/m_ipc_result.h"
|
||||||
|
#include "aqhome/msg/ipc/m_ipc_tag16.h"
|
||||||
|
|
||||||
|
#include <gwenhywfar/debug.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------------------------------
|
||||||
|
* code
|
||||||
|
* ------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
void AQH_NodeServer_HandleConnect(GWEN_UNUSED AQH_OBJECT *o, AQH_OBJECT *ep, const AQH_MESSAGE *msg)
|
||||||
|
{
|
||||||
|
GWEN_TAG16_LIST *tagList;
|
||||||
|
AQH_MESSAGE *outMsg;
|
||||||
|
int resultCode=AQH_MSGDATA_RESULT_SUCCESS;
|
||||||
|
char *clientId=NULL;
|
||||||
|
char *userId=NULL;
|
||||||
|
char *passw=NULL;
|
||||||
|
uint32_t flags;
|
||||||
|
|
||||||
|
tagList=AQH_IpcMessageTag16_ParsePayload(msg, 0);
|
||||||
|
clientId=AQH_Tag16_GetTagDataAsNewString(tagList, AQH_MSG_CONNECT_TAGS_CLIENTID, NULL);
|
||||||
|
userId=AQH_Tag16_GetTagDataAsNewString(tagList, AQH_MSG_CONNECT_TAGS_USERID, NULL);
|
||||||
|
flags=AQH_Tag16_GetTagDataAsUint32(tagList, AQH_MSG_CONNECT_TAGS_FLAGS, 0);
|
||||||
|
passw=AQH_Tag16_GetTagDataAsNewString(tagList, AQH_MSG_CONNECT_TAGS_PASSWORD, NULL);
|
||||||
|
|
||||||
|
if (clientId)
|
||||||
|
AQH_Endpoint_SetServiceName(ep, clientId);
|
||||||
|
if (userId)
|
||||||
|
AQH_Endpoint_SetUserName(ep, userId);
|
||||||
|
|
||||||
|
if (flags & AQH_MSG_CONNECT_FLAGS_WANTUPDATES)
|
||||||
|
AQH_Endpoint_AddFlags(ep, AQH_ENDPOINT_FLAGS_WANTUPDATES);
|
||||||
|
|
||||||
|
/* TODO: add user management, for now we allow all */
|
||||||
|
AQH_Endpoint_SetPermissions(ep,
|
||||||
|
AQH_ENDPOINT_PERMS_LISTVALUES |
|
||||||
|
AQH_ENDPOINT_PERMS_READVALUE |
|
||||||
|
AQH_ENDPOINT_PERMS_ADDVALUE |
|
||||||
|
AQH_ENDPOINT_PERMS_LISTDATA |
|
||||||
|
AQH_ENDPOINT_PERMS_READDATA |
|
||||||
|
AQH_ENDPOINT_PERMS_ADDDATA |
|
||||||
|
AQH_ENDPOINT_PERMS_LISTDEVICES |
|
||||||
|
AQH_ENDPOINT_PERMS_READDEVICE |
|
||||||
|
AQH_ENDPOINT_PERMS_ADDDEVICE |
|
||||||
|
AQH_ENDPOINT_PERMS_MODDEVICE);
|
||||||
|
free(passw);
|
||||||
|
free(userId);
|
||||||
|
free(clientId);
|
||||||
|
|
||||||
|
outMsg=AQH_IpcMessageResult_new(AQH_IPC_PROTOCOL_NODES_ID,
|
||||||
|
AQH_IPC_PROTOCOL_NODES_VERSION,
|
||||||
|
AQH_MSGTYPE_IPC_NODES_RESULT,
|
||||||
|
AQH_Endpoint_GetNextMessageId(ep),
|
||||||
|
AQH_IpcMessage_GetMsgId(msg),
|
||||||
|
resultCode, NULL);
|
||||||
|
AQH_Endpoint_AddMsgOut(ep, outMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,20 +1,27 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* This file is part of the project AqHome.
|
* This file is part of the project AqHome.
|
||||||
* AqHome (c) by 2024 Martin Preuss, all rights reserved.
|
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
|
||||||
*
|
*
|
||||||
* The license for this file can be found in the file COPYING which you
|
* The license for this file can be found in the file COPYING which you
|
||||||
* should have received along with this file.
|
* should have received along with this file.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef AQHOME_TOOL_SETNODEVALUE_H
|
#ifndef AQHOMED_R_CONNECT_H
|
||||||
#define AQHOME_TOOL_SETNODEVALUE_H
|
#define AQHOMED_R_CONNECT_H
|
||||||
|
|
||||||
|
|
||||||
#include <gwenhywfar/db.h>
|
#include "./server.h"
|
||||||
|
|
||||||
|
#include <gwenhywfar/request.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void AQH_NodeServer_HandleConnect(AQH_OBJECT *o, AQH_OBJECT *ep, const AQH_MESSAGE *recvdMsg);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int AQH_Tool_SetNodeValue(GWEN_DB_NODE *dbArgs, int argc, char **argv);
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
#include "./db.h"
|
#include "./db.h"
|
||||||
#include "./devicesread.h"
|
#include "./devicesread.h"
|
||||||
#include "./r_setdata.h"
|
#include "./r_setdata.h"
|
||||||
|
#include "./r_connect.h"
|
||||||
|
|
||||||
#include <aqhome/aqhome.h>
|
#include <aqhome/aqhome.h>
|
||||||
#include <aqhome/ipc2/ipc_endpoint.h>
|
#include <aqhome/ipc2/ipc_endpoint.h>
|
||||||
@@ -27,8 +28,11 @@
|
|||||||
#include <aqhome/ipc2/ipc_server.h>
|
#include <aqhome/ipc2/ipc_server.h>
|
||||||
#include <aqhome/msg/ipc/m_ipc.h>
|
#include <aqhome/msg/ipc/m_ipc.h>
|
||||||
#include <aqhome/msg/ipc/m_ipc_result.h>
|
#include <aqhome/msg/ipc/m_ipc_result.h>
|
||||||
|
#include <aqhome/msg/ipc/m_ipc_connect.h>
|
||||||
#include <aqhome/msg/ipc/data/m_ipcd.h>
|
#include <aqhome/msg/ipc/data/m_ipcd.h>
|
||||||
#include <aqhome/msg/ipc/data/m_ipcd_multidata.h>
|
#include <aqhome/msg/ipc/data/m_ipcd_multidata.h>
|
||||||
|
#include <aqhome/msg/ipc/nodes/m_ipcn.h>
|
||||||
|
#include <aqhome/msg/ipc/nodes/m_ipcn_forward.h>
|
||||||
#include <aqhome/msg/node/m_node.h>
|
#include <aqhome/msg/node/m_node.h>
|
||||||
#include <aqhome/msg/node/m_value.h>
|
#include <aqhome/msg/node/m_value.h>
|
||||||
#include <aqhome/msg/node/m_recvstats.h>
|
#include <aqhome/msg/node/m_recvstats.h>
|
||||||
@@ -94,6 +98,7 @@ static int readIntConfigWithAlt(GWEN_DB_NODE *dbArgs, const char *varName, const
|
|||||||
static int _startIpc(AQH_OBJECT *o, AQH_NODE_SERVER *xo);
|
static int _startIpc(AQH_OBJECT *o, AQH_NODE_SERVER *xo);
|
||||||
static int _startTty(AQH_OBJECT *o, AQH_NODE_SERVER *xo);
|
static int _startTty(AQH_OBJECT *o, AQH_NODE_SERVER *xo);
|
||||||
static int _startBroker(AQH_OBJECT *o, AQH_NODE_SERVER *xo);
|
static int _startBroker(AQH_OBJECT *o, AQH_NODE_SERVER *xo);
|
||||||
|
static int _exchangeConnect(AQH_OBJECT *o, AQH_NODE_SERVER *xo, uint32_t flags);
|
||||||
static void _setupDb(AQH_NODE_SERVER *xo);
|
static void _setupDb(AQH_NODE_SERVER *xo);
|
||||||
static int _loadDeviceList(AQH_NODE_SERVER *xo);
|
static int _loadDeviceList(AQH_NODE_SERVER *xo);
|
||||||
|
|
||||||
@@ -109,9 +114,10 @@ static void _handleMsgFromClient(AQH_OBJECT *o, AQH_NODE_SERVER *xo, AQH_OBJECT
|
|||||||
static void _handleMsgFromTty(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
|
static void _handleMsgFromTty(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
|
||||||
static void _writeTtyMsgToLogFile(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
|
static void _writeTtyMsgToLogFile(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
|
||||||
static void _forwardTtyMsgToBroker(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
|
static void _forwardTtyMsgToBroker(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
|
||||||
static void _forwardValueMessage(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
|
static void _forwardValueMessageToBroker(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
|
||||||
static void _forwardDataFromSendStatsMessage(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
|
static void _forwardDataFromSendStatsMsgToBroker(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
|
||||||
static void _forwardDataFromRecvStatsMessage(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
|
static void _forwardDataFromRecvStatsMsgToBroker(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
|
||||||
|
static void _forwardTtyMsgToClients(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg);
|
||||||
static void _publishInt(AQH_NODE_SERVER *xo, uint32_t uid, const char *vPath, int vModality, const char *vUnits, int v);
|
static void _publishInt(AQH_NODE_SERVER *xo, uint32_t uid, const char *vPath, int vModality, const char *vUnits, int v);
|
||||||
static void _publishDouble(AQH_NODE_SERVER *xo, uint32_t uid, const char *vPath, int vModality, const char *vUnits, double v);
|
static void _publishDouble(AQH_NODE_SERVER *xo, uint32_t uid, const char *vPath, int vModality, const char *vUnits, double v);
|
||||||
static void _setDeviceName(AQH_VALUE *value, uint32_t uid);
|
static void _setDeviceName(AQH_VALUE *value, uint32_t uid);
|
||||||
@@ -562,14 +568,7 @@ int _startBroker(AQH_OBJECT *o, AQH_NODE_SERVER *xo)
|
|||||||
AQH_Object_AddLink(ep, AQH_ENDPOINT_SIGNAL_CLOSED, AQH_NODE_SERVER_SLOT_BROKERCLOSED, o);
|
AQH_Object_AddLink(ep, AQH_ENDPOINT_SIGNAL_CLOSED, AQH_NODE_SERVER_SLOT_BROKERCLOSED, o);
|
||||||
AQH_Object_Enable(ep);
|
AQH_Object_Enable(ep);
|
||||||
|
|
||||||
rv=AQH_IpcEndpoint_ExchangeConnectMsg(ep,
|
rv=_exchangeConnect(o, xo, 0);
|
||||||
AQH_MSGTYPE_IPC_DATA_CONNECT_REQ,
|
|
||||||
AQH_MSGTYPE_IPC_DATA_RESULT,
|
|
||||||
xo->brokerClientId,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
0,
|
|
||||||
xo->timeoutInSeconds);
|
|
||||||
if (rv!=0) {
|
if (rv!=0) {
|
||||||
DBG_ERROR(NULL, "Error connecting to broker: %d", rv);
|
DBG_ERROR(NULL, "Error connecting to broker: %d", rv);
|
||||||
return (rv<0)?rv:GWEN_ERROR_PERMISSIONS;
|
return (rv<0)?rv:GWEN_ERROR_PERMISSIONS;
|
||||||
@@ -588,6 +587,24 @@ int _startBroker(AQH_OBJECT *o, AQH_NODE_SERVER *xo)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int _exchangeConnect(AQH_OBJECT *o, AQH_NODE_SERVER *xo, uint32_t flags)
|
||||||
|
{
|
||||||
|
AQH_MESSAGE *msgOut;
|
||||||
|
uint32_t msgId;
|
||||||
|
|
||||||
|
msgId=AQH_Endpoint_GetNextMessageId(xo->ipcEndpoint);
|
||||||
|
msgOut=AQH_IpcMessageConnect_new(xo->protoId, xo->protoVer,
|
||||||
|
AQH_MSGTYPE_IPC_CONNECT_REQ,
|
||||||
|
msgId, 0,
|
||||||
|
xo->brokerClientId, NULL, NULL, flags);
|
||||||
|
AQH_Endpoint_AddMsgOut(xo->ipcEndpoint, msgOut);
|
||||||
|
return AQH_IpcEndpoint_WaitForResultMsg(xo->ipcEndpoint,
|
||||||
|
xo->protoId, xo->protoVer, AQH_MSGTYPE_IPC_RESULT,
|
||||||
|
msgId, xo->timeoutInSeconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void _setupDb(AQH_NODE_SERVER *xo)
|
void _setupDb(AQH_NODE_SERVER *xo)
|
||||||
{
|
{
|
||||||
if (xo->dbFile) {
|
if (xo->dbFile) {
|
||||||
@@ -700,6 +717,7 @@ void _handleMsgFromClient(GWEN_UNUSED AQH_OBJECT *o, GWEN_UNUSED AQH_NODE_SERVER
|
|||||||
if (protoId==AQH_IPC_PROTOCOL_DATA_ID) {
|
if (protoId==AQH_IPC_PROTOCOL_DATA_ID) {
|
||||||
DBG_ERROR(NULL, "Received IPC packet %d (%x)", (int) code, code);
|
DBG_ERROR(NULL, "Received IPC packet %d (%x)", (int) code, code);
|
||||||
switch(code) {
|
switch(code) {
|
||||||
|
case AQH_MSGTYPE_IPC_DATA_CONNECT_REQ: AQH_NodeServer_HandleConnect(o, ep, msg); break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -745,6 +763,7 @@ void _handleMsgFromTty(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAGE *ms
|
|||||||
AQH_NodeServer_NodeMsgToDb(o, msg);
|
AQH_NodeServer_NodeMsgToDb(o, msg);
|
||||||
_writeTtyMsgToLogFile(xo, msg);
|
_writeTtyMsgToLogFile(xo, msg);
|
||||||
_forwardTtyMsgToBroker(o, xo, msg);
|
_forwardTtyMsgToBroker(o, xo, msg);
|
||||||
|
_forwardTtyMsgToClients(o, xo, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -755,16 +774,44 @@ void _forwardTtyMsgToBroker(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAG
|
|||||||
|
|
||||||
code=AQH_NodeMessage_GetMsgType(msg);
|
code=AQH_NodeMessage_GetMsgType(msg);
|
||||||
switch(code) {
|
switch(code) {
|
||||||
case AQH_MSG_TYPE_VALUE_REPORT: _forwardValueMessage(o, xo, msg); break;
|
case AQH_MSG_TYPE_VALUE_REPORT: _forwardValueMessageToBroker(o, xo, msg); break;
|
||||||
case AQH_MSG_TYPE_COMSENDSTATS: _forwardDataFromSendStatsMessage(xo, msg); break;
|
case AQH_MSG_TYPE_COMSENDSTATS: _forwardDataFromSendStatsMsgToBroker(xo, msg); break;
|
||||||
case AQH_MSG_TYPE_COMRECVSTATS: _forwardDataFromRecvStatsMessage(xo, msg); break;
|
case AQH_MSG_TYPE_COMRECVSTATS: _forwardDataFromRecvStatsMsgToBroker(xo, msg); break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void _forwardValueMessage(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg)
|
void _forwardTtyMsgToClients(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg)
|
||||||
|
{
|
||||||
|
uint8_t code;
|
||||||
|
uint32_t msgGroup;
|
||||||
|
|
||||||
|
code=AQH_NodeMessage_GetMsgType(msg);
|
||||||
|
msgGroup=AQH_NodeMessage_GetMsgGroup(code);
|
||||||
|
if (msgGroup) {
|
||||||
|
AQH_OBJECT *ep;
|
||||||
|
|
||||||
|
ep=AQH_Object_List_First(xo->ipcClientList);
|
||||||
|
while(ep) {
|
||||||
|
if (AQH_Endpoint_GetAcceptedMsgGroups(ep) & msgGroup) {
|
||||||
|
AQH_MESSAGE *outMsg;
|
||||||
|
|
||||||
|
outMsg=AQH_IpcnMessageForward_new(AQH_MSGTYPE_IPC_NODES_FORWARD,
|
||||||
|
AQH_Endpoint_GetNextMessageId(ep), 0,
|
||||||
|
AQH_Message_GetMsgPointer(msg), AQH_Message_GetUsedSize(msg));
|
||||||
|
AQH_Endpoint_AddMsgOut(ep, outMsg);
|
||||||
|
}
|
||||||
|
ep=AQH_Object_List_Next(ep);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void _forwardValueMessageToBroker(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg)
|
||||||
{
|
{
|
||||||
uint8_t valueId;
|
uint8_t valueId;
|
||||||
double v;
|
double v;
|
||||||
@@ -790,7 +837,7 @@ void _forwardValueMessage(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAGE
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void _forwardDataFromSendStatsMessage(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg)
|
void _forwardDataFromSendStatsMsgToBroker(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg)
|
||||||
{
|
{
|
||||||
uint16_t packetsOutInt;
|
uint16_t packetsOutInt;
|
||||||
|
|
||||||
@@ -820,7 +867,7 @@ void _forwardDataFromSendStatsMessage(AQH_NODE_SERVER *xo, const AQH_MESSAGE *ms
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void _forwardDataFromRecvStatsMessage(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg)
|
void _forwardDataFromRecvStatsMsgToBroker(AQH_NODE_SERVER *xo, const AQH_MESSAGE *msg)
|
||||||
{
|
{
|
||||||
uint16_t packetsInInt;
|
uint16_t packetsInInt;
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,22 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define AQH_ENDPOINT_PERMS_LISTVALUES 0x0001
|
||||||
|
#define AQH_ENDPOINT_PERMS_READVALUE 0x0002
|
||||||
|
#define AQH_ENDPOINT_PERMS_ADDVALUE 0x0004
|
||||||
|
|
||||||
|
#define AQH_ENDPOINT_PERMS_LISTDATA 0x0010
|
||||||
|
#define AQH_ENDPOINT_PERMS_READDATA 0x0020
|
||||||
|
#define AQH_ENDPOINT_PERMS_ADDDATA 0x0040
|
||||||
|
#define AQH_ENDPOINT_PERMS_SETDATA 0x0080
|
||||||
|
|
||||||
|
#define AQH_ENDPOINT_PERMS_LISTDEVICES 0x0100
|
||||||
|
#define AQH_ENDPOINT_PERMS_READDEVICE 0x0200
|
||||||
|
#define AQH_ENDPOINT_PERMS_ADDDEVICE 0x0400
|
||||||
|
#define AQH_ENDPOINT_PERMS_MODDEVICE 0x0800
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AQH_OBJECT *AQH_NodeServer_new(AQH_EVENT_LOOP *eventLoop);
|
AQH_OBJECT *AQH_NodeServer_new(AQH_EVENT_LOOP *eventLoop);
|
||||||
int AQH_NodeServer_Init(AQH_OBJECT *o, int argc, char **argv);
|
int AQH_NodeServer_Init(AQH_OBJECT *o, int argc, char **argv);
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,10 @@ struct AQH_NODE_SERVER {
|
|||||||
struct termios initialTermiosState;
|
struct termios initialTermiosState;
|
||||||
|
|
||||||
int timeoutInSeconds;
|
int timeoutInSeconds;
|
||||||
|
|
||||||
|
uint8_t protoId;
|
||||||
|
uint8_t protoVer;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,11 @@
|
|||||||
#include "aqhome/msg/ipc/m_ipc_tag16.h"
|
#include "aqhome/msg/ipc/m_ipc_tag16.h"
|
||||||
#include "aqhome/msg/ipc/m_ipc_result.h"
|
#include "aqhome/msg/ipc/m_ipc_result.h"
|
||||||
#include "aqhome/msg/ipc/data/m_ipcd.h"
|
#include "aqhome/msg/ipc/data/m_ipcd.h"
|
||||||
#include "aqhome/msg/ipc/data/m_ipcd_connect.h"
|
#include "aqhome/msg/ipc/m_ipc_connect.h"
|
||||||
|
#include "aqhome/msg/ipc/nodes/m_ipcn.h"
|
||||||
|
#include "aqhome/msg/ipc/nodes/m_ipcn_forward.h"
|
||||||
|
#include "aqhome/msg/ipc/nodes/m_ipcn_setaccmsggrps.h"
|
||||||
|
#include "aqhome/msg/node/m_node.h"
|
||||||
#include "aqhome/ipc2/ipc_endpoint.h"
|
#include "aqhome/ipc2/ipc_endpoint.h"
|
||||||
|
|
||||||
#include <gwenhywfar/args.h>
|
#include <gwenhywfar/args.h>
|
||||||
@@ -35,9 +39,15 @@ GWEN_INHERIT(AQH_OBJECT, AQH_TOOL_CLIENT)
|
|||||||
|
|
||||||
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
|
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
|
||||||
|
|
||||||
static int _sendWaitHandle(AQH_OBJECT *o, AQH_TOOL_CLIENT *xo);
|
static int _connectEndpoint(AQH_OBJECT *o);
|
||||||
|
static int _exchangeConnectMsgs(AQH_TOOL_CLIENT *xo, uint32_t flags);
|
||||||
|
static int _exchangeAcceptedMsgGroups(AQH_TOOL_CLIENT *xo, uint32_t groups);
|
||||||
|
|
||||||
|
static int _sendWaitAndHandle(AQH_OBJECT *o, AQH_TOOL_CLIENT *xo);
|
||||||
static int _waitAndHandle(AQH_OBJECT *o, AQH_TOOL_CLIENT *xo, uint32_t msgId);
|
static int _waitAndHandle(AQH_OBJECT *o, AQH_TOOL_CLIENT *xo, uint32_t msgId);
|
||||||
static int _exchangeConnect(AQH_TOOL_CLIENT *xo, uint32_t flags);
|
static int _nodesSendWaitAndHandle(AQH_OBJECT *o, AQH_TOOL_CLIENT *xo);
|
||||||
|
static int _nodesWaitAndHandle(AQH_OBJECT *o, AQH_TOOL_CLIENT *xo);
|
||||||
|
|
||||||
static AQH_MESSAGE *_createRequestMessage(AQH_OBJECT *o, uint32_t msgId);
|
static AQH_MESSAGE *_createRequestMessage(AQH_OBJECT *o, uint32_t msgId);
|
||||||
static int _handleResponseMessage(AQH_OBJECT *o, const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList, int first);
|
static int _handleResponseMessage(AQH_OBJECT *o, const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList, int first);
|
||||||
|
|
||||||
@@ -45,7 +55,9 @@ static int _handleResponseMessage(AQH_OBJECT *o, const AQH_MESSAGE *msg, const G
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
AQH_OBJECT *AQH_ToolClient_new(AQH_EVENT_LOOP *eventLoop, GWEN_DB_NODE *dbGlobalArgs, const GWEN_ARGS *argDescrs)
|
AQH_OBJECT *AQH_ToolClient_new(AQH_EVENT_LOOP *eventLoop,
|
||||||
|
uint8_t protoId, uint8_t protoVer,
|
||||||
|
GWEN_DB_NODE *dbGlobalArgs, const GWEN_ARGS *argDescrs)
|
||||||
{
|
{
|
||||||
AQH_OBJECT *o;
|
AQH_OBJECT *o;
|
||||||
AQH_TOOL_CLIENT *xo;
|
AQH_TOOL_CLIENT *xo;
|
||||||
@@ -55,6 +67,8 @@ AQH_OBJECT *AQH_ToolClient_new(AQH_EVENT_LOOP *eventLoop, GWEN_DB_NODE *dbGlobal
|
|||||||
GWEN_INHERIT_SETDATA(AQH_OBJECT, AQH_TOOL_CLIENT, o, xo, _freeData);
|
GWEN_INHERIT_SETDATA(AQH_OBJECT, AQH_TOOL_CLIENT, o, xo, _freeData);
|
||||||
xo->dbGlobalArgs=dbGlobalArgs;
|
xo->dbGlobalArgs=dbGlobalArgs;
|
||||||
xo->args=argDescrs;
|
xo->args=argDescrs;
|
||||||
|
xo->protoId=protoId;
|
||||||
|
xo->protoVer=protoVer;
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
@@ -72,6 +86,18 @@ void GWENHYWFAR_CB _freeData(GWEN_UNUSED void *bp, void *p)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
AQH_OBJECT *AQH_ToolClient_GetEndpoint(const AQH_OBJECT *o)
|
||||||
|
{
|
||||||
|
AQH_TOOL_CLIENT *xo;
|
||||||
|
|
||||||
|
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_TOOL_CLIENT, o);
|
||||||
|
if (xo)
|
||||||
|
return xo->ipcEndpoint;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int AQH_ToolClient_ReadLocalArgs(AQH_OBJECT *o, int argc, char **argv)
|
int AQH_ToolClient_ReadLocalArgs(AQH_OBJECT *o, int argc, char **argv)
|
||||||
{
|
{
|
||||||
if (o) {
|
if (o) {
|
||||||
@@ -216,18 +242,43 @@ int AQH_ToolClient_Run(AQH_OBJECT *o)
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
rv=_exchangeConnect(xo, xo->flags);
|
rv=_exchangeConnectMsgs(xo, xo->flags);
|
||||||
if (rv!=AQH_MSGDATA_RESULT_SUCCESS) {
|
if (rv!=AQH_MSGDATA_RESULT_SUCCESS) {
|
||||||
DBG_ERROR(NULL, "Connect response: %d", rv);
|
DBG_ERROR(NULL, "Connect response: %d", rv);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
return _sendWaitHandle(o, xo);
|
return _sendWaitAndHandle(o, xo);
|
||||||
}
|
}
|
||||||
return GWEN_ERROR_INVALID;
|
return GWEN_ERROR_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int AQH_ToolClient_RunConnected(AQH_OBJECT *o)
|
||||||
|
{
|
||||||
|
AQH_TOOL_CLIENT *xo;
|
||||||
|
|
||||||
|
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_TOOL_CLIENT, o);
|
||||||
|
if (xo)
|
||||||
|
return _sendWaitAndHandle(o, xo);
|
||||||
|
return GWEN_ERROR_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int AQH_ToolClient_RunConnectedWithNodeMsgs(AQH_OBJECT *o)
|
||||||
|
{
|
||||||
|
AQH_TOOL_CLIENT *xo;
|
||||||
|
|
||||||
|
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_TOOL_CLIENT, o);
|
||||||
|
if (xo)
|
||||||
|
return _nodesSendWaitAndHandle(o, xo);
|
||||||
|
return GWEN_ERROR_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int AQH_ToolClient_Watch(AQH_OBJECT *o)
|
int AQH_ToolClient_Watch(AQH_OBJECT *o)
|
||||||
{
|
{
|
||||||
AQH_TOOL_CLIENT *xo;
|
AQH_TOOL_CLIENT *xo;
|
||||||
@@ -242,7 +293,7 @@ int AQH_ToolClient_Watch(AQH_OBJECT *o)
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
rv=_exchangeConnect(xo, xo->flags);
|
rv=_exchangeConnectMsgs(xo, xo->flags);
|
||||||
if (rv!=AQH_MSGDATA_RESULT_SUCCESS) {
|
if (rv!=AQH_MSGDATA_RESULT_SUCCESS) {
|
||||||
DBG_ERROR(NULL, "Connect response: %d", rv);
|
DBG_ERROR(NULL, "Connect response: %d", rv);
|
||||||
return 2;
|
return 2;
|
||||||
@@ -254,6 +305,201 @@ int AQH_ToolClient_Watch(AQH_OBJECT *o)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int AQH_ToolClient_WatchConnected(AQH_OBJECT *o)
|
||||||
|
{
|
||||||
|
AQH_TOOL_CLIENT *xo;
|
||||||
|
|
||||||
|
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_TOOL_CLIENT, o);
|
||||||
|
if (xo)
|
||||||
|
return _waitAndHandle(o, xo, 0);
|
||||||
|
return GWEN_ERROR_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int AQH_ToolClient_Connect(AQH_OBJECT *o, uint32_t connFlags, uint32_t connMsgFlags, uint32_t grps)
|
||||||
|
{
|
||||||
|
AQH_TOOL_CLIENT *xo;
|
||||||
|
|
||||||
|
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_TOOL_CLIENT, o);
|
||||||
|
if (xo) {
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
rv=_connectEndpoint(o);
|
||||||
|
if (rv<0) {
|
||||||
|
DBG_INFO(NULL, "here(%d)", rv);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
if (connFlags & AQH_TOOL_CLIENT_CONNECTFLAGS_WITHCONNECTMSG) {
|
||||||
|
rv=_exchangeConnectMsgs(xo, connMsgFlags);
|
||||||
|
if (rv<0) {
|
||||||
|
DBG_INFO(NULL, "here(%d)", rv);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (connFlags & AQH_TOOL_CLIENT_CONNECTFLAGS_WITHGRPMSG) {
|
||||||
|
rv=_exchangeAcceptedMsgGroups(xo, grps);
|
||||||
|
if (rv<0) {
|
||||||
|
DBG_INFO(NULL, "here(%d)", rv);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return GWEN_ERROR_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int _connectEndpoint(AQH_OBJECT *o)
|
||||||
|
{
|
||||||
|
AQH_TOOL_CLIENT *xo;
|
||||||
|
|
||||||
|
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_TOOL_CLIENT, o);
|
||||||
|
if (xo) {
|
||||||
|
xo->ipcEndpoint=Utils2_SetupBrokerClientEndpoint(AQH_Object_GetEventLoop(o), xo->dbLocalArgs, 0);
|
||||||
|
if (xo->ipcEndpoint==NULL) {
|
||||||
|
DBG_ERROR(NULL, "ERROR creating TCP connection");
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return GWEN_ERROR_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int _exchangeConnectMsgs(AQH_TOOL_CLIENT *xo, uint32_t flags)
|
||||||
|
{
|
||||||
|
AQH_MESSAGE *msgOut;
|
||||||
|
uint32_t msgId;
|
||||||
|
const char *clientId;
|
||||||
|
const char *userId;
|
||||||
|
const char *passw;
|
||||||
|
|
||||||
|
clientId=GWEN_DB_GetCharValue(xo->dbLocalArgs, "brokerClientId", 0, "aqhome-tool");
|
||||||
|
userId=GWEN_DB_GetCharValue(xo->dbLocalArgs, "userId", 0, NULL);
|
||||||
|
passw=GWEN_DB_GetCharValue(xo->dbLocalArgs, "password", 0, NULL);
|
||||||
|
|
||||||
|
msgId=AQH_Endpoint_GetNextMessageId(xo->ipcEndpoint);
|
||||||
|
msgOut=AQH_IpcMessageConnect_new(xo->protoId, xo->protoVer,
|
||||||
|
AQH_MSGTYPE_IPC_CONNECT_REQ,
|
||||||
|
msgId, 0,
|
||||||
|
clientId, userId, passw, flags);
|
||||||
|
AQH_Endpoint_AddMsgOut(xo->ipcEndpoint, msgOut);
|
||||||
|
return AQH_IpcEndpoint_WaitForResultMsg(xo->ipcEndpoint,
|
||||||
|
xo->protoId, xo->protoVer, AQH_MSGTYPE_IPC_RESULT,
|
||||||
|
msgId, xo->timeoutInSeconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int _exchangeAcceptedMsgGroups(AQH_TOOL_CLIENT *xo, uint32_t groups)
|
||||||
|
{
|
||||||
|
AQH_MESSAGE *msgOut;
|
||||||
|
uint32_t msgId;
|
||||||
|
|
||||||
|
msgId=AQH_Endpoint_GetNextMessageId(xo->ipcEndpoint);
|
||||||
|
msgOut=AQH_IpcnMessageSetAcceptedMsgGroups_new(AQH_MSGTYPE_IPC_NODES_SETACCMSGGRPS, msgId, 0, groups);
|
||||||
|
AQH_Endpoint_AddMsgOut(xo->ipcEndpoint, msgOut);
|
||||||
|
return AQH_IpcEndpoint_WaitForResultMsg(xo->ipcEndpoint,
|
||||||
|
xo->protoId, xo->protoVer, AQH_MSGTYPE_IPC_RESULT,
|
||||||
|
msgId, xo->timeoutInSeconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void AQH_ToolClient_SendNodeMsg(AQH_OBJECT *o, const AQH_MESSAGE *nodeMsg)
|
||||||
|
{
|
||||||
|
AQH_TOOL_CLIENT *xo;
|
||||||
|
|
||||||
|
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_TOOL_CLIENT, o);
|
||||||
|
if (xo) {
|
||||||
|
AQH_MESSAGE *msgOut;
|
||||||
|
|
||||||
|
msgOut=AQH_IpcnMessageForward_new(AQH_MSGTYPE_IPC_NODES_FORWARD, AQH_Endpoint_GetNextMessageId(xo->ipcEndpoint), 0,
|
||||||
|
AQH_Message_GetMsgPointer(nodeMsg), AQH_Message_GetUsedSize(nodeMsg));
|
||||||
|
AQH_Endpoint_AddMsgOut(xo->ipcEndpoint, msgOut);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
AQH_MESSAGE *AQH_ToolClient_WaitForNodeMsg(AQH_OBJECT *o, int nodeSrcAddr, uint8_t nodeMsgType, int timeoutInSeconds)
|
||||||
|
{
|
||||||
|
AQH_TOOL_CLIENT *xo;
|
||||||
|
|
||||||
|
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_TOOL_CLIENT, o);
|
||||||
|
if (xo) {
|
||||||
|
time_t startTime;
|
||||||
|
|
||||||
|
startTime=time(NULL);
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
AQH_MESSAGE *msg;
|
||||||
|
time_t now;
|
||||||
|
|
||||||
|
AQH_EventLoop_Run(AQH_Object_GetEventLoop(xo->ipcEndpoint), 500);
|
||||||
|
msg=AQH_Endpoint_GetNextMsgIn(xo->ipcEndpoint);
|
||||||
|
if (msg) {
|
||||||
|
GWEN_TAG16_LIST *tagList;
|
||||||
|
|
||||||
|
tagList=AQH_IpcMessageTag16_ParsePayload(msg, 0);
|
||||||
|
if (tagList) {
|
||||||
|
uint16_t code;
|
||||||
|
|
||||||
|
code=AQH_IpcMessage_GetCode(msg);
|
||||||
|
if (code==AQH_MSGTYPE_IPC_NODES_FORWARD) {
|
||||||
|
const GWEN_TAG16 *tag;
|
||||||
|
const uint8_t *ptr;
|
||||||
|
uint32_t len;
|
||||||
|
|
||||||
|
tag=tagList?GWEN_Tag16_List_FindFirstByTagType(tagList, AQH_MSGNODE_FORWARD_TAGS_MSG):NULL;
|
||||||
|
ptr=tag?GWEN_Tag16_GetTagData(tag):NULL;
|
||||||
|
len=tag?GWEN_Tag16_GetTagLength(tag):0;
|
||||||
|
if (ptr && len) {
|
||||||
|
AQH_MESSAGE *nodeMsg;
|
||||||
|
|
||||||
|
nodeMsg=AQH_NodeMessage_fromBuffer(ptr, len);
|
||||||
|
if (nodeMsg) {
|
||||||
|
if ((nodeSrcAddr==0xff || nodeSrcAddr==0x00 || nodeSrcAddr==AQH_NodeMessage_GetSourceAddress(nodeMsg)) &&
|
||||||
|
(nodeMsgType==0 || nodeMsgType==AQH_NodeMessage_GetMsgType(nodeMsg))) {
|
||||||
|
GWEN_Tag16_List_free(tagList);
|
||||||
|
AQH_Message_free(msg);
|
||||||
|
return nodeMsg;
|
||||||
|
}
|
||||||
|
AQH_Message_free(nodeMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
DBG_ERROR(NULL, "Empty node msg");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
DBG_ERROR(NULL, "Received unexpected message %d (%x), ignoring", code, code);
|
||||||
|
}
|
||||||
|
GWEN_Tag16_List_free(tagList);
|
||||||
|
}
|
||||||
|
AQH_Message_free(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
now=time(NULL);
|
||||||
|
if (now-startTime>timeoutInSeconds) {
|
||||||
|
DBG_INFO(NULL, "Timeout");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int AQH_ToolClient_HandleResultMsg(GWEN_UNUSED const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList, GWEN_UNUSED int first)
|
int AQH_ToolClient_HandleResultMsg(GWEN_UNUSED const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList, GWEN_UNUSED int first)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
@@ -271,7 +517,7 @@ int AQH_ToolClient_HandleResultMsg(GWEN_UNUSED const AQH_MESSAGE *msg, const GWE
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int _sendWaitHandle(AQH_OBJECT *o, AQH_TOOL_CLIENT *xo)
|
int _sendWaitAndHandle(AQH_OBJECT *o, AQH_TOOL_CLIENT *xo)
|
||||||
{
|
{
|
||||||
AQH_MESSAGE *msgOut;
|
AQH_MESSAGE *msgOut;
|
||||||
uint32_t msgId;
|
uint32_t msgId;
|
||||||
@@ -324,24 +570,53 @@ int _waitAndHandle(AQH_OBJECT *o, AQH_TOOL_CLIENT *xo, uint32_t msgId)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int _exchangeConnect(AQH_TOOL_CLIENT *xo, uint32_t flags)
|
int _nodesSendWaitAndHandle(AQH_OBJECT *o, AQH_TOOL_CLIENT *xo)
|
||||||
{
|
{
|
||||||
const char *clientId;
|
AQH_MESSAGE *nodeMsg;
|
||||||
const char *userId;
|
AQH_MESSAGE *msgOut;
|
||||||
const char *passw;
|
uint32_t msgId;
|
||||||
|
|
||||||
clientId=GWEN_DB_GetCharValue(xo->dbLocalArgs, "brokerClientId", 0, "aqhome-tool");
|
msgId=AQH_Endpoint_GetNextMessageId(xo->ipcEndpoint);
|
||||||
userId=GWEN_DB_GetCharValue(xo->dbLocalArgs, "userId", 0, NULL);
|
nodeMsg=_createRequestMessage(o, msgId);
|
||||||
passw=GWEN_DB_GetCharValue(xo->dbLocalArgs, "password", 0, NULL);
|
if (nodeMsg==NULL) {
|
||||||
|
DBG_ERROR(NULL, "Error creating outbound message");
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
msgOut=AQH_IpcnMessageForward_new(AQH_MSGTYPE_IPC_NODES_FORWARD, msgId, 0,
|
||||||
|
AQH_Message_GetMsgPointer(nodeMsg), AQH_Message_GetUsedSize(nodeMsg));
|
||||||
|
AQH_Message_free(nodeMsg);
|
||||||
|
AQH_Endpoint_AddMsgOut(xo->ipcEndpoint, msgOut);
|
||||||
|
|
||||||
return AQH_IpcEndpoint_ExchangeConnectMsg(xo->ipcEndpoint,
|
return _nodesWaitAndHandle(o, xo);
|
||||||
AQH_MSGTYPE_IPC_DATA_CONNECT_REQ,
|
}
|
||||||
AQH_MSGTYPE_IPC_DATA_RESULT,
|
|
||||||
clientId,
|
|
||||||
userId,
|
|
||||||
passw,
|
int _nodesWaitAndHandle(AQH_OBJECT *o, AQH_TOOL_CLIENT *xo)
|
||||||
flags,
|
{
|
||||||
xo->timeoutInSeconds);
|
int first=1;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
AQH_MESSAGE *msgIn;
|
||||||
|
|
||||||
|
msgIn=AQH_ToolClient_WaitForNodeMsg(o, 0, 0, xo->timeoutInSeconds);
|
||||||
|
if (msgIn) {
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
rv=_handleResponseMessage(o, msgIn, NULL, first);
|
||||||
|
AQH_Message_free(msgIn);
|
||||||
|
first=0;
|
||||||
|
if (rv<0) {
|
||||||
|
DBG_ERROR(NULL, "here (%d)", rv);
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
else if (rv==1) {
|
||||||
|
DBG_ERROR(NULL, "Done.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} /* for */
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,15 +16,39 @@
|
|||||||
#include <gwenhywfar/args.h>
|
#include <gwenhywfar/args.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define AQH_TOOL_CLIENT_NODEADDR 240
|
||||||
|
|
||||||
|
#define AQH_TOOL_CLIENT_CONNECTFLAGS_WITHCONNECTMSG 0x0001
|
||||||
|
#define AQH_TOOL_CLIENT_CONNECTFLAGS_WITHGRPMSG 0x0002
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef AQH_MESSAGE* (*AQH_TOOLCLIENT_CREATEREQUESTMESSAGE_FN)(AQH_OBJECT *o, uint32_t msgId);
|
typedef AQH_MESSAGE* (*AQH_TOOLCLIENT_CREATEREQUESTMESSAGE_FN)(AQH_OBJECT *o, uint32_t msgId);
|
||||||
typedef int (*AQH_TOOLCLIENT_HANDLERESPONSEMESSAGE_FN)(AQH_OBJECT *o, const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList, int first);
|
typedef int (*AQH_TOOLCLIENT_HANDLERESPONSEMESSAGE_FN)(AQH_OBJECT *o, const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList, int first);
|
||||||
|
|
||||||
|
|
||||||
AQH_OBJECT *AQH_ToolClient_new(AQH_EVENT_LOOP *eventLoop, GWEN_DB_NODE *dbGlobalArgs, const GWEN_ARGS *argDescrs);
|
AQH_OBJECT *AQH_ToolClient_new(AQH_EVENT_LOOP *eventLoop,
|
||||||
|
uint8_t protoId, uint8_t protoVer,
|
||||||
|
GWEN_DB_NODE *dbGlobalArgs, const GWEN_ARGS *argDescrs);
|
||||||
int AQH_ToolClient_ReadLocalArgs(AQH_OBJECT *o, int argc, char **argv);
|
int AQH_ToolClient_ReadLocalArgs(AQH_OBJECT *o, int argc, char **argv);
|
||||||
|
|
||||||
int AQH_ToolClient_Run(AQH_OBJECT *o);
|
int AQH_ToolClient_Run(AQH_OBJECT *o);
|
||||||
int AQH_ToolClient_Watch(AQH_OBJECT *o);
|
int AQH_ToolClient_Watch(AQH_OBJECT *o);
|
||||||
|
|
||||||
|
int AQH_ToolClient_Connect(AQH_OBJECT *o, uint32_t connFlags, uint32_t connMsgFlags, uint32_t grps);
|
||||||
|
int AQH_ToolClient_RunConnected(AQH_OBJECT *o);
|
||||||
|
int AQH_ToolClient_WatchConnected(AQH_OBJECT *o);
|
||||||
|
|
||||||
|
int AQH_ToolClient_RunConnectedWithNodeMsgs(AQH_OBJECT *o);
|
||||||
|
|
||||||
|
|
||||||
|
void AQH_ToolClient_SendNodeMsg(AQH_OBJECT *o, const AQH_MESSAGE *nodeMsg);
|
||||||
|
AQH_MESSAGE *AQH_ToolClient_WaitForNodeMsg(AQH_OBJECT *o, int nodeSrcAddr, uint8_t nodeMsgType, int timeoutInSeconds);
|
||||||
|
|
||||||
|
AQH_OBJECT *AQH_ToolClient_GetEndpoint(const AQH_OBJECT *o);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GWEN_DB_NODE *AQH_ToolClient_GetDbGlobalArgs(const AQH_OBJECT *o);
|
GWEN_DB_NODE *AQH_ToolClient_GetDbGlobalArgs(const AQH_OBJECT *o);
|
||||||
GWEN_DB_NODE *AQH_ToolClient_GetDbLocalArgs(const AQH_OBJECT *o);
|
GWEN_DB_NODE *AQH_ToolClient_GetDbLocalArgs(const AQH_OBJECT *o);
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ struct AQH_TOOL_CLIENT {
|
|||||||
AQH_OBJECT *ipcEndpoint;
|
AQH_OBJECT *ipcEndpoint;
|
||||||
int timeoutInSeconds;
|
int timeoutInSeconds;
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
|
|
||||||
|
uint8_t protoId;
|
||||||
|
uint8_t protoVer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ int AQH_Tool_AddDataPoint(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
|||||||
};
|
};
|
||||||
|
|
||||||
eventLoop=AQH_EventLoop_new();
|
eventLoop=AQH_EventLoop_new();
|
||||||
o=AQH_ToolClient_new(eventLoop, dbGlobalArgs, args);
|
o=AQH_ToolClient_new(eventLoop, AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, dbGlobalArgs, args);
|
||||||
AQH_ToolClient_SetCreateRequestMessageFn(o, _createRequestMessage);
|
AQH_ToolClient_SetCreateRequestMessageFn(o, _createRequestMessage);
|
||||||
rv=AQH_ToolClient_ReadLocalArgs(o, argc, argv);
|
rv=AQH_ToolClient_ReadLocalArgs(o, argc, argv);
|
||||||
if (rv!=0)
|
if (rv!=0)
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ int AQH_Tool_GetDataPoints(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
|||||||
};
|
};
|
||||||
|
|
||||||
eventLoop=AQH_EventLoop_new();
|
eventLoop=AQH_EventLoop_new();
|
||||||
o=AQH_ToolClient_new(eventLoop, dbGlobalArgs, args);
|
o=AQH_ToolClient_new(eventLoop, AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, dbGlobalArgs, args);
|
||||||
AQH_ToolClient_SetCreateRequestMessageFn(o, _createRequestMessage);
|
AQH_ToolClient_SetCreateRequestMessageFn(o, _createRequestMessage);
|
||||||
AQH_ToolClient_SetHandleResponseMessageFn(o, _handleResponseMessage);
|
AQH_ToolClient_SetHandleResponseMessageFn(o, _handleResponseMessage);
|
||||||
rv=AQH_ToolClient_ReadLocalArgs(o, argc, argv);
|
rv=AQH_ToolClient_ReadLocalArgs(o, argc, argv);
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ int AQH_Tool_GetDevices(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
|||||||
};
|
};
|
||||||
|
|
||||||
eventLoop=AQH_EventLoop_new();
|
eventLoop=AQH_EventLoop_new();
|
||||||
o=AQH_ToolClient_new(eventLoop, dbGlobalArgs, args);
|
o=AQH_ToolClient_new(eventLoop, AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, dbGlobalArgs, args);
|
||||||
AQH_ToolClient_SetCreateRequestMessageFn(o, _createRequestMessage);
|
AQH_ToolClient_SetCreateRequestMessageFn(o, _createRequestMessage);
|
||||||
AQH_ToolClient_SetHandleResponseMessageFn(o, _handleResponseMessage);
|
AQH_ToolClient_SetHandleResponseMessageFn(o, _handleResponseMessage);
|
||||||
rv=AQH_ToolClient_ReadLocalArgs(o, argc, argv);
|
rv=AQH_ToolClient_ReadLocalArgs(o, argc, argv);
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ int AQH_Tool_GetValues(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
|||||||
};
|
};
|
||||||
|
|
||||||
eventLoop=AQH_EventLoop_new();
|
eventLoop=AQH_EventLoop_new();
|
||||||
o=AQH_ToolClient_new(eventLoop, dbGlobalArgs, args);
|
o=AQH_ToolClient_new(eventLoop, AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, dbGlobalArgs, args);
|
||||||
AQH_ToolClient_SetCreateRequestMessageFn(o, _createRequestMessage);
|
AQH_ToolClient_SetCreateRequestMessageFn(o, _createRequestMessage);
|
||||||
AQH_ToolClient_SetHandleResponseMessageFn(o, _handleResponseMessage);
|
AQH_ToolClient_SetHandleResponseMessageFn(o, _handleResponseMessage);
|
||||||
rv=AQH_ToolClient_ReadLocalArgs(o, argc, argv);
|
rv=AQH_ToolClient_ReadLocalArgs(o, argc, argv);
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ int AQH_Tool_ModDevice(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
|||||||
};
|
};
|
||||||
|
|
||||||
eventLoop=AQH_EventLoop_new();
|
eventLoop=AQH_EventLoop_new();
|
||||||
o=AQH_ToolClient_new(eventLoop, dbGlobalArgs, args);
|
o=AQH_ToolClient_new(eventLoop, AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, dbGlobalArgs, args);
|
||||||
AQH_ToolClient_SetCreateRequestMessageFn(o, _createRequestMessage);
|
AQH_ToolClient_SetCreateRequestMessageFn(o, _createRequestMessage);
|
||||||
rv=AQH_ToolClient_ReadLocalArgs(o, argc, argv);
|
rv=AQH_ToolClient_ReadLocalArgs(o, argc, argv);
|
||||||
if (rv!=0)
|
if (rv!=0)
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ int AQH_Tool_SetData(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
|||||||
};
|
};
|
||||||
|
|
||||||
eventLoop=AQH_EventLoop_new();
|
eventLoop=AQH_EventLoop_new();
|
||||||
o=AQH_ToolClient_new(eventLoop, dbGlobalArgs, args);
|
o=AQH_ToolClient_new(eventLoop, AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, dbGlobalArgs, args);
|
||||||
AQH_ToolClient_SetCreateRequestMessageFn(o, _createRequestMessage);
|
AQH_ToolClient_SetCreateRequestMessageFn(o, _createRequestMessage);
|
||||||
rv=AQH_ToolClient_ReadLocalArgs(o, argc, argv);
|
rv=AQH_ToolClient_ReadLocalArgs(o, argc, argv);
|
||||||
if (rv!=0)
|
if (rv!=0)
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ int AQH_Tool_Watch(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
|||||||
};
|
};
|
||||||
|
|
||||||
eventLoop=AQH_EventLoop_new();
|
eventLoop=AQH_EventLoop_new();
|
||||||
o=AQH_ToolClient_new(eventLoop, dbGlobalArgs, args);
|
o=AQH_ToolClient_new(eventLoop, AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, dbGlobalArgs, args);
|
||||||
AQH_ToolClient_AddFlags(o, AQH_ENDPOINT_FLAGS_WANTUPDATES);
|
AQH_ToolClient_AddFlags(o, AQH_ENDPOINT_FLAGS_WANTUPDATES);
|
||||||
AQH_ToolClient_SetHandleResponseMessageFn(o, _handleResponseMessage);
|
AQH_ToolClient_SetHandleResponseMessageFn(o, _handleResponseMessage);
|
||||||
rv=AQH_ToolClient_ReadLocalArgs(o, argc, argv);
|
rv=AQH_ToolClient_ReadLocalArgs(o, argc, argv);
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
#include "./nodes/ping.h"
|
#include "./nodes/ping.h"
|
||||||
#include "./nodes/flash.h"
|
#include "./nodes/flash.h"
|
||||||
#include "./nodes/getnodes.h"
|
#include "./nodes/getnodes.h"
|
||||||
#include "./nodes/setnodevalue.h"
|
|
||||||
#include "./data/getvalues.h"
|
#include "./data/getvalues.h"
|
||||||
#include "./data/getdevices.h"
|
#include "./data/getdevices.h"
|
||||||
#include "./data/adddata.h"
|
#include "./data/adddata.h"
|
||||||
@@ -87,7 +86,6 @@ int main(int argc, char **argv)
|
|||||||
const GWEN_FUNCS cmdDefArray[]= {
|
const GWEN_FUNCS cmdDefArray[]= {
|
||||||
GWEN_FE_DAH("ping", AQH_Tool_Ping, I18N("Ping a given node on the network")),
|
GWEN_FE_DAH("ping", AQH_Tool_Ping, I18N("Ping a given node on the network")),
|
||||||
GWEN_FE_DAH("flash", AQH_Tool_Flash, I18N("Flash a given node on the network")),
|
GWEN_FE_DAH("flash", AQH_Tool_Flash, I18N("Flash a given node on the network")),
|
||||||
GWEN_FE_DAH("setnodevalue", AQH_Tool_SetNodeValue, I18N("Set a raw value in a node")),
|
|
||||||
GWEN_FE_DAH("getnodes", AQH_Tool_GetNodes, I18N("Request list of known devices on the network")),
|
GWEN_FE_DAH("getnodes", AQH_Tool_GetNodes, I18N("Request list of known devices on the network")),
|
||||||
GWEN_FE_DAH("getvalues", AQH_Tool_GetValues, I18N("Request list of known values on the data server")),
|
GWEN_FE_DAH("getvalues", AQH_Tool_GetValues, I18N("Request list of known values on the data server")),
|
||||||
GWEN_FE_DAH("getdevices", AQH_Tool_GetDevices, I18N("Request list of known devices on the data server")),
|
GWEN_FE_DAH("getdevices", AQH_Tool_GetDevices, I18N("Request list of known devices on the data server")),
|
||||||
|
|||||||
@@ -36,7 +36,6 @@
|
|||||||
ping.h
|
ping.h
|
||||||
flash.h
|
flash.h
|
||||||
getnodes.h
|
getnodes.h
|
||||||
setnodevalue.h
|
|
||||||
</headers>
|
</headers>
|
||||||
|
|
||||||
<sources>
|
<sources>
|
||||||
@@ -45,7 +44,6 @@
|
|||||||
ping.c
|
ping.c
|
||||||
flash.c
|
flash.c
|
||||||
getnodes.c
|
getnodes.c
|
||||||
setnodevalue.c
|
|
||||||
</sources>
|
</sources>
|
||||||
|
|
||||||
<useTargets>
|
<useTargets>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* This file is part of the project AqHome.
|
* This file is part of the project AqHome.
|
||||||
* AqHome (c) by 2023 Martin Preuss, all rights reserved.
|
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
|
||||||
*
|
*
|
||||||
* The license for this file can be found in the file COPYING which you
|
* The license for this file can be found in the file COPYING which you
|
||||||
* should have received along with this file.
|
* should have received along with this file.
|
||||||
@@ -11,181 +11,124 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "./flash.h"
|
#include "./flash.h"
|
||||||
#include "../utils.h"
|
#include "../client.h"
|
||||||
|
|
||||||
#include "aqhome/ipc/endpoint_ipc.h"
|
#include "aqhome/msg/ipc/nodes/m_ipcn.h"
|
||||||
#include "aqhome/ipc/nodes/msg_ipc_setaccmsggrps.h"
|
#include "aqhome/msg/node/m_node.h"
|
||||||
#include "aqhome/ipc/nodes/msg_ipc_forward.h"
|
#include "aqhome/msg/node/m_flashready.h"
|
||||||
#include "aqhome/msg/msg_node.h"
|
#include "aqhome/msg/node/m_flashstart.h"
|
||||||
#include "aqhome/msg/msg_flashready.h"
|
#include "aqhome/msg/node/m_flashend.h"
|
||||||
#include "aqhome/msg/msg_flashstart.h"
|
#include "aqhome/msg/node/m_flashdata.h"
|
||||||
#include "aqhome/msg/msg_flashresponse.h"
|
#include "aqhome/msg/node/m_flashresponse.h"
|
||||||
#include "aqhome/msg/msg_flashdata.h"
|
#include "aqhome/msg/node/m_reboot.h"
|
||||||
#include "aqhome/msg/msg_flashend.h"
|
|
||||||
#include "aqhome/msg/msg_reboot.h"
|
|
||||||
#include "aqhome/hexfile/hexfile.h"
|
#include "aqhome/hexfile/hexfile.h"
|
||||||
#include "aqhome/hexfile/flashrecord.h"
|
#include "aqhome/hexfile/flashrecord.h"
|
||||||
|
|
||||||
#include <gwenhywfar/args.h>
|
|
||||||
#include <gwenhywfar/i18n.h>
|
#include <gwenhywfar/i18n.h>
|
||||||
#include <gwenhywfar/debug.h>
|
#include <gwenhywfar/debug.h>
|
||||||
#include <gwenhywfar/text.h>
|
|
||||||
|
|
||||||
#include <time.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------------------------------
|
||||||
|
* defs
|
||||||
|
* ------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
#define I18S(msg) msg
|
#define I18S(msg) msg
|
||||||
#define I18N(msg) GWEN_I18N_Translate(PACKAGE, msg)
|
#define I18N(msg) GWEN_I18N_Translate(PACKAGE, msg)
|
||||||
|
|
||||||
#define FLASH_TOOL_MAX_REPEAT 16
|
#define A_ARG GWEN_ARGS_FLAGS_HAS_ARGUMENT
|
||||||
|
#define A_END (GWEN_ARGS_FLAGS_HELP | GWEN_ARGS_FLAGS_LAST)
|
||||||
|
#define A_CHAR GWEN_ArgsType_Char
|
||||||
|
#define A_INT GWEN_ArgsType_Int
|
||||||
|
|
||||||
/*#define DEBUG_FLASH*/
|
#define FLASH_TOOL_MAX_REPEAT 16
|
||||||
|
#define FLASH_TOOL_DEFAULT_TIMEOUTINSECS 5
|
||||||
|
|
||||||
|
|
||||||
static int _doFlash(GWEN_DB_NODE *dbArgs);
|
|
||||||
|
|
||||||
static AQH_FLASHRECORD_LIST *_readHexfileIntoFlashRecordList(const char *hexFilename);
|
/* ------------------------------------------------------------------------------------------------
|
||||||
|
* forward declarations
|
||||||
|
* ------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
static int _rebootNode(GWEN_MSG_ENDPOINT *epTcp, unsigned int uid, int timeoutInSeconds);
|
static int doFlash(AQH_OBJECT *o);
|
||||||
static int _performFlashProcedure(GWEN_MSG_ENDPOINT *epTcp,
|
static int _rebootNode(AQH_OBJECT *o, unsigned int uid, int timeoutInSeconds);
|
||||||
|
static int _performFlashProcedure(AQH_OBJECT *o,
|
||||||
unsigned int uid,
|
unsigned int uid,
|
||||||
const AQH_FLASHRECORD_LIST *flashRecordList,
|
const AQH_FLASHRECORD_LIST *flashRecordList,
|
||||||
int pageSize,
|
int pageSize,
|
||||||
int timeoutInSeconds);
|
int timeoutInSeconds);
|
||||||
|
static int _flashStart(AQH_OBJECT *o, unsigned int uid, int timeoutInSeconds);
|
||||||
|
static int _flashRecord(AQH_OBJECT *o,
|
||||||
|
const AQH_FLASHRECORD *flashRecord,
|
||||||
|
uint16_t pageSize,
|
||||||
|
int timeoutInSeconds);
|
||||||
|
static int _flashData(AQH_OBJECT *o, uint32_t address, const uint8_t *ptr, uint32_t len, int timeoutInSeconds);
|
||||||
|
static int _flashEnd(AQH_OBJECT *o, int reason, int timeoutInSeconds);
|
||||||
|
static int _waitForFlashResponse(AQH_OBJECT *o, int timeoutInSeconds);
|
||||||
|
static AQH_FLASHRECORD_LIST *_readHexfileIntoFlashRecordList(const char *hexFilename);
|
||||||
|
|
||||||
|
|
||||||
static int _flashStart(GWEN_MSG_ENDPOINT *epTcp, unsigned int uid, int timeoutInSeconds);
|
|
||||||
|
|
||||||
|
|
||||||
static GWEN_MSG *_waitForFlashReadyMessageForUid(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 *epTcp, int timeoutInSeconds);
|
|
||||||
static int _waitForRebootResponseMessage(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds);
|
|
||||||
static int _sendFlashRecord(GWEN_MSG_ENDPOINT *epTcp,
|
|
||||||
const AQH_FLASHRECORD *flashRecord,
|
|
||||||
uint16_t pageSize,
|
|
||||||
int timeoutInSeconds);
|
|
||||||
static int _sendFlashEnd(GWEN_MSG_ENDPOINT *epTcp, int reason, int timeoutInSeconds);
|
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------------------------------
|
||||||
|
* code
|
||||||
|
* ------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
int AQH_Tool_Flash(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
int AQH_Tool_Flash(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
||||||
{
|
{
|
||||||
GWEN_DB_NODE *dbLocalArgs;
|
AQH_EVENT_LOOP *eventLoop;
|
||||||
|
AQH_OBJECT *o;
|
||||||
int rv;
|
int rv;
|
||||||
const GWEN_ARGS args[]= {
|
const GWEN_ARGS args[]= {
|
||||||
{
|
/* flags type name min max s long short_descr, long_descr */
|
||||||
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
{ A_ARG, A_CHAR, "tcpAddress", 0, 1, "t", "tcpaddress", I18S("TCP address to connect to [127.0.0.1]"), NULL},
|
||||||
GWEN_ArgsType_Char, /* type */
|
{ A_ARG, A_INT, "tcpPort", 0, 1, "P", "tcpport", I18S("Specify the TCP port to listen on"), NULL},
|
||||||
"tcpAddress", /* name */
|
{ A_ARG, A_INT, "timeout", 0, 1, "T", NULL, I18S("Specify timeout in seconds for response"), NULL},
|
||||||
0, /* minnum */
|
{ A_ARG, A_CHAR, "userId", 0, 1, "u", "userid", I18S("Specify user id"), NULL},
|
||||||
1, /* maxnum */
|
{ A_ARG, A_CHAR, "password", 0, 1, "p", "password", I18S("Specify service password"), NULL},
|
||||||
"t", /* short option */
|
{ A_ARG, A_CHAR, "uid", 1, 1, "u", "uid", I18S("Specify UID of the node to flash"),NULL},
|
||||||
"tcpaddress", /* long option */
|
{ A_ARG, A_CHAR, "hexFilename", 1, 1, "H", NULL, I18S("Specify hexfile to flash"), NULL},
|
||||||
I18S("Specify TCP address to connect to (defaults to 127.0.0.1)"),
|
{ 0, A_INT, "reboot", 0, 1, "R", NULL, I18S("Request node reboot before trying to flash"), NULL},
|
||||||
I18S("Specify TCP address to connect to (defaults to 127.0.0.1)")
|
{ A_END, A_INT, "help", 0, 0, "h", "help", I18S("Show this help screen"), NULL}
|
||||||
},
|
|
||||||
{
|
|
||||||
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
|
||||||
GWEN_ArgsType_Int, /* type */
|
|
||||||
"tcpPort", /* name */
|
|
||||||
0, /* minnum */
|
|
||||||
1, /* maxnum */
|
|
||||||
"P", /* short option */
|
|
||||||
"tcpport", /* long option */
|
|
||||||
I18S("Specify the TCP port to listen on"),
|
|
||||||
I18S("Specify the TCP port to listen on")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
|
||||||
GWEN_ArgsType_Char, /* type */
|
|
||||||
"uid", /* name */
|
|
||||||
1, /* minnum */
|
|
||||||
1, /* maxnum */
|
|
||||||
"u", /* short option */
|
|
||||||
"uid", /* long option */
|
|
||||||
I18S("Specify UID of the node to flash"),
|
|
||||||
I18S("Specify UID of the node to flash)")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
|
||||||
GWEN_ArgsType_Char, /* type */
|
|
||||||
"hexFilename", /* name */
|
|
||||||
1, /* minnum */
|
|
||||||
1, /* maxnum */
|
|
||||||
"H", /* short option */
|
|
||||||
NULL, /* long option */
|
|
||||||
I18S("Specify hexfile to flash"),
|
|
||||||
I18S("Specify hexfile to flash)")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
|
||||||
GWEN_ArgsType_Int, /* type */
|
|
||||||
"timeout", /* name */
|
|
||||||
0, /* minnum */
|
|
||||||
1, /* maxnum */
|
|
||||||
"T", /* short option */
|
|
||||||
NULL, /* long option */
|
|
||||||
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 */
|
|
||||||
"help", /* name */
|
|
||||||
0, /* minnum */
|
|
||||||
0, /* maxnum */
|
|
||||||
"h", /* short option */
|
|
||||||
"help", /* long option */
|
|
||||||
"Show this help screen", /* short description */
|
|
||||||
"Show this help screen" /* long description */
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
dbLocalArgs=GWEN_DB_GetGroup(dbGlobalArgs, GWEN_DB_FLAGS_DEFAULT, "local");
|
eventLoop=AQH_EventLoop_new();
|
||||||
rv=GWEN_Args_Check(argc, argv, 1,
|
o=AQH_ToolClient_new(eventLoop, AQH_IPC_PROTOCOL_NODES_ID, AQH_IPC_PROTOCOL_NODES_VERSION, dbGlobalArgs, args);
|
||||||
GWEN_ARGS_MODE_ALLOW_FREEPARAM,
|
rv=AQH_ToolClient_ReadLocalArgs(o, argc, argv);
|
||||||
args,
|
if (rv!=0)
|
||||||
dbLocalArgs);
|
return rv;
|
||||||
if (rv==GWEN_ARGS_RESULT_ERROR) {
|
|
||||||
fprintf(stderr, "ERROR: Could not parse arguments\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else if (rv==GWEN_ARGS_RESULT_HELP) {
|
|
||||||
GWEN_BUFFER *ubuf;
|
|
||||||
|
|
||||||
ubuf=GWEN_Buffer_new(0, 1024, 0, 1);
|
rv=AQH_ToolClient_Connect(o, AQH_TOOL_CLIENT_CONNECTFLAGS_WITHCONNECTMSG | AQH_TOOL_CLIENT_CONNECTFLAGS_WITHGRPMSG,
|
||||||
if (GWEN_Args_Usage(args, ubuf, GWEN_ArgsOutType_Txt)) {
|
0, AQH_MSG_TYPEGROUP_FLASH);
|
||||||
fprintf(stderr, "ERROR: Could not create help string\n");
|
if (rv<0) {
|
||||||
return 1;
|
DBG_INFO(NULL, "here(%d)", rv);
|
||||||
}
|
AQH_Object_free(o);
|
||||||
fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(ubuf));
|
AQH_EventLoop_free(eventLoop);
|
||||||
GWEN_Buffer_free(ubuf);
|
return rv;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return _doFlash(dbLocalArgs);
|
rv=doFlash(o);
|
||||||
|
if (rv<0) {
|
||||||
|
DBG_INFO(NULL, "here(%d)", rv);
|
||||||
|
AQH_Object_free(o);
|
||||||
|
AQH_EventLoop_free(eventLoop);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
AQH_Object_free(o);
|
||||||
|
AQH_EventLoop_free(eventLoop);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int _doFlash(GWEN_DB_NODE *dbArgs)
|
int doFlash(AQH_OBJECT *o)
|
||||||
{
|
{
|
||||||
GWEN_MSG_ENDPOINT *epTcp;
|
GWEN_DB_NODE *dbArgs;
|
||||||
int rv;
|
int rv;
|
||||||
int timeoutInSeconds;
|
int timeoutInSeconds;
|
||||||
int doReboot;
|
int doReboot;
|
||||||
@@ -193,17 +136,21 @@ int _doFlash(GWEN_DB_NODE *dbArgs)
|
|||||||
unsigned int uid;
|
unsigned int uid;
|
||||||
const char *hexFilename;
|
const char *hexFilename;
|
||||||
AQH_FLASHRECORD_LIST *flashRecordList=NULL;
|
AQH_FLASHRECORD_LIST *flashRecordList=NULL;
|
||||||
GWEN_MSG *msg;
|
AQH_MESSAGE *msg;
|
||||||
uint16_t pageSize;
|
uint16_t pageSize;
|
||||||
|
|
||||||
|
dbArgs=AQH_ToolClient_GetDbLocalArgs(o);
|
||||||
|
|
||||||
/* read data */
|
/* read data */
|
||||||
timeoutInSeconds=GWEN_DB_GetIntValue(dbArgs, "timeout", 0, 30);
|
timeoutInSeconds=GWEN_DB_GetIntValue(dbArgs, "timeout", 0, FLASH_TOOL_DEFAULT_TIMEOUTINSECS);
|
||||||
doReboot=GWEN_DB_GetIntValue(dbArgs, "reboot", 0, 0);
|
doReboot=GWEN_DB_GetIntValue(dbArgs, "reboot", 0, 0);
|
||||||
s=GWEN_DB_GetCharValue(dbArgs, "uid", 0, NULL);
|
s=GWEN_DB_GetCharValue(dbArgs, "uid", 0, NULL);
|
||||||
if (1!=sscanf(s, "%x", &uid)) {
|
if (1!=sscanf(s, "%x", &uid)) {
|
||||||
DBG_ERROR(NULL, "Bad uid \"%s\"", s);
|
DBG_ERROR(NULL, "Bad uid \"%s\"", s);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* read hex file */
|
||||||
hexFilename=GWEN_DB_GetCharValue(dbArgs, "hexFilename", 0, NULL);
|
hexFilename=GWEN_DB_GetCharValue(dbArgs, "hexFilename", 0, NULL);
|
||||||
flashRecordList=_readHexfileIntoFlashRecordList(hexFilename);
|
flashRecordList=_readHexfileIntoFlashRecordList(hexFilename);
|
||||||
if (flashRecordList==NULL) {
|
if (flashRecordList==NULL) {
|
||||||
@@ -211,27 +158,12 @@ int _doFlash(GWEN_DB_NODE *dbArgs)
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* setup client connection */
|
/* probably reboot node */
|
||||||
epTcp=Utils_SetupNodesClientEndpoint(dbArgs);
|
|
||||||
if (epTcp==NULL) {
|
|
||||||
DBG_ERROR(NULL, "ERROR creating TCP connection");
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* declare accepted message type groups */
|
|
||||||
rv=Utils_SendAcceptedMsgGroups(epTcp, AQH_MSG_TYPEGROUP_FLASH);
|
|
||||||
if (rv<0) {
|
|
||||||
DBG_INFO(NULL, "here (%d)", rv);
|
|
||||||
GWEN_MsgEndpoint_free(epTcp);
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (doReboot) {
|
if (doReboot) {
|
||||||
fprintf(stdout, "Sending REBOOT request\n");
|
fprintf(stdout, "Sending REBOOT request\n");
|
||||||
rv=_rebootNode(epTcp, uid, timeoutInSeconds);
|
rv=_rebootNode(o, uid, timeoutInSeconds);
|
||||||
if (rv<0) {
|
if (rv<0) {
|
||||||
DBG_INFO(NULL, "here (%d)", rv);
|
DBG_INFO(NULL, "here (%d)", rv);
|
||||||
GWEN_MsgEndpoint_free(epTcp);
|
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
fprintf(stdout, "Reboot in progress\n");
|
fprintf(stdout, "Reboot in progress\n");
|
||||||
@@ -239,35 +171,258 @@ int _doFlash(GWEN_DB_NODE *dbArgs)
|
|||||||
|
|
||||||
/* wait for FLASH_READY message */
|
/* wait for FLASH_READY message */
|
||||||
fprintf(stdout, "Waiting for node to become ready for flashing\n");
|
fprintf(stdout, "Waiting for node to become ready for flashing\n");
|
||||||
msg=_waitForFlashReadyMessageForUid(epTcp, uid, timeoutInSeconds);
|
msg=AQH_ToolClient_WaitForNodeMsg(o, 0, AQH_MSG_TYPE_FLASH_READY, timeoutInSeconds);
|
||||||
if (msg==NULL) {
|
if (msg==NULL) {
|
||||||
DBG_INFO(NULL, "No FLASH_READY message received.");
|
DBG_INFO(NULL, "No FLASH_READY message received.");
|
||||||
GWEN_MsgEndpoint_free(epTcp);
|
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
DBG_INFO(NULL, "FLASH_READY message received");
|
DBG_INFO(NULL, "FLASH_READY message received");
|
||||||
pageSize=AQH_FlashReadyMsg_GetPagesize(msg);
|
pageSize=AQH_FlashReadyMessage_GetPagesize(msg);
|
||||||
fprintf(stdout, "Node is ready for flashing (pagesize=%d bytes)\n", pageSize);
|
fprintf(stdout, "Node is ready for flashing (pagesize=%d bytes)\n", pageSize);
|
||||||
GWEN_Msg_free(msg);
|
AQH_Message_free(msg);
|
||||||
|
|
||||||
/* perform flash */
|
/* perform flash */
|
||||||
rv=_performFlashProcedure(epTcp, uid, flashRecordList, pageSize, timeoutInSeconds);
|
rv=_performFlashProcedure(o, uid, flashRecordList, pageSize, timeoutInSeconds);
|
||||||
if (rv<0) {
|
if (rv<0) {
|
||||||
if (rv<0) {
|
if (rv<0) {
|
||||||
DBG_INFO(NULL, "here (%d)", rv);
|
DBG_INFO(NULL, "here (%d)", rv);
|
||||||
GWEN_MsgEndpoint_free(epTcp);
|
|
||||||
AQH_FlashRecord_List_free(flashRecordList);
|
AQH_FlashRecord_List_free(flashRecordList);
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AQH_FlashRecord_List_free(flashRecordList);
|
AQH_FlashRecord_List_free(flashRecordList);
|
||||||
GWEN_MsgEndpoint_free(epTcp);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int _rebootNode(AQH_OBJECT *o, unsigned int uid, int timeoutInSeconds)
|
||||||
|
{
|
||||||
|
AQH_MESSAGE *nodeMsg;
|
||||||
|
|
||||||
|
/* send REBOOT_REQUEST message */
|
||||||
|
fprintf(stdout, "- sending REBOOT request\n");
|
||||||
|
DBG_INFO(NULL, "Sending REBOOT REQUEST message");
|
||||||
|
nodeMsg=AQH_RebootMessage_new(0, 0xff, AQH_MSG_TYPE_REBOOT_REQ, uid);
|
||||||
|
if (nodeMsg==NULL) {
|
||||||
|
DBG_ERROR(NULL, "Error creating message");
|
||||||
|
return GWEN_ERROR_GENERIC;
|
||||||
|
}
|
||||||
|
|
||||||
|
AQH_ToolClient_SendNodeMsg(o, nodeMsg);
|
||||||
|
nodeMsg=AQH_ToolClient_WaitForNodeMsg(o, 0, AQH_MSG_TYPE_REBOOT_RSP, timeoutInSeconds);
|
||||||
|
if (nodeMsg==NULL) {
|
||||||
|
DBG_INFO(NULL, "Bad or no reboot response received.");
|
||||||
|
return GWEN_ERROR_GENERIC;
|
||||||
|
}
|
||||||
|
|
||||||
|
DBG_INFO(NULL, "REBOOT_RESPONSE message received");
|
||||||
|
AQH_Message_free(nodeMsg);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int _performFlashProcedure(AQH_OBJECT *o,
|
||||||
|
unsigned int uid,
|
||||||
|
const AQH_FLASHRECORD_LIST *flashRecordList,
|
||||||
|
int pageSize,
|
||||||
|
int timeoutInSeconds)
|
||||||
|
{
|
||||||
|
int rv;
|
||||||
|
const AQH_FLASHRECORD *flashRecord;
|
||||||
|
|
||||||
|
rv=_flashStart(o, uid, timeoutInSeconds);
|
||||||
|
if (rv<0) {
|
||||||
|
DBG_INFO(NULL, "here (%d)", rv);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
flashRecord=AQH_FlashRecord_List_First(flashRecordList);
|
||||||
|
while(flashRecord) {
|
||||||
|
DBG_ERROR(NULL, "Sending flash record at %08x", AQH_FlashRecord_GetAddress(flashRecord));
|
||||||
|
rv=_flashRecord(o, flashRecord, pageSize, timeoutInSeconds);
|
||||||
|
if (rv!=0) {
|
||||||
|
DBG_ERROR(NULL, "Error sending flash data (%d)", rv);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
flashRecord=AQH_FlashRecord_List_Next(flashRecord);
|
||||||
|
}
|
||||||
|
|
||||||
|
rv=_flashEnd(o, 0, timeoutInSeconds);
|
||||||
|
if (rv<0) {
|
||||||
|
DBG_INFO(NULL, "here (%d)", rv);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
DBG_ERROR(NULL, "Flash finished.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int _flashStart(AQH_OBJECT *o, unsigned int uid, int timeoutInSeconds)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i=0; i<FLASH_TOOL_MAX_REPEAT; i++) {
|
||||||
|
AQH_MESSAGE *nodeMsg;
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
if (i)
|
||||||
|
fprintf(stdout, "- sending FLASH_START (retry %d)\n", i);
|
||||||
|
else
|
||||||
|
fprintf(stdout, "- sending FLASH_START\n");
|
||||||
|
/* send FLASH_START message */
|
||||||
|
DBG_INFO(NULL, "Sending FLASH START message (%d)", i);
|
||||||
|
nodeMsg=AQH_FlashStartMessage_new(0, 0xc1, AQH_MSG_TYPE_FLASH_START, uid);
|
||||||
|
if (nodeMsg==NULL) {
|
||||||
|
DBG_ERROR(NULL, "Error creating message");
|
||||||
|
return GWEN_ERROR_GENERIC;
|
||||||
|
}
|
||||||
|
AQH_ToolClient_SendNodeMsg(o, nodeMsg);
|
||||||
|
rv=_waitForFlashResponse(o, timeoutInSeconds);
|
||||||
|
if (rv==0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DBG_INFO(NULL, "No FLASH_RESPONSE message received");
|
||||||
|
return GWEN_ERROR_GENERIC;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int _flashRecord(AQH_OBJECT *o,
|
||||||
|
const AQH_FLASHRECORD *flashRecord,
|
||||||
|
uint16_t pageSize,
|
||||||
|
int timeoutInSeconds)
|
||||||
|
{
|
||||||
|
const uint8_t *ptr;
|
||||||
|
uint32_t len;
|
||||||
|
uint32_t address;
|
||||||
|
|
||||||
|
ptr=AQH_FlashRecord_GetDataPointer(flashRecord);
|
||||||
|
len=AQH_FlashRecord_GetDataLength(flashRecord);
|
||||||
|
address=AQH_FlashRecord_GetAddress(flashRecord);
|
||||||
|
DBG_ERROR(NULL, "Sending record: addr=%04x, len=%d, pagesize=%d", address, len, pageSize);
|
||||||
|
while(ptr && len) {
|
||||||
|
int rv;
|
||||||
|
uint32_t sendLen;
|
||||||
|
|
||||||
|
usleep(100000);
|
||||||
|
sendLen=(len>pageSize)?pageSize:len;
|
||||||
|
rv=_flashData(o, address, ptr, sendLen, timeoutInSeconds);
|
||||||
|
if (rv<0) {
|
||||||
|
DBG_INFO(NULL, "here (%d)", rv);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
ptr+=sendLen;
|
||||||
|
address+=sendLen;
|
||||||
|
len-=sendLen;
|
||||||
|
} /* while */
|
||||||
|
DBG_ERROR(NULL, "Full record sent and acknowledged");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int _flashData(AQH_OBJECT *o, uint32_t address, const uint8_t *ptr, uint32_t len, int timeoutInSeconds)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i=0;i<FLASH_TOOL_MAX_REPEAT;i++) {
|
||||||
|
AQH_MESSAGE *nodeMsg;
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
#ifdef DEBUG_FLASH
|
||||||
|
DBG_ERROR(NULL, " Sending message: addr=%04x, data len=%d, pagesize=%d", address, len, pageSize);
|
||||||
|
GWEN_Text_LogString((const char*) ptr, len, NULL, GWEN_LoggerLevel_Error);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (i)
|
||||||
|
fprintf(stdout, "- send data: dest addr=%04x, len=%d bytes (retry %d)\n", address, len, i);
|
||||||
|
else
|
||||||
|
fprintf(stdout, "- send data: dest addr=%04x, len=%d bytes\n", address, len);
|
||||||
|
|
||||||
|
nodeMsg=AQH_FlashDataMessage_new(0, 0xc1, AQH_MSG_TYPE_FLASH_DATA, address, ptr, len);
|
||||||
|
if (nodeMsg==NULL) {
|
||||||
|
DBG_ERROR(NULL, "Error creating message");
|
||||||
|
return GWEN_ERROR_GENERIC;
|
||||||
|
}
|
||||||
|
|
||||||
|
AQH_ToolClient_SendNodeMsg(o, nodeMsg);
|
||||||
|
rv=_waitForFlashResponse(o, timeoutInSeconds);
|
||||||
|
if (rv==0)
|
||||||
|
return 0;
|
||||||
|
} /* for */
|
||||||
|
DBG_INFO(NULL, "No FLASH_RESPONSE message received");
|
||||||
|
return GWEN_ERROR_GENERIC;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int _flashEnd(AQH_OBJECT *o, int reason, int timeoutInSeconds)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i=0; i<FLASH_TOOL_MAX_REPEAT; i++) {
|
||||||
|
AQH_MESSAGE *nodeMsg;
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
if (i)
|
||||||
|
fprintf(stdout, "- sending FLASH_END (retry %d)\n", i);
|
||||||
|
else
|
||||||
|
fprintf(stdout, "- sending FLASH_END\n");
|
||||||
|
/* send FLASH_START message */
|
||||||
|
DBG_INFO(NULL, "Sending FLASH END message (%d)", i);
|
||||||
|
nodeMsg=AQH_FlashEndMessage_new(0, 0xc1, AQH_MSG_TYPE_FLASH_END, reason);
|
||||||
|
if (nodeMsg==NULL) {
|
||||||
|
DBG_ERROR(NULL, "Error creating message");
|
||||||
|
return GWEN_ERROR_GENERIC;
|
||||||
|
}
|
||||||
|
AQH_ToolClient_SendNodeMsg(o, nodeMsg);
|
||||||
|
rv=_waitForFlashResponse(o, timeoutInSeconds);
|
||||||
|
if (rv==0)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
DBG_INFO(NULL, "No FLASH_RESPONSE message received");
|
||||||
|
return GWEN_ERROR_GENERIC;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int _waitForFlashResponse(AQH_OBJECT *o, int timeoutInSeconds)
|
||||||
|
{
|
||||||
|
AQH_MESSAGE *nodeMsg;
|
||||||
|
|
||||||
|
nodeMsg=AQH_ToolClient_WaitForNodeMsg(o, 0, AQH_MSG_TYPE_FLASH_RSP, timeoutInSeconds);
|
||||||
|
if (nodeMsg==NULL) {
|
||||||
|
DBG_INFO(NULL, "Bad or no flash response received.");
|
||||||
|
return GWEN_ERROR_GENERIC;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
uint8_t result;
|
||||||
|
|
||||||
|
result=AQH_FlashResponseMessage_GetCode(nodeMsg);
|
||||||
|
AQH_Message_free(nodeMsg);
|
||||||
|
if (AQH_FlashResponseMessage_GetCode(nodeMsg)!=0) {
|
||||||
|
DBG_ERROR(NULL, "Negative FLASH_RESPONSE received (%d)", result);
|
||||||
|
return GWEN_ERROR_GENERIC;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
DBG_INFO(NULL, "FLASH_RESPONSE message received");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DBG_INFO(NULL, "No FLASH_RESPONSE message received");
|
||||||
|
return GWEN_ERROR_GENERIC;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AQH_FLASHRECORD_LIST *_readHexfileIntoFlashRecordList(const char *hexFilename)
|
AQH_FLASHRECORD_LIST *_readHexfileIntoFlashRecordList(const char *hexFilename)
|
||||||
{
|
{
|
||||||
AQH_HEXFILE *hexfile;
|
AQH_HEXFILE *hexfile;
|
||||||
@@ -293,327 +448,4 @@ AQH_FLASHRECORD_LIST *_readHexfileIntoFlashRecordList(const char *hexFilename)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int _rebootNode(GWEN_MSG_ENDPOINT *epTcp, unsigned int uid, int timeoutInSeconds)
|
|
||||||
{
|
|
||||||
int rv;
|
|
||||||
|
|
||||||
/* send REBOOT_REQUEST message */
|
|
||||||
DBG_INFO(NULL, "Sending REBOOT REQUEST message");
|
|
||||||
rv=_sendRebootRequest(epTcp, uid);
|
|
||||||
if (rv<0) {
|
|
||||||
DBG_INFO(NULL, "here (%d)", rv);
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
rv=_waitForRebootResponseMessage(epTcp, timeoutInSeconds);
|
|
||||||
if (rv!=0) {
|
|
||||||
DBG_INFO(NULL, "Bad or no reboot response received (%d).", rv);
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
DBG_INFO(NULL, "REBOOT_RESPONSE message received");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int _performFlashProcedure(GWEN_MSG_ENDPOINT *epTcp,
|
|
||||||
unsigned int uid,
|
|
||||||
const AQH_FLASHRECORD_LIST *flashRecordList,
|
|
||||||
int pageSize,
|
|
||||||
int timeoutInSeconds)
|
|
||||||
{
|
|
||||||
int rv;
|
|
||||||
const AQH_FLASHRECORD *flashRecord;
|
|
||||||
|
|
||||||
fprintf(stdout, "Sending FLASH_START\n");
|
|
||||||
rv=_flashStart(epTcp, uid, timeoutInSeconds);
|
|
||||||
if (rv<0) {
|
|
||||||
DBG_INFO(NULL, "here (%d)", rv);
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* send FLASH_DATA requests and retrieve FLASH_RSP responses */
|
|
||||||
flashRecord=AQH_FlashRecord_List_First(flashRecordList);
|
|
||||||
while(flashRecord) {
|
|
||||||
DBG_ERROR(NULL, "Sending flash record at %08x", AQH_FlashRecord_GetAddress(flashRecord));
|
|
||||||
rv=_sendFlashRecord(epTcp, flashRecord, pageSize, timeoutInSeconds);
|
|
||||||
if (rv!=0) {
|
|
||||||
DBG_ERROR(NULL, "Error sending flash data (%d)", rv);
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
flashRecord=AQH_FlashRecord_List_Next(flashRecord);
|
|
||||||
}
|
|
||||||
|
|
||||||
rv=_sendFlashEnd(epTcp, 0, timeoutInSeconds);
|
|
||||||
if (rv<0) {
|
|
||||||
DBG_INFO(NULL, "here (%d)", rv);
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
rv=Utils_FlushOutMessageQueue(epTcp, timeoutInSeconds);
|
|
||||||
if (rv<0) {
|
|
||||||
DBG_INFO(NULL, "here (%d)", rv);
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int _flashStart(GWEN_MSG_ENDPOINT *epTcp, unsigned int uid, int timeoutInSeconds)
|
|
||||||
{
|
|
||||||
int rv;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i=0; i<FLASH_TOOL_MAX_REPEAT; i++) {
|
|
||||||
if (i)
|
|
||||||
fprintf(stdout, " sending FLASH_START (retry %d)\n", i);
|
|
||||||
/* send FLASH_START message */
|
|
||||||
DBG_INFO(NULL, "Sending FLASH START message (%d)", i);
|
|
||||||
rv=_sendFlashStart(epTcp, uid);
|
|
||||||
if (rv<0) {
|
|
||||||
DBG_INFO(NULL, "here (%d)", rv);
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* wait for response */
|
|
||||||
rv=_waitForFlashResponseMessage(epTcp, timeoutInSeconds);
|
|
||||||
if (rv!=0) {
|
|
||||||
DBG_INFO(NULL, "Bad or no response received (%d).", rv);
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
DBG_INFO(NULL, "FLASH_RESPONSE message received");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GWEN_MSG *_waitForFlashReadyMessageForUid(GWEN_MSG_ENDPOINT *epTcp, unsigned int uid, int timeoutInSeconds)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i=0;i<16;i++) {
|
|
||||||
GWEN_MSG *msg;
|
|
||||||
unsigned int receivedUid;
|
|
||||||
|
|
||||||
msg=Utils_WaitForSpecificNodeMessage(epTcp, AQH_MSG_TYPE_FLASH_READY, 0, timeoutInSeconds);
|
|
||||||
if (msg==NULL) {
|
|
||||||
DBG_INFO(NULL, "No FLASH_READY message received.");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
receivedUid=AQH_FlashReadyMsg_GetUid(msg);
|
|
||||||
if (receivedUid==uid) {
|
|
||||||
DBG_INFO(NULL, "Received FLASH_READY message for given uid");
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
DBG_INFO(NULL, "Received FLASH_READY message but not for given uid (%08x)", receivedUid);
|
|
||||||
}
|
|
||||||
GWEN_Msg_free(msg);
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int _waitForRebootResponseMessage(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds)
|
|
||||||
{
|
|
||||||
GWEN_MSG *msg;
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
GWEN_Msg_free(msg);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int _waitForFlashResponseMessage(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds)
|
|
||||||
{
|
|
||||||
GWEN_MSG *msg;
|
|
||||||
int responseCode;
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
responseCode=AQH_FlashResponseMsg_GetCode(msg);
|
|
||||||
GWEN_Msg_free(msg);
|
|
||||||
return responseCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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_NODES_FORWARD,
|
|
||||||
GWEN_MsgEndpoint_GetNextMessageId(epTcp), 0,
|
|
||||||
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;
|
|
||||||
GWEN_MSG *msgOut;
|
|
||||||
|
|
||||||
msgNode=AQH_FlashStartMsg_new(0, 0xc1, AQH_MSG_TYPE_FLASH_START, uid);
|
|
||||||
if (msgNode==NULL) {
|
|
||||||
DBG_ERROR(NULL, "Error creating message");
|
|
||||||
return GWEN_ERROR_GENERIC;
|
|
||||||
}
|
|
||||||
|
|
||||||
msgOut=AQH_ForwardIpcMsg_new(AQH_MSGTYPE_IPC_NODES_FORWARD,
|
|
||||||
GWEN_MsgEndpoint_GetNextMessageId(epTcp), 0,
|
|
||||||
GWEN_Msg_GetConstBuffer(msgNode), GWEN_Msg_GetBytesInBuffer(msgNode));
|
|
||||||
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
|
|
||||||
GWEN_Msg_free(msgNode);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int _sendFlashEnd(GWEN_MSG_ENDPOINT *epTcp, int reason, int timeoutInSeconds)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i=0;i<FLASH_TOOL_MAX_REPEAT;i++) {
|
|
||||||
GWEN_MSG *msgNode;
|
|
||||||
GWEN_MSG *msgOut;
|
|
||||||
int rv;
|
|
||||||
|
|
||||||
fprintf(stdout, "Sending end\n");
|
|
||||||
|
|
||||||
usleep(100000);
|
|
||||||
|
|
||||||
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_NODES_FORWARD,
|
|
||||||
GWEN_MsgEndpoint_GetNextMessageId(epTcp), 0,
|
|
||||||
GWEN_Msg_GetConstBuffer(msgNode), GWEN_Msg_GetBytesInBuffer(msgNode));
|
|
||||||
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
|
|
||||||
GWEN_Msg_free(msgNode);
|
|
||||||
|
|
||||||
rv=_waitForFlashResponseMessage(epTcp, timeoutInSeconds);
|
|
||||||
if (rv==0) {
|
|
||||||
fprintf(stdout, "-> ACK received.\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
DBG_ERROR(NULL, "Negative response to flash end message (%d)", rv);
|
|
||||||
}
|
|
||||||
} /* for */
|
|
||||||
if (i>=FLASH_TOOL_MAX_REPEAT) {
|
|
||||||
DBG_ERROR(NULL, "Too many errors (tried %d times), giving up", i);
|
|
||||||
return GWEN_ERROR_IO;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int _sendFlashRecord(GWEN_MSG_ENDPOINT *epTcp,
|
|
||||||
const AQH_FLASHRECORD *flashRecord,
|
|
||||||
uint16_t pageSize,
|
|
||||||
int timeoutInSeconds)
|
|
||||||
{
|
|
||||||
const uint8_t *ptr;
|
|
||||||
uint32_t len;
|
|
||||||
uint32_t address;
|
|
||||||
|
|
||||||
ptr=AQH_FlashRecord_GetDataPointer(flashRecord);
|
|
||||||
len=AQH_FlashRecord_GetDataLength(flashRecord);
|
|
||||||
address=AQH_FlashRecord_GetAddress(flashRecord);
|
|
||||||
while(ptr && len) {
|
|
||||||
uint32_t sendLen;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
sendLen=(len>pageSize)?pageSize:len;
|
|
||||||
for (i=0;i<FLASH_TOOL_MAX_REPEAT;i++) {
|
|
||||||
GWEN_MSG *msgNode;
|
|
||||||
GWEN_MSG *msgOut;
|
|
||||||
int rv;
|
|
||||||
|
|
||||||
#ifdef DEBUG_FLASH
|
|
||||||
DBG_ERROR(NULL, " Sending message: addr=%04x, data len=%d, pagesize=%d", address, sendLen, pageSize);
|
|
||||||
GWEN_Text_LogString((const char*) ptr, sendLen, NULL, GWEN_LoggerLevel_Error);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (i)
|
|
||||||
fprintf(stdout, "Send data: dest addr=%04x, len=%d bytes (retry %d)\n", address, sendLen, i);
|
|
||||||
else
|
|
||||||
fprintf(stdout, "Send data: dest addr=%04x, len=%d bytes\n", address, sendLen);
|
|
||||||
|
|
||||||
usleep(100000);
|
|
||||||
|
|
||||||
msgNode=AQH_FlashDataMsg_new(0, 0xc1, AQH_MSG_TYPE_FLASH_DATA, address, ptr, sendLen);
|
|
||||||
if (msgNode==NULL) {
|
|
||||||
DBG_ERROR(NULL, "Error creating message");
|
|
||||||
return GWEN_ERROR_GENERIC;
|
|
||||||
}
|
|
||||||
|
|
||||||
msgOut=AQH_ForwardIpcMsg_new(AQH_MSGTYPE_IPC_NODES_FORWARD,
|
|
||||||
GWEN_MsgEndpoint_GetNextMessageId(epTcp), 0,
|
|
||||||
GWEN_Msg_GetConstBuffer(msgNode), GWEN_Msg_GetBytesInBuffer(msgNode));
|
|
||||||
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
|
|
||||||
GWEN_Msg_free(msgNode);
|
|
||||||
|
|
||||||
rv=_waitForFlashResponseMessage(epTcp, timeoutInSeconds);
|
|
||||||
if (rv==0) {
|
|
||||||
fprintf(stdout, "-> ACK received.\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
DBG_ERROR(NULL, "Negative response to flash data message (%d)", rv);
|
|
||||||
}
|
|
||||||
} /* for */
|
|
||||||
if (i>=FLASH_TOOL_MAX_REPEAT) {
|
|
||||||
DBG_ERROR(NULL, "Too many errors (tried %d times), giving up", i);
|
|
||||||
/* TODO: send flash end message */
|
|
||||||
return GWEN_ERROR_IO;
|
|
||||||
}
|
|
||||||
ptr+=sendLen;
|
|
||||||
address+=sendLen;
|
|
||||||
len-=sendLen;
|
|
||||||
} /* while */
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* This file is part of the project AqHome.
|
* This file is part of the project AqHome.
|
||||||
* AqHome (c) by 2023 Martin Preuss, all rights reserved.
|
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
|
||||||
*
|
*
|
||||||
* The license for this file can be found in the file COPYING which you
|
* The license for this file can be found in the file COPYING which you
|
||||||
* should have received along with this file.
|
* should have received along with this file.
|
||||||
@@ -11,213 +11,156 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "./getnodes.h"
|
#include "./getnodes.h"
|
||||||
|
#include "../client.h"
|
||||||
#include "../utils.h"
|
#include "../utils.h"
|
||||||
|
|
||||||
#include "aqhome/ipc/endpoint_ipc.h"
|
#include "aqhome/msg/ipc/m_ipc.h"
|
||||||
#include "aqhome/ipc/nodes/msg_ipc_getdevices_req.h"
|
#include "aqhome/msg/ipc/m_ipc_result.h"
|
||||||
#include "aqhome/ipc/nodes/msg_ipc_getdevices_rsp.h"
|
#include "aqhome/msg/ipc/nodes/m_ipcn.h"
|
||||||
#include "aqhome/ipc/msg_ipc_result.h"
|
#include "aqhome/msg/ipc/nodes/m_ipcn_getdevices_req.h"
|
||||||
#include "aqhome/msg/msg_node.h"
|
#include "aqhome/msg/ipc/nodes/m_ipcn_getdevices_rsp.h"
|
||||||
|
#include <aqhome/nodes/nodeinfo.h>
|
||||||
|
|
||||||
#include <gwenhywfar/args.h>
|
#include <gwenhywfar/args.h>
|
||||||
#include <gwenhywfar/i18n.h>
|
#include <gwenhywfar/i18n.h>
|
||||||
#include <gwenhywfar/debug.h>
|
#include <gwenhywfar/debug.h>
|
||||||
#include <gwenhywfar/text.h>
|
#include <gwenhywfar/text.h>
|
||||||
|
|
||||||
#include <time.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------------------------------
|
||||||
|
* defs
|
||||||
|
* ------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
#define I18S(msg) msg
|
#define I18S(msg) msg
|
||||||
#define I18N(msg) GWEN_I18N_Translate(PACKAGE, msg)
|
#define I18N(msg) GWEN_I18N_Translate(PACKAGE, msg)
|
||||||
|
|
||||||
|
#define A_ARG GWEN_ARGS_FLAGS_HAS_ARGUMENT
|
||||||
|
#define A_END (GWEN_ARGS_FLAGS_HELP | GWEN_ARGS_FLAGS_LAST)
|
||||||
|
#define A_CHAR GWEN_ArgsType_Char
|
||||||
|
#define A_INT GWEN_ArgsType_Int
|
||||||
|
|
||||||
|
|
||||||
static int _doGetNodes(GWEN_DB_NODE *dbArgs);
|
|
||||||
static int _sendGetDevices(GWEN_MSG_ENDPOINT *epTcp);
|
/* ------------------------------------------------------------------------------------------------
|
||||||
static void _printNodeFromMsg(const GWEN_MSG *msg);
|
* forward declarations
|
||||||
|
* ------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
static AQH_MESSAGE *_createRequestMessage(AQH_OBJECT *o, uint32_t msgId);
|
||||||
|
static int _handleResponseMessage(AQH_OBJECT *o, const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList, int first);
|
||||||
|
static void _printNode(const AQH_NODE_INFO *ni);
|
||||||
static void _printUintAsTextOrHex(uint32_t u, int bits);
|
static void _printUintAsTextOrHex(uint32_t u, int bits);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------------------------------
|
||||||
|
* code
|
||||||
|
* ------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
int AQH_Tool_GetNodes(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
int AQH_Tool_GetNodes(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
||||||
{
|
{
|
||||||
GWEN_DB_NODE *dbLocalArgs;
|
AQH_EVENT_LOOP *eventLoop;
|
||||||
|
AQH_OBJECT *o;
|
||||||
int rv;
|
int rv;
|
||||||
const GWEN_ARGS args[]= {
|
const GWEN_ARGS args[]= {
|
||||||
{
|
/* flags type name min max s long short_descr, long_descr */
|
||||||
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
{ A_ARG, A_CHAR, "tcpAddress", 0, 1, "t", "tcpaddress", I18S("TCP address to connect to [127.0.0.1]"), NULL},
|
||||||
GWEN_ArgsType_Char, /* type */
|
{ A_ARG, A_INT, "tcpPort", 0, 1, "P", "tcpport", I18S("TCP port to connect to"), NULL},
|
||||||
"tcpAddress", /* name */
|
{ A_ARG, A_INT, "timeout", 0, 1, "T", NULL, I18S("Specify timeout in seconds for response"), NULL},
|
||||||
0, /* minnum */
|
{ 0, A_INT, "printHeader", 0, 1, "H", "printheader", I18S("Print header if given"), NULL},
|
||||||
1, /* maxnum */
|
{ A_END, A_INT, "help", 0, 0, "h", "help", I18S("Show this help screen"), NULL}
|
||||||
"t", /* short option */
|
|
||||||
"tcpaddress", /* long option */
|
|
||||||
I18S("Specify TCP address to connect to (defaults to 127.0.0.1)"),
|
|
||||||
I18S("Specify TCP address to connect to (defaults to 127.0.0.1)")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
|
||||||
GWEN_ArgsType_Int, /* type */
|
|
||||||
"tcpPort", /* name */
|
|
||||||
0, /* minnum */
|
|
||||||
1, /* maxnum */
|
|
||||||
"P", /* short option */
|
|
||||||
"tcpport", /* long option */
|
|
||||||
I18S("Specify the TCP port to listen on"),
|
|
||||||
I18S("Specify the TCP port to listen on")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
|
||||||
GWEN_ArgsType_Int, /* type */
|
|
||||||
"timeout", /* name */
|
|
||||||
0, /* minnum */
|
|
||||||
1, /* maxnum */
|
|
||||||
"T", /* short option */
|
|
||||||
NULL, /* long option */
|
|
||||||
I18S("Specify timeout in seconds for PONG response"),
|
|
||||||
I18S("Specify timeout in seconds for PONG response")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
GWEN_ARGS_FLAGS_HELP | GWEN_ARGS_FLAGS_LAST, /* flags */
|
|
||||||
GWEN_ArgsType_Int, /* type */
|
|
||||||
"help", /* name */
|
|
||||||
0, /* minnum */
|
|
||||||
0, /* maxnum */
|
|
||||||
"h", /* short option */
|
|
||||||
"help", /* long option */
|
|
||||||
"Show this help screen", /* short description */
|
|
||||||
"Show this help screen" /* long description */
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
dbLocalArgs=GWEN_DB_GetGroup(dbGlobalArgs, GWEN_DB_FLAGS_DEFAULT, "local");
|
eventLoop=AQH_EventLoop_new();
|
||||||
rv=GWEN_Args_Check(argc, argv, 1,
|
o=AQH_ToolClient_new(eventLoop, AQH_IPC_PROTOCOL_NODES_ID, AQH_IPC_PROTOCOL_NODES_VERSION, dbGlobalArgs, args);
|
||||||
GWEN_ARGS_MODE_ALLOW_FREEPARAM,
|
AQH_ToolClient_SetCreateRequestMessageFn(o, _createRequestMessage);
|
||||||
args,
|
AQH_ToolClient_SetHandleResponseMessageFn(o, _handleResponseMessage);
|
||||||
dbLocalArgs);
|
rv=AQH_ToolClient_ReadLocalArgs(o, argc, argv);
|
||||||
if (rv==GWEN_ARGS_RESULT_ERROR) {
|
if (rv!=0)
|
||||||
fprintf(stderr, "ERROR: Could not parse arguments\n");
|
return rv;
|
||||||
return 1;
|
rv=AQH_ToolClient_Run(o);
|
||||||
}
|
AQH_Object_free(o);
|
||||||
else if (rv==GWEN_ARGS_RESULT_HELP) {
|
AQH_EventLoop_free(eventLoop);
|
||||||
GWEN_BUFFER *ubuf;
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
ubuf=GWEN_Buffer_new(0, 1024, 0, 1);
|
|
||||||
if (GWEN_Args_Usage(args, ubuf, GWEN_ArgsOutType_Txt)) {
|
|
||||||
fprintf(stderr, "ERROR: Could not create help string\n");
|
AQH_MESSAGE *_createRequestMessage(GWEN_UNUSED AQH_OBJECT *o, uint32_t msgId)
|
||||||
|
{
|
||||||
|
return AQH_IpcnMessageGetDevicesReq_new(AQH_MSGTYPE_IPC_NODES_GETDEVICES_REQ, msgId, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int _handleResponseMessage(GWEN_UNUSED AQH_OBJECT *o, const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList, int first)
|
||||||
|
{
|
||||||
|
uint16_t code;
|
||||||
|
//GWEN_DB_NODE *dbArgs;
|
||||||
|
//int printHeader;
|
||||||
|
|
||||||
|
//dbArgs=AQH_ToolClient_GetDbLocalArgs(o);
|
||||||
|
//printHeader=first?GWEN_DB_GetIntValue(dbArgs, "printHeader", 0, 0):0;
|
||||||
|
|
||||||
|
code=AQH_IpcMessage_GetCode(msg);
|
||||||
|
if (code==AQH_MSGTYPE_IPC_NODES_GETDEVICES_RSP) {
|
||||||
|
AQH_NODE_INFO *ni;
|
||||||
|
|
||||||
|
ni=AQH_IpcnMessageGetDevicesRsp_ReadNodeInfo(tagList);
|
||||||
|
if (ni)
|
||||||
|
_printNode(ni);
|
||||||
|
|
||||||
|
if (AQH_IpcnMessageGetDevicesRsp_GetFlags(tagList) & AQH_MSGNODE_GETDEVICES_RSP_FLAGS_LASTMSG) {
|
||||||
|
DBG_INFO(NULL, "Last message received");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(ubuf));
|
|
||||||
GWEN_Buffer_free(ubuf);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
else if (code==AQH_MSGTYPE_IPC_NODES_RESULT)
|
||||||
return _doGetNodes(dbLocalArgs);
|
return AQH_ToolClient_HandleResultMsg(msg, tagList, first);
|
||||||
|
else {
|
||||||
|
DBG_INFO(NULL, "Unexpected message \"%d\"", code);
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int _doGetNodes(GWEN_DB_NODE *dbArgs)
|
|
||||||
{
|
|
||||||
GWEN_MSG_ENDPOINT *epTcp;
|
|
||||||
int rv;
|
|
||||||
int timeoutInSeconds;
|
|
||||||
|
|
||||||
epTcp=Utils_SetupNodesClientEndpoint(dbArgs);
|
void _printNode(const AQH_NODE_INFO *ni)
|
||||||
if (epTcp==NULL) {
|
|
||||||
DBG_ERROR(NULL, "ERROR creating TCP connection");
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
timeoutInSeconds=GWEN_DB_GetIntValue(dbArgs, "timeout", 0, 5);
|
|
||||||
|
|
||||||
rv=Utils_SendAcceptedMsgGroups(epTcp, 0);
|
|
||||||
if (rv<0) {
|
|
||||||
DBG_INFO(NULL, "here (%d)", rv);
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
rv=_sendGetDevices(epTcp);
|
|
||||||
if (rv<0) {
|
|
||||||
DBG_INFO(NULL, "here (%d)", rv);
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
GWEN_MSG *msg;
|
|
||||||
uint16_t code;
|
|
||||||
|
|
||||||
msg=Utils_WaitForSpecificIpcMessage(epTcp, AQH_MSGTYPE_IPC_NODES_GETDEVICES_RSP, timeoutInSeconds);
|
|
||||||
if (msg==NULL) {
|
|
||||||
DBG_INFO(NULL, "No GET_DEVICE response received.");
|
|
||||||
GWEN_MsgEndpoint_free(epTcp);
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
code=GWEN_IpcMsg_GetCode(msg);
|
|
||||||
if (code==AQH_MSGTYPE_IPC_NODES_RESULT) {
|
|
||||||
fprintf(stdout, "No device list (%d)\n", AQH_ResultIpcMsg_GetResultCode(msg));
|
|
||||||
GWEN_Msg_free(msg);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if (code==AQH_MSGTYPE_IPC_NODES_GETDEVICES_RSP) {
|
|
||||||
uint8_t flags;
|
|
||||||
|
|
||||||
flags=AQH_GetDevicesResponseIpcMsg_GetFlags(msg);
|
|
||||||
_printNodeFromMsg(msg);
|
|
||||||
|
|
||||||
GWEN_Msg_free(msg);
|
|
||||||
if (flags & AQH_MSGIPC_GETDEVICES_RSP_FLAGS_LAST) {
|
|
||||||
DBG_INFO(NULL, "Last");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
GWEN_Msg_free(msg);
|
|
||||||
return GWEN_ERROR_GENERIC;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
GWEN_MsgEndpoint_free(epTcp);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void _printNodeFromMsg(const GWEN_MSG *msg)
|
|
||||||
{
|
{
|
||||||
uint32_t u;
|
uint32_t u;
|
||||||
int64_t ts64;
|
const GWEN_TIMESTAMP *ts;
|
||||||
GWEN_TIMESTAMP *ts;
|
|
||||||
|
|
||||||
ts64=AQH_GetDevicesResponseIpcMsg_GetTimestamp(msg);
|
|
||||||
ts=GWEN_Timestamp_fromInt64(ts64); /* TODO: fix timestamp */
|
|
||||||
|
|
||||||
fprintf(stdout, "- node: addr=%d, uid=0x%08x, device=",
|
fprintf(stdout, "- node: addr=%d, uid=0x%08x, device=",
|
||||||
AQH_GetDevicesResponseIpcMsg_GetBusAddress(msg),
|
AQH_NodeInfo_GetBusAddress(ni),
|
||||||
(unsigned int) AQH_GetDevicesResponseIpcMsg_GetUid(msg));
|
(unsigned int) AQH_NodeInfo_GetUid(ni));
|
||||||
u=AQH_GetDevicesResponseIpcMsg_GetManufacturer(msg);
|
ts=AQH_NodeInfo_GetTimestampLastChange(ni);
|
||||||
|
|
||||||
|
u=AQH_NodeInfo_GetManufacturer(ni);
|
||||||
_printUintAsTextOrHex(u, 32);
|
_printUintAsTextOrHex(u, 32);
|
||||||
fprintf(stdout, ":");
|
fprintf(stdout, ":");
|
||||||
u=AQH_GetDevicesResponseIpcMsg_GetDeviceType(msg);
|
u=AQH_NodeInfo_GetDeviceType(ni);
|
||||||
_printUintAsTextOrHex(u, 16);
|
_printUintAsTextOrHex(u, 16);
|
||||||
u=AQH_GetDevicesResponseIpcMsg_GetDeviceVersion(msg);
|
u=AQH_NodeInfo_GetDeviceVersion(ni);
|
||||||
fprintf(stdout, " v%d.%d", (u>>8) & 0xff, u & 0xff);
|
fprintf(stdout, " v%d.%d", (u>>8) & 0xff, u & 0xff);
|
||||||
u=AQH_GetDevicesResponseIpcMsg_GetFirmwareVersion(msg);
|
u=AQH_NodeInfo_GetFirmwareVersion(ni);
|
||||||
fprintf(stdout, ", firmware=%d.%d.%d (%d), ",
|
fprintf(stdout, ", firmware=%d.%d.%d (%d), ",
|
||||||
(u>>16) & 0xff, (u>>8) & 0xff, u & 0xff, (u>>24) & 0xff);
|
(u>>16) & 0xff, (u>>8) & 0xff, u & 0xff, (u>>24) & 0xff);
|
||||||
if (ts) {
|
if (ts)
|
||||||
fprintf(stdout, "last seen %s, ", GWEN_Timestamp_GetString(ts));
|
fprintf(stdout, "last seen %s, ", GWEN_Timestamp_GetString(ts));
|
||||||
GWEN_Timestamp_free(ts);
|
|
||||||
}
|
|
||||||
fprintf(stdout, "pkg out: %d, pkg in: %d, collisions: %d, busy: %d, crc: %d, io: %d\n",
|
fprintf(stdout, "pkg out: %d, pkg in: %d, collisions: %d, busy: %d, crc: %d, io: %d\n",
|
||||||
AQH_GetDevicesResponseIpcMsg_GetPkgOut(msg),
|
AQH_NodeInfo_GetStatsPacketsOut(ni),
|
||||||
AQH_GetDevicesResponseIpcMsg_GetPkgIn(msg),
|
AQH_NodeInfo_GetStatsPacketsIn(ni),
|
||||||
AQH_GetDevicesResponseIpcMsg_GetCollisions(msg),
|
AQH_NodeInfo_GetStatsCollisions(ni),
|
||||||
AQH_GetDevicesResponseIpcMsg_GetBusy(msg),
|
AQH_NodeInfo_GetStatsBusy(ni),
|
||||||
AQH_GetDevicesResponseIpcMsg_GetCrcErrors(msg),
|
AQH_NodeInfo_GetStatsCrcErrors(ni),
|
||||||
AQH_GetDevicesResponseIpcMsg_GetIoErrors(msg));
|
AQH_NodeInfo_GetStatsIoErrors(ni));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -250,22 +193,3 @@ void _printUintAsTextOrHex(uint32_t u, int bits)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int _sendGetDevices(GWEN_MSG_ENDPOINT *epTcp)
|
|
||||||
{
|
|
||||||
GWEN_MSG *msgOut;
|
|
||||||
|
|
||||||
msgOut=AQH_GetDevicesRequestIpcMsg_new(AQH_MSGTYPE_IPC_NODES_GETDEVICES_REQ,
|
|
||||||
GWEN_MsgEndpoint_GetNextMessageId(epTcp), 0);
|
|
||||||
if (msgOut==NULL) {
|
|
||||||
DBG_ERROR(NULL, "Error creating message");
|
|
||||||
return GWEN_ERROR_GENERIC;
|
|
||||||
}
|
|
||||||
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* This file is part of the project AqHome.
|
* This file is part of the project AqHome.
|
||||||
* AqHome (c) by 2023 Martin Preuss, all rights reserved.
|
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
|
||||||
*
|
*
|
||||||
* The license for this file can be found in the file COPYING which you
|
* The license for this file can be found in the file COPYING which you
|
||||||
* should have received along with this file.
|
* should have received along with this file.
|
||||||
@@ -11,181 +11,128 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "./ping.h"
|
#include "./ping.h"
|
||||||
|
#include "../client.h"
|
||||||
#include "../utils.h"
|
#include "../utils.h"
|
||||||
|
|
||||||
#include "aqhome/ipc/nodes/msg_ipc_setaccmsggrps.h"
|
#include "aqhome/msg/ipc/m_ipc.h"
|
||||||
#include "aqhome/ipc/nodes/msg_ipc_ping.h"
|
#include "aqhome/msg/ipc/m_ipc_result.h"
|
||||||
#include "aqhome/ipc/nodes/msg_ipc_forward.h"
|
#include "aqhome/msg/ipc/nodes/m_ipcn.h"
|
||||||
#include "aqhome/ipc/endpoint_ipc.h"
|
#include "aqhome/msg/ipc/nodes/m_ipcn_forward.h"
|
||||||
#include "aqhome/msg/msg_node.h"
|
#include "aqhome/msg/node/m_node.h"
|
||||||
|
#include "aqhome/msg/node/m_ping.h"
|
||||||
|
#include "aqhome/msg/node/m_pong.h"
|
||||||
|
|
||||||
#include <gwenhywfar/args.h>
|
#include <gwenhywfar/args.h>
|
||||||
#include <gwenhywfar/i18n.h>
|
#include <gwenhywfar/i18n.h>
|
||||||
#include <gwenhywfar/debug.h>
|
#include <gwenhywfar/debug.h>
|
||||||
#include <gwenhywfar/text.h>
|
#include <gwenhywfar/text.h>
|
||||||
|
|
||||||
#include <time.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------------------------------
|
||||||
|
* defs
|
||||||
|
* ------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
#define I18S(msg) msg
|
#define I18S(msg) msg
|
||||||
#define I18N(msg) GWEN_I18N_Translate(PACKAGE, msg)
|
#define I18N(msg) GWEN_I18N_Translate(PACKAGE, msg)
|
||||||
|
|
||||||
|
#define A_ARG GWEN_ARGS_FLAGS_HAS_ARGUMENT
|
||||||
|
#define A_END (GWEN_ARGS_FLAGS_HELP | GWEN_ARGS_FLAGS_LAST)
|
||||||
|
#define A_CHAR GWEN_ArgsType_Char
|
||||||
|
#define A_INT GWEN_ArgsType_Int
|
||||||
|
|
||||||
|
|
||||||
static int _doPing(GWEN_DB_NODE *dbArgs);
|
/* ------------------------------------------------------------------------------------------------
|
||||||
static int _sendPing(GWEN_MSG_ENDPOINT *epTcp, int nodeAddr);
|
* forward declarations
|
||||||
|
* ------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
static AQH_MESSAGE *_createRequestMessage(AQH_OBJECT *o, uint32_t msgId);
|
||||||
|
static int _handleResponseMessage(AQH_OBJECT *o, const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList, int first);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------------------------------
|
||||||
|
* implementations
|
||||||
|
* ------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
int AQH_Tool_Ping(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
int AQH_Tool_Ping(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
||||||
{
|
{
|
||||||
GWEN_DB_NODE *dbLocalArgs;
|
AQH_EVENT_LOOP *eventLoop;
|
||||||
|
AQH_OBJECT *o;
|
||||||
int rv;
|
int rv;
|
||||||
const GWEN_ARGS args[]= {
|
const GWEN_ARGS args[]= {
|
||||||
{
|
/* flags type name min max s long short_descr, long_descr */
|
||||||
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
{ A_ARG, A_CHAR, "tcpAddress", 0, 1, "t", "tcpaddress", I18S("TCP address to connect to [127.0.0.1]"), NULL},
|
||||||
GWEN_ArgsType_Char, /* type */
|
{ A_ARG, A_INT, "tcpPort", 0, 1, "P", "tcpport", I18S("Specify the TCP port to listen on"), NULL},
|
||||||
"tcpAddress", /* name */
|
{ A_ARG, A_INT, "timeout", 0, 1, "T", NULL, I18S("Specify timeout in seconds for response"), NULL},
|
||||||
0, /* minnum */
|
{ A_ARG, A_CHAR, "userId", 0, 1, "u", "userid", I18S("Specify user id"), NULL},
|
||||||
1, /* maxnum */
|
{ A_ARG, A_CHAR, "password", 0, 1, "p", "password", I18S("Specify service password"), NULL},
|
||||||
"t", /* short option */
|
{ A_ARG, A_INT, "nodeAddr", 1, 1, "n", "nodeaddr", I18S("Specify bus addr of the node to ping"), NULL},
|
||||||
"tcpaddress", /* long option */
|
{ A_END, A_INT, "help", 0, 0, "h", "help", I18S("Show this help screen"), NULL}
|
||||||
I18S("Specify TCP address to connect to (defaults to 127.0.0.1)"),
|
|
||||||
I18S("Specify TCP address to connect to (defaults to 127.0.0.1)")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
|
||||||
GWEN_ArgsType_Int, /* type */
|
|
||||||
"tcpPort", /* name */
|
|
||||||
0, /* minnum */
|
|
||||||
1, /* maxnum */
|
|
||||||
"P", /* short option */
|
|
||||||
"tcpport", /* long option */
|
|
||||||
I18S("Specify the TCP port to listen on"),
|
|
||||||
I18S("Specify the TCP port to listen on")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
|
||||||
GWEN_ArgsType_Int, /* type */
|
|
||||||
"nodeAddr", /* name */
|
|
||||||
1, /* minnum */
|
|
||||||
1, /* maxnum */
|
|
||||||
"n", /* short option */
|
|
||||||
"nodeaddr", /* long option */
|
|
||||||
I18S("Specify bus addr of the node to ping"),
|
|
||||||
I18S("Specify bus addr of the node to ping")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
|
||||||
GWEN_ArgsType_Int, /* type */
|
|
||||||
"timeout", /* name */
|
|
||||||
0, /* minnum */
|
|
||||||
1, /* maxnum */
|
|
||||||
"T", /* short option */
|
|
||||||
NULL, /* long option */
|
|
||||||
I18S("Specify timeout in seconds for PONG response"),
|
|
||||||
I18S("Specify timeout in seconds for PONG response")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
GWEN_ARGS_FLAGS_HELP | GWEN_ARGS_FLAGS_LAST, /* flags */
|
|
||||||
GWEN_ArgsType_Int, /* type */
|
|
||||||
"help", /* name */
|
|
||||||
0, /* minnum */
|
|
||||||
0, /* maxnum */
|
|
||||||
"h", /* short option */
|
|
||||||
"help", /* long option */
|
|
||||||
"Show this help screen", /* short description */
|
|
||||||
"Show this help screen" /* long description */
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
dbLocalArgs=GWEN_DB_GetGroup(dbGlobalArgs, GWEN_DB_FLAGS_DEFAULT, "local");
|
eventLoop=AQH_EventLoop_new();
|
||||||
rv=GWEN_Args_Check(argc, argv, 1,
|
o=AQH_ToolClient_new(eventLoop, AQH_IPC_PROTOCOL_NODES_ID, AQH_IPC_PROTOCOL_NODES_VERSION, dbGlobalArgs, args);
|
||||||
GWEN_ARGS_MODE_ALLOW_FREEPARAM,
|
AQH_ToolClient_SetCreateRequestMessageFn(o, _createRequestMessage);
|
||||||
args,
|
AQH_ToolClient_SetHandleResponseMessageFn(o, _handleResponseMessage);
|
||||||
dbLocalArgs);
|
rv=AQH_ToolClient_ReadLocalArgs(o, argc, argv);
|
||||||
if (rv==GWEN_ARGS_RESULT_ERROR) {
|
if (rv!=0)
|
||||||
fprintf(stderr, "ERROR: Could not parse arguments\n");
|
return rv;
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else if (rv==GWEN_ARGS_RESULT_HELP) {
|
|
||||||
GWEN_BUFFER *ubuf;
|
|
||||||
|
|
||||||
ubuf=GWEN_Buffer_new(0, 1024, 0, 1);
|
rv=AQH_ToolClient_Connect(o, AQH_TOOL_CLIENT_CONNECTFLAGS_WITHCONNECTMSG | AQH_TOOL_CLIENT_CONNECTFLAGS_WITHGRPMSG,
|
||||||
if (GWEN_Args_Usage(args, ubuf, GWEN_ArgsOutType_Txt)) {
|
0, AQH_MSG_TYPEGROUP_ALL);
|
||||||
fprintf(stderr, "ERROR: Could not create help string\n");
|
if (rv<0) {
|
||||||
return 1;
|
DBG_INFO(NULL, "here(%d)", rv);
|
||||||
}
|
AQH_Object_free(o);
|
||||||
fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(ubuf));
|
AQH_EventLoop_free(eventLoop);
|
||||||
GWEN_Buffer_free(ubuf);
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
rv=AQH_ToolClient_RunConnectedWithNodeMsgs(o);
|
||||||
|
AQH_Object_free(o);
|
||||||
|
AQH_EventLoop_free(eventLoop);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
AQH_MESSAGE *_createRequestMessage(GWEN_UNUSED AQH_OBJECT *o, GWEN_UNUSED uint32_t msgId)
|
||||||
|
{
|
||||||
|
AQH_MESSAGE *nodeMsg;
|
||||||
|
GWEN_DB_NODE *dbArgs;
|
||||||
|
int nodeAddr;
|
||||||
|
|
||||||
|
dbArgs=AQH_ToolClient_GetDbLocalArgs(o);
|
||||||
|
nodeAddr=GWEN_DB_GetIntValue(dbArgs, "nodeAddr", 0, 0);
|
||||||
|
|
||||||
|
nodeMsg=AQH_PingMessage_new(nodeAddr, AQH_TOOL_CLIENT_NODEADDR, AQH_MSG_TYPE_PING, 0);
|
||||||
|
return nodeMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int _handleResponseMessage(AQH_OBJECT *o, const AQH_MESSAGE *msg, GWEN_UNUSED const GWEN_TAG16_LIST *tagList, GWEN_UNUSED int first)
|
||||||
|
{
|
||||||
|
GWEN_DB_NODE *dbArgs;
|
||||||
|
uint16_t code;
|
||||||
|
int nodeAddr;
|
||||||
|
|
||||||
|
dbArgs=AQH_ToolClient_GetDbLocalArgs(o);
|
||||||
|
nodeAddr=GWEN_DB_GetIntValue(dbArgs, "nodeAddr", 0, 0);
|
||||||
|
|
||||||
|
code=AQH_NodeMessage_GetMsgType(msg);
|
||||||
|
if ((code==AQH_MSG_TYPE_PONG) &&
|
||||||
|
(nodeAddr==0 || nodeAddr==0xff || nodeAddr==AQH_NodeMessage_GetSourceAddress(msg))) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
DBG_INFO(NULL, "Unexpected message \"%d\"", code);
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
return _doPing(dbLocalArgs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int _doPing(GWEN_DB_NODE *dbArgs)
|
|
||||||
{
|
|
||||||
GWEN_MSG_ENDPOINT *epTcp;
|
|
||||||
int rv;
|
|
||||||
int nodeAddr;
|
|
||||||
int timeoutInSeconds;
|
|
||||||
GWEN_MSG *msg;
|
|
||||||
|
|
||||||
epTcp=Utils_SetupNodesClientEndpoint(dbArgs);
|
|
||||||
if (epTcp==NULL) {
|
|
||||||
DBG_ERROR(NULL, "ERROR creating TCP connection");
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
nodeAddr=GWEN_DB_GetIntValue(dbArgs, "nodeAddr", 0, 0);
|
|
||||||
timeoutInSeconds=GWEN_DB_GetIntValue(dbArgs, "timeout", 0, 5);
|
|
||||||
|
|
||||||
rv=Utils_SendAcceptedMsgGroups(epTcp, AQH_MSG_TYPEGROUP_ALL);
|
|
||||||
if (rv<0) {
|
|
||||||
DBG_INFO(NULL, "here (%d)", rv);
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(stdout, "Sending PING request\n");
|
|
||||||
|
|
||||||
rv=_sendPing(epTcp, nodeAddr);
|
|
||||||
if (rv<0) {
|
|
||||||
DBG_INFO(NULL, "here (%d)", rv);
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
msg=Utils_WaitForSpecificNodeMessage(epTcp, AQH_MSG_TYPE_PONG, nodeAddr, timeoutInSeconds);
|
|
||||||
if (msg==NULL) {
|
|
||||||
DBG_INFO(NULL, "No PONG response received.");
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(stdout, "PONG response received\n");
|
|
||||||
GWEN_MsgEndpoint_free(epTcp);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int _sendPing(GWEN_MSG_ENDPOINT *epTcp, int nodeAddr)
|
|
||||||
{
|
|
||||||
GWEN_MSG *msgOut;
|
|
||||||
|
|
||||||
msgOut=AQH_PingIpcMsg_new(AQH_MSGTYPE_IPC_NODES_PING, GWEN_MsgEndpoint_GetNextMessageId(epTcp), 0, nodeAddr);
|
|
||||||
if (msgOut==NULL) {
|
|
||||||
DBG_ERROR(NULL, "Error creating message");
|
|
||||||
return GWEN_ERROR_GENERIC;
|
|
||||||
}
|
|
||||||
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,297 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
* This file is part of the project AqHome.
|
|
||||||
* AqHome (c) by 2024 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 "./setnodevalue.h"
|
|
||||||
#include "../utils.h"
|
|
||||||
|
|
||||||
#include "aqhome/ipc/nodes/msg_ipc_setaccmsggrps.h"
|
|
||||||
#include "aqhome/ipc/nodes/msg_ipc_ping.h"
|
|
||||||
#include "aqhome/ipc/nodes/msg_ipc_forward.h"
|
|
||||||
#include "aqhome/ipc/endpoint_ipc.h"
|
|
||||||
#include "aqhome/msg/msg_node.h"
|
|
||||||
#include "aqhome/msg/msg_value3.h"
|
|
||||||
|
|
||||||
#include <gwenhywfar/args.h>
|
|
||||||
#include <gwenhywfar/i18n.h>
|
|
||||||
#include <gwenhywfar/debug.h>
|
|
||||||
#include <gwenhywfar/text.h>
|
|
||||||
|
|
||||||
#include <time.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
|
|
||||||
#define I18S(msg) msg
|
|
||||||
#define I18N(msg) GWEN_I18N_Translate(PACKAGE, msg)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int _doSetValue(GWEN_DB_NODE *dbArgs);
|
|
||||||
static GWEN_MSG *_waitForSetValueResponse(GWEN_MSG_ENDPOINT *epTcp, int nodeAddr, int msgId, int timeoutInSeconds);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int AQH_Tool_SetNodeValue(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
|
||||||
{
|
|
||||||
GWEN_DB_NODE *dbLocalArgs;
|
|
||||||
int rv;
|
|
||||||
const GWEN_ARGS args[]= {
|
|
||||||
{
|
|
||||||
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
|
||||||
GWEN_ArgsType_Char, /* type */
|
|
||||||
"tcpAddress", /* name */
|
|
||||||
0, /* minnum */
|
|
||||||
1, /* maxnum */
|
|
||||||
"t", /* short option */
|
|
||||||
"tcpaddress", /* long option */
|
|
||||||
I18S("Specify TCP address to connect to (defaults to 127.0.0.1)"),
|
|
||||||
I18S("Specify TCP address to connect to (defaults to 127.0.0.1)")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
|
||||||
GWEN_ArgsType_Int, /* type */
|
|
||||||
"tcpPort", /* name */
|
|
||||||
0, /* minnum */
|
|
||||||
1, /* maxnum */
|
|
||||||
"P", /* short option */
|
|
||||||
"tcpport", /* long option */
|
|
||||||
I18S("Specify the TCP port to listen on"),
|
|
||||||
I18S("Specify the TCP port to listen on")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
|
||||||
GWEN_ArgsType_Int, /* type */
|
|
||||||
"nodeAddr", /* name */
|
|
||||||
1, /* minnum */
|
|
||||||
1, /* maxnum */
|
|
||||||
"n", /* short option */
|
|
||||||
"nodeaddr", /* long option */
|
|
||||||
I18S("Specify bus addr of the node to send to"),
|
|
||||||
I18S("Specify bus addr of the node to send to")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
|
||||||
GWEN_ArgsType_Int, /* type */
|
|
||||||
"timeout", /* name */
|
|
||||||
0, /* minnum */
|
|
||||||
1, /* maxnum */
|
|
||||||
"T", /* short option */
|
|
||||||
NULL, /* long option */
|
|
||||||
I18S("Specify timeout in seconds for response"),
|
|
||||||
I18S("Specify timeout in seconds for response")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
|
||||||
GWEN_ArgsType_Int, /* type */
|
|
||||||
"valueId", /* name */
|
|
||||||
1, /* minnum */
|
|
||||||
1, /* maxnum */
|
|
||||||
"V", /* short option */
|
|
||||||
"valueId", /* long option */
|
|
||||||
I18S("Specify id of value to change"),
|
|
||||||
I18S("Specify id of value to change")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
|
||||||
GWEN_ArgsType_Int, /* type */
|
|
||||||
"value", /* name */
|
|
||||||
1, /* minnum */
|
|
||||||
1, /* maxnum */
|
|
||||||
"v", /* short option */
|
|
||||||
"value", /* long option */
|
|
||||||
I18S("Specify value to send"),
|
|
||||||
I18S("Specify value to send")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
|
||||||
GWEN_ArgsType_Int, /* type */
|
|
||||||
"denom", /* name */
|
|
||||||
0, /* minnum */
|
|
||||||
1, /* maxnum */
|
|
||||||
"d", /* short option */
|
|
||||||
"denom", /* long option */
|
|
||||||
I18S("Specify denominator to send"),
|
|
||||||
I18S("Specify denominator to send")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
|
||||||
GWEN_ArgsType_Int, /* type */
|
|
||||||
"msgId", /* name */
|
|
||||||
0, /* minnum */
|
|
||||||
1, /* maxnum */
|
|
||||||
"m", /* short option */
|
|
||||||
"msgId", /* long option */
|
|
||||||
I18S("Specify a msg id"),
|
|
||||||
I18S("Specify a msg id")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
GWEN_ARGS_FLAGS_HELP | GWEN_ARGS_FLAGS_LAST, /* flags */
|
|
||||||
GWEN_ArgsType_Int, /* type */
|
|
||||||
"help", /* name */
|
|
||||||
0, /* minnum */
|
|
||||||
0, /* maxnum */
|
|
||||||
"h", /* short option */
|
|
||||||
"help", /* long option */
|
|
||||||
"Show this help screen", /* short description */
|
|
||||||
"Show this help screen" /* long description */
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
dbLocalArgs=GWEN_DB_GetGroup(dbGlobalArgs, GWEN_DB_FLAGS_DEFAULT, "local");
|
|
||||||
rv=GWEN_Args_Check(argc, argv, 1,
|
|
||||||
GWEN_ARGS_MODE_ALLOW_FREEPARAM,
|
|
||||||
args,
|
|
||||||
dbLocalArgs);
|
|
||||||
if (rv==GWEN_ARGS_RESULT_ERROR) {
|
|
||||||
fprintf(stderr, "ERROR: Could not parse arguments\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else if (rv==GWEN_ARGS_RESULT_HELP) {
|
|
||||||
GWEN_BUFFER *ubuf;
|
|
||||||
|
|
||||||
ubuf=GWEN_Buffer_new(0, 1024, 0, 1);
|
|
||||||
if (GWEN_Args_Usage(args, ubuf, GWEN_ArgsOutType_Txt)) {
|
|
||||||
fprintf(stderr, "ERROR: Could not create help string\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(ubuf));
|
|
||||||
GWEN_Buffer_free(ubuf);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return _doSetValue(dbLocalArgs);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int _doSetValue(GWEN_DB_NODE *dbArgs)
|
|
||||||
{
|
|
||||||
GWEN_MSG_ENDPOINT *epTcp;
|
|
||||||
int rv;
|
|
||||||
int nodeAddr;
|
|
||||||
int timeoutInSeconds;
|
|
||||||
int valueId;
|
|
||||||
int value;
|
|
||||||
int denom;
|
|
||||||
int msgId;
|
|
||||||
GWEN_MSG *msgNode;
|
|
||||||
GWEN_MSG *msgOut;
|
|
||||||
GWEN_MSG *msg;
|
|
||||||
|
|
||||||
epTcp=Utils_SetupNodesClientEndpoint(dbArgs);
|
|
||||||
if (epTcp==NULL) {
|
|
||||||
DBG_ERROR(NULL, "ERROR creating TCP connection");
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
nodeAddr=GWEN_DB_GetIntValue(dbArgs, "nodeAddr", 0, 0);
|
|
||||||
timeoutInSeconds=GWEN_DB_GetIntValue(dbArgs, "timeout", 0, 5);
|
|
||||||
|
|
||||||
valueId=GWEN_DB_GetIntValue(dbArgs, "valueId", 0, 0);
|
|
||||||
msgId=GWEN_DB_GetIntValue(dbArgs, "msgId", 0, 0);
|
|
||||||
value=GWEN_DB_GetIntValue(dbArgs, "value", 0, 0);
|
|
||||||
denom=GWEN_DB_GetIntValue(dbArgs, "denom", 0, 1);
|
|
||||||
|
|
||||||
rv=Utils_SendAcceptedMsgGroups(epTcp, AQH_MSG_TYPEGROUP_ALL);
|
|
||||||
if (rv<0) {
|
|
||||||
DBG_INFO(NULL, "here (%d)", rv);
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(stdout, "Sending SETVALUE request\n");
|
|
||||||
msgNode=AQH_Value3Msg_new(0xc1, nodeAddr, AQH_MSG_TYPE_VALUE_SET, msgId, valueId, value, denom);
|
|
||||||
if (msgNode==NULL) {
|
|
||||||
DBG_ERROR(NULL, "Error creating message");
|
|
||||||
return GWEN_ERROR_GENERIC;
|
|
||||||
}
|
|
||||||
msgOut=AQH_ForwardIpcMsg_new(AQH_MSGTYPE_IPC_NODES_FORWARD,
|
|
||||||
GWEN_MsgEndpoint_GetNextMessageId(epTcp), 0,
|
|
||||||
GWEN_Msg_GetConstBuffer(msgNode), GWEN_Msg_GetBytesInBuffer(msgNode));
|
|
||||||
if (msgOut==NULL) {
|
|
||||||
DBG_ERROR(NULL, "Error creating message");
|
|
||||||
return GWEN_ERROR_GENERIC;
|
|
||||||
}
|
|
||||||
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
|
|
||||||
|
|
||||||
msg=_waitForSetValueResponse(epTcp, nodeAddr, msgId, timeoutInSeconds);
|
|
||||||
if (msg==NULL) {
|
|
||||||
DBG_INFO(NULL, "No SETVALUE response received.");
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_VALUE_SET_ACK) {
|
|
||||||
fprintf(stdout, "Value set\n");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fprintf(stdout, "Value not set\n");
|
|
||||||
}
|
|
||||||
GWEN_Msg_free(msg);
|
|
||||||
GWEN_MsgEndpoint_free(epTcp);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GWEN_MSG *_waitForSetValueResponse(GWEN_MSG_ENDPOINT *epTcp, int nodeAddr, int msgId, int timeoutInSeconds)
|
|
||||||
{
|
|
||||||
time_t startTime;
|
|
||||||
|
|
||||||
startTime=time(NULL);
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
GWEN_MSG *msg;
|
|
||||||
time_t now;
|
|
||||||
|
|
||||||
while( (msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epTcp)) ) {
|
|
||||||
if (GWEN_IpcMsg_GetCode(msg)==AQH_MSGTYPE_IPC_NODES_FORWARD) {
|
|
||||||
GWEN_MSG *nodeMsg;
|
|
||||||
|
|
||||||
DBG_INFO(NULL, "Received IPC FORWARD message");
|
|
||||||
nodeMsg=AQH_ForwardIpcMsg_GetCopyOfNodeMsg(msg);
|
|
||||||
if (nodeMsg) {
|
|
||||||
int recvNodeAddr;
|
|
||||||
int recvMsgType;
|
|
||||||
|
|
||||||
recvNodeAddr=AQH_NodeMsg_GetSourceAddress(nodeMsg);
|
|
||||||
recvMsgType=AQH_NodeMsg_GetMsgType(nodeMsg);
|
|
||||||
DBG_INFO(AQH_LOGDOMAIN, "Received node msg from %d (%d)", recvNodeAddr, recvNodeAddr);
|
|
||||||
if ((nodeAddr==0 || recvNodeAddr==nodeAddr) &&
|
|
||||||
(recvMsgType==AQH_MSG_TYPE_VALUE_SET_ACK || recvMsgType==AQH_MSG_TYPE_VALUE_SET_NACK)) {
|
|
||||||
int recvMsgId;
|
|
||||||
|
|
||||||
recvMsgId=AQH_Value3Msg_GetMsgId(nodeMsg);
|
|
||||||
if (recvMsgId==msgId) {
|
|
||||||
GWEN_Msg_free(msg);
|
|
||||||
return nodeMsg;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
DBG_INFO(NULL, "Received IPC message %d, ignoring", GWEN_IpcMsg_GetCode(msg));
|
|
||||||
}
|
|
||||||
GWEN_Msg_free(msg);
|
|
||||||
} /* while */
|
|
||||||
now=time(NULL);
|
|
||||||
if (now-startTime>timeoutInSeconds) {
|
|
||||||
DBG_INFO(NULL, "Timeout");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
GWEN_MsgEndpoint_IoLoop(epTcp, 2000); /* 2000 ms */
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -13,22 +13,14 @@
|
|||||||
|
|
||||||
#include "./utils.h"
|
#include "./utils.h"
|
||||||
|
|
||||||
#include "aqhome/ipc/endpoint_ipc.h"
|
|
||||||
#include "aqhome/ipc/nodes/msg_ipc_setaccmsggrps.h"
|
|
||||||
#include "aqhome/ipc/nodes/msg_ipc_forward.h"
|
|
||||||
#include "aqhome/ipc/data/ipc_data.h"
|
|
||||||
#include "aqhome/ipc/data/msg_data_connect.h"
|
|
||||||
#include "aqhome/ipc/msg_ipc_result.h"
|
|
||||||
#include "aqhome/ipc/endpoint_ipcclient.h"
|
|
||||||
|
|
||||||
#include "aqhome/msg/ipc/m_ipc.h"
|
#include "aqhome/msg/ipc/m_ipc.h"
|
||||||
#include "aqhome/msg/ipc/data/m_ipcd.h"
|
#include "aqhome/msg/ipc/data/m_ipcd.h"
|
||||||
|
#include "aqhome/msg/ipc/nodes/m_ipcn.h"
|
||||||
|
#include "aqhome/msg/ipc/nodes/m_ipcn_setaccmsggrps.h"
|
||||||
#include "aqhome/ipc2/tcp_object.h"
|
#include "aqhome/ipc2/tcp_object.h"
|
||||||
#include "aqhome/ipc2/ipc_client.h"
|
#include "aqhome/ipc2/ipc_client.h"
|
||||||
|
|
||||||
|
|
||||||
#include <gwenhywfar/endpoint_tcpc.h>
|
|
||||||
#include <gwenhywfar/endpoint_multilayer.h>
|
|
||||||
#include <gwenhywfar/debug.h>
|
#include <gwenhywfar/debug.h>
|
||||||
#include <gwenhywfar/timestamp.h>
|
#include <gwenhywfar/timestamp.h>
|
||||||
#include <gwenhywfar/db.h>
|
#include <gwenhywfar/db.h>
|
||||||
@@ -78,315 +70,23 @@ AQH_OBJECT *Utils2_SetupBrokerClientEndpoint(AQH_EVENT_LOOP *eventLoop, GWEN_DB_
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
GWEN_MSG_ENDPOINT *Utils_SetupBrokerClientEndpoint(GWEN_DB_NODE *dbArgs, uint32_t flags)
|
int Utils_SendAcceptedMsgGroups(AQH_OBJECT *ep, uint32_t groups)
|
||||||
{
|
{
|
||||||
const char *brokerAddress;
|
AQH_MESSAGE *msgOut;
|
||||||
int brokerPort;
|
|
||||||
const char *brokerClientId;
|
|
||||||
|
|
||||||
brokerAddress=GWEN_DB_GetCharValue(dbArgs, "brokerAddress", 0, NULL);
|
msgOut=AQH_IpcnMessageSetAcceptedMsgGroups_new(AQH_MSGTYPE_IPC_NODES_SETACCMSGGRPS,
|
||||||
if (!(brokerAddress && *brokerAddress))
|
AQH_Endpoint_GetNextMessageId(ep),0,
|
||||||
brokerAddress=GWEN_DB_GetCharValue(dbArgs, "ConfigFile/brokerAddress", 0, "127.0.0.1");
|
groups);
|
||||||
|
|
||||||
brokerPort=GWEN_DB_GetIntValue(dbArgs, "brokerPort", 0, -1);
|
|
||||||
if (brokerPort<0)
|
|
||||||
brokerPort=GWEN_DB_GetIntValue(dbArgs, "ConfigFile/brokerPort", 0, 45456);
|
|
||||||
|
|
||||||
brokerClientId=GWEN_DB_GetCharValue(dbArgs, "brokerClientId", 0, "aqhome-tool");
|
|
||||||
|
|
||||||
if (brokerAddress && *brokerAddress && brokerPort) {
|
|
||||||
GWEN_MSG_ENDPOINT *ep;
|
|
||||||
GWEN_MSG_ENDPOINT *ipcBaseEndpoint;
|
|
||||||
int rv;
|
|
||||||
|
|
||||||
ep=AQH_ClientIpcEndpoint_new("brokerIpcClient", 0);
|
|
||||||
GWEN_MsgEndpoint_AddFlags(ep, flags);
|
|
||||||
|
|
||||||
ipcBaseEndpoint=AQH_IpcEndpoint_CreateIpcTcpClient(brokerAddress, brokerPort, "brokerPhysEndpoint", 0);
|
|
||||||
AQH_IpcEndpoint_SetServiceName(ipcBaseEndpoint, brokerClientId);
|
|
||||||
GWEN_MsgEndpoint_Tree2_AddChild(ep, ipcBaseEndpoint);
|
|
||||||
|
|
||||||
rv=GWEN_MultilayerEndpoint_StartConnect(ep);
|
|
||||||
if (rv<0 && rv!=GWEN_ERROR_IN_PROGRESS) {
|
|
||||||
DBG_ERROR(NULL, "Error connecting to broker server %s:%d (%d), will retry later", brokerAddress, brokerPort, rv);
|
|
||||||
GWEN_MsgEndpoint_free(ep);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ep;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GWEN_MSG_ENDPOINT *Utils_SetupNodesClientEndpoint(GWEN_DB_NODE *dbArgs)
|
|
||||||
{
|
|
||||||
return Utils_SetupIpcEndpoint(dbArgs, "tcpAddress", "tcpPort", "ConfigFile/nodesAddress", "ConfigFile/nodesPort", 45454);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GWEN_MSG_ENDPOINT *Utils_SetupIpcEndpoint(GWEN_DB_NODE *dbArgs,
|
|
||||||
const char *varNameAddr,
|
|
||||||
const char *varNamePort,
|
|
||||||
const char *fileVarNameAddr,
|
|
||||||
const char *fileVarNamePort,
|
|
||||||
int defaultPort)
|
|
||||||
{
|
|
||||||
GWEN_MSG_ENDPOINT *epTcp;
|
|
||||||
const char *tcpAddress;
|
|
||||||
int tcpPort;
|
|
||||||
int rv;
|
|
||||||
|
|
||||||
tcpAddress=GWEN_DB_GetCharValue(dbArgs, varNameAddr, 0, NULL);
|
|
||||||
if (!(tcpAddress && *tcpAddress))
|
|
||||||
tcpAddress=GWEN_DB_GetCharValue(dbArgs, fileVarNameAddr, 0, "127.0.0.1");
|
|
||||||
|
|
||||||
tcpPort=GWEN_DB_GetIntValue(dbArgs, varNamePort, 0, -1);
|
|
||||||
if (tcpPort<0)
|
|
||||||
tcpPort=GWEN_DB_GetIntValue(dbArgs, fileVarNamePort, 0, defaultPort);
|
|
||||||
|
|
||||||
DBG_INFO(NULL, "Setup tcp client endpoint to %s:%d", tcpAddress, tcpPort);
|
|
||||||
epTcp=AQH_IpcEndpoint_CreateIpcTcpClient(tcpAddress, tcpPort, "aqhome-tool-IPC", 0);
|
|
||||||
if (epTcp==NULL) {
|
|
||||||
DBG_ERROR(NULL, "Error creating endpoint TCPc");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
GWEN_MsgEndpoint_SetDefaultMessageSize(epTcp, UTILS_IPC_ENDPOINT_DEFAULT_MSGSIZE);
|
|
||||||
rv=GWEN_TcpcEndpoint_StartConnect(epTcp);
|
|
||||||
if (rv<0 && rv!=GWEN_ERROR_IN_PROGRESS) {
|
|
||||||
DBG_ERROR(NULL, "Error connecting (%d)", rv);
|
|
||||||
GWEN_MsgEndpoint_free(epTcp);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return epTcp;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT *epTcp,
|
|
||||||
int msgCode,
|
|
||||||
int nodeAddr,
|
|
||||||
int timeoutInSeconds)
|
|
||||||
{
|
|
||||||
time_t startTime;
|
|
||||||
|
|
||||||
startTime=time(NULL);
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
GWEN_MSG *msg;
|
|
||||||
time_t now;
|
|
||||||
|
|
||||||
while( (msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epTcp)) ) {
|
|
||||||
if (GWEN_IpcMsg_GetCode(msg)==AQH_MSGTYPE_IPC_NODES_FORWARD) {
|
|
||||||
GWEN_MSG *nodeMsg;
|
|
||||||
|
|
||||||
DBG_INFO(NULL, "Received IPC FORWARD message");
|
|
||||||
nodeMsg=AQH_ForwardIpcMsg_GetCopyOfNodeMsg(msg);
|
|
||||||
if (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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
DBG_INFO(NULL, "Received IPC message %d, ignoring", GWEN_IpcMsg_GetCode(msg));
|
|
||||||
}
|
|
||||||
GWEN_Msg_free(msg);
|
|
||||||
} /* while */
|
|
||||||
now=time(NULL);
|
|
||||||
if (now-startTime>timeoutInSeconds) {
|
|
||||||
DBG_INFO(NULL, "Timeout");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
GWEN_MsgEndpoint_IoLoop(epTcp, 2000); /* 2000 ms */
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GWEN_MSG *Utils_WaitForSpecificIpcMessage(GWEN_MSG_ENDPOINT *epTcp,
|
|
||||||
int msgCode,
|
|
||||||
int timeoutInSeconds)
|
|
||||||
{
|
|
||||||
time_t startTime;
|
|
||||||
|
|
||||||
startTime=time(NULL);
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
GWEN_MSG *msg;
|
|
||||||
time_t now;
|
|
||||||
|
|
||||||
GWEN_MsgEndpoint_IoLoop(epTcp, 2000); /* 2000 ms */
|
|
||||||
msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epTcp);
|
|
||||||
if (msg) {
|
|
||||||
uint16_t code;
|
|
||||||
|
|
||||||
code=GWEN_IpcMsg_GetCode(msg);
|
|
||||||
if (code==msgCode) {
|
|
||||||
DBG_INFO(NULL, "Received expected IPC message");
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
else if (code==AQH_MSGTYPE_IPC_DATA_RESULT) {
|
|
||||||
DBG_INFO(NULL, "Received IPC result message");
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
DBG_INFO(NULL, "Received unexpected message %d (%x)", code, code);
|
|
||||||
}
|
|
||||||
GWEN_Msg_free(msg);
|
|
||||||
}
|
|
||||||
now=time(NULL);
|
|
||||||
if (now-startTime>timeoutInSeconds) {
|
|
||||||
DBG_INFO(NULL, "Timeout");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GWEN_MSG *Utils_WaitForResponse(GWEN_MSG_ENDPOINT *epTcp, uint32_t msgId, int timeoutInSeconds)
|
|
||||||
{
|
|
||||||
time_t startTime;
|
|
||||||
|
|
||||||
startTime=time(NULL);
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
GWEN_MSG *msg;
|
|
||||||
time_t now;
|
|
||||||
|
|
||||||
GWEN_MsgEndpoint_IoLoop(epTcp, 2000); /* 2000 ms */
|
|
||||||
msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epTcp);
|
|
||||||
if (msg) {
|
|
||||||
if (GWEN_IpcMsg_GetRefMsgId(msg)==msgId) {
|
|
||||||
DBG_INFO(NULL, "Received expected IPC message");
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
uint16_t code;
|
|
||||||
|
|
||||||
code=GWEN_IpcMsg_GetCode(msg);
|
|
||||||
DBG_ERROR(NULL,
|
|
||||||
"Received unexpected message %d (%x) [msgId=%d, refMsgId=%d]",
|
|
||||||
code, code, GWEN_IpcMsg_GetMsgId(msg), GWEN_IpcMsg_GetRefMsgId(msg));
|
|
||||||
}
|
|
||||||
GWEN_Msg_free(msg);
|
|
||||||
}
|
|
||||||
now=time(NULL);
|
|
||||||
if (now-startTime>timeoutInSeconds) {
|
|
||||||
DBG_ERROR(NULL, "Timeout");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int Utils_FlushOutMessageQueue(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds)
|
|
||||||
{
|
|
||||||
time_t startTime;
|
|
||||||
|
|
||||||
startTime=time(NULL);
|
|
||||||
|
|
||||||
while(GWEN_MsgEndpoint_HaveMessageToSend(epTcp)) {
|
|
||||||
time_t now;
|
|
||||||
|
|
||||||
GWEN_MsgEndpoint_IoLoop(epTcp, 2000); /* 2000 ms */
|
|
||||||
now=time(NULL);
|
|
||||||
if (now-startTime>timeoutInSeconds) {
|
|
||||||
DBG_INFO(NULL, "Timeout");
|
|
||||||
return GWEN_ERROR_TIMEOUT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int Utils_SendAcceptedMsgGroups(GWEN_MSG_ENDPOINT *epTcp, uint32_t groups)
|
|
||||||
{
|
|
||||||
GWEN_MSG *msgOut;
|
|
||||||
|
|
||||||
msgOut=AQH_SetAcceptedMsgGroupsIpcMsg_new(AQH_MSGTYPE_IPC_NODES_SETACCMSGGRPS,
|
|
||||||
GWEN_MsgEndpoint_GetNextMessageId(epTcp),0,
|
|
||||||
groups);
|
|
||||||
if (msgOut==NULL) {
|
if (msgOut==NULL) {
|
||||||
DBG_ERROR(NULL, "Error creating message");
|
DBG_ERROR(NULL, "Error creating message");
|
||||||
return GWEN_ERROR_GENERIC;
|
return GWEN_ERROR_GENERIC;
|
||||||
}
|
}
|
||||||
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
|
AQH_Endpoint_AddMsgOut(ep, msgOut);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GWEN_MSG_ENDPOINT *Utils_OpenBrokerConnection(GWEN_DB_NODE *dbArgs, uint32_t flags, int timeoutInSeconds)
|
|
||||||
{
|
|
||||||
GWEN_MSG_ENDPOINT *epTcp;
|
|
||||||
GWEN_MSG *msgOut;
|
|
||||||
GWEN_MSG *msgIn;
|
|
||||||
uint32_t result;
|
|
||||||
const char *clientId;
|
|
||||||
const char *userId;
|
|
||||||
const char *password;
|
|
||||||
|
|
||||||
clientId=GWEN_DB_GetCharValue(dbArgs, "clientId", 0, NULL);
|
|
||||||
userId=GWEN_DB_GetCharValue(dbArgs, "userId", 0, NULL);
|
|
||||||
password=GWEN_DB_GetCharValue(dbArgs, "password", 0, NULL);
|
|
||||||
|
|
||||||
epTcp=Utils_SetupBrokerClientEndpoint(dbArgs, 0);
|
|
||||||
if (epTcp==NULL) {
|
|
||||||
DBG_ERROR(NULL, "ERROR creating TCP connection");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
msgOut=AQH_ConnectDataIpcMsg_new(AQH_MSGTYPE_IPC_DATA_CONNECT_REQ,
|
|
||||||
GWEN_MsgEndpoint_GetNextMessageId(epTcp), 0,
|
|
||||||
clientId, userId, password, flags);
|
|
||||||
if (msgOut==NULL) {
|
|
||||||
DBG_ERROR(NULL, "Error creating message");
|
|
||||||
GWEN_MsgEndpoint_free(epTcp);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
|
|
||||||
|
|
||||||
msgIn=Utils_WaitForSpecificIpcMessage(epTcp, AQH_MSGTYPE_IPC_DATA_RESULT, timeoutInSeconds);
|
|
||||||
if (msgIn==NULL) {
|
|
||||||
DBG_ERROR(NULL, "No response received");
|
|
||||||
GWEN_MsgEndpoint_free(epTcp);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
result=AQH_ResultIpcMsg_GetResultCode(msgIn);
|
|
||||||
GWEN_Msg_free(msgIn);
|
|
||||||
|
|
||||||
if (result!=AQH_MSG_IPC_SUCCESS) {
|
|
||||||
DBG_ERROR(NULL, "Response: %d", result);
|
|
||||||
GWEN_MsgEndpoint_free(epTcp);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return epTcp;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Utils_PrintDataPoints(const uint64_t *dataPoints, uint32_t numValues, const char *valueUnits)
|
void Utils_PrintDataPoints(const uint64_t *dataPoints, uint32_t numValues, const char *valueUnits)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|||||||
@@ -24,30 +24,9 @@
|
|||||||
|
|
||||||
AQH_OBJECT *Utils2_SetupBrokerClientEndpoint(AQH_EVENT_LOOP *eventLoop, GWEN_DB_NODE *dbArgs, uint32_t flags);
|
AQH_OBJECT *Utils2_SetupBrokerClientEndpoint(AQH_EVENT_LOOP *eventLoop, GWEN_DB_NODE *dbArgs, uint32_t flags);
|
||||||
AQH_MESSAGE *Utils2_WaitForResponseMsg(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *epTcp, uint32_t refMsgId, int timeoutInSeconds);
|
AQH_MESSAGE *Utils2_WaitForResponseMsg(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *epTcp, uint32_t refMsgId, int timeoutInSeconds);
|
||||||
|
int Utils_SendAcceptedMsgGroups(AQH_OBJECT *ep, uint32_t groups);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GWEN_MSG_ENDPOINT *Utils_SetupIpcEndpoint(GWEN_DB_NODE *dbArgs,
|
|
||||||
const char *varNameAddr,
|
|
||||||
const char *varNamePort,
|
|
||||||
const char *fileVarNameAddr,
|
|
||||||
const char *fileVarNamePort,
|
|
||||||
int defaultPort);
|
|
||||||
GWEN_MSG_ENDPOINT *Utils_SetupBrokerClientEndpoint(GWEN_DB_NODE *dbArgs, uint32_t flags);
|
|
||||||
GWEN_MSG_ENDPOINT *Utils_SetupNodesClientEndpoint(GWEN_DB_NODE *dbArgs);
|
|
||||||
|
|
||||||
GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT *epTcp, int msgCode, int nodeAddr, int timeoutInSeconds);
|
|
||||||
|
|
||||||
GWEN_MSG *Utils_WaitForSpecificIpcMessage(GWEN_MSG_ENDPOINT *epTcp, int msgCode, int timeoutInSeconds);
|
|
||||||
|
|
||||||
GWEN_MSG *Utils_WaitForResponse(GWEN_MSG_ENDPOINT *epTcp, uint32_t msgId, int timeoutInSeconds);
|
|
||||||
|
|
||||||
int Utils_FlushOutMessageQueue(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds);
|
|
||||||
|
|
||||||
int Utils_SendAcceptedMsgGroups(GWEN_MSG_ENDPOINT *epTcp, uint32_t groups);
|
|
||||||
|
|
||||||
GWEN_MSG_ENDPOINT *Utils_OpenBrokerConnection(GWEN_DB_NODE *dbArgs, uint32_t flags, int timeoutInSeconds);
|
|
||||||
|
|
||||||
void Utils_PrintDataPoints(const uint64_t *dataPoints, uint32_t numValues, const char *valueUnits);
|
void Utils_PrintDataPoints(const uint64_t *dataPoints, uint32_t numValues, const char *valueUnits);
|
||||||
void Utils_PrintSingleDataPoint(uint64_t timestamp, double data, const char *valueUnits);
|
void Utils_PrintSingleDataPoint(uint64_t timestamp, double data, const char *valueUnits);
|
||||||
void Utils_PrintMeanData(const uint64_t *dataPoints, uint32_t numValues, const char *valueUnits);
|
void Utils_PrintMeanData(const uint64_t *dataPoints, uint32_t numValues, const char *valueUnits);
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ const char *_readGroupOrVar(AQH_VARS **pVars, const char *src, GWEN_BUFFER *wbuf
|
|||||||
/* read untyped var, assume string */
|
/* read untyped var, assume string */
|
||||||
s=_contAsVar(pVars, AQH_Vars_DataType_ValueString, s, GWEN_Buffer_GetStart(wbuf), wbuf);
|
s=_contAsVar(pVars, AQH_Vars_DataType_ValueString, s, GWEN_Buffer_GetStart(wbuf), wbuf);
|
||||||
if (s==NULL) {
|
if (s==NULL) {
|
||||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
DBG_INFO(AQH_LOGDOMAIN, "here");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -180,7 +180,7 @@ const char *_readGroupOrVar(AQH_VARS **pVars, const char *src, GWEN_BUFFER *wbuf
|
|||||||
else {
|
else {
|
||||||
s=_contAsTypedVar(pVars, s, GWEN_Buffer_GetStart(wbuf), wbuf);
|
s=_contAsTypedVar(pVars, s, GWEN_Buffer_GetStart(wbuf), wbuf);
|
||||||
if (s==NULL) {
|
if (s==NULL) {
|
||||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
DBG_INFO(AQH_LOGDOMAIN, "here");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -333,6 +333,33 @@ void AQH_Endpoint_SetState(AQH_OBJECT *o, int i)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
uint32_t AQH_Endpoint_GetAcceptedMsgGroups(const AQH_OBJECT *o)
|
||||||
|
{
|
||||||
|
if (o) {
|
||||||
|
AQH_ENDPOINT *xo;
|
||||||
|
|
||||||
|
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_ENDPOINT, o);
|
||||||
|
if (xo)
|
||||||
|
return xo->acceptedMsgGroups;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void AQH_Endpoint_SetAcceptedMsgGroups(AQH_OBJECT *o, uint32_t i)
|
||||||
|
{
|
||||||
|
if (o) {
|
||||||
|
AQH_ENDPOINT *xo;
|
||||||
|
|
||||||
|
xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_ENDPOINT, o);
|
||||||
|
if (xo)
|
||||||
|
xo->acceptedMsgGroups=i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AQH_MESSAGE_LIST *AQH_Endpoint_GetMsgOutList(const AQH_OBJECT *o)
|
AQH_MESSAGE_LIST *AQH_Endpoint_GetMsgOutList(const AQH_OBJECT *o)
|
||||||
{
|
{
|
||||||
if (o) {
|
if (o) {
|
||||||
|
|||||||
@@ -56,6 +56,9 @@ AQHOME_API void AQH_Endpoint_SubFlags(AQH_OBJECT *o, uint32_t i);
|
|||||||
AQHOME_API int AQH_Endpoint_GetState(const AQH_OBJECT *o);
|
AQHOME_API int AQH_Endpoint_GetState(const AQH_OBJECT *o);
|
||||||
AQHOME_API void AQH_Endpoint_SetState(AQH_OBJECT *o, int i);
|
AQHOME_API void AQH_Endpoint_SetState(AQH_OBJECT *o, int i);
|
||||||
|
|
||||||
|
AQHOME_API uint32_t AQH_Endpoint_GetAcceptedMsgGroups(const AQH_OBJECT *o);
|
||||||
|
AQHOME_API void AQH_Endpoint_SetAcceptedMsgGroups(AQH_OBJECT *o, uint32_t i);
|
||||||
|
|
||||||
AQHOME_API AQH_MESSAGE_LIST *AQH_Endpoint_GetMsgOutList(const AQH_OBJECT *o);
|
AQHOME_API AQH_MESSAGE_LIST *AQH_Endpoint_GetMsgOutList(const AQH_OBJECT *o);
|
||||||
AQHOME_API AQH_MESSAGE *AQH_Endpoint_GetNextMsgOut(AQH_OBJECT *o);
|
AQHOME_API AQH_MESSAGE *AQH_Endpoint_GetNextMsgOut(AQH_OBJECT *o);
|
||||||
AQHOME_API void AQH_Endpoint_AddMsgOut(AQH_OBJECT *o, AQH_MESSAGE *msg);
|
AQHOME_API void AQH_Endpoint_AddMsgOut(AQH_OBJECT *o, AQH_MESSAGE *msg);
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ struct AQH_ENDPOINT {
|
|||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
char *serviceName;
|
char *serviceName;
|
||||||
char *userName;
|
char *userName;
|
||||||
|
|
||||||
|
uint32_t acceptedMsgGroups;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -14,34 +14,15 @@
|
|||||||
#include "aqhome/msg/ipc/m_ipc.h"
|
#include "aqhome/msg/ipc/m_ipc.h"
|
||||||
#include "aqhome/msg/ipc/m_ipc_result.h"
|
#include "aqhome/msg/ipc/m_ipc_result.h"
|
||||||
#include "aqhome/msg/ipc/m_ipc_tag16.h"
|
#include "aqhome/msg/ipc/m_ipc_tag16.h"
|
||||||
#include "aqhome/msg/ipc/data/m_ipcd_connect.h"
|
#include "aqhome/msg/ipc/m_ipc_connect.h"
|
||||||
|
|
||||||
#include <gwenhywfar/debug.h>
|
#include <gwenhywfar/debug.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int AQH_IpcEndpoint_ExchangeConnectMsg(AQH_OBJECT *ipcEndpoint,
|
int AQH_IpcEndpoint_WaitForResultMsg(AQH_OBJECT *ipcEndpoint,
|
||||||
uint16_t connectMsgCode,
|
uint8_t protoId, uint8_t protoVer, uint16_t resultMsgCode,
|
||||||
uint16_t resultMsgCode,
|
uint32_t refMsgId, int timeoutInSeconds)
|
||||||
const char *clientId,
|
|
||||||
const char *userId,
|
|
||||||
const char *passw,
|
|
||||||
uint32_t flags,
|
|
||||||
int timeoutInSeconds)
|
|
||||||
{
|
|
||||||
AQH_MESSAGE *msgOut;
|
|
||||||
uint32_t msgId;
|
|
||||||
|
|
||||||
msgId=AQH_Endpoint_GetNextMessageId(ipcEndpoint);
|
|
||||||
msgOut=AQH_IpcdMessageConnect_new(connectMsgCode, msgId, 0, clientId, userId, passw, flags);
|
|
||||||
AQH_Endpoint_AddMsgOut(ipcEndpoint, msgOut);
|
|
||||||
|
|
||||||
return AQH_IpcEndpoint_WaitForResultMsg(ipcEndpoint, resultMsgCode, msgId, timeoutInSeconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int AQH_IpcEndpoint_WaitForResultMsg(AQH_OBJECT *ipcEndpoint, uint16_t resultMsgCode, uint32_t refMsgId, int timeoutInSeconds)
|
|
||||||
{
|
{
|
||||||
for (;;) {
|
for (;;) {
|
||||||
AQH_MESSAGE *msgIn;
|
AQH_MESSAGE *msgIn;
|
||||||
@@ -55,7 +36,9 @@ int AQH_IpcEndpoint_WaitForResultMsg(AQH_OBJECT *ipcEndpoint, uint16_t resultMsg
|
|||||||
int code;
|
int code;
|
||||||
|
|
||||||
code=AQH_IpcMessage_GetCode(msgIn);
|
code=AQH_IpcMessage_GetCode(msgIn);
|
||||||
if (code==resultMsgCode) {
|
if (AQH_IpcMessage_GetProtoId(msgIn)==protoId &&
|
||||||
|
AQH_IpcMessage_GetProtoVersion(msgIn)==protoVer &&
|
||||||
|
code==resultMsgCode) {
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
result=AQH_IpcMessageResult_GetResult(tagList);
|
result=AQH_IpcMessageResult_GetResult(tagList);
|
||||||
|
|||||||
@@ -14,18 +14,12 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
AQHOME_API int AQH_IpcEndpoint_ExchangeConnectMsg(AQH_OBJECT *ipcEndpoint,
|
AQHOME_API int AQH_IpcEndpoint_WaitForResultMsg(AQH_OBJECT *ipcEndpoint,
|
||||||
uint16_t connectMsgCode,
|
uint8_t protoId, uint8_t protoVer, uint16_t resultMsgCode,
|
||||||
uint16_t resultMsgCode,
|
uint32_t refMsgId, int timeoutInSeconds);
|
||||||
const char *clientId,
|
|
||||||
const char *userId,
|
|
||||||
const char *passw,
|
|
||||||
uint32_t flags,
|
|
||||||
int timeoutInSeconds);
|
|
||||||
AQHOME_API int AQH_IpcEndpoint_WaitForResultMsg(AQH_OBJECT *ipcEndpoint, uint16_t resultMsgCode, uint32_t refMsgId, int timeoutInSeconds);
|
|
||||||
AQHOME_API AQH_MESSAGE *AQH_IpcEndpoint_WaitForResponseMsg(AQH_OBJECT *ipcEndpoint, uint32_t refMsgId, int timeoutInSeconds);
|
AQHOME_API AQH_MESSAGE *AQH_IpcEndpoint_WaitForResponseMsg(AQH_OBJECT *ipcEndpoint, uint32_t refMsgId, int timeoutInSeconds);
|
||||||
AQHOME_API void AQH_IpcEndpoint_SendResponseResultToEndpoint(AQH_OBJECT *ep,
|
AQHOME_API void AQH_IpcEndpoint_SendResponseResultToEndpoint(AQH_OBJECT *ep,
|
||||||
uint8_t protoId, uint8_t protoVer,uint16_t code,
|
uint8_t protoId, uint8_t protoVer, uint16_t code,
|
||||||
uint32_t refMsgId, int result);
|
uint32_t refMsgId, int result);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,7 @@
|
|||||||
<headers dist="true" install="$(pkgincludedir)/msg" >
|
<headers dist="true" install="$(pkgincludedir)/msg" >
|
||||||
m_ipc.h
|
m_ipc.h
|
||||||
m_ipc_tag16.h
|
m_ipc_tag16.h
|
||||||
|
m_ipc_connect.h
|
||||||
m_ipc_result.h
|
m_ipc_result.h
|
||||||
</headers>
|
</headers>
|
||||||
|
|
||||||
@@ -60,6 +61,7 @@
|
|||||||
|
|
||||||
m_ipc.c
|
m_ipc.c
|
||||||
m_ipc_tag16.c
|
m_ipc_tag16.c
|
||||||
|
m_ipc_connect.c
|
||||||
m_ipc_result.c
|
m_ipc_result.c
|
||||||
</sources>
|
</sources>
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,6 @@
|
|||||||
|
|
||||||
<headers dist="true" install="$(pkgincludedir)/msg" >
|
<headers dist="true" install="$(pkgincludedir)/msg" >
|
||||||
m_ipcd.h
|
m_ipcd.h
|
||||||
m_ipcd_connect.h
|
|
||||||
m_ipcd_multidata.h
|
m_ipcd_multidata.h
|
||||||
m_ipcd_devices.h
|
m_ipcd_devices.h
|
||||||
m_ipcd_values.h
|
m_ipcd_values.h
|
||||||
@@ -63,7 +62,6 @@
|
|||||||
$(local/typefiles)
|
$(local/typefiles)
|
||||||
|
|
||||||
m_ipcd.c
|
m_ipcd.c
|
||||||
m_ipcd_connect.c
|
|
||||||
m_ipcd_multidata.c
|
m_ipcd_multidata.c
|
||||||
m_ipcd_devices.c
|
m_ipcd_devices.c
|
||||||
m_ipcd_values.c
|
m_ipcd_values.c
|
||||||
|
|||||||
@@ -22,9 +22,8 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define AQH_MSGTYPE_IPC_DATA_RESULT 0x0001 /* AQH_ResultIpcMsg */
|
#define AQH_MSGTYPE_IPC_DATA_RESULT AQH_MSGTYPE_IPC_RESULT
|
||||||
|
#define AQH_MSGTYPE_IPC_DATA_CONNECT_REQ AQH_MSGTYPE_IPC_CONNECT_REQ
|
||||||
#define AQH_MSGTYPE_IPC_DATA_CONNECT_REQ 0x0010 /* serviceName, userName, password */
|
|
||||||
|
|
||||||
#define AQH_MSGTYPE_IPC_DATA_UPDATEDATA 0x0100 /* AQH_MultiDataDataIpcMsg */
|
#define AQH_MSGTYPE_IPC_DATA_UPDATEDATA 0x0100 /* AQH_MultiDataDataIpcMsg */
|
||||||
#define AQH_MSGTYPE_IPC_DATA_DATACHANGED 0x0200 /* AQH_MultiDataDataIpcMsg */
|
#define AQH_MSGTYPE_IPC_DATA_DATACHANGED 0x0200 /* AQH_MultiDataDataIpcMsg */
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
* This file is part of the project AqHome.
|
|
||||||
* AqHome (c) by 2025 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_M_IPCD_CONNECT_H
|
|
||||||
#define AQH_M_IPCD_CONNECT_H
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <aqhome/api.h>
|
|
||||||
#include <aqhome/ipc2/message.h>
|
|
||||||
|
|
||||||
#include <gwenhywfar/tag16.h>
|
|
||||||
|
|
||||||
|
|
||||||
#define AQH_MSGDATA_CONNECT_TAGS_CLIENTID 0x0001
|
|
||||||
#define AQH_MSGDATA_CONNECT_TAGS_USERID 0x0002
|
|
||||||
#define AQH_MSGDATA_CONNECT_TAGS_PASSWORD 0x0003
|
|
||||||
#define AQH_MSGDATA_CONNECT_TAGS_FLAGS 0x0004
|
|
||||||
|
|
||||||
#define AQH_MSGDATA_CONNECT_FLAGS_WANTUPDATES 0x0001
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AQHOME_API AQH_MESSAGE *AQH_IpcdMessageConnect_new(uint16_t code,
|
|
||||||
uint32_t msgId, uint32_t refMsgId,
|
|
||||||
const char *clientId, const char *userId, const char *password,
|
|
||||||
uint32_t flags);
|
|
||||||
|
|
||||||
AQHOME_API void AQH_IpcdMessageConnect_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
|
|
||||||
GWEN_BUFFER *dbuf, const char *sText);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -25,6 +25,8 @@
|
|||||||
#define AQH_IPCMSG_OFFS_PAYLOAD 16 /* begin of payload for a given message */
|
#define AQH_IPCMSG_OFFS_PAYLOAD 16 /* begin of payload for a given message */
|
||||||
|
|
||||||
|
|
||||||
|
#define AQH_MSGTYPE_IPC_RESULT 0x0001
|
||||||
|
#define AQH_MSGTYPE_IPC_CONNECT_REQ 0x0010
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,9 +11,8 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "aqhome/msg/ipc/data/m_ipcd_connect.h"
|
#include "aqhome/msg/ipc/m_ipc_connect.h"
|
||||||
#include "aqhome/msg/ipc/m_ipc_tag16.h"
|
#include "aqhome/msg/ipc/m_ipc_tag16.h"
|
||||||
#include "aqhome/msg/ipc/data/m_ipcd.h"
|
|
||||||
#include "aqhome/msg/ipc/m_ipc.h"
|
#include "aqhome/msg/ipc/m_ipc.h"
|
||||||
|
|
||||||
#include <gwenhywfar/text.h>
|
#include <gwenhywfar/text.h>
|
||||||
@@ -34,22 +33,23 @@
|
|||||||
* ------------------------------------------------------------------------------------------------
|
* ------------------------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
AQH_MESSAGE *AQH_IpcdMessageConnect_new(uint16_t code, uint32_t msgId, uint32_t refMsgId,
|
AQH_MESSAGE *AQH_IpcMessageConnect_new(uint8_t protoId, uint8_t protoVer, uint16_t code,
|
||||||
const char *clientId, const char *userId, const char *password, uint32_t flags)
|
uint32_t msgId, uint32_t refMsgId,
|
||||||
|
const char *clientId, const char *userId, const char *password, uint32_t flags)
|
||||||
{
|
{
|
||||||
AQH_MESSAGE *msg;
|
AQH_MESSAGE *msg;
|
||||||
GWEN_BUFFER *buf;
|
GWEN_BUFFER *buf;
|
||||||
|
|
||||||
buf=GWEN_Buffer_new(0, 256, 0, 1);
|
buf=GWEN_Buffer_new(0, 256, 0, 1);
|
||||||
if (clientId && *clientId)
|
if (clientId && *clientId)
|
||||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_MSGDATA_CONNECT_TAGS_CLIENTID, clientId, buf);
|
GWEN_Tag16_WriteStringTagToBuffer(AQH_MSG_CONNECT_TAGS_CLIENTID, clientId, buf);
|
||||||
if (userId && *userId)
|
if (userId && *userId)
|
||||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_MSGDATA_CONNECT_TAGS_USERID, userId, buf);
|
GWEN_Tag16_WriteStringTagToBuffer(AQH_MSG_CONNECT_TAGS_USERID, userId, buf);
|
||||||
if (password && *password)
|
if (password && *password)
|
||||||
GWEN_Tag16_WriteStringTagToBuffer(AQH_MSGDATA_CONNECT_TAGS_PASSWORD, password, buf);
|
GWEN_Tag16_WriteStringTagToBuffer(AQH_MSG_CONNECT_TAGS_PASSWORD, password, buf);
|
||||||
GWEN_Tag16_WriteUint32TagToBuffer(AQH_MSGDATA_CONNECT_TAGS_FLAGS, flags, buf);
|
GWEN_Tag16_WriteUint32TagToBuffer(AQH_MSG_CONNECT_TAGS_FLAGS, flags, buf);
|
||||||
|
|
||||||
msg=AQH_IpcMessage_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId,
|
msg=AQH_IpcMessage_new(protoId, protoVer, code, msgId, refMsgId,
|
||||||
GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf));
|
GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf));
|
||||||
|
|
||||||
GWEN_Buffer_free(buf);
|
GWEN_Buffer_free(buf);
|
||||||
@@ -58,16 +58,16 @@ AQH_MESSAGE *AQH_IpcdMessageConnect_new(uint16_t code, uint32_t msgId, uint32_t
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void AQH_IpcdMessageConnect_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList, GWEN_BUFFER *dbuf, const char *sText)
|
void AQH_IpcMessageConnect_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList, GWEN_BUFFER *dbuf, const char *sText)
|
||||||
{
|
{
|
||||||
char *clientId=NULL;
|
char *clientId=NULL;
|
||||||
char *userId=NULL;
|
char *userId=NULL;
|
||||||
uint32_t flags=0;
|
uint32_t flags=0;
|
||||||
|
|
||||||
if (tagList) {
|
if (tagList) {
|
||||||
clientId=AQH_Tag16_GetTagDataAsNewString(tagList, AQH_MSGDATA_CONNECT_TAGS_CLIENTID, NULL);
|
clientId=AQH_Tag16_GetTagDataAsNewString(tagList, AQH_MSG_CONNECT_TAGS_CLIENTID, NULL);
|
||||||
userId=AQH_Tag16_GetTagDataAsNewString(tagList, AQH_MSGDATA_CONNECT_TAGS_USERID, NULL);
|
userId=AQH_Tag16_GetTagDataAsNewString(tagList, AQH_MSG_CONNECT_TAGS_USERID, NULL);
|
||||||
flags=AQH_Tag16_GetTagDataAsUint32(tagList, AQH_MSGDATA_CONNECT_TAGS_FLAGS, 0);
|
flags=AQH_Tag16_GetTagDataAsUint32(tagList, AQH_MSG_CONNECT_TAGS_FLAGS, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
GWEN_Buffer_AppendArgs(dbuf,
|
GWEN_Buffer_AppendArgs(dbuf,
|
||||||
40
aqhome/msg/ipc/m_ipc_connect.h
Normal file
40
aqhome/msg/ipc/m_ipc_connect.h
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* This file is part of the project AqHome.
|
||||||
|
* AqHome (c) by 2025 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_M_IPCD_CONNECT_H
|
||||||
|
#define AQH_M_IPCD_CONNECT_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <aqhome/api.h>
|
||||||
|
#include <aqhome/ipc2/message.h>
|
||||||
|
|
||||||
|
#include <gwenhywfar/tag16.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define AQH_MSG_CONNECT_TAGS_CLIENTID 0x0001
|
||||||
|
#define AQH_MSG_CONNECT_TAGS_USERID 0x0002
|
||||||
|
#define AQH_MSG_CONNECT_TAGS_PASSWORD 0x0003
|
||||||
|
#define AQH_MSG_CONNECT_TAGS_FLAGS 0x0004
|
||||||
|
|
||||||
|
#define AQH_MSG_CONNECT_FLAGS_WANTUPDATES 0x0001
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
AQHOME_API AQH_MESSAGE *AQH_IpcMessageConnect_new(uint8_t protoId, uint8_t protoVer, uint16_t code,
|
||||||
|
uint32_t msgId, uint32_t refMsgId,
|
||||||
|
const char *clientId, const char *userId, const char *password,
|
||||||
|
uint32_t flags);
|
||||||
|
|
||||||
|
AQHOME_API void AQH_IpcMessageConnect_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
|
||||||
|
GWEN_BUFFER *dbuf, const char *sText);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -49,6 +49,7 @@
|
|||||||
m_ipcn_forward.h
|
m_ipcn_forward.h
|
||||||
m_ipcn_getdevices_req.h
|
m_ipcn_getdevices_req.h
|
||||||
m_ipcn_getdevices_rsp.h
|
m_ipcn_getdevices_rsp.h
|
||||||
|
m_ipcn_setaccmsggrps.h
|
||||||
</headers>
|
</headers>
|
||||||
|
|
||||||
|
|
||||||
@@ -63,6 +64,7 @@
|
|||||||
m_ipcn_forward.c
|
m_ipcn_forward.c
|
||||||
m_ipcn_getdevices_req.c
|
m_ipcn_getdevices_req.c
|
||||||
m_ipcn_getdevices_rsp.c
|
m_ipcn_getdevices_rsp.c
|
||||||
|
m_ipcn_setaccmsggrps.c
|
||||||
</sources>
|
</sources>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,8 @@
|
|||||||
#define AQH_IPC_PROTOCOL_NODES_VERSION 1
|
#define AQH_IPC_PROTOCOL_NODES_VERSION 1
|
||||||
|
|
||||||
|
|
||||||
#define AQH_MSGTYPE_IPC_NODES_RESULT 0xf001
|
#define AQH_MSGTYPE_IPC_NODES_RESULT AQH_MSGTYPE_IPC_RESULT
|
||||||
|
#define AQH_MSGTYPE_IPC_NODES_CONNECT_REQ AQH_MSGTYPE_IPC_CONNECT_REQ
|
||||||
|
|
||||||
#define AQH_MSGTYPE_IPC_NODES_FORWARD 0xf100
|
#define AQH_MSGTYPE_IPC_NODES_FORWARD 0xf100
|
||||||
#define AQH_MSGTYPE_IPC_NODES_VALUE 0xf200
|
#define AQH_MSGTYPE_IPC_NODES_VALUE 0xf200
|
||||||
|
|||||||
@@ -52,6 +52,13 @@ AQH_MESSAGE *AQH_IpcnMessageGetDevicesRsp_new(uint16_t code, uint32_t msgId, uin
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
uint32_t AQH_IpcnMessageGetDevicesRsp_GetFlags(const GWEN_TAG16_LIST *tagList)
|
||||||
|
{
|
||||||
|
return tagList?AQH_Tag16_GetTagDataAsUint32(tagList, AQH_MSGNODE_GETDEVICES_RSP_TAGS_FLAGS, 0):0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AQH_NODE_INFO *AQH_IpcnMessageGetDevicesRsp_ReadNodeInfo(const GWEN_TAG16_LIST *tagList)
|
AQH_NODE_INFO *AQH_IpcnMessageGetDevicesRsp_ReadNodeInfo(const GWEN_TAG16_LIST *tagList)
|
||||||
{
|
{
|
||||||
if (tagList) {
|
if (tagList) {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include <gwenhywfar/buffer.h>
|
#include <gwenhywfar/buffer.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define AQH_MSGNODE_GETDEVICES_RSP_FLAGS_LASTMSG 0x01
|
||||||
|
|
||||||
#define AQH_MSGNODE_GETDEVICES_RSP_TAGS_FLAGS 0x01
|
#define AQH_MSGNODE_GETDEVICES_RSP_TAGS_FLAGS 0x01
|
||||||
#define AQH_MSGNODE_GETDEVICES_RSP_TAGS_NODEINFO 0xc2
|
#define AQH_MSGNODE_GETDEVICES_RSP_TAGS_NODEINFO 0xc2
|
||||||
@@ -28,6 +29,7 @@
|
|||||||
|
|
||||||
AQHOME_API AQH_MESSAGE *AQH_IpcnMessageGetDevicesRsp_new(uint16_t code, uint32_t msgId, uint32_t refMsgId,
|
AQHOME_API AQH_MESSAGE *AQH_IpcnMessageGetDevicesRsp_new(uint16_t code, uint32_t msgId, uint32_t refMsgId,
|
||||||
uint32_t flags, const AQH_NODE_INFO *ni);
|
uint32_t flags, const AQH_NODE_INFO *ni);
|
||||||
|
AQHOME_API uint32_t AQH_IpcnMessageGetDevicesRsp_GetFlags(const GWEN_TAG16_LIST *tagList);
|
||||||
AQHOME_API AQH_NODE_INFO *AQH_IpcnMessageGetDevicesRsp_ReadNodeInfo(const GWEN_TAG16_LIST *tagList);
|
AQHOME_API AQH_NODE_INFO *AQH_IpcnMessageGetDevicesRsp_ReadNodeInfo(const GWEN_TAG16_LIST *tagList);
|
||||||
|
|
||||||
AQHOME_API void AQH_IpcnMessageGetDevicesRsp_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
|
AQHOME_API void AQH_IpcnMessageGetDevicesRsp_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
|
||||||
|
|||||||
77
aqhome/msg/ipc/nodes/m_ipcn_setaccmsggrps.c
Normal file
77
aqhome/msg/ipc/nodes/m_ipcn_setaccmsggrps.c
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* This file is part of the project AqHome.
|
||||||
|
* AqHome (c) by 2025 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/msg/ipc/nodes/m_ipcn_setaccmsggrps.h"
|
||||||
|
#include "aqhome/msg/ipc/nodes/m_ipcn.h"
|
||||||
|
#include "aqhome/msg/ipc/m_ipc_tag16.h"
|
||||||
|
#include "aqhome/msg/ipc/m_ipc.h"
|
||||||
|
|
||||||
|
#include <gwenhywfar/text.h>
|
||||||
|
#include <gwenhywfar/tag16.h>
|
||||||
|
#include <gwenhywfar/buffer.h>
|
||||||
|
#include <gwenhywfar/debug.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------------------------------
|
||||||
|
* forward declarations
|
||||||
|
* ------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------------------------------
|
||||||
|
* implementation
|
||||||
|
* ------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
AQH_MESSAGE *AQH_IpcnMessageSetAcceptedMsgGroups_new(uint16_t code, uint32_t msgId, uint32_t refMsgId, uint32_t grps)
|
||||||
|
{
|
||||||
|
AQH_MESSAGE *msg;
|
||||||
|
GWEN_BUFFER *buf;
|
||||||
|
|
||||||
|
buf=GWEN_Buffer_new(0, 256, 0, 1);
|
||||||
|
|
||||||
|
GWEN_Tag16_WriteUint32TagToBuffer(AQH_MSGNODES_SETACCMSGGRPS_TAGS_GROUPS, grps, buf);
|
||||||
|
|
||||||
|
msg=AQH_IpcMessage_new(AQH_IPC_PROTOCOL_NODES_ID, AQH_IPC_PROTOCOL_NODES_VERSION, code, msgId, refMsgId,
|
||||||
|
GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf));
|
||||||
|
GWEN_Buffer_free(buf);
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
uint32_t AQH_IpcnMessageSetAcceptedMsgGroups_GetGroups(const GWEN_TAG16_LIST *tagList)
|
||||||
|
{
|
||||||
|
return tagList?AQH_Tag16_GetTagDataAsUint32(tagList, AQH_MSGNODES_SETACCMSGGRPS_TAGS_GROUPS, 0):0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void AQH_IpcnMessageSetAcceptedMsgGroups_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
|
||||||
|
GWEN_BUFFER *dbuf, const char *sText)
|
||||||
|
{
|
||||||
|
GWEN_Buffer_AppendArgs(dbuf,
|
||||||
|
"SET_ACCEPTED_MSG_GROUPS(%s) %s (code=%d, proto=%d, proto version=%d, groups=%08x)\n",
|
||||||
|
AQH_IpcnMessage_MsgTypeToChar(AQH_IpcMessage_GetCode(msg)),
|
||||||
|
sText?sText:"",
|
||||||
|
AQH_IpcMessage_GetCode(msg),
|
||||||
|
AQH_IpcMessage_GetProtoId(msg),
|
||||||
|
AQH_IpcMessage_GetProtoVersion(msg),
|
||||||
|
AQH_IpcnMessageSetAcceptedMsgGroups_GetGroups(tagList));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
42
aqhome/msg/ipc/nodes/m_ipcn_setaccmsggrps.h
Normal file
42
aqhome/msg/ipc/nodes/m_ipcn_setaccmsggrps.h
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* This file is part of the project AqHome.
|
||||||
|
* AqHome (c) by 2025 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_MSGNODES_SETACCMSGGRPS_H
|
||||||
|
#define AQH_MSGNODES_SETACCMSGGRPS_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <aqhome/api.h>
|
||||||
|
#include <aqhome/ipc2/message.h>
|
||||||
|
#include <aqhome/data/value.h>
|
||||||
|
|
||||||
|
#include <gwenhywfar/tag16.h>
|
||||||
|
#include <gwenhywfar/buffer.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define AQH_MSGNODES_SETACCMSGGRPS_TAGS_GROUPS 0x0001
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
AQHOME_API AQH_MESSAGE *AQH_IpcnMessageSetAcceptedMsgGroups_new(uint16_t code, uint32_t msgId, uint32_t refMsgId, uint32_t grps);
|
||||||
|
|
||||||
|
AQHOME_API void AQH_IpcdMessageSetAcceptedMsgGroups_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
|
||||||
|
GWEN_BUFFER *dbuf, const char *sText);
|
||||||
|
|
||||||
|
uint32_t AQH_IpcnMessageSetAcceptedMsgGroups_GetGroups(const GWEN_TAG16_LIST *tagList);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user