From 352ffdd326f89e511566666969467dfc1a8f8479 Mon Sep 17 00:00:00 2001 From: Kragg Malak Date: Sat, 16 Dec 2023 23:43:50 -0700 Subject: [PATCH 1/5] FEATURE: Displays all the queue there's room for on the screen in NMEA passthrough, tracking real estate used. Always prints available text buffer and two self-genned messages. Prints whatever else in the queue (from start) there's room for. --- esp32_marauder/GpsInterface.cpp | 18 +++--- esp32_marauder/GpsInterface.h | 27 ++++++-- esp32_marauder/WiFiScan.cpp | 105 ++++++++++++++++++++++++-------- 3 files changed, 112 insertions(+), 38 deletions(-) diff --git a/esp32_marauder/GpsInterface.cpp b/esp32_marauder/GpsInterface.cpp index f86055257..9194a97b6 100644 --- a/esp32_marauder/GpsInterface.cpp +++ b/esp32_marauder/GpsInterface.cpp @@ -102,8 +102,8 @@ void GpsInterface::enqueue(MicroNMEA& nmea){ if(this->text_in){ int size=text_in->size(); if(size){ - #ifdef GPS_TEXT_MAXCOPIES - if(this->text_cycles>=GPS_TEXT_MAXCOPIES){ + #ifdef GPS_TEXT_MAXCYCLES + if(this->text_cycles>=GPS_TEXT_MAXCYCLES){ #else if(this->text_cycles){ #endif @@ -158,8 +158,8 @@ void GpsInterface::enqueue(MicroNMEA& nmea){ #else if(size>=5){ #endif - #ifdef GPS_TEXT_MAXCOPIES - if(this->text_cycles>=GPS_TEXT_MAXCOPIES){ + #ifdef GPS_TEXT_MAXCYCLES + if(this->text_cycles>=GPS_TEXT_MAXCYCLES){ #else if(this->text_cycles){ #endif @@ -198,8 +198,8 @@ void GpsInterface::enqueue(MicroNMEA& nmea){ if(this->queue_enabled_flag){ if(!this->queue) this->new_queue(); if(enqueue){ - String enqueue_me=nmea_sentence.c_str(); - this->queue->add(enqueue_me); + nmea_sentence_t line = { unparsed, msg_id, nmea_sentence.c_str() }; + this->queue->add(line); } } else @@ -234,12 +234,12 @@ bool GpsInterface::queue_enabled(){ return this->queue_enabled_flag; } -LinkedList* GpsInterface::get_queue(){ +LinkedList* GpsInterface::get_queue(){ return this->queue; } void GpsInterface::new_queue(){ - this->queue=new LinkedList; + this->queue=new LinkedList; } void GpsInterface::flush_queue(){ @@ -250,7 +250,7 @@ void GpsInterface::flush_queue(){ void GpsInterface::flush_queue_nmea(){ if(this->queue){ if(this->queue->size()){ - LinkedList *delme=this->queue; + LinkedList *delme=this->queue; this->new_queue(); delete delme; } diff --git a/esp32_marauder/GpsInterface.h b/esp32_marauder/GpsInterface.h index ae6f7ee46..98fd768e5 100644 --- a/esp32_marauder/GpsInterface.h +++ b/esp32_marauder/GpsInterface.h @@ -10,7 +10,26 @@ #include "configs.h" //#define GPS_TEXT_MAXLINES 5 //default:5 lines in the buffer maximum -//#define GPS_TEXT_MAXCOPIES 1 //default:any nonzero number resets, i.e. one copy +//#define GPS_TEXT_MAXCYCLES 1 //default:1 + +//#define GPS_NMEA_SCRNLINES TEXT_HEIGHT //default: defined TEXT_HEIGHT from configs.h +//#define GPS_NMEA_SCRNWRAP true //default:true, except on MARAUDER_MINI where false + +#ifdef MARAUDER_MINI + #ifndef GPS_NMEA_SCRNWRAP + #define GPS_NMEA_SCRNWRAP false + #endif +#else + #ifndef GPS_NMEA_SCRNWRAP + #define GPS_NMEA_SCRNWRAP true + #endif +#endif + +struct nmea_sentence_t { + bool unparsed; + String type; + String sentence; +}; void gps_nmea_notimp(MicroNMEA& nmea); @@ -38,7 +57,7 @@ class GpsInterface { void setType(String t); void enqueue(MicroNMEA& nmea); - LinkedList* get_queue(); + LinkedList* get_queue(); void flush_queue(); void flush_text(); void new_queue(); @@ -84,9 +103,9 @@ class GpsInterface { type_t type_flag = GPSTYPE_NATIVE; bool queue_enabled_flag=0; - LinkedList *queue=NULL; + LinkedList *queue=NULL; - int text_cycles=0; + unsigned int text_cycles=0; LinkedList *text_in=NULL; LinkedList *text=NULL; diff --git a/esp32_marauder/WiFiScan.cpp b/esp32_marauder/WiFiScan.cpp index 07a5b9676..c18ac883b 100644 --- a/esp32_marauder/WiFiScan.cpp +++ b/esp32_marauder/WiFiScan.cpp @@ -1204,9 +1204,12 @@ void WiFiScan::RunGPSInfo() { void WiFiScan::RunGPSNmea() { #ifdef HAS_GPS - LinkedList *buffer=gps_obj.get_queue(); + LinkedList *buffer=gps_obj.get_queue(); bool queue_enabled=gps_obj.queue_enabled(); + String gxgga = gps_obj.generateGXgga(); + String gxrmc = gps_obj.generateGXrmc(); + if(!buffer||!queue_enabled) gps_obj.flush_queue(); #ifndef HAS_SCREEN @@ -1214,29 +1217,54 @@ void WiFiScan::RunGPSNmea() { gps_obj.flush_text(); #else // Get screen position ready - display_obj.tft.setTextWrap(true); + int offset=100; + if((SCREEN_HEIGHT / 3)((TFT_HEIGHT-offset-BOT_FIXED_AREA)/10)) + lines=(TFT_HEIGHT-offset-BOT_FIXED_AREA)/10; + #endif String text=gps_obj.getText(); if(queue_enabled){ - if(gps_obj.getTextQueueSize()>0) - display_obj.tft.print(gps_obj.getTextQueue()); + int queue=gps_obj.getTextQueueSize(); + if(queue>0){ + display_obj.tft.println(gps_obj.getTextQueue()); + lines-=queue; //used lines for text display + } else - if(text != "") display_obj.tft.print(text); + if(text != ""){ + display_obj.tft.println(text); + lines--; + } } else - if(text != "") display_obj.tft.print(text); + if(text != ""){ + display_obj.tft.println(text); + lines--; + } - //This one doesn't contain self-genned GxGGA or GxRMC, nor does it contain GxTXT, processed above - String display_nmea_sentence=gps_obj.getNmeaNotparsed(); + #if GPS_NMEA_SCRNWRAP + lines-=((gxgga.length()-1)/STANDARD_FONT_CHAR_LIMIT) + 1; + lines-=((gxrmc.length()-1)/STANDARD_FONT_CHAR_LIMIT) + 1; + display_obj.tft.setTextWrap(GPS_NMEA_SCRNWRAP); + #else + lines-=2; //two self-genned messages + #endif #endif if(buffer && queue_enabled){ @@ -1244,15 +1272,35 @@ void WiFiScan::RunGPSNmea() { if(size){ gps_obj.new_queue(); for(int i=0;iget(i)); + nmea_sentence_t line=buffer->get(i); + Serial.println(line.sentence); + + #ifdef HAS_SCREEN + if(lines>0){ + if(line.unparsed){ + if(line.type != "" && line.type != "TXT" && line.type != "GGA" && line.type != "RMC"){ + int length=line.sentence.length(); + if(length){ + #if GPS_NMEA_SCRNWRAP + if((((length-1)/STANDARD_FONT_CHAR_LIMIT) + 1)<=lines){ + #endif + display_obj.tft.println(line.sentence); + #if GPS_NMEA_SCRNWRAP + lines-=((length-1)/STANDARD_FONT_CHAR_LIMIT) + 1; + #else + lines--; + #endif + #if GPS_NMEA_SCRNWRAP + } + #endif + } + } + } + } + #endif } delete buffer; } - - #ifdef HAS_SCREEN - //This matches the else block, but could later display more of the queue... - display_obj.tft.print(display_nmea_sentence); - #endif } else { static String old_nmea_sentence=""; String nmea_sentence=gps_obj.getNmeaNotimp(); @@ -1263,17 +1311,24 @@ void WiFiScan::RunGPSNmea() { } #ifdef HAS_SCREEN - display_obj.tft.print(display_nmea_sentence); + if(lines>0){ + String display_nmea_sentence=gps_obj.getNmeaNotparsed(); + int length=display_nmea_sentence.length(); + if(length) + #if GPS_NMEA_SCRNWRAP + if((((length-1)/STANDARD_FONT_CHAR_LIMIT) + 1)<=lines) + #endif + display_obj.tft.println(display_nmea_sentence); + } #endif } - String gxgga = gps_obj.generateGXgga(); - String gxrmc = gps_obj.generateGXrmc(); - #ifdef HAS_SCREEN - display_obj.tft.print(gxgga); - display_obj.tft.print(gxrmc); - display_obj.tft.setTextWrap(false); + display_obj.tft.println(gxgga); + display_obj.tft.println(gxrmc); + #if GPS_NMEA_SCRNWRAP + display_obj.tft.setTextWrap(false); + #endif #endif gps_obj.sendSentence(Serial, gxgga.c_str()); From deafe63e9445b83e8efcf7e2b873664914ce4374 Mon Sep 17 00:00:00 2001 From: Kragg Malak Date: Sat, 16 Dec 2023 23:45:22 -0700 Subject: [PATCH 2/5] BUG FIX: Queue overflow due to no stopping queue on exit from GPS menu fixed. Now calls stopscan. --- esp32_marauder/MenuFunctions.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/esp32_marauder/MenuFunctions.cpp b/esp32_marauder/MenuFunctions.cpp index c7279531f..d9739c33e 100644 --- a/esp32_marauder/MenuFunctions.cpp +++ b/esp32_marauder/MenuFunctions.cpp @@ -1688,6 +1688,7 @@ void MenuFunctions::RunSetup() gpsInfoMenu.parentMenu = &deviceMenu; this->addNodes(&gpsInfoMenu, text09, TFT_LIGHTGREY, NULL, 0, [this]() { wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF; + wifi_scan_obj.StartScan(WIFI_SCAN_OFF); this->changeMenu(gpsInfoMenu.parentMenu); }); } From bc88a1f94aed794e53f231d8240894d29b09621e Mon Sep 17 00:00:00 2001 From: Kragg Malak Date: Sat, 16 Dec 2023 23:46:10 -0700 Subject: [PATCH 3/5] SAFETY MECHANISM: If scan off, yet queue enabled for any reason, disable it. Prevents prior bug. --- esp32_marauder/WiFiScan.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/esp32_marauder/WiFiScan.cpp b/esp32_marauder/WiFiScan.cpp index c18ac883b..9e863a4e1 100644 --- a/esp32_marauder/WiFiScan.cpp +++ b/esp32_marauder/WiFiScan.cpp @@ -4825,4 +4825,7 @@ void WiFiScan::main(uint32_t currentTime) packets_sent = 0; } } + else if ((currentScanMode == WIFI_SCAN_OFF)) + if(gps_obj.queue_enabled()) + gps_obj.disable_queue(); } From 875f06c7d7760af8e6ed951d04dce3842ffc671b Mon Sep 17 00:00:00 2001 From: Kragg Malak Date: Sun, 17 Dec 2023 00:21:24 -0700 Subject: [PATCH 4/5] Resolve Build Test Error: gps_obj now only referenced inside appropriate #ifdef HAS_GPS block. --- esp32_marauder/WiFiScan.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/esp32_marauder/WiFiScan.cpp b/esp32_marauder/WiFiScan.cpp index 9e863a4e1..092fa01c0 100644 --- a/esp32_marauder/WiFiScan.cpp +++ b/esp32_marauder/WiFiScan.cpp @@ -4825,7 +4825,9 @@ void WiFiScan::main(uint32_t currentTime) packets_sent = 0; } } - else if ((currentScanMode == WIFI_SCAN_OFF)) - if(gps_obj.queue_enabled()) - gps_obj.disable_queue(); + #ifdef HAS_GPS + else if ((currentScanMode == WIFI_SCAN_OFF)) + if(gps_obj.queue_enabled()) + gps_obj.disable_queue(); + #endif } From 9b13876f47c5a08d8056283e22ce06b281182162 Mon Sep 17 00:00:00 2001 From: Kragg Malak Date: Sun, 17 Dec 2023 18:37:20 -0700 Subject: [PATCH 5/5] ADDITIONAL SAFETY MEASURE: Queue limited at 30 sentences (configurable at build time). --- esp32_marauder/GpsInterface.cpp | 16 +++++++++++++++- esp32_marauder/GpsInterface.h | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/esp32_marauder/GpsInterface.cpp b/esp32_marauder/GpsInterface.cpp index 9194a97b6..5a87a5c31 100644 --- a/esp32_marauder/GpsInterface.cpp +++ b/esp32_marauder/GpsInterface.cpp @@ -196,11 +196,25 @@ void GpsInterface::enqueue(MicroNMEA& nmea){ this->notparsed_nmea_sentence = nmea_sentence.c_str(); if(this->queue_enabled_flag){ - if(!this->queue) this->new_queue(); if(enqueue){ nmea_sentence_t line = { unparsed, msg_id, nmea_sentence.c_str() }; + + if(this->queue){ + #ifdef GPS_NMEA_MAXQUEUE + if(this->queue->size()>=GPS_NMEA_MAXQUEUE) + #else + if(this->queue->size()>=30) + #endif + this->flush_queue(); + } + else + this->new_queue(); + this->queue->add(line); } + else + if(!this->queue) + this->new_queue(); } else this->flush_queue(); diff --git a/esp32_marauder/GpsInterface.h b/esp32_marauder/GpsInterface.h index 98fd768e5..5094d177a 100644 --- a/esp32_marauder/GpsInterface.h +++ b/esp32_marauder/GpsInterface.h @@ -14,6 +14,7 @@ //#define GPS_NMEA_SCRNLINES TEXT_HEIGHT //default: defined TEXT_HEIGHT from configs.h //#define GPS_NMEA_SCRNWRAP true //default:true, except on MARAUDER_MINI where false +//#define GPS_NMEA_MAXQUEUE 30 //default:30 messages max in queue #ifdef MARAUDER_MINI #ifndef GPS_NMEA_SCRNWRAP