From: Ian Jackson Date: Fri, 18 Feb 2011 23:10:35 +0000 (+0000) Subject: safety: in movpos split "actual" into "actualpos" and "actualunk", so we know which... X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=9a419333d7eedff3d4936526df2fd8a0873545bf;p=trains.git safety: in movpos split "actual" into "actualpos" and "actualunk", so we know which features' positions we know; this means movpos_poscomb_actual disappears but we didn't need it anyway --- diff --git a/hostside/commands.c b/hostside/commands.c index e29eea6..fa5a6cb 100644 --- a/hostside/commands.c +++ b/hostside/commands.c @@ -283,9 +283,9 @@ static int cmd_movfeat(ParseState *ps, const CmdInfo *ci) { if (move->motion) target= movpos_change_intent(move->motion); else - target= movpos_poscomb_actual(move); + target= move->movposcomb; - if (target<0) { + if (!SOMEP(target)) { if (movei->n_movfeats > 1) ouprintf("info movfeat-collapsing-unknown %s :" " will set previously-unknown, but not set," diff --git a/hostside/movpos.c b/hostside/movpos.c index 5b04d30..6388d53 100644 --- a/hostside/movpos.c +++ b/hostside/movpos.c @@ -14,10 +14,14 @@ typedef struct { typedef struct Method Method; typedef struct Change Change; +#define PRunkx PRIx32 +typedef uint32_t UnkMap; + typedef struct MovPosChange { Segment *move; /* everything beyond here is private for indep */ - MovPosComb actual, target; + MovPosComb actualpos, target; + UnkMap actualunk; /* bit per movfeat, set iff actualpos contains dummy 0 */ int refcount; int n_changes; Change *changes[]; @@ -111,7 +115,8 @@ const char *movpos_pname(const Segment *move, MovPosComb poscomb) { static void ouposn_moving(const MovPosChange *indep) { Segment *move= indep->move; ouprintf("movpos %s position %s moving\n", - move->i->pname, movpos_pname(move, indep->actual)); + move->i->pname, + indep->actualunk ? "?" : movpos_pname(move, indep->actualpos)); } static void ouposn_stable(const Segment *move) { ouprintf("movpos %s position %s stable\n", @@ -132,10 +137,6 @@ MovPosComb movposcomb_update_feature(MovPosComb startpoint, return above*above_weight + featpos*mfi->weight + below; } -MovPosComb movpos_poscomb_actual(const Segment *seg) { - return seg->moving ? seg->motion->actual : seg->movposcomb; -} - static void ignore_all_abandon(Method *m) { } /*========== points and other fixed timeslot movfeats ==========*/ @@ -703,10 +704,12 @@ static Method *methods[]= { static void method_update_feature(Method *m, MovPosChange *indep, const Motion *mo) { + int featix= mo->i - indep->move->i->movfeats; + assert(featix >= 0 && featix < indep->move->i->n_movfeats); ouposn_feat(indep->move, mo->i, mo->posn, m); - if (SOMEP(indep->actual)) - indep->actual= - movposcomb_update_feature(indep->actual, mo->i, mo->posn); + indep->actualpos= + movposcomb_update_feature(indep->actualpos, mo->i, mo->posn); + indep->actualunk &= (~(UnkMap)1 << featix); ouposn_moving(indep); } @@ -752,17 +755,20 @@ static Method *feature_method(const MovFeatInfo *feati) { return meth; } -static int change_needed(const MovFeatInfo *feati, - MovPosComb startpoint, MovPosComb target) { +static int change_needed(int featix, const MovFeatInfo *feati, + MovPosComb startpointpos, UnkMap startpointunk, + MovPosComb target) { int r; - r= !SOMEP(startpoint) || + + r= (startpointunk & ((UnkMap)1 << featix)) || (target / feati->weight) % feati->posns - - (startpoint / feati->weight) % feati->posns; + (startpointpos / feati->weight) % feati->posns; + if (DEBUGP(movpos,eval)) DPRINTFA(" { %s:%s(%d*%d) %d..%d => %d }", feature_method(feati)->pname, feati->pname, feati->posns, feati->weight, - startpoint, target, r); + startpointpos, target, r); return r; } @@ -789,7 +795,7 @@ static void indep_dispose(MovPosChange *indep) { #define EVAL_MAX_MOTIONS 2 static ErrorCode indep_prepare(Segment *move, MovPosComb target, - MovPosComb startpoint, + MovPosComb startpointpos, int ms, int confirming, MovPosChange **indep_r /* 0 ok */, int *cost_r /* 0 ok */) { @@ -800,22 +806,38 @@ static ErrorCode indep_prepare(Segment *move, MovPosComb target, const SegmentInfo *movei= move->i; int feat, DP; + UnkMap startpointunk; MovPosChange *indep=0; DPRINTF1(movpos,eval, "movpos prepare %s/%s <-%s", move->i->pname, - movpos_pname(move,target), movpos_pname(move,startpoint)); + movpos_pname(move,target), movpos_pname(move,startpointpos)); - if (!SOMEP(startpoint)) { - startpoint= movpos_poscomb_actual(move); - DPRINTF2(" actual <-%s", movpos_pname(move,startpoint)); + if (SOMEP(startpointpos)) { + startpointunk= 0; + } else { + if (move->moving) { + startpointpos= move->motion->actualpos; + startpointunk= move->motion->actualunk; + } else if (SOMEP(move->movposcomb)) { + startpointpos= move->movposcomb; + startpointunk= 0; + } else { + startpointpos= 0; + startpointunk= ((UnkMap)1 << move->i->n_movfeats) - 1; + } + DPRINTF2(" actual <-%s&%"PRunkx, movpos_pname(move,startpointpos), + startpointunk); } n_meths= 0; for (feat=0; featn_movfeats; feat++) { const MovFeatInfo *feati= &movei->movfeats[feat]; - if (!change_needed(feati,startpoint,target)) continue; + if (!change_needed(feat,feati, + startpointpos,startpointunk, + target)) + continue; MovPosComb posn= target / feati->weight % feati->posns; Method *meth= feature_method(feati); @@ -847,7 +869,8 @@ static ErrorCode indep_prepare(Segment *move, MovPosComb target, DPRINTF2(" alloc"); indep= mmalloc(sizeof(*indep) + sizeof(Change*) * n_meths); indep->move= move; - indep->actual= startpoint; + indep->actualpos= startpointpos; + indep->actualunk= startpointunk; indep->target= target; indep->n_changes= n_meths; indep->refcount= 0; @@ -1070,19 +1093,10 @@ ErrorCode movpos_findcomb_bysegs(Segment *back, Segment *move, Segment *fwd, ErrorCode movpos_change(Segment *move, MovPosComb target, int maxdelay_ms, MovPosChange *resv) { int DP; - MovPosComb actual; ErrorCode ec; - if (!move->moving) { - actual= move->movposcomb; - assert(!move->motion); - } else { - actual= move->motion->actual; - } - - DPRINTF1(movpos,entry, "movpos change %s/%s maxdelay=%dms actual=%s", - move->i->pname, movpos_pname(move, target), - maxdelay_ms, movpos_pname(move, actual)); + DPRINTF1(movpos,entry, "movpos change %s/%s maxdelay=%dms", + move->i->pname, movpos_pname(move, target), maxdelay_ms); if (resv) DPRINTF2(" resv=%s/%s", resv->move->i->pname, movpos_pname(resv->move, resv->target)); @@ -1092,7 +1106,7 @@ ErrorCode movpos_change(Segment *move, MovPosComb target, MovPosChange *inst= 0; - ec= indep_prepare(move,target, actual, + ec= indep_prepare(move,target, NOTA(MovPosComb), maxdelay_ms,1, &inst, 0); if (ec) goto x; @@ -1157,7 +1171,7 @@ void motions_all_abandon(void) { MovPosChange *abandon= seg->motion; indep_remove(abandon); - seg->movposcomb= abandon->actual; + seg->movposcomb= abandon->actualunk ? NOTA(MovPosComb) : abandon->actualpos; seg->moving= 0; seg->motion= 0; indep_dispose(abandon); diff --git a/hostside/realtime.h b/hostside/realtime.h index 4364d70..d644ca2 100644 --- a/hostside/realtime.h +++ b/hostside/realtime.h @@ -15,6 +15,7 @@ #include #include +#include #include #include diff --git a/hostside/safety.h b/hostside/safety.h index 78447c7..19c9fd9 100644 --- a/hostside/safety.h +++ b/hostside/safety.h @@ -227,11 +227,6 @@ movpos_reserve(Segment *move, int maxdelay_ms, MovPosChange **res_r, void movpos_unreserve(MovPosChange *reservation /* 0 ok */); -MovPosComb movpos_poscomb_actual(const Segment *seg); - /* gives actual current position as published by movfeatkind - * -1 means not known or cannot be represented as a MovPosComb - */ - MovPosComb movpos_change_intent(MovPosChange *chg); /* Returns the target value supplied to _reserve or _change */