acsip s76g

Dependencies:   TinyGPSPlus

Files at this revision

API Documentation at this revision

Comitter:
frank_dunn1
Date:
Wed Jul 08 08:54:48 2020 +0000
Parent:
52:922d8fdaae44
Commit message:
mods

Changed in this revision

TinyGPSPlus.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 922d8fdaae44 -r a3344ee53c2c TinyGPSPlus.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TinyGPSPlus.lib	Wed Jul 08 08:54:48 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/aoba/code/TinyGPSPlus/#6d3813637f20
diff -r 922d8fdaae44 -r a3344ee53c2c main.cpp
--- a/main.cpp	Sun Jul 05 20:31:13 2020 +0000
+++ b/main.cpp	Wed Jul 08 08:54:48 2020 +0000
@@ -19,7 +19,7 @@
 #include "lorawan/LoRaWANInterface.h"
 #include "lorawan/system/lorawan_data_structures.h"
 #include "events/EventQueue.h"
-
+#include "TinyGPSPlus.h"
 // Application helpers
 #include "trace_helper.h"
 #include "lora_radio_helper.h"
@@ -31,12 +31,16 @@
 // If longer messages are used, these buffers must be changed accordingly.
 uint8_t tx_buffer[30];
 uint8_t rx_buffer[30];
+char buf[128];
 
+char c;
 /*
  * Sets up an application dependent transmission timer in ms. Used only when Duty Cycling is off for testing
  */
 #define TX_TIMER                        10000
 
+
+
 /**
  * Maximum number of events for the event queue.
  * 10 is the safe number for the stack events, however, if application
@@ -49,8 +53,16 @@
  */
 #define CONFIRMED_MSG_RETRY_COUNTER     3
 
-//Serial pc(PC_11,PC_10);
+#define DATABUFFER_SIZE 128
+
+
+
+
+Serial gpsPort(PC_10,PC_11,115200);
 Serial pc(PA_9,PA_10);
+TinyGPSPlus gps;
+DigitalOut GPS_LEVEL_SHIFTER_EN(PC_6);
+DigitalOut GPS_RESET(PB_2);
 /**
 * This event queue is the global event queue for both the
 * application and stack. To conserve memory, the stack is designed to run
@@ -78,12 +90,65 @@
  */
 static lorawan_app_callbacks_t callbacks;
 
+void gpsSetup()
+{
+
+    GPS_LEVEL_SHIFTER_EN=1;
+    wait(0.2);
+    GPS_RESET=0;
+
+    wait(1);
+
+    GPS_RESET=1;
+
+   // wait(1);
+    //gpsPort.printf("@GSR\r\n");//"@GNS 0x3\r\n"
+    //wait(.25);
+    //gpsPort.printf("@GNS 0x3\r\n");
+    //wait(.25);
+    //gpsPort.printf("@BSSL 0x25\r\n");
+    //wait(.25);
+    //gpsPort.printf("@GCD\r\n");
+    //wait(.25);
+}
+
+void getGpsData()
+{   
+    
+    c= gpsPort.getc();
+
+    //pc.putc(c);
+    switch (c) {
+        case '\n':
+            if (gps.satellites.isValid() && gps.satellites.value() > 3 && gps.hdop.hdop() > 0) {
+                snprintf(buf, 128, "{\"lat\":%lf,\"lng\":%lf}", gps.location.lat(), gps.location.lng());
+            } else {
+                snprintf(buf, 128, "Satellites: %lu, time: %04d-%02d-%02dT%02d:%02d:%02d.%02d",
+                         gps.satellites.value(), gps.date.year(), gps.date.month(), gps.date.day(),
+                         gps.time.hour(), gps.time.minute(), gps.time.second(), gps.time.centisecond());
+            }
+            pc.printf("%s\r\n", buf);
+        break;
+        default:
+            gps.encode(c);
+            break;
+    }
+    
+    ev_queue.call(getGpsData); 
+}
+
+
 /**
  * Entry point for application
  */
 int main(void)
