chiark / gitweb /
hostside: more length for bavarian
[trains.git] / hostside / realtime.h
index 6b049f340a8cdad40b39a56caff54ff97f4fb322..d644ca21de773bdee6b1dc719fdb6551227b35e9 100644 (file)
 
 #include <fcntl.h>
 #include <dirent.h>
+#include <inttypes.h>
 
 #include <sys/types.h>
 #include <sys/time.h>
 
+#include "../.git-revid-autoversion.h"
 #include "../layout/layout-data.h"
 #include "realtime+dflags.h"
 
-typedef struct Segment Segment;
-typedef struct Train Train;
+typedef struct Segment Segment; /* from safety.h */
+typedef struct Train Train; /* from safety.h */
 typedef struct TimeoutEvent TimeoutEvent;
 
 /*---------- from retransmit.c ----------*/
@@ -36,7 +38,8 @@ typedef unsigned Retransmit__Time;
    * retransmit.c only; as a special exception, caller may edit pi
    * directly.  Normally, though, pi is set by supplying an NMRA
    * command to one of the _queue functions; iff the Nmra* is
-   * non-null, _queue will add an NMRA checksum and update pi.
+   * non-null, _queue will add an NMRA checksum (modifying *n)
+   * and update pi (which always results in a nonzero pi.l).
    */
 struct RetransmitRelaxedNode {
   PicInsn pi;
@@ -55,54 +58,59 @@ union RetransmitUrgentNode {
 void retransmit_start(void);
 void retransmit_something(void);
 
-void retransmit_relaxed_queue(RetransmitRelaxedNode *rn, Nmra *n);
-void retransmit_relaxed_requeue(RetransmitRelaxedNode *rn, Nmra *n);
-void retransmit_relaxed_cancel(RetransmitRelaxedNode *rn);
-
 void retransmit_urgent_queue(RetransmitUrgentNode *rn, Nmra *n);
 void retransmit_urgent_queue_relaxed(RetransmitUrgentNode *urg, Nmra *n);
 void retransmit_urgent_requeue(RetransmitUrgentNode *rn, Nmra *n);
 void retransmit_urgent_cancel(RetransmitUrgentNode *rn);
 
-  /* ... NB: these are NOT idempotent.  Use _requeue it's queued;
-   * _requeue is just _cancel followed by queue. */
+void retransmit_relaxed_queue(RetransmitRelaxedNode *rn, Nmra *n);
+void retransmit_relaxed_cancel(RetransmitRelaxedNode *rn);
+
+  /* ... NB: these are NOT idempotent and NOT interchangeable.  Use
+   * urgent_requeue if it's queued and has changed and must get a new
+   * quota of urgency; _requeue is just _cancel followed by queue. */
 
-/*---------- features, filled in by record, used by features.c ----------*/
+/*---------- adjuncts, filled in by record, used by adjuncts.c ----------*/
 
-#define FEATURESADDR_TRANSMITS 4
+#define ADJUNCTSADDR_TRANSMITS 4
   /* 0..2 are func0to4 func5to8 func9to12 and speed cmd
    * pi.l is 0 if not transmitting */
 
-typedef struct FeaturesAddr {
-  struct FeaturesAddr *next;
-  int addr, cbitmap;
-  RetransmitRelaxedNode rn[FEATURESADDR_TRANSMITS];
-} FeaturesAddr;
+#define ADJS_SPEEDSTEP_BIT     0x4000u /* a->{current,all,permit}, f->bits */
+#define ADJS_SPEEDSTEP_REVERSE 0x8000u /* in a->all */
+
+typedef struct AdjunctsAddr {
+  struct AdjunctsAddr *next;
+  int addr, speedstep;
+  unsigned current, permit, all;
+  RetransmitRelaxedNode rn[ADJUNCTSADDR_TRANSMITS];
+} AdjunctsAddr;
 
 typedef struct {
-  FeaturesAddr *a;
-  int bitval; /* may have no or several bits set */
-  int speedstep; /* -ve means backwards; 0 means not to use motor for feat */
-} FeaturesFeature;
-
-typedef struct FeaturesTarget {
-  struct FeaturesTarget *next;
-  char *pname;
-  char *featchs; /* null-terminated */
-  FeaturesFeature **feats; /* same order as featchs */
-} FeaturesTarget;
+  char *pname; /* first, for pname1st_compar */
+  AdjunctsAddr *a;
+  unsigned bits; /* may have no or several bits set */
+} AdjunctsAdjunct;
+
+typedef struct AdjunctsTarget {
+  char *pname; /* first, for pname1st_compar */
+  int n_adjs;
+  AdjunctsAdjunct *adjs;
+} AdjunctsTarget;
 
 extern int n_trains;
 extern Train *trains;
 extern Segment *segments;
 
-extern FeaturesTarget *feattargs;
-extern FeaturesAddr *feataddrs;
+extern int n_adjtargs, n_adjaddrs;
+extern AdjunctsTarget *adjtargs;
+extern AdjunctsAddr **adjaddrs;
 
 /*---------- global variables, in realtime.c ----------*/
 
 extern CommandInput cmdi;
 extern int picio_send_noise;
+extern int disable_watchdog;
 
 #define CIXF_U                 0x0000ffffu
 #define CIXF_FORCE             0x00010000u
@@ -118,6 +126,7 @@ void serial_moredata(PicInsn *buf);
 
 extern StartupState sta_state;
 extern const char *const stastatelist[];
+void cmdi_output_bufferempty(OutBufferChain *obc);
 
 void resolve_begin(void); /* from resolve.c */
 int resolve_complete(void);
@@ -142,13 +151,16 @@ void persist_map_veryearly(void);
 
 void oupicio(const char *dirn, const PicInsnInfo *pii, int obj, int v,
             void (*qprintf)(const char *fmt, ...));
-void ouhexi(const char *word, const Byte *command, int length);
-void ouhexo(const char *word, const Byte *command, int length);
+void ouhex(const char *word, const Byte *command, int length);
+void ouhex_nosim(const char *word, const Byte *command, int length);
 
 void serial_transmit(const PicInsn *pi);
 void command_doline(ParseState *ps, CommandInput *cmdi_arg);
 const CmdInfo *current_cmd;
 
+void check_rusage_baseline(void);
+void check_rusage_check(int always_report);
+
 /*---------- for/from simulate.c ----------*/
 
 void serial_indata_process(int buf_used);
@@ -181,10 +193,14 @@ int picinsn_polarity_testbit(const PicInsn *pi, const SegmentInfo *segi);
   /* this belongs in {au,skel}proto-pic.[ch] really but it's
    * more convenient here. */
 
+void adjuncts_start_xmit(void);
+void adjuncts_updated(AdjunctsAddr *a);
+
 /*---------- from movpos.c ----------*/
 
 void points_turning_on(void);
 void motions_all_abandon(void);
+void movpos_reportall(void);
 
 /*---------- from eventhelp.c ----------*/
 
@@ -213,9 +229,10 @@ void toev_stop(TimeoutEvent*);    /* IR -> I */
 
 void realtime_priority(void);
 
-#define RTFEAT_DEFAULTS  0100u /* turns on MLOCK and SCHEDPRIO iff not sim */
+#define RTFEAT_DEFAULTS  0100u /* turns things on iff not sim */
 #define RTFEAT_MEM       0001u /* mlock */
 #define RTFEAT_CPU       0002u /* hard CPU scheduling priority */
+#define RTFEAT_RUSAGE    0004u /* check up on faults etc. in getrusage */
 
 #define RTFEAT_ALL_SHIFT 16
 #define RTFEAT_ALL(x) (RTFEAT_##x << RTFEAT_ALL_SHIFT)
@@ -224,20 +241,29 @@ void realtime_priority(void);
 
 extern unsigned rtfeats_use;
 
-void ouvprintf(const char *fmt, va_list al);
-void ouprintf(const char *fmt, ...);
+void ouvprintf(const char *fmt, va_list al)
+     __attribute__((format(printf,1,0)));
+void ouprintf(const char *fmt, ...)
+     __attribute__((format(printf,1,2)));
+
+void ouvprintf_only(const char *fmt, va_list al)
+     __attribute__((format(printf,1,0)));
+void ouprintf_only(const char *fmt, ...)
+     __attribute__((format(printf,1,2)));
 
-void ouvprintf_only(const char *fmt, va_list al);
-void ouprintf_only(const char *fmt, ...);
+extern unsigned long eventcounter; /* for debugging use only ! */
+void debug_count_event(const char *what);
 
 #define DEBUGP(a,k) (dflags_##a & DBIT_##a##_##k)
 
+#define DPRINTFA ouprintf_only
+
 #define COND_DPRINTF(cond, a,k, fmt, ...) \
- ((cond) ? ouprintf_only("debug " #a "/" #k " : " fmt,##__VA_ARGS__) : (void)0)
+ ((cond) ? DPRINTFA("debug " #a "/" #k " : " fmt,##__VA_ARGS__) : (void)0)
 
 #define DPRINTF(a,k,f,...) COND_DPRINTF(DEBUGP(a,k),a,k,f,##__VA_ARGS__)
 #define DPRINTF1(a,k,f,...) COND_DPRINTF((DP)=DEBUGP(a,k), a,k,f,##__VA_ARGS__)
-#define DPRINTF2(f,...) ((DP) ? ouprintf_only(f,##__VA_ARGS__) : (void)0)
+#define DPRINTF2(f,...) ((DP) ? DPRINTFA(f,##__VA_ARGS__) : (void)0)
 
 /*---------- tbi ----------*/