From: ian Date: Sat, 17 May 2008 14:50:01 +0000 (+0000) Subject: support PICs change of X from PING to PONG; also leave various useless stuff out... X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=56de32b7b12cc3dc58d612bdcb8f251e70f0193c;p=trains.git support PICs change of X from PING to PONG; also leave various useless stuff out of the simulation log --- diff --git a/hostside/eventhelp.c b/hostside/eventhelp.c index 0232a69..0e907ba 100644 --- a/hostside/eventhelp.c +++ b/hostside/eventhelp.c @@ -8,16 +8,24 @@ #include "realtime.h" +const char toev_fast_pclass[]= "fast"; + void real_mgettimeofday(struct timeval *tv) { int r; r= gettimeofday(tv,0); if (r) diee("gettimeofday failed"); } +static int toev_sim_show(TimeoutEvent *toev) { + return simlog_full || toev->pclass!=toev_fast_pclass; +} + void *toev_callback(oop_source *source, struct timeval tv, void *t_v) { TimeoutEvent *toev= t_v; - simlog("timer-event %s.%s\n",toev->pclass,toev->pinst); - simlog_flush(); + if (toev_sim_show(toev)) { + simlog("timer-event %s.%s\n",toev->pclass,toev->pinst); + simlog_flush(); + } toev->running= 0; toev->callback(toev); return OOP_CONTINUE; @@ -29,7 +37,8 @@ void toev_start(TimeoutEvent *toev) { toev_stop(toev); if (toev->duration==-1) return; toev->running= 1; - mgettimeofday(&toev->abs); + if (toev_sim_show(toev)) mgettimeofday(&toev->abs); + else real_mgettimeofday(&toev->abs); assert(toev->duration < INT_MAX/1000); toev->abs.tv_usec += toev->duration * 1000; toev->abs.tv_sec += toev->abs.tv_usec / 1000000; diff --git a/hostside/realtime.c b/hostside/realtime.c index fcd02ae..f76e922 100644 --- a/hostside/realtime.c +++ b/hostside/realtime.c @@ -339,6 +339,7 @@ int main(int argc, const char **argv) { case 'p': persist_fn= arg; arg=0; break; case 'v': picio_send_noise= atoi(arg); arg=0; break; case 'm': sta_state= Sta_Manual; break; + case 'V': simlog_full=1; break; case 'L': logcopy_fn= arg; arg=0; break; case 'S': simulate= arg; arg=0; break; default: badusage("unknown option"); diff --git a/hostside/realtime.h b/hostside/realtime.h index fafa15d..fb98a72 100644 --- a/hostside/realtime.h +++ b/hostside/realtime.h @@ -158,7 +158,6 @@ void serial_transmit(const PicInsn *pi); /*---------- for/from simulate.c ----------*/ -const char *simulate; void serial_indata_process(int buf_used); void sim_initialise(const char *logduplicate); @@ -177,6 +176,9 @@ void sim_toev_start(TimeoutEvent *toev); void sim_toev_stop(TimeoutEvent *toev); void sim_mgettimeofday(struct timeval *tv); +extern int simlog_full; +extern const char *simulate; + extern PicInsn serial_buf; /*---------- from actual.c ----------*/ @@ -192,6 +194,8 @@ void motions_all_abandon(void); /*---------- from eventhelp.c ----------*/ +extern const char toev_fast_pclass[]; + typedef void TimeoutEventFn(TimeoutEvent*); struct TimeoutEvent { /* Undefined Idle Running set by */ int running; /* any 0 1 toev_ */ diff --git a/hostside/simulate.c b/hostside/simulate.c index f0b8f7e..2f42e32 100644 --- a/hostside/simulate.c +++ b/hostside/simulate.c @@ -12,6 +12,9 @@ typedef struct SimTimeout { typedef void SimEventFn(void); +int simlog_full; +const char *simulate; + static SimEventFn se_timestamp, se_timerevent; static SimEventFn se_serial, se_command, se_eof; diff --git a/hostside/startup.c b/hostside/startup.c index fb7c137..275941c 100644 --- a/hostside/startup.c +++ b/hostside/startup.c @@ -15,8 +15,8 @@ static void sta_goto(StartupState new_state); /*---------- ping ----------*/ -static int ping_seq; -static TimeoutEvent ping_toev= { .pclass="startup", .pinst="ping" }; +static int pong_seq; +static TimeoutEvent ping_toev= { .pclass=toev_fast_pclass, .pinst="ping" }; static void timedout_ping(TimeoutEvent *toev) { assert(sta_state >= Sta_Ping); @@ -24,7 +24,7 @@ static void timedout_ping(TimeoutEvent *toev) { } static void timefor_ping(TimeoutEvent *toev) { - enco_pic_ping(&piob, ping_seq); + enco_pic_ping(&piob, pong_seq ^ PING_PONG_PATTERN); serial_transmit(&piob); ping_toev.callback= timedout_ping; toev_start(&ping_toev); @@ -34,15 +34,19 @@ static void initial_ping(void) { struct timeval now; mgettimeofday(&now); - ping_seq= (now.tv_sec & 0x1fU) << 5; /* bottom 5bi of secs: period 32s */ - ping_seq |= (now.tv_usec >> 15); /* top 5bi of 20bi us: res.~2^15us */ + pong_seq= (now.tv_sec & 0x1fU) << 5; /* bottom 5bi of secs: period 32s */ + pong_seq |= (now.tv_usec >> 15); /* top 5bi of 20bi us: res.~2^15us */ ping_toev.duration= 300; timefor_ping(0); } /*---------- watchdog ----------*/ -static TimeoutEvent watchdog_toev= { .pclass="startup", .pinst="watchdog" }; +static TimeoutEvent watchdog_toev= { + .pclass=toev_fast_pclass, + .pinst="watchdog", + .duration= UNMARGIN_WATCHDOG - MARGIN_WATCHDOG, +}; static PicInsn watchdog_piob; static void watchdog_transmit(TimeoutEvent *toev) { @@ -51,7 +55,6 @@ static void watchdog_transmit(TimeoutEvent *toev) { } static void watchdog_start(void) { - watchdog_toev.duration= UNMARGIN_WATCHDOG - MARGIN_WATCHDOG; watchdog_toev.callback= watchdog_transmit; enco_pic_watchdog(&watchdog_piob, UNMARGIN_WATCHDOG_16); watchdog_transmit(0); @@ -219,7 +222,10 @@ void serial_moredata(PicInsn *buf) { if (!suppress && picio_send_noise >= 2) ouhexi("picioh in msg", buf->d, buf->l); else - simlog_serial(buf->d, buf->l); + if (simlog_full || sta_state < Sta_Settling || + !((pii->opcode==PICMSG_NMRADONE && obj==1) || + (pii->opcode==PICMSG_PONG && obj==pong_seq))) + simlog_serial(buf->d, buf->l); if (!pii) { oprintf(UPO, "picio in unknown\n"); return; } if (!suppress) @@ -240,8 +246,8 @@ void on_pic_pong(const PicInsnInfo *pii, const PicInsn *pi, int objnum) { if (sta_state == Sta_Manual) return; - if (objnum != ping_seq) - die("PIC sent wrong ping response (0x%x, wanted 0x%x)", objnum, ping_seq); + if (objnum != pong_seq) + die("PIC sent wrong ping response (0x%x, wanted 0x%x)", objnum, pong_seq); ping_toev.duration= 1000; ping_toev.callback= timefor_ping;