sdcard

Dependencies:   SDFileSystem mbed

Fork of rtcfinalcodeyuppie by Pradeep Kotipalli

Revision:
5:3979ca24777a
Parent:
4:374c51671a69
Child:
6:31a33cbe6cdb
--- a/rtsc.cpp	Mon Dec 22 14:33:30 2014 +0000
+++ b/rtsc.cpp	Tue Feb 03 17:10:21 2015 +0000
@@ -28,15 +28,9 @@
     hours1=hexint(hours1);
     minutes1=hexint(minutes1);
     seconds1=hexint(seconds1);
-    /*char y[3]=getstr(year);
-    char m[3]=getstr(month);
-    char dat[3]=getstr(date);
-    char da[3]=getstr(day);
-    char h[3]=getstr(hours);
-    char mi[3]=getstr(minutes);
-    char s[3]=getstr(seconds);*/
     char time[15];
     sprintf(time,"%02d%02d%02d%02d%02d%02d%02d",year1,month1,date1,day1,hours1,minutes1,seconds1);
+    
     return(time);
     
 }
@@ -46,39 +40,37 @@
     a=(a/16)*10+(a%16);
     return a;
 }
-
-char* getts(void)
+//storedata stores the dummy structure in the file with timestamp as the filename in HK directory
+void storedata(void)
 {
     spi.format(8,3);
     spi.frequency(1000000);
-    spiwrite(0x80);
-    spiwrite(0x81);
-    spiwrite(0x82);
-    spiwrite(0x83);
-    spiwrite(0x84);
-    spiwrite(0x85);
-    spiwrite(0x86);
+    spiwrite(0x80);           //write seconds to 01
+    spiwrite(0x81);           //write minutes t0 01
+    spiwrite(0x82);           //write hours  to 01
+    spiwrite(0x83);           //write day of week to 01
+    spiwrite(0x84);           //write day of month to 01
+    spiwrite(0x85);           //write month to 01
+    spiwrite(0x86);           //write year to 01
     for(int i=0;i<1000000;i++){
-    int seconds=spiread(0x00);
-    int minutes =spiread(0x01);
-    int hours =spiread(0x02);
-    int day =spi.write(0x03);
-    int date =spiread(0x04);
-    int month =spiread(0x05);
-    int year =spiread(0x06);
+    int seconds=spiread(0x00);     //read seconds
+    int minutes =spiread(0x01);    //read minutes
+    int hours =spiread(0x02);      //read hours
+    int day =spi.write(0x03);      //read day of the week
+    int date =spiread(0x04);       //read day of the month
+    int month =spiread(0x05);      //read month
+    int year =spiread(0x06);       //read year
     cs = 1;
     
-    wait(1);
-    printf("Seconds register = %2X : %2X : %2X : %2X : %2X : %2X : %2X \n\r",year,month,date,day, hours,minutes,seconds);
-     printf("b4 returning tmpstmp is : %s\n",getname(year,month,date,day,hours,minutes,seconds));
-     printf("Hello World!\n"); 
+    //Assigning dummy values to the structure
+    
     SensorData Sensor;
     
     printf("Writing dummy values\n");
     strcpy( Sensor.Voltage, "49");
     strcpy( Sensor.Current, "83");
-    strcpy( Sensor.Temperature, "53");
-    strcpy( Sensor.PanelTemperature, "43");
+    Sensor.Temperature ='5';
+    strcpy( Sensor.PanelTemperature, "4");
     Sensor.Vcell_soc='9';
     Sensor.alerts= '4';
     Sensor.crate='7';
@@ -86,9 +78,8 @@
     Sensor.faultpoll='4';            
     Sensor.faultir='g';              
     Sensor.power_mode='k';           
-    strcpy( Sensor.AngularSpeed, "49");
-    strcpy(Sensor.Bnewvalue,"76");
-    SensorData* Sensor1= &Sensor;
+    strcpy( Sensor.AngularSpeed, "9");
+    strcpy(Sensor.Bnewvalue,"6");
     printf("Done writing dummy values\n");
     mkdir("/sd/hk", 0777);
     char date2[100]="/sd/hk/";
@@ -101,9 +92,23 @@
     }
     else
     {
-    fwrite(Sensor1, sizeof(*Sensor1), 1, fp);
+    fprintf(fp, "%s -", Sensor.Voltage);
+    fprintf(fp,"%s -",Sensor.Current);
+    fprintf(fp,"%c -",Sensor.Temperature);
+    fprintf(fp,"%s -",Sensor.PanelTemperature);
+    fprintf(fp,"%c -",Sensor.Vcell_soc);            //printing the contents of the strucure in a single line in the file
+    fprintf(fp,"%c -",Sensor.alerts);
+    fprintf(fp,"%c -",Sensor.crate);
+    fprintf(fp,"%c -",Sensor.BatteryTemperature);
+    fprintf(fp,"%c -",Sensor.faultpoll);
+    fprintf(fp,"%c -",Sensor.faultir);
+    fprintf(fp,"%c -",Sensor.power_mode);
+    fprintf(fp,"%s -",Sensor.AngularSpeed);
+    fprintf(fp,"%s",Sensor.Bnewvalue);
     fclose(fp);
-    printf("Mission Accomplished\n");
-    printf("Goodbye World!\n");
+    printf("%s",getname(year,month,date,day,hours,minutes,seconds));
+    wait(10);
+    
+    
     }
     }}
\ No newline at end of file