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
Diff: dataRecorder.cpp
- Revision:
- 5:0a4ff027086c
- Parent:
- 3:df8fb1b5d868
- Child:
- 9:a2ba4015796e
--- a/dataRecorder.cpp Thu Apr 05 01:22:57 2018 -0400 +++ b/dataRecorder.cpp Thu Apr 05 04:08:32 2018 -0400 @@ -2,8 +2,6 @@ /* CONSTRUCTOR*/ DataRecorder::DataRecorder(){ - - DataRecorder(); //Initialize SDCard Reader Class m_saveBuddy = new SDCardReader(); @@ -24,6 +22,8 @@ uint16_t DataRecorder::popLastDataPoint(){ + printf("pop data\n"); + m_data_quantity--; if (m_data_quantity<0){ m_data_quantity=0; @@ -39,6 +39,7 @@ } uint32_t DataRecorder::popLastTimeStamp(){ + printf("pop time\n"); m_time_quantity--; if (m_time_quantity<0){ m_time_quantity=0; @@ -55,6 +56,7 @@ } void DataRecorder::logDistancePoint(uint16_t value){ + printf("push distance\n"); m_data_quantity++; if (m_data_quantity>BUF_SIZE){ m_data_quantity=BUF_SIZE; @@ -63,6 +65,7 @@ } void DataRecorder::logTimeStamp(uint32_t value){ + printf("push time\n"); m_time_quantity++; if (m_time_quantity>BUF_SIZE){ m_time_quantity=BUF_SIZE; @@ -70,24 +73,53 @@ 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 - int numPoints = m_data_quantity; //add check for timestamps + + printf("before logging, data quantity is %i\n",m_data_quantity); - int indexArr[m_data_quantity]; - for (int i = m_data_quantity; i >=0 ; i--){ + 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[m_time_quantity]; - uint16_t* allDataArr[m_data_quantity]; + //uint32_t timeArr[numPoints]; + //uint16_t* allDataArr[numPoints]; for (int i = 0; i < numPoints; i++){ - uint16_t dataEntry[1]; - dataEntry[1] = popLastDataPoint(); + //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); }