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: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of CDMS_CODE by
Diff: CDMS_HK.h
- Revision:
- 103:b55559925dc1
- Child:
- 104:a50ae79ca36e
diff -r 80c911a6e736 -r b55559925dc1 CDMS_HK.h
--- /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
