GPS working with LoRa code - can't transmit faster that once every 6 seconds

Dependencies:   mbed LoRaWAN-lib_gps_lora SingleFrequencyLora

Committer:
Rishin
Date:
Wed Nov 15 15:27:36 2017 +0000
Revision:
11:f2a7f98cc9bf
Parent:
10:0b5a507b4a4d
Child:
12:d9144f16d78b
Fixed issue with GPS parsing - RMC was not completely filled => causing problems

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rishin 5:850a9db98a41 1 #include "l86.hpp"
Rishin 5:850a9db98a41 2 #include <string.h>
Rishin 6:670ff1507ff4 3 #include <stdio.h>
Rishin 7:1c90f51096fe 4 #include "mbed.h"
Rishin 5:850a9db98a41 5
Rishin 7:1c90f51096fe 6 #ifdef DEBUGGER
Rishin 7:1c90f51096fe 7 RawSerial pc2(PC_TX, PC_RX); // USART2
Rishin 7:1c90f51096fe 8 #endif
Rishin 7:1c90f51096fe 9
Rishin 10:0b5a507b4a4d 10 /* Parse NMEA RMC sentence into RMC data struct */
Rishin 10:0b5a507b4a4d 11 RMC_data Parse_RMC_sentence(char RMC_sentence[MAX_NMEA_LENGTH]){
Rishin 5:850a9db98a41 12 const char delimeter[2] = ",";
Rishin 5:850a9db98a41 13 char *token = "";
Rishin 5:850a9db98a41 14 int i = 0;
Rishin 7:1c90f51096fe 15 char temp[11][12]; /* [11][12]: 11 strings, of length 12 */
Rishin 7:1c90f51096fe 16 RMC_data RMC_parsed;
Rishin 5:850a9db98a41 17
Rishin 7:1c90f51096fe 18 strcpy(RMC_parsed.Message, RMC_sentence);
Rishin 5:850a9db98a41 19
Rishin 5:850a9db98a41 20 //Seperated Message
Rishin 5:850a9db98a41 21 /* get the first token */
Rishin 10:0b5a507b4a4d 22 token = strtok(RMC_sentence, delimeter);
Rishin 5:850a9db98a41 23
Rishin 5:850a9db98a41 24 /* walk through other tokens */
Rishin 5:850a9db98a41 25 while( token != NULL )
Rishin 5:850a9db98a41 26 {
Rishin 5:850a9db98a41 27 strcpy(temp[i],token);
Rishin 5:850a9db98a41 28 i++;
Rishin 5:850a9db98a41 29 token = strtok(NULL, delimeter);
Rishin 5:850a9db98a41 30 }
Rishin 5:850a9db98a41 31
Rishin 6:670ff1507ff4 32 //Copy the message into its individual components
Rishin 7:1c90f51096fe 33 strcpy(RMC_parsed.Message_ID,temp[0]);
Rishin 7:1c90f51096fe 34 strcpy(RMC_parsed.UTC_Time,temp[1]);
Rishin 7:1c90f51096fe 35 strcpy(RMC_parsed.Status,temp[2]);
Rishin 7:1c90f51096fe 36 if(strcmp(RMC_parsed.Status,"A") == 0){
Rishin 7:1c90f51096fe 37 strcpy(RMC_parsed.Latitude,temp[3]);
Rishin 7:1c90f51096fe 38 strcpy(RMC_parsed.N_S_Indicator,temp[4]);
Rishin 7:1c90f51096fe 39 strcpy(RMC_parsed.Longitude,temp[5]);
Rishin 7:1c90f51096fe 40 strcpy(RMC_parsed.E_W_Indicator,temp[6]);
Rishin 7:1c90f51096fe 41 strcpy(RMC_parsed.Speed_Over_Ground,temp[7]);
Rishin 7:1c90f51096fe 42 strcpy(RMC_parsed.Course_Over_Ground,temp[8]);
Rishin 7:1c90f51096fe 43 strcpy(RMC_parsed.Date,temp[9]);
Rishin 7:1c90f51096fe 44 strcpy(RMC_parsed.Mode,temp[10]);
Rishin 7:1c90f51096fe 45 }
Rishin 7:1c90f51096fe 46 return RMC_parsed;
Rishin 6:670ff1507ff4 47 }
Rishin 6:670ff1507ff4 48
Rishin 7:1c90f51096fe 49 // Use GPS data parse function? // parses into data formats that will be sent over LoRa
Rishin 7:1c90f51096fe 50
Rishin 10:0b5a507b4a4d 51 /* Print RMC_data struct to PC USART for debugging */
Rishin 7:1c90f51096fe 52 void Print_RMC_data(RMC_data *RMC_data_print){
Rishin 9:b866f1bc8fd4 53 pc2.printf("RMC_Message: %s",RMC_data_print->Message);
Rishin 7:1c90f51096fe 54 pc2.printf("UTC_Time: %s\r\n",RMC_data_print->UTC_Time);
Rishin 7:1c90f51096fe 55 pc2.printf("Status: %s\r\n",RMC_data_print->Status);
Rishin 7:1c90f51096fe 56 if(strcmp(RMC_data_print->Status,"A") == 0){
Rishin 7:1c90f51096fe 57 pc2.printf("Latitude: %s\r\n",RMC_data_print->Latitude);
Rishin 7:1c90f51096fe 58 pc2.printf("N/S: %s\r\n",RMC_data_print->N_S_Indicator);
Rishin 7:1c90f51096fe 59 pc2.printf("Longitude: %s\r\n",RMC_data_print->Longitude);
Rishin 7:1c90f51096fe 60 pc2.printf("E/W: %s\r\n",RMC_data_print->E_W_Indicator);
Rishin 7:1c90f51096fe 61 pc2.printf("Speed: %s\r\n",RMC_data_print->Speed_Over_Ground);
Rishin 7:1c90f51096fe 62 pc2.printf("Course: %s\r\n",RMC_data_print->Course_Over_Ground);
Rishin 7:1c90f51096fe 63 pc2.printf("Date: %s\r\n",RMC_data_print->Date);
Rishin 7:1c90f51096fe 64 pc2.printf("Mode: %s\r\n",RMC_data_print->Mode);
Rishin 7:1c90f51096fe 65 }
Rishin 10:0b5a507b4a4d 66 }
Rishin 10:0b5a507b4a4d 67
Rishin 10:0b5a507b4a4d 68 /* Parse RMC_data struct into GPS data struct ready for sending over LoRa */
Rishin 10:0b5a507b4a4d 69 GPS_data Parse_RMC_data(RMC_data RMC_parsed){
Rishin 10:0b5a507b4a4d 70 GPS_data GPS_parsed;
Rishin 11:f2a7f98cc9bf 71 if(strcmp(RMC_parsed.Status,"A") == 0){
Rishin 11:f2a7f98cc9bf 72 strcpy(GPS_parsed.UTC_Time,RMC_parsed.UTC_Time);
Rishin 11:f2a7f98cc9bf 73 if (strcmp(RMC_parsed.N_S_Indicator, "N") == 0){
Rishin 11:f2a7f98cc9bf 74 strcpy(GPS_parsed.Latitude, strcat("+", RMC_parsed.Latitude));
Rishin 11:f2a7f98cc9bf 75 }
Rishin 11:f2a7f98cc9bf 76 else{
Rishin 11:f2a7f98cc9bf 77 strcpy(GPS_parsed.Latitude, strcat("-", RMC_parsed.Latitude));
Rishin 11:f2a7f98cc9bf 78 }
Rishin 11:f2a7f98cc9bf 79 if (strcmp(RMC_parsed.E_W_Indicator, "E") == 0){
Rishin 11:f2a7f98cc9bf 80 strcpy(GPS_parsed.Longitude, strcat("+", RMC_parsed.Longitude));
Rishin 11:f2a7f98cc9bf 81 }
Rishin 11:f2a7f98cc9bf 82 else{
Rishin 11:f2a7f98cc9bf 83 strcpy(GPS_parsed.Longitude, strcat("-", RMC_parsed.Longitude));
Rishin 11:f2a7f98cc9bf 84 }
Rishin 11:f2a7f98cc9bf 85 strcpy(GPS_parsed.Speed_Over_Ground,RMC_parsed.Speed_Over_Ground);
Rishin 11:f2a7f98cc9bf 86 strcpy(GPS_parsed.Course_Over_Ground,RMC_parsed.Course_Over_Ground);
Rishin 11:f2a7f98cc9bf 87 strcpy(GPS_parsed.Date,RMC_parsed.Date);
Rishin 11:f2a7f98cc9bf 88 strcpy(GPS_parsed.Valid,RMC_parsed.Status);
Rishin 10:0b5a507b4a4d 89 }
Rishin 11:f2a7f98cc9bf 90 else {
Rishin 11:f2a7f98cc9bf 91 strcpy(GPS_parsed.UTC_Time, "000000.000");
Rishin 11:f2a7f98cc9bf 92 strcpy(GPS_parsed.Latitude,"+0000.0000");
Rishin 11:f2a7f98cc9bf 93 strcpy(GPS_parsed.Longitude,"+00000.0000");
Rishin 11:f2a7f98cc9bf 94 strcpy(GPS_parsed.Speed_Over_Ground,"0.00");
Rishin 11:f2a7f98cc9bf 95 strcpy(GPS_parsed.Course_Over_Ground,"000.00");
Rishin 11:f2a7f98cc9bf 96 strcpy(GPS_parsed.Date,"000000");
Rishin 11:f2a7f98cc9bf 97 strcpy(GPS_parsed.Valid,"V");
Rishin 10:0b5a507b4a4d 98 }
Rishin 10:0b5a507b4a4d 99 return GPS_parsed;
Rishin 10:0b5a507b4a4d 100 }
Rishin 10:0b5a507b4a4d 101
Rishin 10:0b5a507b4a4d 102 /* Print GPS_data struct to PC USART for debugging */
Rishin 10:0b5a507b4a4d 103 void Print_GPS_data(GPS_data GPS_data_print){
Rishin 10:0b5a507b4a4d 104 pc2.printf("UTC_Time: %s\r\n",GPS_data_print.UTC_Time);
Rishin 10:0b5a507b4a4d 105 pc2.printf("Status: %s\r\n",GPS_data_print.Valid);
Rishin 10:0b5a507b4a4d 106 pc2.printf("Latitude: %s\r\n",GPS_data_print.Latitude);
Rishin 10:0b5a507b4a4d 107 pc2.printf("Longitude: %s\r\n",GPS_data_print.Longitude);
Rishin 10:0b5a507b4a4d 108 pc2.printf("Speed: %s\r\n",GPS_data_print.Speed_Over_Ground);
Rishin 10:0b5a507b4a4d 109 pc2.printf("Course: %s\r\n",GPS_data_print.Course_Over_Ground);
Rishin 10:0b5a507b4a4d 110 pc2.printf("Date: %s\r\n",GPS_data_print.Date);
Rishin 10:0b5a507b4a4d 111 }