aqhome-tool: setdata can now use ":" to separate bytes/words
This commit is contained in:
@@ -23,6 +23,10 @@
|
|||||||
#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 <gwenhywfar/stringlist.h>
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------------------------------
|
||||||
@@ -46,6 +50,10 @@
|
|||||||
|
|
||||||
static AQH_MESSAGE *_createRequestMessage(AQH_OBJECT *o, uint32_t msgId);
|
static AQH_MESSAGE *_createRequestMessage(AQH_OBJECT *o, uint32_t msgId);
|
||||||
static int _readValueFromString(const char *s, double *pDouble);
|
static int _readValueFromString(const char *s, double *pDouble);
|
||||||
|
static int _readValueFromStringList(const char *s, double *pDouble);
|
||||||
|
static int _read16BitValues(const GWEN_STRINGLIST *sl, double *pDouble);
|
||||||
|
static int _read8BitValues(const GWEN_STRINGLIST *sl, double *pDouble);
|
||||||
|
static int _readDouble(const char *s, double *pDouble);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -130,6 +138,115 @@ AQH_MESSAGE *_createRequestMessage(GWEN_UNUSED AQH_OBJECT *o, uint32_t msgId)
|
|||||||
|
|
||||||
|
|
||||||
int _readValueFromString(const char *s, double *pDouble)
|
int _readValueFromString(const char *s, double *pDouble)
|
||||||
|
{
|
||||||
|
if (s && *s) {
|
||||||
|
if (strchr(s, ':')!=NULL)
|
||||||
|
return _readValueFromStringList(s, pDouble);
|
||||||
|
else
|
||||||
|
return _readDouble(s, pDouble);
|
||||||
|
}
|
||||||
|
DBG_ERROR(NULL, "Missing value");
|
||||||
|
return GWEN_ERROR_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int _readValueFromStringList(const char *s, double *pDouble)
|
||||||
|
{
|
||||||
|
GWEN_STRINGLIST *sl;
|
||||||
|
|
||||||
|
sl=GWEN_StringList_fromString2(s, ":", 0, GWEN_TEXT_FLAGS_DEL_QUOTES);
|
||||||
|
if (sl) {
|
||||||
|
int cnt;
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
cnt=GWEN_StringList_Count(sl);
|
||||||
|
if (cnt<3){ /* read two 16 bit values */
|
||||||
|
rv=_read16BitValues(sl, pDouble);
|
||||||
|
GWEN_StringList_free(sl);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
else if (cnt<5) { /* read four 8 bit values */
|
||||||
|
rv=_read8BitValues(sl, pDouble);
|
||||||
|
GWEN_StringList_free(sl);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
DBG_ERROR(NULL, "Bad value \"%s\"", s);
|
||||||
|
return GWEN_ERROR_GENERIC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
DBG_ERROR(NULL, "Bad value \"%s\"", s);
|
||||||
|
return GWEN_ERROR_GENERIC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int _read16BitValues(const GWEN_STRINGLIST *sl, double *pDouble)
|
||||||
|
{
|
||||||
|
const GWEN_STRINGLISTENTRY *se;
|
||||||
|
uint32_t result=0;
|
||||||
|
|
||||||
|
se=GWEN_StringList_FirstEntry(sl);
|
||||||
|
while(se) {
|
||||||
|
const char *s;
|
||||||
|
|
||||||
|
s=GWEN_StringListEntry_Data(se);
|
||||||
|
if (s && *s) {
|
||||||
|
double v;
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
rv=_readDouble(s, &v);
|
||||||
|
if (rv<0) {
|
||||||
|
DBG_INFO(NULL, "here (%d)", rv);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
result<<=16;
|
||||||
|
result+=(((uint32_t) v) & 0xffff);
|
||||||
|
}
|
||||||
|
se=GWEN_StringListEntry_Next(se);
|
||||||
|
}
|
||||||
|
|
||||||
|
*pDouble=(double) result;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int _read8BitValues(const GWEN_STRINGLIST *sl, double *pDouble)
|
||||||
|
{
|
||||||
|
const GWEN_STRINGLISTENTRY *se;
|
||||||
|
uint32_t result=0;
|
||||||
|
|
||||||
|
se=GWEN_StringList_FirstEntry(sl);
|
||||||
|
while(se) {
|
||||||
|
const char *s;
|
||||||
|
|
||||||
|
s=GWEN_StringListEntry_Data(se);
|
||||||
|
if (s && *s) {
|
||||||
|
double v;
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
rv=_readDouble(s, &v);
|
||||||
|
if (rv<0) {
|
||||||
|
DBG_INFO(NULL, "here (%d)", rv);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
result<<=8;
|
||||||
|
result=(((uint32_t) v) & 0xff);
|
||||||
|
}
|
||||||
|
se=GWEN_StringListEntry_Next(se);
|
||||||
|
}
|
||||||
|
|
||||||
|
*pDouble=(double) result;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int _readDouble(const char *s, double *pDouble)
|
||||||
{
|
{
|
||||||
int l;
|
int l;
|
||||||
|
|
||||||
@@ -155,14 +272,21 @@ int _readValueFromString(const char *s, double *pDouble)
|
|||||||
double d;
|
double d;
|
||||||
|
|
||||||
if (1==sscanf(s, "%lf", &d)) {
|
if (1==sscanf(s, "%lf", &d)) {
|
||||||
return d;
|
*pDouble=d;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DBG_ERROR(NULL, "Bad value \"%s\"", s);
|
DBG_ERROR(NULL, "Bad value \"%s\"", s);
|
||||||
return GWEN_ERROR_GENERIC;
|
return GWEN_ERROR_INVALID;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
DBG_ERROR(NULL, "Empty value");
|
||||||
|
return GWEN_ERROR_INVALID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user