- various enhancements, integrate linahdl.c into linadriv.c
This commit is contained in:
63
linadriv.c
63
linadriv.c
@ -26,8 +26,8 @@ Markus Zolliker, Oct 2006
|
|||||||
#include <sicsvar.h>
|
#include <sicsvar.h>
|
||||||
#include <evdriver.i>
|
#include <evdriver.i>
|
||||||
#include <rs232controller.h>
|
#include <rs232controller.h>
|
||||||
#include "linahdl.h"
|
|
||||||
#include "fsm.h"
|
#include "fsm.h"
|
||||||
|
#include "ease.h"
|
||||||
#include "initializer.h"
|
#include "initializer.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -37,6 +37,67 @@ typedef struct {
|
|||||||
|
|
||||||
static ParClass linaClass = { "LINA", sizeof(Lina) };
|
static ParClass linaClass = { "LINA", sizeof(Lina) };
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
int LinaHandler(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)) {
|
||||||
|
eab->msg[0] = '\0';
|
||||||
|
l = sizeof(eab->ans);
|
||||||
|
iret = readRS232TillTerm(eab->ser, eab->ans, &l);
|
||||||
|
if (eab->state != EASE_expect && eab->state != EASE_lost) {
|
||||||
|
if (iret == 1) {
|
||||||
|
ParPrintf(eab, eError, "unexpected answer: %s", eab->ans);
|
||||||
|
}
|
||||||
|
goto quit;
|
||||||
|
}
|
||||||
|
if (iret == 1) {
|
||||||
|
ParPrintf(eab, -2, "ans: %s", eab->ans);
|
||||||
|
if (eab->state == EASE_lost) {
|
||||||
|
goto quit;
|
||||||
|
} else if (strncmp(eab->cmd,"ID",2) == 0) {
|
||||||
|
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 */
|
||||||
|
eab->errCode = EASE_DEV_CHANGED;
|
||||||
|
eab->state = EASE_idle;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
eab->state = EASE_idle;
|
||||||
|
goto quit;
|
||||||
|
} else {
|
||||||
|
eab->tmo = 120;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (iret != 1) {
|
||||||
|
eab->errCode = iret;
|
||||||
|
eab->state = EASE_idle;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
eab->state = EASE_read;
|
||||||
|
} else if (eab->state == EASE_expect) {
|
||||||
|
if (time(NULL) > eab->cmdtime + eab->tmo) {
|
||||||
|
eab->state = EASE_lost;
|
||||||
|
}
|
||||||
|
} else if (eab->state == EASE_lost) {
|
||||||
|
/*
|
||||||
|
if (time(NULL) > eab->cmdtime) {
|
||||||
|
EaseWrite(eab, "RS");
|
||||||
|
eab->state = EASE_lost;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
goto quit;
|
||||||
|
error:
|
||||||
|
/* EaseWriteError(eab); */
|
||||||
|
quit:
|
||||||
|
return EaseHandler(eab);
|
||||||
|
}
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
static void LinaParDef(void *object) {
|
static void LinaParDef(void *object) {
|
||||||
Lina *drv = ParCast(&linaClass, object);
|
Lina *drv = ParCast(&linaClass, object);
|
||||||
|
81
linahdl.c
81
linahdl.c
@ -1,81 +0,0 @@
|
|||||||
/*---------------------------------------------------------------------------
|
|
||||||
linahdl.c
|
|
||||||
|
|
||||||
lina (signal recovery lock in amplifier model 7265) handler
|
|
||||||
|
|
||||||
Markus Zolliker, Oct 2006
|
|
||||||
----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
there is no error return value, eab->errCode is used. On success, eab->errCode
|
|
||||||
is not changed, i.e. an existing errCode is not overwritten.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <fortify.h>
|
|
||||||
#include "sics.h"
|
|
||||||
#include "oxinst.h"
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
|
||||||
int LinaHandler(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)) {
|
|
||||||
eab->msg[0] = '\0';
|
|
||||||
l = sizeof(eab->ans);
|
|
||||||
iret = readRS232TillTerm(eab->ser, eab->ans, &l);
|
|
||||||
if (eab->state != EASE_expect && eab->state != EASE_lost) {
|
|
||||||
if (iret == 1) {
|
|
||||||
ParPrintf(eab, eError, "unexpected answer: %s", eab->ans);
|
|
||||||
}
|
|
||||||
goto quit;
|
|
||||||
}
|
|
||||||
if (iret == 1) {
|
|
||||||
ParPrintf(eab, -2, "ans: %s", eab->ans);
|
|
||||||
if (eab->state == EASE_lost) {
|
|
||||||
goto quit;
|
|
||||||
} else if (strncmp(eab->cmd,"ID",2) == 0) {
|
|
||||||
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 */
|
|
||||||
eab->errCode = EASE_DEV_CHANGED;
|
|
||||||
eab->state = EASE_idle;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
eab->state = EASE_idle;
|
|
||||||
goto quit;
|
|
||||||
} else {
|
|
||||||
eab->tmo = 120;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (iret != 1) {
|
|
||||||
eab->errCode = iret;
|
|
||||||
eab->state = EASE_idle;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
eab->state = EASE_read;
|
|
||||||
} else if (eab->state == EASE_expect) {
|
|
||||||
if (time(NULL) > eab->cmdtime + eab->tmo) {
|
|
||||||
eab->state = EASE_lost;
|
|
||||||
}
|
|
||||||
} else if (eab->state == EASE_lost) {
|
|
||||||
/*
|
|
||||||
if (time(NULL) > eab->cmdtime) {
|
|
||||||
EaseWrite(eab, "RS");
|
|
||||||
eab->state = EASE_lost;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
goto quit;
|
|
||||||
error:
|
|
||||||
/* EaseWriteError(eab); */
|
|
||||||
quit:
|
|
||||||
return EaseHandler(eab);
|
|
||||||
}
|
|
16
linahdl.h
16
linahdl.h
@ -1,16 +0,0 @@
|
|||||||
/*---------------------------------------------------------------------------
|
|
||||||
linahdl.h
|
|
||||||
|
|
||||||
lina (signal recovery lock in amplifier model 7265) handler
|
|
||||||
|
|
||||||
Markus Zolliker, Oct 2006
|
|
||||||
----------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
#ifndef LINAHDL_H
|
|
||||||
#define LINAHDL_H
|
|
||||||
|
|
||||||
#include "ease.h"
|
|
||||||
|
|
||||||
int LinaHandler(void *eab);
|
|
||||||
|
|
||||||
#endif
|
|
Reference in New Issue
Block a user