a

Dependencies:   HEPTA_CDH HEPTA_EPS HEPTA_SENSOR mbed

Revision:
33:c64ee36e2d50
Parent:
32:c22cbcfb4635
Child:
35:b26666d35b9d
--- a/main.cpp	Fri Aug 19 04:35:30 2022 +0000
+++ b/main.cpp	Mon Nov 14 01:54:03 2022 +0000
@@ -10,89 +10,117 @@
                   p13, p14,p25,p24);
 HEPTA_COM com(p9,p10);
 DigitalOut condition(LED1);
-Serial sat(USBTX,USBRX,9600);
+RawSerial sat(USBTX,USBRX,9600);
 Timer sattime;
 int rcmd = 0,cmdflag = 0; //command variable
+//getting command and flag
+void commandget()
+{
+    rcmd = sat.getc();
+    cmdflag = 1;
+}
+//interrupting 
+void receive(int rcmd, int cmdflag)
+{
+    sat.attach(commandget,Serial::RxIrq);
+}
 
 int main() {
-    sat.printf("From Sat : Nominal Operation\r\n");
-    com.printf("From Sat : Nominal Operation\r\n");
-    com.baud(9600);
-    int flag = 0; //condition flag
-    float batvol, temp; //voltage, temperature 
-    int rcmd=0,cmdflag=0;  //command variable
-    sattime.start();
-    eps.turn_on_regulator();//turn on 3.3V conveter
-    for(int i = 0; i < 100; i++) {
-        com.xbee_receive(&rcmd,&cmdflag);//interupting by ground station command
-        
-        //satellite condition led
-        condition = !condition;
-        
-        //senssing HK data(dummy data)
-        eps.vol(&batvol);
-        sensor.temp_sense(&temp);
-        
-        //Transmitting HK data to Ground Station(GS)
-        com.printf("HEPTASAT::Condition = %d, Time = %f [s], batVol = %.2f [V],Temp = %.2f [C]\r\n",flag,sattime.read(),batvol,temp);
-        wait_ms(1000);
-                
-        //Power Saving Mode 
-        if((batvol <= 3.5)  | (temp > 35.0)){
-            eps.shut_down_regulator();
-            com.printf("Power saving mode ON\r\n"); 
-            flag = 1;
-        } else if((flag == 1) & (batvol > 3.7) & (temp <= 25.0)) {
-            eps.turn_on_regulator();
-            com.printf("Power saving mode OFF\r\n");
-            flag = 0;
-        }
-        //Contents of command
-        if (cmdflag == 1) {
-            if (rcmd == 'a') {
-                sat.printf("rcmd=%c,cmdflag=%d\r\n",rcmd,cmdflag);
-                com.printf("Hepta-Sat Lite Uplink Ok\r\n");
-                for(int j=0;j<5;j++){
-                    com.printf("Hello World!\r\n");
-                    condition = 1;
-                    wait_ms(1000);
+    sat.printf("HEPTA-Sat Debug Program start\r\n");
+    while(1){
+        sat.printf("Please sellect a mode bellow\r\n");
+        sat.printf("========================================\r\n");
+        sat.printf("a: Check saving to SD card Mode\r\n");
+        sat.printf("b: Check the battery voltage Mode\r\n");
+        sat.printf("c: Check the temp sensor Mode\r\n");
+        sat.printf("d: Check the 9 axis Mode\r\n");
+        sat.printf("e: Check GPS rawdata Mode\r\n");
+        sat.printf("f: Chec Camera snapchat Mode\r\n");
+        sat.printf("g: \r\n");
+        sat.printf("========================================\r\n");
+        int rcmd=0,cmdflag=0;  //command variable
+        sattime.start();
+        eps.turn_on_regulator();//turn on 3.3V conveter
+        for(int i = 0; i < 100; i++) {
+            receive(rcmd,cmdflag);
+            
+            //satellite condition led
+            condition = !condition;
+            //Contents of command
+            if (cmdflag == 1) {
+                if (rcmd == 'a') {
+                    //SD mode
+                    char str[100];
+                    mkdir("/sd/mydir", 0777);
+                    FILE *fp = fopen("/sd/mydir/test.txt","w");
+                    if(fp == NULL) {
+                        error("Could not open file for write\r\n");
+                    }
+                    for(int i=0; i<10; i++)fprintf(fp,"Hello my name is HEPTA!\r\n");
+                    fclose(fp);
+                    fp = fopen("/sd/mydir/test.txt","r");
+                    for(int j = 0; j < 10; j++) {
+                        fgets(str,100,fp);
+                        sat.puts(str);
+                    }
+                    fclose(fp);
+                    sat.printf("Goodbye!!\r\n");
+                }else if (rcmd == 'b') {
+                    float bt;
+                    for(int i = 0; i < 10; i++) {
+                        eps.vol(&bt);
+                        sat.printf("Vol = %f\r\n",bt);
+                        wait(0.5);
+                    }        
+                }else if (rcmd == 'c') {        
+                    //Please insert your answer
+                    float temp;
+                    for (int i=0;i<10;i++) {
+                        sensor.temp_sense(&temp);
+                        sat.printf("temp = %f\r\n",temp);
+                        wait(0.5);
+                    }
+                }else if (rcmd == 'd') {
+                    //Please insert your answer
+                    float ax,ay,az;
+                    float gx,gy,gz;
+                    float mx,my,mz;
+                    for(int i = 0; i<10; i++) {
+                        sensor.sen_acc(&ax,&ay,&az);
+                        sat.printf("acc : ax= %f, ay= %f, az= %f\r\n",ax,ay,az);
+                        sensor.sen_gyro(&gx,&gy,&gz);
+                        sat.printf("gyro: gx= %f, gy= %f, gz= %f\r\n",gx,gy,gz);
+                        sensor.sen_mag(&mx,&my,&mz);
+                        sat.printf("mag : mx= %f, my= %f, mz= %f\r\n",mx,my,mz);
+                        wait(0.5);
+                    }
+                }else if (rcmd == 'e') {
+                    //Please insert your answer
+                    sensor.gps_setting();
+                    sat.printf("GPS Raw Data Mode\r\n");
+                    while(1) sat.putc(sensor.getc());
+                }else if (rcmd == 'f') { 
+                    FILE *dummy = fopen("/sd/dummy.txt","w");
+                    if(dummy == NULL) {
+                        error("Could not open file for write\r\n");
+                    }
+                    fclose(dummy);
+                    
+                    sat.printf("Camera Snapshot Mode\r\n");
+                    sat.printf("Hit Any Key To Take Picture\r\n");
+                    while(!sat.readable()) {}
+                    sensor.Sync();
+                    sensor.initialize(HeptaCamera_GPS::Baud115200, HeptaCamera_GPS::JpegResolution320x240);
+                    sensor.test_jpeg_snapshot_picture("/sd/test.jpg");
+                }else if (rcmd == 'g'){
+                    sat.printf("Xbee Count Up Mode\r\n");
+                    for(int i = 0; i < 10; i++) {
+                        com.printf("num = %d\r\n",i);
+                        wait(0.5);
+                    }
                 }
-            }else if (rcmd == 'b') {
-                sat.printf("rcmd=%c,cmdflag=%d\r\n",rcmd,cmdflag);
-                com.printf("Hepta-Sat Lite Uplink Ok\r\n");
-                char str[100];
-                mkdir("/sd/mydir", 0777);
-                FILE *fp = fopen("/sd/mydir/satdata.txt","w");
-                if(fp == NULL) {
-                    error("Could not open file for write\r\n");
-                }
-                for(int i = 0; i < 10; i++) {
-                    eps.vol(&batvol);
-                    fprintf(fp,"%f\r\n",batvol);
-                    condition = 1;
-                    wait_ms(1000);
-                }
-                fclose(fp);
-                fp = fopen("/sd/mydir/satdata.txt","r");
-                for(int i = 0; i < 10; i++) {
-                    fgets(str,100,fp);
-                    com.puts(str);
-                }
-                fclose(fp);                
-            }else if (rcmd == 'c') {        
-                //Please insert your answer
-
-            }else if (rcmd == 'd') {
-                //Please insert your answer
-
-            }else if (rcmd == 'e') {
-                //Please insert your answer
-
+                rcmd=0,cmdflag=0;
             }
-            com.initialize();
         }
     }
-    sattime.stop();
-    sat.printf("From Sat : End of operation\r\n");
-    com.printf("From Sat : End of operation\r\n");
 }