hi

Dependencies:   SDFileSystem mbed

Fork of SDFileSystem_HelloWorld by mbed official

Files at this revision

API Documentation at this revision

Comitter:
Ishwar_Anjana
Date:
Mon Dec 25 17:35:11 2017 +0000
Parent:
1:e4d7342be507
Child:
3:5e6d3d2b2557
Commit message:
hi

Changed in this revision

SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/SDFileSystem.lib	Tue May 16 05:18:55 2017 +0000
+++ b/SDFileSystem.lib	Mon Dec 25 17:35:11 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/SDFileSystem/#8db0d3b02cec
+http://mbed.org/users/mbed_official/code/SDFileSystem/#5a50a96290c2
--- a/main.cpp	Tue May 16 05:18:55 2017 +0000
+++ b/main.cpp	Mon Dec 25 17:35:11 2017 +0000
@@ -1,19 +1,139 @@
 #include "mbed.h"
 #include "SDFileSystem.h"
+#include <string>
+#include <vector>\
+#include <stdio.h>
+#include <iostream>
  
-SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
+ 
+SDFileSystem sd(D11, D12, D13, D10, "sd"); // the pinout on the mbed Cool Components workshop board
+ 
+//.....assumes SDFileSystem is setup in earlier code for device "/sd"
+ 
+vector<string> filenames;    //filenames are stored in a vector string
+vector<string> filedata;      //file data is stored in a vector string
+///////////////////////////////////////////////////////////////////////////////
+using namespace std;
+typedef unsigned char BYTE;
+
+long getFileSize(FILE *file)
+{
+    long lCurPos,lEndPos;
+    lCurPos = ftell(file);
+    fseek(file,lCurPos, 0);
+    return lEndPos;    
+}
+//////////////////////////////////////////////////////////////////////////////
+
+
  
+void read_file_names(char *dir)
+{
+    DIR *dp;
+    struct dirent *dirp;
+    dp = opendir(dir);
+  //read all directory and file names in current directory into filename vector
+    while((dirp = readdir(dp)) != NULL) {
+        filenames.push_back(string(dirp->d_name));  
+    }
+    closedir(dp);
+}
+void read_file_data (char *dir)
+{
+    DIR *dp;
+    struct dirent *dirp;
+    dp = opendir(dir);
+  //read all directory and file names in current directory into filename vector
+    while((dirp = readdir(dp)) != NULL) {
+        filenames.push_back(string(dirp->d_name));  
+    }
+    closedir(dp);
+}
 int main() {
     printf("Hello World!\n");   
  
-    mkdir("/sd/mydir", 0777);
+    
     
-    FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
+    FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");                                                                                                 
     if(fp == NULL) {
         error("Could not open file for write\n");
     }
     fprintf(fp, "Hello fun SD Card World!");
+    
     fclose(fp); 
  
     printf("Goodbye World!\n");
-}
+                                                                                                                             
+    printf("Reading files!\n");
+    
+    read_file_names("/sd");
+        //read_file_data("/sd/sky.raw");
+    
+     // print filename strings from vector using an iterator
+ for(vector<string>::iterator it=filenames.begin(); it < filenames.end(); it++)  
+  {
+    printf("%s\n\r",(*it).c_str());
+  }
+ //////////////////////////////////////////////////////////////////////////////
+ const char *filePath = "/sd/sky.raw";
+BYTE *fileBuf;
+FILE *file = NULL;
+
+if ((file = fopen(filePath, "rb"))== NULL)
+    {
+        //cout << "Could not open the file" << end1 ;
+        printf("Could not open the file");
+    
+    }
+else
+{
+ 
+       // cout << "opening file successfull" << end1 ;
+        printf("opening file successfull");
+ }
+ 
+ long fileSize = getFileSize(file);
+ 
+ fileBuf = new BYTE[fileSize];
+ 
+ fread(fileBuf, fileSize, 1, file);
+ 
+ for(int i=0; i<100; i++)
+ {
+    printf("%X", fileBuf[i]);
+     }
+
+cin.get();
+delete[]fileBuf;
+fclose(file);
+/////////////////////////////////////////////////////////////////////////////////
+
+
+
+/////////////////////////////////////////////////////////////////////////////////
+
+
+
+  fp = fopen("/sd/mydir/sdtest.txt", "r+");
+    if(fp == NULL){
+        printf("error in opening file");
+    }
+    
+//    fread(fp, buff, 10, readBuff);
+    char line[100]; /* Line buffer */
+//    FRESULT fr;     /* FatFs return code */
+    /* Read all lines and display it */
+    while (fgets(line, sizeof line, fp)) {
+        printf(line);
+    }
+    
+    fscanf(fp, line, sizeof line);
+    
+    printf("Reading line %s", line);
+    }
+    
+
+
+
+
+
--- a/mbed.bld	Tue May 16 05:18:55 2017 +0000
+++ b/mbed.bld	Mon Dec 25 17:35:11 2017 +0000
@@ -1,1 +1,1 @@
-https://mbed.org/users/mbed_official/code/mbed/builds/e1686b8d5b90
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/7130f322cb7e
\ No newline at end of file