chiark / gitweb /
fix train not on layout speed request death; hope to fix polarisation; turn off on...
authorian <ian>
Fri, 16 May 2008 18:33:59 +0000 (18:33 +0000)
committerian <ian>
Fri, 16 May 2008 18:33:59 +0000 (18:33 +0000)
hostside/realtime.c
hostside/safety.c
hostside/safety.h
hostside/speed.c

index 1153d1d9dbbe1caac171ce18e89e877a12ebc144..fcd02aec13ba1ac759519f3f3e710917b58f094a 100644 (file)
@@ -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));
 }
index 73f1048f552f86081e1e113f5f4384aa459d93c2..d014f39b44fcff86072b9f72f226d35a5849a9ce 100644 (file)
@@ -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;
index 96dfec8be1d78aaa644a8870ddfb2cad95fa8564..2e88f13519ac6aef96dbc5e04df94fae40f7ba15 100644 (file)
@@ -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*/
index 197ea955114364368a3b5ee1ad7312f420d3d5d5..43175b6d29ff8ef602877e9715ab3172ea455e17 100644 (file)
@@ -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);
 }