From: ian Date: Sun, 11 May 2008 14:30:18 +0000 (+0000) Subject: handle NULs more sanely X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=e668d4656eab95ae1f53b0fbd21fc446813e1cfc;p=trains.git handle NULs more sanely --- diff --git a/cebpic/README.protocol b/cebpic/README.protocol index 79db9a5..1f59b99 100644 --- a/cebpic/README.protocol +++ b/cebpic/README.protocol @@ -71,6 +71,7 @@ From PIC to host: < 0 000 0100 (ENQ) WAGGLED Pin changed according to WAGGLE < 0 0100 PPP (20+) POINTED Point change done using capacitor P < 0 0101 PPP (28+) CHARGED Point capacitor P is now charged + < 0 00000 00 NUL Junk, prob because layout turned off < 0 00000 FF NMRADONE Have processed F NMRADATA message(s) < 0000 1010 (LF) } debugging output 0x0a (newline) and diff --git a/hostside/retransmit.c b/hostside/retransmit.c index 0a60bfd..ab35463 100644 --- a/hostside/retransmit.c +++ b/hostside/retransmit.c @@ -140,7 +140,7 @@ void retransmit_urgent_cancel(RetransmitUrgentNode *urg) { void on_pic_nmradone(const PicInsnInfo *pii, const PicInsn *pi, int objnum) { - if (!objnum) die("PIC sent NUL!"); + assert(objnum); if (sta_state == Sta_Run || sta_state == Sta_Manual) while (objnum--) retransmit_something(); diff --git a/hostside/startup.c b/hostside/startup.c index 27091a0..d933df1 100644 --- a/hostside/startup.c +++ b/hostside/startup.c @@ -47,14 +47,17 @@ oprintf(DUPO("ip") " %ld.%06ld\n", now.tv_sec, now.tv_usec); timefor_ping(0); } +static void sta_startup_manual(void) { + waggle_startup_manual(); + retransmit_start(); + oprintf(UPO, "stastate %s\n", stastatelist[sta_state]); +} + void sta_startup(void) { - if (sta_state != Sta_Manual) { - sta_goto(Sta_Flush); - } else { - waggle_startup_manual(); - retransmit_start(); - } + if (sta_state == Sta_Manual) sta_startup_manual(); + else sta_goto(Sta_Flush); } + void sta_finalising_done(void) { sta_goto(Sta_Run); } static void sta_goto(StartupState new_state) { @@ -191,6 +194,15 @@ void serial_moredata(PicInsn *buf) { pii->input_fn(pii,buf,obj); } +void on_pic_nul(const PicInsnInfo *pii, const PicInsn *pi, int objnum) { + /* layout turned off, probably */ + if (sta_state == Sta_Manual) return; + enco_pic_off(&piob); + serial_transmit(&piob); + sta_goto(Sta_Flush); + return; +} + void on_pic_pong(const PicInsnInfo *pii, const PicInsn *pi, int objnum) { if (sta_state == Sta_Manual) return;