- Adapted indenation to new agreed upon system

- Fixed bad status in poldi zug driver
This commit is contained in:
koennecke
2009-02-13 09:01:03 +00:00
parent 6c7bb14fad
commit eb72d5c486
151 changed files with 38234 additions and 38208 deletions

71
fsm.c
View File

@@ -36,37 +36,41 @@ struct Fsm {
static Fsm *fsm = NULL;
static FsmFunc callFunc = NULL;
void FsmWait(long delay) {
void FsmWait(long delay)
{
assert(fsm);
fsm->till = time(NULL) + delay;
}
void FsmSpeed(Fsm *task) {
void FsmSpeed(Fsm * task)
{
assert(task);
if (task->till != 0) task->till = time(NULL);
if (task->till != 0)
task->till = time(NULL);
}
int FsmTaskHandler(Fsm *task) {
int FsmTaskHandler(Fsm * task)
{
long line;
Statistics *old;
old = StatisticsBegin(task->stat);
if (task->pause) {
task->handler(task->obj);
StatisticsEnd(old);
return 1;
}
if (task->pc >= 0) { /* task->pc < 0 means stop current function */
if (task->pc >= 0) { /* task->pc < 0 means stop current function */
if (task->till != 0) {
if (time(NULL) < task->till) {
StatisticsEnd(old);
return 1; /* wait */
return 1; /* wait */
}
task->till = 0;
}
if (task->handler(task->obj) == 0) {
StatisticsEnd(old);
return 1; /* wait for answer */
return 1; /* wait for answer */
}
fsm = task;
task->pc = task->func(task->pc, task->obj);
@@ -85,7 +89,7 @@ int FsmTaskHandler(Fsm *task) {
StatisticsEnd(old);
if (task->pc <= 0) {
if (task->sp == 0) {
return (task->obj != NULL); /* finish task only when explicitely stopped */
return (task->obj != NULL); /* finish task only when explicitely stopped */
}
if (task->sp > 0) {
task->sp--;
@@ -95,12 +99,14 @@ int FsmTaskHandler(Fsm *task) {
}
return 1;
}
void FsmKill(void *data) {
void FsmKill(void *data)
{
free(data);
}
void FsmRestartTask(Fsm *task, FsmFunc func) {
void FsmRestartTask(Fsm * task, FsmFunc func)
{
task->pc = 0;
task->func = func;
task->sp = 0;
@@ -108,11 +114,12 @@ void FsmRestartTask(Fsm *task, FsmFunc func) {
task->till = 0;
}
Fsm *FsmStartTask(void *obj, FsmHandler handler, FsmFunc func, char *name) {
Fsm *FsmStartTask(void *obj, FsmHandler handler, FsmFunc func, char *name)
{
Fsm *task;
char fsmName[80];
task=malloc(sizeof *task);
task = malloc(sizeof *task);
task->obj = obj;
task->handler = handler;
snprintf(fsmName, sizeof fsmName, "fsm %s", name);
@@ -121,38 +128,45 @@ Fsm *FsmStartTask(void *obj, FsmHandler handler, FsmFunc func, char *name) {
return task;
}
int FsmStop(Fsm *task, FsmFunc func) {
int FsmStop(Fsm * task, FsmFunc func)
{
int i;
if (task == NULL) task = fsm;
if (func == NULL) return 0;
if (task == NULL)
task = fsm;
if (func == NULL)
return 0;
assert(task);
for (i=0; i < task->sp; i++) {
for (i = 0; i < task->sp; i++) {
if (func == task->stack[i].func) {
break;
}
}
if (i == task->sp) { /* not found on stack */
if (func != task->func) return 0; /* is also not running function */
if (i == task->sp) { /* not found on stack */
if (func != task->func)
return 0; /* is also not running function */
} else {
task->sp = i; /* unwind stack to level i */
task->sp = i; /* unwind stack to level i */
}
task->pc = -1; /* leave function */
task->pc = -1; /* leave function */
return 1;
}
void FsmStopTask(Fsm *task) {
void FsmStopTask(Fsm * task)
{
assert(task);
task->sp = 0;
task->pc = -1;
task->obj = NULL;
}
void FsmPause(Fsm *task, int pause) {
void FsmPause(Fsm * task, int pause)
{
task->pause = pause;
}
long FsmCallOld(long pc, FsmFunc func) {
long FsmCallOld(long pc, FsmFunc func)
{
assert(fsm);
assert(fsm->sp < MAXSTACK);
fsm->stack[fsm->sp].pc = pc;
@@ -163,7 +177,8 @@ long FsmCallOld(long pc, FsmFunc func) {
return fsm->func(fsm->pc, fsm->obj);
}
void FsmCall(FsmFunc func) {
void FsmCall(FsmFunc func)
{
assert(fsm);
callFunc = func;
}