- changed OxiGet

- various bug fixes and improvements
This commit is contained in:
zolliker
2005-11-17 07:57:19 +00:00
parent 797cd1146d
commit 01fce80d95
13 changed files with 209 additions and 470 deletions

View File

@ -18,11 +18,44 @@ is not changed, i.e. an existing errCode is not overwritten.
#include "sics.h"
#include "oxinst.h"
/*----------------------------------------------------------------------------*/
char *OxiCorrect(char *str) {
/* there are sometimes communication errors with the IGH
as the errors always follow the same pattern, they can
be corrected, with the following code. The argument
is corrected in place, the result is NULL or a text
describing the conversion */
int i;
unsigned char chr;
static char buf[32];
char *result = NULL;
for (i=0; i<=24; i++, str++) {
chr = *str;
if (chr == 0) return result;
if (chr > 0x60) {
if (chr > 0xC0) {
chr -= 0x80;
} else {
chr -= 0x40;
}
snprintf(buf, sizeof buf, "%2.2x->%2.2x (%c)", *str, chr, chr);
*str = chr;
result = buf;
}
}
if (result) {
strcat(buf, " overflow");
return result;
} else {
return "overflow";
}
}
/*----------------------------------------------------------------------------*/
int OxiHandler(void *object) {
int iret, l;
EaseBase *eab = EaseBaseCast(object);
char *corr;
if (eab->state < EASE_idle) goto quit;
if (availableNetRS232(eab->ser) || availableRS232(eab->ser)) {
@ -36,6 +69,12 @@ int OxiHandler(void *object) {
goto quit;
}
if (iret == 1) {
if (eab->syntax <= -8) {
corr = OxiCorrect(eab->ans);
if (corr) {
ParPrintf(eab, eWarning, "corrected bad response from IGH: %s", corr);
}
}
ParPrintf(eab, -2, "ans: %s", eab->ans);
if (strcmp(eab->ans, "??ck") == 0) {
if (eab->state == EASE_lost) {
@ -84,13 +123,13 @@ quit:
return EaseHandler(eab);
}
double OxiGet(EaseBase *eab, int dig, int *pdig) {
double OxiGet(EaseBase *eab, int dig, int *pdig, double old) {
char *endp, *p;
double val;
if (eab->state != EASE_read) {
/* eab->errCode = EASE_ILL_ANS; */
return 0.0;
eab->errCode = EASE_ILL_ANS;
return old;
}
p = strchr(eab->ans, '.');
if (p) {
@ -100,13 +139,13 @@ double OxiGet(EaseBase *eab, int dig, int *pdig) {
val=strtod(eab->ans+1, &endp);
if (*endp != '\0') {
eab->errCode = EASE_ILL_ANS;
return 0.0;
return old;
}
} else {
val=strtol(eab->ans+1, &endp, 10);
if (*endp != '\0') {
eab->errCode = EASE_ILL_ANS;
return 0.0;
return old;
}
if (eab->syntax <= 0) { /* old style format */
for (; dig > 0; dig--) val=val*0.1;