chiark / gitweb /
new resolution arrangements
[trains.git] / hostside / realtime.h
1 /*
2  * declarations for realtime daemon
3  */
4
5 #ifndef REALTIME_H
6 #define REALTIME_H
7
8 #include "daemons.h"
9 #include "auproto-pic.h"
10 #include "dliste.h"
11
12 #include <stdarg.h>
13 #include <string.h>
14 #include <errno.h>
15 #include <assert.h>
16 #include <stdlib.h>
17 #include <limits.h>
18 #include <stddef.h>
19
20 #include <sys/types.h>
21 #include <sys/time.h>
22 #include <sys/stat.h>
23 #include <sys/mman.h>
24 #include <sys/wait.h>
25
26 #include <unistd.h>
27 #include <fcntl.h>
28 #include <dirent.h>
29
30 #include "../layout/layout-data.h"
31
32 typedef struct Segment Segment;
33 typedef struct Train Train;
34
35 /*---------- from retransmit.c ----------*/
36
37 typedef struct RetransmitRelaxedNode RetransmitRelaxedNode;
38 typedef union RetransmitUrgentNode RetransmitUrgentNode;
39 typedef unsigned Retransmit__Time;
40
41   /* Contents of the retransmission nodes is generally all for use by
42    * retransmit.c only; as a special exception, caller may edit pi
43    * directly.  Normally, though, pi is set by supplying an NMRA
44    * command to one of the _queue functions; iff the Nmra* is
45    * non-null, _queue will add an NMRA checksum and update pi.
46    */
47 struct RetransmitRelaxedNode {
48   PicInsn pi;
49   DLIST_NODE(RetransmitRelaxedNode) rr;
50 };
51 union RetransmitUrgentNode {
52   PicInsn pi;
53   struct {
54     RetransmitRelaxedNode relaxed;
55     int ix;
56     Retransmit__Time when;
57     DLIST_NODE(RetransmitUrgentNode) queue;
58   } u;
59 };
60
61 void retransmit_start(void);
62 void retransmit_something(void);
63
64 void retransmit_relaxed_queue(RetransmitRelaxedNode *rn, Nmra *n);
65 void retransmit_relaxed_requeue(RetransmitRelaxedNode *rn, Nmra *n);
66 void retransmit_relaxed_cancel(RetransmitRelaxedNode *rn);
67
68 void retransmit_urgent_queue(RetransmitUrgentNode *rn, Nmra *n);
69 void retransmit_urgent_queue_relaxed(RetransmitUrgentNode *urg, Nmra *n);
70 void retransmit_urgent_requeue(RetransmitUrgentNode *rn, Nmra *n);
71 void retransmit_urgent_cancel(RetransmitUrgentNode *rn);
72
73   /* ... NB: these are NOT idempotent.  Use _requeue it's queued;
74    * _requeue is just _cancel followed by queue. */
75
76 /*---------- features, filled in by record, used by features.c ----------*/
77
78 typedef struct {
79   int addr, cbitmap;
80   RetransmitRelaxedNode rn[4]; /* nmra feat setting cmds and speed cmd */
81 } FeaturesAddr;
82
83 typedef struct {
84   FeaturesAddr *a;
85   int bitval; /* may have no or several bits set */
86   int speedstep; /* -ve means backwards; 0 means not to use motor for feat */
87 } FeaturesFeature;
88
89 typedef struct {
90   char *pname;
91   char *featchs; /* null-terminated for convenience; _ means unused */
92   FeaturesFeature *feats; /* same order as featchs */
93 } FeaturesTarget;
94
95 extern int n_trains;
96 extern Train *trains;
97 extern Segment *segments;
98 extern int n_feattargs;
99 extern FeaturesTarget *feattargs;
100
101 /*---------- global variables, in realtime.c ----------*/
102
103 extern CommandInput cmdi;
104 extern int picio_send_noise;
105
106 #define UPO (&(cmdi.out))
107
108 /*---------- from/for startup.c ----------*/
109
110 #include "stastate.h"
111
112 void sta_startup(void);
113 void sta_finalising_done(void);
114 void serial_moredata(PicInsn *buf);
115
116 extern StartupState sta_state;
117 extern const char *const stastatelist[];
118
119 void resolve_begin(void); /* from resolve.c */
120 int resolve_complete(void);
121 void resolve_motioncheck(void);
122
123 /*---------- from/for record.c and persist.c ----------*/
124
125 void records_parse(const char **argv);
126 void persist_entrails_interpret(void);
127 void persist_entrails_run_converter(void);
128 void persist_install(void);
129
130 extern const char *persist_fn;
131 extern char *persist_record_converted;
132
133 void persist_map_veryearly(void);
134
135 /*---------- from/for realtime.c ----------*/
136
137 void oupicio(const char *dirn, const PicInsnInfo *pii, int objnum);
138 void ouhex(const char *word, const Byte *command, int length);
139
140 void serial_transmit(const PicInsn *pi);
141 int ps_needsegment(ParseState *ps, Segment **seg_r,
142                    const SegmentInfo **segi_r);
143
144 /*---------- from actual.c ----------*/
145
146 int picinsn_polarity_testbit(const PicInsn *pi, const SegmentInfo *segi);
147   /* this belongs in {au,skel}proto-pic.[ch] really but it's
148    * more convenient here. */
149
150 /*---------- from movpos.c ----------*/
151
152 void points_turning_on(void);
153 void points_all_abandon(void);
154
155 /*---------- tbi ----------*/
156
157 void choreographers_all_abandon(void);
158
159
160 #include "record.h"
161
162 #define PERSIST_CONVERT_OPTION "--persist-convert-entrails"
163
164 #include "safety.h"
165
166
167 #endif /*REALTIME_H*/