From 419bd31b281ca7b20497e25703caa7a6a76a4d76 Mon Sep 17 00:00:00 2001 From: Eneko Cruz Date: Sun, 15 May 2016 16:49:49 +0200 Subject: [PATCH] Modified logged messages and gps mode switch notification functions for coherence. --- gps/GPS.cc | 22 +++++++++++++++++----- gps/GPS.h | 2 ++ logic/initialize.cc | 4 ++++ logic/land.cc | 2 +- logic/safe_mode.cc | 4 ++++ logic/wait_launch.cc | 2 +- 6 files changed, 29 insertions(+), 7 deletions(-) diff --git a/gps/GPS.cc b/gps/GPS.cc index bcd342e..2884a67 100644 --- a/gps/GPS.cc +++ b/gps/GPS.cc @@ -353,7 +353,7 @@ void GPS::enter_airborne_1g_mode() 0x03, 0x00, 0x00, 0x00, 0x00, 0x10, 0x27, 0x00, 0x00, //determines new 0x05, 0x00, 0xFA, 0x00, 0xFA, 0x00, 0x64, 0x00, 0x2C, //operation mode. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0xDC + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0xDC }; uint8_t sz_setdm6 = 44; @@ -496,7 +496,7 @@ bool GPS::receive_check_ublox_ack(unsigned char *message) ack_packet[9]+= ack_packet[8]; } bytes_ordered = 0; - + gettimeofday(&time_start, NULL); ms_start = (long)((time_start.tv_sec)*1000 + (time_start.tv_usec)/1000); ms_now = ms_start; @@ -505,7 +505,7 @@ bool GPS::receive_check_ublox_ack(unsigned char *message) gettimeofday(&time_now, NULL); //timing out after ms_now = (long)((time_now.tv_sec)*1000 + (time_now.tv_usec)/1000); //3s - if (bytes_ordered > 9) + if (bytes_ordered > 9) { return true; } @@ -526,14 +526,26 @@ bool GPS::receive_check_ublox_ack(unsigned char *message) return false; } +void GPS::notify_initialization() +{ + this->logger->log("Initialization notified. Switching to pedestrian mode"); + this->enter_pedestrian_mode(); +} + void GPS::notify_takeoff() { - this->logger->log("GPS notified takeoff. Switching to airborne mode"); + this->logger->log("Takeoff notified. Switching to airborne mode"); + this->enter_airborne_1g_mode(); +} + +void GPS::notify_safe_mode() +{ + this->logger->log("Safe mode entry notified. Switching to airborne mode"); this->enter_airborne_1g_mode(); } void GPS::notify_landing() { - this->logger->log("GPS notified landing. Switching to stationary mode"); + this->logger->log("Landing notified. Switching to stationary mode"); this->enter_stationary_mode(); } diff --git a/gps/GPS.h b/gps/GPS.h index 45b7379..a9b657c 100644 --- a/gps/GPS.h +++ b/gps/GPS.h @@ -79,6 +79,8 @@ namespace os { void notify_takeoff(); void notify_landing(); + void notify_initialization(); + void notify_safe_mode(); }; } diff --git a/logic/initialize.cc b/logic/initialize.cc index d48aa38..41d325f 100644 --- a/logic/initialize.cc +++ b/logic/initialize.cc @@ -37,6 +37,10 @@ if ( ! GPS::get_instance().initialize()) } logger.log("GPS initialized."); +//Notify the GPS about its initialization, so that it sets itself to the appropriate mode +logger.log("Notifying GPS about initialization..."); +GPS::get_instance().notify_initialization(); + logger.log("Initializing GSM..."); if ( ! GSM::get_instance().initialize()) { diff --git a/logic/land.cc b/logic/land.cc index 5ec6ac8..d4b22b8 100644 --- a/logic/land.cc +++ b/logic/land.cc @@ -4,7 +4,7 @@ if ( ! Camera::get_instance().stop()) else logger->log("Video stopped."); -logger->log("Setting GPS to stationary mode..."); +logger->log("Notifying GPS about landing..."); GPS::get_instance().notify_landing(); logger->log("Waiting 1 minute before sending landed SMS..."); diff --git a/logic/safe_mode.cc b/logic/safe_mode.cc index 859d116..bcddf28 100644 --- a/logic/safe_mode.cc +++ b/logic/safe_mode.cc @@ -161,6 +161,10 @@ switch (last_state) } logger->log("GPS fix acquired."); + + logger->log("Notifying GPS about entering safe mode..."); + GPS::get_instance().notify_safe_mode(); + this_thread::sleep_for(5s); for (int i = 0; GPS::get_instance().get_HDOP() > 5 && i < 10; diff --git a/logic/wait_launch.cc b/logic/wait_launch.cc index ff60d78..debbb03 100644 --- a/logic/wait_launch.cc +++ b/logic/wait_launch.cc @@ -12,5 +12,5 @@ while ( ! has_launched(launch_altitude)) logger->log("Balloon launched."); -logger->log("Setting GPS to airborne mode..."); +logger->log("Notifying GPS about launch..."); GPS::get_instance().notify_takeoff();