GPS working with LoRa code - can't transmit faster that once every 6 seconds
Dependencies: mbed LoRaWAN-lib_gps_lora SingleFrequencyLora
l86.cpp@10:0b5a507b4a4d, 2017-11-14 (annotated)
- Committer:
- Rishin
- Date:
- Tue Nov 14 16:06:16 2017 +0000
- Revision:
- 10:0b5a507b4a4d
- Parent:
- 9:b866f1bc8fd4
- Child:
- 11:f2a7f98cc9bf
Added GPS parse function, but the program hangs when the function is called
Who changed what in which revision?
User | Revision | Line number | New 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 | 10:0b5a507b4a4d | 71 | strcpy(GPS_parsed.UTC_Time,RMC_parsed.UTC_Time); |
Rishin | 10:0b5a507b4a4d | 72 | if (strcmp(RMC_parsed.N_S_Indicator, "N") == 0){ |
Rishin | 10:0b5a507b4a4d | 73 | strcpy(GPS_parsed.Latitude, strcat("+", RMC_parsed.Latitude)); |
Rishin | 10:0b5a507b4a4d | 74 | } |
Rishin | 10:0b5a507b4a4d | 75 | else{ |
Rishin | 10:0b5a507b4a4d | 76 | strcpy(GPS_parsed.Latitude, strcat("-", RMC_parsed.Latitude)); |
Rishin | 10:0b5a507b4a4d | 77 | } |
Rishin | 10:0b5a507b4a4d | 78 | if (strcmp(RMC_parsed.E_W_Indicator, "E") == 0){ |
Rishin | 10:0b5a507b4a4d | 79 | strcpy(GPS_parsed.Longitude, strcat("+", RMC_parsed.Latitude)); |
Rishin | 10:0b5a507b4a4d | 80 | } |
Rishin | 10:0b5a507b4a4d | 81 | else{ |
Rishin | 10:0b5a507b4a4d | 82 | strcpy(GPS_parsed.Longitude, strcat("-", RMC_parsed.Latitude)); |
Rishin | 10:0b5a507b4a4d | 83 | } |
Rishin | 10:0b5a507b4a4d | 84 | strcpy(GPS_parsed.Speed_Over_Ground,RMC_parsed.Speed_Over_Ground); |
Rishin | 10:0b5a507b4a4d | 85 | strcpy(GPS_parsed.Course_Over_Ground,RMC_parsed.Course_Over_Ground); |
Rishin | 10:0b5a507b4a4d | 86 | strcpy(GPS_parsed.Date,RMC_parsed.Date); |
Rishin | 10:0b5a507b4a4d | 87 | strcpy(GPS_parsed.Valid,RMC_parsed.Status); |
Rishin | 10:0b5a507b4a4d | 88 | return GPS_parsed; |
Rishin | 10:0b5a507b4a4d | 89 | } |
Rishin | 10:0b5a507b4a4d | 90 | |
Rishin | 10:0b5a507b4a4d | 91 | /* Print GPS_data struct to PC USART for debugging */ |
Rishin | 10:0b5a507b4a4d | 92 | void Print_GPS_data(GPS_data GPS_data_print){ |
Rishin | 10:0b5a507b4a4d | 93 | pc2.printf("UTC_Time: %s\r\n",GPS_data_print.UTC_Time); |
Rishin | 10:0b5a507b4a4d | 94 | pc2.printf("Status: %s\r\n",GPS_data_print.Valid); |
Rishin | 10:0b5a507b4a4d | 95 | pc2.printf("Latitude: %s\r\n",GPS_data_print.Latitude); |
Rishin | 10:0b5a507b4a4d | 96 | pc2.printf("Longitude: %s\r\n",GPS_data_print.Longitude); |
Rishin | 10:0b5a507b4a4d | 97 | pc2.printf("Speed: %s\r\n",GPS_data_print.Speed_Over_Ground); |
Rishin | 10:0b5a507b4a4d | 98 | pc2.printf("Course: %s\r\n",GPS_data_print.Course_Over_Ground); |
Rishin | 10:0b5a507b4a4d | 99 | pc2.printf("Date: %s\r\n",GPS_data_print.Date); |
Rishin | 10:0b5a507b4a4d | 100 | } |