LoRa send is causing hang-up when a gps fix is acquired

Dependencies:   mbed LoRaWAN-lib_publishing_testing_UART_bug SingleFrequencyLora

Fork of simple-demo-76_revised_20171113_copy by Rishin Amin

Committer:
Rishin
Date:
Mon Dec 04 14:46:58 2017 +0000
Revision:
12:dc90bd3ac7d8
Child:
14:539ef77197e0
commit for publishing

Who changed what in which revision?

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