From fa6bf5a33254b5f4212c4e8f88a98fcedaf009ef Mon Sep 17 00:00:00 2001 From: ian Date: Sun, 27 Jul 2008 22:19:29 +0000 Subject: [PATCH] call predict() at end of resolution; fixes to resolution --- hostside/resolve.c | 49 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/hostside/resolve.c b/hostside/resolve.c index dc093bc..465e065 100644 --- a/hostside/resolve.c +++ b/hostside/resolve.c @@ -418,9 +418,9 @@ static int constraint_nextseg(TrackLocation *t, struct TrackAdvanceContext *c, FindEndUserContext *u= (void*)c; DPRINTF(resolving,ends, " constraint_nextseg %c" - " %s%s dist=INF-%d det=%d ours=%d owner=%s home=%s\n", + " %s%s remain=%d dist=INF-%d det=%d ours=%d owner=%s home=%s\n", "fr"[u->rear], - t->backwards?"-":"", t->seg->i->pname, + t->backwards?"-":"", t->seg->i->pname, t->remain, TL_DIST_INF - c->distance, t->seg->res_detect, t->seg->resfin_ours, @@ -435,10 +435,18 @@ static int constraint_nextseg(TrackLocation *t, struct TrackAdvanceContext *c, if (before) { if (t->seg == u->startpoint) return 'l'; const SegmentLinkInfo *rlink= &pci->link[!t->backwards]; - if (before->seg != &segments[rlink->next]) return 'm'; + if (before->seg != &segments[rlink->next]) { + DPRINTF(resolving,ends, " j mismatch %s %s\n", + before->seg->i->pname, info_segments[rlink->next].pname); + return 'j'; + } } if (t->seg->res_detect) { u->atlastdetect= c->distance; + if (!before) + /* wind back to start of this segment which is necessary if this + * we are looking rearwards */ + u->atlastdetect += (pci->dist - t->remain); u->lastdetect= t->seg; } return 0; @@ -511,9 +519,11 @@ static void end_constraints(FindEndUserContext *u) { u->problems++; } - DPRINTF(resolving,ends, " lims %c hardwhy=%c %s,%s lim=%d..%d out=%d..%d\n", - "fr"[u->rear], cons->hardwhy, - cons->lastdetect->i->pname, u->t.seg->i->pname, + DPRINTF(resolving,ends, " lims %c %s,%s,%c dist=INF-%d" + " lim=%d..%d out=%d..%d\n", + "fr"[u->rear], + cons->lastdetect->i->pname, u->t.seg->i->pname, cons->hardwhy, + TL_DIST_INF - u->tc.distance, lim.min, lim.max, cons->min, cons->max); } @@ -521,8 +531,6 @@ static int resolve_complete_ends_train(Train *tra) { SEG_IV; FindEndUserContext u; const SegPosCombInfo *pci; - struct timeval tnow; - ErrorCode ec; int r, DP; switch (tra->resolution) { @@ -581,7 +589,7 @@ static int resolve_complete_ends_train(Train *tra) { u.problems++; } - int min= MIN(u.constraints[0].min, u.constraints[1].min); + int min= MAX(u.constraints[0].min, u.constraints[1].min); int max= MIN(u.constraints[0].max, u.constraints[1].max); DPRINTF(resolving,ends, " lims a %d..%d problems=%d\n", min, max, u.problems); @@ -607,12 +615,9 @@ static int resolve_complete_ends_train(Train *tra) { tra->uncertainty= max - min; report_train_position(tra); - - mgettimeofday(&tnow); - tra->plan_lookahead_nsegs= INT_MAX; - ec= predict(tra,tnow, PREDF_OLDPLAN, 0,0, 0, - 0,(char*)"resolution confirmation"); - assert(!ec); + /* We don't lay the train out now since the moveable features + * are not yet in place. We can defer it, though, as it is guaranteed + * to work, now. */ return 0; } @@ -680,11 +685,25 @@ int resolve_complete(void) { } void resolve_motioncheck(void) { + ErrorCode ec; SEG_IV; + TRA_IV; + struct timeval tnow; + assert(sta_state == Sta_Finalising); FOR_SEG if (seg->moving) return; + FOR_TRA { + if (tra->resolution == RR_N) continue; + + mgettimeofday(&tnow); + tra->plan_lookahead_nsegs= INT_MAX; + ec= predict(tra,tnow, PREDF_OLDPLAN, 0,0, 0, + 0,(char*)"resolution confirmation"); + assert(!ec); + } + sta_finalising_done(); } -- 2.30.2