- 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) { void AsconInsertProtocol(AsconProtocol *protocol) {
AsconProtocol *p;
for (p = protocols; p != NULL; p = p->next) {
if (p == protocol)
return;
}
protocol->next = protocols; protocol->next = protocols;
protocols = protocol; protocols = protocol;
} }

View File

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

View File

@ -218,9 +218,7 @@ static int LogReader(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[]) int argc, char *argv[])
{ {
/* Usage: /* Usage:
graph <start time> <end time> [ none <none value> ] np <number of points> <variable> [<variable> ...] graph <start time> <end time> [ none <none value> | text | np <number of points> ] <variable> [<variable> ...]
graph <start time> <end time> text <variable>
graph <start time> <end time> <step> <variable> [<variable> ...]
<start time> and <end time> are seconds since epoch (unix time) or, if the value <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 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 <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 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. 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). <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. 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 "text" means that the values are not numeric, in this case np is not needed
are returned. and by default infinitely high
The third variant is old style and can be replaced by the first variant, where
<number of points> = (<start time> - <end time>) / <step> + 2
Output format: Output format:
@ -308,15 +304,16 @@ Statistics *old;
to += now; to += now;
} }
iarg = 3; iarg = 3;
type0 = NUMERIC;
while (1) { while (1) {
if (iarg >= argc) if (iarg >= argc)
goto illarg; goto illarg;
if (strcasecmp(argv[iarg], "text") == 0) { /* non-numeric values */ if (strcasecmp(argv[iarg], "text") == 0) { /* non-numeric values */
iarg++; iarg++;
step = 1; step = 1;
type0 = TEXT;
np = to - from + 2; np = to - from + 2;
break; type0 = TEXT;
/* break; */
} else if (strcasecmp(argv[iarg], "none") == 0) { /* none */ } else if (strcasecmp(argv[iarg], "none") == 0) { /* none */
iarg++; iarg++;
if (iarg >= argc) if (iarg >= argc)
@ -327,7 +324,6 @@ Statistics *old;
iarg++; iarg++;
if (iarg >= argc) if (iarg >= argc)
goto illarg; goto illarg;
type0 = NUMERIC;
np = strtol(argv[iarg], &p, 0); np = strtol(argv[iarg], &p, 0);
if (p == argv[iarg]) if (p == argv[iarg])
goto illarg; goto illarg;
@ -341,14 +337,9 @@ Statistics *old;
} }
break; break;
} else { } else {
step = strtol(argv[iarg], &p, 0); np = to - from + 2;
if (p == argv[iarg]) step = 1;
goto illarg; break;
iarg++;
if (step <= 0)
step = 1;
type0 = NUMERIC;
np = (from - to) / step + 2;
} }
} }
if (step <= 0) if (step <= 0)

32
remob.c
View File

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

View File

@ -51,7 +51,8 @@ double DoubleTime(void)
{ {
struct timeval now; struct timeval now;
/* the resolution of this function is usec, if the machine supports this /* 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); gettimeofday(&now, NULL);
return now.tv_sec + now.tv_usec / 1e6; return now.tv_sec + now.tv_usec / 1e6;