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;
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) {
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 */
/* 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.
+ */
/*
*