chiark / gitweb /
wip reorg with new scalars instead of justarrive
[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 TimeInterval;
10 typedef short Distance;
11 typedef char Speed; /* non-negative, units of 4mm/s */
12
13 typedef struct {
14   SegmentNum foredetect; /* train's detectable part is at most maxinto */
15   Distance maxinto, uncertainty; /* into foredetect but train may be */
16   unsigned                       /* uncertainty less far advanced */
17     backwards:1; /* train is moving backwards wrt its own front and back */
18   Speed speed;
19 } TrainState;
20
21 typedef struct {
22   unsigned
23     owned:1, /* this track segment is reserved for a train */
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     pt_moving:1, /* points have been told to change, sideways is new state */
27     autostop:1, /* owning train is slow and wants to stop on detection */
28     tr_updated:1; /* for use by safety_train_changed etc.; otherwise 0 */
29   TimeInterval until_here, /* ) nonnegative; */  /* ) always valid but */
30     until_detect;          /* ) 0 if already */  /* )  only meaningful */
31   TrainNum owner;                                /* )  iff owned       */
32   /*polarity?*/
33 } SegmentState;
34
35 typedef struct {
36   unsigned next_backwards:1;
37   SegmentNum next;
38   Distance dist;
39 } SegmentLinkInfo;
40
41 typedef struct {
42   SegmentLink backwards, forwards, sideways;
43 } SegmentInfo;
44
45 typedef struct {
46   Speed maxspeed;
47   Distance tail, detectable, head;
48 } TrainInfo;
49
50 extern const TrainInfo info_train[NUM_TRAINS];
51 extern const SegmentInfo info_segment[NUM_SEGMENTS];
52
53 typedef struct {
54   TrainState tras[NUM_TRAINS];
55   SegmentState segs[NUM_SEGMENTS];
56 } State;
57
58 #endif /*SAFETY_H*/