aqhome-tool: added command "time" to set node network time.
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 2025 Martin Preuss, all rights reserved.
|
* AqHome (c) by 2026 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.
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "./nodes/ping.h"
|
#include "./nodes/ping.h"
|
||||||
#include "./nodes/flash.h"
|
#include "./nodes/flash.h"
|
||||||
|
#include "./nodes/settime.h"
|
||||||
#include "./nodes/getnodes.h"
|
#include "./nodes/getnodes.h"
|
||||||
#include "./data/getvalues.h"
|
#include "./data/getvalues.h"
|
||||||
#include "./data/getdevices.h"
|
#include "./data/getdevices.h"
|
||||||
@@ -91,6 +92,7 @@ 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("time", AQH_Tool_SetTime, I18N("Set node network time (handled by RTC module)")),
|
||||||
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("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")),
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
ping.h
|
ping.h
|
||||||
flash.h
|
flash.h
|
||||||
getnodes.h
|
getnodes.h
|
||||||
|
settime.h
|
||||||
</headers>
|
</headers>
|
||||||
|
|
||||||
<sources>
|
<sources>
|
||||||
@@ -44,6 +45,7 @@
|
|||||||
ping.c
|
ping.c
|
||||||
flash.c
|
flash.c
|
||||||
getnodes.c
|
getnodes.c
|
||||||
|
settime.c
|
||||||
</sources>
|
</sources>
|
||||||
|
|
||||||
<useTargets>
|
<useTargets>
|
||||||
|
|||||||
139
apps/aqhome-tool/nodes/settime.c
Normal file
139
apps/aqhome-tool/nodes/settime.c
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* This file is part of the project AqHome.
|
||||||
|
* AqHome (c) by 2026 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 "./settime.h"
|
||||||
|
#include "../client.h"
|
||||||
|
#include "../utils.h"
|
||||||
|
|
||||||
|
#include "aqhome/msg/ipc/m_ipc.h"
|
||||||
|
#include "aqhome/msg/ipc/m_ipc_result.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_time.h"
|
||||||
|
|
||||||
|
#include <gwenhywfar/args.h>
|
||||||
|
#include <gwenhywfar/i18n.h>
|
||||||
|
#include <gwenhywfar/debug.h>
|
||||||
|
#include <gwenhywfar/text.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------------------------------
|
||||||
|
* defs
|
||||||
|
* ------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define I18S(msg) 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
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------------------------------
|
||||||
|
* 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_SetTime(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
||||||
|
{
|
||||||
|
AQH_EVENT_LOOP *eventLoop;
|
||||||
|
AQH_OBJECT *o;
|
||||||
|
int rv;
|
||||||
|
const GWEN_ARGS args[]= {
|
||||||
|
/* flags type name min max s long short_descr, long_descr */
|
||||||
|
{ A_ARG, A_CHAR, "tcpAddress", 0, 1, "t", "tcpaddress", I18S("TCP address to connect to [127.0.0.1]"), NULL},
|
||||||
|
{ A_ARG, A_INT, "tcpPort", 0, 1, "P", "tcpport", I18S("Specify the TCP port to listen on"), NULL},
|
||||||
|
{ A_ARG, A_INT, "timeout", 0, 1, "T", NULL, I18S("Specify timeout in seconds for response"), NULL},
|
||||||
|
{ A_ARG, A_CHAR, "userId", 0, 1, "u", "userid", I18S("Specify user id"), NULL},
|
||||||
|
{ A_ARG, A_CHAR, "password", 0, 1, "p", "password", I18S("Specify service password"), NULL},
|
||||||
|
{ A_ARG, A_INT, "nodeAddr", 1, 1, "n", "nodeaddr", I18S("Specify bus addr of the node to ping"), NULL},
|
||||||
|
{ A_END, A_INT, "help", 0, 0, "h", "help", I18S("Show this help screen"), NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
eventLoop=AQH_EventLoop_new();
|
||||||
|
o=AQH_ToolClient_new(eventLoop, AQH_IPC_PROTOCOL_NODES_ID, AQH_IPC_PROTOCOL_NODES_VERSION, dbGlobalArgs, args);
|
||||||
|
AQH_ToolClient_SetCreateRequestMessageFn(o, _createRequestMessage);
|
||||||
|
AQH_ToolClient_SetHandleResponseMessageFn(o, _handleResponseMessage);
|
||||||
|
rv=AQH_ToolClient_ReadLocalArgs(o, argc, argv);
|
||||||
|
if (rv!=0)
|
||||||
|
return rv;
|
||||||
|
|
||||||
|
rv=AQH_ToolClient_Connect(o, AQH_TOOL_CLIENT_CONNECTFLAGS_WITHCONNECTMSG | AQH_TOOL_CLIENT_CONNECTFLAGS_WITHGRPMSG,
|
||||||
|
0, AQH_MSG_TYPEGROUP_ALL);
|
||||||
|
if (rv<0) {
|
||||||
|
DBG_INFO(NULL, "here(%d)", rv);
|
||||||
|
AQH_Object_free(o);
|
||||||
|
AQH_EventLoop_free(eventLoop);
|
||||||
|
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;
|
||||||
|
GWEN_TIMESTAMP *ts;
|
||||||
|
|
||||||
|
dbArgs=AQH_ToolClient_GetDbLocalArgs(o);
|
||||||
|
nodeAddr=GWEN_DB_GetIntValue(dbArgs, "nodeAddr", 0, 0);
|
||||||
|
ts=GWEN_Timestamp_NowInLocalTime();
|
||||||
|
|
||||||
|
nodeMsg=AQH_TimeMessage_new(nodeAddr, AQH_TOOL_CLIENT_NODEADDR, AQH_MSG_TYPE_TIME_REQSET, 0, ts);
|
||||||
|
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_TIME_RSPSET) &&
|
||||||
|
(nodeAddr==0 || nodeAddr==0xff || nodeAddr==AQH_NodeMessage_GetSourceAddress(msg))) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
DBG_INFO(NULL, "Unexpected message \"%d\"", code);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
20
apps/aqhome-tool/nodes/settime.h
Normal file
20
apps/aqhome-tool/nodes/settime.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* This file is part of the project AqHome.
|
||||||
|
* AqHome (c) by 2026 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 AQHOME_TOOL_SETTIME_H
|
||||||
|
#define AQHOME_TOOL_SETTIME_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <gwenhywfar/db.h>
|
||||||
|
|
||||||
|
|
||||||
|
int AQH_Tool_SetTime(GWEN_DB_NODE *dbArgs, int argc, char **argv);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
Reference in New Issue
Block a user