- Adapted indenation to new agreed upon system
- Fixed bad status in poldi zug driver
This commit is contained in:
61
oxinst.c
61
oxinst.c
@ -20,28 +20,32 @@ is not changed, i.e. an existing errCode is not overwritten.
|
||||
#include "oxinst.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
char *OxiCorrect(char *str) {
|
||||
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 */
|
||||
describing the conversion */
|
||||
int i;
|
||||
unsigned char chr;
|
||||
static char buf[32];
|
||||
char *result = NULL;
|
||||
|
||||
if (str[0] == '?') return NULL;
|
||||
for (i=0; i<=24; i++, str++) {
|
||||
|
||||
if (str[0] == '?')
|
||||
return NULL;
|
||||
for (i = 0; i <= 24; i++, str++) {
|
||||
chr = *str;
|
||||
if (chr == 0) return result;
|
||||
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)", (unsigned char)*str, chr, chr);
|
||||
snprintf(buf, sizeof buf, "%2.2x->%2.2x (%c)", (unsigned char) *str,
|
||||
chr, chr);
|
||||
*str = chr;
|
||||
result = buf;
|
||||
}
|
||||
@ -52,14 +56,17 @@ char *OxiCorrect(char *str) {
|
||||
} else {
|
||||
return "overflow";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int OxiHandler(void *object) {
|
||||
int OxiHandler(void *object)
|
||||
{
|
||||
int iret, l;
|
||||
EaseBase *eab = EaseBaseCast(object);
|
||||
char *corr;
|
||||
|
||||
if (eab->state < EASE_idle) goto quit;
|
||||
|
||||
if (eab->state < EASE_idle)
|
||||
goto quit;
|
||||
if (availableNetRS232(eab->ser) || availableRS232(eab->ser)) {
|
||||
eab->msg[0] = '\0';
|
||||
l = sizeof(eab->ans);
|
||||
@ -83,15 +90,15 @@ int OxiHandler(void *object) {
|
||||
if (strcmp(eab->ans, eab->version) == 0) {
|
||||
/* we are still connected with the same device */
|
||||
} else if (*eab->version == '\0') {
|
||||
strncat(eab->version, eab->ans, sizeof(eab->version)-1);
|
||||
} else { /* version (and therefore device) changed */
|
||||
strncat(eab->version, eab->ans, sizeof(eab->version) - 1);
|
||||
} else { /* version (and therefore device) changed */
|
||||
eab->errCode = EASE_DEV_CHANGED;
|
||||
eab->state = EASE_idle;
|
||||
goto error;
|
||||
}
|
||||
eab->state = EASE_idle;
|
||||
goto quit;
|
||||
} else if (eab->cmd[2] == 'k') { /* ?ck */
|
||||
} else if (eab->cmd[2] == 'k') { /* ?ck */
|
||||
} else {
|
||||
eab->tmo = 120;
|
||||
if (eab->syntax <= -8) {
|
||||
@ -128,10 +135,11 @@ quit:
|
||||
return EaseHandler(eab);
|
||||
}
|
||||
|
||||
double OxiGet(EaseBase *eab, int dig, int *pdig, double old) {
|
||||
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 old;
|
||||
@ -141,35 +149,38 @@ double OxiGet(EaseBase *eab, int dig, int *pdig, double old) {
|
||||
if (pdig != NULL) {
|
||||
*pdig = strlen(eab->ans) - (p - eab->ans) - 1;
|
||||
}
|
||||
val=strtod(eab->ans+1, &endp);
|
||||
val = strtod(eab->ans + 1, &endp);
|
||||
if (*endp != '\0') {
|
||||
eab->errCode = EASE_ILL_ANS;
|
||||
return old;
|
||||
}
|
||||
} else {
|
||||
val=strtol(eab->ans+1, &endp, 10);
|
||||
val = strtol(eab->ans + 1, &endp, 10);
|
||||
if (*endp != '\0') {
|
||||
eab->errCode = EASE_ILL_ANS;
|
||||
return old;
|
||||
}
|
||||
if (eab->syntax <= 0) { /* old style format */
|
||||
for (; dig > 0; dig--) val=val*0.1;
|
||||
if (eab->syntax <= 0) { /* old style format */
|
||||
for (; dig > 0; dig--)
|
||||
val = val * 0.1;
|
||||
}
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
void OxiSet(EaseBase *eab, char *cmd, double val, int dig) {
|
||||
void OxiSet(EaseBase * eab, char *cmd, double val, int dig)
|
||||
{
|
||||
char buf[64];
|
||||
double f;
|
||||
|
||||
|
||||
if (eab->syntax > 0) {
|
||||
f = fabs(val);
|
||||
if (f < 1.0) f = 1.0;
|
||||
if (f < 1.0)
|
||||
f = 1.0;
|
||||
dig = 5 - log10(f);
|
||||
if (dig < 0) dig = 0;
|
||||
if (dig < 0)
|
||||
dig = 0;
|
||||
}
|
||||
snprintf(buf, sizeof(buf), "%s%.*f", cmd, dig, val);
|
||||
EaseWrite(eab, buf);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user