From: ian Date: Sat, 12 Feb 2005 14:12:18 +0000 (+0000) Subject: wip X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=8b54071f373f76e88bfb4d542332a7264280733b;p=trains.git wip --- diff --git a/hostside/safety.c b/hostside/safety.c index cbd5c28..a73bf2e 100644 --- a/hostside/safety.c +++ b/hostside/safety.c @@ -4,12 +4,50 @@ #include "safety.h" +State safety_actual; -void safety_notify_detection(State *s, SegmentIx seg) { - if (s->seg[seg].detectable_now) return; - if (!s->seg[seg].detectable_future) - panic(NONE, seg, "unexpected detection"); +void safety_train_changed(TrainIx trai) { + State *s = &safety_actual; + TrainState *tra = s->tras[trai]; + for (segi = +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]; + + if (seg->detectable_now) return; + if (!seg->detectable_future) + safety_panic(NONE, segi, "unexpected detection"); + + tra->foredetect= segi; + tra->justarrived= 0; + + if (seg->autostop) { + actual_setspeed(trai, 0); + tra->justarrived= 1; + } + + ec= safety_train_changed(trai); + if (ec) { + logmsg(trai, segi, "emergency stop"); + actual_emergencystop(trai); + tra->justarrived= 0; + ec= safety_train_changed(s, trai); + if (ec) panic(trai, segi, "emergency stop insufficient!"); + } +} + + + + + + + own int main(void) { diff --git a/hostside/safety.h b/hostside/safety.h index 7e7100e..1825811 100644 --- a/hostside/safety.h +++ b/hostside/safety.h @@ -5,10 +5,11 @@ typedef unsigned short TrainIx; typedef unsigned short SegmentIx; +typedef unsigned short Distance; typedef unsigned char Speed; /* non-negative, units of 4mm/s */ typedef struct { - SegmentIx foremost; + SegmentIx foredetect; unsigned justarrived:1, reverse:1; Speed speed; } TrainState; @@ -16,7 +17,7 @@ typedef struct { typedef struct { unsigned present_now:1, present_future:1, detectable_now:1, detectable_future:1, - sideways:1; + sideways:1, autostop:1; TrainIx owner; /*polarity?*/ } SegmentState; @@ -25,22 +26,23 @@ typedef struct { typedef struct { unsigned next_rev:1; SegmentIx next; - + Distance dist; } SegmentLink; typedef struct { - SegmentIx backwards, forwards, sideways; + SegmentLink backwards, forwards, sideways; } SegmentInfo; typedef struct { Speed maxspeed; - + int n_detections; + const Distance *detections; /* incremental distances from front */ } TrainInfo; typedef struct { - TrainState traNUM_TRAINS]; - SegmentState seg[NUM_SEGMENTS]; + TrainState trasNUM_TRAINS]; + SegmentState segs[NUM_SEGMENTS]; } State; #endif /*SAFETY_H*/