![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
yuppie2
Dependencies: SDFileSystem mbed
Fork of rtcfinalcodehet by
Revision 5:3979ca24777a, committed 2015-02-03
- Comitter:
- pradeepvk2208
- Date:
- Tue Feb 03 17:10:21 2015 +0000
- Parent:
- 4:374c51671a69
- Commit message:
- hi
Changed in this revision
--- a/main.cpp Mon Dec 22 14:33:30 2014 +0000 +++ b/main.cpp Tue Feb 03 17:10:21 2015 +0000 @@ -6,160 +6,7 @@ int main() { - - - /*// Setup the spi for 8 bit data, high steady state clock, - // second edge capture, with a 1MHz clock rate - spi.format(8,3); - spi.frequency(1000000); - - // Send the commands to write to test the seconds register - cs = 0; - spi.write(0x80); // set write register to seconds - spi.write(0x00); // send value of one*//*spiwrite(0x80); - spiwrite(0x81); - spiwrite(0x82); - spiwrite(0x83); - spiwrite(0x84); - spiwrite(0x85); - spiwrite(0x86);*/ - - - /* cs=1; - cs=0; - spi.write(0x81); //write reg to minutes - spi.write(0x00); - spiwrite(0x81); - - cs=1; - cs=0; - - spi.write(0x82); //write reg to minutes - spi.write(0x01); - - cs=1; - - cs = 0; - spi.write(0x83); // set write register to seconds - spi.write(0x01); // send value of one - - cs=1; - - cs = 0; - spi.write(0x84); // set write register to seconds - spi.write(0x01); // send value of one - - cs=1; - - cs = 0; - spi.write(0x85); // set write register to seconds - spi.write(0x01); // send value of one - - cs=1; - - cs = 0; - spi.write(0x86); // set write register to seconds - spi.write(0x01); // send value of one - - cs=1;*/ - // Receive the contents of the seconds register - - /* for(int i=0;i<1000000;i++){ - - - cs=0; - spi.write(0x00); // set read register to seconds - int seconds = spi.write(0x00); // read the value*/ - //int seconds=spiread(0x00); - - /*cs=1; - cs=0; - - spi.write(0x01);*/ - //int minutes =spiread(0x01); - - - /*cs=1; - cs=0; + storedata(); +} - spi.write(0x02);*/ - //int hours =spiread(0x02); - /* cs = 1; //This cs=1 is to make the chipselect line high to "deselect" the slave in our case RTC - - cs=0; - - spi.write(0x03);*/ - //int day =spi.write(0x03); - /*cs = 1; - - cs=0; - - spi.write(0x04);*/ - // int date =spiread(0x04); - /*cs = 1; - - cs=0; - - spi.write(0x05);*/ - //int month =spiread(0x05); - /*cs = 1; - - cs=0; - - spi.write(0x06);*/ - // int year =spiread(0x06); - //cs = 1; - - //wait(1); - //This printf function is to check the timestamp function in the terminal output - // 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)); - //}*/ - - getts(); - - - - } - - /* void spiwrite(int a) - { - cs=1; - cs=0; - spi.write(a); - spi.write(0x01); - } - int spiread(int a) - { - cs=1; - cs=0; - spi.write(a); - return(spi.write(0x00)); - } - char* getname(int year1,int month1,int date1,int day1,int hours1,int minutes1,int seconds1) -{ - year1= hexint(year1); - month1=hexint(month1); - date1=hexint(date1); - day1=hexint(day1); - 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,"%2d%2d%2d%2d%2d%2d%2d",year1,month1,date1,day1,hours1,minutes1,seconds1); - return(time); - -} - -int hexint(int a) -{ - a=(a/16)*10+(a%16); - return a; -}*/ \ No newline at end of file + \ No newline at end of file
--- 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
--- a/rtsc.h Mon Dec 22 14:33:30 2014 +0000 +++ b/rtsc.h Tue Feb 03 17:10:21 2015 +0000 @@ -4,30 +4,21 @@ typedef struct SensorData { char Voltage[8]; char Current[4]; - char Temperature[1]; - char PanelTemperature[2];//read by the 4 thermistors on solar panels - char Vcell_soc;//MSBs correspond to Vcell, LSBs to Soc - char alerts;//UNQUANTISED - //(alerts[0]=1)-> reset indicator=>dont care - //(alerts[1]=1)-> Vcell>ValrtMax(5.1V)->will always be high->dont care - //(alerts[2]=1)-> Vcell<ValrtMin(5.1V)->indicates deep discharge - //(alerts[3]=1)-> Vcell<Vreset(2.5V) - //(alerts[5]=1)-> Soc CROSSES the threshold value - //(alerts[6]=1)-> alert on (alerts[3]) enabled when Vcell<Vreset(here we set it to be 2.5V) + char Temperature; + char PanelTemperature[2]; //HK Data Structure + char Vcell_soc; + char alerts; char crate; - char BatteryTemperature; //to be populated - char faultpoll; //polled faults - char faultir; //interrupted faults - char power_mode; //power modes + char BatteryTemperature; + char faultpoll; + char faultir; + char power_mode; char AngularSpeed[2]; char Bnewvalue[2]; - - //float magnetometer,gyro=>to be addes } SensorData; void spiwrite(int); int spiread(int); int hexint(int); char* getname(int,int,int,int,int,int,int); -char* getts(void); -void storedata(char*,SensorData*); \ No newline at end of file +void storedata(void); \ No newline at end of file