chiark / gitweb /
initial simulation tests OK
authorian <ian>
Sun, 4 May 2008 16:26:40 +0000 (16:26 +0000)
committerian <ian>
Sun, 4 May 2008 16:26:40 +0000 (16:26 +0000)
hostside/main.c
hostside/obc.c
hostside/simulate.c
hostside/x.gdb
hostside/xs.gdb [new file with mode: 0644]

index 48216d7f3bc1e28fef12e2ff546db138d6a50c25..08292ce4b009dcaa2703df801d2674b802f78b6e 100644 (file)
@@ -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 <stdio.h>
index 91d8321e4b71680ba81b70b962ada6c38b66dd67..6eafc192cb506f5856365206d45def457acb1c47 100644 (file)
@@ -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;
index 5a58601c83e7e209ed15d03faf632db5ba5a3d8c..801b06580697db9876f3465c04adf315142a22f7 100644 (file)
@@ -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<l; i++, q++) {
-    c[0]= *p++;
-    c[1]= *p++;
-    *q= strtoul(c,&ep,16);
+    serial_buf.d[buf_used++]= strtoul(c,&ep,16);
     if (*ep) simbad("bad hex");
   }
   serial_indata_process(buf_used);
@@ -175,6 +175,7 @@ void sim_run(void) {
   for (;;) {
     sevent();
     sevent_type();
+    sevent_type= 0;
     obc_tryflush(&cmdi.out);
   }
 }
index c19641208bed1c6bcd8508229b7d6239a1dc2ab4..6e0c285159ec310bb31fc14bcc3160b3edc6c8a2 100644 (file)
@@ -2,7 +2,7 @@ file ./realtime
 #set args --persist-convert-entrails <persist.data.new
 #break cmd_movfeat
 
-set args -s/dev/ttyUSB0 shinkansen.speeds.record homes.record 
+set args shinkansen.speeds.record homes.record 
 
 break vdie
 break nmra_errchk_fail
@@ -11,5 +11,5 @@ break safety_panic
 
 run
 
-# valgrind  ./realtime -s/dev/ttyUSB0 shinkansen.speeds.record homes.record
-# strace -e read=5 -e write=5 -ot ./realtime -s/dev/ttyUSB0 shinkansen.speeds.record homes.record 
+# valgrind  ./realtime shinkansen.speeds.record homes.record
+# strace -e read=5 -e write=5 -ot ./realtime shinkansen.speeds.record homes.record 
diff --git a/hostside/xs.gdb b/hostside/xs.gdb
new file mode 100644 (file)
index 0000000..db251a4
--- /dev/null
@@ -0,0 +1,7 @@
+file ./realtime
+break vdie
+break nmra_errchk_fail
+break predict_problem
+break safety_panic
+set args -S+realtime.log shinkansen.speeds.record homes.record 
+run