SP8EBC-ParaTNC/include/nvm.h

82 wiersze
1.8 KiB
C

2022-11-01 20:22:21 +00:00
/*
* nvm.h
*
* Created on: Nov 1, 2022
* Author: mateusz
*/
#ifndef NVM_H_
#define NVM_H_
#include <stdint.h>
2024-05-26 19:03:16 +00:00
#include "event_log.h"
2022-11-01 20:22:21 +00:00
2022-11-10 17:16:56 +00:00
#define NVM_RECORD_SIZE 8 // in bytes!!
2022-11-01 20:22:21 +00:00
typedef struct __attribute__((packed)) nvm_measurement_t {
/**
* Date-time timestamp in timezone local for a place where station is installed.
* Mixture of BCD and integer format, this is just sligtly processed RTC registers
* content.
* bit 0 - bit 12 === number of minutes starting from midnight (max 1440)
* bit 13 - bit 21 === days from new year (max 356)
* bit 25 - bit 31 === years (from 00 to 99, from 2000 up to 2099)
*/
uint32_t timestamp;
/**
2022-11-10 17:16:56 +00:00
* Temperature represented as 0.2 degrees increment and
2022-11-01 20:22:21 +00:00
* humidity in 2% steps
2022-11-10 17:16:56 +00:00
* bit 0 - bit 9 === raw temperature, physical: raw / 5 - 50 (from -50.0 to +52.3)
2022-11-01 20:22:21 +00:00
* bit 10 - bit 15 === raw humidity, physical: raw * 2 (from 0% to 100%)
*/
uint16_t temperature_humidity;
/**
* Average windspeed and gust windspeed stored in 0.2m/s increments
2022-11-10 17:16:56 +00:00
* bit 0 - bit 7 === raw average windspeed, physical: raw / 5 (from 0m/s up to 50m/s)
* bit 9 - bit 12 === raw maximum windspeed, physical: physical_average + raw / 3
* bit 13 - bit 16 === wind direction. lookup table:
* 0 -
2022-11-01 20:22:21 +00:00
*/
uint16_t wind;
}nvm_measurement_t;
typedef enum nvm_state_result_t {
NVM_UNINITIALIZED,
NVM_OK,
NVM_NO_SPACE_LEFT,
NVM_INIT_ERROR,
NVM_PGM_ERROR
}nvm_state_result_t;
2024-05-26 19:03:16 +00:00
/**
*
*/
2022-11-01 20:22:21 +00:00
void nvm_measurement_init(void);
2024-05-26 19:03:16 +00:00
/**
*
* @param data
* @return
*/
2022-11-01 20:22:21 +00:00
nvm_state_result_t nvm_measurement_store(nvm_measurement_t * data);
2024-05-26 19:03:16 +00:00
/**
*
* @param oldest
* @param newest
*/
void nvm_event_log_find_first_oldest_newest(event_log_t* oldest, event_log_t* newest);
/**
*
*/
2022-11-10 17:16:56 +00:00
void nvm_erase_all(void);
void nvm_test_prefill(void); ///<! Only for test purposes!
2022-11-01 20:22:21 +00:00
#endif /* NVM_H_ */