From: ian Date: Tue, 20 May 2008 21:38:16 +0000 (+0000) Subject: separate pred_getmovpos and report_getmovpos, and make the former less buggy X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=0640d2b9005ff56506942d9a5aa3b4164d892460;p=trains.git separate pred_getmovpos and report_getmovpos, and make the former less buggy --- diff --git a/hostside/safety.c b/hostside/safety.c index 8e901a0..9f315ab 100644 --- a/hostside/safety.c +++ b/hostside/safety.c @@ -266,13 +266,12 @@ typedef struct { neednewplan:1, stopping:1, done_first_new_fdet:1, - usecurrentposn:1, /* for pred_getmovpos */ + usecurrentposn:1, /* for {pred,report}_getmovpos */ optimistic:1, /* for autopoint */ 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 */ - know_best_polarity:1, /* longest-lasting into the future */ - alwaysusemotions:1; /* for report_train_ownerships, uses ->motion */ + know_best_polarity:1; /* longest-lasting into the future */ TrackLocation nose, fdet, tail; TrackAdvanceContext nosec, tailc, fdetc; TimeInterval elapsed; /* from now, minimum */ @@ -395,14 +394,10 @@ static void pred_callback_debug(const char *what, TrackLocation *t, static int pred_getmovpos(TrackLocation *t, TrackAdvanceContext *c, MovPosComb *use_io) { PredictUserContext *u= c->u; - if (u->usecurrentposn) return 0; - if (u->alwaysusemotions) { - if (t->seg->motion) - *use_io= movpos_change_intent(t->seg->motion); - } else if (t->seg->moving || t->seg->pred_vacated) { - if (t->seg->motion_newplan) - *use_io= movpos_change_intent(t->seg->motion_newplan); - } + if (!u->usecurrentposn && + !t->seg->now_present && + t->seg->motion_newplan) + *use_io= movpos_change_intent(t->seg->motion_newplan); if (*use_io<0) safety_panic(u->train, t->seg, "track route unexpectedly not known"); return 0; @@ -487,6 +482,8 @@ static int nose_nextseg(TrackLocation *t, TrackAdvanceContext *c, } } + int autopoint= u->train->autopoint && t->seg->autopoint; + if (t->seg->motion_newplan) { route_plan= movpos_change_intent(t->seg->motion); *mpc_io= route_plan; @@ -498,6 +495,7 @@ static int nose_nextseg(TrackLocation *t, TrackAdvanceContext *c, if (route_plan != u->desire_movposcomb) return predict_problem(u, t->seg, " proposed route would be against" " approaching train"); + autopoint= 1; } else if (t->seg->motion) { /* We already have a plan. */ route_plan= movpos_change_intent(t->seg->motion); @@ -530,7 +528,7 @@ static int nose_nextseg(TrackLocation *t, TrackAdvanceContext *c, max_ms= u->elapsed; } - if (!u->train->autopoint || !t->seg->autopoint) + if (!autopoint) return predict_problem(u,t->seg,"will not automatically set route"); ec= movpos_reserve(t->seg, max_ms, &t->seg->motion_newplan, @@ -706,8 +704,8 @@ ErrorCode predict(Train *tra, struct timeval tnow, unsigned flags, u.desire_movposcomb= desire_movposcomb; oprintf(DUPO("safety") " predict ***starting*** %s%s maxspeed=%f" - " (speed %f try %f, step %d%s) stopdist=%d flags=%c%c" - " desire=%s/%s %s\n", + " (speed %f try %f, step %d%s) stopdist=%d flags=%c%c%s" + " desire=%s/%s\n", tra->backwards?"-":"",tra->pname, u.maxspeed, tra->speed.speed, tra->speed.try_speed, tra->speed.step, tra->speed.decel.running ? " decel" : "", @@ -970,13 +968,22 @@ void report_train_position(Train *tra) { tra->foredetect->i->pname, tra->maxinto, tra->uncertainty); } +static int report_getmovpos(TrackLocation *t, TrackAdvanceContext *c, + MovPosComb *use_io) { + PredictUserContext *u= c->u; + if (!u->usecurrentposn && t->seg->motion) + *use_io= movpos_change_intent(t->seg->motion); + assert(*use_io>=0); + return 0; +} + static int report_nextseg(TrackLocation *t, struct TrackAdvanceContext *c, MovPosComb *mpc, const TrackLocation *before) { PredictUserContext *u= c->u; char flags[6]; int r; - if (u->alwaysusemotions) /* we've had foredetect */ + if (!u->usecurrentposn) /* we've had foredetect */ if (++u->lookahead > u->train->plan_lookahead_nsegs) return -1; @@ -989,13 +996,12 @@ static int report_nextseg(TrackLocation *t, struct TrackAdvanceContext *c, if (t->seg == u->train->foredetect) { strcat(flags,"!"); u->usecurrentposn= 0; - u->alwaysusemotions= 1; } oprintf(UPO," %s%s", t->backwards?"-":"", t->seg->i->pname); if (t->seg->i->n_poscombs > 1) { - r= pred_getmovpos(t,c,mpc); assert(!r); assert(*mpc>=0); + r= report_getmovpos(t,c,mpc); assert(!r); assert(*mpc>=0); oprintf(UPO,"/%s", t->seg->i->poscombs[*mpc].pname); } oprintf(UPO,"%s",flags); @@ -1010,7 +1016,6 @@ void report_train_ownerships(Train *tra, Segment *hindmost, memset(&u,0,sizeof(u)); u.train= tra; u.hindmost= 0; - u.alwaysusemotions= always_use_motions; u.usecurrentposn= !always_use_motions; /* Walk along the train printing its segments: */ @@ -1022,7 +1027,7 @@ void report_train_ownerships(Train *tra, Segment *hindmost, u.nosec.distance= TL_DIST_INF;; u.nosec.nextseg= report_nextseg; - u.nosec.getmovpos= pred_getmovpos; + u.nosec.getmovpos= report_getmovpos; u.nosec.u= &u; u.hindmost= hindmost;