let setData use double values instead of strings.

this allows for storing value set with setData which can then be used in
the cgi module to retrieve the last value set.
This commit is contained in:
Martin Preuss
2025-10-07 23:50:50 +02:00
parent 1aeeed9845
commit d0c8b3b284
22 changed files with 421 additions and 186 deletions

View File

@@ -45,6 +45,7 @@
*/
static AQH_MESSAGE *_createRequestMessage(AQH_OBJECT *o, uint32_t msgId);
static int _readValueFromString(const char *s, double *pDouble);
@@ -93,18 +94,30 @@ AQH_MESSAGE *_createRequestMessage(GWEN_UNUSED AQH_OBJECT *o, uint32_t msgId)
GWEN_DB_NODE *dbArgs;
const char *valueName;
const char *valueUnits;
const char *valueData;
const char *valueDataAsString;
double valueData;
AQH_VALUE *v;
int rv;
dbArgs=AQH_ToolClient_GetDbLocalArgs(o);
valueName=GWEN_DB_GetCharValue(dbArgs, "valueName", 0, NULL);
valueUnits=GWEN_DB_GetCharValue(dbArgs, "valueUnits", 0, NULL);
valueData=GWEN_DB_GetCharValue(dbArgs, "value", 0, NULL);
valueDataAsString=GWEN_DB_GetCharValue(dbArgs, "value", 0, NULL);
if (valueDataAsString && *valueDataAsString) {
rv=_readValueFromString(valueDataAsString, &valueData);
if (rv<0) {
DBG_ERROR(NULL, "ERROR: Bad value");
return NULL;
}
}
if (!(valueName && *valueName)) {
DBG_ERROR(NULL, "ERROR: Missing value name");
return NULL;
}
v=AQH_Value_new();
AQH_Value_SetNameForSystem(v, valueName);
AQH_Value_SetValueUnits(v, valueUnits);
@@ -116,3 +129,40 @@ AQH_MESSAGE *_createRequestMessage(GWEN_UNUSED AQH_OBJECT *o, uint32_t msgId)
int _readValueFromString(const char *s, double *pDouble)
{
int l;
l=strlen(s);
if (l) {
if (*s=='#') {
unsigned int h;
if (1==sscanf(s+1, "%x", &h)) {
*pDouble=(double) h;
return 0;
}
}
else if (l>1 && s[0]=='0' && ((tolower(s[1])=='x') || tolower(s[1])=='b')) {
unsigned int h;
if (1==sscanf(s, "%u", &h)) {
*pDouble=(double) h;
return 0;
}
}
else {
double d;
if (1==sscanf(s, "%lf", &d)) {
return d;
}
}
DBG_ERROR(NULL, "Bad value \"%s\"", s);
return GWEN_ERROR_GENERIC;
}
}