SELKIELogger  1.0.0
Logger.h.in
1 #ifndef SL_LOGGER_H
2 #define SL_LOGGER_H
3 
4 #include <stdbool.h>
5 #include <stddef.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 
9 #include <errno.h>
10 #include <libgen.h>
11 #include <pthread.h>
12 #include <string.h>
13 #include <time.h>
14 #include <unistd.h>
15 
16 #include "SELKIELoggerBase.h"
17 #include "SELKIELoggerGPS.h"
18 #include "SELKIELoggerMQTT.h"
19 #include "SELKIELoggerNMEA.h"
20 #include "SELKIELoggerI2C.h"
21 
22 #include "version.h"
23 
31 #define DEFAULT_MON_PREFIX "@DEFAULT_MON_PREFIX@"
32 
34 #define DEFAULT_STATE_NAME "@DEFAULT_STATE_NAME@"
35 
37 #define DEFAULT_MARK_FREQUENCY @DEFAULT_MARK_FREQUENCY@
38 
40 #define DEFAULT_MARK_FREQ_STRING "@DEFAULT_MARK_FREQUENCY@"
41 
43 
51 #define SERIAL_SLEEP 1E3
52 
54 struct global_opts {
56  char *dataPrefix;
57  char *stateName;
58  bool saveState;
60  int coreFreq;
61 
62  // Not really options, but this is a convenient place to track them
63  FILE *monitorFile;
64  char *monFileStem;
65  FILE *varFile;
66 };
67 
69 typedef void *(*device_fn)(void *);
70 
72 typedef struct {
78 
80 
86 typedef struct {
87  char *tag;
88  char *type;
92  void *dParams;
93  int returnCode;
95 
97 
102 typedef struct {
103  unsigned int count;
104  uint32_t lastTimestamp;
106 } channel_stats;
107 
109 bool timespec_subtract(struct timespec *result, struct timespec *x, struct timespec *y);
110 
113 
115 void destroy_global_opts(struct global_opts *go);
116 
118 bool write_state_file(char *sFName, channel_stats stats[128][128], uint32_t lTS, char *vFName);
119 
120 #include "LoggerConfig.h" // Include first, so types are available below
121 
124 
125 #include "LoggerDW.h"
126 #include "LoggerGPS.h"
127 #include "LoggerLPMS.h"
128 #include "LoggerMP.h"
129 #include "LoggerMQTT.h"
130 #include "LoggerNet.h"
131 #include "LoggerNMEA.h"
132 #include "LoggerN2K.h"
133 #include "LoggerI2C.h"
134 #include "LoggerSerial.h"
135 #include "LoggerTime.h"
136 
137 #include "LoggerDMap.h" // Include after all data sources/devices defined
138 
139 #include "LoggerSignals.h"
140 
141 
143 #endif
void *(* device_fn)(void *)
Device specific callback functions.
Definition: Logger.h.in:69
bool timespec_subtract(struct timespec *result, struct timespec *x, struct timespec *y)
Difference between timespecs (used for rate keeping)
Definition: Logger.c:900
bool write_state_file(char *sFName, channel_stats stats[128][128], uint32_t lTS, char *vFName)
Write out the state file.
Definition: Logger.c:974
bool(* dc_parser)(log_thread_args_t *, config_section *)
Data source specific configuration parsers;.
Definition: Logger.h.in:123
bool log_softwareVersion(msgqueue *q)
Push current software version into message queue.
Definition: Logger.c:926
void destroy_global_opts(struct global_opts *go)
Cleanup function for global_opts struct.
Definition: Logger.c:943
Channel statistics.
Definition: Logger.h.in:102
unsigned int count
Number of messages received.
Definition: Logger.h.in:103
uint32_t lastTimestamp
Timestamp of last received message.
Definition: Logger.h.in:104
msg_t * lastMessage
Last message received.
Definition: Logger.h.in:105
Configuration file section.
Definition: LoggerConfig.h:54
Device specific function information.
Definition: Logger.h.in:72
device_fn logging
Main logging thread, passed to pthread_create()
Definition: Logger.h.in:74
device_fn startup
Called serially at startup, opens devices etc.
Definition: Logger.h.in:73
device_fn shutdown
Called on shutdown - close handles etc.
Definition: Logger.h.in:75
device_fn channels
Send a current channel map to the queue (optional)
Definition: Logger.h.in:76
General program options.
Definition: Logger.h.in:54
char * dataPrefix
File prefix for main log and data files (optionally prefixed by path)
Definition: Logger.h.in:56
int coreFreq
Core marker/timer frequency.
Definition: Logger.h.in:60
char * configFileName
Name of configuration file used.
Definition: Logger.h.in:55
char * stateName
Name (and optionally path) to state file for live data.
Definition: Logger.h.in:57
bool saveState
Enable / Disable use of state file. Default true.
Definition: Logger.h.in:58
char * monFileStem
Current serial numbered file prefix.
Definition: Logger.h.in:64
bool rotateMonitor
Enable / Disable daily rotation of main log and data files.
Definition: Logger.h.in:59
FILE * varFile
Current variables file.
Definition: Logger.h.in:65
FILE * monitorFile
Current data output file.
Definition: Logger.h.in:63
Logging thread information.
Definition: Logger.h.in:86
msgqueue * logQ
Main message queue. Pushed to by threads, consumed by main()
Definition: Logger.h.in:89
device_callbacks funcs
Callback information for this device/thread.
Definition: Logger.h.in:91
char * tag
Tag/source name for messages etc.
Definition: Logger.h.in:87
char * type
Data source type.
Definition: Logger.h.in:88
void * dParams
Device/Thread specific data.
Definition: Logger.h.in:92
program_state * pstate
Current program state, used for logging.
Definition: Logger.h.in:90
int returnCode
Thread return code (output)
Definition: Logger.h.in:93
Queuable message.
Definition: messages.h:71
Represent a simple FIFO message queue.
Definition: queue.h:51
Program state and logging information.
Definition: logging.h:40