cdms n bae

Dependencies:   SDFileSystem mbed-rtos mbed

Fork of CDMS_RTOS by Pradeep Kotipalli

Committer:
sakthipriya
Date:
Fri Feb 06 18:12:16 2015 +0000
Revision:
8:4acac3bf5e9b
Parent:
7:60e940b7a36b
Child:
9:d6623702495b
working cdms withut rtc

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pradeepvk2208 6:ee97f01e6b7d 1 #include "hk.h"
pradeepvk2208 6:ee97f01e6b7d 2 SPI spi(PTD6, PTD7, PTD5);
pradeepvk2208 6:ee97f01e6b7d 3 DigitalOut cs(D6);
pradeepvk2208 6:ee97f01e6b7d 4
pradeepvk2208 6:ee97f01e6b7d 5 SDFileSystem sd(PTD6, PTD7, PTD5, D7,"sd");
pradeepvk2208 6:ee97f01e6b7d 6
sakthipriya 7:60e940b7a36b 7 //Timer t1;
sakthipriya 7:60e940b7a36b 8 //DigitalOut interrupt(D9);
sakthipriya 7:60e940b7a36b 9 //const int addr = 0x20;
pradeepvk2208 6:ee97f01e6b7d 10 bool ack0;
sakthipriya 7:60e940b7a36b 11 //I2C master (D14,D15);
pradeepvk2208 6:ee97f01e6b7d 12
pradeepvk2208 6:ee97f01e6b7d 13 void spiwrite(int a)
pradeepvk2208 6:ee97f01e6b7d 14 {
pradeepvk2208 6:ee97f01e6b7d 15 cs=1;
pradeepvk2208 6:ee97f01e6b7d 16 cs=0;
pradeepvk2208 6:ee97f01e6b7d 17 spi.write(a);
pradeepvk2208 6:ee97f01e6b7d 18 spi.write(0x01);
pradeepvk2208 6:ee97f01e6b7d 19 }
pradeepvk2208 6:ee97f01e6b7d 20
pradeepvk2208 6:ee97f01e6b7d 21 int spiread(int a)
pradeepvk2208 6:ee97f01e6b7d 22 {
pradeepvk2208 6:ee97f01e6b7d 23 cs=1;
pradeepvk2208 6:ee97f01e6b7d 24 cs=0;
pradeepvk2208 6:ee97f01e6b7d 25 spi.write(a);
pradeepvk2208 6:ee97f01e6b7d 26 return(spi.write(0x00));
pradeepvk2208 6:ee97f01e6b7d 27 }
pradeepvk2208 6:ee97f01e6b7d 28 char* getname(int year1,int month1,int date1,int day1,int hours1,int minutes1,int seconds1)
pradeepvk2208 6:ee97f01e6b7d 29 {
pradeepvk2208 6:ee97f01e6b7d 30 year1= hexint(year1);
pradeepvk2208 6:ee97f01e6b7d 31 month1=hexint(month1);
pradeepvk2208 6:ee97f01e6b7d 32 date1=hexint(date1);
pradeepvk2208 6:ee97f01e6b7d 33 day1=hexint(day1);
pradeepvk2208 6:ee97f01e6b7d 34 hours1=hexint(hours1);
pradeepvk2208 6:ee97f01e6b7d 35 minutes1=hexint(minutes1);
pradeepvk2208 6:ee97f01e6b7d 36 seconds1=hexint(seconds1);
pradeepvk2208 6:ee97f01e6b7d 37 char time[15];
pradeepvk2208 6:ee97f01e6b7d 38 sprintf(time,"%02d%02d%02d%02d%02d%02d%02d",year1,month1,date1,day1,hours1,minutes1,seconds1);
pradeepvk2208 6:ee97f01e6b7d 39
pradeepvk2208 6:ee97f01e6b7d 40 return(time);
pradeepvk2208 6:ee97f01e6b7d 41
pradeepvk2208 6:ee97f01e6b7d 42 }
pradeepvk2208 6:ee97f01e6b7d 43
pradeepvk2208 6:ee97f01e6b7d 44 int hexint(int a)
pradeepvk2208 6:ee97f01e6b7d 45 {
pradeepvk2208 6:ee97f01e6b7d 46 a=(a/16)*10+(a%16);
pradeepvk2208 6:ee97f01e6b7d 47 return a;
pradeepvk2208 6:ee97f01e6b7d 48 }
pradeepvk2208 6:ee97f01e6b7d 49 //storedata stores the dummy structure in the file with timestamp as the filename in HK directory
pradeepvk2208 6:ee97f01e6b7d 50 void init_rtc(void)
pradeepvk2208 6:ee97f01e6b7d 51 {
pradeepvk2208 6:ee97f01e6b7d 52 spi.format(8,3);
pradeepvk2208 6:ee97f01e6b7d 53 spi.frequency(1000000);
pradeepvk2208 6:ee97f01e6b7d 54 spiwrite(0x80); //write seconds to 01
pradeepvk2208 6:ee97f01e6b7d 55 spiwrite(0x81); //write minutes t0 01
pradeepvk2208 6:ee97f01e6b7d 56 spiwrite(0x82); //write hours to 01
pradeepvk2208 6:ee97f01e6b7d 57 spiwrite(0x83); //write day of week to 01
pradeepvk2208 6:ee97f01e6b7d 58 spiwrite(0x84); //write day of month to 01
pradeepvk2208 6:ee97f01e6b7d 59 spiwrite(0x85); //write month to 01
pradeepvk2208 6:ee97f01e6b7d 60 spiwrite(0x86); //write year to 01
pradeepvk2208 6:ee97f01e6b7d 61 }
sakthipriya 7:60e940b7a36b 62 void storedata(char * data)
pradeepvk2208 6:ee97f01e6b7d 63 {
pradeepvk2208 6:ee97f01e6b7d 64
sakthipriya 8:4acac3bf5e9b 65 printf("ready to store");
pradeepvk2208 6:ee97f01e6b7d 66 spi.format(8,3);
pradeepvk2208 6:ee97f01e6b7d 67 spi.frequency(1000000);
pradeepvk2208 6:ee97f01e6b7d 68
pradeepvk2208 6:ee97f01e6b7d 69 int seconds=spiread(0x00); //read seconds
pradeepvk2208 6:ee97f01e6b7d 70 int minutes =spiread(0x01); //read minutes
pradeepvk2208 6:ee97f01e6b7d 71 int hours =spiread(0x02); //read hours
pradeepvk2208 6:ee97f01e6b7d 72 int day =spi.write(0x03); //read day of the week
pradeepvk2208 6:ee97f01e6b7d 73 int date =spiread(0x04); //read day of the month
pradeepvk2208 6:ee97f01e6b7d 74 int month =spiread(0x05); //read month
pradeepvk2208 6:ee97f01e6b7d 75 int year =spiread(0x06); //read year
pradeepvk2208 6:ee97f01e6b7d 76 cs = 1;
pradeepvk2208 6:ee97f01e6b7d 77
pradeepvk2208 6:ee97f01e6b7d 78 //Assigning dummy values to the structure
pradeepvk2208 6:ee97f01e6b7d 79
pradeepvk2208 6:ee97f01e6b7d 80 /* SensorData Sensor;
pradeepvk2208 6:ee97f01e6b7d 81
pradeepvk2208 6:ee97f01e6b7d 82 printf("Writing dummy values\n");
pradeepvk2208 6:ee97f01e6b7d 83 strcpy( Sensor.Voltage, "49");
pradeepvk2208 6:ee97f01e6b7d 84 strcpy( Sensor.Current, "83");
pradeepvk2208 6:ee97f01e6b7d 85 Sensor.Temperature ='5';
pradeepvk2208 6:ee97f01e6b7d 86 strcpy( Sensor.PanelTemperature, "4");
pradeepvk2208 6:ee97f01e6b7d 87 Sensor.Vcell_soc='9';
pradeepvk2208 6:ee97f01e6b7d 88 Sensor.alerts= '4';
pradeepvk2208 6:ee97f01e6b7d 89 Sensor.crate='7';
pradeepvk2208 6:ee97f01e6b7d 90 Sensor.BatteryTemperature='6';
pradeepvk2208 6:ee97f01e6b7d 91 Sensor.faultpoll='4';
pradeepvk2208 6:ee97f01e6b7d 92 Sensor.faultir='g';
pradeepvk2208 6:ee97f01e6b7d 93 Sensor.power_mode='k';
pradeepvk2208 6:ee97f01e6b7d 94 strcpy( Sensor.AngularSpeed, "9");
pradeepvk2208 6:ee97f01e6b7d 95 strcpy(Sensor.Bnewvalue,"6");
pradeepvk2208 6:ee97f01e6b7d 96 printf("Done writing dummy values\n"); */
pradeepvk2208 6:ee97f01e6b7d 97 mkdir("/sd/hk", 0777);
pradeepvk2208 6:ee97f01e6b7d 98 char date2[100]="/sd/hk/";
pradeepvk2208 6:ee97f01e6b7d 99 strcat(date2,getname(year,month,date,day,hours,minutes,seconds));
pradeepvk2208 6:ee97f01e6b7d 100 strcat(date2,".txt");
pradeepvk2208 6:ee97f01e6b7d 101 FILE *fp ;
pradeepvk2208 6:ee97f01e6b7d 102 fp= fopen(date2, "w");
pradeepvk2208 6:ee97f01e6b7d 103 if(fp == NULL)
pradeepvk2208 6:ee97f01e6b7d 104 {
pradeepvk2208 6:ee97f01e6b7d 105 error("Could not open file for write\n");
pradeepvk2208 6:ee97f01e6b7d 106 }
pradeepvk2208 6:ee97f01e6b7d 107 else
pradeepvk2208 6:ee97f01e6b7d 108 {
pradeepvk2208 6:ee97f01e6b7d 109 fprintf(fp, "%s ", data);
pradeepvk2208 6:ee97f01e6b7d 110 fclose(fp);
pradeepvk2208 6:ee97f01e6b7d 111 printf("%s",getname(year,month,date,day,hours,minutes,seconds));
pradeepvk2208 6:ee97f01e6b7d 112 }
pradeepvk2208 6:ee97f01e6b7d 113 }