SDFileSystem, slightly modified for the ExoController

Dependencies:   SDFileSystem

Dependents:   Data-Management-Honka

Fork of SDFileSystem_HelloWorld by Bradley Perry

Revision:
3:8f5903a77a13
Parent:
2:ec4d7e5fa68e
Child:
4:99e9c9e0dfb0
--- a/SDFile.cpp	Wed Dec 17 21:43:42 2014 +0000
+++ b/SDFile.cpp	Wed Feb 04 23:58:12 2015 +0000
@@ -4,42 +4,58 @@
 #include "errno.h"
 
 
-SDFile::SDFile(string path, string filename) {
+SDFile::SDFile(string path, string filename)
+{
     //Creates the necessary directory
-    char *a=new char[path.size()+1];
-    a[path.size()]=0;
+    printf("Creating SDFile object\r\n");
+    char *a = new char[path.size()+1];
+    a[path.size()] = 0;
     memcpy(a,path.c_str(),path.size());
-    int dir = mkdir((const char *)a, 0777);
     //Calculates the full filename, then creates the file
     std::string fullname = path + filename;
 
-    char *b=new char[filename.size()+1];
-    b[filename.size()]=0;
-    memcpy(b,filename.c_str(),filename.size());
-    fp = fopen((const char*)b, "w+");
+    char *b = new char[fullname.size()+1];
+    b[fullname.size()] = 0;
+    memcpy(b,fullname.c_str(),fullname.size());
+    _fp = fopen((const char*)b, "w+");
+    printf("fp is %d\r\n", _fp);
     
     
 }
 
-//Reads from the file pointed to by FP to an array
-int* SDFile::read(int *array, int length) {
+/**
+* This function reads bytes from the SDFile object.
+* @author Michael Ling
+* @param length    The number of bytes to read
+* @param array    The int array the bytes are copied to
+* @date 2/2/2015
+*/
+int* SDFile::read(int length, int *array)
+{
    
     //shift to the end of the file and go back accounting for the commas, spaces, \n, and \r (6 places per data)
-    fseek(fp, -6*length, SEEK_END);
+    fseek(_fp, -6*length, SEEK_END);
     //cycle through the length of the vector and read the values.
-    for(int i=0; i<length; i++) {
-        fscanf(fp, "%x, ", &array[i]);
+    for(int i = 0; i < length; i++) {
+        fscanf(_fp, "%x, ", &array[i]);
     }
    
     return array;
 }
 
-//writes from an array to the file pointed to by fp
-void SDFile::write(int *array, int length) {
-    fseek(fp, 0, SEEK_SET);
-    for(int i=0; i<length-1; i++) {
-        fprintf(fp,"%04x, ", array[i]);
+/** 
+* This function writes from an array to the file pointed to by fp
+* @param length    length of data to write
+* @param array    array to draw written data from
+* @author Michael Ling
+* @date 2/2/2015
+*/
+void SDFile::write(int length, int *array)
+{
+    fseek(_fp, 0, SEEK_SET);
+    for(int i = 0; i < length-1; i++) {
+        fprintf(_fp, "%04x, ", array[i]);
     }
-    fprintf(fp, "%04x\r\n", array[length-1]);
+    fprintf(_fp, "%04x\r\n", array[length-1]);
 }
     
\ No newline at end of file