RocketLogger  1.1.4
calibration.c
Go to the documentation of this file.
1 
32 #include "calibration.h"
33 
34 // reset calibration
38 void reset_offsets(void) {
39  int i;
40  for (i = 0; i < NUM_CHANNELS; i++) {
41  calibration.offsets[i] = 0;
42  }
43 }
44 
48 void reset_scales(void) {
49  int i;
50  for (i = 0; i < NUM_CHANNELS; i++) {
51  calibration.scales[i] = 1;
52  }
53 }
54 
61 int read_calibration(struct rl_conf* conf) {
62 
63  // open calibration file
64  FILE* file = fopen(CALIBRATION_FILE, "r");
65  if (file == NULL) {
66  // no calibration file available
67  reset_offsets();
68  reset_scales();
70  return FAILURE;
71  }
72  // read calibration
73  fread(&calibration, sizeof(struct rl_calibration), 1, file);
74 
75  // reset calibration, if ignored
76  if (conf->calibration == CAL_IGNORE) {
77  reset_offsets();
78  reset_scales();
79  }
80 
81  // store timestamp to conf and status
83 
84  // close file
85  fclose(file);
86 
87  return SUCCESS;
88 }
int offsets[NUM_CHANNELS]
Channel offsets (in bit)
Definition: types.h:305
double scales[NUM_CHANNELS]
Channel scalings.
Definition: types.h:307
#define FAILURE
Definition: types.h:78
#define SUCCESS
Definition: types.h:75
struct rl_status status
Current status of RocketLogger.
Definition: rl_server.c:71
#define CALIBRATION_FILE
Calibration file name.
Definition: types.h:88
rl_use_cal calibration
Use/ignore existing calibration.
Definition: types.h:269
Definition: types.h:247
#define NUM_CHANNELS
Maximum number of RocketLogger channels.
Definition: types.h:104
void reset_scales(void)
Definition: calibration.c:48
uint64_t time
Time stamp of calibration run.
Definition: types.h:303
uint64_t calibration_time
Time stamp of last calibration run.
Definition: types.h:295
void reset_offsets(void)
Definition: calibration.c:38
Ignore calibration.
Definition: types.h:192
int read_calibration(struct rl_conf *conf)
Definition: calibration.c:61
struct rl_calibration calibration
Calibration data.
Definition: types.h:335