From 91e54f6fc755f1cd0e431617422eccc49fd0080e Mon Sep 17 00:00:00 2001 From: ian Date: Sun, 13 Feb 2005 11:52:29 +0000 Subject: [PATCH] before throw away copy-without-segments-of-this-train --- hostside/safety.c | 17 ++++++++++++++--- hostside/safety.h | 14 +++++++------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/hostside/safety.c b/hostside/safety.c index d0f51c9..cc8ffac 100644 --- a/hostside/safety.c +++ b/hostside/safety.c @@ -4,7 +4,7 @@ #include "safety.h" -State safety_actual; +State *s, safety_buf[2]; typedef struct TrackLocation TrackLocation; struct TrackLocation { @@ -18,10 +18,22 @@ void trackfollow_further(TrackLocation *tloc, Distance *remain_io); * *remain_io becomes zero, or tloc->segi changes. */ void safety_train_changed(TrainIx trai) { - State *s = &safety_actual; TrainState *tra = s->tras[trai]; + State *try = &safety_buf[!(s-safety_buf)]; TrackLocation tloc; + try->tras= s->tras; + for (lsegi=0, dlseg=try->segs, slseg=s->segs; + lsegi < NUM_SEGMENTS; + lsegi++, dlseg++, slseg++) { + *dlseg = *slseg; + if (dlseg->owner == trai) { + dlseg->owner = NO_TRAIN; + dlseg->present_now = dlseg->present_future = + dlseg->detectable_now = dlseg->detectable_future = + dlseg->autostop = 0; + + tloc.segi= tra->foredetect; tloc.into= tra->justarrived ? JUSTARRIVED_DIST : @@ -31,7 +43,6 @@ s->trais[trai] SegmentState *seg = s->seg[segi]; void safety_notify_detection(SegmentIx segi) { - State *s = &safety_actual; SegmentState *seg = s->seg[segi]; TrainIx trai = segs->owner; TrainState *tra = s->tras[trai]; diff --git a/hostside/safety.h b/hostside/safety.h index f552218..bf6d276 100644 --- a/hostside/safety.h +++ b/hostside/safety.h @@ -5,8 +5,9 @@ typedef unsigned short TrainIx; typedef unsigned short SegmentIx; -typedef unsigned short Distance; -typedef unsigned char Speed; /* non-negative, units of 4mm/s */ +typedef unsigned short LocationIx; +typedef short Distance; +typedef char Speed; /* non-negative, units of 4mm/s */ typedef struct { SegmentIx foredetect; @@ -22,15 +23,15 @@ typedef struct { detectable_now:1, detectable_future:1, /* owning train draws current */ reverse:1, /* owning train's motion is (would be) backwards wrt track */ sideways:1, /* for segment with points, points are set to `alternative' */ - autostop:1; /* owning train is slow and should stop on detection */ - TrainIx owner; + autostop:1, /* owning train is slow and wants to stop on detection */ + updated:1; /* for use by safety_train_changed etc.; otherwise 0 */ /*polarity?*/ } SegmentState; - typedef struct { unsigned next_rev:1; SegmentIx next; + SegmentIx clashing; Distance dist; } SegmentLink; @@ -40,8 +41,7 @@ typedef struct { typedef struct { Speed maxspeed; - int n_detections; - const Distance *detections; /* incremental distances from rear */ + Distance tail, detectable, head; } TrainInfo; -- 2.30.2