chiark / gitweb /
wip
authorian <ian>
Sat, 12 Feb 2005 14:12:18 +0000 (14:12 +0000)
committerian <ian>
Sat, 12 Feb 2005 14:12:18 +0000 (14:12 +0000)
hostside/safety.c
hostside/safety.h

index cbd5c280175cd30ab787d6c3af4e9e65d93aa8a4..a73bf2ef09aa27d79cbea3a2f628a95595663b71 100644 (file)
@@ -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) {
index 7e7100eecd342ede55ebee4e4736d44111b63d1f..1825811dcf0331f5da759a182f3343d68df582f4 100644 (file)
@@ -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*/