chiark / gitweb /
new movfeat command
authorian <ian>
Sun, 1 Jun 2008 22:04:07 +0000 (22:04 +0000)
committerian <ian>
Sun, 1 Jun 2008 22:04:07 +0000 (22:04 +0000)
hostside/README.commands
hostside/commands.c
hostside/movpos.c
hostside/safety.h

index 0d69e3f81f9281a12639d46b9612768db9bd0f63..fdf97c916723b911141186661d7741cb2acc50ef 100644 (file)
@@ -83,7 +83,9 @@ POSSIBLY-ASYNCHRONOUS REPORTING OF MESSAGES TO/FROM (MASTER) PIC
             <overallposn> may be ? for unknown
 
  U< ?debug <context> : <debug message>
- U< ?info : <informational message>
+
+ U< ?info [<stuff>] : <informational message>
+ U< ?info movfeat-collapsing-unknown <segment> : will set previously [etc.]
 
 MESSAGES TO SIMULATION LOG
 
@@ -167,6 +169,20 @@ MULTIPLEXER-IMPLEMENTED FUNCTIONALITY AFFECTING WHOLE SYSTEM
 
 ======================================================================
 
+INCOMPLETE LIST OF OTHER COMMANDS
+
+ route            <seg> <movposcomb>  [<maxms>]
+ route <before>|- <seg> <after>|-     [<maxms>]    any suitable movposcomb
+
+ route+ <as above>    change even segments owned by a train's route
+ route++ <as above>   even queue changes for segments currently under a train
+ !route <as above>    just do it, don't ask safety system
+
+ movfeat <seg> <feat> <posn> [<maxms>]
+ movfeat+ <as above>                           } see route+
+ movfeat++ <as above>                          } see route++
+ !movfeat                                      } see !route
+
 DIRECT NMRA AND PIC INSTRUCTIONS
 
                                             Example (always the same msg):
index 0fcc7a2d3636b02427975e58f6e432710d65a388..fc111a9e58a2f90ea57ac7a82def32f616601840 100644 (file)
@@ -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   },
index f02043e3e30dd23d014c759d19579e22f6405121..86954b85beb1117e4f7a4e4dfd867ec1bbdff6c7 100644 (file)
@@ -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;
+}
index 87305c4771561beaa620dfc78e2f235c169bfc16..452eaced5729b203dfbffebbb5e49d239a06e74a 100644 (file)
@@ -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,