ARLISS2012

Dependencies:   mbed-rtos mbed MMA7361L MPL115A2

Fork of rtos_basic by mbed official

Revision:
6:c97217c9191b
Parent:
5:31bafc5b1bcd
--- a/main.cpp	Thu Aug 30 09:37:06 2012 +0000
+++ b/main.cpp	Thu Apr 30 13:50:23 2015 +0000
@@ -1,3 +1,7 @@
+/*
+@author Akira Kashihara <akira.kashihara@gmail.com>
+@suthor Kenta Osaki
+*/
 #include "mbed.h" //use mbed basic library                                                                               <include start
 #include "MPL115A2.h" // use MPL115A2 library
 #include "MMA7361L.h" //use MMA7361L library use 
@@ -12,12 +16,12 @@
 DigitalIn startsw(p6); //decide pin number of start switch
 BusOut leds(LED1, LED2, LED3, LED4); // decide led number of system check
 AnalogIn hu(p16); // decide pin number of humidity
-AnalogIn illu(p15);
+//AnalogIn illu(p15);
 Serial xbee(p28,p27); //decide pin number of xbee and decide Serial using
 Serial gps(p13, p14); // decide pin number of gps                                                                        <which pin does system use?(end)
 
-float begin, end;// timer define
-float begin_1;
+long int begin, end;// timer define
+long int begin_1 = 0;
 
 FILE *fp = fopen("/local/cansat.txt", "a"); //file system start, file open                                               <about file system to open "cansat.txt"
 
@@ -25,10 +29,10 @@
 char GPS[1000];
 int timer_count = 0;
 int xbee_count = 0;
-bool xbee_flag = false;
+bool xbee_flag = true;
 bool gps_flag = true; //about gps_flag define(true)                                                                      <gps_define(true)
 bool gps_get = true; //which gps get or lost
-bool stateSW = false; //about switch flag define(false)                                                                  <stateSW(false)
+bool stateSW = false; //about switch flag define(false)                                                           //  <stateSW(false)
 int at = 20; // define avarage time
 
 void gps_thread(void const *argument)                                //   <gps thread start
@@ -107,24 +111,26 @@
                     float accelX = accelx_buff / at;
                     float accelY = accely_buff / at;
                     float accelZ = accelz_buff / at;                                                               //    <avarage data(end)
-                    float lx = illu * 3.3 / 3 * 1000;
+                    //   float lx = illu * 3.3 / 3 * 1000;
 
                     end = timer.read_us() - timer_count*2000;
-                    double timers = (end - begin ) / 1000000;
+                    double timers = 1.0 * (end - begin ) / 1000000;
 
                     if(timers > 2000) {
                         timer_count ++;
-                        begin = timer.read_us() - timer_count*2000;; //timer number read
+                        begin = timer.read_us() - timer_count * 2000; //timer number read
                         timers = (end - begin) / 1000000;
                     }
 
 
                     if(xbee_count > 6) {
-                        double stop_timer = (end - begin_1) / 1000000;
-                        if(stop_timer > 30) {
+                        double stop_timer = 1.0 * (end - begin_1) / 1000000;
+                        if(stop_timer > 60 * 30) {
                             fclose(fp);
                             timer.stop();
-                            gps_flag = 0;
+                            gps_get = 1;
+                            gps_flag = 1;
+                            xbee.printf("CanSat was able to close the file\r\n");
                             while(true) {
                                 leds = 8;
                                 wait(1.0);
@@ -133,32 +139,29 @@
                             }
                         }
                     }
-
-                    if(lx > 800) {
-                        xbee_count ++;
+                    /*                   if(lx > 800) {
+                                           xbee_count ++;
 
-                        if(xbee_count > 5) {
-                            xbee_flag = true;
-                            if(xbee_count == 6) {
-                                begin_1 = timer.read_us();
-                                break;
-                            }
-                        }
-                    }
-
+                                           if(xbee_count >= 5) {
+                                               xbee_flag = true;
+                                               if(xbee_count == 5) {
+                                                   begin_1 = timer.read_us();
+                                               }
+                                           }
+                                       }*/
                     leds = 4;
 
                     if (gps_get == false) {
-                        fprintf(fp, "$DATA,%4.1f,%4.1f,%2.2f,%2.2f,%2.2f,%4.1f,%4.1f,%5.2f,#end\r\n", timers + timer_count * 2000, tempv, accelX, accelY, accelZ, press, humi,lx);
+                        fprintf(fp, "$DATA,%4.1f,%4.1f,%2.2f,%2.2f,%2.2f,%4.1f,%4.1f,#end\r\n", timers + timer_count * 2000, tempv, accelX, accelY, accelZ, press, humi);
                         if(xbee_flag == true) {
-                            xbee.printf("$DATA,%4.1f,%4.1f,%2.2f,%2.2f,%2.2f,%4.1f,%4.1f,%5.2f,#end\r\n", timers + timer_count * 2000, tempv, accelX, accelY, accelZ, press, humi,lx);
+                            xbee.printf("$DATA,%4.1f,%4.1f,%2.2f,%2.2f,%2.2f,%4.1f,%4.1f,#end\r\n", timers + timer_count * 2000, tempv, accelX, accelY, accelZ, press, humi);
                         }
                     }
 
                     if (gps_get == true) {
                         leds = 15;
                         if(xbee_flag == true) {
-                            xbee.printf("%s,#end\r\n", GPS);  //GPS data is dent by xbee                                                <xbee send system(GPS)
+                            xbee.printf("%s,#end\r\n", GPS);  //GPS data is dent by xbee
                         }
                         fprintf(fp, "%s,#end\r\n", GPS);  //GPS data is writen to mbed                                              <write system(GPS)
                         gps_get = false;