
Repository for CDMS code
Dependencies: SimpleDMA mbed-rtos mbed eeprom
Fork of COM_MNG_TMTC_SIMPLE by
Revision 103:b55559925dc1, committed 2016-01-29
- Comitter:
- shreeshas95
- Date:
- Fri Jan 29 17:36:10 2016 +0000
- Parent:
- 102:80c911a6e736
- Child:
- 104:a50ae79ca36e
- Commit message:
- Integrated HK : YET TO BE TESTED
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CDMS_HK.h Fri Jan 29 17:36:10 2016 +0000 @@ -0,0 +1,203 @@ +//#include "cdms_rtc.h" +#include "pinconfig.h" + +void FCTN_CDMS_HK_MAIN(); +void FCTN_CDMS_HK(); +//extern uint8_t CDMS_HK_STATUS; +//extern uint8_t Power_level; +//extern uint8_t Att_level; +//extern char CDMS_HK[8]; + +Serial hk_cdms(USBTX, USBRX); + +AnalogIn TempInput(PIN27); // Input from Current Multiplexer +AnalogIn CDMS_temp_sensor(PIN53); + +DigitalOut SelectLinec3 (PIN79); // MSB of Select Lines +DigitalOut SelectLinec2 (PIN78); +DigitalOut SelectLinec1 (PIN77); +DigitalOut SelectLinec0 (PIN76); // LSB of Select Lines + +void FCTN_CDMS_HK_MAIN() +{ +// CDMS_HK_STATUS=(CDMS_HK_STATUS)|(HK_MAIN_STATUS); + FCTN_CDMS_HK; + hk_cdms.printf(" \r\nCDMS HK entered Verify COM RX RSSI >0.4 \r\n"); + + int HK_I2C; + char BAE_HK[73]; + FCTN_I2C_READ(BAE_HK,73); + printf("BAE_HK=%s",BAE_HK); + /*if(HK_I2C==0) + { + if(Power_level!=0) + { + printf("Update Power_level to 0 in Flash"); + } + Att_level=0; + CDMS_HK_STATUS=(CDMS_HK_STATUS)|(HK_BAE_ERR_I2C); + CDMS_HK_STATUS=(CDMS_HK_STATUS)&(~(HK_MAIN_STATUS)); + }**/ + uint8_t CDMS_quant[17]; + // printf("BAE HK is %s",BAE_HK); + for(int i=0;i<16;i++) + { + CDMS_quant[i]= (uint8_t)quant_data.temp_quant[i]; + } + CDMS_quant[16]= (uint8_t)quant_data.CDMS_temp_quant; + uint64_t time=0x00;//replace with rtc function + char tree[61]; + hk_cdms.printf("i am done\r\n"); + uint8_t data[512]; + for(int i=0;i<512;i++) + { + data[i]=0x00; + } + tree[0]=(char)(time>>(56))&(0xFF); + tree[1]=(char)(time>>(48))&(0xFF); + tree[2]=(char)(time>>(40))&(0xFF); + tree[3]=(char)(time>>(32))&(0xFF); + tree[4]=(char)(time>>(24))&(0xFF); + tree[5]=(char)(time>>(16))&(0xFF); + tree[6]=(char)(time>>(8))&(0xFF); + tree[7]=(char)(time)&(0xFF); + for(int i=0;i<73;i++) + { + tree[i+8]=BAE_HK[i]; + } + printf("Hope u r alive \r\n"); + for(int i=0;i<81;i++) + { + data[i]=(uint8_t)tree[i]; + } + for(int i=81;i<98;i++) + { + data[i]=CDMS_quant[i]; + } + for(int i=0;i<512;i++) + { + printf("%d",data[i]); + } + uint8_t fsc=FCTN_SD_MNGR(0x3); + printf("FSC where SD is written is %d\r\n",fsc); + int a=SD_WRITE(data,0x00000012,0x3); + printf("Result of writing is %d \r\n",a); + //BCN long frame ??? + //CDMS_HK_STATUS=(CDMS_HK_STATUS)&(~(HK_MAIN_STATUS)); + hk_cdms.printf("CDMS executed succesfully\r\n"); +} + + + +int quantiz(float start,float step,float x) +{ + int y=(x-start)/step; + if(y<=0)y=0; + if(y>=255)y=255; + return y; +} + + + +void saveMin(char x,char y){ + if(y<x){ + x=y; + } + +} +void saveMax(char x,char y){ + if (y>x) + { + x=y; + } +} +void minMaxHkData(){ + + + + if(firstCount==true){ + for (int i = 0; i < 16; ++i){ + min_max_data.temp_min[i] = quant_data.temp_quant[i]; + min_max_data.temp_max[i] = quant_data.temp_quant[i]; + } + + min_max_data.CDMS_temp_min=quant_data.CDMS_temp_quant; + min_max_data.CDMS_temp_max=quant_data.CDMS_temp_quant; + + + } + else { + for (int i = 0; i < 16; ++i) + { + saveMin(min_max_data.temp_min[i],quant_data.temp_quant[i]); + saveMax(min_max_data.temp_max[i],quant_data.temp_quant[i]); + } + + saveMin(min_max_data.CDMS_temp_min,quant_data.CDMS_temp_quant); + saveMax(min_max_data.CDMS_temp_max,quant_data.CDMS_temp_quant); + + + } + firstCount=false; +} + +void FCTN_CDMS_HK() +{ + + int Iteration=0; + + SelectLinec0=0; + SelectLinec1=0; + SelectLinec2=0; + SelectLinec3=0; + + for(Iteration=0; Iteration<16; Iteration++){ + + actual_data.temp_actual[Iteration]=TempInput.read(); + + SelectLinec0=!(SelectLinec0); + if(Iteration%2==1) + SelectLinec1=!(SelectLinec1); + if(Iteration%4==3) + SelectLinec2=!(SelectLinec2); + if(Iteration%8==7) + SelectLinec3=!(SelectLinec3); + } + +actual_data.CDMS_temp_actual=(-90.7*3.3*CDMS_temp_sensor.read())+190.1543; + + for(Iteration=0;Iteration<16;Iteration++){ + + if(Iteration<14){ + + actual_data.temp_actual[Iteration]=actual_data.temp_actual[Iteration]*3.3; + int resistance; + + resistance=24000*actual_data.temp_actual[Iteration]/(3.3-actual_data.temp_actual[Iteration]); + if(actual_data.temp_actual[Iteration]>1.47) + { + actual_data.temp_actual[Iteration]=3694/log(24.032242*resistance); + } + else{ + + actual_data.temp_actual[Iteration]=3365.4/log(7.60573*resistance); + } + } + else + actual_data.temp_actual[Iteration]=(-90.7*3.3*actual_data.temp_actual[Iteration])+190.1543; + } + + for(Iteration=0;Iteration<16;Iteration++){ + + if(Iteration<14){ + + quant_data.temp_quant[Iteration]=quantiz(tstart_thermistor,tstep_thermistor,actual_data.temp_actual[Iteration]); + } + else + quant_data.temp_quant[Iteration]=quantiz(tstart,tstep,actual_data.temp_actual[Iteration]); + } + + quant_data.CDMS_temp_quant=quantiz(tstart,tstep,actual_data.CDMS_temp_actual); + + minMaxHkData(); +} \ No newline at end of file
--- a/COM_MNG_TMTC.h Fri Jan 29 17:09:41 2016 +0000 +++ b/COM_MNG_TMTC.h Fri Jan 29 17:36:10 2016 +0000 @@ -10,8 +10,6 @@ //added RLY_TMTC function //added included related files -#include "pinconfig.h" -#include "i2c.h" //#include "Flash.h" #include "cdms_rtc.h" @@ -417,7 +415,7 @@ if(tm_status_4m_slv == 1) { //printf("receiving...\r\n"); - FCTN_I2C_READ((char*)tm_pointer->TM_string); + FCTN_I2C_READ((char*)tm_pointer->TM_string,134); //printf("%s", tm_pointer->TM_string); received+=1; tm_pointer = tm_pointer->next_TM;
--- a/DefinitionsAndGlobals.h Fri Jan 29 17:09:41 2016 +0000 +++ b/DefinitionsAndGlobals.h Fri Jan 29 17:36:10 2016 +0000 @@ -167,4 +167,10 @@ uint8_t gPAYLOAD_BUFFER[PAYLOAD_BUFFER_LENGTH]; // CALL SIGN TM -const uint8_t gCALL_SIGN_STRING[TM_SHORT_SIZE] = {0xE0, 0x00, 0x00, 0x00, 0x56, 0x55, 0x32, 0x4E, 0x43, 0x46, 0x00, 0xAC, 0x11}; \ No newline at end of file +const uint8_t gCALL_SIGN_STRING[TM_SHORT_SIZE] = {0xE0, 0x00, 0x00, 0x00, 0x56, 0x55, 0x32, 0x4E, 0x43, 0x46, 0x00, 0xAC, 0x11}; + +// CDMS HK +CDMS_HK_actual actual_data; +CDMS_HK_quant quant_data; +CDMS_HK_min_max min_max_data; +bool firstCount=true; \ No newline at end of file
--- a/Structures.h Fri Jan 29 17:09:41 2016 +0000 +++ b/Structures.h Fri Jan 29 17:36:10 2016 +0000 @@ -138,4 +138,34 @@ } ~Short_tm(){} -}; \ No newline at end of file +}; + + +// CDMS HK + +#define tstart -40 +#define tstep 8 //to be finalized by thermal team +#define tstart_thermistor -40 +#define tstep_thermistor 8 + +typedef struct CDMS_HK_actual +{ + float temp_actual[16]; + float CDMS_temp_actual; + +}CDMS_HK_actual; + +typedef struct CDMS_HK_quant +{ + char temp_quant[16]; + char CDMS_temp_quant; + +}CDMS_HK_quant; + +typedef struct CDMS_HK_min_max +{ + char temp_max[16]; + char temp_min[16]; + char CDMS_temp_min; + char CDMS_temp_max; +}CDMS_HK_min_max; \ No newline at end of file
--- a/i2c.h Fri Jan 29 17:09:41 2016 +0000 +++ b/i2c.h Fri Jan 29 17:36:10 2016 +0000 @@ -37,25 +37,25 @@ } -void FCTN_I2C_READ(char *data) +void FCTN_I2C_READ(char *data,int length) { - irpt_2_slv = 1; -// t_read.start(); - read_ack = master.read(addr|1,data,tm_len); - // t_read.stop(); - + irpt_2_slv = 1; + //t_read.start(); + read_ack = master.read(addr|1,data,length); + //t_read.stop(); + //if(read_ack == 0) - // gPC.printf("\n\rData received from BAE %s \n",data); + // printf("\n\rData received from BAE %s \n",data); if (read_ack == 1) { -// led2 = 1; - //gPC.printf("\n \r data not received \n"); -// led2 = 0; + gLEDR = 1; + printf("\n \r data not received \n"); + gLEDR = 0; } //if(read_ack == 1) -//gPC.printf("\n \r data not received \n"); +//pc.printf("\n \r data not received \n"); irpt_2_slv = 0; - //gPC.printf("\n\r %d \n",t.read_us()); + //printf("\n\r %d \n",t.read_us()); //t.reset(); } \ No newline at end of file
--- a/main.cpp Fri Jan 29 17:09:41 2016 +0000 +++ b/main.cpp Fri Jan 29 17:36:10 2016 +0000 @@ -10,11 +10,14 @@ #include "mbed_debug.h" #include "Structures.h" +#include "pinconfig.h" #include "DefinitionsAndGlobals.h" #include "crc.h" +#include "i2c.h" #include "COM_SND_TM_functions.h" #include "COM_SND_TM.h" #include "cdms_sd.h" +#include "CDMS_HK.h" #include "OBSRS.h" #include "adf.h" #include "COM_RCV_TC.h"