chiark / gitweb /
c5c152635c1efa7b07eda1242de4cbcc3ac679f0
[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 /*---------- global variables, in realtime.c ----------*/
77
78 extern CommandInput cmdi;
79 extern int picio_send_noise;
80
81 #define UPO (&(cmdi.out))
82
83 /*---------- from/for startup.c ----------*/
84
85 #include "stastate.h"
86
87 void sta_startup(void);
88 void serial_moredata(PicInsn *buf);
89
90 extern StartupState sta_state;
91 extern const char *const stastatelist[];
92
93 void resolve_begin(void); /* from resolve.c */
94 int resolve_complete(void);
95
96 /*---------- from/for record.c and persist.c ----------*/
97
98 void records_parse(const char **argv);
99 void persist_entrails_interpret(void);
100 void persist_entrails_run_converter(void);
101 void persist_install(void);
102
103 extern const char *persist_fn;
104 extern char *persist_record_converted;
105
106 void persist_map_veryearly(void);
107
108 /*---------- from/for realtime.c ----------*/
109
110 void oupicio(const char *dirn, const PicInsnInfo *pii, int objnum);
111 void ouhex(const char *word, const Byte *command, int length);
112
113 void serial_transmit(const PicInsn *pi);
114 int ps_needsegment(ParseState *ps, Segment **seg_r,
115                    const SegmentInfo **segi_r);
116
117 /*---------- from actual.c ----------*/
118
119 int picinsn_polarity_testbit(const PicInsn *pi, const SegmentInfo *segi);
120   /* this belongs in {au,skel}proto-pic.[ch] really but it's
121    * more convenient here. */
122
123 /*---------- from movpos.c ----------*/
124
125 void points_turning_on(void);
126 void points_all_abandon(void);
127
128 /*---------- tbi ----------*/
129
130 void choreographers_all_abandon(void);
131
132
133 #include "record.h"
134
135 #define PERSIST_CONVERT_OPTION "--persist-convert-entrails"
136
137 #include "safety.h"
138
139
140 #endif /*REALTIME_H*/