chiark / gitweb /
giant reorg abolishes TrainNum most of the time; working on making it build
[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
23 #include "../layout/layout-data.h"
24
25 typedef struct Segment Segment;
26 typedef struct Train Train;
27
28 /*---------- from retransmit.c ----------*/
29
30 typedef struct RetransmitRelaxedNode RetransmitRelaxedNode;
31 typedef union RetransmitUrgentNode RetransmitUrgentNode;
32 typedef unsigned Retransmit__Time;
33
34 struct RetransmitRelaxedNode { /* all for use by retransmit.c only */
35   PicInsn pi;
36   DLIST_NODE(RetransmitRelaxedNode) rr;
37 };
38 union RetransmitUrgentNode { /* all for use by retransmit.c only */
39   PicInsn pi;
40   struct {
41     RetransmitRelaxedNode relaxed;
42     int ix;
43     Retransmit__Time when;
44     DLIST_NODE(RetransmitUrgentNode) queue;
45   } u;
46 };
47
48 void retransmit_relaxed_queue(RetransmitRelaxedNode *rn, const Nmra *n);
49 void retransmit_relaxed_requeue(RetransmitRelaxedNode *rn, const Nmra *n);
50 void retransmit_relaxed_cancel(RetransmitRelaxedNode *rn);
51
52 void retransmit_urgent_queue(RetransmitUrgentNode *rn, const Nmra *n);
53 void retransmit_urgent_queue_relaxed(RetransmitUrgentNode *urg, const Nmra *n);
54 void retransmit_urgent_requeue(RetransmitUrgentNode *rn, const Nmra *n);
55 void retransmit_urgent_cancel(RetransmitUrgentNode *rn);
56
57   /* ... NB: these are NOT idempotent.  Use _requeue it's queued;
58    * _requeue is just _cancel followed by queue. */
59
60 /*---------- global variables, in realtime.c ----------*/
61
62 extern CommandInput cmdi;
63
64 #define UPO (&(cmdi.out))
65
66 /*---------- from/for startup.c ----------*/
67
68 typedef enum {   /* sta_toev   ping_toev    */
69   Sta_Flush,     /*  R 300      I ?         */
70   Sta_Off,       /*  I ?        I ?         */
71   Sta_Ping,      /*  I ?        I ?         */
72   Sta_Fault,     /*  I ?        R set       */
73   Sta_Settling,  /*  I ?        R set       */
74   Sta_Resolving, /*  I ?        R set       */
75   Sta_Run        /*  I ?        R set       */
76 } StartupState;
77
78 void sta_startup(void);
79 void serial_moredata(PicInsn *buf);
80
81 extern StartupState sta_state;
82
83 /*---------- from/for record.c ----------*/
84
85 void records_parse(const char **argv);
86
87 /*---------- from/for realtime.c ----------*/
88
89 void oupicio(const char *dirn, const PicInsnInfo *pii, int objnum);
90 void ouhex(const char *word, const Byte *command, int length);
91
92 void serial_transmit(const PicInsn *pi);
93
94 /*---------- from actual.c ----------*/
95
96 int picinsn_polarity_testbit(const PicInsn *pi, const SegmentInfo *segi);
97   /* this belongs in {au,skel}proto-pic.[ch] really but it's
98    * more convenient here. */
99
100 /*---------- tbi ----------*/
101
102 void abandon_run(void);
103
104
105 #include "safety.h"
106
107
108 #endif /*REALTIME_H*/