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
14     justarrived:1, /* is stopped just after triggering foredetect segment */
15     reverse:1; /* train is moving backwards wrt its own front and back */
16   Speed speed;
17 } TrainState;
18
19 typedef struct {
20   unsigned
21     present_now:1, present_future:1, /* owning train is or will use space */
22     detectable_now:1, detectable_future:1, /* owning train draws current */
23     reverse:1, /* owning train's motion is (would be) backwards wrt track */
24     sideways:1, /* for segment with points, points are set to `alternative' */
25     autostop:1; /* owning train is slow and should stop on detection */
26   TrainIx owner;
27   /*polarity?*/
28 } SegmentState;
29
30
31 typedef struct {
32   unsigned next_rev:1;
33   SegmentIx next;
34   Distance dist;
35 } SegmentLink;
36
37 typedef struct {
38   SegmentLink backwards, forwards, sideways;
39 } SegmentInfo;
40
41 typedef struct {
42   Speed maxspeed;
43   int n_detections;
44   const Distance *detections; /* incremental distances from rear */
45 } TrainInfo;
46
47
48 typedef struct {
49   TrainState trasNUM_TRAINS];
50   SegmentState segs[NUM_SEGMENTS];
51 } State;
52
53 #endif /*SAFETY_H*/