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:
1:45627bbdeb69
Parent:
0:ebe71c7e7854
Child:
2:c2cfb0ebc3bd
--- a/dataRecorder.h	Tue Apr 03 21:50:25 2018 +0000
+++ b/dataRecorder.h	Tue Apr 03 22:41:46 2018 -0400
@@ -1,58 +1,67 @@
 #include "mbed.h"
 #include "platform/CircularBuffer.h"
- 
-#define BUF_SIZE    150
+#include "sdCardReader.h"
 
+
+//converts number to string
 #include <sstream>
 #define SSTR( x ) static_cast< std::ostringstream & >(( std::ostringstream() << std::dec << x ) ).str()
 
-// include circular buffer
+// Define circular buffer size
+#define BUF_SIZE    150
+
+
+/** Data Recorder is a class that stores data measurements in a ring buffer. 
+It contains an SD Card Reader with a filesystem to store measurements when required  **/
 
 class DataRecorder{
   public:
     DataRecorder();
-    
-    int getNumStored();
-    uint16_t popLastValue();
-    
-    
-    uint8_t* getDistanceBlock();
-    int getDistanceDataLength();
+
+    /** Get Information **/
+    // gets the number of values stored in the circular buffer
+    int getQuantityStored();
     
-    //writes input value to buffer
-    void LogDistancePoint(uint16_t value);
-    
-    void savePoint(uint16_t value);
-        
-        
+    // pops the last value off of the circular buffer 
+    uint16_t popLastDataPoint();
+    uint32_t popLastTimeStamp();
+
+    /** Set Information **/
+    void logDistancePoint(uint16_t value);
+    void logTimeStamp(uint32_t value);
+ 
+    /** Save logged data to SD card **/
+    void saveLoggedData(string filename);
     //saves buffer to sd card and clears it    
-    int WriteDataAndClearBuffer();
-    
+    void saveLoggedDataAndClearBuffer(string filename);
+
     
   private:
-  
-    
+
+    void savePoint(uint16_t value);
     void pushEleToBuffer(uint16_t);
     // input values are converted to char arrays
     // iterate over char array to add values to buffer
     // buffer contents it turned into a uint8_t array and written to 
     // sd card
+
+    /* Buffers for Data Storage */
+    CircularBuffer<uint16_t, BUF_SIZE> buf_data;
+    CircularBuffer<uint32_t, BUF_SIZE> buf_timestamp;
+
+    // Count for buffers
+    int m_data_quantity;
     
-    // clear pops all elements out of buffer.
-    CircularBuffer<char, BUF_SIZE> buf;
-    char data_stream[];// = "DataToBeAddedToBuffer";
-    uint32_t bytes_written;// = 0;
-    int m;
-    const uint8_t separator = ' ';
-  
-    //sdcard blocks
-    uint8_t blockDistance[4096];
-    int blockDistance_Index;
+    /* SD Card Interface Object  */
+    SDCardReader* m_saveBuddy;
+
+
+
     
     //specialized buffers
-    CircularBuffer<uint16_t, BUF_SIZE> buf_distance;
-    CircularBuffer<uint16_t, BUF_SIZE> buf_kalmanAngle;
-    CircularBuffer<uint32_t, BUF_SIZE> buf_timestamp;
+    //CircularBuffer<uint16_t, BUF_SIZE> buf_distance;
+    //CircularBuffer<uint16_t, BUF_SIZE> buf_kalmanAngle;
+    //CircularBuffer<uint32_t, BUF_SIZE> buf_timestamp;
     
     /*CircularBuffer<char, BUF_SIZE> buf_accX;
     CircularBuffer<char, BUF_SIZE> buf_accY;
@@ -61,38 +70,15 @@
     CircularBuffer<char, BUF_SIZE> buf_gyroY;
     CircularBuffer<char, BUF_SIZE> buf_gyroZ;*/
     
-    
+    //sdcard blocks
+    //uint8_t blockDistance[4096];
+    //int blockDistance_Index;
+
+    // clear pops all elements out of buffer.
+    /*CircularBuffer<char, BUF_SIZE> buf;
+    char data_stream[];// = "DataToBeAddedToBuffer";
+    uint32_t bytes_written;// = 0;
+    int m;
+    const uint8_t separator = ' ';*/
     
 };
-
-/*
-
-  uint32_t bytes_written = 0;
-    
-    while (!buf.full()) {
-        buf.push(data_stream[bytes_written++]);
-    }
-    
-    printf("Circular buffer is full: \"%s\" or empty: \"%s\" \n", 
-           (buf.full()? "true":"false"), 
-           (buf.empty()? "true":"false") );
-    printf ("Bytes written %d \n", bytes_written);
-    
-    // If buffer is full, contents will be over-written
-    buf.push(data_stream[bytes_written++]);
-    
-    char data;
-    printf ("Buffer contents: ");
-    while (!buf.empty()) {
-        buf.pop(data);
-        printf("%c", data);
-    }
-    printf("\n");
- 
-    printf("Circular buffer is full: \"%s\" or empty: \"%s\" \n", 
-           (buf.full()? "true":"false"), 
-           (buf.empty()? "true":"false") );
- 
-    return 0;
-    
-    */
\ No newline at end of file