aqhome-tool: Decreased verbosity, fixed flash handling.
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#include <gwenhywfar/i18n.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
#include <gwenhywfar/text.h>
|
||||
#include <gwenhywfar/timestamp.h>
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
@@ -44,6 +45,8 @@
|
||||
#define A_CHAR GWEN_ArgsType_Char
|
||||
#define A_INT GWEN_ArgsType_Int
|
||||
|
||||
#define LAST1H (60*60)
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
@@ -53,7 +56,7 @@
|
||||
|
||||
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 _printNode(const AQH_NODE_INFO *ni, int printAll);
|
||||
static void _printUintAsTextOrHex(uint32_t u, int bits);
|
||||
|
||||
|
||||
@@ -74,6 +77,7 @@ int AQH_Tool_GetNodes(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
||||
{ A_ARG, A_INT, "tcpPort", 0, 1, "P", "tcpport", I18S("TCP port to connect to"), NULL},
|
||||
{ A_ARG, A_INT, "timeout", 0, 1, "T", NULL, I18S("Specify timeout in seconds for response"), NULL},
|
||||
{ 0, A_INT, "printHeader", 0, 1, "H", "printheader", I18S("Print header if given"), NULL},
|
||||
{ 0, A_INT, "printAll", 0, 1, "a", "printall", I18S("Print all devices (not only last seen)"), NULL},
|
||||
{ A_END, A_INT, "help", 0, 0, "h", "help", I18S("Show this help screen"), NULL}
|
||||
};
|
||||
|
||||
@@ -104,11 +108,13 @@ AQH_MESSAGE *_createRequestMessage(GWEN_UNUSED AQH_OBJECT *o, uint32_t msgId)
|
||||
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;
|
||||
GWEN_DB_NODE *dbArgs;
|
||||
//int printHeader;
|
||||
int printAll;
|
||||
|
||||
//dbArgs=AQH_ToolClient_GetDbLocalArgs(o);
|
||||
dbArgs=AQH_ToolClient_GetDbLocalArgs(o);
|
||||
//printHeader=first?GWEN_DB_GetIntValue(dbArgs, "printHeader", 0, 0):0;
|
||||
printAll=GWEN_DB_GetIntValue(dbArgs, "printAll", 0, 0);
|
||||
|
||||
code=AQH_IpcMessage_GetCode(msg);
|
||||
if (code==AQH_MSGTYPE_IPC_NODES_GETDEVICES_RSP) {
|
||||
@@ -116,7 +122,7 @@ int _handleResponseMessage(GWEN_UNUSED AQH_OBJECT *o, const AQH_MESSAGE *msg, co
|
||||
|
||||
ni=AQH_IpcnMessageGetDevicesRsp_ReadNodeInfo(tagList);
|
||||
if (ni)
|
||||
_printNode(ni);
|
||||
_printNode(ni, printAll);
|
||||
|
||||
if (AQH_IpcnMessageGetDevicesRsp_GetFlags(tagList) & AQH_MSGNODE_GETDEVICES_RSP_FLAGS_LASTMSG) {
|
||||
DBG_INFO(NULL, "Last message received");
|
||||
@@ -135,35 +141,44 @@ int _handleResponseMessage(GWEN_UNUSED AQH_OBJECT *o, const AQH_MESSAGE *msg, co
|
||||
|
||||
|
||||
|
||||
void _printNode(const AQH_NODE_INFO *ni)
|
||||
void _printNode(const AQH_NODE_INFO *ni, int printAll)
|
||||
{
|
||||
uint32_t u;
|
||||
const GWEN_TIMESTAMP *ts;
|
||||
time_t now;
|
||||
time_t tLastSeen=0;
|
||||
int timeSinceLastSeen;
|
||||
|
||||
fprintf(stdout, "- node: addr=%3d, uid=0x%08x, device=",
|
||||
AQH_NodeInfo_GetBusAddress(ni),
|
||||
(unsigned int) AQH_NodeInfo_GetUid(ni));
|
||||
now=time(NULL);
|
||||
ts=AQH_NodeInfo_GetTimestampLastChange(ni);
|
||||
tLastSeen=ts?GWEN_Timestamp_toTimeT(ts):now;
|
||||
timeSinceLastSeen=(int) (now-tLastSeen);
|
||||
if (printAll || timeSinceLastSeen<LAST1H) {
|
||||
uint32_t u;
|
||||
|
||||
u=AQH_NodeInfo_GetManufacturer(ni);
|
||||
_printUintAsTextOrHex(u, 32);
|
||||
fprintf(stdout, ":");
|
||||
u=AQH_NodeInfo_GetDeviceType(ni);
|
||||
_printUintAsTextOrHex(u, 16);
|
||||
u=AQH_NodeInfo_GetDeviceVersion(ni);
|
||||
fprintf(stdout, " v%d.%d", (u>>8) & 0xff, u & 0xff);
|
||||
u=AQH_NodeInfo_GetFirmwareVersion(ni);
|
||||
fprintf(stdout, ", firmware=%d.%d.%d (%d), ",
|
||||
(u>>16) & 0xff, (u>>8) & 0xff, u & 0xff, (u>>24) & 0xff);
|
||||
if (ts)
|
||||
fprintf(stdout, "last seen %s, ", GWEN_Timestamp_GetString(ts));
|
||||
fprintf(stdout, "pkg out: %d, pkg in: %d, collisions: %d, busy: %d, crc: %d, io: %d\n",
|
||||
AQH_NodeInfo_GetStatsPacketsOut(ni),
|
||||
AQH_NodeInfo_GetStatsPacketsIn(ni),
|
||||
AQH_NodeInfo_GetStatsCollisions(ni),
|
||||
AQH_NodeInfo_GetStatsBusy(ni),
|
||||
AQH_NodeInfo_GetStatsCrcErrors(ni),
|
||||
AQH_NodeInfo_GetStatsIoErrors(ni));
|
||||
fprintf(stdout, "- node: addr=%3d, uid=0x%08x, device=",
|
||||
AQH_NodeInfo_GetBusAddress(ni),
|
||||
(unsigned int) AQH_NodeInfo_GetUid(ni));
|
||||
|
||||
u=AQH_NodeInfo_GetManufacturer(ni);
|
||||
_printUintAsTextOrHex(u, 32);
|
||||
fprintf(stdout, ":");
|
||||
u=AQH_NodeInfo_GetDeviceType(ni);
|
||||
_printUintAsTextOrHex(u, 16);
|
||||
u=AQH_NodeInfo_GetDeviceVersion(ni);
|
||||
fprintf(stdout, " v%d.%d", (u>>8) & 0xff, u & 0xff);
|
||||
u=AQH_NodeInfo_GetFirmwareVersion(ni);
|
||||
fprintf(stdout, ", firmware=%d.%d.%d (%d), ",
|
||||
(u>>16) & 0xff, (u>>8) & 0xff, u & 0xff, (u>>24) & 0xff);
|
||||
if (ts)
|
||||
fprintf(stdout, "last seen %s, ", GWEN_Timestamp_GetString(ts));
|
||||
fprintf(stdout, "pkg out: %d, pkg in: %d, collisions: %d, busy: %d, crc: %d, io: %d\n",
|
||||
AQH_NodeInfo_GetStatsPacketsOut(ni),
|
||||
AQH_NodeInfo_GetStatsPacketsIn(ni),
|
||||
AQH_NodeInfo_GetStatsCollisions(ni),
|
||||
AQH_NodeInfo_GetStatsBusy(ni),
|
||||
AQH_NodeInfo_GetStatsCrcErrors(ni),
|
||||
AQH_NodeInfo_GetStatsIoErrors(ni));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user