GDP group 24 node core

Dependencies:   EthernetInterface SDFileSystem mbed-rtos mbed snail MbedJSONValue

Committer:
jakehodges
Date:
Tue Jan 13 23:40:29 2015 +0000
Revision:
19:70c911d35e67
Parent:
0:fcab3b154e49
Child:
23:b57a47c7862a
Change SD card directory structure to use type codes rather than hard-coded strings

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Trumple 0:fcab3b154e49 1 #include <string>
Trumple 0:fcab3b154e49 2 #include "sdcard.h"
Trumple 0:fcab3b154e49 3 #include <map>
Trumple 0:fcab3b154e49 4
Trumple 0:fcab3b154e49 5 sdcard::sdcard(): sd(p5, p6, p7, p8, "sd")
jakehodges 19:70c911d35e67 6 {
Trumple 0:fcab3b154e49 7 //first write sometimes fails, let's ensure the first write isn't real data
Trumple 0:fcab3b154e49 8 FILE *fp = fopen("/sd/boot", "w");
Trumple 0:fcab3b154e49 9 fprintf(fp, "boot");
Trumple 0:fcab3b154e49 10 fclose(fp);
Trumple 0:fcab3b154e49 11 }
Trumple 0:fcab3b154e49 12
Trumple 0:fcab3b154e49 13 int sdcard::write(long int time, d_reply data)
Trumple 0:fcab3b154e49 14 {
Trumple 0:fcab3b154e49 15
Trumple 0:fcab3b154e49 16 string sd_name = "/sd/";
Trumple 0:fcab3b154e49 17 string sd_location ="";
Trumple 0:fcab3b154e49 18 char time_s[64];
Trumple 0:fcab3b154e49 19
jakehodges 19:70c911d35e67 20 sd_location = sd_name + data.type;
Trumple 0:fcab3b154e49 21 mkdir(sd_location.c_str(), 0777);
Trumple 0:fcab3b154e49 22
Trumple 0:fcab3b154e49 23 sprintf(time_s, "%d", time);
Trumple 0:fcab3b154e49 24 sd_location += "/" + string(time_s) + ".txt";
Trumple 0:fcab3b154e49 25
Trumple 0:fcab3b154e49 26 FILE *fp = fopen(sd_location.c_str(), "w");
Trumple 0:fcab3b154e49 27
Trumple 0:fcab3b154e49 28 if (fp == NULL)
Trumple 0:fcab3b154e49 29 {
Trumple 0:fcab3b154e49 30 printf("File pointer null, failed to open file\r\n");
Trumple 0:fcab3b154e49 31 }
Trumple 0:fcab3b154e49 32
Trumple 0:fcab3b154e49 33 string serializedData;
Trumple 0:fcab3b154e49 34
Trumple 0:fcab3b154e49 35 for (int i = 0; i < data.readings.size(); i++)
Trumple 0:fcab3b154e49 36 fprintf(fp, "%i", data.readings[i]);
Trumple 0:fcab3b154e49 37
Trumple 0:fcab3b154e49 38 fclose(fp);
Trumple 0:fcab3b154e49 39
Trumple 0:fcab3b154e49 40 return 1;
Trumple 0:fcab3b154e49 41 }