- various enhancements
This commit is contained in:
33
ease.c
33
ease.c
@ -89,6 +89,7 @@ void EaseWriteError(EaseBase *eab) {
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void EaseWrite(EaseBase *eab, char *cmd) {
|
||||
/* cmd==NULL: repeat the same command */
|
||||
int iRet;
|
||||
char trash[64];
|
||||
int l;
|
||||
@ -100,7 +101,9 @@ void EaseWrite(EaseBase *eab, char *cmd) {
|
||||
if (iRet < 0) break;
|
||||
ParPrintf(eab, -2, "trash: %s\n", trash);
|
||||
}
|
||||
snprintf(eab->cmd, sizeof(eab->cmd), "%s%s", cmd, eab->ser->sendTerminator);
|
||||
if (cmd) {
|
||||
snprintf(eab->cmd, sizeof(eab->cmd), "%s%s", cmd, eab->ser->sendTerminator);
|
||||
}
|
||||
iRet = writeRS232(eab->ser, eab->cmd, strlen(eab->cmd));
|
||||
if (iRet < 0) {
|
||||
FsmStop(eab->task, eab->idle);
|
||||
@ -112,25 +115,36 @@ void EaseWrite(EaseBase *eab, char *cmd) {
|
||||
eab->errCode = iRet;
|
||||
return;
|
||||
}
|
||||
ParPrintf(eab, -2, "cmd: %s", cmd);
|
||||
if (cmd) {
|
||||
ParPrintf(eab, -2, "cmd: %s", cmd);
|
||||
} else {
|
||||
ParPrintf(eab, -2, "cmd: %s", eab->cmd);
|
||||
}
|
||||
eab->state = EASE_expect;
|
||||
eab->cmdtime = time(NULL);
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int EaseWaitRead(EaseBase *eab) {
|
||||
int cnt=0;
|
||||
time_t start;
|
||||
|
||||
if (eab->state < EASE_idle) {
|
||||
return NOTCONNECTED;
|
||||
}
|
||||
FsmPause(eab->task, 1);
|
||||
time(&start);
|
||||
while (eab->state == EASE_expect) {
|
||||
/* TaskYield(pServ->pTasker); does not work (pardef is not recursive) */
|
||||
FsmTaskHandler(eab->task);
|
||||
cnt++;
|
||||
if (time(NULL) > start+5) {
|
||||
eab->ans[0]='\0';
|
||||
eab->state = EASE_read;
|
||||
return TIMEOUT;
|
||||
}
|
||||
}
|
||||
FsmPause(eab->task, 0);
|
||||
/* if (cnt>1) printf("TaskYield %d\n", cnt); */
|
||||
/* if (cnt>1) ParPrintf(eab, eError, "TaskYield %d\n", cnt); */
|
||||
return 1;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@ -408,8 +422,9 @@ void EaseSetUpdate(void *object, int flag, int state) {
|
||||
static long EaseRun(void *obj, SConnection *pCon, float fVal) {
|
||||
EaseBase *eab = EaseBaseCast(obj);
|
||||
EaseDriv *ead = EaseDrivCast(obj);
|
||||
|
||||
assert(ead );
|
||||
int canc;
|
||||
|
||||
assert(ead);
|
||||
|
||||
ParSaveConn(eab, pCon);
|
||||
if (! eab->doit) {
|
||||
@ -421,7 +436,10 @@ static long EaseRun(void *obj, SConnection *pCon, float fVal) {
|
||||
return 0;
|
||||
}
|
||||
if (FsmStop(eab->task, eab->doit)) {
|
||||
canc = 1;
|
||||
ParPrintf(ead, eWarning, "running %s cancelled", eab->p.name);
|
||||
} else {
|
||||
canc = 0;
|
||||
}
|
||||
if (eab->todo) {
|
||||
ParPrintf(ead, eError, "ERROR: %s busy", eab->p.name);
|
||||
@ -442,6 +460,9 @@ static long EaseRun(void *obj, SConnection *pCon, float fVal) {
|
||||
ead->finish = 0;
|
||||
ead->usedSettle = 0;
|
||||
ead->tolState = EASE_outOfTolerance;
|
||||
if (canc) {
|
||||
ParPrintf(ead, eWarning, "rerun %s", eab->p.name);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@ -633,7 +654,7 @@ static int EaseInit(SConnection *pCon, EaseBase *eab, int argc, char *argv[],
|
||||
|
||||
eab->task = NULL;
|
||||
if (EaseRestart(eab) < 0) return -1;
|
||||
eab->task = FsmStartTask(eab, eab->handler, eab->idle);
|
||||
eab->task = FsmStartTask(eab, eab->handler, eab->idle, eab->p.name);
|
||||
|
||||
TaskRegister(pServ->pTasker, (TaskFunc)FsmTaskHandler, NULL, FsmKill,
|
||||
eab->task, 0);
|
||||
|
13
fsm.c
13
fsm.c
@ -6,6 +6,7 @@ a finite state machine within sics
|
||||
M. Zolliker, Aug 2004
|
||||
---------------------------------------------------------------------------- */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <time.h>
|
||||
@ -28,12 +29,12 @@ struct Fsm {
|
||||
int pause;
|
||||
int sp;
|
||||
StackItem stack[MAXSTACK];
|
||||
Statistics *stat;
|
||||
};
|
||||
|
||||
|
||||
static Fsm *fsm = NULL;
|
||||
static FsmFunc callFunc = NULL;
|
||||
static Statistics *taskStat = NULL;
|
||||
|
||||
void FsmWait(long delay) {
|
||||
assert(fsm);
|
||||
@ -49,10 +50,7 @@ int FsmTaskHandler(Fsm *task) {
|
||||
long line;
|
||||
Statistics *old;
|
||||
|
||||
if (taskStat == NULL) {
|
||||
taskStat=StatisticsNew("<fsm>");
|
||||
}
|
||||
old = StatisticsBegin(taskStat);
|
||||
old = StatisticsBegin(task->stat);
|
||||
if (task->pause) {
|
||||
task->handler(task->obj);
|
||||
StatisticsEnd(old);
|
||||
@ -110,12 +108,15 @@ void FsmRestartTask(Fsm *task, FsmFunc func) {
|
||||
task->till = 0;
|
||||
}
|
||||
|
||||
Fsm *FsmStartTask(void *obj, FsmHandler handler, FsmFunc func) {
|
||||
Fsm *FsmStartTask(void *obj, FsmHandler handler, FsmFunc func, char *name) {
|
||||
Fsm *task;
|
||||
char fsmName[80];
|
||||
|
||||
task=malloc(sizeof *task);
|
||||
task->obj = obj;
|
||||
task->handler = handler;
|
||||
snprintf(fsmName, sizeof fsmName, "fsm %s", name);
|
||||
task->stat = StatisticsNew(fsmName);
|
||||
FsmRestartTask(task, func);
|
||||
return task;
|
||||
}
|
||||
|
@ -368,6 +368,7 @@ static long IpsChangeField(long pc, void *object) {
|
||||
ParPrintf(drv, -1, "IPS: wait %d sec to open switch", delay);
|
||||
|
||||
start_ramp:
|
||||
ParLog(drv);
|
||||
FsmWait(1);
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
EaseWrite(eab, "X");
|
||||
@ -390,6 +391,7 @@ static long IpsChangeField(long pc, void *object) {
|
||||
ParPrintf(drv, -1, "IPS: ramp to %f Tesla", drv->d.targetValue);
|
||||
|
||||
ramping:
|
||||
ParLog(drv);
|
||||
FsmWait(1);
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
EaseWrite(eab, "R7"); /* read "current" in Tesla */
|
||||
@ -413,7 +415,6 @@ static long IpsChangeField(long pc, void *object) {
|
||||
}
|
||||
OxiSet(eab, "J", fld, 3);
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
ParLog(drv);
|
||||
goto ramping;
|
||||
|
||||
target_reached:
|
||||
@ -423,6 +424,7 @@ static long IpsChangeField(long pc, void *object) {
|
||||
/* but we continue in the background */
|
||||
drv->tim = time(NULL);
|
||||
stab3:
|
||||
ParLog(drv);
|
||||
FsmWait(1);
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
EaseWrite(eab, "X");
|
||||
@ -441,6 +443,7 @@ static long IpsChangeField(long pc, void *object) {
|
||||
ParPrintf(drv, -1, "IPS: wait 30 sec to close switch");
|
||||
|
||||
wait_closed:
|
||||
ParLog(drv);
|
||||
FsmWait(1);
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
EaseWrite(eab, "R18"); /* read persistent field in Tesla */
|
||||
|
10
itcdriv.c
10
itcdriv.c
@ -502,21 +502,21 @@ static long ItcRead(long pc, void *object) {
|
||||
skiphtr:
|
||||
|
||||
if (EaseGetUpdate(drv, ITC_PROP)) goto skipprop;
|
||||
EaseWrite(eab, "R9"); /* read prop */
|
||||
EaseWrite(eab, "R8"); /* read prop */
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
if (EaseGetUpdate(drv, ITC_PROP)) goto skipprop;
|
||||
drv->prop = OxiGet(eab, 1, NULL, drv->prop);
|
||||
skipprop:
|
||||
|
||||
if (EaseGetUpdate(drv, ITC_INTEG)) goto skipint;
|
||||
EaseWrite(eab, "R10"); /* read int */
|
||||
EaseWrite(eab, "R9"); /* read int */
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
if (EaseGetUpdate(drv, ITC_INTEG)) goto skipint;
|
||||
drv->integ = OxiGet(eab, 1, NULL, drv->integ);
|
||||
skipint:
|
||||
|
||||
if (EaseGetUpdate(drv, ITC_DERIV)) goto skipderiv;
|
||||
EaseWrite(eab, "R11"); /* read deriv */
|
||||
EaseWrite(eab, "R10"); /* read deriv */
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
if (EaseGetUpdate(drv, ITC_DERIV)) goto skipderiv;
|
||||
drv->deriv = OxiGet(eab, 1, NULL, drv->deriv);
|
||||
@ -696,8 +696,8 @@ static long ItcSet(long pc, void *object) {
|
||||
}
|
||||
goto loop;
|
||||
case ITC_PROP: OxiSet(eab, "P", drv->prop, 1); goto loop;
|
||||
case ITC_INTEG: OxiSet(eab, "I", drv->prop, 1); goto loop;
|
||||
case ITC_DERIV: OxiSet(eab, "D", drv->prop, 1); goto loop;
|
||||
case ITC_INTEG: OxiSet(eab, "I", drv->integ, 1); goto loop;
|
||||
case ITC_DERIV: OxiSet(eab, "D", drv->deriv, 1); goto loop;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user