Simplified data storage without eeprom, include timestamps
This commit is contained in:
@ -4,9 +4,6 @@
|
||||
|
||||
void bluetoothConfigure();
|
||||
|
||||
bool bluetoothIsConnected();
|
||||
void bluetoothStop();
|
||||
|
||||
// In main.cpp
|
||||
uint32_t secondsUntilNextTemperatureMeasurement();
|
||||
|
||||
uint8_t getWakeupCause();
|
||||
bool bluetoothIsConnected();
|
90
include/eepromInterface.h
Normal file
90
include/eepromInterface.h
Normal file
@ -0,0 +1,90 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct DeviceInfo {
|
||||
|
||||
// The index where the measurement data starts in the eeprom storage
|
||||
uint16_t startIndex;
|
||||
|
||||
// The time when the device was powered on (seconds since 1970)
|
||||
uint32_t deviceStartTime;
|
||||
};
|
||||
|
||||
struct Measurement {
|
||||
|
||||
uint16_t measurementIntervalsSinceDeviceStart;
|
||||
|
||||
uint8_t temperature0;
|
||||
|
||||
uint8_t temperature1;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
constexpr size_t eepromTotalSize = 13350;
|
||||
constexpr uint16_t maxiumDeviceInfoCount = 10;
|
||||
constexpr uint16_t dataStorageStartIndex = sizeof(DeviceInfo) * maxiumDeviceInfoCount;
|
||||
constexpr uint16_t sizeOfMeasurement = sizeof(Measurement);
|
||||
|
||||
class EEPROMInterface {
|
||||
|
||||
public:
|
||||
|
||||
bool isInitialized;
|
||||
|
||||
/**
|
||||
* @brief Initialize the storage
|
||||
*
|
||||
*/
|
||||
EEPROMInterface();
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
uint8_t startNewDeviceSession();
|
||||
|
||||
/**
|
||||
* @brief Remove all stored data
|
||||
*
|
||||
* @return true The data was deleted
|
||||
* @return false There was an error deleting the data
|
||||
*/
|
||||
bool clearAllData();
|
||||
|
||||
bool writeData(uint8_t* data, uint16_t count);
|
||||
|
||||
/**
|
||||
* @brief Free space in the buffer
|
||||
*
|
||||
* @param buffer
|
||||
* @param count
|
||||
* @return uint16_t The number
|
||||
*/
|
||||
uint16_t readData(uint8_t* buffer, uint16_t count);
|
||||
|
||||
uint16_t getStoredByteCount();
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief The index into the buffer where the next byte should be written
|
||||
*
|
||||
*/
|
||||
uint16_t writeIndex;
|
||||
|
||||
/**
|
||||
* @brief The index into the buffer where the first byte is stored
|
||||
*
|
||||
*/
|
||||
uint16_t readIndex;
|
||||
|
||||
/**
|
||||
* @brief Find the write index, the first zero byte after a non-zero byte
|
||||
*
|
||||
* @return uint16_t The write index
|
||||
*/
|
||||
uint16_t findEndIndex();
|
||||
|
||||
uint16_t findStartIndex();
|
||||
};
|
7
include/main.h
Normal file
7
include/main.h
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
uint32_t secondsUntilNextTemperatureMeasurement();
|
||||
uint8_t getWakeupCause();
|
||||
uint32_t getUniqueID();
|
@ -6,33 +6,17 @@
|
||||
|
||||
constexpr uint8_t temperatureSensorCount = 2;
|
||||
|
||||
constexpr size_t storageSize = 80000;
|
||||
constexpr uint16_t storageIntervalInSeconds = 15;
|
||||
constexpr size_t maximumStorageDurationInHours = (storageSize / TEMPERATURE_SENSOR_MAX_COUNT) * storageIntervalInSeconds / 3600;
|
||||
|
||||
// Max size: 7664
|
||||
constexpr size_t maxRtcStorageSize = 7664;
|
||||
constexpr size_t rtcStorageSize = 7550;
|
||||
constexpr size_t rtcStorageSize = 7580;
|
||||
|
||||
constexpr size_t maxEepromSize = 13350;
|
||||
constexpr size_t eepromSize = 13350;
|
||||
|
||||
constexpr size_t totalStorageSize = rtcStorageSize + eepromSize;
|
||||
|
||||
// The minimum temperature to store, in millidegrees celcius
|
||||
// True minimum will be higher by 1°, since two values are reserved
|
||||
constexpr long temperatureShiftForStorage = -40000;
|
||||
constexpr long maximumTemperature = temperatureShiftForStorage + 255 * 500;
|
||||
|
||||
constexpr uint8_t temperatureMaximumValue = 255;
|
||||
|
||||
enum class StorageFlags: uint8_t {
|
||||
HasInitializedEEPROM = 1,
|
||||
FailedToInitEEPROM = 2,
|
||||
FailedToWriteEEPROM = 4,
|
||||
RTCStorageOverflow = 5,
|
||||
};
|
||||
|
||||
void storageConfigure(bool isFirstRun);
|
||||
|
||||
/**
|
||||
@ -51,12 +35,14 @@ uint16_t getNumberOfMeasurements();
|
||||
|
||||
uint32_t getTotalNumberOfMeasurements();
|
||||
|
||||
uint32_t getStartTimeOfCurrentRecording();
|
||||
|
||||
uint8_t getLastTemperature(uint8_t sensorIndex);
|
||||
|
||||
uint16_t getTimeSinceValidTemperature(uint8_t sensorIndex);
|
||||
|
||||
uint16_t getRecordedBytesAtOffset(uint8_t* buffer, uint16_t offset, uint16_t count);
|
||||
|
||||
void discardAllRecordedBytes();
|
||||
uint16_t getDataChecksum();
|
||||
|
||||
uint8_t getStorageErrorFlags();
|
||||
void discardAllRecordedBytes();
|
||||
|
Reference in New Issue
Block a user