![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
sdcard
Dependencies: SDFileSystem mbed
Fork of rtcfinalcodeyuppie by
rtsc.cpp@6:31a33cbe6cdb, 2015-06-04 (annotated)
- Committer:
- cholletisaik777
- Date:
- Thu Jun 04 10:46:25 2015 +0000
- Revision:
- 6:31a33cbe6cdb
- Parent:
- 5:3979ca24777a
sd card
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pradeepvk2208 | 3:6cde88f8c50f | 1 | #include "rtsc.h" |
pradeepvk2208 | 3:6cde88f8c50f | 2 | SPI spi(PTD6, PTD7, PTD5); |
cholletisaik777 | 6:31a33cbe6cdb | 3 | //DigitalOut cs(PTD2); |
pradeepvk2208 | 3:6cde88f8c50f | 4 | |
cholletisaik777 | 6:31a33cbe6cdb | 5 | SDFileSystem sd(PTD6, PTD7, PTD5, PTD2,"sd"); |
pradeepvk2208 | 4:374c51671a69 | 6 | |
cholletisaik777 | 6:31a33cbe6cdb | 7 | /*void spiwrite(int a) |
pradeepvk2208 | 3:6cde88f8c50f | 8 | { |
pradeepvk2208 | 3:6cde88f8c50f | 9 | cs=1; |
pradeepvk2208 | 3:6cde88f8c50f | 10 | cs=0; |
pradeepvk2208 | 3:6cde88f8c50f | 11 | spi.write(a); |
pradeepvk2208 | 3:6cde88f8c50f | 12 | spi.write(0x01); |
pradeepvk2208 | 3:6cde88f8c50f | 13 | } |
pradeepvk2208 | 3:6cde88f8c50f | 14 | |
pradeepvk2208 | 3:6cde88f8c50f | 15 | int spiread(int a) |
pradeepvk2208 | 3:6cde88f8c50f | 16 | { |
pradeepvk2208 | 3:6cde88f8c50f | 17 | cs=1; |
pradeepvk2208 | 3:6cde88f8c50f | 18 | cs=0; |
pradeepvk2208 | 3:6cde88f8c50f | 19 | spi.write(a); |
pradeepvk2208 | 3:6cde88f8c50f | 20 | return(spi.write(0x00)); |
pradeepvk2208 | 3:6cde88f8c50f | 21 | } |
pradeepvk2208 | 3:6cde88f8c50f | 22 | char* getname(int year1,int month1,int date1,int day1,int hours1,int minutes1,int seconds1) |
pradeepvk2208 | 3:6cde88f8c50f | 23 | { |
pradeepvk2208 | 3:6cde88f8c50f | 24 | year1= hexint(year1); |
pradeepvk2208 | 3:6cde88f8c50f | 25 | month1=hexint(month1); |
pradeepvk2208 | 3:6cde88f8c50f | 26 | date1=hexint(date1); |
pradeepvk2208 | 3:6cde88f8c50f | 27 | day1=hexint(day1); |
pradeepvk2208 | 3:6cde88f8c50f | 28 | hours1=hexint(hours1); |
pradeepvk2208 | 3:6cde88f8c50f | 29 | minutes1=hexint(minutes1); |
pradeepvk2208 | 3:6cde88f8c50f | 30 | seconds1=hexint(seconds1); |
pradeepvk2208 | 3:6cde88f8c50f | 31 | char time[15]; |
pradeepvk2208 | 4:374c51671a69 | 32 | sprintf(time,"%02d%02d%02d%02d%02d%02d%02d",year1,month1,date1,day1,hours1,minutes1,seconds1); |
pradeepvk2208 | 5:3979ca24777a | 33 | |
pradeepvk2208 | 3:6cde88f8c50f | 34 | return(time); |
pradeepvk2208 | 3:6cde88f8c50f | 35 | |
cholletisaik777 | 6:31a33cbe6cdb | 36 | }*/ |
pradeepvk2208 | 3:6cde88f8c50f | 37 | |
pradeepvk2208 | 3:6cde88f8c50f | 38 | int hexint(int a) |
pradeepvk2208 | 3:6cde88f8c50f | 39 | { |
pradeepvk2208 | 3:6cde88f8c50f | 40 | a=(a/16)*10+(a%16); |
pradeepvk2208 | 3:6cde88f8c50f | 41 | return a; |
pradeepvk2208 | 3:6cde88f8c50f | 42 | } |
pradeepvk2208 | 5:3979ca24777a | 43 | //storedata stores the dummy structure in the file with timestamp as the filename in HK directory |
pradeepvk2208 | 5:3979ca24777a | 44 | void storedata(void) |
pradeepvk2208 | 3:6cde88f8c50f | 45 | { |
cholletisaik777 | 6:31a33cbe6cdb | 46 | /*spi.format(8,3); |
pradeepvk2208 | 3:6cde88f8c50f | 47 | spi.frequency(1000000); |
pradeepvk2208 | 5:3979ca24777a | 48 | spiwrite(0x80); //write seconds to 01 |
pradeepvk2208 | 5:3979ca24777a | 49 | spiwrite(0x81); //write minutes t0 01 |
pradeepvk2208 | 5:3979ca24777a | 50 | spiwrite(0x82); //write hours to 01 |
pradeepvk2208 | 5:3979ca24777a | 51 | spiwrite(0x83); //write day of week to 01 |
pradeepvk2208 | 5:3979ca24777a | 52 | spiwrite(0x84); //write day of month to 01 |
pradeepvk2208 | 5:3979ca24777a | 53 | spiwrite(0x85); //write month to 01 |
pradeepvk2208 | 5:3979ca24777a | 54 | spiwrite(0x86); //write year to 01 |
pradeepvk2208 | 3:6cde88f8c50f | 55 | for(int i=0;i<1000000;i++){ |
pradeepvk2208 | 5:3979ca24777a | 56 | int seconds=spiread(0x00); //read seconds |
pradeepvk2208 | 5:3979ca24777a | 57 | int minutes =spiread(0x01); //read minutes |
pradeepvk2208 | 5:3979ca24777a | 58 | int hours =spiread(0x02); //read hours |
pradeepvk2208 | 5:3979ca24777a | 59 | int day =spi.write(0x03); //read day of the week |
pradeepvk2208 | 5:3979ca24777a | 60 | int date =spiread(0x04); //read day of the month |
pradeepvk2208 | 5:3979ca24777a | 61 | int month =spiread(0x05); //read month |
pradeepvk2208 | 5:3979ca24777a | 62 | int year =spiread(0x06); //read year |
cholletisaik777 | 6:31a33cbe6cdb | 63 | cs = 1; */ |
cholletisaik777 | 6:31a33cbe6cdb | 64 | |
cholletisaik777 | 6:31a33cbe6cdb | 65 | |
cholletisaik777 | 6:31a33cbe6cdb | 66 | mkdir("/sd/TIME", 0777); |
cholletisaik777 | 6:31a33cbe6cdb | 67 | FILE*fp1= fopen("/sd/TIME/timer.txt", "w"); |
cholletisaik777 | 6:31a33cbe6cdb | 68 | if(fp1 == NULL) { |
cholletisaik777 | 6:31a33cbe6cdb | 69 | error("Could not open file for write\n"); |
cholletisaik777 | 6:31a33cbe6cdb | 70 | } |
cholletisaik777 | 6:31a33cbe6cdb | 71 | fclose(fp1); |
pradeepvk2208 | 3:6cde88f8c50f | 72 | |
pradeepvk2208 | 5:3979ca24777a | 73 | //Assigning dummy values to the structure |
cholletisaik777 | 6:31a33cbe6cdb | 74 | for(int i=0;i<1000000;i++){ |
pradeepvk2208 | 4:374c51671a69 | 75 | SensorData Sensor; |
pradeepvk2208 | 4:374c51671a69 | 76 | |
pradeepvk2208 | 4:374c51671a69 | 77 | printf("Writing dummy values\n"); |
pradeepvk2208 | 4:374c51671a69 | 78 | strcpy( Sensor.Voltage, "49"); |
pradeepvk2208 | 4:374c51671a69 | 79 | strcpy( Sensor.Current, "83"); |
pradeepvk2208 | 5:3979ca24777a | 80 | Sensor.Temperature ='5'; |
pradeepvk2208 | 5:3979ca24777a | 81 | strcpy( Sensor.PanelTemperature, "4"); |
pradeepvk2208 | 4:374c51671a69 | 82 | Sensor.Vcell_soc='9'; |
pradeepvk2208 | 4:374c51671a69 | 83 | Sensor.alerts= '4'; |
pradeepvk2208 | 4:374c51671a69 | 84 | Sensor.crate='7'; |
pradeepvk2208 | 4:374c51671a69 | 85 | Sensor.BatteryTemperature='6'; |
pradeepvk2208 | 4:374c51671a69 | 86 | Sensor.faultpoll='4'; |
pradeepvk2208 | 4:374c51671a69 | 87 | Sensor.faultir='g'; |
pradeepvk2208 | 4:374c51671a69 | 88 | Sensor.power_mode='k'; |
pradeepvk2208 | 5:3979ca24777a | 89 | strcpy( Sensor.AngularSpeed, "9"); |
pradeepvk2208 | 5:3979ca24777a | 90 | strcpy(Sensor.Bnewvalue,"6"); |
pradeepvk2208 | 4:374c51671a69 | 91 | printf("Done writing dummy values\n"); |
pradeepvk2208 | 4:374c51671a69 | 92 | mkdir("/sd/hk", 0777); |
pradeepvk2208 | 4:374c51671a69 | 93 | char date2[100]="/sd/hk/"; |
cholletisaik777 | 6:31a33cbe6cdb | 94 | char str[15]; |
cholletisaik777 | 6:31a33cbe6cdb | 95 | sprintf(str, "%d", i); |
cholletisaik777 | 6:31a33cbe6cdb | 96 | strcat(date2,str); |
pradeepvk2208 | 4:374c51671a69 | 97 | strcat(date2,".txt"); |
cholletisaik777 | 6:31a33cbe6cdb | 98 | |
cholletisaik777 | 6:31a33cbe6cdb | 99 | if(i%20==0) |
cholletisaik777 | 6:31a33cbe6cdb | 100 | {FILE *fp ; |
cholletisaik777 | 6:31a33cbe6cdb | 101 | Timer t1; |
cholletisaik777 | 6:31a33cbe6cdb | 102 | t1.start(); |
pradeepvk2208 | 4:374c51671a69 | 103 | fp= fopen(date2, "w"); |
pradeepvk2208 | 4:374c51671a69 | 104 | if(fp == NULL) { |
pradeepvk2208 | 4:374c51671a69 | 105 | error("Could not open file for write\n"); |
pradeepvk2208 | 3:6cde88f8c50f | 106 | } |
pradeepvk2208 | 4:374c51671a69 | 107 | else |
pradeepvk2208 | 4:374c51671a69 | 108 | { |
cholletisaik777 | 6:31a33cbe6cdb | 109 | int p; |
cholletisaik777 | 6:31a33cbe6cdb | 110 | for(p=0;p<20;p++) |
cholletisaik777 | 6:31a33cbe6cdb | 111 | {fprintf(fp, "%s -", Sensor.Voltage); |
pradeepvk2208 | 5:3979ca24777a | 112 | fprintf(fp,"%s -",Sensor.Current); |
pradeepvk2208 | 5:3979ca24777a | 113 | fprintf(fp,"%c -",Sensor.Temperature); |
pradeepvk2208 | 5:3979ca24777a | 114 | fprintf(fp,"%s -",Sensor.PanelTemperature); |
pradeepvk2208 | 5:3979ca24777a | 115 | fprintf(fp,"%c -",Sensor.Vcell_soc); //printing the contents of the strucure in a single line in the file |
pradeepvk2208 | 5:3979ca24777a | 116 | fprintf(fp,"%c -",Sensor.alerts); |
pradeepvk2208 | 5:3979ca24777a | 117 | fprintf(fp,"%c -",Sensor.crate); |
pradeepvk2208 | 5:3979ca24777a | 118 | fprintf(fp,"%c -",Sensor.BatteryTemperature); |
pradeepvk2208 | 5:3979ca24777a | 119 | fprintf(fp,"%c -",Sensor.faultpoll); |
pradeepvk2208 | 5:3979ca24777a | 120 | fprintf(fp,"%c -",Sensor.faultir); |
pradeepvk2208 | 5:3979ca24777a | 121 | fprintf(fp,"%c -",Sensor.power_mode); |
pradeepvk2208 | 5:3979ca24777a | 122 | fprintf(fp,"%s -",Sensor.AngularSpeed); |
cholletisaik777 | 6:31a33cbe6cdb | 123 | fprintf(fp,"%s\n",Sensor.Bnewvalue);} |
pradeepvk2208 | 4:374c51671a69 | 124 | fclose(fp); |
cholletisaik777 | 6:31a33cbe6cdb | 125 | t1.stop(); |
cholletisaik777 | 6:31a33cbe6cdb | 126 | float timesd=t1.read(); |
cholletisaik777 | 6:31a33cbe6cdb | 127 | printf("The time taken for writing 5 hk data was %f seconds\n", timesd); |
cholletisaik777 | 6:31a33cbe6cdb | 128 | //printf("%s",getname(year,month,date,day,hours,minutes,seconds)); |
cholletisaik777 | 6:31a33cbe6cdb | 129 | FILE *fp2=fopen("/sd/TIME/timer.txt", "a"); |
cholletisaik777 | 6:31a33cbe6cdb | 130 | if(fp2 == NULL) { |
cholletisaik777 | 6:31a33cbe6cdb | 131 | error("Could not open file for write\n"); |
cholletisaik777 | 6:31a33cbe6cdb | 132 | } |
cholletisaik777 | 6:31a33cbe6cdb | 133 | else |
cholletisaik777 | 6:31a33cbe6cdb | 134 | { |
cholletisaik777 | 6:31a33cbe6cdb | 135 | fprintf(fp2,"%f \n",timesd); |
cholletisaik777 | 6:31a33cbe6cdb | 136 | |
cholletisaik777 | 6:31a33cbe6cdb | 137 | } |
cholletisaik777 | 6:31a33cbe6cdb | 138 | fclose(fp2); |
cholletisaik777 | 6:31a33cbe6cdb | 139 | wait(3); |
pradeepvk2208 | 5:3979ca24777a | 140 | |
pradeepvk2208 | 5:3979ca24777a | 141 | |
cholletisaik777 | 6:31a33cbe6cdb | 142 | }} |
pradeepvk2208 | 4:374c51671a69 | 143 | }} |