-{ 
-   pc.printf("hello");
+
+{
+    //getGpsData();
+    gpsSetup();
+    
+
+    pc.printf("hello");
     // setup tracing
     setup_trace();
 
@@ -109,8 +174,8 @@
         return -1;
     }
 
-    printf("\r\n CONFIRMED message retries : %d \r\n",
-           CONFIRMED_MSG_RETRY_COUNTER);
+    pc.printf("\r\n CONFIRMED message retries : %d \r\n",
+              CONFIRMED_MSG_RETRY_COUNTER);
 
     // Enable adaptive data rate
     if (lorawan.enable_adaptive_datarate() != LORAWAN_STATUS_OK) {
@@ -129,8 +194,10 @@
         return -1;
     }
 
-    printf("\r\n Connection - In Progress ...\r\n");
-
+    pc.printf("\r\n Connection - In Progress ...\r\n");
+     
+     
+    ev_queue.call(getGpsData); 
     // make your event queue dispatching events forever
     ev_queue.dispatch_forever();
 
@@ -144,7 +211,7 @@
 {
     uint16_t packet_len;
     int16_t retcode;
-    pc.printf("\n\rHello world");    
+    pc.printf("\n\rHello world");
 
     packet_len = sprintf((char *) tx_buffer, "Hello world");
 
@@ -166,6 +233,7 @@
 
     pc.printf("\r\n %d bytes scheduled for transmission \r\n", retcode);
     memset(tx_buffer, 0, sizeof(tx_buffer));
+
 }
 
 /**
@@ -175,7 +243,7 @@
 {
     switch (event) {
         case CONNECTED:
-            printf("\r\n Connection - Successful \r\n");
+            pc.printf("\r\n Connection - Successful \r\n");
             if (MBED_CONF_LORA_DUTY_CYCLE_ON) {
                 send_message();
             } else {
@@ -185,36 +253,37 @@
             break;
         case DISCONNECTED:
             ev_queue.break_dispatch();
-            printf("\r\n Disconnected Successfully \r\n");
+            pc.printf("\r\n Disconnected Successfully \r\n");
             break;
         case TX_DONE:
-            printf("\r\n Message Sent to Network Server \r\n");
+            pc.printf("\r\n Message Sent to Network Server \r\n");
             if (MBED_CONF_LORA_DUTY_CYCLE_ON) {
                 send_message();
+
             }
             break;
         case TX_TIMEOUT:
         case TX_ERROR:
         case TX_CRYPTO_ERROR:
         case TX_SCHEDULING_ERROR:
-            printf("\r\n Transmission Error - EventCode = %d \r\n", event);
+            pc.printf("\r\n Transmission Error - EventCode = %d \r\n", event);
             // try again
             if (MBED_CONF_LORA_DUTY_CYCLE_ON) {
                 send_message();
             }
             break;
         case RX_DONE:
-            printf("\r\n Received message from Network Server \r\n");
+            pc.printf("\r\n Received message from Network Server \r\n");
             break;
         case RX_TIMEOUT:
         case RX_ERROR:
-            printf("\r\n Error in reception - Code = %d \r\n", event);
+            pc.printf("\r\n Error in reception - Code = %d \r\n", event);
             break;
         case JOIN_FAILURE:
-            printf("\r\n OTAA Failed - Check Keys \r\n");
+            pc.printf("\r\n OTAA Failed - Check Keys \r\n");
             break;
         case UPLINK_REQUIRED:
-            printf("\r\n Uplink required by NS \r\n");
+            pc.printf("\r\n Uplink required by NS \r\n");
             if (MBED_CONF_LORA_DUTY_CYCLE_ON) {
                 send_message();
             }
diff -r 922d8fdaae44 -r a3344ee53c2c mbed-os.lib
--- a/mbed-os.lib	Sun Jul 05 20:31:13 2020 +0000
+++ b/mbed-os.lib	Wed Jul 08 08:54:48 2020 +0000
@@ -1,1 +1,1 @@
-https://github.com/ARMmbed/mbed-os/#51d55508e8400b60af467005646c4e2164738d48
+https://github.com/ARMmbed/mbed-os/#3ab72c71b75cb9cb91160a54fba22ec43b036ed2