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

Commit 21379f4

Browse files
author
Paul Clark
committed
Updated setVal and added 'multi' setVal
Added 8- and 32-bit versions of setVal. Added 8-, 16- and 32-bit versions of newCfgValset, addCfgValset and sendCfgValset to provide multiSetVal support.
1 parent d34792f commit 21379f4

File tree

2 files changed

+316
-7
lines changed

2 files changed

+316
-7
lines changed

src/SparkFun_Ublox_Arduino_Library.cpp

+294-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
- Modified ProcessUBXPacket to parse HPPOSLLH packet
2929
- Added query staleness verification for HPPOSLLH data
3030
31+
Modified by Paul Clark, 1st July 2019
32+
- Added 8 and 32 bit versions of setVal
33+
- Added newCfgValset, addCfgValset and sendCfgValset to support the setting of multiple keyID and value pairs simultaneously
34+
3135
This program is distributed in the hope that it will be useful,
3236
but WITHOUT ANY WARRANTY; without even the implied warranty of
3337
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@@ -951,19 +955,28 @@ uint8_t SFE_UBLOX_GPS::getVal8(uint32_t key, uint8_t layer, uint16_t maxWait)
951955
return (extractByte(8));
952956
}
953957

954-
//Given a key, set an 8-bit value
958+
//Given a key, set a 16-bit value
955959
//This function takes a full 32-bit key
956960
//Default layer is BBR
957961
//Configuration of modern Ublox modules is now done via getVal/setVal/delVal, ie protocol v27 and above found on ZED-F9P
958962
uint8_t SFE_UBLOX_GPS::setVal(uint32_t key, uint16_t value, uint8_t layer, uint16_t maxWait)
963+
{
964+
return setVal16(key, value, layer, maxWait);
965+
}
966+
967+
//Given a key, set a 16-bit value
968+
//This function takes a full 32-bit key
969+
//Default layer is BBR
970+
//Configuration of modern Ublox modules is now done via getVal/setVal/delVal, ie protocol v27 and above found on ZED-F9P
971+
uint8_t SFE_UBLOX_GPS::setVal16(uint32_t key, uint16_t value, uint8_t layer, uint16_t maxWait)
959972
{
960973
packetCfg.cls = UBX_CLASS_CFG;
961974
packetCfg.id = UBX_CFG_VALSET;
962975
packetCfg.len = 4 + 4 + 2; //4 byte header, 4 byte key ID, 2 bytes of value
963976
packetCfg.startingSpot = 0;
964977

965978
//Clear packet payload
966-
for (uint8_t x = 0; x < packetCfg.len; x++)
979+
for (uint16_t x = 0; x < packetCfg.len; x++)
967980
packetCfg.payload[x] = 0;
968981

969982
payloadCfg[0] = 0; //Message Version - set to 0
@@ -987,6 +1000,285 @@ uint8_t SFE_UBLOX_GPS::setVal(uint32_t key, uint16_t value, uint8_t layer, uint1
9871000
return (true);
9881001
}
9891002

1003+
//Given a key, set an 8-bit value
1004+
//This function takes a full 32-bit key
1005+
//Default layer is BBR
1006+
//Configuration of modern Ublox modules is now done via getVal/setVal/delVal, ie protocol v27 and above found on ZED-F9P
1007+
uint8_t SFE_UBLOX_GPS::setVal8(uint32_t key, uint8_t value, uint8_t layer, uint16_t maxWait)
1008+
{
1009+
packetCfg.cls = UBX_CLASS_CFG;
1010+
packetCfg.id = UBX_CFG_VALSET;
1011+
packetCfg.len = 4 + 4 + 1; //4 byte header, 4 byte key ID, 1 byte value
1012+
packetCfg.startingSpot = 0;
1013+
1014+
//Clear packet payload
1015+
for (uint16_t x = 0; x < packetCfg.len; x++)
1016+
packetCfg.payload[x] = 0;
1017+
1018+
payloadCfg[0] = 0; //Message Version - set to 0
1019+
payloadCfg[1] = layer; //By default we ask for the BBR layer
1020+
1021+
//Load key into outgoing payload
1022+
payloadCfg[4] = key >> 8 * 0; //Key LSB
1023+
payloadCfg[5] = key >> 8 * 1;
1024+
payloadCfg[6] = key >> 8 * 2;
1025+
payloadCfg[7] = key >> 8 * 3;
1026+
1027+
//Load user's value
1028+
payloadCfg[8] = value; //Value
1029+
1030+
//Send VALSET command with this key and value
1031+
if (sendCommand(packetCfg, maxWait) == false)
1032+
return (false); //If command send fails then bail
1033+
1034+
//All done
1035+
return (true);
1036+
}
1037+
1038+
//Given a key, set a 32-bit value
1039+
//This function takes a full 32-bit key
1040+
//Default layer is BBR
1041+
//Configuration of modern Ublox modules is now done via getVal/setVal/delVal, ie protocol v27 and above found on ZED-F9P
1042+
uint8_t SFE_UBLOX_GPS::setVal32(uint32_t key, uint32_t value, uint8_t layer, uint16_t maxWait)
1043+
{
1044+
packetCfg.cls = UBX_CLASS_CFG;
1045+
packetCfg.id = UBX_CFG_VALSET;
1046+
packetCfg.len = 4 + 4 + 4; //4 byte header, 4 byte key ID, 4 bytes of value
1047+
packetCfg.startingSpot = 0;
1048+
1049+
//Clear packet payload
1050+
for (uint16_t x = 0; x < packetCfg.len; x++)
1051+
packetCfg.payload[x] = 0;
1052+
1053+
payloadCfg[0] = 0; //Message Version - set to 0
1054+
payloadCfg[1] = layer; //By default we ask for the BBR layer
1055+
1056+
//Load key into outgoing payload
1057+
payloadCfg[4] = key >> 8 * 0; //Key LSB
1058+
payloadCfg[5] = key >> 8 * 1;
1059+
payloadCfg[6] = key >> 8 * 2;
1060+
payloadCfg[7] = key >> 8 * 3;
1061+
1062+
//Load user's value
1063+
payloadCfg[8] = value >> 8 * 0; //Value LSB
1064+
payloadCfg[9] = value >> 8 * 1;
1065+
payloadCfg[10] = value >> 8 * 2;
1066+
payloadCfg[11] = value >> 8 * 3;
1067+
1068+
//Send VALSET command with this key and value
1069+
if (sendCommand(packetCfg, maxWait) == false)
1070+
return (false); //If command send fails then bail
1071+
1072+
//All done
1073+
return (true);
1074+
}
1075+
1076+
//Start defining a new UBX-CFG-VALSET ubxPacket
1077+
//This function takes a full 32-bit key and 32-bit value
1078+
//Default layer is BBR
1079+
//Configuration of modern Ublox modules is now done via getVal/setVal/delVal, ie protocol v27 and above found on ZED-F9P
1080+
uint8_t SFE_UBLOX_GPS::newCfgValset32(uint32_t key, uint32_t value, uint8_t layer)
1081+
{
1082+
packetCfg.cls = UBX_CLASS_CFG;
1083+
packetCfg.id = UBX_CFG_VALSET;
1084+
packetCfg.len = 4 + 4 + 4; //4 byte header, 4 byte key ID, 4 bytes of value
1085+
packetCfg.startingSpot = 0;
1086+
1087+
//Clear packet payload
1088+
for (uint16_t x = 0; x < MAX_PAYLOAD_SIZE; x++)
1089+
packetCfg.payload[x] = 0;
1090+
1091+
payloadCfg[0] = 0; //Message Version - set to 0
1092+
payloadCfg[1] = layer; //By default we ask for the BBR layer
1093+
1094+
//Load key into outgoing payload
1095+
payloadCfg[4] = key >> 8 * 0; //Key LSB
1096+
payloadCfg[5] = key >> 8 * 1;
1097+
payloadCfg[6] = key >> 8 * 2;
1098+
payloadCfg[7] = key >> 8 * 3;
1099+
1100+
//Load user's value
1101+
payloadCfg[8] = value >> 8 * 0; //Value LSB
1102+
payloadCfg[9] = value >> 8 * 1;
1103+
payloadCfg[10] = value >> 8 * 2;
1104+
payloadCfg[11] = value >> 8 * 3;
1105+
1106+
//All done
1107+
return (true);
1108+
}
1109+
1110+
//Start defining a new UBX-CFG-VALSET ubxPacket
1111+
//This function takes a full 32-bit key and 16-bit value
1112+
//Default layer is BBR
1113+
//Configuration of modern Ublox modules is now done via getVal/setVal/delVal, ie protocol v27 and above found on ZED-F9P
1114+
uint8_t SFE_UBLOX_GPS::newCfgValset16(uint32_t key, uint16_t value, uint8_t layer)
1115+
{
1116+
packetCfg.cls = UBX_CLASS_CFG;
1117+
packetCfg.id = UBX_CFG_VALSET;
1118+
packetCfg.len = 4 + 4 + 2; //4 byte header, 4 byte key ID, 2 bytes of value
1119+
packetCfg.startingSpot = 0;
1120+
1121+
//Clear packet payload
1122+
for (uint16_t x = 0; x < MAX_PAYLOAD_SIZE; x++)
1123+
packetCfg.payload[x] = 0;
1124+
1125+
payloadCfg[0] = 0; //Message Version - set to 0
1126+
payloadCfg[1] = layer; //By default we ask for the BBR layer
1127+
1128+
//Load key into outgoing payload
1129+
payloadCfg[4] = key >> 8 * 0; //Key LSB
1130+
payloadCfg[5] = key >> 8 * 1;
1131+
payloadCfg[6] = key >> 8 * 2;
1132+
payloadCfg[7] = key >> 8 * 3;
1133+
1134+
//Load user's value
1135+
payloadCfg[8] = value >> 8 * 0; //Value LSB
1136+
payloadCfg[9] = value >> 8 * 1;
1137+
1138+
//All done
1139+
return (true);
1140+
}
1141+
1142+
//Start defining a new UBX-CFG-VALSET ubxPacket
1143+
//This function takes a full 32-bit key and 8-bit value
1144+
//Default layer is BBR
1145+
//Configuration of modern Ublox modules is now done via getVal/setVal/delVal, ie protocol v27 and above found on ZED-F9P
1146+
uint8_t SFE_UBLOX_GPS::newCfgValset8(uint32_t key, uint8_t value, uint8_t layer)
1147+
{
1148+
packetCfg.cls = UBX_CLASS_CFG;
1149+
packetCfg.id = UBX_CFG_VALSET;
1150+
packetCfg.len = 4 + 4 + 1; //4 byte header, 4 byte key ID, 1 byte value
1151+
packetCfg.startingSpot = 0;
1152+
1153+
//Clear packet payload
1154+
for (uint16_t x = 0; x < MAX_PAYLOAD_SIZE; x++)
1155+
packetCfg.payload[x] = 0;
1156+
1157+
payloadCfg[0] = 0; //Message Version - set to 0
1158+
payloadCfg[1] = layer; //By default we ask for the BBR layer
1159+
1160+
//Load key into outgoing payload
1161+
payloadCfg[4] = key >> 8 * 0; //Key LSB
1162+
payloadCfg[5] = key >> 8 * 1;
1163+
payloadCfg[6] = key >> 8 * 2;
1164+
payloadCfg[7] = key >> 8 * 3;
1165+
1166+
//Load user's value
1167+
payloadCfg[8] = value; //Value
1168+
1169+
//All done
1170+
return (true);
1171+
}
1172+
1173+
//Add another keyID and value to an existing UBX-CFG-VALSET ubxPacket
1174+
//This function takes a full 32-bit key and 32-bit value
1175+
uint8_t SFE_UBLOX_GPS::addCfgValset32(uint32_t key, uint32_t value)
1176+
{
1177+
//Load key into outgoing payload
1178+
payloadCfg[packetCfg.len + 0] = key >> 8 * 0; //Key LSB
1179+
payloadCfg[packetCfg.len + 1] = key >> 8 * 1;
1180+
payloadCfg[packetCfg.len + 2] = key >> 8 * 2;
1181+
payloadCfg[packetCfg.len + 3] = key >> 8 * 3;
1182+
1183+
//Load user's value
1184+
payloadCfg[packetCfg.len + 4] = value >> 8 * 0; //Value LSB
1185+
payloadCfg[packetCfg.len + 5] = value >> 8 * 1;
1186+
payloadCfg[packetCfg.len + 6] = value >> 8 * 2;
1187+
payloadCfg[packetCfg.len + 7] = value >> 8 * 3;
1188+
1189+
//Update packet length: 4 byte key ID, 4 bytes of value
1190+
packetCfg.len = packetCfg.len + 4 + 4;
1191+
1192+
//All done
1193+
return (true);
1194+
}
1195+
1196+
//Add another keyID and value to an existing UBX-CFG-VALSET ubxPacket
1197+
//This function takes a full 32-bit key and 16-bit value
1198+
uint8_t SFE_UBLOX_GPS::addCfgValset16(uint32_t key, uint16_t value)
1199+
{
1200+
//Load key into outgoing payload
1201+
payloadCfg[packetCfg.len + 0] = key >> 8 * 0; //Key LSB
1202+
payloadCfg[packetCfg.len + 1] = key >> 8 * 1;
1203+
payloadCfg[packetCfg.len + 2] = key >> 8 * 2;
1204+
payloadCfg[packetCfg.len + 3] = key >> 8 * 3;
1205+
1206+
//Load user's value
1207+
payloadCfg[packetCfg.len + 4] = value >> 8 * 0; //Value LSB
1208+
payloadCfg[packetCfg.len + 5] = value >> 8 * 1;
1209+
1210+
//Update packet length: 4 byte key ID, 2 bytes of value
1211+
packetCfg.len = packetCfg.len + 4 + 2;
1212+
1213+
//All done
1214+
return (true);
1215+
}
1216+
1217+
//Add another keyID and value to an existing UBX-CFG-VALSET ubxPacket
1218+
//This function takes a full 32-bit key and 8-bit value
1219+
uint8_t SFE_UBLOX_GPS::addCfgValset8(uint32_t key, uint8_t value)
1220+
{
1221+
//Load key into outgoing payload
1222+
payloadCfg[packetCfg.len + 0] = key >> 8 * 0; //Key LSB
1223+
payloadCfg[packetCfg.len + 1] = key >> 8 * 1;
1224+
payloadCfg[packetCfg.len + 2] = key >> 8 * 2;
1225+
payloadCfg[packetCfg.len + 3] = key >> 8 * 3;
1226+
1227+
//Load user's value
1228+
payloadCfg[packetCfg.len + 4] = value; //Value
1229+
1230+
//Update packet length: 4 byte key ID, 1 byte value
1231+
packetCfg.len = packetCfg.len + 4 + 1;
1232+
1233+
//All done
1234+
return (true);
1235+
}
1236+
1237+
//Add a final keyID and value to an existing UBX-CFG-VALSET ubxPacket and send it
1238+
//This function takes a full 32-bit key and 32-bit value
1239+
uint8_t SFE_UBLOX_GPS::sendCfgValset32(uint32_t key, uint32_t value, uint16_t maxWait)
1240+
{
1241+
//Load keyID and value into outgoing payload
1242+
addCfgValset32(key, value);
1243+
1244+
//Send VALSET command with this key and value
1245+
if (sendCommand(packetCfg, maxWait) == false)
1246+
return (false); //If command send fails then bail
1247+
1248+
//All done
1249+
return (true);
1250+
}
1251+
1252+
//Add a final keyID and value to an existing UBX-CFG-VALSET ubxPacket and send it
1253+
//This function takes a full 32-bit key and 16-bit value
1254+
uint8_t SFE_UBLOX_GPS::sendCfgValset16(uint32_t key, uint16_t value, uint16_t maxWait)
1255+
{
1256+
//Load keyID and value into outgoing payload
1257+
addCfgValset16(key, value);
1258+
1259+
//Send VALSET command with this key and value
1260+
if (sendCommand(packetCfg, maxWait) == false)
1261+
return (false); //If command send fails then bail
1262+
1263+
//All done
1264+
return (true);
1265+
}
1266+
1267+
//Add a final keyID and value to an existing UBX-CFG-VALSET ubxPacket and send it
1268+
//This function takes a full 32-bit key and 8-bit value
1269+
uint8_t SFE_UBLOX_GPS::sendCfgValset8(uint32_t key, uint8_t value, uint16_t maxWait)
1270+
{
1271+
//Load keyID and value into outgoing payload
1272+
addCfgValset8(key, value);
1273+
1274+
//Send VALSET command with this key and value
1275+
if (sendCommand(packetCfg, maxWait) == false)
1276+
return (false); //If command send fails then bail
1277+
1278+
//All done
1279+
return (true);
1280+
}
1281+
9901282
//Get the current TimeMode3 settings - these contain survey in statuses
9911283
boolean SFE_UBLOX_GPS::getSurveyMode(uint16_t maxWait)
9921284
{

src/SparkFun_Ublox_Arduino_Library.h

+22-5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
getMeanSeaLevel(), getHorizontalAccuracy(), getVerticalAccuracy(), getHPPOSLLH()
2828
- Modified ProcessUBXPacket to parse HPPOSLLH packet
2929
- Added query staleness verification for HPPOSLLH data
30+
31+
Modified by Paul Clark, 1st July 2019
32+
- Added 8 and 32 bit versions of setVal
33+
- Added newCfgValset, addCfgValset and sendCfgValset to support the setting of multiple keyID and value pairs simultaneously
3034
3135
This program is distributed in the hope that it will be useful,
3236
but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -148,9 +152,10 @@ const uint8_t VAL_SIZE_16 = 0x03; //Two bytes
148152
const uint8_t VAL_SIZE_32 = 0x04; //Four bytes
149153
const uint8_t VAL_SIZE_64 = 0x05; //Eight bytes
150154

151-
const uint8_t VAL_LAYER_RAM = 0;
152-
const uint8_t VAL_LAYER_BBR = 1;
153-
const uint8_t VAL_LAYER_FLASH = 2;
155+
//These are the Bitfield layers definitions for the UBX-CFG-VALSET message (not to be confused with Bitfield deviceMask in UBX-CFG-CFG)
156+
const uint8_t VAL_LAYER_RAM = (1 << 0);
157+
const uint8_t VAL_LAYER_BBR = (1 << 1);
158+
const uint8_t VAL_LAYER_FLASH = (1 << 2);
154159
const uint8_t VAL_LAYER_DEFAULT = 7;
155160

156161
//Below are various Groups, IDs, and sizes for various settings
@@ -169,7 +174,7 @@ const uint8_t VAL_ID_I2C_ADDRESS = 0x01;
169174

170175
#ifndef MAX_PAYLOAD_SIZE
171176

172-
#define MAX_PAYLOAD_SIZE 64 //Some commands are larger than 64 bytes but this covers most
177+
#define MAX_PAYLOAD_SIZE 768 //Worst case: UBX_CFG_VALSET packet with 64 keyIDs each with 64 bit values
173178

174179
#endif
175180

@@ -276,7 +281,19 @@ class SFE_UBLOX_GPS
276281
//General configuration (used only on protocol v27 and higher - ie, ZED-F9P)
277282
uint8_t getVal8(uint16_t group, uint16_t id, uint8_t size, uint8_t layer = VAL_LAYER_BBR, uint16_t maxWait = 250); //Returns the value at a given group/id/size location
278283
uint8_t getVal8(uint32_t keyID, uint8_t layer = VAL_LAYER_BBR, uint16_t maxWait = 250); //Returns the value at a given group/id/size location
279-
uint8_t setVal(uint32_t keyID, uint16_t value, uint8_t layer = VAL_LAYER_BBR, uint16_t maxWait = 250); //Returns the value at a given group/id/size location
284+
uint8_t setVal(uint32_t keyID, uint16_t value, uint8_t layer = VAL_LAYER_BBR, uint16_t maxWait = 250); //Sets the 16-bit value at a given group/id/size location
285+
uint8_t setVal8(uint32_t keyID, uint8_t value, uint8_t layer = VAL_LAYER_BBR, uint16_t maxWait = 250); //Sets the 8-bit value at a given group/id/size location
286+
uint8_t setVal16(uint32_t keyID, uint16_t value, uint8_t layer = VAL_LAYER_BBR, uint16_t maxWait = 250); //Sets the 16-bit value at a given group/id/size location
287+
uint8_t setVal32(uint32_t keyID, uint32_t value, uint8_t layer = VAL_LAYER_BBR, uint16_t maxWait = 250); //Sets the 32-bit value at a given group/id/size location
288+
uint8_t newCfgValset8(uint32_t keyID, uint8_t value, uint8_t layer = VAL_LAYER_BBR); //Define a new UBX-CFG-VALSET with the given KeyID and 8-bit value
289+
uint8_t newCfgValset16(uint32_t keyID, uint16_t value, uint8_t layer = VAL_LAYER_BBR); //Define a new UBX-CFG-VALSET with the given KeyID and 16-bit value
290+
uint8_t newCfgValset32(uint32_t keyID, uint32_t value, uint8_t layer = VAL_LAYER_BBR); //Define a new UBX-CFG-VALSET with the given KeyID and 32-bit value
291+
uint8_t addCfgValset8(uint32_t keyID, uint8_t value); //Add a new KeyID and 8-bit value to an existing UBX-CFG-VALSET ubxPacket
292+
uint8_t addCfgValset16(uint32_t keyID, uint16_t value); //Add a new KeyID and 16-bit value to an existing UBX-CFG-VALSET ubxPacket
293+
uint8_t addCfgValset32(uint32_t keyID, uint32_t value); //Add a new KeyID and 32-bit value to an existing UBX-CFG-VALSET ubxPacket
294+
uint8_t sendCfgValset8(uint32_t keyID, uint8_t value, uint16_t maxWait = 250); //Add the final KeyID and 8-bit value to an existing UBX-CFG-VALSET ubxPacket and send it
295+
uint8_t sendCfgValset16(uint32_t keyID, uint16_t value, uint16_t maxWait = 250); //Add the final KeyID and 16-bit value to an existing UBX-CFG-VALSET ubxPacket and send it
296+
uint8_t sendCfgValset32(uint32_t keyID, uint32_t value, uint16_t maxWait = 250); //Add the final KeyID and 32-bit value to an existing UBX-CFG-VALSET ubxPacket and send it
280297

281298
//Functions used for RTK and base station setup
282299
boolean getSurveyMode(uint16_t maxWait = 250); //Get the current TimeMode3 settings

0 commit comments

Comments
 (0)