hk tentative jul 9

Dependencies:   mbed

Fork of mbed_hkfinal by Bharath S

Files at this revision

API Documentation at this revision

Comitter:
pranoysvarma
Date:
Wed Jul 09 05:55:31 2014 +0000
Parent:
0:333cda053c40
Commit message:
hk tentative

Changed in this revision

hkfinal.c Show annotated file Show diff for this revision Revisions of this file
hkfinal.h Show annotated file Show diff for this revision Revisions of this file
diff -r 333cda053c40 -r 8b8bc4aef6f9 hkfinal.c
--- a/hkfinal.c	Tue Jul 08 16:03:07 2014 +0000
+++ b/hkfinal.c	Wed Jul 09 05:55:31 2014 +0000
@@ -1,20 +1,41 @@
-struct SensorData {
+#include "hkfinal.h"
+
+typedef struct SensorData {
     char Voltage[10];
     char Current[10];
     char Temperature[10];
     //float Battery[2];
-} SensorData;
+}SensorDaty;
+
+typedef struct ShortBeacon {
+    char Voltage[1];
+    char AngularSpeed[2];
+    char SubsystemStatus[1]; 
+    char Temp[3];  
+    char ErrorFlag[1];
+}ShortBeacy;
 
 int quantiz(float start,float step,float x)
 {
-    int y=((x*3.18/65536)-start)/step;
+    int y=(x-start)/step;
     if(y<=0)y=0;
     if(y>=15)y=15;
     return y;
 }
 
+void init_beacon(ShortBeacy x){
+    x.Voltage={1};
+    x.AngularSpeed={2,3}
+    x.SubsystemStatus={145};
+    x.Temp={1,2,3};
+    x.ErrorFlag={3};
+}
+
 void FUNC_HK_MAIN()
 {
+    SensorDaty SensorData;
+    ShortBeacy ShortBeacon;
+    init_beacon(ShortBeacon);
 
     int LoopIterator;
 
@@ -26,13 +47,13 @@
     for(LoopIterator=0; LoopIterator<16; LoopIterator++) {
 
         if(LoopIterator%2==0) {
-            SensorData.Current[LoopIterator]=quantiz(start,step,CurrentInput.read_u16());
-            SensorData.Voltage[LoopIterator]=quantiz(start,step,VoltageInput.read_u16());
-            SensorData.Temperature[LoopIterator]=quantiz(start,step,TemperatureInput.read_u16());
+            SensorData.Current[LoopIterator]=quantiz(cstart,cstep,(CurrentInput.read()/(50*rsens)));
+            SensorData.Voltage[LoopIterator]=quantiz(vstart,vstep,(VoltageInput.read()/5.37));
+            SensorData.Temperature[LoopIterator]=quantiz(tstart,tstep,(-90.7*3.18*TemperatureInput.read()+190.1543));
         } else {
-            SensorData.Current[LoopIterator-1]=Current[LoopIterator-1]<<4+quantiz(start,step,CurrentInput.read_u16());
-            SensorData.Voltage[LoopIterator-1]=Voltage[LoopIterator-1]<<4+quantiz(start,step,VoltageInput.read_u16());
-            SensorData.Temperature[LoopIterator-1]=Temperature[LoopIterator-1]<<4+quantiz(start,step,TemperatureInput.read_u16());
+            SensorData.Current[LoopIterator-1]=Current[LoopIterator-1]<<4+quantiz(cstart,cstep,(CurrentInput.read()/(50*rsens)));
+            SensorData.Voltage[LoopIterator-1]=Voltage[LoopIterator-1]<<4+quantiz(vstart,vstep,(VoltageInput.read()/5.37));
+            SensorData.Temperature[LoopIterator-1]=Temperature[LoopIterator-1]<<4+quantiz(tstart,tstep,(-90.7*3.18*TemperatureInput.read()+190.1543));
         }
 // The following lines are used to iterate the select lines from 0 to 15
         SelectLine0=!(SelectLine0);
diff -r 333cda053c40 -r 8b8bc4aef6f9 hkfinal.h
--- a/hkfinal.h	Tue Jul 08 16:03:07 2014 +0000
+++ b/hkfinal.h	Wed Jul 09 05:55:31 2014 +0000
@@ -1,3 +1,5 @@
+#include "mbed.h"
+
 DigitalOut SelectLine3 (p24); // MSB of Select Lines
 DigitalOut SelectLine2 (p23);
 DigitalOut SelectLine1 (p22);
@@ -7,6 +9,14 @@
 AnalogIn VoltageInput(p16); // Input from Voltage Multiplexer
 AnalogIn TemperatureInput(p17); // input from Temperature Multiplexer
 
+#define tstart -40
+#define tstep 8
+#define vstart 3.3
+#define vstep 0.84667
+#define cstart 0.0691
+#define cstep 0.09133
+#define rsens 0.095
+ 
 void FUNC_HK_MAIN();
 
 int quantiz(float start,float step,float x);
\ No newline at end of file