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-05
- Revision:
- 5:0a4ff027086c
- Parent:
- 3:df8fb1b5d868
- Child:
- 9:a2ba4015796e
File content as of revision 5:0a4ff027086c:
#include "dataRecorder.h" /* CONSTRUCTOR*/ 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(){ printf("pop data\n"); 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(){ printf("pop time\n"); 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){ printf("push distance\n"); 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){ printf("push time\n"); m_time_quantity++; if (m_time_quantity>BUF_SIZE){ m_time_quantity=BUF_SIZE; } m_buf_timestamp.push(value); } //helpers int getoSize(int* p){ printf("reg p %i \n",sizeof(p)); printf("star p %i \n",sizeof(*p)); return (sizeof(p)/sizeof(*p)); } int getoSize(uint16_t* p){ return (sizeof(p)/sizeof(*p)); } /** Save logged data to SD card **/ void DataRecorder::saveLoggedData(string filename){ //iterate over buffer and use the sd card commands printf("before logging, data quantity is %i\n",m_data_quantity); int numPoints = m_data_quantity; //add check for timestamps vector<int> indexArr(numPoints); //int indexArr[numPoints]; //index setting for (int i = numPoints-1; i >=0 ; i--){ indexArr[i] = i; } vector<uint32_t> timeArr(numPoints); vector<vector <uint16_t> > allDataArr(numPoints); //uint32_t timeArr[numPoints]; //uint16_t* allDataArr[numPoints]; for (int i = 0; i < numPoints; i++){ //time aggregation timeArr[i] = popLastTimeStamp(); //data aggregation vector<uint16_t> dataEntry(1); dataEntry[0] = popLastDataPoint(); allDataArr[i] = dataEntry; printf("%i\n",static_cast<int>(dataEntry[0])); } printf("Before launch! size test %i \n",indexArr.size()); m_saveBuddy->fullWriteProcedure(filename,indexArr,timeArr,allDataArr); } //saves buffer to sd card and clears it void DataRecorder::saveLoggedDataAndClearBuffer(string filename){ saveLoggedData(filename); // then eraseBuffers(); }