![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
BAE RTOS..working hopefully
hkfinal.cpp
- Committer:
- harshit_felicity
- Date:
- 2014-07-10
- Revision:
- 0:cbe0ea884289
File content as of revision 0:cbe0ea884289:
#include "hkfinal.h" DigitalOut SelectLine3 (p24); // MSB of Select Lines DigitalOut SelectLine2 (p23); DigitalOut SelectLine1 (p22); DigitalOut SelectLine0 (p21); // LSB of Select Lines AnalogIn CurrentInput(p15); // Input from Current Multiplexer AnalogIn VoltageInput(p16); // Input from Voltage Multiplexer AnalogIn TemperatureInput(p17); // input from Temperature Multiplexer typedef struct SensorData { char Voltage[10]; char Current[10]; char Temperature[10]; //float Battery[2]; }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-start)/step; if(y<=0)y=0; if(y>=15)y=15; return y; } void init_beacon(ShortBeacy x){ x.Voltage[0]=1; x.AngularSpeed[0]=2; x.AngularSpeed[1]=3; x.SubsystemStatus[0]=145; x.Temp[0]=1; x.Temp[1]=2; x.Temp[2]=3; x.ErrorFlag[0]=3; } void FUNC_HK_MAIN() { SensorDaty SensorData; ShortBeacy ShortBeacon; init_beacon(ShortBeacon); int LoopIterator; SelectLine0=0; SelectLine1=0; SelectLine2=0; SelectLine3=0; for(LoopIterator=0; LoopIterator<16; LoopIterator++) { if(LoopIterator%2==0) { 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]=SensorData.Current[LoopIterator-1]<<4+quantiz(cstart,cstep,(CurrentInput.read()/(50*rsens))); SensorData.Voltage[LoopIterator-1]=SensorData.Voltage[LoopIterator-1]<<4+quantiz(vstart,vstep,(VoltageInput.read()/5.37)); SensorData.Temperature[LoopIterator-1]=SensorData.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); if(LoopIterator%2==1) SelectLine1=!(SelectLine1); if(LoopIterator%4==3) SelectLine2=!(SelectLine2); if(LoopIterator%8==7) SelectLine3=!(SelectLine3); wait_us(10.0); // A delay of 10 microseconds between each sensor output. Can be changed. } }