chiark / gitweb /
show ownerships
authorian <ian>
Thu, 24 Apr 2008 18:46:15 +0000 (18:46 +0000)
committerian <ian>
Thu, 24 Apr 2008 18:46:15 +0000 (18:46 +0000)
hostside/README.commands
hostside/TODO
hostside/resolve.c
hostside/safety.c
hostside/safety.h

index 1aea6997f9895cb6d0fd64b63daa0af18064807a..74c368a5bcf56a1a6b9e4c0975a9e95f2a757cfd 100644 (file)
@@ -43,8 +43,14 @@ POSSIBLY-ASYNCHRONOUS REPORTING OF MESSAGES TO/FROM (MASTER) PIC
  U< warning watchdog : PIC watchdog timer triggered
  U< warning spurious <count> : spurious short circuit (fault) etc.
 
- U< signalling-problem <train> <foredet> ....
- U< signalling-problem <train> <foredet> detection <nowdet> : <message>
+ U< train <train> signalling-problem ....
+ U< train <train> signalling-problem <problematic-segment> : <message>
+
+ U< train <train> forwards|backwards at [-]<segment>:<maxinto>+-<uncertainty>
+ U< train <train> has <markchar>[-]<segment>[/<movposcomb>]....
+       <markchar> is * for det_expected
+                     ! for foredetect
+                     @ for det_ignore
 
  U< movpos <segment> point <feat><posn>
  U< movpos <segment> position <overallposn> moving
index 5f85828594162446d9bfc5014f4f04dbd767909a..566d1eae833faaaf3c821a4e37b3b6ea855c2e80 100644 (file)
@@ -1,6 +1,4 @@
 want to
-       say something from prediction when we confirm a plan
-               at least segment ownership and intended movposcombs
        document commands [!]movfeat and speed
        stop all trains command ?
 
