Daniel Levine / CircularBufferSDCardLib

Dependencies:   sd-driver_compatible_with_MAX32630FTHR

Fork of CircularBufferSDCardLib by Daniel Levine

Files at this revision

API Documentation at this revision

Comitter:
DVLevine
Date:
Fri Apr 27 02:11:18 2018 -0400
Parent:
11:c70e8305ddd7
Child:
13:91350588d530
Commit message:
Added incrementor that uses a designated text file trialNum.txt to write an integer and to increment that integer everytime it is read.
A convenience function that should likely be broken out into separate ones later.

Changed in this revision

dataRecorder.cpp Show annotated file Show diff for this revision Revisions of this file
dataRecorder.h Show annotated file Show diff for this revision Revisions of this file
sdCardReader.cpp Show annotated file Show diff for this revision Revisions of this file
sdCardReader.h Show annotated file Show diff for this revision Revisions of this file
--- a/dataRecorder.cpp	Tue Apr 10 23:49:52 2018 -0400
+++ b/dataRecorder.cpp	Fri Apr 27 02:11:18 2018 -0400
@@ -137,3 +137,7 @@
   saveLoggedData(filename);
   // then eraseBuffers();
 }
+
+int DataRecorder::getTrialNumAndIncrement(){
+  return m_saveBuddy->readAndIncrement("trialNum.txt");
+}
--- a/dataRecorder.h	Tue Apr 10 23:49:52 2018 -0400
+++ b/dataRecorder.h	Fri Apr 27 02:11:18 2018 -0400
@@ -11,7 +11,7 @@
 #define SSTR( x ) static_cast< std::ostringstream & >(( std::ostringstream() << std::dec << x ) ).str()
 
 // Define circular buffer size
-#define BUF_SIZE    2000
+#define BUF_SIZE    10000
 
 
 /** Data Recorder is a class that stores data measurements in a ring buffer. 
@@ -38,6 +38,8 @@
     //saves buffer to sd card and clears it    
     void saveLoggedDataAndClearBuffer(string filename);
 
+    int getTrialNumAndIncrement();
+
     
   private:
 
--- a/sdCardReader.cpp	Tue Apr 10 23:49:52 2018 -0400
+++ b/sdCardReader.cpp	Fri Apr 27 02:11:18 2018 -0400
@@ -62,9 +62,11 @@
   return f;
 }
 
-void SDCardReader::write_uint16_t(uint16_t data, bool endline, FILE* fileToUse){
+void SDCardReader::write_uint16_t(uint16_t in_data, bool endline, FILE* fileToUse){
   FILE *f = fileToUse;
   printf("%s\n", (!f ? "Fail :(" : "OK"));
+
+  int16_t data = (int16_t)in_data;
   
   //printf("\rWriting 16 bit value: % " PRIu16 " ", data);
   printf("\rWriting 16 bit value %i ", static_cast<int>(data));
@@ -184,5 +186,32 @@
     }
 
     return err;
-} 
+}
+
+//Methods for reading sdcard files. Mostly to read off trial numbers
+int SDCardReader::readAndIncrement(string filename){
+  mountFileSystem();
+  
+  FILE* theFile = openFile(filename);
+  // Get current stream position
+  long pos = ftell(theFile);
+  // Parse out the number 
+  int32_t number;
+  int32_t presentNumber;
+  
+  fscanf(theFile, "%d", &number);
+  presentNumber = number;
+  number += 1;
+  //read lone value as int, return it
+  // Seek to beginning of number
+  fseek(theFile, pos, SEEK_SET);
+  // Store number
+  fprintf(theFile, "%d\n", number);
+  // Flush between write and read on same file
+  fflush(theFile);
+  
+  closeFile(theFile);
+  unmountFileSystem();
+  return (int)presentNumber;
+}
    
--- a/sdCardReader.h	Tue Apr 10 23:49:52 2018 -0400
+++ b/sdCardReader.h	Fri Apr 27 02:11:18 2018 -0400
@@ -31,6 +31,12 @@
 		
 	void mountFileSystem();
 	void unmountFileSystem();
+
+
+	//Read and increment for keeping track of SDcard files
+	//Each file gets a new number
+	int readAndIncrement(string filename); 
+
 	
     private: