From: ian Date: Fri, 16 May 2008 18:33:59 +0000 (+0000) Subject: fix train not on layout speed request death; hope to fix polarisation; turn off on... X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=e67710fa8e12a47ba3ef9d611288b4608604a6ad;p=trains.git fix train not on layout speed request death; hope to fix polarisation; turn off on death --- diff --git a/hostside/realtime.c b/hostside/realtime.c index 1153d1d..fcd02ae 100644 --- a/hostside/realtime.c +++ b/hostside/realtime.c @@ -208,9 +208,10 @@ void oupicio(const char *dirn, const PicInsnInfo *pii, int obj, int v) { } static void obc_error(OutBufferChain *ch, const char *e1, const char *e2) { - if (!e1) { assert(!e2); exit(0); } + if (!e1) { assert(!e2); die_hook(); exit(0); } fprintf(stderr,"command communication error: %s%s%s\n", e1, e2?": ":"", e2?e2:""); + die_hook(); exit(-1); } @@ -228,7 +229,12 @@ void die_vprintf_hook(const char *fmt, va_list al) { } void die_hook(void) { + PicInsn off; int e; + + enco_pic_off(&off); + + write(serial_fd,off.d,off.l); e= events ? obc_tryflush(UPO) : 0; if (e) fprintf(stderr,"(unwritten command output: %s)\n",strerror(e)); } diff --git a/hostside/safety.c b/hostside/safety.c index 73f1048..d014f39 100644 --- a/hostside/safety.c +++ b/hostside/safety.c @@ -558,10 +558,13 @@ static int fdet_nextseg(TrackLocation *t, TrackAdvanceContext *c, if (!u->done_first_new_fdet) { t->seg->det_expected= 1; u->done_first_new_fdet= 1; + } - u->walk_compute_polarise= u->need_polarise= - (t->seg->seg_inverted ^ t->seg->tr_backwards ^ - u->train_polarity_inverted); + if (u->elapsed < MARGIN_POLARISETIME) { + u->need_polarise |= (t->seg->seg_inverted ^ t->seg->tr_backwards ^ + u->train_polarity_inverted); + } else { + u->walk_compute_polarise &= u->need_polarise; } if (u->train->autopoint && !u->autopoint_distance) { @@ -658,9 +661,7 @@ ErrorCode predict(Train *tra, int accelerate, struct timeval tnow, } foredet= tra->foredetect; - - if (!foredet) - return predict_problem(&u,0,"train is not on layout"); + assert(foredet); u.walk_compute_polarise= 1; u.train_polarity_inverted= foredet->seg_inverted ^ foredet->tr_backwards; diff --git a/hostside/safety.h b/hostside/safety.h index 96dfec8..2e88f13 100644 --- a/hostside/safety.h +++ b/hostside/safety.h @@ -362,5 +362,6 @@ int trackloc_set_exactinto(TrackLocation *t, TrackAdvanceContext *c, #define MARGIN_SPEED 1.2 /*ratio*/ #define MARGIN_STOPTIME 50 /*ms*/ #define MARGIN_AUTOPOINTTIME 500 /*ms*/ +#define MARGIN_POLARISETIME 50 /*ms*/ #endif /*SAFETY_H*/ diff --git a/hostside/speed.c b/hostside/speed.c index 197ea95..43175b6 100644 --- a/hostside/speed.c +++ b/hostside/speed.c @@ -147,6 +147,11 @@ ErrorCode speedmanager_speedchange_request(Train *tra, int step, PredictionProblemCallback *ppc, void *ppcu) { struct timeval tnow; assert(ppc || ppcu); + + if (!tra->foredetect) { + ppc(tra,0,ppcu,"train is not on layout"); + return EC_SignallingPredictedProblem; + } mgettimeofday(&tnow); return request_core(tra,step,tnow,ppc,ppcu); }