@@ -40,13 +40,13 @@ bool configureUbloxModule()
4040#define OUTPUT_SETTING 14
4141#define INPUT_SETTING 12
4242
43- // UART1 will primarily be used to pass NMEA from ZED to ESP32 (eventually to cell phone)
43+ // UART1 will primarily be used to pass NMEA and UBX from ZED to ESP32 (eventually to cell phone)
4444 // but the phone can also provide RTCM data. So let's be sure to enable RTCM on UART1 input.
4545 // Protocol out = NMEA, protocol in = RTCM
4646 getPortSettings (COM_PORT_UART1); // Load the settingPayload with this port's settings
47- if (settingPayload[OUTPUT_SETTING] != (COM_TYPE_NMEA) || settingPayload[INPUT_SETTING] != COM_TYPE_RTCM3)
47+ if (settingPayload[OUTPUT_SETTING] != (COM_TYPE_NMEA | COM_TYPE_UBX ) || settingPayload[INPUT_SETTING] != COM_TYPE_RTCM3)
4848 {
49- response &= i2cGNSS.setPortOutput (COM_PORT_UART1, COM_TYPE_NMEA); // Set the UART1 to output NMEA
49+ response &= i2cGNSS.setPortOutput (COM_PORT_UART1, COM_TYPE_NMEA | COM_TYPE_UBX ); // Set the UART1 to output NMEA and UBX
5050 response &= i2cGNSS.setPortInput (COM_PORT_UART1, COM_TYPE_RTCM3); // Set the UART1 to input RTCM
5151 }
5252
@@ -66,9 +66,9 @@ bool configureUbloxModule()
6666 }
6767
6868 getPortSettings (COM_PORT_I2C); // Load the settingPayload with this port's settings
69- if (settingPayload[OUTPUT_SETTING] != COM_TYPE_UBX || settingPayload[INPUT_SETTING] != COM_TYPE_UBX)
69+ if (settingPayload[OUTPUT_SETTING] != ( COM_TYPE_UBX | COM_TYPE_NMEA) || settingPayload[INPUT_SETTING] != COM_TYPE_UBX)
7070 {
71- response &= i2cGNSS.setPortOutput (COM_PORT_I2C, COM_TYPE_UBX); // Set the I2C port to output UBX only (turn off NMEA noise)
71+ response &= i2cGNSS.setPortOutput (COM_PORT_I2C, COM_TYPE_UBX | COM_TYPE_NMEA ); // Set the I2C port to output UBX and NMEA
7272 response &= i2cGNSS.setPortInput (COM_PORT_I2C, COM_TYPE_UBX); // Set the I2C port to input UBX only
7373 }
7474
@@ -81,9 +81,8 @@ bool configureUbloxModule()
8181 response &= i2cGNSS.setPortInput (COM_PORT_USB, (COM_TYPE_UBX | COM_TYPE_NMEA | COM_TYPE_RTCM3)); // Set the USB port to everything
8282 }
8383
84- response &= enableNMEASentences (COM_PORT_UART1); // Make sure the appropriate NMEA sentences are enabled
85-
86- response &= enableRXMSentences (COM_PORT_I2C); // Make sure the appropriate RXM (RAXW and SFXBR) are enabled
84+ response &= enableMessages (COM_PORT_UART1, settings.broadcast ); // Make sure the appropriate messages are enabled
85+ response &= enableMessages (COM_PORT_I2C, settings.log ); // Make sure the appropriate messages are enabled
8786
8887 response &= i2cGNSS.setAutoPVT (true , false ); // Tell the GPS to "send" each solution, but do not update stale data when accessed
8988 response &= i2cGNSS.setAutoHPPOSLLH (true , false ); // Tell the GPS to "send" each high res solution, but do not update stale data when accessed
@@ -105,15 +104,14 @@ bool configureUbloxModule()
105104 return (false );
106105 }
107106
108- // Enable callbacks and logging as needed
109- if (settings.logRAWX == true )
110- {
111- i2cGNSS.logRXMRAWX (); // Enable RXM RAWX data logging
112- }
113- if (settings.logSFRBX == true )
114- {
115- i2cGNSS.logRXMSFRBX (); // Enable RXM SFRBX data logging
116- }
107+ // Based on current settings, update the logging options within the GNSS library
108+ i2cGNSS.logRXMRAWX (settings.log .rawx );
109+ i2cGNSS.logRXMSFRBX (settings.log .sfrbx );
110+
111+ if (logNMEAMessages () == true )
112+ i2cGNSS.setNMEALoggingMask (SFE_UBLOX_FILTER_NMEA_ALL); // Enable logging of all enabled NMEA messages
113+ else
114+ i2cGNSS.setNMEALoggingMask (0 ); // Disable logging of all enabled NMEA messages
117115
118116 // Check rover switch and configure module accordingly
119117 // When switch is set to '1' = BASE, pin will be shorted to ground
@@ -143,57 +141,27 @@ bool configureUbloxModule()
143141 return (response);
144142}
145143
146- // Enable the RAWX and SFRBX message based on user's settings, on a given com port
147- bool enableRXMSentences (uint8_t portType)
144+ // Enable the NMEA/UBX messages, based on given log or broadcast settings, for a given port
145+ bool enableMessages (uint8_t portType, gnssMessages messageSetting )
148146{
149147 bool response = true ;
150-
151- if (settings.logRAWX == true )
152- {
153- if (getRAWXSettings (portType) != 1 )
154- response &= i2cGNSS.enableMessage (UBX_CLASS_RXM, UBX_RXM_RAWX, portType);
155- }
156- else if (settings.logRAWX == false )
157- {
158- if (getRAWXSettings (portType) != 0 )
159- response &= i2cGNSS.disableMessage (UBX_CLASS_RXM, UBX_RXM_RAWX, portType);
160- }
161-
162- if (settings.logSFRBX == true )
163- {
164- if (getSFRBXSettings (portType) != 1 )
165- response &= i2cGNSS.enableMessage (UBX_CLASS_RXM, UBX_RXM_SFRBX, portType);
166- }
167- else if (settings.logSFRBX == false )
168- {
169- if (getSFRBXSettings (portType) != 0 )
170- response &= i2cGNSS.disableMessage (UBX_CLASS_RXM, UBX_RXM_SFRBX, portType);
171- }
172-
173- return (response);
174- }
175-
176- // Enable the NMEA messages, based on user's settings, on a given com port
177- bool enableNMEASentences (uint8_t portType)
178- {
179- bool response = true ;
180- if (settings.outputSentenceGGA == true )
148+ if (messageSetting.gga == true )
181149 {
182150 if (getNMEASettings (UBX_NMEA_GGA, portType) != 1 )
183151 response &= i2cGNSS.enableNMEAMessage (UBX_NMEA_GGA, portType);
184152 }
185- else if (settings. outputSentenceGGA == false )
153+ else if (messageSetting. gga == false )
186154 {
187155 if (getNMEASettings (UBX_NMEA_GGA, portType) != 0 )
188156 response &= i2cGNSS.disableNMEAMessage (UBX_NMEA_GGA, portType);
189157 }
190158
191- if (settings. outputSentenceGSA == true )
159+ if (messageSetting. gsa == true )
192160 {
193161 if (getNMEASettings (UBX_NMEA_GSA, portType) != 1 )
194162 response &= i2cGNSS.enableNMEAMessage (UBX_NMEA_GSA, portType);
195163 }
196- else if (settings. outputSentenceGSA == false )
164+ else if (messageSetting. gsa == false )
197165 {
198166 if (getNMEASettings (UBX_NMEA_GSA, portType) != 0 )
199167 response &= i2cGNSS.disableNMEAMessage (UBX_NMEA_GSA, portType);
@@ -203,39 +171,61 @@ bool enableNMEASentences(uint8_t portType)
203171 // If the update rate is >1Hz then this data can overcome the BT capabilities causing timeouts and lag
204172 // So we set the GSV sentence to 1Hz regardless of update rate
205173 uint16_t measurementFrequency = (uint16_t )getMeasurementFrequency (); // Force to int
206- if (settings. outputSentenceGSV == true )
174+ if (messageSetting. gsv == true )
207175 {
208176 if (getNMEASettings (UBX_NMEA_GSV, portType) != measurementFrequency)
209177 response &= i2cGNSS.enableNMEAMessage (UBX_NMEA_GSV, portType, measurementFrequency);
210178 }
211- else if (settings. outputSentenceGSV == false )
179+ else if (messageSetting. gsv == false )
212180 {
213181 if (getNMEASettings (UBX_NMEA_GSV, portType) != 0 )
214182 response &= i2cGNSS.disableNMEAMessage (UBX_NMEA_GSV, portType);
215183 }
216184
217- if (settings. outputSentenceRMC == true )
185+ if (messageSetting. rmc == true )
218186 {
219187 if (getNMEASettings (UBX_NMEA_RMC, portType) != 1 )
220188 response &= i2cGNSS.enableNMEAMessage (UBX_NMEA_RMC, portType);
221189 }
222- else if (settings. outputSentenceRMC == false )
190+ else if (messageSetting. rmc == false )
223191 {
224192 if (getNMEASettings (UBX_NMEA_RMC, portType) != 0 )
225193 response &= i2cGNSS.disableNMEAMessage (UBX_NMEA_RMC, portType);
226194 }
227195
228- if (settings. outputSentenceGST == true )
196+ if (messageSetting. gst == true )
229197 {
230198 if (getNMEASettings (UBX_NMEA_GST, portType) != 1 )
231199 response &= i2cGNSS.enableNMEAMessage (UBX_NMEA_GST, portType);
232200 }
233- else if (settings. outputSentenceGST == false )
201+ else if (messageSetting. gst == false )
234202 {
235203 if (getNMEASettings (UBX_NMEA_GST, portType) != 0 )
236204 response &= i2cGNSS.disableNMEAMessage (UBX_NMEA_GST, portType);
237205 }
238206
207+ if (messageSetting.rawx == true )
208+ {
209+ if (getRAWXSettings (portType) != 1 )
210+ response &= i2cGNSS.enableMessage (UBX_CLASS_RXM, UBX_RXM_RAWX, portType);
211+ }
212+ else if (messageSetting.rawx == false )
213+ {
214+ if (getRAWXSettings (portType) != 0 )
215+ response &= i2cGNSS.disableMessage (UBX_CLASS_RXM, UBX_RXM_RAWX, portType);
216+ }
217+
218+ if (messageSetting.sfrbx == true )
219+ {
220+ if (getSFRBXSettings (portType) != 1 )
221+ response &= i2cGNSS.enableMessage (UBX_CLASS_RXM, UBX_RXM_SFRBX, portType);
222+ }
223+ else if (messageSetting.sfrbx == false )
224+ {
225+ if (getSFRBXSettings (portType) != 0 )
226+ response &= i2cGNSS.disableMessage (UBX_CLASS_RXM, UBX_RXM_SFRBX, portType);
227+ }
228+
239229 return (response);
240230}
241231
@@ -586,3 +576,29 @@ bool createTestFile()
586576
587577 return (false );
588578}
579+
580+ // Returns true if any messages are enabled for logging
581+ bool logMessages ()
582+ {
583+ if (logNMEAMessages ())
584+ return (true );
585+ if (logUBXMessages ())
586+ return (true );
587+ return (false );
588+ }
589+
590+ // Returns true if any of the NMEA messages are enabled for logging
591+ bool logNMEAMessages ()
592+ {
593+ if (settings.log .gga == true || settings.log .gsa == true || settings.log .gsv == true || settings.log .rmc == true || settings.log .gst == true )
594+ return (true );
595+ return (false );
596+ }
597+
598+ // Returns true if any of the UBX messages are enabled for logging
599+ bool logUBXMessages ()
600+ {
601+ if (settings.log .rawx == true || settings.log .sfrbx == true )
602+ return (true );
603+ return (false );
604+ }
0 commit comments