chiark / gitweb /
train changed wip going well
[trains.git] / hostside / safety.h
1 /**/
2
3 #ifndef SAFETY_H
4 #define SAFETY_H
5
6 typedef unsigned short TrainNum;
7 typedef unsigned short SegmentNum;
8 typedef unsigned short LocationNum;
9 typedef short Distance;
10 typedef char Speed; /* non-negative, units of 4mm/s */
11
12 typedef struct {
13   SegmentNum foredetect;
14   unsigned
15     justarrived:1, /* is stopped just after triggering foredetect segment */
16     backwards:1; /* train is moving backwards wrt its own front and back */
17   Speed speed;
18 } TrainState;
19
20 typedef struct {
21   unsigned
22     tr_detect_now:1, tr_detect_future:1, /* owning train draws current */
23     tr_here_now:1, tr_here_future:1, /* owning train is or will use space */
24     tr_backwards:1, /* train's motion is (would be) backwards wrt track */
25     pt_sideways:1, /* points are set to `alternative'. (no points?: 0) */
26     tr_autostop:1, /* owning train is slow and wants to stop on detection */
27     tr_updated:1; /* for use by safety_train_changed etc.; otherwise 0 */
28   /*polarity?*/
29   TrainNum tran; /* always valid but only meaningful iff tr_here_future */
30 } SegmentState;
31
32 typedef struct {
33   unsigned next_rev:1;
34   SegmentNum next;
35   SegmentNum clashing;
36   Distance dist;
37 } SegmentLinkInfo;
38
39 typedef struct {
40   SegmentLink backwards, forwards, sideways;
41 } SegmentInfo;
42
43 typedef struct {
44   Speed maxspeed;
45   Distance tail, detectable, head;
46 } TrainInfo;
47
48 extern const TrainInfo info_train[NUM_TRAINS];
49 extern const SegmentInfo info_segment[NUM_SEGMENTS];
50
51 typedef struct {
52   TrainState tras[NUM_TRAINS];
53   SegmentState segs[NUM_SEGMENTS];
54 } State;
55
56 #endif /*SAFETY_H*/