GPS working with LoRa code - can't transmit faster that once every 6 seconds
Dependencies: mbed LoRaWAN-lib_gps_lora SingleFrequencyLora
app/l86.cpp@13:66d854ad31d8, 2017-11-24 (annotated)
- Committer:
- Rishin
- Date:
- Fri Nov 24 15:20:12 2017 +0000
- Revision:
- 13:66d854ad31d8
- Parent:
- l86.cpp@12:d9144f16d78b
- Child:
- 15:b4d11baea8bc
Valid GPS data sent over LoRa for roughly 7 mins with no crash
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 | 12:d9144f16d78b | 7 | RawSerial pc2(USBTX, USBRX); // 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 | 12:d9144f16d78b | 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 | 12:d9144f16d78b | 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 | 12:d9144f16d78b | 71 | char tempLat[11]="0"; |
Rishin | 12:d9144f16d78b | 72 | char tempLong[12]="0"; |
Rishin | 11:f2a7f98cc9bf | 73 | if(strcmp(RMC_parsed.Status,"A") == 0){ |
Rishin | 11:f2a7f98cc9bf | 74 | strcpy(GPS_parsed.UTC_Time,RMC_parsed.UTC_Time); |
Rishin | 11:f2a7f98cc9bf | 75 | if (strcmp(RMC_parsed.N_S_Indicator, "N") == 0){ |
Rishin | 12:d9144f16d78b | 76 | tempLat[0] = '+'; |
Rishin | 11:f2a7f98cc9bf | 77 | } |
Rishin | 11:f2a7f98cc9bf | 78 | else{ |
Rishin | 12:d9144f16d78b | 79 | tempLat[0] = '-'; |
Rishin | 11:f2a7f98cc9bf | 80 | } |
Rishin | 12:d9144f16d78b | 81 | strcat(tempLat, RMC_parsed.Latitude); |
Rishin | 12:d9144f16d78b | 82 | strcpy(GPS_parsed.Latitude,tempLat); |
Rishin | 11:f2a7f98cc9bf | 83 | if (strcmp(RMC_parsed.E_W_Indicator, "E") == 0){ |
Rishin | 12:d9144f16d78b | 84 | tempLong[0] = '+'; |
Rishin | 11:f2a7f98cc9bf | 85 | } |
Rishin | 11:f2a7f98cc9bf | 86 | else{ |
Rishin | 12:d9144f16d78b | 87 | tempLong[0] = '-'; |
Rishin | 11:f2a7f98cc9bf | 88 | } |
Rishin | 12:d9144f16d78b | 89 | strcat(tempLong, RMC_parsed.Longitude); |
Rishin | 12:d9144f16d78b | 90 | strcpy(GPS_parsed.Longitude, tempLong); |
Rishin | 11:f2a7f98cc9bf | 91 | strcpy(GPS_parsed.Speed_Over_Ground,RMC_parsed.Speed_Over_Ground); |
Rishin | 11:f2a7f98cc9bf | 92 | strcpy(GPS_parsed.Course_Over_Ground,RMC_parsed.Course_Over_Ground); |
Rishin | 11:f2a7f98cc9bf | 93 | strcpy(GPS_parsed.Date,RMC_parsed.Date); |
Rishin | 11:f2a7f98cc9bf | 94 | strcpy(GPS_parsed.Valid,RMC_parsed.Status); |
Rishin | 10:0b5a507b4a4d | 95 | } |
Rishin | 11:f2a7f98cc9bf | 96 | else { |
Rishin | 11:f2a7f98cc9bf | 97 | strcpy(GPS_parsed.UTC_Time, "000000.000"); |
Rishin | 11:f2a7f98cc9bf | 98 | strcpy(GPS_parsed.Latitude,"+0000.0000"); |
Rishin | 11:f2a7f98cc9bf | 99 | strcpy(GPS_parsed.Longitude,"+00000.0000"); |
Rishin | 11:f2a7f98cc9bf | 100 | strcpy(GPS_parsed.Speed_Over_Ground,"0.00"); |
Rishin | 11:f2a7f98cc9bf | 101 | strcpy(GPS_parsed.Course_Over_Ground,"000.00"); |
Rishin | 11:f2a7f98cc9bf | 102 | strcpy(GPS_parsed.Date,"000000"); |
Rishin | 12:d9144f16d78b | 103 | strcpy(GPS_parsed.Valid,RMC_parsed.Status); |
Rishin | 10:0b5a507b4a4d | 104 | } |
Rishin | 10:0b5a507b4a4d | 105 | return GPS_parsed; |
Rishin | 10:0b5a507b4a4d | 106 | } |
Rishin | 10:0b5a507b4a4d | 107 | |
Rishin | 10:0b5a507b4a4d | 108 | /* Print GPS_data struct to PC USART for debugging */ |
Rishin | 10:0b5a507b4a4d | 109 | void Print_GPS_data(GPS_data GPS_data_print){ |
Rishin | 10:0b5a507b4a4d | 110 | pc2.printf("UTC_Time: %s\r\n",GPS_data_print.UTC_Time); |
Rishin | 10:0b5a507b4a4d | 111 | pc2.printf("Status: %s\r\n",GPS_data_print.Valid); |
Rishin | 10:0b5a507b4a4d | 112 | pc2.printf("Latitude: %s\r\n",GPS_data_print.Latitude); |
Rishin | 10:0b5a507b4a4d | 113 | pc2.printf("Longitude: %s\r\n",GPS_data_print.Longitude); |
Rishin | 10:0b5a507b4a4d | 114 | pc2.printf("Speed: %s\r\n",GPS_data_print.Speed_Over_Ground); |
Rishin | 10:0b5a507b4a4d | 115 | pc2.printf("Course: %s\r\n",GPS_data_print.Course_Over_Ground); |
Rishin | 10:0b5a507b4a4d | 116 | pc2.printf("Date: %s\r\n",GPS_data_print.Date); |
Rishin | 10:0b5a507b4a4d | 117 | } |
Rishin | 12:d9144f16d78b | 118 |