index be94f48e7bbf00dc4a3a00b0ebdd9c5df0f54bd4..782ff58282844d74a50ecb6ce965c57a8908a461 100644 (file)
@@ -351,6 +351,7 @@ int resolve_complete(void) {
 
 typedef struct {
   Train *train;
+  Segment *furthest;
   int extraspace;
 } FindEndUserContext;
 
@@ -363,6 +364,7 @@ static int findhead_nextseg(TrackLocation *t, struct TrackAdvanceContext *c,
                            MovPosComb *mpc_io, Segment *before) {
   FindEndUserContext *u= c->u;
   if (t->seg->owner != u->train) return -1;
+  u->furthest= t->seg;
   if (!t->seg->res_detect) { u->extraspace= 0; return -1; }
   
   u->train->foredetect= t->seg;
@@ -404,6 +406,7 @@ static void resolve_train_finalise(Segment *startpoint) {
   tc.u= &u;
 
   u.extraspace= MARGIN_NOSE + tra->head;
+  u.furthest= 0;
 
   r= findhead_nextseg(&t,&tc,0,0); assert(!r);
   trackloc_advance(&t,&tc);
@@ -435,12 +438,17 @@ static void resolve_train_finalise(Segment *startpoint) {
   }
 
   FOR_SEG {
-    seg->owner= 0;
+    if (seg->owner == tra)
+      seg->owner= 0;
+
     if (seg->resfin_done) {
       seg->owner= tra;
       seg->resfin_done= 0;
     }
   }
+
+  report_train_position(tra);
+  report_train_ownerships(tra, u.furthest);
 }
   
 
index d14bd557ef28d449571ad962ee93904aef935176..1d10d4019ef9ba8227cf9100d0d1fd25175cecc4 100644 (file)
@@ -234,6 +234,7 @@ typedef struct {
   unsigned
     count_time:1,
     accelerating:1,
+    usecurrentposn:1, /* for pred_getmovpos */
     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 */
@@ -242,6 +243,7 @@ typedef struct {
   TrackAdvanceContext nosec, tailc, fdetc;
   TimeInterval elapsed; /* from now, minimum */
   Distance was_distance;
+  Segment *furthest;
 
   PredictionProblemCallback *problem_callback;
   void *problem_callback_u;
@@ -289,6 +291,7 @@ static ErrorCode predict_problem(PredictUserContext *u, Segment *seg,
 static int pred_getmovpos(TrackLocation *t, TrackAdvanceContext *c,
                          MovPosComb *use_io) {
   PredictUserContext *u= c->u;
+  if (u->usecurrentposn) return 0;
   if (t->seg->motion) *use_io= movpos_change_intent(t->seg->motion);
   if (*use_io<0) safety_panic(u->train, t->seg,
                              "track route unexpectedly not known");
@@ -406,6 +409,7 @@ static int nose_nextseg(TrackLocation *t, TrackAdvanceContext *c,
   t->seg->tr_backwards= t->backwards;
   t->seg->pred_present= 1;
   t->seg->until= u->elapsed;
+  u->furthest= t->seg;
   return 0; /* yay! */
 }
 
@@ -525,6 +529,77 @@ static int fdet_nextseg(TrackLocation *t, TrackAdvanceContext *c,
   return 0;
 }
 
+/*---------- reporting position and ownership ----------*/
+
+void report_train_position(Train *tra) {
+  oprintf(UPO, "train %s %s at %s%s:%d+-%d",
+         tra->pname, tra->backwards ? "backwards" : "forwards",
+         tra->foredetect->tr_backwards?"-":"",
+         tra->foredetect->i->pname, tra->maxinto, tra->uncertainty);
+}  
+  
+static int report_nextseg(TrackLocation *t, struct TrackAdvanceContext *c,
+                         MovPosComb *mpc, Segment *before) {
+  PredictUserContext *u= c->u;
+  char flags[6];
+  int r;
+
+  if (t->seg->owner != u->train) return -1;
+  if (u->usecurrentposn && !t->seg->det_ignore)
+    /* We've gone back past our own tail into the place where our
+     * head is going to be in the far future.  Confusing, eh ? */
+    return -1;
+
+  if (t->seg->det_expected)
+    strcat(flags,"*");
+  if (t->seg == u->train->foredetect) {
+    strcat(flags,"!");
+    u->usecurrentposn=1;
+  }
+  if (t->seg->det_ignore)
+    strcat(flags,"@");
+  if (t->seg->tr_backwards)
+    strcat(flags,"-");
+
+  oprintf(UPO," %s%s",flags,t->seg->i->pname);
+
+  if (t->seg->i->n_poscombs > 1) {
+    r= pred_getmovpos(t,c,mpc);  assert(!r);
+    oprintf(UPO,"/%s", t->seg->i->poscombs[*mpc].pname);
+  }
+
+  return 0;
+}
+
+void report_train_ownerships(Train *tra, Segment *furthest) {
+  PredictUserContext u;
+  MovPosComb mpc;
+  int r;
+
+  memset(&u,0,sizeof(u));
+  u.train= tra;
+  u.furthest= furthest;
+  u.usecurrentposn= 0;
+  
+  /* Walk backwards along the train printing its segments: */
+  oprintf(UPO, "train %s has", tra->pname);
+  
+  u.tail.seg= furthest;
+  u.tail.remain= 0;
+  u.tail.backwards= !u.tail.seg->tr_backwards;
+
+  u.tailc.distance= INT_MAX;;
+  u.tailc.nextseg= report_nextseg;
+  u.tailc.getmovpos= pred_getmovpos;
+  u.tailc.u= &u;
+
+  mpc= furthest->movposcomb;
+  r= report_nextseg(&u.tail,&u.tailc,&mpc,0);  assert(!r);
+  trackloc_advance(&u.tail,&u.tailc);
+  oprintf(UPO, "\n");
+}
+  
+
 /*---------- prediction entrypoint ----------*/
 
 ErrorCode predict_confirm(Train *tra, int accelerate,
@@ -548,6 +623,8 @@ ErrorCode predict_confirm(Train *tra, int accelerate,
   u.train_polarity_inverted= foredet->seg_inverted ^ foredet->tr_backwards;
   u.problem_callback= ppc;
   u.problem_callback_u= ppcu;
+  u.furthest= tra->foredetect;
+  u.usecurrentposn= 1;
 
   u.fdetc.getmovpos= pred_getmovpos;
   u.tailc.getmovpos= pred_getmovpos;
@@ -628,6 +705,7 @@ ErrorCode predict_confirm(Train *tra, int accelerate,
   if (u.need_polarise)
     actual_inversions_done();
 
+  report_train_ownerships(tra,u.furthest);
   return 0;
 
  xproblem:
@@ -647,8 +725,8 @@ ErrorCode predict_confirm(Train *tra, int accelerate,
 
 static void detection_report_problem(Train *tra, Segment *seg,
                                     void *pu, const char *message) {
-  oprintf(UPO, "signalling-problem %s @%s detection @%s : %s",
-         tra->pname, tra->foredetect->i->pname, seg->i->pname, message);
+  oprintf(UPO, "train %s signalling-problem %s : %s",
+         tra->pname, seg->i->pname, message);
 }
 
 void safety_notify_detection(Segment *seg) {
@@ -667,6 +745,8 @@ void safety_notify_detection(Segment *seg) {
   tra->uncertainty= tra->maxinto=
     seg->i->poscombs[seg->movposcomb].dist;
 
+  report_train_position(tra);
+
   ec= predict_confirm(tra, 0, detection_report_problem, 0);
   if (!ec) return;
 
index 8072dfd077251dcfe6e3cf3a8dacf6026e43a7fd..09eb2b18aa739bd5278480b14d7187fe3fa7065e 100644 (file)
@@ -115,6 +115,12 @@ ErrorCode predict_confirm(Train *tra, int accelerate,
    * cause safety_panic if it fails.
    */
 
+void report_train_position(Train *tra);
+void report_train_ownerships(Train *tra, Segment *furthest);
+  /* ... for use by things which update these only, which
+   * is basically safety.c and resolve.c */
+
+
 /*========== movpos.c ==========*/
 /*
  * movpos.c manages the CDU and points and other moveable features.