Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SDFileSystem mbed-rtos mbed
Fork of CDMS_BAE by
Revision 6:ee97f01e6b7d, committed 2015-02-05
- Comitter:
- pradeepvk2208
- Date:
- Thu Feb 05 22:32:29 2015 +0000
- Parent:
- 5:3979ca24777a
- Child:
- 7:60e940b7a36b
- Commit message:
- CDMS with hk
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hk.cpp Thu Feb 05 22:32:29 2015 +0000
@@ -0,0 +1,131 @@
+#include "hk.h"
+SPI spi(PTD6, PTD7, PTD5);
+DigitalOut cs(D6);
+
+SDFileSystem sd(PTD6, PTD7, PTD5, D7,"sd");
+
+Timer t1;
+DigitalOut interrupt(D9);
+const int addr = 0x20;
+bool ack0;
+I2C master (D14,D15);
+
+ 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 time[15];
+ sprintf(time,"%02d%02d%02d%02d%02d%02d%02d",year1,month1,date1,day1,hours1,minutes1,seconds1);
+
+ return(time);
+
+}
+
+int hexint(int a)
+{
+ a=(a/16)*10+(a%16);
+ return a;
+}
+//storedata stores the dummy structure in the file with timestamp as the filename in HK directory
+void init_rtc(void)
+{
+ spi.format(8,3);
+ spi.frequency(1000000);
+ 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
+}
+void storedata(char * data,int length)
+{
+
+ ack0 =true;
+
+ interrupt = 1;
+ t1.start();
+ //wait_ms(20);
+ ack0 = master.read(addr|1,data,length);
+ t1.stop();
+
+
+ if(!ack0)
+ {
+ printf("\n master has read %s from slave\n\r",data);
+
+ }
+ //master.stop();
+ printf("\n%d\n\r",t1.read_us());
+ t1.reset();
+
+ interrupt=0;
+ spi.format(8,3);
+ spi.frequency(1000000);
+
+ 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;
+
+ //Assigning dummy values to the structure
+
+ /* SensorData Sensor;
+
+ printf("Writing dummy values\n");
+ strcpy( Sensor.Voltage, "49");
+ strcpy( Sensor.Current, "83");
+ Sensor.Temperature ='5';
+ strcpy( Sensor.PanelTemperature, "4");
+ Sensor.Vcell_soc='9';
+ Sensor.alerts= '4';
+ Sensor.crate='7';
+ Sensor.BatteryTemperature='6';
+ Sensor.faultpoll='4';
+ Sensor.faultir='g';
+ Sensor.power_mode='k';
+ strcpy( Sensor.AngularSpeed, "9");
+ strcpy(Sensor.Bnewvalue,"6");
+ printf("Done writing dummy values\n"); */
+ mkdir("/sd/hk", 0777);
+ char date2[100]="/sd/hk/";
+ strcat(date2,getname(year,month,date,day,hours,minutes,seconds));
+ strcat(date2,".txt");
+ FILE *fp ;
+ fp= fopen(date2, "w");
+ if(fp == NULL)
+ {
+ error("Could not open file for write\n");
+ }
+ else
+ {
+ fprintf(fp, "%s ", data);
+ fclose(fp);
+ printf("%s",getname(year,month,date,day,hours,minutes,seconds));
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hk.h Thu Feb 05 22:32:29 2015 +0000
@@ -0,0 +1,25 @@
+#include "mbed.h"
+#include "SDFileSystem.h"
+#include "string.h"
+typedef struct SensorData {
+ char Voltage[8];
+ char Current[4];
+ char Temperature;
+ char PanelTemperature[2]; //HK Data Structure
+ char Vcell_soc;
+ char alerts;
+ char crate;
+ char BatteryTemperature;
+ char faultpoll;
+ char faultir;
+ char power_mode;
+ char AngularSpeed[2];
+ char Bnewvalue[2];
+} SensorData;
+
+void spiwrite(int);
+int spiread(int);
+int hexint(int);
+char* getname(int,int,int,int,int,int,int);
+void storedata(char*,int);
+void init_rtc(void);
--- a/main.cpp Tue Feb 03 17:10:21 2015 +0000
+++ b/main.cpp Thu Feb 05 22:32:29 2015 +0000
@@ -1,12 +1,73 @@
-#include "rtsc.h"
+#include "mbed.h"
+#include "rtos.h"
+#include "hk.h"
+
+InterruptIn data_ready(D10);
+InterruptIn data_ready1(D6);
+int init=0;
+char data_receive[25];
+
+
+
+Thread * ptr_t_hk;
+Thread * ptr_t_i2c1;
+
+
+void FUNC_HK_DATA()
+{
+ storedata(data_receive,25);
+}
+void FUNC_SCIENCE_DATA()
+{
+ printf("Saved Science in SD");
+}
+
+void T_I2C_HK(void const *args)
+{
+
+ while(1)
+ {
+ Thread::signal_wait(0x1);
+ FUNC_HK_DATA();
+ }
+}
+
+void T_I2C_MASTER_FSLAVE1(void const *args)
+{
+ while(1)
+ {
+ Thread::signal_wait(0x2);
+ FUNC_SCIENCE_DATA();
+ }
+}
+void FUNC_INT()
+{
+
+ ptr_t_hk->signal_set(0x1);
+
+}
+void FUNC_INT1()
+{
+
+ ptr_t_i2c1->signal_set(0x2);
+
+}
+
+
+int main()
+
+{
+ if(init==0)
+ {
+ init_rtc();
+ init++;
+ }
+ ptr_t_hk = new Thread (T_I2C_HK);
+ data_ready.rise(&FUNC_INT);
+ ptr_t_i2c1= new Thread (T_I2C_MASTER_FSLAVE1);
+ data_ready1.rise(&FUNC_INT1);
+}
-int main()
-{
-
- storedata();
-}
-
-
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Thu Feb 05 22:32:29 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#5448826aa700
--- a/rtsc.cpp Tue Feb 03 17:10:21 2015 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,114 +0,0 @@
-#include "rtsc.h"
-SPI spi(PTD6, PTD7, PTD5);
-DigitalOut cs(PTD2);
-
-SDFileSystem sd(PTD6, PTD7, PTD5, D10,"sd");
-
- 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 time[15];
- sprintf(time,"%02d%02d%02d%02d%02d%02d%02d",year1,month1,date1,day1,hours1,minutes1,seconds1);
-
- return(time);
-
-}
-
-int hexint(int a)
-{
- a=(a/16)*10+(a%16);
- return a;
-}
-//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); //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); //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;
-
- //Assigning dummy values to the structure
-
- SensorData Sensor;
-
- printf("Writing dummy values\n");
- strcpy( Sensor.Voltage, "49");
- strcpy( Sensor.Current, "83");
- Sensor.Temperature ='5';
- strcpy( Sensor.PanelTemperature, "4");
- Sensor.Vcell_soc='9';
- Sensor.alerts= '4';
- Sensor.crate='7';
- Sensor.BatteryTemperature='6';
- Sensor.faultpoll='4';
- Sensor.faultir='g';
- Sensor.power_mode='k';
- strcpy( Sensor.AngularSpeed, "9");
- strcpy(Sensor.Bnewvalue,"6");
- printf("Done writing dummy values\n");
- mkdir("/sd/hk", 0777);
- char date2[100]="/sd/hk/";
- strcat(date2,getname(year,month,date,day,hours,minutes,seconds));
- strcat(date2,".txt");
- FILE *fp ;
- fp= fopen(date2, "w");
- if(fp == NULL) {
- error("Could not open file for write\n");
- }
- else
- {
- 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("%s",getname(year,month,date,day,hours,minutes,seconds));
- wait(10);
-
-
- }
- }}
\ No newline at end of file
--- a/rtsc.h Tue Feb 03 17:10:21 2015 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-#include "mbed.h"
-#include "SDFileSystem.h"
-#include "string.h"
-typedef struct SensorData {
- char Voltage[8];
- char Current[4];
- char Temperature;
- char PanelTemperature[2]; //HK Data Structure
- char Vcell_soc;
- char alerts;
- char crate;
- char BatteryTemperature;
- char faultpoll;
- char faultir;
- char power_mode;
- char AngularSpeed[2];
- char Bnewvalue[2];
-} SensorData;
-
-void spiwrite(int);
-int spiread(int);
-int hexint(int);
-char* getname(int,int,int,int,int,int,int);
-void storedata(void);
\ No newline at end of file
