91 uint32_t storeChksum = 0, recordSize;
92 const uint32_t *initialBufPtr = *eeprom_buffer;
102 const size_t chksumBufLen = *eeprom_buffer - initialBufPtr;
106 if (calcChksum != storeChksum) {
115 if (*eeprom_buffer == NULL) {
119 *sca = *(*eeprom_buffer)++;
127 if (*eeprom_buffer == NULL) {
132 if (num_of_array == NULL) {
136 if (num_of_elem == NULL) {
142 float **eeprom_buffer_float = (
float **) eeprom_buffer;
145 "sizeof (uint32_t) differ from sizeof (mtostk_time_t)");
146 _Static_assert(
sizeof(
uint32_t) ==
sizeof(
float),
147 "sizeof (uint32_t) differ from sizeof (float)");
149 *num_of_array = *(*eeprom_buffer)++;
154 for (
size_t idx = 0;
idx < *num_of_array;
idx++) {
155 const size_t this_num_of_elem = *(*eeprom_buffer)++;
156 if (*num_of_elem == 0) {
157 *num_of_elem = this_num_of_elem;
159 if (*num_of_elem != this_num_of_elem) {
168 for (
int32_t jdx = 0; jdx < *num_of_elem; jdx++) {
179 if (*eeprom_buffer == NULL) {
183 const size_t numOfArrays = *(*eeprom_buffer)++;
184 if (numOfArrays > 1) {
188 const size_t numOfElems = *(*eeprom_buffer)++;
194 *str++ = *(*eeprom_buffer_byte)++;
204 if (*eeprom_buffer == NULL) {
208 const size_t numOfArrays = *(*eeprom_buffer)++;
213 for (
size_t i = 0; i < numOfArrays; i++) {
214 const size_t numOfElems = *(*eeprom_buffer)++;
218 *eeprom_buffer_byte += numOfElems * dataSize;
228 *eeprom_buffer_byte += dataSize;
238 uint32_t sum1 = 0xffff, sum2 = 0xffff;
241 unsigned tlen = words > 359 ? 359 :
words;
244 sum2 += sum1 += *data++;
246 sum1 = (sum1 & 0xffff) + (sum1 >> 16);
247 sum2 = (sum2 & 0xffff) + (sum2 >> 16);
250 sum1 = (sum1 & 0xffff) + (sum1 >> 16);
251 sum2 = (sum2 & 0xffff) + (sum2 >> 16);
252 return sum2 << 16 | sum1;
259 for (i = 1; i < num_coef; i++) {
260 y += coeffs[i] * powf(value, (
float) i);
281 if (temp <= params->temps[0]) {
287 for (i = 0; i <= params->
num_temp - 2; i++) {
288 const float t1 = params->
temps[i];
289 const float t2 = params->
temps[i + 1];
290 if (temp > t1 && temp <= t2) {
294 const float alpha = (t2 - temp) / (t2 - t1);
295 return (alpha * v1 + (1.0f - alpha) *
v2);
static float mtostk_apply_polynomial_temp(Sensors_params *params, float temp, float value)
static bool mtostk_populate_sensor_from_buffer(Sensors_params *sp, uint32_t **eeprom_buffer)
float temps[MTOSTK_MAX_TEMP_ARRAY_SIZE]
#define MTOSTK_MAX_POLY_ARRAY_SIZE
bool mtostk_populate_cal_from_buffer(Calibration_params *cp, uint8_t *_eeprom_buffer)
Initializes a Calibration_params structure from memory buffer.
static float mtostk_apply_polynomial(float *coeffs, uint16_t num_coef, float value)
float coeffs[MTOSTK_MAX_TEMP_ARRAY_SIZE][MTOSTK_MAX_POLY_ARRAY_SIZE]
#define MTOSTK_MAX_SEEK_ARRAY_SIZE
float mtostk_get_calibrated_value(Calibration_params *cp, Mtostk_sensors type, float uncal, float temp)
get calibrated value for a sensor according to current temperature
static bool mtostk_populate_uint_from_buffer(uint32_t *sca, uint32_t **eeprom_buffer)
static uint32_t fletcher32(uint32_t const *_data, size_t words)
static bool mtostk_populate_uuid_from_buffer(char *str, uint32_t **eeprom_buffer)
#define MTOSTK_MAX_TEMP_ARRAY_SIZE
Calibration_params structure initialized with calibvration data read from meteostick eeprom...
static bool mtostk_seek_scalar_buffer(size_t dataSize, uint32_t **eeprom_buffer)
Sensors_params params[MTOSTK_NUM_SENSORS]
Parser for calibration data coming from 25AA256 EEPROM of the Meteo Stick.
uint32_t mtostk_time_t
time in seconds since 01/01/1970
static bool mtostk_populate_float_array_from_buffer(float *ar, uint16_t *num_of_array, uint16_t *num_of_elem, uint32_t **eeprom_buffer)
static bool mtostk_seek_array_buffer(size_t dataSize, uint32_t **eeprom_buffer)