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