for checking i2c with integrated bae
Dependencies: SDFileSystem mbed-rtos mbed
Diff: sdcard.cpp
- Revision:
- 0:cb112a717428
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sdcard.cpp Mon Sep 15 14:01:49 2014 +0000 @@ -0,0 +1,109 @@ +#include "sdcard.h" + +/*SDFileSystem sd(p5, p6, p7, p8, "sd"); // mosi, miso, clk, cs, name + +void writedummies(SensorData* Sensor){ + int i; + printf("Writing dummy values\n"); //Debug statement + for(i=0; i<10; i++) (*Sensor).Voltage[i] = 35.14; //dummy values. Will be removed + for(i=0; i<10; i++) (*Sensor).Current[i] = 644.46; + for(i=0; i<10; i++) (*Sensor).Temp[i] = 6534.03; + printf("Done writing dummy values\n"); +} + +void setfilenames(char* beaname, char* acsname, char* epsname, time_t seconds){ + char date[7]; + printf("Setting file names\n"); + strftime(date, 7, "%d%m%y", localtime(&seconds)); //getting ddmmyy from unix time + printf("%s\t%s\t%s\n", beaname, acsname, epsname); + + printf("Appending file extensions\n"); + for(int i=10; i<16; i++){ + printf("In %dth iteration",i); + beaname[i] = date[i-10]; //creating file name for beacon hk + } + beaname[16] = '.'; beaname[17] = 't'; beaname[18] = 'x'; beaname[19] = 't'; beaname[20]='\0'; + + for(int i=10; i<16; i++) acsname[i] = date[i-10]; //creating file name for acs hk + acsname[16] = '.'; acsname[17] = 't'; acsname[18] = 'x'; acsname[19] = 't'; acsname[20]='\0'; + + for(int i=10; i<16; i++) epsname[i] = date[i-10]; //creating file name for eps hk + epsname[16] = '.'; epsname[17] = 't'; epsname[18] = 'x'; epsname[19] = 't'; epsname[20]='\0'; + + printf("All filenames created\n"); //Debug statement +} + +void writevaluesf(char* beaname, char* acsname, char* epsname, time_t seconds, SensorData* Sensor){ + FILE* fp; + char time[7]; + strftime(time, 7, "%H%M%S", localtime(&seconds)); //getting time from unix time + + fp = fopen(beaname,"w"); + if(fp == NULL) { + error("Could not open file for write\n"); + } + else{ + //fprintf(fp,"%s\n",time); //time stamping: Look for a better way + fwrite((*Sensor).Voltage, sizeof(float), BEANUM, fp); //needs to be changed + fclose(fp); + } + + fp = fopen(acsname,"w"); + if(fp == NULL) { + error("Could not open file for write\n"); + } + else{ + //fprintf(fp,"%s\n",time); //time stamping: Look for a better way + fwrite((*Sensor).Current, sizeof(float), ACSNUM, fp); //needs to be changed + fclose(fp); + } + + fp = fopen(epsname,"w"); + if(fp == NULL) { + error("Could not open file for write\n"); + } + else{ + //fprintf(fp,"%s\n",time); //time stamping: Look for a better way + fwrite((*Sensor).Temp, sizeof(float), EPSNUM, fp); //needs to be changed + fclose(fp); + } + + printf("Writing over\n"); //Debug statement +} + +//Function for debugging purposes +void readvaluesff(char* beaname, char* acsname, char* epsname, SensorData* Sensor){ + FILE* fpr; //debug only + float* readstr = (float*) malloc( sizeof(float) * 30); //reading back for debugging + + fpr = fopen(beaname,"r"); + if(fpr == NULL) { + error("Could not open file for read\n"); + } + else{ + fread(readstr, sizeof(float), 10, fpr); + } + fclose(fpr); + + fpr = fopen(acsname,"r"); + if(fpr == NULL) { + error("Could not open file for read\n"); + } + else{ + fread((readstr+10), sizeof(float), 10, fpr); + } + fclose(fpr); + + fpr = fopen(epsname,"r"); + if(fpr == NULL) { + error("Could not open file for read\n"); + } + else{ + fread((readstr+20), sizeof(float), 10, fpr); + } + fclose(fpr); + + for(int i=0; i<30; i++) + printf("%f\n",readstr[i]); +} +*/ \ No newline at end of file