- remob.c: forward errors to sics correctly

- minor, more cosmetic fixes
This commit is contained in:
2015-04-28 16:17:32 +02:00
parent 04906f672a
commit fb7741178d
5 changed files with 47 additions and 24 deletions

View File

@ -388,6 +388,12 @@ int AsconBaseHandler(Ascon * a)
}
void AsconInsertProtocol(AsconProtocol *protocol) {
AsconProtocol *p;
for (p = protocols; p != NULL; p = p->next) {
if (p == protocol)
return;
}
protocol->next = protocols;
protocols = protocol;
}

View File

@ -101,6 +101,7 @@ void DeleteDynString(pDynString self)
if (self->pBuffer)
free(self->pBuffer);
self->iMAGIC = 0;
free(self);
}

View File

@ -218,9 +218,7 @@ static int LogReader(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[])
{
/* Usage:
graph <start time> <end time> [ none <none value> ] np <number of points> <variable> [<variable> ...]
graph <start time> <end time> text <variable>
graph <start time> <end time> <step> <variable> [<variable> ...]
graph <start time> <end time> [ none <none value> | text | np <number of points> ] <variable> [<variable> ...]
<start time> and <end time> are seconds since epoch (unix time) or, if the value
is below one day, a time relative to the actual time
@ -230,15 +228,13 @@ static int LogReader(SConnection * pCon, SicsInterp * pSics, void *pData,
<number of points> is the maximal number of points to be returned. If more values
are present and the values are numeric, the data is reduced. If the data is not
numeric, the last values may be skipped in order to avoid overflow.
If np is not given, it is assumed to be very high.
<variable> is the name of a variable (several vaiables may be given).
Note that slashes are converted to dots, and that the first slash is ignored.
The seconds variant is for text values, which can not be reduced. In any case, all values
are returned.
The third variant is old style and can be replaced by the first variant, where
<number of points> = (<start time> - <end time>) / <step> + 2
"text" means that the values are not numeric, in this case np is not needed
and by default infinitely high
Output format:
@ -308,15 +304,16 @@ Statistics *old;
to += now;
}
iarg = 3;
type0 = NUMERIC;
while (1) {
if (iarg >= argc)
goto illarg;
if (strcasecmp(argv[iarg], "text") == 0) { /* non-numeric values */
iarg++;
step = 1;
type0 = TEXT;
np = to - from + 2;
break;
type0 = TEXT;
/* break; */
} else if (strcasecmp(argv[iarg], "none") == 0) { /* none */
iarg++;
if (iarg >= argc)
@ -327,7 +324,6 @@ Statistics *old;
iarg++;
if (iarg >= argc)
goto illarg;
type0 = NUMERIC;
np = strtol(argv[iarg], &p, 0);
if (p == argv[iarg])
goto illarg;
@ -341,14 +337,9 @@ Statistics *old;
}
break;
} else {
step = strtol(argv[iarg], &p, 0);
if (p == argv[iarg])
goto illarg;
iarg++;
if (step <= 0)
step = 1;
type0 = NUMERIC;
np = (from - to) / step + 2;
np = to - from + 2;
step = 1;
break;
}
}
if (step <= 0)

32
remob.c
View File

@ -313,7 +313,8 @@ static int RemTransact(RemServer * remserver, int nChan,
int try;
int argMask;
RemChannel *rc = &remserver->rc[nChan];
pDynString errorResult;
try = 3;
if (rc->timeout) { /* eat old responses */
while (RemRead(rc, 0) > 0) {
@ -339,6 +340,20 @@ tryagain:
if (iRet <= 0)
goto close;
while (!StartsWith(rc->line, "TRANSACTIONFINISHED")) {
if (StartsWith(rc->line, "ERROR:")) {
errorResult = CreateDynString(60, 64);
do {
RemHandle(remserver);
DynStringConcat(errorResult, rc->line);
DynStringConcat(errorResult, "\n");
iRet = RemRead(rc, 2000);
} while (!StartsWith(rc->line, "TRANSACTIONFINISHED"));
if (pCon != NULL) {
SCPrintf(pCon, eError, "ERROR: in %s:\n%s", remserver->name, GetCharArray(errorResult));
}
DeleteDynString(errorResult);
return -2;
}
RemHandle(remserver);
va_start(ap, cmd);
arg = va_arg(ap, char *);
@ -448,15 +463,17 @@ static float RemobGetValue(void *pData, SConnection * pCon)
SCDeleteConnection(remserver->conn);
}
remserver->conn = SCCopyConnection(pCon);
none = -1.25e6;
none = -1.234e32;
value = none;
snprintf(buf, sizeof(buf), "<%s", remob->name);
/* get value needs only spy priviledge */
iRet =
RemTransact(remserver, 0, pCon, remob->name, buf, &value, ">", NULL);
/*
if (iRet <= 0) {
return 0.0;
}
*/
if (value != none) {
return value;
}
@ -654,7 +671,13 @@ int RemobAction(SConnection * pCon, SicsInterp * pSics, void *pData,
remserver->conn = SCCopyConnection(pCon);
}
if (argc == 1) {
iRet = RemTransact(remserver, nChan, pCon, remob->name, ">", NULL);
/* filter out time stamps !=== */
iRet = RemTransact(remserver, nChan, pCon, remob->name, "!===", ">", NULL);
if (iRet < 0) {
iRet = 0;
} else {
iRet = 1;
}
} else if (strcasecmp(argv[1], "interest") == 0) {
/* ignore interest commands, as they would not work properly */
iRet = 1;
@ -666,7 +689,8 @@ int RemobAction(SConnection * pCon, SicsInterp * pSics, void *pData,
cmd = Arg2Tcl0(argc - 1, argv + 1, buf, sizeof buf, remob->name);
if (cmd) {
RemTransact(remserver, nChan, pCon, cmd, ">", NULL);
/* filter out time stamps !=== */
RemTransact(remserver, nChan, pCon, cmd, "!===", ">", NULL);
if (cmd != buf)
free(cmd);
}

View File

@ -51,7 +51,8 @@ double DoubleTime(void)
{
struct timeval now;
/* the resolution of this function is usec, if the machine supports this
and the mantissa of a double is 51 bits or more (31 for sec and 20 for mic$
and the mantissa of a double is 51 bits or more (31 bits for seconds
and 20 for microseconds)
*/
gettimeofday(&now, NULL);
return now.tv_sec + now.tv_usec / 1e6;