From 69af09fe543e3fc922d37e4e3d197ff1547d7172 Mon Sep 17 00:00:00 2001 From: zolliker Date: Wed, 25 Feb 2009 14:50:47 +0000 Subject: [PATCH] - fixed errors occured after intendation command in fsm mechanism --- amilevel.c | 2 ++ ease.c | 11 +++++++++++ ease.h | 1 + euro2kdriv.c | 3 +++ fsm.c | 24 ++++++++++++------------ fsm.h | 6 +++--- haakedriv.c | 3 +++ ighdriv.c | 3 +++ ilmdriv.c | 2 ++ ipsdriv.c | 1 + itcdriv.c | 6 ++++++ linadriv.c | 3 +++ lsc370driv.c | 5 +++++ sinqhttpprot.c | 16 ++++++++-------- 14 files changed, 63 insertions(+), 23 deletions(-) diff --git a/amilevel.c b/amilevel.c index 0cd8768..fee05f3 100644 --- a/amilevel.c +++ b/amilevel.c @@ -65,6 +65,7 @@ static long AmiRead(long pc, void *object) switch (pc) { default: /* FSM BEGIN ****************************** */ + EasePchk(drv); EaseWrite(eab, "level"); return __LINE__; case __LINE__: /**********************************/ @@ -82,6 +83,7 @@ static long AmiStart(long pc, void *object) switch (pc) { default: /* FSM BEGIN ****************************** */ + EasePchk(drv); EaseWrite(eab, "cm"); return __LINE__; case __LINE__: /**********************************/ diff --git a/ease.c b/ease.c index db7fdad..8af3132 100644 --- a/ease.c +++ b/ease.c @@ -177,6 +177,15 @@ void EaseParHasChanged(void) parameterChange = 1; } +/*----------------------------------------------------------------------------*/ +void EasePchk(void *drv) +{ + int pc = FsmPc(); + if (pc > 0) { + ParPrintf(drv, eError, "ERROR: illegal line in fsm %d", pc); + } +} + /*----------------------------------------------------------------------------*/ void EaseSavePars(void) { @@ -313,6 +322,7 @@ static long EaseSendIt(long pc, void *object) switch (pc) { default: /* FSM BEGIN ****************************** */ + EasePchk(eab); EaseWrite(eab, eab->sendCmd); ParPrintf(eab, eWarning, "send cmd> %s", eab->sendCmd); eab->sendCmd = NULL; @@ -354,6 +364,7 @@ static long EaseIdle(long pc, void *object) switch (pc) { default: /* FSM BEGIN ****************************** */ + EasePchk(eab); idle: if (!EaseCheckDoit(eab)) diff --git a/ease.h b/ease.h index 695398e..b6d4c54 100644 --- a/ease.h +++ b/ease.h @@ -87,6 +87,7 @@ void EaseSendPar(void *object); void EaseMsgPar(void *object); void EaseKillDriv(EaseDriv * ead); void EaseDrivPar(void *object, char *fmt, char *unit); +void EasePchk(void *drv); void EaseParHasChanged(void); void EaseStop(EaseBase * eab); int EaseCheckDoit(EaseBase * eab); diff --git a/euro2kdriv.c b/euro2kdriv.c index 3f3741b..1995c71 100644 --- a/euro2kdriv.c +++ b/euro2kdriv.c @@ -366,6 +366,7 @@ static long Euro2kRead(long pc, void *object) switch (pc) { default: /* FSM BEGIN ****************************** */ + EasePchk(drv); if (drv->script && drv->script[0] != '\0' && 0 != strcmp(drv->script, "0")) { pTcl = InterpGetTcl(pServ->pSics); @@ -479,6 +480,7 @@ static long Euro2kSet(long pc, void *object) switch (pc) { default: /* FSM BEGIN ****************************** */ + EasePchk(drv); loop: upd = EaseNextUpdate(drv); if (upd == EASE_RUN) { @@ -548,6 +550,7 @@ static long Euro2kStart(long pc, void *object) switch (pc) { default: /* FSM BEGIN ****************************** */ + EasePchk(drv); ModBusRequestValue(eab, 122, modBusInt); return __LINE__; case __LINE__: /**********************************/ diff --git a/fsm.c b/fsm.c index a68a283..5f21420 100644 --- a/fsm.c +++ b/fsm.c @@ -49,6 +49,13 @@ void FsmSpeed(Fsm * task) task->till = time(NULL); } +long FsmPc(void) { + if (fsm) { + return fsm->pc; + } + return -1; +} + int FsmTaskHandler(Fsm * task) { long line; @@ -74,6 +81,8 @@ int FsmTaskHandler(Fsm * task) } fsm = task; task->pc = task->func(task->pc, task->obj); + if (task->pc > 0) + task->pc++; /* go to next line (case must be one line after return) */ while (callFunc) { assert(fsm->sp < MAXSTACK); fsm->stack[fsm->sp].pc = task->pc; @@ -83,11 +92,14 @@ int FsmTaskHandler(Fsm * task) fsm->func = callFunc; callFunc = NULL; task->pc = fsm->func(fsm->pc, fsm->obj); + if (task->pc > 0) + task->pc++; /* go to next line (case must be one line after return) */ } fsm = NULL; } StatisticsEnd(old); if (task->pc <= 0) { + task->pc = 0; if (task->sp == 0) { return (task->obj != NULL); /* finish task only when explicitely stopped */ } @@ -165,18 +177,6 @@ void FsmPause(Fsm * task, int pause) task->pause = pause; } -long FsmCallOld(long pc, FsmFunc func) -{ - assert(fsm); - assert(fsm->sp < MAXSTACK); - fsm->stack[fsm->sp].pc = pc; - fsm->stack[fsm->sp].func = fsm->func; - fsm->sp++; - fsm->func = func; - fsm->pc = 0; - return fsm->func(fsm->pc, fsm->obj); -} - void FsmCall(FsmFunc func) { assert(fsm); diff --git a/fsm.h b/fsm.h index 47e2249..81bd63e 100644 --- a/fsm.h +++ b/fsm.h @@ -51,6 +51,9 @@ Fsm *FsmStartTask(void *obj, FsmHandler handler, FsmFunc func, char *name); void FsmRestartTask(Fsm * task, FsmFunc func); /* restart a stopped task */ +long FsmPc(void); +/* check current pc (used in EasePchk called in first step in fsm functions) */ + int FsmTaskHandler(Fsm * task); /* this is the task handler. the argument should be the pointer obtained from FsmStartTask @@ -68,9 +71,6 @@ void FsmKill(void *task); void FsmPause(Fsm * task, int pause); /* pause=1: pause task, pause=0: continue task */ -long FsmCallOld(long pc, FsmFunc func); -/* these functions are used in fsm macros and must not be called directly */ - void FsmCall(FsmFunc func); void FsmWait(long delay); diff --git a/haakedriv.c b/haakedriv.c index 38bcbce..4ce231e 100644 --- a/haakedriv.c +++ b/haakedriv.c @@ -224,6 +224,7 @@ static long HaakeRead(long pc, void *object) switch (pc) { default: /* FSM BEGIN ****************************** */ + EasePchk(drv); EaseWrite(eab, "B"); return __LINE__; case __LINE__: /**********************************/ @@ -276,6 +277,7 @@ static long HaakeStart(long pc, void *object) switch (pc) { default: /* FSM BEGIN ****************************** */ + EasePchk(drv); EaseWrite(eab, "V"); return __LINE__; case __LINE__: /**********************************/ @@ -319,6 +321,7 @@ static long HaakeSet(long pc, void *object) switch (pc) { default: /* FSM BEGIN ****************************** */ + EasePchk(drv); upd = EaseNextUpdate(drv); switch (upd) { case EASE_RUN: diff --git a/ighdriv.c b/ighdriv.c index 48e7d5c..13b5bde 100644 --- a/ighdriv.c +++ b/ighdriv.c @@ -344,6 +344,7 @@ static long IghRead(long pc, void *object) switch (pc) { default: /* FSM BEGIN ****************************** */ + EasePchk(drv); EaseWrite(eab, "X"); return __LINE__; case __LINE__: /**********************************/ @@ -563,6 +564,7 @@ static long IghStart(long pc, void *object) switch (pc) { default: /* FSM BEGIN ****************************** */ + EasePchk(drv); EaseWrite(eab, "V"); return __LINE__; case __LINE__: /**********************************/ @@ -601,6 +603,7 @@ static long IghSet(long pc, void *object) switch (pc) { default: /* FSM BEGIN ****************************** */ + EasePchk(drv); EaseWrite(eab, "C3"); drv->remote = 2; loop: diff --git a/ilmdriv.c b/ilmdriv.c index d5a732e..36868df 100644 --- a/ilmdriv.c +++ b/ilmdriv.c @@ -130,6 +130,7 @@ static long IlmRead(long pc, void *object) switch (pc) { default: /* FSM BEGIN ****************************** */ + EasePchk(drv); EaseWrite(eab, "X"); return __LINE__; case __LINE__: /**********************************/ @@ -195,6 +196,7 @@ static long IlmStart(long pc, void *object) switch (pc) { default: /* FSM BEGIN ****************************** */ + EasePchk(drv); EaseWrite(eab, "V"); return __LINE__; case __LINE__: /**********************************/ diff --git a/ipsdriv.c b/ipsdriv.c index b818c7c..d7ae7a0 100644 --- a/ipsdriv.c +++ b/ipsdriv.c @@ -301,6 +301,7 @@ static long IpsRead(long pc, void *object) switch (pc) { default: /* FSM BEGIN ****************************** */ + EasePchk(drv); EaseWrite(eab, "X"); return __LINE__; case __LINE__: /**********************************/ diff --git a/itcdriv.c b/itcdriv.c index 9275d34..ea3173b 100644 --- a/itcdriv.c +++ b/itcdriv.c @@ -464,6 +464,7 @@ static long ItcRead(long pc, void *object) switch (pc) { default: /* FSM BEGIN ****************************** */ + EasePchk(drv); EaseWrite(eab, "X"); return __LINE__; case __LINE__: /**********************************/ @@ -733,6 +734,7 @@ static long ItcStart(long pc, void *object) switch (pc) { default: /* FSM BEGIN ****************************** */ + EasePchk(drv); EaseWrite(eab, "V"); return __LINE__; case __LINE__: /**********************************/ @@ -782,6 +784,7 @@ static long ItcSetTemp(long pc, void *object) switch (pc) { default: /* FSM BEGIN ****************************** */ + EasePchk(drv); if (drv->controlChan == 0) { ParPrintf(drv, eError, "no control channel selected"); goto quit; @@ -849,6 +852,7 @@ static long ItcSetGas(long pc, void *object) switch (pc) { default: /* FSM BEGIN ****************************** */ + EasePchk(drv); if (drv->gasMode != 1 && drv->gasMode != 2) { ParPrintf(drv, eError, "gasMode must be set to manual or auto"); goto quit; @@ -892,6 +896,7 @@ static long ItcSetHtr(long pc, void *object) switch (pc) { default: /* FSM BEGIN ****************************** */ + EasePchk(drv); if (drv->a == 0) goto skipmode; EaseWrite(eab, "A0"); @@ -921,6 +926,7 @@ static long ItcSet(long pc, void *object) switch (pc) { default: /* FSM BEGIN ****************************** */ + EasePchk(drv); EaseWrite(eab, "C3"); loop: return __LINE__; diff --git a/linadriv.c b/linadriv.c index 275e1d0..9fd0b0d 100644 --- a/linadriv.c +++ b/linadriv.c @@ -137,6 +137,7 @@ static long LinaRead(long pc, void *object) switch (pc) { default: /* FSM BEGIN ****************************** */ + EasePchk(drv); EaseWrite(eab, "XY."); return __LINE__; case __LINE__: /**********************************/ @@ -160,6 +161,7 @@ static long LinaStart(long pc, void *object) switch (pc) { default: /* FSM BEGIN ****************************** */ + EasePchk(drv); EaseWrite(eab, "ID"); return __LINE__; case __LINE__: /**********************************/ @@ -190,6 +192,7 @@ static long LinaSet(long pc, void *object) switch (pc) { default: /* FSM BEGIN ****************************** */ + EasePchk(drv); /* snprintf(cmd, sizeof cmd, "SETP %.5g;SETP?", drv->d.targetValue); EaseWrite(eab, cmd); diff --git a/lsc370driv.c b/lsc370driv.c index 9c943f0..b64b301 100644 --- a/lsc370driv.c +++ b/lsc370driv.c @@ -284,6 +284,9 @@ static long Lsc370Read(long pc, void *object) switch (pc) { default: /* FSM BEGIN ****************************** */ + if (pc != 0) { + return -2; + } drv->index = 0; chanLoop: if (drv->channel[drv->index] == 0) { @@ -393,6 +396,7 @@ static long Lsc370Start(long pc, void *object) switch (pc) { default: /* FSM BEGIN ****************************** */ + EasePchk(drv); EaseWrite(eab, "*IDN?"); return __LINE__; case __LINE__: /**********************************/ @@ -423,6 +427,7 @@ static long Lsc370Set(long pc, void *object) switch (pc) { default: /* FSM BEGIN ****************************** */ + EasePchk(drv); EaseWrite(eab, "MODE 1;MODE?"); /* remote mode */ return __LINE__; case __LINE__: /**********************************/ diff --git a/sinqhttpprot.c b/sinqhttpprot.c index c68a1a1..8f29080 100644 --- a/sinqhttpprot.c +++ b/sinqhttpprot.c @@ -31,7 +31,7 @@ static int configRequest(Ascon * a) request = CreateDynString(64, 64); if (request == NULL) { - AsconError(a, "Out of memory", 122); + AsconError(a, "Out of memory", 0); return 0; } DynStringConcat(request, "http://"); @@ -44,7 +44,7 @@ static int configRequest(Ascon * a) ghttp_set_type(pHttp->request, ghttp_type_get); ghttp_set_header(pHttp->request, "connection", "keep-alive"); if (ghttp_set_uri(pHttp->request, uri) < 0) { - AsconError(a, "Bad URL", a->state); + AsconError(a, "Bad URL", 0); return 0; } if (pHttp->userName != NULL && pHttp->password != NULL) { @@ -68,11 +68,11 @@ static void handleReply(Ascon * a) pPtr = ghttp_get_body(pHttp->request); len = ghttp_get_body_len(pHttp->request); if (strstr(pPtr, "ERROR") != NULL) { - AsconError(a, pPtr, a->state); + AsconError(a, pPtr, 0); DynStringConcat(a->rdBuffer, pPtr); } else if (strstr(pPtr, "Authentication Error") != NULL) { DynStringConcat(a->rdBuffer, pPtr); - AsconError(a, pPtr, a->state); + AsconError(a, pPtr, 0); } else { pType = (char *) ghttp_get_header(pHttp->request, "Content-Type"); if (strstr(pType, "sinqhm") == NULL) { @@ -126,7 +126,7 @@ static int HttpHandler(Ascon * a) status = ghttp_process(pHttp->request); } if (status == ghttp_error) { - AsconError(a, "Server error", 123); + AsconError(a, "Server error", 0); DynStringConcat(a->rdBuffer, "Server error"); a->state = AsconReadDone; } else { @@ -149,7 +149,7 @@ static int HttpHandler(Ascon * a) a->state = AsconReading; } else { if (DoubleTime() > a->start + a->timeout) { - AsconError(a, " read timeout", 0); + AsconError(a, "read timeout", 0); a->state = AsconTimeout; /* this to clear the line */ ghttp_close(pHttp->request); @@ -169,7 +169,7 @@ static int HttpHandler(Ascon * a) switch (status) { case ghttp_not_done: if (DoubleTime() > a->start + a->timeout) { - AsconError(a, " read timeout", 0); + AsconError(a, "read timeout", 0); a->state = AsconTimeout; /* this to clear the line */ ghttp_close(pHttp->request); @@ -188,7 +188,7 @@ static int HttpHandler(Ascon * a) configRequest(a); status = ghttp_process(pHttp->request); if (status == ghttp_error) { - AsconError(a, "Server error", a->state); + AsconError(a, "Server error", 0); DynStringConcat(a->rdBuffer, "Server error"); a->state = AsconReadDone; }