RocketLogger  1.1.6
types.h
Go to the documentation of this file.
1 
32 #ifndef TYPES_H_
33 #define TYPES_H_
34 
35 // INCLUDES
36 
37 // standard
38 #include <ctype.h>
39 #include <errno.h>
40 #include <stdarg.h>
41 #include <stdint.h>
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <string.h>
45 #include <unistd.h>
46 
47 // ipc, memory mapping, multithreading
48 #include <pthread.h>
49 #include <signal.h>
50 #include <sys/mman.h>
51 #include <sys/shm.h>
52 
53 // files
54 #include <fcntl.h>
55 #include <poll.h>
56 #include <sys/stat.h>
57 
58 // time
59 #include <sys/time.h>
60 #include <time.h>
61 
62 // pru
63 #include <pruss_intc_mapping.h>
64 #include <prussdrv.h>
65 
66 // ncurses (text-based UI)
67 #include <ncurses.h>
68 
69 // DEFINES
70 
71 // return codes
75 #define SUCCESS 1
76 #define UNDEFINED 0
77 #define TIME_OUT 0
78 #define FAILURE -1
79 
80 // files
82 #define PID_FILE "/var/run/rocketlogger.pid"
83 #define LOG_FILE "/var/www/log/log.txt"
85 #define MAC_ADDRESS_FILE "/sys/class/net/eth0/address"
87 #define CALIBRATION_FILE "/etc/rocketlogger/calibration.dat"
89 
91 #define MAX_LOG_FILE_SIZE 1000000
92 
94 #define SHMEM_STATUS_KEY 1111
95 #define SHMEM_DATA_KEY 4443
97 #define SHMEM_PERMISSIONS 0666
99 
100 // constants
102 #define MAX_PATH_LENGTH 256
103 #define NUM_CHANNELS 8
105 #define NUM_I_CHANNELS 2
107 #define NUM_V_CHANNELS 4
109 #define NUM_DIGITAL_INPUTS 6
111 #define METER_UPDATE_RATE 5
113 #define PRU_DIG_SIZE 2
115 #define PRU_BUFFER_STATUS_SIZE 4
117 
119 #define KSPS 1000
120 
124 #define I1L_VALID_BIT 1
125 #define I2L_VALID_BIT 1
126 #define DIGIN1_BIT 2
127 #define DIGIN2_BIT 4
128 #define DIGIN3_BIT 8
129 #define DIGIN4_BIT 2
130 #define DIGIN5_BIT 4
131 #define DIGIN6_BIT 8
132 
134 #define MIN_ADC_RATE 1000
135 
136 // ROCKETLOGGER
140 typedef enum state {
141  RL_OFF = 0,
143  RL_ERROR = -1,
144 } rl_state;
145 
149 typedef enum sampling {
152 } rl_sampling;
153 
157 typedef enum mode {
168 } rl_mode;
169 
173 typedef enum aggregation {
178 
182 typedef enum file_format {
183  NO_FILE = 0,
184  CSV = 1,
185  BIN = 2
187 
191 typedef enum use_cal {
193  CAL_USE = 1
194 } rl_use_cal;
195 
199 typedef enum log_type {
203 } rl_log_type;
204 
206 #define RL_CONF_VERSION 0x01
207 
208 // AMBIENT CONF //
209 #define AMBIENT_MAX_SENSOR_COUNT 128
210 #define AMBIENT_DISABLED 0
211 #define AMBIENT_ENABLED 1
212 struct rl_ambient {
213  int enabled;
217 } ambient;
218 
219 // channel properties
221 #define CHANNEL_DISABLED 0
222 #define CHANNEL_ENABLED 1
224 
225 // channel indices in channels array
229 #define I1H_INDEX 0
230 #define I1L_INDEX 1
231 #define V1_INDEX 2
232 #define V2_INDEX 3
233 #define I2H_INDEX 4
234 #define I2L_INDEX 5
235 #define V3_INDEX 6
236 #define V4_INDEX 7
237 
238 // digital inputs
240 #define DIGITAL_INPUTS_DISABLED 0
241 #define DIGITAL_INPUTS_ENABLED 1
243 
247 struct rl_conf {
249  int version;
261  int channels[NUM_CHANNELS];
263  int force_high_channels[NUM_I_CHANNELS];
273  uint64_t max_file_size;
278 };
279 
283 struct rl_status {
289  uint64_t samples_taken;
291  uint32_t buffer_number;
293  struct rl_conf conf;
296 };
297 
303  uint64_t time;
305  int offsets[NUM_CHANNELS];
307  double scales[NUM_CHANNELS];
308 };
309 
310 // SEMAPHORES
312 #define SEM_KEY 2222
313 #define NUM_SEMS 2
315 #define SEM_TIME_OUT 3
317 #define SEM_WRITE_TIME_OUT 1
319 #define SEM_SET_TIME_OUT 1
321 
323 #define DATA_SEM 0
324 #define WAIT_SEM 1
327 
329 #define NO_FLAG 0
330 
331 // ----- GLOBAL VARIABLES ----- //
337 extern const char* channel_names[NUM_CHANNELS];
339 extern const char* digital_input_names[NUM_DIGITAL_INPUTS];
341 extern const char* valid_info_names[NUM_I_CHANNELS];
342 
343 #endif /* TYPES_H_ */
Limited sampling mode (limited by number of samples to take)
Definition: types.h:158
Print default configuration.
Definition: types.h:164
Get current status of RocketLogger.
Definition: types.h:161
#define NUM_DIGITAL_INPUTS
Number of RocketLogger digital channels.
Definition: types.h:110
rl_mode mode
Sampling mode.
Definition: types.h:251
Stop continuous sampling.
Definition: types.h:162
Continuous sampling mode (in background)
Definition: types.h:159
int available_sensors[AMBIENT_MAX_SENSOR_COUNT]
Definition: types.h:215
CSV format.
Definition: types.h:184
sampling
Definition: types.h:149
mode
Definition: types.h:157
enum mode rl_mode
int digital_inputs
En-/disable digital inputs.
Definition: types.h:265
#define MAX_PATH_LENGTH
Maximum path length in characters.
Definition: types.h:102
use_cal
Definition: types.h:191
enum aggregation rl_aggregation
struct rl_ambient ambient
int enable_web_server
En-/disable plots on web interface.
Definition: types.h:267
rl_use_cal calibration
Use/ignore existing calibration.
Definition: types.h:269
Binary format.
Definition: types.h:185
Show help.
Definition: types.h:166
const char * valid_info_names[NUM_I_CHANNELS]
Range valid information names.
Definition: file_handling.c:48
int enabled
Definition: types.h:213
rl_state state
State.
Definition: types.h:285
int sensor_count
Definition: types.h:214
uint64_t samples_taken
Number of samples taken.
Definition: types.h:289
Aggregate by averaging data.
Definition: types.h:176
state
Definition: types.h:140
int version
Configuration structure version.
Definition: types.h:249
#define NUM_I_CHANNELS
Maximum number of RocketLogger current channels.
Definition: types.h:106
Aggregate using downsampling.
Definition: types.h:175
log_type
Definition: types.h:199
int sample_limit
Sample limit (0 for continuous)
Definition: types.h:259
Definition: types.h:247
enum sampling rl_sampling
#define NUM_CHANNELS
Maximum number of RocketLogger channels.
Definition: types.h:104
enum use_cal rl_use_cal
Warning.
Definition: types.h:201
Running.
Definition: types.h:142
Set default configuration.
Definition: types.h:163
enum log_type rl_log_type
uint64_t time
Time stamp of calibration run.
Definition: types.h:303
Print the RocketLogger Software Stack version.
Definition: types.h:165
uint64_t calibration_time
Time stamp of last calibration run.
Definition: types.h:295
enum file_format rl_file_format
rl_file_format file_format
File format.
Definition: types.h:271
uint32_t buffer_number
Number of buffers taken.
Definition: types.h:291
int update_rate
Data update rate.
Definition: types.h:257
char file_name[MAX_PATH_LENGTH]
Definition: types.h:216
Error.
Definition: types.h:200
int sample_rate
Sampling rate.
Definition: types.h:253
No file.
Definition: types.h:183
No aggregation.
Definition: types.h:174
const char * channel_names[NUM_CHANNELS]
Channel names.
Definition: file_handling.c:42
Not sampling.
Definition: types.h:150
struct rl_status status
RocketLogger status.
Definition: types.h:333
Use calibration (if existing)
Definition: types.h:193
uint64_t max_file_size
Maximum data file size.
Definition: types.h:273
Sampling.
Definition: types.h:151
rl_sampling sampling
Sampling state.
Definition: types.h:287
Ignore calibration.
Definition: types.h:192
Information.
Definition: types.h:202
aggregation
Definition: types.h:173
Meter mode (display current values in terminal)
Definition: types.h:160
rl_aggregation aggregation
Aggregation mode (for sampling rates below lowest native one)
Definition: types.h:255
Error.
Definition: types.h:143
enum state rl_state
#define AMBIENT_MAX_SENSOR_COUNT
Definition: types.h:209
const char * digital_input_names[NUM_DIGITAL_INPUTS]
Digital input names.
Definition: file_handling.c:45
No mode.
Definition: types.h:167
Idle.
Definition: types.h:141
struct rl_calibration calibration
Calibration data.
Definition: types.h:335
file_format
Definition: types.h:182