unsigned
count_time:1,
accelerating:1,
+ usecurrentposn:1, /* for pred_getmovpos */
walk_compute_polarise:1, /* nose_nextseg still needs to worry */
need_polarise:1, /* when we commit */
train_polarity_inverted:1, /* right now, or if know_best, the best */
TrackAdvanceContext nosec, tailc, fdetc;
TimeInterval elapsed; /* from now, minimum */
Distance was_distance;
+ Segment *furthest;
PredictionProblemCallback *problem_callback;
void *problem_callback_u;
static int pred_getmovpos(TrackLocation *t, TrackAdvanceContext *c,
MovPosComb *use_io) {
PredictUserContext *u= c->u;
+ if (u->usecurrentposn) return 0;
if (t->seg->motion) *use_io= movpos_change_intent(t->seg->motion);
if (*use_io<0) safety_panic(u->train, t->seg,
"track route unexpectedly not known");
t->seg->tr_backwards= t->backwards;
t->seg->pred_present= 1;
t->seg->until= u->elapsed;
+ u->furthest= t->seg;
return 0; /* yay! */
}
return 0;
}
+/*---------- reporting position and ownership ----------*/
+
+void report_train_position(Train *tra) {
+ oprintf(UPO, "train %s %s at %s%s:%d+-%d",
+ tra->pname, tra->backwards ? "backwards" : "forwards",
+ tra->foredetect->tr_backwards?"-":"",
+ tra->foredetect->i->pname, tra->maxinto, tra->uncertainty);
+}
+
+static int report_nextseg(TrackLocation *t, struct TrackAdvanceContext *c,
+ MovPosComb *mpc, Segment *before) {
+ PredictUserContext *u= c->u;
+ char flags[6];
+ int r;
+
+ if (t->seg->owner != u->train) return -1;
+ if (u->usecurrentposn && !t->seg->det_ignore)
+ /* We've gone back past our own tail into the place where our
+ * head is going to be in the far future. Confusing, eh ? */
+ return -1;
+
+ if (t->seg->det_expected)
+ strcat(flags,"*");
+ if (t->seg == u->train->foredetect) {
+ strcat(flags,"!");
+ u->usecurrentposn=1;
+ }
+ if (t->seg->det_ignore)
+ strcat(flags,"@");
+ if (t->seg->tr_backwards)
+ strcat(flags,"-");
+
+ oprintf(UPO," %s%s",flags,t->seg->i->pname);
+
+ if (t->seg->i->n_poscombs > 1) {
+ r= pred_getmovpos(t,c,mpc); assert(!r);
+ oprintf(UPO,"/%s", t->seg->i->poscombs[*mpc].pname);
+ }
+
+ return 0;
+}
+
+void report_train_ownerships(Train *tra, Segment *furthest) {
+ PredictUserContext u;
+ MovPosComb mpc;
+ int r;
+
+ memset(&u,0,sizeof(u));
+ u.train= tra;
+ u.furthest= furthest;
+ u.usecurrentposn= 0;
+
+ /* Walk backwards along the train printing its segments: */
+ oprintf(UPO, "train %s has", tra->pname);
+
+ u.tail.seg= furthest;
+ u.tail.remain= 0;
+ u.tail.backwards= !u.tail.seg->tr_backwards;
+
+ u.tailc.distance= INT_MAX;;
+ u.tailc.nextseg= report_nextseg;
+ u.tailc.getmovpos= pred_getmovpos;
+ u.tailc.u= &u;
+
+ mpc= furthest->movposcomb;
+ r= report_nextseg(&u.tail,&u.tailc,&mpc,0); assert(!r);
+ trackloc_advance(&u.tail,&u.tailc);
+ oprintf(UPO, "\n");
+}
+
+
/*---------- prediction entrypoint ----------*/
ErrorCode predict_confirm(Train *tra, int accelerate,
u.train_polarity_inverted= foredet->seg_inverted ^ foredet->tr_backwards;
u.problem_callback= ppc;
u.problem_callback_u= ppcu;
+ u.furthest= tra->foredetect;
+ u.usecurrentposn= 1;
u.fdetc.getmovpos= pred_getmovpos;
u.tailc.getmovpos= pred_getmovpos;
if (u.need_polarise)
actual_inversions_done();
+ report_train_ownerships(tra,u.furthest);
return 0;
xproblem:
static void detection_report_problem(Train *tra, Segment *seg,
void *pu, const char *message) {
- oprintf(UPO, "signalling-problem %s @%s detection @%s : %s",
- tra->pname, tra->foredetect->i->pname, seg->i->pname, message);
+ oprintf(UPO, "train %s signalling-problem %s : %s",
+ tra->pname, seg->i->pname, message);
}
void safety_notify_detection(Segment *seg) {
tra->uncertainty= tra->maxinto=
seg->i->poscombs[seg->movposcomb].dist;
+ report_train_position(tra);
+
ec= predict_confirm(tra, 0, detection_report_problem, 0);
if (!ec) return;