From: ian Date: Sun, 20 Jan 2008 18:31:55 +0000 (+0000) Subject: suppress noisy messages X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=60d8cb71f65049166202346796358b974fa259d1;p=trains.git suppress noisy messages --- diff --git a/hostside/.cvsignore b/hostside/.cvsignore index 82443ed..1962df4 100644 --- a/hostside/.cvsignore +++ b/hostside/.cvsignore @@ -10,6 +10,7 @@ auproto-* gui-plan-bot selectors.h errorcodes.h +stastate.h retransmit-table.h record-l.[ch] record-y.[ch] diff --git a/hostside/Makefile b/hostside/Makefile index 0c0bc2d..589bffa 100644 --- a/hostside/Makefile +++ b/hostside/Makefile @@ -1,7 +1,7 @@ # AUTOINCS= auproto-pic.h layoutinfo.h selectors.h retransmit-table.h \ - errorcodes.h + errorcodes.h stastate.h TARGETS= hostside-old gui-plan-bot realtime include ../common.make @@ -50,7 +50,7 @@ auproto-pic.c auproto-pic.h: auproto-%: \ layoutinfo.h: ../layout/ours.layout-data.c Makefile sed -e '/^#include/,$$d' $< $o -selectors.h retransmit-table.h errorcodes.h: %: %.gen +selectors.h retransmit-table.h errorcodes.h stastate.h: %: %.gen (echo "/*autogenerated*/" && ./$<) $o safety: safety.o utils.o trackloc.o ../layout/ours.layout-data.o diff --git a/hostside/parse-proto-spec b/hostside/parse-proto-spec index 5564ca2..c35319e 100755 --- a/hostside/parse-proto-spec +++ b/hostside/parse-proto-spec @@ -92,6 +92,11 @@ sub process_line () { $v{yn}= $yval; $v{dname}= $dname; $v{cname}= $cname; + $v{noiselevel}= + ($cname =~ m/nmradone/ ? 3 : + $cname =~ m/p[io]ng/ ? 2 : + $cname =~ m/detect/ ? 1 : + 0); $v{cnameyn}= $cname.$yval; $v{cnameynu}= uc($cname.$yval); $v{opcode}= b2xh($opcode, 0); diff --git a/hostside/realtime.c b/hostside/realtime.c index 509ff1b..9972240 100644 --- a/hostside/realtime.c +++ b/hostside/realtime.c @@ -9,6 +9,7 @@ const char *progname= "realtime"; /*---------- global variables ----------*/ CommandInput cmdi; +int picio_send_noise= 1; static const char *device= "/dev/ttya0"; @@ -290,7 +291,7 @@ static void *serial_readable(oop_source *evts, int fd, void serial_transmit(const PicInsn *pi) { const PicInsnInfo *pii; - int objnum; + int objnum, suppress=0; if ((pi->d[0] & 0xf8) == 0x90) { SegmentNum segn; @@ -308,16 +309,22 @@ void serial_transmit(const PicInsn *pi) { } oprintf(UPO,">\n"); } else if (pi->d[0] == 0xff) { - oprint_nmradata(pi); + if (picio_send_noise < 3) + suppress= 1; + else + oprint_nmradata(pi); } else { picinsn_decode(pi, pic_command_infos, &pii, &objnum); if (!pii) oprintf(UPO, "picio out unknown\n"); + else if (pii->noiselevel > picio_send_noise) + suppress= 1; else oupicio("out",pii,objnum); } - ouhex("picioh out", pi->d, pi->l); + if (!suppress) + ouhex("picioh out", pi->d, pi->l); /* note that the serial port is still in nonblocking mode. if * we ever buffer up far enough that the kernel wants to make us diff --git a/hostside/realtime.h b/hostside/realtime.h index 541a5ef..94413e8 100644 --- a/hostside/realtime.h +++ b/hostside/realtime.h @@ -69,25 +69,19 @@ void retransmit_urgent_cancel(RetransmitUrgentNode *rn); /*---------- global variables, in realtime.c ----------*/ extern CommandInput cmdi; +extern int picio_send_noise; #define UPO (&(cmdi.out)) /*---------- from/for startup.c ----------*/ -typedef enum { /* sta_toev ping_toev */ - Sta_Flush, /* R 300 I ? */ - Sta_Off, /* I ? I ? */ - Sta_Ping, /* I ? I ? */ - Sta_Fault, /* I ? R set */ - Sta_Settling, /* I ? R set */ - Sta_Resolving, /* I ? R set */ - Sta_Run /* I ? R set */ -} StartupState; +#include "stastate.h" void sta_startup(void); void serial_moredata(PicInsn *buf); extern StartupState sta_state; +extern const char *const stastatelist[]; /*---------- from/for record.c ----------*/ diff --git a/hostside/skelproto-pic.c b/hostside/skelproto-pic.c index 31895b2..92c847d 100644 --- a/hostside/skelproto-pic.c +++ b/hostside/skelproto-pic.c @@ -68,11 +68,11 @@ void picinsn_decode(const PicInsn *pi, const PicInsnInfo *table, } const PicInsnInfo pic_command_infos[]= { - { "@cnameyn@", @opcodeyn@, @opcodemaskyn@, @arglen@, 0 }, @h2p@ + { "@cnameyn@", @opcodeyn@, @opcodemaskyn@, @arglen@, @noiselevel@, 0 }, @h2p@ { 0 } }; const PicInsnInfo pic_reply_infos[]= { - { "@cnameyn@", @opcodeyn@, @opcodemaskyn@, @arglen@, on_pic_@cnameyn@ },@p2h@ + { "@cnameyn@", @opcodeyn@, @opcodemaskyn@, @arglen@, @noiselevel@, on_pic_@cnameyn@ },@p2h@ { 0 } }; diff --git a/hostside/skelproto-pic.h b/hostside/skelproto-pic.h index d30cad1..ee63e64 100644 --- a/hostside/skelproto-pic.h +++ b/hostside/skelproto-pic.h @@ -34,7 +34,7 @@ void oopicio(const char *dirn, const PicInsnInfo *pii, int objnum); struct PicInsnInfo { const char *name; Byte opcode, mask; - int argbits; + int argbits, noiselevel; PicInputFn *input_fn; }; diff --git a/hostside/startup.c b/hostside/startup.c index 7efdc1a..458cb8e 100644 --- a/hostside/startup.c +++ b/hostside/startup.c @@ -5,6 +5,7 @@ #include "realtime.h" +const char *const stastatelist[]= DEFINE_STASTATE_DATA; StartupState sta_state; static TimeoutEvent sta_toev; @@ -86,13 +87,13 @@ static void sta_goto(StartupState new_state) { sta_state= new_state; /* notify various people: */ - oprintf(UPO, "stastate %d\n", sta_state); + oprintf(UPO, "stastate %s\n", stastatelist[sta_state]); /* ... add others here. */ } void serial_moredata(PicInsn *buf) { const PicInsnInfo *pii; - int objnum; + int objnum, suppress; Byte *ep; /* Called when more data is received from PICs. @@ -144,10 +145,13 @@ void serial_moredata(PicInsn *buf) { found_end: /* Aha! */ buf->l= ep - buf->d + 1; - ouhex("picioh in msg", buf->d, buf->l); picinsn_decode(buf, pic_reply_infos, &pii, &objnum); + suppress= pii && pii->noiselevel > picio_send_noise; + if (!suppress) + ouhex("picioh in msg", buf->d, buf->l); if (!pii) { oprintf(UPO, "picio in unknown\n"); return; } - oupicio("in",pii,objnum); + if (!suppress) + oupicio("in",pii,objnum); pii->input_fn(pii,buf,objnum); } diff --git a/hostside/stastate.h.gen b/hostside/stastate.h.gen new file mode 100755 index 0000000..faa07fb --- /dev/null +++ b/hostside/stastate.h.gen @@ -0,0 +1,21 @@ +#!/bin/sh + +set -e +Sta () { l="$l $1"; } + + # sta_toev ping_toev + Sta Flush # R 300 I ? + Sta Off # I ? I ? + Sta Ping # I ? I ? + Sta Fault # I ? R set + Sta Settling # I ? R set + Sta Resolving # I ? R set + Sta Run # I ? R set + +echo 'typedef enum {' +for s in $l; do echo " Sta_$s,"; done +echo '} StartupState; +#define DEFINE_STASTATE_DATA \' +printf ' { ' +for s in $l; do printf '"%s",' $s; done +echo '0 }'