From: ian Date: Sat, 24 May 2008 11:28:16 +0000 (+0000) Subject: optimise away identical flickering detections X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=a4283887047737db8f331dd79172987c9b52ea90;p=trains.git optimise away identical flickering detections --- diff --git a/hostside/README.commands b/hostside/README.commands index 4ca65b7..9ffb95a 100644 --- a/hostside/README.commands +++ b/hostside/README.commands @@ -71,9 +71,11 @@ POSSIBLY-ASYNCHRONOUS REPORTING OF MESSAGES TO/FROM (MASTER) PIC MESSAGES TO SIMULATION LOG L picioh in suppressed [...] + L picioh in suppressed-detect [...] L command-in .... L timestamp . L timer-event . + L 0|1 detection, same segment as last suppressed-detect ====================================================================== diff --git a/hostside/simulate.c b/hostside/simulate.c index 2f42e32..0f5f9b5 100644 --- a/hostside/simulate.c +++ b/hostside/simulate.c @@ -16,7 +16,7 @@ int simlog_full; const char *simulate; static SimEventFn se_timestamp, se_timerevent; -static SimEventFn se_serial, se_command, se_eof; +static SimEventFn se_serial, se_samedet, se_command, se_eof; static SimTimeout *simtimeouts; @@ -25,16 +25,22 @@ static FILE *siminput; static char *sevent_buf; static size_t sevent_buflen; static int sevent_lno; +static Byte sevent_lastdet[2]; static SimEventFn *sevent_type; static char *sevent_data; static struct timeval sevent_abst; +#define PICMSG_DETECT_01 (PICMSG_DETECT0^PICMSG_DETECT1) + /*---------- writing simulation log ----------*/ +static Byte simlog_lastdet[2]; + void simlogv(const char *fmt, va_list al) { if (simoutput==stdout) ovprintf(UPO,fmt,al); else if (simoutput) vfprintf(simoutput,fmt,al); + simlog_lastdet[0]= 0; } void simlog(const char *fmt, ...) { va_list al; @@ -49,10 +55,34 @@ void simlog_flush(void) { diee("write simulation log"); } void simlog_serial(const Byte *data, int length) { - simlog("picioh in suppressed"); + static Byte db0, db1; + int is_det; + + if (!length) return; + + db0= data[0] & ~PICMSG_DETECT_01; + + /* optimise consecutive dithering detects into just 0 and 1 msgs */ + is_det= PICMSG_DETECT0_P(db0) && length==2 && !((db1=data[1]) & 0x80); + if (is_det) { + if (db0==simlog_lastdet[0] && data[1]==simlog_lastdet[1]) { + simlog("%d\n",!!(data[0] & PICMSG_DETECT_01)); + goto set_lastdet; + } + simlog("picioh in suppressed-detect"); + } else { + simlog("picioh in suppressed"); + } + while (length--) simlog(" %02x",*data++); simlog("\n"); simlog_flush(); + + set_lastdet: + if (is_det) { + simlog_lastdet[0]= db0; + simlog_lastdet[1]= db1; + } } void simlog_open(const char *fn) { if (!fn) fn= "+realtime.log"; @@ -89,6 +119,12 @@ static void sevent(void) { assert(sevent_buf[gr-1]=='\n'); sevent_buf[gr-1]= 0; + if ((sevent_buf[0] & ~1)=='0' && !sevent_buf[1]) { + sevent_type= se_samedet; + sevent_data= &sevent_buf[0]; + return; + } + #define IF_ET(pfx, et) \ if (!strncmp(pfx " ", sevent_buf, sizeof(pfx)) \ && (sevent_type=(et), p=sevent_buf+(sizeof(pfx)))) @@ -190,6 +226,26 @@ static void se_serial(void) { serial_buf.d[buf_used++]= strtoul(c,&ep,16); if (*ep) simbad("bad hex"); } + if (buf_used>=2) { + Byte db0= serial_buf.d[buf_used-2] & ~PICMSG_DETECT_01; + if (PICMSG_DETECT0_P(db0)) { + sevent_lastdet[0]= db0; + sevent_lastdet[1]= serial_buf.d[buf_used-1]; + } + } + serial_indata_process(buf_used); +} + +static void se_samedet(void) { + int buf_used; + + buf_used= serial_buf.l; + if (buf_used >= sizeof(serial_buf.d)-1) simbad("samedet serial_buf overrun"); + if (!sevent_lastdet[0]) simbad("samedet but no previous det"); + if (sevent_lastdet[1] & 0x80) simbad("samedet but bad previous det"); + serial_buf.d[buf_used++]= sevent_lastdet[0] | + (sevent_data[0]=='1' ? PICMSG_DETECT_01 : 0); + serial_buf.d[buf_used++]= sevent_lastdet[1]; serial_indata_process(buf_used); }