chiark / gitweb /
wip
[trains.git] / hostside / safety.h
1 /**/
2
3 #ifndef SAFETY_H
4 #define SAFETY_H
5
6 typedef unsigned short TrainIx;
7 typedef unsigned short SegmentIx;
8 typedef unsigned short Distance;
9 typedef unsigned char Speed; /* non-negative, units of 4mm/s */
10
11 typedef struct {
12   SegmentIx foredetect;
13   unsigned justarrived:1, reverse:1;
14   Speed speed;
15 } TrainState;
16
17 typedef struct {
18   unsigned present_now:1, present_future:1,
19     detectable_now:1, detectable_future:1,
20     sideways:1, autostop:1;
21   TrainIx owner;
22   /*polarity?*/
23 } SegmentState;
24
25
26 typedef struct {
27   unsigned next_rev:1;
28   SegmentIx next;
29   Distance dist;
30 } SegmentLink;
31
32 typedef struct {
33   SegmentLink backwards, forwards, sideways;
34 } SegmentInfo;
35
36 typedef struct {
37   Speed maxspeed;
38   int n_detections;
39   const Distance *detections;   /* incremental distances from front */
40 } TrainInfo;
41
42
43 typedef struct {
44   TrainState trasNUM_TRAINS];
45   SegmentState segs[NUM_SEGMENTS];
46 } State;
47
48 #endif /*SAFETY_H*/