Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit 9dcc2ff

Browse files
committed
Add port config. Add setNavFreq.
1 parent 9803472 commit 9dcc2ff

File tree

4 files changed

+145
-29
lines changed

4 files changed

+145
-29
lines changed

examples/Example3_GetPosition/Example3_GetPosition.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ void setup()
4545

4646
Wire.setClock(400000); //Increase I2C clock speed to 400kHz
4747

48+
49+
myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
50+
myGPS.setNavigationFrequency(4); //Set output to 4 times a second
51+
4852
/*long pos = myGPS.getPositionAccuracy();
4953
Serial.print("pos: ");
5054
Serial.println(pos);

examples/NEO-M8P-2/Example3_EnableRTCM/Example3_EnableRTCM.ino

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ void setup()
4949
while(Serial.available() == 0) ; //Wait for user to press a key
5050

5151
boolean response = true;
52-
response &= myGPS.enableRTCMmessage(UBX_RTCM_1005, UBX_RTCM_I2C_PORT, 1); //Enable message 1005 to output through I2C port, message every second
53-
response &= myGPS.enableRTCMmessage(UBX_RTCM_1077, UBX_RTCM_I2C_PORT, 1);
54-
response &= myGPS.enableRTCMmessage(UBX_RTCM_1087, UBX_RTCM_I2C_PORT, 1);
55-
response &= myGPS.enableRTCMmessage(UBX_RTCM_1230, UBX_RTCM_I2C_PORT, 10); //Enable message every 10 seconds
52+
response &= myGPS.enableRTCMmessage(UBX_RTCM_1005, COM_PORT_I2C, 1); //Enable message 1005 to output through I2C port, message every second
53+
response &= myGPS.enableRTCMmessage(UBX_RTCM_1077, COM_PORT_I2C, 1);
54+
response &= myGPS.enableRTCMmessage(UBX_RTCM_1087, COM_PORT_I2C, 1);
55+
response &= myGPS.enableRTCMmessage(UBX_RTCM_1230, COM_PORT_I2C, 10); //Enable message every 10 seconds
56+
57+
myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
5658

5759
if (response == true)
5860
{

src/SparkFun_Ublox_Arduino_Library.cpp

Lines changed: 110 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -590,16 +590,9 @@ boolean SFE_UBLOX_GPS::getSurveyStatus(uint16_t maxWait)
590590
return(false); //If command send fails then bail
591591

592592
//We got a response, now parse the bits into the svin structure
593-
svin.observationTime |= payloadCfg[8] << 8*0;
594-
svin.observationTime |= payloadCfg[9] << 8*1;
595-
svin.observationTime |= payloadCfg[10] << 8*2;
596-
svin.observationTime |= payloadCfg[11] << 8*3;
597-
598-
uint32_t tempFloat = 0;
599-
tempFloat |= payloadCfg[28] << 8*0;
600-
tempFloat |= payloadCfg[29] << 8*1;
601-
//tempFloat |= payloadCfg[30] << 8*2;
602-
//tempFloat |= payloadCfg[31] << 8*3;
593+
svin.observationTime = extractLong(8);
594+
595+
uint32_t tempFloat = extractInt(28);
603596
svin.meanAccuracy = tempFloat / 10000.0; //Convert 0.1mm to m
604597

605598
svin.valid = payloadCfg[36];
@@ -645,7 +638,7 @@ boolean SFE_UBLOX_GPS::disableRTCMmessage(uint8_t messageNumber, uint8_t portID,
645638
boolean SFE_UBLOX_GPS::setRTCMport(uint8_t portID, boolean enableRTCM3, uint16_t maxWait)
646639
{
647640
//Get the current config values for this port ID
648-
getPortSettings(portID);
641+
getPortSettings(portID); //This will load the payloadCfg array with current port settings
649642

650643
packetCfg.cls = UBX_CLASS_CFG;
651644
packetCfg.id = UBX_CFG_PRT;
@@ -656,14 +649,14 @@ boolean SFE_UBLOX_GPS::setRTCMport(uint8_t portID, boolean enableRTCM3, uint16_t
656649
for(uint8_t x = 0 ; x < packetCfg.len ; x++)
657650
packetCfg.payload[x] = 0;
658651

659-
//msg_payload is now loaded with current bytes. Change only the ones we need to
652+
//payloadCfg is now loaded with current bytes. Change only the ones we need to
660653
payloadCfg[13] |= (1 << 5); //InProtocolMask LSB - Set inRtcm3
661654
payloadCfg[15] |= (1 << 5); //OutProtocolMask LSB - Set outRtcm3
662655

663656
return ( sendCommand(packetCfg, maxWait) );
664657
}
665658

666-
//Returns the current protocol bits in the UBX-CFG-PRT command for a given port
659+
//Loads the payloadCfg array with the current protocol bits located the UBX-CFG-PRT register for a given port
667660
boolean SFE_UBLOX_GPS::getPortSettings(uint8_t portID, uint16_t maxWait)
668661
{
669662
packetCfg.cls = UBX_CLASS_CFG;
@@ -676,15 +669,112 @@ boolean SFE_UBLOX_GPS::getPortSettings(uint8_t portID, uint16_t maxWait)
676669
return ( sendCommand(packetCfg, maxWait) );
677670
}
678671

679-
//Given a spot, extract four bytes and build a long from the payload
672+
//Configure a given port to output UBX, NMEA, RTCM3 or a combination thereof
673+
//Port 0=I2c, 1=UART1, 2=UART2, 3=USB, 4=SPI
674+
//Bit:0 = UBX, :1=NMEA, :5=RTCM3
675+
boolean SFE_UBLOX_GPS::setPortOutput(uint8_t portID, uint8_t outStreamSettings, uint16_t maxWait)
676+
{
677+
//Get the current config values for this port ID
678+
getPortSettings(portID); //This will load the payloadCfg array with current port settings
679+
680+
//Yes, this is the depreciated way to do it but it's still supported on v27 so it
681+
//covers both ZED-F9P (v27) and SAM-M8Q (v18)
682+
683+
packetCfg.cls = UBX_CLASS_CFG;
684+
packetCfg.id = UBX_CFG_PRT;
685+
packetCfg.len = 20;
686+
packetCfg.startingSpot = 0;
687+
688+
//payloadCfg is now loaded with current bytes. Change only the ones we need to
689+
payloadCfg[14] = outStreamSettings; //OutProtocolMask LSB - Set outStream bits
690+
691+
return ( sendCommand(packetCfg, maxWait) );
692+
}
693+
694+
//Configure a given port to input UBX, NMEA, RTCM3 or a combination thereof
695+
//Port 0=I2c, 1=UART1, 2=UART2, 3=USB, 4=SPI
696+
//Bit:0 = UBX, :1=NMEA, :5=RTCM3
697+
boolean SFE_UBLOX_GPS::setPortInput(uint8_t portID, uint8_t inStreamSettings, uint16_t maxWait)
698+
{
699+
//Get the current config values for this port ID
700+
getPortSettings(portID); //This will load the payloadCfg array with current port settings
701+
702+
packetCfg.cls = UBX_CLASS_CFG;
703+
packetCfg.id = UBX_CFG_PRT;
704+
packetCfg.len = 20;
705+
packetCfg.startingSpot = 0;
706+
707+
//payloadCfg is now loaded with current bytes. Change only the ones we need to
708+
payloadCfg[12] = inStreamSettings; //InProtocolMask LSB - Set inStream bits
709+
710+
return ( sendCommand(packetCfg, maxWait) );
711+
}
712+
713+
//Configure a port to output UBX, NMEA, RTCM3 or a combination thereof
714+
boolean SFE_UBLOX_GPS::setI2COutput(uint8_t comSettings, uint16_t maxWait)
715+
{
716+
return(setPortOutput(COM_PORT_I2C, comSettings, maxWait));
717+
}
718+
boolean SFE_UBLOX_GPS::setUART1Output(uint8_t comSettings, uint16_t maxWait)
719+
{
720+
return(setPortOutput(COM_PORT_UART1, comSettings, maxWait));
721+
}
722+
boolean SFE_UBLOX_GPS::setUART2Output(uint8_t comSettings, uint16_t maxWait)
723+
{
724+
return(setPortOutput(COM_PORT_UART2, comSettings, maxWait));
725+
}
726+
boolean SFE_UBLOX_GPS::setUSBOutput(uint8_t comSettings, uint16_t maxWait)
727+
{
728+
return(setPortOutput(COM_PORT_USB, comSettings, maxWait));
729+
}
730+
boolean SFE_UBLOX_GPS::setSPIOutput(uint8_t comSettings, uint16_t maxWait)
731+
{
732+
return(setPortOutput(COM_PORT_SPI, comSettings, maxWait));
733+
}
734+
735+
//Set the rate at which the module will give us an updated navigation solution
736+
//Expects a number that is the updates per second. For example 1 = 1Hz, 2 = 2Hz, etc.
737+
//Max is 40Hz(?!)
738+
boolean SFE_UBLOX_GPS::setNavigationFrequency(uint8_t navFreq, uint16_t maxWait)
739+
{
740+
//if(updateRate > 40) updateRate = 40; //Not needed: module will correct out of bounds values
741+
742+
//Query the module for the latest lat/long
743+
packetCfg.cls = UBX_CLASS_CFG;
744+
packetCfg.id = UBX_CFG_RATE;
745+
packetCfg.len = 0;
746+
packetCfg.startingSpot = 0;
747+
748+
if(sendCommand(packetCfg, maxWait) == false) //This will load the payloadCfg array with current settings of the given register
749+
return(false); //If command send fails then bail
750+
751+
uint16_t measurementRate = 1000 / navFreq ;
752+
753+
//payloadCfg is now loaded with current bytes. Change only the ones we need to
754+
payloadCfg[0] = measurementRate & 0xFF; //measRate LSB
755+
payloadCfg[1] = measurementRate >> 8; //measRate MSB
756+
757+
return ( sendCommand(packetCfg, maxWait) );
758+
}
759+
760+
//Given a spot in the payload array, extract four bytes and build a long
680761
uint32_t SFE_UBLOX_GPS::extractLong(uint8_t spotToStart)
681762
{
682-
uint32_t pos = 0;
683-
pos |= (int32_t)payloadCfg[spotToStart + 0] << 8*0;
684-
pos |= (int32_t)payloadCfg[spotToStart + 1] << 8*1;
685-
pos |= (int32_t)payloadCfg[spotToStart + 2] << 8*2;
686-
pos |= (int32_t)payloadCfg[spotToStart + 3] << 8*3;
687-
return(pos);
763+
uint32_t val = 0;
764+
val |= (int32_t)payloadCfg[spotToStart + 0] << 8*0;
765+
val |= (int32_t)payloadCfg[spotToStart + 1] << 8*1;
766+
val |= (int32_t)payloadCfg[spotToStart + 2] << 8*2;
767+
val |= (int32_t)payloadCfg[spotToStart + 3] << 8*3;
768+
return(val);
769+
}
770+
771+
//Given a spot in the payload array, extract two bytes and build an int
772+
uint16_t SFE_UBLOX_GPS::extractInt(uint8_t spotToStart)
773+
{
774+
uint16_t val = 0;
775+
val |= (int16_t)payloadCfg[spotToStart + 0] << 8*0;
776+
val |= (int16_t)payloadCfg[spotToStart + 1] << 8*1;
777+
return(val);
688778
}
689779

690780
//Given a spot, extract byte the payload

src/SparkFun_Ublox_Arduino_Library.h

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,22 @@ const uint8_t UBX_RTCM_1005 = 0x05; //Stationary RTK reference ARP
113113
const uint8_t UBX_RTCM_1077 = 0x4D; //GPS MSM7
114114
const uint8_t UBX_RTCM_1087 = 0x57; //GLONASS MSM7
115115
const uint8_t UBX_RTCM_1230 = 0xE6; //GLONASS code-phase biases, set to once every 10 seconds
116-
const uint8_t UBX_RTCM_I2C_PORT = 0;
117-
const uint8_t UBX_RTCM_UART1_PORT = 1;
118-
const uint8_t UBX_RTCM_UART2_PORT = 2;
119-
const uint8_t UBX_RTCM_USB_PORT = 3;
120-
const uint8_t UBX_RTCM_SPI_PORT = 4;
121116

122117
const uint8_t UBX_ACK_NACK = 0x00;
123118
const uint8_t UBX_ACK_ACK = 0x01;
124119

120+
//The folloing consts are used to configure the various ports and streams for those ports. See -CFG-PRT.
121+
const uint8_t COM_PORT_I2C = 0;
122+
const uint8_t COM_PORT_UART1 = 1;
123+
const uint8_t COM_PORT_UART2 = 2;
124+
const uint8_t COM_PORT_USB = 3;
125+
const uint8_t COM_PORT_SPI = 4;
126+
127+
const uint8_t COM_TYPE_UBX = (1<<0);
128+
const uint8_t COM_TYPE_NMEA = (1<<1);
129+
const uint8_t COM_TYPE_RTCM3 = (1<<5);
130+
131+
125132
#define MAX_PAYLOAD_SIZE 64 //Some commands are larger than 64 bytes but this covers most
126133

127134
//-=-=-=-=- UBX binary specific variables
@@ -177,6 +184,18 @@ class SFE_UBLOX_GPS
177184
boolean getSurveyStatus(uint16_t maxWait); //Reads survey in status and sets the global variables
178185
boolean enableRTCMmessage(uint8_t messageNumber, uint8_t portID, uint8_t secondsBetweenMessages, uint16_t maxWait = 250); //Given a message number turns on a message ID for output over given PortID
179186
boolean disableRTCMmessage(uint8_t messageNumber, uint8_t portID, uint16_t maxWait = 250); //Turn off given RTCM message from a given port
187+
188+
boolean setPortOutput(uint8_t portID, uint8_t comSettings, uint16_t maxWait = 250); //Configure a given port to output UBX, NMEA, RTCM3 or a combination thereof
189+
boolean setPortInput(uint8_t portID, uint8_t comSettings, uint16_t maxWait = 250); //Configure a given port to input UBX, NMEA, RTCM3 or a combination thereof
190+
191+
boolean setI2COutput(uint8_t comSettings, uint16_t maxWait = 250); //Configure I2C port to output UBX, NMEA, RTCM3 or a combination thereof
192+
boolean setUART1Output(uint8_t comSettings, uint16_t maxWait = 250); //Configure UART1 port to output UBX, NMEA, RTCM3 or a combination thereof
193+
boolean setUART2Output(uint8_t comSettings, uint16_t maxWait = 250); //Configure UART2 port to output UBX, NMEA, RTCM3 or a combination thereof
194+
boolean setUSBOutput(uint8_t comSettings, uint16_t maxWait = 250); //Configure USB port to output UBX, NMEA, RTCM3 or a combination thereof
195+
boolean setSPIOutput(uint8_t comSettings, uint16_t maxWait = 250); //Configure SPI port to output UBX, NMEA, RTCM3 or a combination thereof
196+
197+
boolean setNavigationFrequency(uint8_t navFreq, uint16_t maxWait = 250); //Set the number of nav solutions sent per second
198+
180199
boolean setRTCMport(uint8_t portID, boolean enableRTCM3, uint16_t maxWait = 250); //Enable/Disable RTCM3 (both input and output) for a given port
181200

182201
boolean getPortSettings(uint8_t portID, uint16_t maxWait = 250); //Returns the current protocol bits in the UBX-CFG-PRT command for a given port
@@ -240,6 +259,7 @@ class SFE_UBLOX_GPS
240259

241260
//Functions
242261
uint32_t extractLong(uint8_t spotToStart); //Combine four bytes from payload into long
262+
uint16_t extractInt(uint8_t spotToStart); //Combine two bytes from payload into int
243263
uint8_t extractByte(uint8_t spotToStart); //Get byte from payload
244264
void addToChecksum(uint8_t incoming); //Given an incoming byte, adjust rollingChecksumA/B
245265

0 commit comments

Comments
 (0)