20211204

Dependencies:   mbed

Committer:
heptasat2021
Date:
Sat Dec 04 04:27:35 2021 +0000
Revision:
0:89798219a0dd
satcode_20211204

Who changed what in which revision?

UserRevisionLine numberNew contents of line
heptasat2021 0:89798219a0dd 1 #include "mbed.h"
heptasat2021 0:89798219a0dd 2 DigitalOut condition(LED1);
heptasat2021 0:89798219a0dd 3 Serial gs(USBTX,USBRX,9600);
heptasat2021 0:89798219a0dd 4 Timer sattime;
heptasat2021 0:89798219a0dd 5 int rcmd = 0, cmdflag = 0; //command variable
heptasat2021 0:89798219a0dd 6
heptasat2021 0:89798219a0dd 7 //getting command and command flag
heptasat2021 0:89798219a0dd 8 void commandget()
heptasat2021 0:89798219a0dd 9 {
heptasat2021 0:89798219a0dd 10 rcmd = gs.getc();
heptasat2021 0:89798219a0dd 11 cmdflag = 1;
heptasat2021 0:89798219a0dd 12 }
heptasat2021 0:89798219a0dd 13 //interrupting process by command receive
heptasat2021 0:89798219a0dd 14 void receive(int rcmd, int cmdflag)
heptasat2021 0:89798219a0dd 15 {
heptasat2021 0:89798219a0dd 16 gs.attach(commandget,Serial::RxIrq);
heptasat2021 0:89798219a0dd 17 }
heptasat2021 0:89798219a0dd 18 //initializing
heptasat2021 0:89798219a0dd 19 void initialize()
heptasat2021 0:89798219a0dd 20 {
heptasat2021 0:89798219a0dd 21 rcmd = 0;
heptasat2021 0:89798219a0dd 22 cmdflag = 0;
heptasat2021 0:89798219a0dd 23 condition = 0;
heptasat2021 0:89798219a0dd 24 }
heptasat2021 0:89798219a0dd 25
heptasat2021 0:89798219a0dd 26 int main()
heptasat2021 0:89798219a0dd 27 {
heptasat2021 0:89798219a0dd 28 gs.printf("From Sat : Nominal Operation\r\n");
heptasat2021 0:89798219a0dd 29 int flag = 0; //condition flag
heptasat2021 0:89798219a0dd 30 float batvol, temp; //voltage, temperature
heptasat2021 0:89798219a0dd 31 sattime.start();
heptasat2021 0:89798219a0dd 32 receive(rcmd,cmdflag); //interrupting
heptasat2021 0:89798219a0dd 33 for(int i=0;i<50;i++){
heptasat2021 0:89798219a0dd 34 //satellite condition led
heptasat2021 0:89798219a0dd 35 condition = !condition;
heptasat2021 0:89798219a0dd 36
heptasat2021 0:89798219a0dd 37 //senssing HK data(dummy data)
heptasat2021 0:89798219a0dd 38 batvol = 3.7;
heptasat2021 0:89798219a0dd 39 temp = 28.5;
heptasat2021 0:89798219a0dd 40
heptasat2021 0:89798219a0dd 41 //Transmitting HK data to Ground Station(GS)
heptasat2021 0:89798219a0dd 42 gs.printf("HEPTASAT::Condition = %d, Time = %f [s], batvol = %2f [V], temp = %2f [deg C]\r\n",flag,sattime.read(),batvol,temp);
heptasat2021 0:89798219a0dd 43 wait_ms(1000);
heptasat2021 0:89798219a0dd 44
heptasat2021 0:89798219a0dd 45 if(cmdflag == 1){
heptasat2021 0:89798219a0dd 46 if(rcmd == 'a'){
heptasat2021 0:89798219a0dd 47 for(int j=0;j<5;j++){
heptasat2021 0:89798219a0dd 48 gs.printf("Hello World!\r\n");
heptasat2021 0:89798219a0dd 49 condition = 1;
heptasat2021 0:89798219a0dd 50 wait_ms(1000);
heptasat2021 0:89798219a0dd 51 }
heptasat2021 0:89798219a0dd 52 }
heptasat2021 0:89798219a0dd 53 initialize(); //initializing
heptasat2021 0:89798219a0dd 54 }
heptasat2021 0:89798219a0dd 55 }
heptasat2021 0:89798219a0dd 56 sattime.stop();
heptasat2021 0:89798219a0dd 57 gs.printf("From Sat : End of operation\r\n");
heptasat2021 0:89798219a0dd 58 }