}
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);
}
}
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));
}
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) {
}
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;
#define MARGIN_SPEED 1.2 /*ratio*/
#define MARGIN_STOPTIME 50 /*ms*/
#define MARGIN_AUTOPOINTTIME 500 /*ms*/
+#define MARGIN_POLARISETIME 50 /*ms*/
#endif /*SAFETY_H*/
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);
}