FOSSASAT-1B
Loading...
Searching...
No Matches
persistent_storage.h
Go to the documentation of this file.
1#ifndef PERSISTENT_STORAGE_H_INCLUDED
2#define PERSISTENT_STORAGE_H_INCLUDED
3
4#include "FossaSat1B.h"
5
6// EEPROM only included once to suppress unused variable warning
7#include <EEPROM.h>
8
21template <typename T>
23 T val;
24 EEPROM.get(addr, val);
25 return(val);
26}
27
35template <typename T>
37 EEPROM.put(addr, val);
38}
39
47
55
63
72template <typename T>
75 T avg = Persistent_Storage_Read<T>(addr + sizeof(val));
76 T max = Persistent_Storage_Read<T>(addr + 2*sizeof(val));
77
78 if(val < min) {
80 }
81
82 Persistent_Storage_Write<T>(addr + sizeof(val), (avg + val)/2);
83
84 if(val > max) {
85 Persistent_Storage_Write<T>(addr + 2*sizeof(val), val);
86 }
87}
88
89#endif
T Persistent_Storage_Read(uint16_t addr)
This function reads a value of type T from EEPROM.
void Persistent_Storage_Wipe()
This functions clears the EEPROM by writing EEPROM_RESET_VALUE to each memory addres.
void Persistent_Storage_Increment_Frame_Counter(bool valid)
This functions increments one of frame counters of the currently active modem in EEPROM.
void Persistent_Storage_Increment_Counter(uint16_t addr)
This functions increments 2-byte counter in EEPROM.
void Persistent_Storage_Update_Stats(uint16_t addr, T val)
Updates minimum, average and maximum stats in EEPROM.
void Persistent_Storage_Write(uint16_t addr, T val)
This function writes a value of type T to the eerom.