A set of data recording functions to locally store data in a circular buffer, with functions for offloading to an SD Card when convenient. dataRecorderr.h shows accessible functions to the main program - all direct SD operations are abstracted away by the library. When using this library, #include dataRecorder.h
Dependencies: sd-driver_compatible_with_MAX32630FTHR
Fork of CircularBufferSDCardLib by
dataRecorder.cpp
- Committer:
- DVLevine
- Date:
- 2018-04-04
- Revision:
- 3:df8fb1b5d868
- Parent:
- 2:c2cfb0ebc3bd
- Child:
- 5:0a4ff027086c
File content as of revision 3:df8fb1b5d868:
#include "dataRecorder.h" /* CONSTRUCTOR*/ DataRecorder::DataRecorder(){ DataRecorder(); //Initialize SDCard Reader Class m_saveBuddy = new SDCardReader(); //Initialize data quantity as 0 m_data_quantity = 0; } /* PUBLIC METHODS */ int DataRecorder::getDataQuantity(){ return m_data_quantity; } int DataRecorder::getTimeStampQuantity(){ return m_time_quantity; } uint16_t DataRecorder::popLastDataPoint(){ m_data_quantity--; if (m_data_quantity<0){ m_data_quantity=0; } uint16_t poppedData; if(!m_buf_data.empty()){ m_buf_data.pop(poppedData); return poppedData; }else{ return (uint16_t)0; } } uint32_t DataRecorder::popLastTimeStamp(){ m_time_quantity--; if (m_time_quantity<0){ m_time_quantity=0; } uint32_t poppedData; if(!m_buf_timestamp.empty()){ m_buf_timestamp.pop(poppedData); return poppedData; }else{ return (uint16_t)0; } } void DataRecorder::logDistancePoint(uint16_t value){ m_data_quantity++; if (m_data_quantity>BUF_SIZE){ m_data_quantity=BUF_SIZE; } m_buf_data.push(value); } void DataRecorder::logTimeStamp(uint32_t value){ m_time_quantity++; if (m_time_quantity>BUF_SIZE){ m_time_quantity=BUF_SIZE; } m_buf_timestamp.push(value); } /** Save logged data to SD card **/ void DataRecorder::saveLoggedData(string filename){ //iterate over buffer and use the sd card commands int numPoints = m_data_quantity; //add check for timestamps int indexArr[m_data_quantity]; for (int i = m_data_quantity; i >=0 ; i--){ indexArr[i] = i; } uint32_t timeArr[m_time_quantity]; uint16_t* allDataArr[m_data_quantity]; for (int i = 0; i < numPoints; i++){ uint16_t dataEntry[1]; dataEntry[1] = popLastDataPoint(); allDataArr[i] = dataEntry; } m_saveBuddy->fullWriteProcedure(filename,indexArr,timeArr,allDataArr); } //saves buffer to sd card and clears it void DataRecorder::saveLoggedDataAndClearBuffer(string filename){ saveLoggedData(filename); // then eraseBuffers(); }