RocketLogger  1.1
types.h
Go to the documentation of this file.
1 
31 #ifndef TYPES_H_
32 #define TYPES_H_
33 
34 // INCLUDES
35 
36 // standard
37 #include <ctype.h>
38 #include <errno.h>
39 #include <stdarg.h>
40 #include <stdint.h>
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <string.h>
44 #include <unistd.h>
45 
46 // ipc, memory mapping, multithreading
47 #include <pthread.h>
48 #include <signal.h>
49 #include <sys/mman.h>
50 #include <sys/shm.h>
51 
52 // files
53 #include <fcntl.h>
54 #include <poll.h>
55 #include <sys/stat.h>
56 
57 // time
58 #include <sys/time.h>
59 #include <time.h>
60 
61 // pru
62 #include <pruss_intc_mapping.h>
63 #include <prussdrv.h>
64 
65 // ncurses (text-based UI)
66 #include <ncurses.h>
67 
68 // DEFINES
69 
70 // return codes
74 #define SUCCESS 1
75 #define UNDEFINED 0
76 #define TIME_OUT 0
77 #define FAILURE -1
78 
79 // files
81 #define PID_FILE "/var/run/rocketlogger.pid"
82 #define LOG_FILE "/var/www/log/log.txt"
84 #define MAC_ADDRESS_FILE "/sys/class/net/eth0/address"
86 #define CALIBRATION_FILE "/etc/rocketlogger/calibration.dat"
88 
90 #define MAX_LOG_FILE_SIZE 1000000
91 
93 #define SHMEM_STATUS_KEY 1111
94 #define SHMEM_DATA_KEY 4443
96 #define SHMEM_PERMISSIONS 0666
98 
99 // constants
101 #define MAX_PATH_LENGTH 256
102 #define NUM_CHANNELS 8
104 #define NUM_I_CHANNELS 2
106 #define NUM_V_CHANNELS 4
108 #define NUM_DIGITAL_INPUTS 6
110 #define METER_UPDATE_RATE 5
112 #define PRU_DIG_SIZE 2
114 #define PRU_BUFFER_STATUS_SIZE 4
116 
118 #define KSPS 1000
119 
123 #define I1L_VALID_BIT 1
124 #define I2L_VALID_BIT 1
125 #define DIGIN1_BIT 2
126 #define DIGIN2_BIT 4
127 #define DIGIN3_BIT 8
128 #define DIGIN4_BIT 2
129 #define DIGIN5_BIT 4
130 #define DIGIN6_BIT 8
131 
133 #define MIN_ADC_RATE 1000
134 
135 // ROCKETLOGGER
139 typedef enum state {
140  RL_OFF = 0,
142  RL_ERROR = -1,
143 } rl_state;
144 
148 typedef enum sampling {
151 } rl_sampling;
152 
156 typedef enum mode {
167 } rl_mode;
168 
172 typedef enum aggregation {
177 
181 typedef enum file_format {
182  NO_FILE = 0,
183  CSV = 1,
184  BIN = 2
186 
190 typedef enum use_cal {
192  CAL_USE = 1
193 } rl_use_cal;
194 
198 typedef enum log_type {
202 } rl_log_type;
203 
205 #define RL_CONF_VERSION 0x01
206 
207 // AMBIENT CONF //
208 #define AMBIENT_MAX_SENSOR_COUNT 128
209 #define AMBIENT_DISABLED 0
210 #define AMBIENT_ENABLED 1
211 struct rl_ambient {
212  int enabled;
216 } ambient;
217 
218 // channel properties
220 #define CHANNEL_DISABLED 0
221 #define CHANNEL_ENABLED 1
223 
224 // channel indices in channels array
228 #define I1H_INDEX 0
229 #define I1L_INDEX 1
230 #define V1_INDEX 2
231 #define V2_INDEX 3
232 #define I2H_INDEX 4
233 #define I2L_INDEX 5
234 #define V3_INDEX 6
235 #define V4_INDEX 7
236 
237 // digital inputs
239 #define DIGITAL_INPUTS_DISABLED 0
240 #define DIGITAL_INPUTS_ENABLED 1
242 
246 struct rl_conf {
248  int version;
260  int channels[NUM_CHANNELS];
262  int force_high_channels[NUM_I_CHANNELS];
272  uint64_t max_file_size;
277 };
278 
282 struct rl_status {
288  uint64_t samples_taken;
290  uint32_t buffer_number;
292  struct rl_conf conf;
295 };
296 
302  uint64_t time;
304  int offsets[NUM_CHANNELS];
306  double scales[NUM_CHANNELS];
307 };
308 
309 // SEMAPHORES
311 #define SEM_KEY 2222
312 #define NUM_SEMS 2
314 #define SEM_TIME_OUT 3
316 #define SEM_WRITE_TIME_OUT 1
318 #define SEM_SET_TIME_OUT 1
320 
322 #define DATA_SEM 0
323 #define WAIT_SEM 1
326 
328 #define NO_FLAG 0
329 
330 // ----- GLOBAL VARIABLES ----- //
336 extern const char* channel_names[NUM_CHANNELS];
338 extern const char* digital_input_names[NUM_DIGITAL_INPUTS];
340 extern const char* valid_info_names[NUM_I_CHANNELS];
341 
342 #endif /* TYPES_H_ */
Limited sampling mode (limited by number of samples to take)
Definition: types.h:157
Print default configuration.
Definition: types.h:163
Get current status of RocketLogger.
Definition: types.h:160
#define NUM_DIGITAL_INPUTS
Number of RocketLogger digital channels.
Definition: types.h:109
rl_mode mode
Sampling mode.
Definition: types.h:250
Stop continuous sampling.
Definition: types.h:161
Continuous sampling mode (in background)
Definition: types.h:158
int available_sensors[AMBIENT_MAX_SENSOR_COUNT]
Definition: types.h:214
CSV format.
Definition: types.h:183
sampling
Definition: types.h:148
mode
Definition: types.h:156
enum mode rl_mode
int digital_inputs
En-/disable digital inputs.
Definition: types.h:264
#define MAX_PATH_LENGTH
Maximum path length in characters.
Definition: types.h:101
use_cal
Definition: types.h:190
enum aggregation rl_aggregation
struct rl_ambient ambient
int enable_web_server
En-/disable plots on web interface.
Definition: types.h:266
rl_use_cal calibration
Use/ignore existing calibration.
Definition: types.h:268
Binary format.
Definition: types.h:184
Show help.
Definition: types.h:165
const char * valid_info_names[NUM_I_CHANNELS]
Range valid information names.
Definition: file_handling.c:47
int enabled
Definition: types.h:212
rl_state state
State.
Definition: types.h:284
int sensor_count
Definition: types.h:213
uint64_t samples_taken
Number of samples taken.
Definition: types.h:288
Aggregate by averaging data.
Definition: types.h:175
state
Definition: types.h:139
int version
Configuration structure version.
Definition: types.h:248
#define NUM_I_CHANNELS
Maximum number of RocketLogger current channels.
Definition: types.h:105
Aggregate using downsampling.
Definition: types.h:174
log_type
Definition: types.h:198
int sample_limit
Sample limit (0 for continuous)
Definition: types.h:258
Definition: types.h:246
enum sampling rl_sampling
#define NUM_CHANNELS
Maximum number of RocketLogger channels.
Definition: types.h:103
enum use_cal rl_use_cal
Warning.
Definition: types.h:200
Running.
Definition: types.h:141
Set default configuration.
Definition: types.h:162
enum log_type rl_log_type
uint64_t time
Time stamp of calibration run.
Definition: types.h:302
Print the RocketLogger Software Stack version.
Definition: types.h:164
uint64_t calibration_time
Time stamp of last calibration run.
Definition: types.h:294
enum file_format rl_file_format
rl_file_format file_format
File format.
Definition: types.h:270
uint32_t buffer_number
Number of buffers taken.
Definition: types.h:290
int update_rate
Data update rate.
Definition: types.h:256
char file_name[MAX_PATH_LENGTH]
Definition: types.h:215
Error.
Definition: types.h:199
int sample_rate
Sampling rate.
Definition: types.h:252
No file.
Definition: types.h:182
No aggregation.
Definition: types.h:173
const char * channel_names[NUM_CHANNELS]
Channel names.
Definition: file_handling.c:41
Not sampling.
Definition: types.h:149
struct rl_status status
RocketLogger status.
Definition: types.h:332
Use calibration (if existing)
Definition: types.h:192
uint64_t max_file_size
Maximum data file size.
Definition: types.h:272
Sampling.
Definition: types.h:150
rl_sampling sampling
Sampling state.
Definition: types.h:286
Ignore calibration.
Definition: types.h:191
Information.
Definition: types.h:201
aggregation
Definition: types.h:172
Meter mode (display current values in terminal)
Definition: types.h:159
rl_aggregation aggregation
Aggregation mode (for sampling rates below lowest native one)
Definition: types.h:254
Error.
Definition: types.h:142
enum state rl_state
#define AMBIENT_MAX_SENSOR_COUNT
Definition: types.h:208
const char * digital_input_names[NUM_DIGITAL_INPUTS]
Digital input names.
Definition: file_handling.c:44
No mode.
Definition: types.h:166
Idle.
Definition: types.h:140
struct rl_calibration calibration
Calibration data.
Definition: types.h:334
file_format
Definition: types.h:181