|
Avionics
Core avionics package for CURE flight computers
|
SPI flash implementation of IDataSaver with timestamp compression. More...
#include <DataSaverSPI.h>


Public Member Functions | |
| DataSaverSPI (uint16_t timestampInterval_ms, Adafruit_SPIFlash *flash) | |
| Construct a new DataSaverSPI object. | |
| int | saveDataPoint (const DataPoint &dataPoint, uint8_t name) override |
| Saves a DataPoint to SPI flash. | |
| int | saveTimestamp (uint32_t timestamp_ms) |
| Persist a bare timestamp entry to flash. | |
| virtual bool | begin () override |
| Initialize the flash chip and metadata. | |
| bool | isPostLaunchMode () |
| Returns whether the metadata from the flash chip indicates that it contains post-launch data that hasn't been dumped yet. Call clearPostLaunchMode() to clear this flag. once you are confident that you have the data you want dumped to a more permanent storage or another machine. | |
| void | clearPostLaunchMode () |
| Clears the post-launch mode flag on the flash chip **WARNING: This will allow the data to be overwritten Only call this after you have dumped the data to a more permanent storage or another machine. | |
| void | launchDetected (uint32_t launchTimestamp_ms) |
| Call this when launch is detected to set the post-launch flag and prevent any data from being overwritten until the flag is cleared. All data written from this point on is "post-launch" data which is sacred and should not be overwritten until it has been dumped. | |
| void | dumpData (Stream &serial, bool ignoreEmptyPages) |
| Dumps all data from flash to Serial. | |
| void | clearInternalState () |
| Resets all internal state values (buffer, lastDataPoint, nextWriteAddress, lastTimestamp_ms) Does not erase the flash chip. | |
| void | eraseAllData () |
| Clears/erases the entire flash chip to start fresh. | |
| uint32_t | getLastTimestamp () const |
| Returns the last timestamp that was actually written to flash. | |
| DataPoint | getLastDataPoint () const |
| Returns the last DataPoint that was written (not necessarily including timestamp, just the data chunk). | |
| uint32_t | getLaunchWriteAddress () const |
| uint32_t | getNextWriteAddress () const |
| void | resetTimestamp () |
| Resets the timestamp to 0. Can be used to start a new flight during runtime. Useful for testing. | |
| bool | quickGetPostLaunchMode () |
| Returns whether the flash chip is in post-launch mode without updating the postLaunchMode flag or reading from flash. | |
| size_t | getBufferIndex () const |
| Returns the current buffer index Useful for testing. | |
| uint32_t | getBufferFlushes () const |
| Returns the current buffer flush count Useful for testing. | |
| bool | getIsChipFullDueToPostLaunchProtection () const |
| bool | getRebootedInPostLaunchMode () const |
| Public Member Functions inherited from IDataSaver | |
| virtual int | saveDataPoint (float data, uint32_t timestamp_ms, uint8_t name) final |
| Convenience overload to construct and save a data point. | |
Static Public Attributes | |
| static constexpr size_t | BUFFER_SIZE = 256 |
SPI flash implementation of IDataSaver with timestamp compression.
Definition at line 39 of file DataSaverSPI.h.
| DataSaverSPI::DataSaverSPI | ( | uint16_t | timestampInterval_ms, |
| Adafruit_SPIFlash * | flash ) |
Construct a new DataSaverSPI object.
| timestampInterval_ms | Interval in ms at which timestamps are stored |
| flash | Pointer to an initialized Adafruit_SPIFlash object |
Definition at line 6 of file DataSaverSPI.cpp.
|
overridevirtual |
Initialize the flash chip and metadata.
Reimplemented from IDataSaver.
Definition at line 106 of file DataSaverSPI.cpp.
| void DataSaverSPI::clearInternalState | ( | ) |
Resets all internal state values (buffer, lastDataPoint, nextWriteAddress, lastTimestamp_ms) Does not erase the flash chip.
Reset in-memory pointers without erasing flash contents.
Definition at line 227 of file DataSaverSPI.cpp.
| void DataSaverSPI::clearPostLaunchMode | ( | ) |
Clears the post-launch mode flag on the flash chip **WARNING: This will allow the data to be overwritten Only call this after you have dumped the data to a more permanent storage or another machine.
Definition at line 131 of file DataSaverSPI.cpp.
| void DataSaverSPI::dumpData | ( | Stream & | serial, |
| bool | ignoreEmptyPages ) |
Dumps all data from flash to Serial.
Stream all recorded data to a serial connection.
| serial | Output stream. |
| ignoreEmptyPages | Skip pages that appear unwritten. |
Definition at line 139 of file DataSaverSPI.cpp.
| void DataSaverSPI::eraseAllData | ( | ) |
Clears/erases the entire flash chip to start fresh.
Erase the entire flash chip to start fresh.
Definition at line 239 of file DataSaverSPI.cpp.
|
inline |
Returns the current buffer flush count Useful for testing.
Definition at line 249 of file DataSaverSPI.h.
|
inline |
Returns the current buffer index Useful for testing.
Definition at line 241 of file DataSaverSPI.h.
|
inline |
Definition at line 253 of file DataSaverSPI.h.
|
inline |
Returns the last DataPoint that was written (not necessarily including timestamp, just the data chunk).
Definition at line 167 of file DataSaverSPI.h.
|
inline |
Returns the last timestamp that was actually written to flash.
Definition at line 159 of file DataSaverSPI.h.
|
inline |
Definition at line 171 of file DataSaverSPI.h.
|
inline |
Definition at line 175 of file DataSaverSPI.h.
|
inline |
Definition at line 257 of file DataSaverSPI.h.
| bool DataSaverSPI::isPostLaunchMode | ( | ) |
Returns whether the metadata from the flash chip indicates that it contains post-launch data that hasn't been dumped yet. Call clearPostLaunchMode() to clear this flag. once you are confident that you have the data you want dumped to a more permanent storage or another machine.
Will also update the postLaunchMode flag.
Definition at line 124 of file DataSaverSPI.cpp.
|
virtual |
Call this when launch is detected to set the post-launch flag and prevent any data from being overwritten until the flag is cleared. All data written from this point on is "post-launch" data which is sacred and should not be overwritten until it has been dumped.
Sets postLaunchMode flag to true on the flash chip. Records the address at which the launch was detected and ensures that it's not overwritten
Data is saved in a circular fashion but once the address where the launch detected is reached this will stop saving data entirely. Also keeps 1 minute of data from before the launch was detected (b/c launch can be detected late and we have extra room)
The rocket may not be recovered for several hours, this prevents the cool launch data from being overwitten with boring laying-on-the-ground data.
Reimplemented from IDataSaver.
Definition at line 250 of file DataSaverSPI.cpp.
|
inline |
Returns whether the flash chip is in post-launch mode without updating the postLaunchMode flag or reading from flash.
Definition at line 191 of file DataSaverSPI.h.
|
inline |
Resets the timestamp to 0. Can be used to start a new flight during runtime. Useful for testing.
Definition at line 183 of file DataSaverSPI.h.
|
overridevirtual |
Saves a DataPoint to SPI flash.
If the new data point’s timestamp differs from the last written timestamp by more than timestampInterval_ms, the new timestamp is also written to flash. Otherwise, the timestamp is omitted (to save space).
| dataPoint | The data point to save |
| name | An 8-bit “identifier” for the data point (could be a sensor ID) |
Implements IDataSaver.
Definition at line 20 of file DataSaverSPI.cpp.
| int DataSaverSPI::saveTimestamp | ( | uint32_t | timestamp_ms | ) |
Persist a bare timestamp entry to flash.
| timestamp_ms | Timestamp in milliseconds to record. |
Definition at line 42 of file DataSaverSPI.cpp.
|
staticconstexpr |
Definition at line 42 of file DataSaverSPI.h.