RocketLogger  1.1
calibration.c
Go to the documentation of this file.
1 
31 #include "calibration.h"
32 
33 // reset calibration
37 void reset_offsets(void) {
38  int i;
39  for (i = 0; i < NUM_CHANNELS; i++) {
40  calibration.offsets[i] = 0;
41  }
42 }
43 
47 void reset_scales(void) {
48  int i;
49  for (i = 0; i < NUM_CHANNELS; i++) {
50  calibration.scales[i] = 1;
51  }
52 }
53 
60 int read_calibration(struct rl_conf* conf) {
61 
62  // open calibration file
63  FILE* file = fopen(CALIBRATION_FILE, "r");
64  if (file == NULL) {
65  // no calibration file available
66  reset_offsets();
67  reset_scales();
69  return FAILURE;
70  }
71  // read calibration
72  fread(&calibration, sizeof(struct rl_calibration), 1, file);
73 
74  // reset calibration, if ignored
75  if (conf->calibration == CAL_IGNORE) {
76  reset_offsets();
77  reset_scales();
78  }
79 
80  // store timestamp to conf and status
82 
83  // calculate values for high rates
84  if (conf->sample_rate == 32000 || conf->sample_rate == 64000) {
85  int i;
86  for (i = 0; i < NUM_CHANNELS; i++) {
87  calibration.offsets[i] = calibration.offsets[i] / 256;
88  calibration.scales[i] = calibration.scales[i] * 256;
89  }
90  }
91 
92  // close file
93  fclose(file);
94 
95  return SUCCESS;
96 }
int offsets[NUM_CHANNELS]
Channel offsets (in bit)
Definition: types.h:304
double scales[NUM_CHANNELS]
Channel scalings.
Definition: types.h:306
#define FAILURE
Definition: types.h:77
#define SUCCESS
Definition: types.h:74
struct rl_status status
Current status of RocketLogger.
Definition: rl_server.c:70
#define CALIBRATION_FILE
Calibration file name.
Definition: types.h:87
rl_use_cal calibration
Use/ignore existing calibration.
Definition: types.h:268
Definition: types.h:246
#define NUM_CHANNELS
Maximum number of RocketLogger channels.
Definition: types.h:103
void reset_scales(void)
Definition: calibration.c:47
uint64_t time
Time stamp of calibration run.
Definition: types.h:302
uint64_t calibration_time
Time stamp of last calibration run.
Definition: types.h:294
void reset_offsets(void)
Definition: calibration.c:37
int sample_rate
Sampling rate.
Definition: types.h:252
Ignore calibration.
Definition: types.h:191
int read_calibration(struct rl_conf *conf)
Definition: calibration.c:60
struct rl_calibration calibration
Calibration data.
Definition: types.h:334