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:
5:0a4ff027086c
Parent:
4:fe6d2823b7cb
Child:
6:a36eda5701df
--- a/sdCardReader.cpp	Thu Apr 05 01:22:57 2018 -0400
+++ b/sdCardReader.cpp	Thu Apr 05 04:08:32 2018 -0400
@@ -3,6 +3,9 @@
 
 //helpers
 int getSize(int* p){
+  printf("reg p %i \n",sizeof(p));
+  printf("star p %i \n",sizeof(*p));
+  
   return (sizeof(p)/sizeof(*p));
 }
 
@@ -63,15 +66,17 @@
   FILE *f = fileToUse;
   printf("%s\n", (!f ? "Fail :(" : "OK"));
   
-  printf("\rWriting 16 bit value: %" PRIu16, data);
+  //printf("\rWriting 16 bit value: % " PRIu16 " ", data);
+  printf("\rWriting 16 bit value %i ", static_cast<int>(data));
   fflush(stdout);
 
   int err = 0;
   //write and check for error
   if (endline){
-    err = fprintf(f,"%" PRIu16 "\n",data);
+    err = fprintf(f,"%i\n",static_cast<int>(data));
+    //err = fprintf(f,"%" PRIu16 "\n",data);
   }else{
-    err = fprintf(f,"%" PRIu16,data);
+    err = fprintf(f,"%i " ,static_cast<int>(data));
   }
 
   if (err < 0) {
@@ -85,16 +90,17 @@
   FILE *f = fileToUse;
   printf("%s\n", (!f ? "Fail :(" : "OK"));
 
-  printf("\rWriting 32 bit value:  %" PRIu32, data);
-  //printf("\rWriting datapoint %d", data);
+  //printf("\rWriting 32 bit value:  %" PRIu32 " ", data);
+  printf("\rWriting 32 bit value %i ", static_cast<int>(data));
   fflush(stdout);
 
   int err = 0;
   //write and check for error
   if (endline){
-    err = fprintf(f,"%" PRIu32 "\n",data);
+    //err = fprintf(f,"%" PRIu32 "\n",data);
+    err = fprintf(f,"%i\n",static_cast<int>(data));
   }else{
-    err = fprintf(f,"%" PRIu32,data);
+    err = fprintf(f,"%i ",static_cast<int>(data));
   }
   
   if (err < 0) {
@@ -117,11 +123,13 @@
   } 
 }
 
-int SDCardReader::fullWriteProcedure(string filename,int* indexArr, uint32_t* timeArr, uint16_t** allData){
+int SDCardReader::fullWriteProcedure(string filename,vector<int> indexArr, vector<uint32_t> timeArr, vector<vector <uint16_t> > allData){
   mountFileSystem();
   FILE* theFile = openFile(filename);
 
-  for (int i = 0; i<getSize(indexArr); i++){
+  printf("The size of indexArr is %i \n",indexArr.size());
+  
+  for (unsigned int i = 0; i< indexArr.size(); i++){
     writeDataPoint(theFile,indexArr[i],timeArr[i], allData[i]);
   }
   
@@ -134,7 +142,7 @@
 //use circular buffers instead of strings
 //write as 1st column, index. 2nd column timestamp. 3rd column data1. 4th data2. etc.
 //pass in array of circular buffers 
-int SDCardReader::writeDataPoint(FILE* theFile, int index, uint32_t timestamp, uint16_t* data){
+int SDCardReader::writeDataPoint(FILE* theFile, int index, uint32_t timestamp, vector<uint16_t> data){
   //  FILE* theFile = openFile(filename);
 
   //write index
@@ -143,17 +151,11 @@
   write_uint32_t(timestamp, false, theFile);
 
   //write data
-  for (int i = 0; i < getSize(data)-1; i++) {
+  for (unsigned int i = 0; i < data.size()-1; i++) {
     write_uint16_t(data[i], false, theFile);
   }
-  write_uint16_t(data[getSize(data)], false, theFile);
-  
-  closeFile(theFile);
-  
-  // call the SDBlockDevice instance de-initialisation method.
-    this->deinit();
-    
-    return 0;
+  write_uint16_t(data[data.size()], true, theFile);
+  return 0;
 }
 
 int SDCardReader::eraseData(){