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
Revision 14:539ef77197e0, committed 2017-12-04
- Comitter:
- Rishin
- Date:
- Mon Dec 04 21:25:19 2017 +0000
- Parent:
- 13:9f1dd1497e9a
- Commit message:
- initial commit for publish
Changed in this revision
diff -r 9f1dd1497e9a -r 539ef77197e0 app/l86.cpp --- a/app/l86.cpp Mon Dec 04 14:48:01 2017 +0000 +++ b/app/l86.cpp Mon Dec 04 21:25:19 2017 +0000 @@ -33,16 +33,16 @@ strcpy(RMC_parsed.Message_ID,temp[0]); strcpy(RMC_parsed.UTC_Time,temp[1]); strcpy(RMC_parsed.Status,temp[2]); - //if(strcmp(RMC_parsed.Status,"A") == 0){ + if(strcmp(RMC_parsed.Status,"A") == 0){ strcpy(RMC_parsed.Latitude,temp[3]); strcpy(RMC_parsed.N_S_Indicator,temp[4]); strcpy(RMC_parsed.Longitude,temp[5]); strcpy(RMC_parsed.E_W_Indicator,temp[6]); strcpy(RMC_parsed.Speed_Over_Ground,temp[7]); strcpy(RMC_parsed.Course_Over_Ground,temp[8]); - //strcpy(RMC_parsed.Date,temp[9]); + strcpy(RMC_parsed.Date,temp[9]); strcpy(RMC_parsed.Mode,temp[10]); - //} + } return RMC_parsed; } @@ -68,8 +68,8 @@ /* Parse RMC_data struct into GPS data struct ready for sending over LoRa */ GPS_data Parse_RMC_data(RMC_data RMC_parsed){ GPS_data GPS_parsed; - char tempLat[11]; - char tempLong[12]; + char tempLat[11]="0"; + char tempLong[12]="0"; if(strcmp(RMC_parsed.Status,"A") == 0){ strcpy(GPS_parsed.UTC_Time,RMC_parsed.UTC_Time); if (strcmp(RMC_parsed.N_S_Indicator, "N") == 0){ @@ -90,7 +90,7 @@ strcpy(GPS_parsed.Longitude, tempLong); strcpy(GPS_parsed.Speed_Over_Ground,RMC_parsed.Speed_Over_Ground); strcpy(GPS_parsed.Course_Over_Ground,RMC_parsed.Course_Over_Ground); - //strcpy(GPS_parsed.Date,RMC_parsed.Date); + strcpy(GPS_parsed.Date,RMC_parsed.Date); strcpy(GPS_parsed.Valid,RMC_parsed.Status); } else { @@ -99,7 +99,7 @@ strcpy(GPS_parsed.Longitude,"+00000.0000"); strcpy(GPS_parsed.Speed_Over_Ground,"0.00"); strcpy(GPS_parsed.Course_Over_Ground,"000.00"); - //strcpy(GPS_parsed.Date,RMC_parsed.Date); + strcpy(GPS_parsed.Date,"000000"); strcpy(GPS_parsed.Valid,RMC_parsed.Status); } return GPS_parsed; @@ -113,6 +113,6 @@ pc2.printf("Longitude: %s\r\n",GPS_data_print.Longitude); pc2.printf("Speed: %s\r\n",GPS_data_print.Speed_Over_Ground); pc2.printf("Course: %s\r\n",GPS_data_print.Course_Over_Ground); - //pc2.printf("Date: %s\r\n",GPS_data_print.Date); + pc2.printf("Date: %s\r\n",GPS_data_print.Date); }
diff -r 9f1dd1497e9a -r 539ef77197e0 app/l86.hpp --- a/app/l86.hpp Mon Dec 04 14:48:01 2017 +0000 +++ b/app/l86.hpp Mon Dec 04 21:25:19 2017 +0000 @@ -11,9 +11,9 @@ #define DEBUGGER // uncomment to output serial data to PC /* PIN DEFINITIONS */ -// #define RESET_PIN PB_14 -// #define FORCE_ON_PIN PB_15 -// #define ONEPPS_PIN PA_8 +#define RESET_PIN PB_14 +#define FORCE_ON_PIN PB_15 +#define ONEPPS_PIN PA_8 #define GPS_RX PA_10 #define GPS_TX PA_9 #define PC_RX PC_5 @@ -21,7 +21,7 @@ #define GPS_STATUS_LED LED1 /* PMTK MMESSAGE DEFINITIONS */ -#define MAX_NMEA_LENGTH 328 // maximum length of an NMEA sentence +#define MAX_NMEA_LENGTH 82 // maximum length of an NMEA sentence #define PMTK_SET_NMEA_OUTPUT_RMC "$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29\r\n" #define PMTK_SET_UPDATE_F_2HZ "$PMTK300,500,0,0,0,0*28\r\n" #define PMTK_COLD_RESTART "$PMTK104*37\r\n" @@ -61,7 +61,7 @@ char Longitude[12]; char Speed_Over_Ground[5]; char Course_Over_Ground[7]; - //char Date[7]; + char Date[7]; char Valid[2]; }GPS_data;
diff -r 9f1dd1497e9a -r 539ef77197e0 app/main.cpp --- a/app/main.cpp Mon Dec 04 14:48:01 2017 +0000 +++ b/app/main.cpp Mon Dec 04 21:25:19 2017 +0000 @@ -34,10 +34,10 @@ // #ifdef DEBUGGER -// RawSerial pc(PC_TX, PC_RX); // USART2 +RawSerial pc(USBTX, USBRX); // USART2 // #endif -Serial gps(GPS_TX, GPS_RX); // USART1 +RawSerial gps(GPS_TX, GPS_RX); // USART1 // DigitalOut Reset(RESET_PIN); // DigitalOut Force_on(FORCE_ON_PIN); @@ -48,111 +48,143 @@ GPS_data GPS_parse; volatile int Char_index = 0; // index for char array char Rx_data[MAX_NMEA_LENGTH] = "0"; // char array to store received bytes -char tx_line[82]; // uint8_t valid = 0; -volatile uint8_t GPS_data_ready = 0; +//volatile uint8_t GPS_data_ready = 0; volatile uint8_t sending = 0; -volatile bool keepOut = false; +volatile bool timerset = false; -uint8_t miss_count =0; +volatile bool firstfix = false; + +volatile bool keepOut = false; Ticker LoRaSend_timer; -void flushSerialBuffer(void) { char char1 = 0; while (gps.readable()) { char1 = gps.getc(); } return; } +//void flushSerialBuffer(void) { char char1 = 0; while (gps.readable()) { char1 = gps.getc(); } return; } + +void LoRaSend(){ + //GPS_status = !GPS_status; + //if (keepOut) + // return; + __disable_irq();//NVIC_DisableIRQ(USART1_IRQn); + //if(GPS_data_ready == 1){ + // pc.putc('1'); + sending = 1; + // pc.putc('3'); + char AppDatas[APPDATA_SIZE]; + // pc.putc('4'); + strcpy(AppDatas, GPS_parse.Latitude); + // pc.putc('5'); + strcat(AppDatas, ","); + // pc.putc('6'); + strcat(AppDatas, GPS_parse.Longitude); + // pc.putc('7'); + strcat(AppDatas, ","); + // pc.putc('8'); + strcat(AppDatas, GPS_parse.Course_Over_Ground); + // pc.putc('9'); + strcat(AppDatas, ","); + // pc.putc('a'); + strcat(AppDatas, GPS_parse.Speed_Over_Ground); + // pc.putc('b'); + strcat(AppDatas, ","); + //strcat(AppDatas, GPS_parse.Date); + //strcat(AppDatas, ","); + // pc.putc('c'); + strcat(AppDatas, GPS_parse.UTC_Time); + // pc.putc('d'); + strcat(AppDatas, ","); + // pc.putc('e'); + strcat(AppDatas, GPS_parse.Valid); + // pc.putc('f'); + // McpsReq_t mcpsReq; + // pc.putc('g'); + // uint8_t AppPort = 3; + // pc.putc('h'); + // mcpsReq.Type = MCPS_UNCONFIRMED; + // pc.putc('i'); + // mcpsReq.Req.Unconfirmed.fPort = AppPort; + // pc.putc('j'); + // mcpsReq.Req.Unconfirmed.fBuffer = AppDatas; + // pc.putc('k'); + // mcpsReq.Req.Unconfirmed.fBufferSize = APPDATA_SIZE+2; + // pc.putc('l'); + // mcpsReq.Req.Unconfirmed.Datarate = DR_5; + // status = !status; + //GPS_status = !GPS_status; + // pc.putc('m'); + // LoRaMacMcpsRequest( &mcpsReq ); + // GPS_data_ready = 0; + // Ready_for_more = 1; + //} + sending = 0; + __enable_irq();//NVIC_EnableIRQ(USART1_IRQn); + pc.putc('N'); +} + void gps_receive(void) { // Note: you need to actually read from the serial to clear the RX interrupt - //while(gps.readable()) { - GPS_status= !GPS_status; - if(sending==1){ - flushSerialBuffer(); - return; - } - if(gps.readable()){ - __disable_irq(); - keepOut = true; + __disable_irq(); + keepOut = true; // + while(gps.readable()) { char incoming = gps.getc(); // #ifdef DEBUGGER // pc.putc(incoming); // #endif Rx_data[Char_index] = incoming; - if((Rx_data[Char_index] == '\n')) - { // Received the end of an NMEA scentence - if((strncmp(GPRMC_Tag,Rx_data,(sizeof(GPRMC_Tag)-1)) == 0) || (strncmp(GNRMC_Tag,Rx_data,(sizeof(GNRMC_Tag)-1)) == 0)) - { + if((Rx_data[Char_index] == '\n')){ // Received the end of an NMEA scentence + if((strncmp(GPRMC_Tag,Rx_data,(sizeof(GPRMC_Tag)-1)) == 0) || (strncmp(GNRMC_Tag,Rx_data,(sizeof(GNRMC_Tag)-1)) == 0)){ RMC = Parse_RMC_sentence(Rx_data); - if(strcmp(RMC.Status, "A") == 0) - { - // GPS_status = 0; // Turn status LED off + if(strcmp(RMC.Status, "A") == 0){ + // valid = 1; + // GPS_status = 0; // Turn status LED off + // GPS_parse = Parse_RMC_data(RMC); // Parse into format suitable for Tom (Dinghy_RaceTrak software) + // Call function to send using LoRa module + // LoRaSend(); + // pc.putc('O'); + if(timerset == false) + firstfix = true; + /* + if(firstfix == false) // + { // + //LoRaSend_timer.attach(&LoRaSend, 1.0); // + firstfix = true; // + } */ // } - else - { + else{ // GPS_status = 1; + // Send "No GPS fix" over LoRa? } - if (sending) - { - Char_index = 0; - memset(Rx_data,0,sizeof(Rx_data)); - __enable_irq(); - keepOut = false; - return; - } - GPS_data_ready = 0; + ///* + if (sending) // + { // + Char_index = 0; // + memset(Rx_data,0,sizeof(Rx_data)); // + __enable_irq(); // + keepOut = false; // + return; // + } //*/ // + GPS_status=!GPS_status; + // delete this line + //GPS_data_ready = 0; GPS_parse = Parse_RMC_data(RMC); // Parse into format suitable for Tom (Dinghy_RaceTrak software) - GPS_data_ready = 1; + //GPS_data_ready = 1; + + } Char_index = 0; memset(Rx_data,0,sizeof(Rx_data)); - } else Char_index++; } keepOut = false; __enable_irq(); + // put first fix code here if above doesn't work return; -} - -void LoRaSend(){ - //GPS_status = !GPS_status; - if (keepOut) - return; - __disable_irq();//NVIC_DisableIRQ(USART1_IRQn); - if(GPS_data_ready == 1){ - sending = 1; - char AppDatas[APPDATA_SIZE]; - strcpy(AppDatas, GPS_parse.Latitude); - strcat(AppDatas, ","); - strcat(AppDatas, GPS_parse.Longitude); - strcat(AppDatas, ","); - strcat(AppDatas, GPS_parse.Course_Over_Ground); - strcat(AppDatas, ","); - strcat(AppDatas, GPS_parse.Speed_Over_Ground); - strcat(AppDatas, ","); - //strcat(AppDatas, GPS_parse.Date); - //strcat(AppDatas, ","); - strcat(AppDatas, GPS_parse.UTC_Time); - strcat(AppDatas, ","); - strcat(AppDatas, GPS_parse.Valid); - - McpsReq_t mcpsReq; - - uint8_t AppPort = 3; - mcpsReq.Type = MCPS_UNCONFIRMED; - mcpsReq.Req.Unconfirmed.fPort = AppPort; - mcpsReq.Req.Unconfirmed.fBuffer = AppDatas; - mcpsReq.Req.Unconfirmed.fBufferSize = APPDATA_SIZE+2; - mcpsReq.Req.Unconfirmed.Datarate = DR_5; - // status = !status; - //GPS_status = !GPS_status; - LoRaMacMcpsRequest( &mcpsReq ); - GPS_data_ready = 0; - // Ready_for_more = 1; - } - sending = 0; - __enable_irq();//NVIC_EnableIRQ(USART1_IRQn); + // store chars into a string then process into LAT, LONG, SOG, COG & DATETIME, VALID/INVLAID } void McpsConfirm( McpsConfirm_t *mcpsConfirm ) @@ -230,7 +262,7 @@ //Sendframe McpsReq_t mcpsReq; - + uint8_t AppPort = 3; mcpsReq.Type = MCPS_UNCONFIRMED; mcpsReq.Req.Unconfirmed.fPort = AppPort; @@ -239,7 +271,6 @@ mcpsReq.Req.Unconfirmed.Datarate = DR_5; LoRaMacMcpsRequest( &mcpsReq );*/ - GPS_status = 1; gps.attach(&gps_receive, Serial::RxIrq); gps.printf(PMTK_SET_NMEA_OUTPUT_RMC); // Only output RMC and GPTXT @@ -253,9 +284,16 @@ gps.printf(PMTK_SET_NMEA_OUTPUT_RMC); // Only output RMC and GPTXT wait(1.0); gps.printf(PMTK_SET_UPDATE_F_2HZ); // Set update Frequency to 2Hz - LoRaSend_timer.attach(&LoRaSend, 1.0); + //LoRaSend_timer.attach(&LoRaSend, 1.0); while(1){ - //Print_RMC_data(&RMC); - //wait(0.5); + if(sending==0){ + Print_GPS_data(GPS_parse); + } + if(firstfix){ + LoRaSend_timer.attach(&LoRaSend, 1.0); + firstfix = false; + timerset = true; + } + wait(0.5); } } \ No newline at end of file