Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: USBDevice max32630fthr
Revision 14:8ff04e82bda2, committed 2017-07-03
- Comitter:
- koziniec
- Date:
- Mon Jul 03 16:50:59 2017 +0000
- Parent:
- 13:ff0b39177386
- Child:
- 15:7d75ecaeabdb
- Commit message:
- green led if a gps fix is obtained (time is set); red led if gps times out.; blue led if waiting for gps and flashing if time but no fix obtained; ; code in main needs some proper switch input and calls to rockblock routines but so far ok.
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Jul 03 15:46:51 2017 +0000
+++ b/main.cpp Mon Jul 03 16:50:59 2017 +0000
@@ -6,13 +6,15 @@
#define OFF 1
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
+const int GPS_TIMEOUT=180; //Wait three minutes maximum for GPS.
+
Serial pc(USBTX, USBRX);
Serial gps(P5_3, P5_4, 9600);
I2C i2c(P5_7,P6_0); // SDA, SCL
DigitalOut red_led(LED1,1);
DigitalOut green_led(LED2,1);
-DigitalOut blue_led(LED3,1);
+DigitalOut gps_led(LED3,1); //Blue
char gpsfix_last_utc_time[11] = {0};
char gpsfix_last_utc_date[7] = {0};
char gpsfix_longtitude[12] = {0};
@@ -29,11 +31,18 @@
{
char data[2];
data[0] = 0x16; //MAX14690 LDO3cfg register
- data[1] = 0xE0; //Disable LDO3
if (state == ON) {
data[1] = 0xE2; //Enable LDO3
+ i2c.write( 0x50, data, 2 );
+ gps_led=ON;
+ } else {
+ data[1] = 0xE0; //Disable LDO3
+ i2c.write( 0x50, data, 2 );
+ gps_led=OFF;
+ while (gps.readable()) {
+ char dummy = gps.getc(); //Empty serial buffer because overflows reveal MBED bugs :-(
+ }
}
- i2c.write( 0x50, data, 2 );
}
int get_epoch_from_last_gps_time(void)
@@ -60,18 +69,12 @@
int gps_update(void)
{
-#define GPS_TIMEOUT 120; //Wait two minutes maximum for GPS.
gps_power(ON);
time_t gps_on_time = time(NULL); //Start time for GPS timeout calculation.
bool wait_for_fix = true; //Set this to false once a fix is obtained.
- blue_led = ON;
while (wait_for_fix) { //Keep monitoring the GPS until we get a fix.
- if ((time(NULL) - gps_on_time ) > 120) {
+ if ((time(NULL) - gps_on_time) > GPS_TIMEOUT) {
gps_power(OFF);
- blue_led = OFF;
- while (gps.readable()) {
- char dummy = gps.getc(); //Empty serial buffer because overflows reveal MBED bugs :-(
- }
return EXIT_FAILURE; //Return an error if the GPS takes too long for a fix.
}
int checksum = 0;
@@ -107,7 +110,7 @@
token = strtok(NULL, ",");
if (*token != 32) { //If there is a time present (anything but a space), record it.
//pc.printf("Time: %s\n\r",token);
- blue_led =! blue_led; //Flash blue LED
+ gps_led =! gps_led; //Flash blue LED
memcpy(gpsfix_last_utc_time, token, sizeof gpsfix_last_utc_time - 1);
}
}
@@ -120,11 +123,7 @@
if (*token == 'A') { //Is this an 'A'ctive (valid) fix?
pc.printf("Got a fix\n\r");
gps_power(OFF); //Yes - No need for GPS now
- blue_led = OFF;
wait_for_fix = false; //Stop looping now we have a fix.
- while (gps.readable()) {
- char dummy = gps.getc(); //Empty serial buffer because overflows reveal MBED bugs :-(
- }
if (token != NULL) {
token = strtok(NULL, ",");
//pc.printf("Latitude: %s\n\r",token);
@@ -169,9 +168,6 @@
}
}
}
- while (gps.readable()) {
- char dummy = gps.getc();
- }
}
return EXIT_SUCCESS;
}
@@ -207,9 +203,9 @@
} else {
pc.printf("\n\rGPS timed out and we have no existing fix.\n\r");
pc.printf("We can send an Iridium packet but coordinates are rough.\n\r");
+ pc.printf("Sending SOS in 10 seconds");
+ red_led=ON;
}
- pc.printf("Sending SOS in 10 seconds");
- red_led=ON;
while(true) {}; //STOP HERE
}
}