- 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);
|
||||
|
Reference in New Issue
Block a user