From: ian Date: Sun, 1 Jun 2008 22:04:07 +0000 (+0000) Subject: new movfeat command X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=577e1608051e710b6c305876e6f5700ff8f55074;p=trains.git new movfeat command --- diff --git a/hostside/README.commands b/hostside/README.commands index 0d69e3f..fdf97c9 100644 --- a/hostside/README.commands +++ b/hostside/README.commands @@ -83,7 +83,9 @@ POSSIBLY-ASYNCHRONOUS REPORTING OF MESSAGES TO/FROM (MASTER) PIC may be ? for unknown U< ?debug : - U< ?info : + + U< ?info [] : + U< ?info movfeat-collapsing-unknown : will set previously [etc.] MESSAGES TO SIMULATION LOG @@ -167,6 +169,20 @@ MULTIPLEXER-IMPLEMENTED FUNCTIONALITY AFFECTING WHOLE SYSTEM ====================================================================== +INCOMPLETE LIST OF OTHER COMMANDS + + route [] + route |- |- [] any suitable movposcomb + + route+ change even segments owned by a train's route + route++ even queue changes for segments currently under a train + !route just do it, don't ask safety system + + movfeat [] + movfeat+ } see route+ + movfeat++ } see route++ + !movfeat } see !route + DIRECT NMRA AND PIC INSTRUCTIONS Example (always the same msg): diff --git a/hostside/commands.c b/hostside/commands.c index 0fcc7a2..fc111a9 100644 --- a/hostside/commands.c +++ b/hostside/commands.c @@ -230,10 +230,70 @@ static int ps_needtrain(ParseState *ps, Train **tra_r) { return 0; } -static int cmd_movpos(ParseState *ps, const CmdInfo *ci) { +static int cmd_route_movfeat(ParseState *ps, const CmdInfo *ci, + Segment *move, const SegmentInfo *movei, + int poscomb) { + long ms; + + ms= -1; + if (ps->remain && CIXF_FORCE) + MUSTECR( ps_neednumber(ps,&ms,0,100000,"milliseconds") ); + + MUSTECR( ps_neednoargs(ps) ); + + if (ci->xarg & CIXF_FORCE) { + if (!(sta_state < Sta_Resolving || sta_state == Sta_Manual)) + return badcmd(ps,"movpos queueing arrangements not ready"); + + MovPosChange *reservation= 0; + if (!move->moving && move->motion) { + reservation= move->motion; + move->motion= 0; + } + MUSTECR( movpos_change(move,poscomb,ms,reservation) ); + } else { + MUSTECRPREDICT( safety_movposchange(move, poscomb, ci->xarg & CIXF_U, + CMDPPC) ); + } + + return 0; +} + +static int cmd_movfeat(ParseState *ps, const CmdInfo *ci) { + Segment *move; + const SegmentInfo *movei; + const MovFeatInfo *mfi; + MovPosComb target; + long pos_l; + + MUSTECR( ps_needsegment(ps,&move,&movei) ); + mfi= some_needword_lookup_counted(ps, movei->movfeats, movei->n_movfeats, + "moveable feature name"); + if (!mfi) return EC_BadCmd; + + MUSTECR( ps_neednumber(ps,&pos_l,0,mfi->posns-1,"position number") ); + + if (move->motion) + target= movpos_change_intent(move->motion); + else + target= movpos_poscomb_actual(move); + + if (target<0) { + if (movei->n_movfeats > 1) + ouprintf("info movfeat-collapsing-unknown %s :" + " will set previously-unknown, but not set," + " feature(s) to position 0", + movei->pname); + target= 0; + } + target= movposcomb_update_feature(target,mfi,pos_l); + + return cmd_route_movfeat(ps,ci, move,movei,target); +} + +static int cmd_route(ParseState *ps, const CmdInfo *ci) { Segment *move; const SegmentInfo *movei; - long ms; MovPosComb poscomb; long poscomb_l; @@ -252,23 +312,8 @@ static int cmd_movpos(ParseState *ps, const CmdInfo *ci) { MUSTECR( ps_needsegmentperhaps(ps,&fwd,0) ); MUSTECR( movpos_findcomb_bysegs(back,move,fwd,move->movposcomb,&poscomb) ); } - - ms= -1; - if (ps->remain && CIXF_FORCE) - MUSTECR( ps_neednumber(ps,&ms,0,100000,"milliseconds") ); - MUSTECR( ps_neednoargs(ps) ); - - if (ci->xarg & CIXF_FORCE) { - if (!(sta_state < Sta_Resolving || sta_state == Sta_Manual)) - return badcmd(ps,"movpos queueing arrangements not ready"); - MUSTECR( movpos_change(move,poscomb,ms,0) ); - } else { - MUSTECRPREDICT( safety_movposchange(move, poscomb, ci->xarg & CIXF_U, - CMDPPC) ); - } - - return 0; + return cmd_route_movfeat(ps,ci, move,movei,poscomb); } static int cmd_speed(ParseState *ps, const CmdInfo *ci) { @@ -338,11 +383,15 @@ const CmdInfo toplevel_cmds[]= { { "!pic", cmd_pic, CIXF_ANYSTA|CIXF_FORCE }, { "!nmra", cmd_nmra, CIXF_ANYSTA }, { "noop", cmd_noop, CIXF_ANYSTA }, - { "movpos", cmd_movpos }, - { "route", cmd_movpos, 1 }, - { "reroute", cmd_movpos, 2 }, + { "route", cmd_route }, + { "route+", cmd_route, 1 }, + { "route++", cmd_route, 2 }, + { "movfeat", cmd_movfeat }, + { "movfeat+", cmd_movfeat, 1 }, + { "movfeat++", cmd_movfeat, 2 }, + { "!route", cmd_route, CIXF_ANYSTA|CIXF_FORCE }, + { "!movfeat", cmd_movfeat, CIXF_ANYSTA|CIXF_FORCE }, //{ "autopoint", cmd_autopoint }, - { "!movpos", cmd_movpos, CIXF_ANYSTA|CIXF_FORCE }, { "!invert", cmd_invert, CIXF_ANYSTA|CIXF_FORCE }, { "speed", cmd_speed }, { "!speed", cmd_speed, CIXF_ANYSTA|CIXF_FORCE }, diff --git a/hostside/movpos.c b/hostside/movpos.c index f02043e..86954b8 100644 --- a/hostside/movpos.c +++ b/hostside/movpos.c @@ -469,10 +469,7 @@ static void fsq_check_action(FsqMethod *m) { mo->i->pname, mo->posn, m->m.pname); m->f.cslot++; - MovPosComb above_weight= mo->i->weight * mo->i->posns; - MovPosComb above= r->actual / above_weight; - MovPosComb below= r->actual % mo->i->weight; - r->actual= above*above_weight + mo->posn*mo->i->weight + below; + r->actual= movposcomb_update_feature(r->actual,mo->i,mo->posn); if (r->h.actual >= 0 || !r->n_motions) r->h.actual= r->actual; ouposn_moving(&r->h); @@ -926,3 +923,12 @@ void motions_all_abandon(void) { for (meth=methods; *meth; meth++) (*meth)->all_abandon(*meth); } + +MovPosComb movposcomb_update_feature(MovPosComb startpoint, + const MovFeatInfo *mfi, + int featpos) { + MovPosComb above_weight= mfi->weight * mfi->posns; + MovPosComb above= startpoint / above_weight; + MovPosComb below= startpoint % mfi->weight; + return above*above_weight + featpos*mfi->weight + below; +} diff --git a/hostside/safety.h b/hostside/safety.h index 87305c4..452eace 100644 --- a/hostside/safety.h +++ b/hostside/safety.h @@ -220,6 +220,12 @@ MovPosComb movpos_change_intent(MovPosChange *chg); const char *movpos_pname(Segment *move, MovPosComb poscomb); +MovPosComb movposcomb_update_feature(MovPosComb startpoint, + const MovFeatInfo *mfi, + int featpos); + /* Returns movposcomb representing a changed combination of positions; + * pure function. */ + /*========== speed.c ==========*/ ErrorCode speedmanager_speedchange_request(Train *tra, int step,