|
| 1 | +## How to add new messages to the SparkFun u-blox GNSS Arduino Library |
| 2 | + |
| 3 | +Based on [this issue](https://github.com/sparkfun/SparkFun_u-blox_GNSS_Arduino_Library/issues/97), here is a summary of how to add new messages to the SparkFun u-blox GNSS Arduino Library with full "auto" support (for callbacks, logging, etc.). |
| 4 | + |
| 5 | +Looking at the issue, we see that the library is not supporting the UBX-NAV-PVAT (Navigation Position Velocity Attitude Time solution). |
| 6 | +PVAT is a new message added in version 1.21 of the HPS (High Precision Fusion) firmware and version 33.21 of the F9 Interface Description. |
| 7 | +This makes us wonder if more new messages have been added which should also be included? |
| 8 | + |
| 9 | +### Step 1: Check the Interface Description for new keys |
| 10 | + |
| 11 | +* Download the latest [interface description](https://www.u-blox.com/sites/default/files/F9-HPS-1.21_InterfaceDescription_UBX-21019746.pdf) from the [u-blox website](https://www.u-blox.com/en/product/zed-f9r-module#tab-documentation-resources) |
| 12 | +* Open the interface description in Adobe Acrobat Reader DC (the free version) |
| 13 | +* Do a ```File \ Save as Text...``` |
| 14 | +* Save the file in ```Text (Accessible) (*.txt)``` format |
| 15 | +* Go make a cup of tea - this takes a while |
| 16 | +* Open the txt file in Notepad++ or another editor which supports Regular Expressions |
| 17 | +* The keys will have been saved as individual lines in the format: 0xnnnnnnnn space CR LF |
| 18 | +* So all we need to do is use a regex to delete everything else |
| 19 | +* Open Search \ Replace |
| 20 | +* Click the Search Mode - Regular Expression button |
| 21 | +* In the "Find what :" box enter: ```^(?!.*0x[\dabcdefABCDEF]{8}\s\r\n).*``` |
| 22 | +* Clear the "Replace with :" box |
| 23 | +* Click "Replace All" |
| 24 | +* You are left with just the keys - and a bunch of empty lines, some of which contain form feeds (\f) |
| 25 | +* Delete the empty lines (\r\n) by replacing \r\n with nothing - don't panic, this takes a few seconds |
| 26 | +* Delete the form feeds by replacing \f with nothing |
| 27 | +* Finally replace the remaining spaces (\s) with \r\n |
| 28 | +* Delete any spurious lines left at the start of the file. E.g. ROM and BASE and 0x118B2060. These came from the General information section |
| 29 | +* The following line (0x10340014) is the first key from the "Configuration Reference" section |
| 30 | +* Search for that key number and you will find it again half way through the file. This second copy came from "Configuration Defaults" |
| 31 | +* Delete the duplicate keys from that line onwards |
| 32 | +* Save the file |
| 33 | +* Open it in a spreadsheet, e.g. LibreOffice Calc |
| 34 | +* Select the "A" column and click "Sort Ascending A-Z" |
| 35 | +* Save the file (as Text CSV) |
| 36 | +* Use KDiff3 or another diff package to see the new additions |
| 37 | + |
| 38 | +You can find the keys in the [keys folder](https://github.com/sparkfun/SparkFun_u-blox_GNSS_Arduino_Library/tree/main/keys), saved as sorted text files. |
| 39 | +There are separate files for the P, R and T interfaces, plus a combined list (also sorted in ascending order). |
| 40 | + |
| 41 | +Comparing HPS 1.21 to HPS 1.20, we can see that the following keys have been added: |
| 42 | + |
| 43 | +* 0x10340014 CFG-BDS-USE_GEO_PRN |
| 44 | +* 0x10710005 CFG-I2CINPROT-SPARTN |
| 45 | +* 0x10730005 CFG-UART1INPROT-SPARTN |
| 46 | +* 0x10750005 CFG-UART2INPROT-SPARTN |
| 47 | +* 0x10770005 CFG-USBINPROT-SPARTN |
| 48 | +* 0x10790005 CFG-SPIINPROT-SPARTN |
| 49 | +* 0x20050035 CFG-TP-DRSTR_TP1 |
| 50 | +* 0x20910605 CFG-MSGOUT-UBX_RXM_SPARTN_I2C |
| 51 | +* 0x20910606 CFG-MSGOUT-UBX_RXM_SPARTN_UART1 |
| 52 | +* 0x20910607 CFG-MSGOUT-UBX_RXM_SPARTN_UART2 |
| 53 | +* 0x20910608 CFG-MSGOUT-UBX_RXM_SPARTN_USB |
| 54 | +* 0x20910609 CFG-MSGOUT-UBX_RXM_SPARTN_SPI |
| 55 | +* 0x2091062a CFG-MSGOUT-UBX_NAV_PVAT_I2C |
| 56 | +* 0x2091062b CFG-MSGOUT-UBX_NAV_PVAT_UART1 |
| 57 | +* 0x2091062c CFG-MSGOUT-UBX_NAV_PVAT_UART2 |
| 58 | +* 0x2091062d CFG-MSGOUT-UBX_NAV_PVAT_USB |
| 59 | +* 0x2091062e CFG-MSGOUT-UBX_NAV_PVAT_SPI |
| 60 | +* 0x20910634 CFG-MSGOUT-UBX_SEC_SIG_I2C |
| 61 | +* 0x20910635 CFG-MSGOUT-UBX_SEC_SIG_UART1 |
| 62 | +* 0x20910636 CFG-MSGOUT-UBX_SEC_SIG_UART2 |
| 63 | +* 0x20910637 CFG-MSGOUT-UBX_SEC_SIG_USB |
| 64 | +* 0x20910638 CFG-MSGOUT-UBX_SEC_SIG_SPI |
| 65 | + |
| 66 | +Interestingly, we can also see that one key has been deleted: |
| 67 | + |
| 68 | +* 0x10530006 CFG-UART2-REMAP |
| 69 | + |
| 70 | +From this we can confirm - as documented by u-blox in the [Release Notes](https://www.u-blox.com/sites/default/files/ZED-F9R-02B_FW1.00HPS1.21_RN_UBX-21035491_1.3.pdf) - |
| 71 | +that HPS 1.21: |
| 72 | + |
| 73 | +* adds support for SPARTN (Safe Position Augmentation for Real-Time Navigation) correction messages |
| 74 | +* enables the use of BeiDou geostationary satellites (previously, this configuration item had a different name) |
| 75 | +* enables UBX-SEC-SIG message (signal security measures) as output across the different interfaces |
| 76 | +* enables UBX_NAV_PVAT message (navigation and altitude position) as output across the different interfaces |
| 77 | + |
| 78 | +There are also two new dynamic models, robotic lawn mower (11) and e-scooter model (12), which we need to add to the library. |
| 79 | + |
| 80 | +See [this commit](https://github.com/sparkfun/SparkFun_u-blox_GNSS_Arduino_Library/commit/805aab18b6656513bfee473487a437754cd3965d) for the changes. |
| 81 | + |
| 82 | +### Step 2: Update the combined keys file |
| 83 | + |
| 84 | +Update [u-blox_config_keys_sorted.txt](https://github.com/sparkfun/SparkFun_u-blox_GNSS_Arduino_Library/blob/main/keys/u-blox_config_keys_sorted.txt) |
| 85 | +to include the new keys. |
| 86 | + |
| 87 | +See [this commit](https://github.com/sparkfun/SparkFun_u-blox_GNSS_Arduino_Library/commit/8895764f237ae494dcd0fa1ae942d487d2e1557f) for the changes. |
| 88 | + |
| 89 | +### Step 3: Update u-blox_config_keys.h |
| 90 | + |
| 91 | +Update [u-blox_config_keys.h](https://github.com/sparkfun/SparkFun_u-blox_GNSS_Arduino_Library/blob/main/src/u-blox_config_keys.h) to include the new keys. |
| 92 | +Include the descriptions as defined in the Interface Description. |
| 93 | + |
| 94 | +See [this commit](https://github.com/sparkfun/SparkFun_u-blox_GNSS_Arduino_Library/commit/3609da15f90a7a66b41524e77c6dc3dd76cd362c) for the changes. |
| 95 | + |
| 96 | +### Step 4: Add the new message struct to u-blox_struct.h |
| 97 | + |
| 98 | +The next step is to add the new struct for UBX-NAV-PVAT to u-blox_struct.h. |
| 99 | + |
| 100 | +The messages are in ascending class and ID order. So we add UBX-NAV-PVAT (0x01 0x17) after UBX-NAV-HPPOSLLH (0x01 0x14). |
| 101 | + |
| 102 | +The names and widths of the fields are taken directly from the interface definition. |
| 103 | + |
| 104 | +See [this commit](https://github.com/sparkfun/SparkFun_u-blox_GNSS_Arduino_Library/commit/a4ba440c6240e0974c27f40b976a5ddf0fbdb9b6) for the changes. |
| 105 | + |
| 106 | +### Step 5: Update SparkFun_u-blox_GNSS_Arduino_Library.h |
| 107 | + |
| 108 | +Add the new message ID: ```const uint8_t UBX_NAV_PVAT = 0x17;``` |
| 109 | + |
| 110 | +Add the new functions to provide "auto" support for UBX-NAV-PVAT: ```getNAVPVAT```, ```setAutoNAVPVAT```, ..., ```logNAVPVAT``` |
| 111 | + |
| 112 | +Add new helper functions to access the most important fields: ```getVehicleRoll```, ..., ```getMotionHeading``` |
| 113 | + |
| 114 | +Add the pointer to the struct storage: ```UBX_NAV_PVAT_t *packetUBXNAVPVAT = NULL;``` |
| 115 | + |
| 116 | +Add the private init function: ```bool initPacketUBXNAVPVAT();``` |
| 117 | + |
| 118 | +See [this commit](https://github.com/sparkfun/SparkFun_u-blox_GNSS_Arduino_Library/commit/423a1e2ccd418dd679257edc6edeec0bd3029052) for the changes. |
| 119 | + |
| 120 | +### Step 6: Update SparkFun_u-blox_GNSS_Arduino_Library.cpp |
| 121 | + |
| 122 | +Now we need to update SparkFun_u-blox_GNSS_Arduino_Library.cpp: |
| 123 | + |
| 124 | +#### Step 6.1: Update end() |
| 125 | + |
| 126 | +See [this commit](https://github.com/sparkfun/SparkFun_u-blox_GNSS_Arduino_Library/commit/35d225e3f1abb316eda3becb7f8e2eb04ff1d17c) for the changes. |
| 127 | + |
| 128 | +#### Step 6.2: Update checkAutomatic() |
| 129 | + |
| 130 | +See [this commit](https://github.com/sparkfun/SparkFun_u-blox_GNSS_Arduino_Library/commit/b746d8e2742961ede95e2d06d5db3a3a557e571d) for the changes. |
| 131 | + |
| 132 | +#### Step 6.3: Update processUBXpacket() |
| 133 | + |
| 134 | +Take time to double-check that you have used the correct data width, signed/unsigned and position for each field. |
| 135 | + |
| 136 | +See [this commit](https://github.com/sparkfun/SparkFun_u-blox_GNSS_Arduino_Library/commit/8eecdd5044f810b0e2b567150ff63a17c219fe8e) for the changes. |
| 137 | + |
| 138 | +#### Step 6.4: Update checkCallbacks() |
| 139 | + |
| 140 | +See [this commit](https://github.com/sparkfun/SparkFun_u-blox_GNSS_Arduino_Library/commit/b53bffaa3ae12482cfb268f23796963d0b8519c9) for the changes. |
| 141 | + |
| 142 | +#### Step 6.5: Add the "auto" functions |
| 143 | + |
| 144 | +See [this commit](https://github.com/sparkfun/SparkFun_u-blox_GNSS_Arduino_Library/commit/e394ae003ad38117d150598774d0552059416473) for the changes. |
| 145 | + |
| 146 | +#### Step 6.6: Add the helper functions (if any) |
| 147 | + |
| 148 | +See [this commit](https://github.com/sparkfun/SparkFun_u-blox_GNSS_Arduino_Library/commit/318e76383e96d6676bbb57294c25e665c0d4a31f) for the changes. |
| 149 | + |
| 150 | +### Step 7: Add an example |
| 151 | + |
| 152 | +See [this commit](https://github.com/sparkfun/SparkFun_u-blox_GNSS_Arduino_Library/commit/06014dc95f1b9ffae4876fbacfb9390541d7c31d) for the changes. |
| 153 | + |
| 154 | +### Step 8: Update keywords.txt |
| 155 | + |
| 156 | +Add the new "auto" and helper functions to keywords.txt. |
| 157 | + |
| 158 | +See [this commit](https://github.com/sparkfun/SparkFun_u-blox_GNSS_Arduino_Library/commit/4f0a0ca3c5e6420be9064b91702947c23104bd1b) for the changes. |
| 159 | + |
| 160 | +### Step 9: Update Theory.md |
| 161 | + |
| 162 | +Add the new message to the list of "auto" messages. |
| 163 | + |
| 164 | +See [this commit](https://github.com/sparkfun/SparkFun_u-blox_GNSS_Arduino_Library/commit/57f133259245d8071c73797e4be2ff630c2720ab) for the changes. |
| 165 | + |
| 166 | +That's all folks! |
0 commit comments