11#define METADATA_START_ADDRESS 0x000000
12#define DATA_START_ADDRESS 0x001000
13#define POST_LAUNCH_FLAG_ADDRESS 0x000000
14#define LAUNCH_START_ADDRESS_ADDRESS 0x000001
16#define POST_LAUNCH_FLAG_TRUE 0x00
17#define POST_LAUNCH_FLAG_FALSE 0x01
79 virtual bool begin()
override;
160 return lastTimestamp_ms;
168 return lastDataPoint;
172 return launchWriteAddress;
176 return nextWriteAddress;
184 lastTimestamp_ms = 0;
192 return this->postLaunchMode;
197 uint16_t timestampInterval_ms;
200 uint32_t lastTimestamp_ms;
203 uint32_t launchTimestamp_ms;
212 uint32_t nextWriteAddress;
215 uint32_t launchWriteAddress;
224 bool writeToFlash(
const uint8_t* data,
size_t length);
229 bool readFromFlash(uint32_t& readAddress, uint8_t* buffer,
size_t length);
233 size_t bufferIndex = 0;
234 uint32_t bufferFlushes = 0;
250 return bufferFlushes;
254 return isChipFullDueToPostLaunchProtection;
258 return rebootedInPostLaunchMode;
279 int addDataToBuffer(
const uint8_t* data,
size_t length);
284 int addRecordToBuffer(
Record_t * record) {
285 return addDataToBuffer(
reinterpret_cast<const uint8_t*
>(record), 5);
288 int addRecordToBuffer(TimestampRecord_t * record) {
289 return addDataToBuffer(
reinterpret_cast<const uint8_t*
>(record), 5);
294 bool isChipFullDueToPostLaunchProtection;
298 bool rebootedInPostLaunchMode =
false;
constexpr uint8_t EMPTY_PAGE
Timestamped float measurement container.
DataSaverSPI(uint16_t timestampInterval_ms, Adafruit_SPIFlash *flash)
Construct a new DataSaverSPI object.
void resetTimestamp()
Resets the timestamp to 0. Can be used to start a new flight during runtime. Useful for testing.
static constexpr size_t BUFFER_SIZE
size_t getBufferIndex() const
Returns the current buffer index Useful for testing.
uint32_t getLaunchWriteAddress() const
bool getIsChipFullDueToPostLaunchProtection() const
bool quickGetPostLaunchMode()
Returns whether the flash chip is in post-launch mode without updating the postLaunchMode flag or rea...
uint32_t getNextWriteAddress() const
int saveDataPoint(const DataPoint &dataPoint, uint8_t name) override
Saves a DataPoint to SPI flash.
void clearInternalState()
Resets all internal state values (buffer, lastDataPoint, nextWriteAddress, lastTimestamp_ms) Does not...
uint32_t getLastTimestamp() const
Returns the last timestamp that was actually written to flash.
bool isPostLaunchMode()
Returns whether the metadata from the flash chip indicates that it contains post-launch data that has...
void clearPostLaunchMode()
Clears the post-launch mode flag on the flash chip **WARNING: This will allow the data to be overwrit...
DataPoint getLastDataPoint() const
Returns the last DataPoint that was written (not necessarily including timestamp, just the data chunk...
void eraseAllData()
Clears/erases the entire flash chip to start fresh.
int saveTimestamp(uint32_t timestamp_ms)
Persist a bare timestamp entry to flash.
uint32_t getBufferFlushes() const
Returns the current buffer flush count Useful for testing.
bool getRebootedInPostLaunchMode() const
void dumpData(Stream &serial, bool ignoreEmptyPages)
Dumps all data from flash to Serial.
virtual bool begin() override
Initialize the flash chip and metadata.
void launchDetected(uint32_t launchTimestamp_ms)
Call this when launch is detected to set the post-launch flag and prevent any data from being overwri...
Abstract interface for persisting timestamped data points.