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

Commit 814da75

Browse files
authored
Merge pull request #106 from mayopan/master
Create Example21_ModuleInfo.ino
2 parents ce5e9a7 + bbc5183 commit 814da75

File tree

1 file changed

+176
-0
lines changed

1 file changed

+176
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
/*
2+
Module Info - extracts and prints the full module information from UBX_MON_VER
3+
using a custom command.
4+
By: @mayopan
5+
Date: May 9th, 2020
6+
Based on:
7+
Send Custom Command
8+
By: Paul Clark (PaulZC)
9+
Date: April 20th, 2020
10+
License: MIT. See license file for more information but you can
11+
basically do whatever you want with this code.
12+
Previously it was possible to create and send a custom packet
13+
through the library but it would always appear to timeout as
14+
some of the internal functions referred to the internal private
15+
struct packetCfg.
16+
The most recent version of the library allows sendCommand to
17+
use a custom packet as if it were packetCfg and so:
18+
- sendCommand will return a sfe_ublox_status_e enum as if
19+
it had been called from within the library
20+
- the custom packet will be updated with data returned by the module
21+
(previously this was not possible from outside the library)
22+
Feel like supporting open source hardware?
23+
Buy a board from SparkFun!
24+
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
25+
NEO-M8P RTK: https://www.sparkfun.com/products/15005
26+
SAM-M8Q: https://www.sparkfun.com/products/15106
27+
Hardware Connections:
28+
Plug a Qwiic cable into the GPS and a BlackBoard
29+
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
30+
Open the serial monitor at 115200 baud to see the output
31+
*/
32+
33+
#include <Wire.h> //Needed for I2C to GPS
34+
35+
#define MAX_PAYLOAD_SIZE 384 // Override MAX_PAYLOAD_SIZE for getModuleInfo which can return up to 348 bytes
36+
37+
#include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_Ublox_GPS
38+
39+
// Extend the class for getModuleInfo
40+
class SFE_UBLOX_GPS_ADD : public SFE_UBLOX_GPS
41+
{
42+
public:
43+
boolean getModuleInfo(uint16_t maxWait = 1100); //Queries module, texts
44+
45+
struct minfoStructure // Structure to hold the module info (uses 340 bytes of RAM)
46+
{
47+
char swVersion[30];
48+
char hwVersion[10];
49+
uint8_t extensionNo = 0;
50+
char extension[10][30];
51+
} minfo;
52+
};
53+
54+
SFE_UBLOX_GPS_ADD myGPS;
55+
56+
void setup()
57+
{
58+
Serial.begin(115200); // You may need to increase this for high navigation rates!
59+
while (!Serial)
60+
; //Wait for user to open terminal
61+
Serial.println(F("SparkFun Ublox Example"));
62+
63+
Wire.begin();
64+
65+
//myGPS.enableDebugging(); // Uncomment this line to enable debug messages
66+
67+
if (myGPS.begin() == false) //Connect to the Ublox module using Wire port
68+
{
69+
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
70+
while (1)
71+
;
72+
}
73+
74+
myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
75+
76+
Serial.print(F("Polling module info"));
77+
if (myGPS.getModuleInfo(1100) == false) // Try to get the module info
78+
{
79+
Serial.print(F("getModuleInfo failed! Freezing..."));
80+
while (1)
81+
;
82+
}
83+
84+
Serial.println();
85+
Serial.println();
86+
Serial.println(F("Module Info : "));
87+
Serial.print(F("Soft version: "));
88+
Serial.println(myGPS.minfo.swVersion);
89+
Serial.print(F("Hard version: "));
90+
Serial.println(myGPS.minfo.hwVersion);
91+
Serial.print(F("Extensions:"));
92+
Serial.println(myGPS.minfo.extensionNo);
93+
for (int i = 0; i < myGPS.minfo.extensionNo; i++)
94+
{
95+
Serial.print(" ");
96+
Serial.println(myGPS.minfo.extension[i]);
97+
}
98+
Serial.println();
99+
Serial.println(F("Done!"));
100+
}
101+
102+
void loop()
103+
{
104+
}
105+
106+
boolean SFE_UBLOX_GPS_ADD::getModuleInfo(uint16_t maxWait)
107+
{
108+
myGPS.minfo.hwVersion[0] = NULL;
109+
myGPS.minfo.swVersion[0] = NULL;
110+
for (int i = 0; i < 10; i++)
111+
myGPS.minfo.extension[i][0] = NULL;
112+
113+
// Let's create our custom packet
114+
uint8_t customPayload[MAX_PAYLOAD_SIZE]; // This array holds the payload data bytes
115+
116+
// The next line creates and initialises the packet information which wraps around the payload
117+
ubxPacket customCfg = {0, 0, 0, 0, 0, customPayload, 0, 0, SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED, SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED};
118+
119+
// The structure of ubxPacket is:
120+
// uint8_t cls : The message Class
121+
// uint8_t id : The message ID
122+
// uint16_t len : Length of the payload. Does not include cls, id, or checksum bytes
123+
// uint16_t counter : Keeps track of number of overall bytes received. Some responses are larger than 255 bytes.
124+
// uint16_t startingSpot : The counter value needed to go past before we begin recording into payload array
125+
// uint8_t *payload : The payload
126+
// uint8_t checksumA : Given to us by the module. Checked against the rolling calculated A/B checksums.
127+
// uint8_t checksumB
128+
// sfe_ublox_packet_validity_e valid : Goes from NOT_DEFINED to VALID or NOT_VALID when checksum is checked
129+
// sfe_ublox_packet_validity_e classAndIDmatch : Goes from NOT_DEFINED to VALID or NOT_VALID when the Class and ID match the requestedClass and requestedID
130+
131+
// sendCommand will return:
132+
// SFE_UBLOX_STATUS_DATA_RECEIVED if the data we requested was read / polled successfully
133+
// SFE_UBLOX_STATUS_DATA_SENT if the data we sent was writted successfully (ACK'd)
134+
// Other values indicate errors. Please see the sfe_ublox_status_e enum for further details.
135+
136+
// Referring to the u-blox M8 Receiver Description and Protocol Specification we see that
137+
// the navigation rate is configured using the UBX-CFG-RATE message. So let's load our
138+
// custom packet with the correct information so we can read (poll / get) the current settings.
139+
140+
customCfg.cls = UBX_CLASS_MON; // This is the message Class
141+
customCfg.id = UBX_MON_VER; // This is the message ID
142+
customCfg.len = 0; // Setting the len (length) to zero let's us poll the current settings
143+
customCfg.startingSpot = 0; // Always set the startingSpot to zero (unless you really know what you are doing)
144+
145+
// We also need to tell sendCommand how long it should wait for a reply
146+
// uint16_t maxWait = 250; // Wait for up to 250ms (Serial may need a lot longer e.g. 1100)
147+
148+
if (sendCommand(&customCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED)
149+
return (false); //If command send fails then bail
150+
151+
uint16_t position = 0;
152+
for (int i = 0; i < 30; i++)
153+
{
154+
minfo.swVersion[i] = customPayload[position];
155+
position++;
156+
}
157+
for (int i = 0; i < 10; i++)
158+
{
159+
minfo.hwVersion[i] = customPayload[position];
160+
position++;
161+
}
162+
163+
while (customCfg.len >= position + 30)
164+
{
165+
for (int i = 0; i < 30; i++)
166+
{
167+
minfo.extension[minfo.extensionNo][i] = customPayload[position];
168+
position++;
169+
}
170+
minfo.extensionNo++;
171+
if (minfo.extensionNo > 9)
172+
break;
173+
}
174+
175+
return (true); //Success!
176+
}

0 commit comments

Comments
 (0)