Skip to content

Commit 835ddc3

Browse files
committed
Reorder functions, add comments
1 parent a2c8a7e commit 835ddc3

File tree

2 files changed

+45
-54
lines changed

2 files changed

+45
-54
lines changed

src/SparkFun_Unicore_GNSS_Arduino_Library.cpp

Lines changed: 41 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ bool UM980::updateOnce()
223223
return (false);
224224
}
225225

226-
// Mode
226+
// Mode commands
227227
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
228228

229229
// Directly set a mode: setMode("ROVER");
@@ -302,7 +302,7 @@ bool UM980::setModeRoverMow()
302302
// be supported on UM980.
303303
}
304304

305-
// Config
305+
// Config commands
306306
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
307307

308308
// Configure a given COM port to a given baud
@@ -354,7 +354,7 @@ bool UM980::configurePPS(const char *configString)
354354
return (sendCommand(command));
355355
}
356356

357-
// Mask
357+
// Mask commands
358358
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
359359

360360
// Available constellations: GPS, BDS, GLO, GAL, QZSS, IRNSS
@@ -441,7 +441,7 @@ bool UM980::disableSystem(const char *systemName)
441441
return (sendCommand(command));
442442
}
443443

444-
// Data Output
444+
// Data Output commands
445445
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
446446

447447
// Set the output rate of a given message on a given COM port/Use
@@ -503,7 +503,7 @@ bool UM980::setRTCMMessage(const char *sentenceType, float outputRate)
503503
return (sendCommand(command));
504504
}
505505

506-
// Other
506+
// Other commands
507507
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
508508

509509
// Disables all messages on this port
@@ -543,7 +543,8 @@ bool UM980::saveConfiguration()
543543
return (sendCommand("SAVECONFIG"));
544544
}
545545

546-
// Lower level interface functions
546+
//Abstraction of the serial interface
547+
//Useful if we ever need to support SoftwareSerial
547548
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
548549

549550
// Enable printfs to various endpoints
@@ -573,8 +574,41 @@ void UM980::debugPrintf(const char *format, ...)
573574
va_end(args2);
574575
}
575576

577+
// Discards any characters sitting in RX buffer
578+
void UM980::clearBuffer()
579+
{
580+
while (serialAvailable())
581+
serialRead();
582+
}
576583

577-
//Query and send commands
584+
uint16_t UM980::serialAvailable()
585+
{
586+
if (_hwSerialPort != nullptr)
587+
{
588+
return (_hwSerialPort->available());
589+
}
590+
return (0);
591+
}
592+
593+
uint8_t UM980::serialRead()
594+
{
595+
if (_hwSerialPort != nullptr)
596+
{
597+
return (_hwSerialPort->read());
598+
}
599+
return (0);
600+
}
601+
602+
void UM980::serialPrintln(const char *command)
603+
{
604+
if (_hwSerialPort != nullptr)
605+
{
606+
_hwSerialPort->println(command);
607+
}
608+
}
609+
610+
611+
//Query and send functionality
578612
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
579613

580614
// Send a command string (ie 'MODE ROVER') to the UM980
@@ -745,44 +779,6 @@ Um980Result UM980::checkCRC(char *response)
745779
return (UM980_RESULT_OK);
746780
}
747781

748-
749-
//Abstraction of the serial interface
750-
//Useful if we ever need to support SoftwareSerial
751-
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
752-
753-
// Discards any characters sitting in RX buffer
754-
void UM980::clearBuffer()
755-
{
756-
while (serialAvailable())
757-
serialRead();
758-
}
759-
760-
uint16_t UM980::serialAvailable()
761-
{
762-
if (_hwSerialPort != nullptr)
763-
{
764-
return (_hwSerialPort->available());
765-
}
766-
return (0);
767-
}
768-
769-
uint8_t UM980::serialRead()
770-
{
771-
if (_hwSerialPort != nullptr)
772-
{
773-
return (_hwSerialPort->read());
774-
}
775-
return (0);
776-
}
777-
778-
void UM980::serialPrintln(const char *command)
779-
{
780-
if (_hwSerialPort != nullptr)
781-
{
782-
_hwSerialPort->println(command);
783-
}
784-
}
785-
786782
//Main Unicore handler and RAM inits
787783
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
788784

src/SparkFun_Unicore_GNSS_Arduino_Library.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class UM980
144144
Print *_debugPort = nullptr; // The stream to send debug messages to if enabled. Usually Serial.
145145

146146
void debugPrintf(const char *format, ...);
147-
147+
148148
protected:
149149
HardwareSerial *_hwSerialPort = nullptr;
150150

@@ -213,7 +213,6 @@ class UM980
213213
bool sendCommand(const char *command, uint16_t maxWaitMs = 1500);
214214
Um980Result sendQuery(const char *command, char *response, uint16_t *maxResponseLength, uint16_t maxWaitMs = 1500);
215215
Um980Result sendQuery(const char *command, char *response, int *maxResponseLength, uint16_t maxWaitMs = 1500);
216-
217216
Um980Result sendString(const char *command, uint16_t maxWaitMs = 1500);
218217
Um980Result checkCRC(char *response);
219218

@@ -257,17 +256,13 @@ class UM980
257256
void unicoreHandler(uint8_t *data, uint16_t length);
258257

259258
bool initBestnav(uint8_t rate = 1);
260-
UNICORE_BESTNAV_t *packetBESTNAV =
261-
nullptr; // Pointer to struct. RAM will be allocated for this if/when necessary
259+
UNICORE_BESTNAV_t *packetBESTNAV = nullptr;
262260

263261
bool initBestnavXyz(uint8_t rate = 1);
264-
UNICORE_BESTNAVXYZ_t *packetBESTNAVXYZ =
265-
nullptr; // Pointer to struct. RAM will be allocated for this if/when necessary
262+
UNICORE_BESTNAVXYZ_t *packetBESTNAVXYZ = nullptr;
266263

267264
bool initRectime(uint8_t rate = 1);
268-
UNICORE_RECTIME_t *packetRECTIME =
269-
nullptr; // Pointer to struct. RAM will be allocated for this if/when necessary
270-
265+
UNICORE_RECTIME_t *packetRECTIME = nullptr;
271266
};
272267

273268
#endif //_SPARKFUN_UNICORE_GNSS_ARDUINO_LIBRARY_H

0 commit comments

Comments
 (0)