![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
sdcard
Dependencies: SDFileSystem mbed
Fork of rtcfinalcodeyuppie by
rtsc.cpp
00001 #include "rtsc.h" 00002 SPI spi(PTD6, PTD7, PTD5); 00003 //DigitalOut cs(PTD2); 00004 00005 SDFileSystem sd(PTD6, PTD7, PTD5, PTD2,"sd"); 00006 00007 /*void spiwrite(int a) 00008 { 00009 cs=1; 00010 cs=0; 00011 spi.write(a); 00012 spi.write(0x01); 00013 } 00014 00015 int spiread(int a) 00016 { 00017 cs=1; 00018 cs=0; 00019 spi.write(a); 00020 return(spi.write(0x00)); 00021 } 00022 char* getname(int year1,int month1,int date1,int day1,int hours1,int minutes1,int seconds1) 00023 { 00024 year1= hexint(year1); 00025 month1=hexint(month1); 00026 date1=hexint(date1); 00027 day1=hexint(day1); 00028 hours1=hexint(hours1); 00029 minutes1=hexint(minutes1); 00030 seconds1=hexint(seconds1); 00031 char time[15]; 00032 sprintf(time,"%02d%02d%02d%02d%02d%02d%02d",year1,month1,date1,day1,hours1,minutes1,seconds1); 00033 00034 return(time); 00035 00036 }*/ 00037 00038 int hexint(int a) 00039 { 00040 a=(a/16)*10+(a%16); 00041 return a; 00042 } 00043 //storedata stores the dummy structure in the file with timestamp as the filename in HK directory 00044 void storedata(void) 00045 { 00046 /*spi.format(8,3); 00047 spi.frequency(1000000); 00048 spiwrite(0x80); //write seconds to 01 00049 spiwrite(0x81); //write minutes t0 01 00050 spiwrite(0x82); //write hours to 01 00051 spiwrite(0x83); //write day of week to 01 00052 spiwrite(0x84); //write day of month to 01 00053 spiwrite(0x85); //write month to 01 00054 spiwrite(0x86); //write year to 01 00055 for(int i=0;i<1000000;i++){ 00056 int seconds=spiread(0x00); //read seconds 00057 int minutes =spiread(0x01); //read minutes 00058 int hours =spiread(0x02); //read hours 00059 int day =spi.write(0x03); //read day of the week 00060 int date =spiread(0x04); //read day of the month 00061 int month =spiread(0x05); //read month 00062 int year =spiread(0x06); //read year 00063 cs = 1; */ 00064 00065 00066 mkdir("/sd/TIME", 0777); 00067 FILE*fp1= fopen("/sd/TIME/timer.txt", "w"); 00068 if(fp1 == NULL) { 00069 error("Could not open file for write\n"); 00070 } 00071 fclose(fp1); 00072 00073 //Assigning dummy values to the structure 00074 for(int i=0;i<1000000;i++){ 00075 SensorData Sensor; 00076 00077 printf("Writing dummy values\n"); 00078 strcpy( Sensor.Voltage, "49"); 00079 strcpy( Sensor.Current, "83"); 00080 Sensor.Temperature ='5'; 00081 strcpy( Sensor.PanelTemperature, "4"); 00082 Sensor.Vcell_soc='9'; 00083 Sensor.alerts= '4'; 00084 Sensor.crate='7'; 00085 Sensor.BatteryTemperature='6'; 00086 Sensor.faultpoll='4'; 00087 Sensor.faultir='g'; 00088 Sensor.power_mode='k'; 00089 strcpy( Sensor.AngularSpeed, "9"); 00090 strcpy(Sensor.Bnewvalue,"6"); 00091 printf("Done writing dummy values\n"); 00092 mkdir("/sd/hk", 0777); 00093 char date2[100]="/sd/hk/"; 00094 char str[15]; 00095 sprintf(str, "%d", i); 00096 strcat(date2,str); 00097 strcat(date2,".txt"); 00098 00099 if(i%20==0) 00100 {FILE *fp ; 00101 Timer t1; 00102 t1.start(); 00103 fp= fopen(date2, "w"); 00104 if(fp == NULL) { 00105 error("Could not open file for write\n"); 00106 } 00107 else 00108 { 00109 int p; 00110 for(p=0;p<20;p++) 00111 {fprintf(fp, "%s -", Sensor.Voltage); 00112 fprintf(fp,"%s -",Sensor.Current); 00113 fprintf(fp,"%c -",Sensor.Temperature); 00114 fprintf(fp,"%s -",Sensor.PanelTemperature); 00115 fprintf(fp,"%c -",Sensor.Vcell_soc); //printing the contents of the strucure in a single line in the file 00116 fprintf(fp,"%c -",Sensor.alerts); 00117 fprintf(fp,"%c -",Sensor.crate); 00118 fprintf(fp,"%c -",Sensor.BatteryTemperature); 00119 fprintf(fp,"%c -",Sensor.faultpoll); 00120 fprintf(fp,"%c -",Sensor.faultir); 00121 fprintf(fp,"%c -",Sensor.power_mode); 00122 fprintf(fp,"%s -",Sensor.AngularSpeed); 00123 fprintf(fp,"%s\n",Sensor.Bnewvalue);} 00124 fclose(fp); 00125 t1.stop(); 00126 float timesd=t1.read(); 00127 printf("The time taken for writing 5 hk data was %f seconds\n", timesd); 00128 //printf("%s",getname(year,month,date,day,hours,minutes,seconds)); 00129 FILE *fp2=fopen("/sd/TIME/timer.txt", "a"); 00130 if(fp2 == NULL) { 00131 error("Could not open file for write\n"); 00132 } 00133 else 00134 { 00135 fprintf(fp2,"%f \n",timesd); 00136 00137 } 00138 fclose(fp2); 00139 wait(3); 00140 00141 00142 }} 00143 }}
Generated on Sun Jul 24 2022 23:21:37 by
![doxygen](doxygen.png)