From: ian Date: Sun, 4 May 2008 16:26:40 +0000 (+0000) Subject: initial simulation tests OK X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=b3f3f74bf6101a361e748f9c1e17f785fdf0ec84;p=trains.git initial simulation tests OK --- diff --git a/hostside/main.c b/hostside/main.c index 48216d7..08292ce 100644 --- a/hostside/main.c +++ b/hostside/main.c @@ -2,11 +2,6 @@ * simple test harness for now * asserts on usage errors * see README for usage info - - * usage: - * ./hostside /dev/ttySn DATA nmra - * ./hostside /dev/ttySn DATA command already encoded - raw transmit - * DATA is an even number of hex digits in a single arg */ #include diff --git a/hostside/obc.c b/hostside/obc.c index 91d8321..6eafc19 100644 --- a/hostside/obc.c +++ b/hostside/obc.c @@ -25,7 +25,8 @@ int obc_tryflush(OutBufferChain *ch) { for (;;) { ob= ch->obs.head; if (!ob) { - events->cancel_fd(events, ch->fd, OOP_WRITE); + if (events) + events->cancel_fd(events, ch->fd, OOP_WRITE); return 0; } if (ch->done_of_head == ob->l) { @@ -67,7 +68,7 @@ static void addlink(OutBufferChain *ch, OutBuffer *ob) { ch->error(ch,"write log",strerror(errno)); } } - if (!ch->obs.head) + if (!ch->obs.head && events) /* in simulation, events==0 */ events->on_fd(events, ch->fd, OOP_WRITE, writeable, ch); LIST_LINK_TAIL(ch->obs, ob); ch->total += ob->l; diff --git a/hostside/simulate.c b/hostside/simulate.c index 5a58601..801b065 100644 --- a/hostside/simulate.c +++ b/hostside/simulate.c @@ -22,7 +22,7 @@ static char *sevent_buf; static size_t sevent_buflen; static SimEventFn *sevent_type; -static char *sevent_data, *sevent_extrap; +static char *sevent_data; static struct timeval sevent_abst; /*---------- simulation input stream parser ----------*/ @@ -62,9 +62,6 @@ static void sevent(void) { return; } IF_ET("timer-event", se_timerevent) { - sevent_extrap= strchr(p,'.'); - if (!sevent_extrap) simbad("missing `.' in timer event name"); - *sevent_extrap++= 0; sevent_data= p; return; } @@ -111,14 +108,19 @@ static void se_timestamp(void) { } static void se_timerevent(void) { TimeoutEvent *toev; SimTimeout *s; + char *delim; + + delim= strchr(sevent_data,'.'); + if (!delim) simbad("missing `.' in timer event name"); + *delim= 0; for (s=simtimeouts; s; s=simtimeouts->l.next) { toev= s->toev; if (!strcmp(toev->pclass, sevent_data) && - !strcmp(toev->pinst, sevent_extrap)) + !strcmp(toev->pinst, delim+1)) goto found; } - simbad("timeout event not found"); + *delim='.'; simbad("timeout event not found"); found: sim_toev_remove(s); @@ -126,23 +128,21 @@ static void se_timerevent(void) { } static void se_serial(void) { - int l, buf_used, i; + int buf_used; char c[3], *ep; const char *p; - Byte *q; - l= strlen(sevent_data); - if (l%2) simbad("odd number of hex digits"); - l /= 2; + c[2]= 0; + for (p=sevent_data, buf_used=serial_buf.l; + ; + ) { + if (*p==' ') p++; + if (!(c[0]= *p++)) break; + if (!(c[1]= *p++)) simbad("odd number of hex digits"); - buf_used= serial_buf.l + l; - if (buf_used > sizeof(serial_buf.d)) simbad("serial_buf overrun"); + if (buf_used==sizeof(serial_buf.d)) simbad("serial_buf overrun"); - c[2]= 0; - for (i=0, p=sevent_data, q=serial_buf.d+serial_buf.l; i