chiark / gitweb /
finished segment inversion arrangements in safety.c
authorian <ian>
Sun, 27 Feb 2005 23:35:24 +0000 (23:35 +0000)
committerian <ian>
Sun, 27 Feb 2005 23:35:24 +0000 (23:35 +0000)
hostside/safety.c
hostside/safety.h

index 7a791a9ddc5afa24b9423ed8c91f903995735677..b982becc6ffb403a67020ed0a167f54fe52c5748 100644 (file)
@@ -99,6 +99,7 @@ static void lay_train_pass(LayTrainState l,
 static void lay_train_inversions(LayTrainState *l) {
   SegmentNum segn;
   SegmentState *seg;
+  const SegmentInfo *segi;
   int train_be_inverted, seg_be_inverted;
  
   if (l->ec) return;
@@ -106,13 +107,19 @@ static void lay_train_inversions(LayTrainState *l) {
   train_be_inverted= l->invert_count[1] > l->invert_count[0];
   assert(l->invert_count[train_be_inverted] >= 0);
 
-  for (segn=0, seg=s->segs;
+  actual_inversions_start();
+  
+  for (segn=0, seg=s->segs, segi=info_segments;
        segn <= NUM_SEGMENTS;
        segn++, seg++) {
     if (!seg->tr_updated) continue;
     assert(seg->owner == l->tran);
     seg_be_inverted= train_be_inverted ^ seg->tr_backwards;
-    
+    assert(!(seg_be_inverted && !segi->invertible));
+    seg->seg_inverted= seg_be_inverted;
+    actual_inversions_segment();
+  }
+  actual_inversions_done();
 }
 
 static void lay_train_done(LayTrainState *l) {
index 8cb78929d2783d688288f21151c97b2a45a1164b..81015ca98915cca2a2f7ee29cac2153bb92e41b5 100644 (file)
@@ -30,7 +30,7 @@ typedef struct {
     pt_moving:1, /* points have been told to change to pt_sideways */
     cm_autostop:1, /* train should stop on detection */
     cm_pointchange:1, /* points should change when they can */
-    seg_inverted:1, /* polarity is inverted! */
+    seg_inverted:1, /* polarity is inverted */
     tr_updated:1; /* for use by safety.c:lay_train etc.; otherwise 0 */
   TimeInterval until_here, /* ) nonnegative; */  /* ) always valid but */
     until_detect;          /* ) 0 if already */  /* )  only meaningful */
@@ -98,9 +98,22 @@ void speedmanager_speedchange_notify(TrainNum tran);
 /* actual.c should only be called from safety.c.
  * It is responsible for communicating with the PICs, including
  * repeating the NMRA commands and redacting detection information.
+ *
+ * In general, when State information is shared between actual.c
+ * and safety.c, actual.c is responsible for modifying State, and
+ * will then call an actual_... function to notify the change.
  */
 
 void actual_setspeed(TrainNum tran);
+
+void actual_inversions_start(void);
+void actual_inversions_segment(SegmentNum);
+void actual_inversions_done(void);
+  /* safety.c will call these in this order: first start, then segment
+   * for 0 or more segments (whose inversion may or may not have
+   * changed), and finally done.  At done, the PICs should be told to
+   * (de)invert the segments as specified.
+   */
   
 /*
  *