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 Daniel Levine

Revision:
2:c2cfb0ebc3bd
Parent:
1:45627bbdeb69
Child:
3:df8fb1b5d868
--- a/dataRecorder.cpp	Tue Apr 03 22:41:46 2018 -0400
+++ b/dataRecorder.cpp	Wed Apr 04 16:17:34 2018 -0400
@@ -13,102 +13,79 @@
 
 /* PUBLIC METHODS */
 
-int DataRecorder::getQuantityStored(){
+int DataRecorder::getDataQuantity(){
   return m_data_quantity;
 }
 
+int DataRecorder::getTimeStampQuantity(){
+  return m_time_quantity;
+}
+
 
 uint16_t DataRecorder::popLastDataPoint(){
-  return m_buf_data.pop();
+  m_data_quantity--;
+    if (m_data_quantity<0){
+    m_data_quantity=0;
+  }
+    if(!m_buf_data.empty()){
+      return m_buf_data.pop();
+    }else{
+      return (uint16_t)0;
+    }
+  
 }
 
 uint32_t DataRecorder::popLastTimeStamp(){
-  return m_buf_timestamp.pop();
+  m_time_quantity--;
+  if (m_time_quantity<0){
+    m_time_quantity=0;
+  }
+
+  if(!m_buf_time.empty()){
+    return m_buf_time.pop();
+  }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 indexArr[m_data_quantity];
+  for (int i = indexArr.size-1; i >=0 ; i--){
+    indexArr[i] = i;
+  }
+  
+  uint32_t timeArr[m_time_quantity];
+  uint16_t* allDataArr[m_data_quantity];
 
-
+  for (int i = 0; i < allDataArr.size; 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();
 }
-
-
-/* PRIVATE METHODS */
-
-
-
-//private buffer load in method
-void DataRecorder::pushEleToBuffer(uint16_t inputVal){
-  buf_distance.push(inputVal);
-  //   while (!buf.full()) {
-    //    buf.push(inputVal);
-   // }
-     
-}
-
-uint8_t* DataRecorder::getDistanceBlock(){
- return blockDistance;
-}
-
-int DataRecorder::getDistanceDataLength(){
-  return blockDistance_Index;   
-};
-
-
-//writes input value to buffer
-void DataRecorder::LogDistancePoint(uint16_t value){
-    buf_distance.push(value);
-    savePoint(value);
-}
-
-void DataRecorder::savePoint(uint16_t value){
-    string yo = SSTR(value);
-    int n = yo.length(); 
-   // declaring character array
-    char char_array[n+1]; 
-     
-   // copying the contents of the 
-   // string to char array
-    strcpy(char_array, yo.c_str()); 
-    
-    
-    int counter = 0;
-    
-    for (int i=blockDistance_Index; i<blockDistance_Index+n; i++){
-      blockDistance[i] = char_array[counter];
-      //printf("%i\n",i);
-      //printf("%c\n",blockDistance[i]);
-      counter++;
-    }
-    
-    blockDistance_Index = blockDistance_Index+n;
-    
-    //add separator
-    blockDistance[blockDistance_Index] = ' ';
-    blockDistance_Index++;
-    
-    //buf.push(char_array[i]); 
-    //buf_distance        
-}
-        
-
-void DataRecorder::savePoint(uint16_t value);
-
-
-
-void DataRecorder::pushEleToBuffer(uint16_t);