diff --git a/.github/workflows/run-unit-tests.yml b/.github/workflows/run-unit-tests.yml index 2c54b9e9600..b68125c8792 100644 --- a/.github/workflows/run-unit-tests.yml +++ b/.github/workflows/run-unit-tests.yml @@ -20,7 +20,7 @@ jobs: uses: ./.github/actions/setup-build-environment - name: Run Unit Tests - run: pio test -e native -e native_kiss_modem -e native_core -e native_ofast -e native_chat -e native_identity_store -e native_node_prefs -e native_radio_wrappers -e native_server -e native_sensor -e native_repeater -e native_repeater_full -e native_region -e native_radio_chips -e native_variant_target -e native_variant_target_override -e native_companion -e native_esp32_rtc_backup -e native_common_cli -e native_common_cli_nrf52 -e native_common_cli_esp32 -e native_common_cli_rs232 -e native_common_cli_espnow -e native_companion_buzzer -e native_companion_wifi -e native_companion_display -e native_companion_all -e native_rak3401_onboard_radio -vv + run: pio test -e native -e native_kiss_modem -e native_core -e native_ofast -e native_chat -e native_identity_store -e native_node_prefs -e native_radio_wrappers -e native_server -e native_sensor -e native_repeater -e native_repeater_full -e native_region -e native_radio_chips -e native_variant_target -e native_variant_target_override -e native_companion -e native_esp32_rtc_backup -e native_common_cli -e native_common_cli_nrf52 -e native_common_cli_esp32 -e native_common_cli_rs232 -e native_common_cli_espnow -e native_companion_buzzer -e native_companion_wifi -e native_companion_display -e native_companion_all -vv - name: Upload Test Results # Upload test results even if the test step failed. diff --git a/docs/cli_commands.md b/docs/cli_commands.md index c45ada36baf..4842a547022 100644 --- a/docs/cli_commands.md +++ b/docs/cli_commands.md @@ -1110,7 +1110,7 @@ GPS time is written to the clock only while such a fix is current, never earlier Covers serial NMEA receivers (`MicroNMEALocationProvider`). **Usage:** -- `gps guard`: status, e.g. `> ok 7sat time ok +1s`, `> rej region time rej nofix`, or `... ALERT gps-clk +3600s 75m` when a trusted fix has disagreed with the clock by the same offset for `GPS_GUARD_ALERT_MIN` minutes. While the alert is active, the offset in hours is also reported in telemetry on the next free channel. +- `gps guard`: status, e.g. `> ok 7sat time ok +1s`, `> rej region time rej nofix`, `> ok 7sat time wait` (last check passed, no current trusted fix to check again, e.g. GPS asleep between periodic fixes), or `... ALERT gps-clk +3600s 75m` when a trusted fix has disagreed with the clock by the same offset for `GPS_GUARD_ALERT_MIN` minutes. - `gps guard on`, `gps guard off`: turn the guard on or off (saved, default on). While off, every fix and GPS time is accepted and `gps guard` shows `off`. - `gps guard accept`: while an alert is active, confirm that the GPS time is right and apply it to the clock. - `gps fence`, `gps fence `: fence radius around the configured `lat`/`lon` (`0` = off). Default `GPS_GUARD_FENCE_M` (1000); a value set here is saved. @@ -1126,6 +1126,8 @@ Covers serial NMEA receivers (`MicroNMEALocationProvider`). #### View or change the GPS advert policy **Usage:** +- `get advert.loc` +- `set advert.loc ` - `gps advert` - `gps advert ` @@ -1133,10 +1135,12 @@ Covers serial NMEA receivers (`MicroNMEALocationProvider`). - `policy`: `none`|`share`|`prefs` - `none`: don't include location in adverts - `share`: share gps location (from SensorManager) - - `prefs`: location stored in node's lat and lon settings + - `prefs`: location stored in node's lat and lon settings (can be different from gps value) **Default:** `prefs` +**Note:** `gps advert` command is the old format but is only accessible when a gps is attached to the unit. It has been kept for compatibility but one should prefer using `get/set` commands instead. + --- ### Sensors (When sensor support is compiled in) diff --git a/docs/refactoring/0011-variant-target.md b/docs/refactoring/0011-variant-target.md index d6892c62713..53a8e22efa7 100644 --- a/docs/refactoring/0011-variant-target.md +++ b/docs/refactoring/0011-variant-target.md @@ -2146,6 +2146,9 @@ New macros in `target.h`, inside nothing (the GPS lines are not under `DISPLAY_C `&board.periph_power`. - `GPS_BAUD_PROBE_LIST` (promicro, B): already a macro in the ini; the shared file reads it as `target.cpp` does today. + Since upstream #3798 (sync of 12.11.) `NmeaGpsDriver` reads the macro itself as the default + of its constructor, so `promicro` no longer needs the special case and the shared file + needs none either. - The type of `sensors` is not a new field: `target.h` already says `extern EnvironmentSensorManager sensors;`, and `decltype(sensors) sensors(nmea);` defines exactly that type. Checked to compile with `g++ -std=gnu++11 -c` on a stand-in (a diff --git a/docs/refactoring/0013-cli-command-table.md b/docs/refactoring/0013-cli-command-table.md index 44dd9f0707d..c0f71000ee1 100644 --- a/docs/refactoring/0013-cli-command-table.md +++ b/docs/refactoring/0013-cli-command-table.md @@ -125,6 +125,7 @@ falls through to the next branch and, in the end, to "Unknown command". | `allow.read.only` | `OK` | on if the value starts with `on`, save | | | `flood.advert.interval` | `OK` or `Error: interval range is 3-168 hours` | hours, `updateFloodAdvertTimer`, save | 0 allowed (off); 1 and 2 are errors | | `advert.interval` | `OK` or `Error: interval range is 60-240 minutes` | stored as minutes / 2, `updateAdvertTimer`, save | 0 allowed; see quirk on zeroing | +| `advert.loc` | `OK` or `Error, invalid policy` | `none`, `share` or `prefs` (prefix match) to `advert_loc_policy`, save | upstream #3815; all builds, unlike `gps advert` | | `guest.password` | `OK` | 15 characters, save | no echo | | `prv.key` | `OK, reboot to apply! New pubkey: ` or `Error, bad key` | `saveIdentity(new id)` | accepted over the air; valid keys only | | `name` | `OK` or `Error, bad chars` | 31 characters, save | longer names are cut without an error | @@ -148,7 +149,8 @@ falls through to the next branch and, in the end, to "Unknown command". ### `get ` All replies start with `> `. Keys: `allow.read.only` (on or off), -`flood.advert.interval`, `advert.interval` (minutes), `guest.password`, `prv.key` +`flood.advert.interval`, `advert.interval` (minutes), `advert.loc` (`> none|prefs|share` +or `Error, invalid policy`), `guest.password`, `prv.key` (ts 0, uppercase hex), `name`, `repeat`, `lat`, `lon`, `flood.max.type` (`> grpdata:4 trace:3`, `> none` when empty, unnamed types as numbers), `flood.max.advert`, `flood.max.unscoped`, `flood.max`, `owner.info` (newline shown as `|`, cut at 159 @@ -184,8 +186,8 @@ single precision noise (`869.6179809` for 869.618). | File | Tests | Covers | |---|---|---| | `test_cli_commands.cpp` | 47 | dispatch order, board hook, prefix quirks, power, clock, advert, neighbors, tempradio, password, erase, ver, board, powersaving, log, stats, routing | -| `test_cli_set.cpp` | 49 | every `set` key, ranges, truncation, the zeroing in `savePrefs`, radio precedence, bridge and `extra.sf` variants | -| `test_cli_get.cpp` | 24 | every `get` key, prefix order, hex output, variants, fallback | +| `test_cli_set.cpp` | 52 | every `set` key, ranges, truncation, the zeroing in `savePrefs`, radio precedence, bridge and `extra.sf` variants | +| `test_cli_get.cpp` | 25 | every `get` key, prefix order, hex output, variants, fallback | | `test_cli_region.cpp` | 34 | every `region` sub command, limits, errors, callbacks | | `test_cli_sensor.cpp` | 39 | `sensor get\|set\|list` with paging, `gps ...` (GPS build) or "Unknown command" (others) | | `test_cli_flood_type.cpp` | 19 | `set` and `get flood.max.type`: names and numbers, sorted list, `off`, range and type errors, damaged stored list, full list | diff --git a/docs/refactoring/sync-upstream-dev-20261112.md b/docs/refactoring/sync-upstream-dev-20261112.md new file mode 100644 index 00000000000..f7054a8d67e --- /dev/null +++ b/docs/refactoring/sync-upstream-dev-20261112.md @@ -0,0 +1,128 @@ +# Sync upstream/dev into integration (12.11.2026) + +Merge of `upstream/dev` bb870313 (24 commits since the last sync base b8ae75d2) into +`integration` 5e32b39d, branch `claude/sync-upstream-dev-20261112-cdc32f`. The merge is a +signed merge commit (no rebase, no squash). Nothing is pushed and nothing is merged into +`integration`. + +## What upstream brought + +- GPS: #3798 `GPS_BAUD_PROBE_LIST` as a build flag for any `NmeaGpsDriver` (the constructor + default now reads it; enabled on Station G2 and G3), #3801 GPS guard shows `time wait` + instead of `rej nofix` between fixes, #3813 and #3817 drop the guard's alert telemetry + channel (`getAlertOffset()` and the `querySensors` code are gone), #3819 MicroNMEA no + longer reads past its buffer (16 zeroed tail bytes). +- #3815 CLI `get advert.loc` and `set advert.loc `, usable without a GPS; + `gps advert` stays for GPS builds. +- #3807 stack-buffer overflow fix in CLI reply buffers (touches the three `MyMesh.cpp`). +- #3811 and #3822 mDNS name built without `String` (`examples/companion_radio/main.cpp`). +- #3784 repeater history queries and its revert #3812 (net effect in this range: none). +- 0147165b reverts the rak13302 tests: `test/test_rak3401_board_startup/`, + `test/test_rak3401_onboard_radio/` and `[env:native_rak3401_onboard_radio]` are gone. + +## Probe and merge + +`git merge-tree --write-tree --name-only HEAD upstream/dev` listed 3 conflict files. The +merge commit is 66ab992a (signed, `gpgsig` present in the commit object). + +## Conflicts and how they were solved + +- `src/helpers/CommonCLI.cpp`: upstream put `advert.loc` into the old `else if` chains of + `handleSetCmd` and `handleGetCmd`, which the fork replaced with the tables of step 13. + The fork side stays. `advert.loc` is now `CommonCLIImpl::setAdvertLoc` / `getAdvertLoc` + and one row in `kSetCmds` (`"advert.loc "`) and one in `kGetCmds` (`"advert.loc"`), placed + before `guest.password`. Not gated by `ENV_INCLUDE_GPS`, as upstream. Replies are + upstream's (`OK`, `Error, invalid policy`, `> none|prefs|share`). Neither name is a prefix + of another row, so the order does not matter. Tests in the harness of 13a (`CliTest`): + `SetAdvertLocTakesEachPolicyAndSaves`, `SetAdvertLocWithAnUnknownPolicyAnswersErrorAndChangesNothing`, + `SetAdvertLocNeedsItsTrailingSpaceAndKeepsAdvertIntervalApart` in `test_cli_set.cpp`, + `GetAdvertLocShowsThePolicy` in `test_cli_get.cpp`. They run in the five `native_common_cli*` + environments (+4 cases each). +- `platformio.ini`: upstream shortened `test_ignore` to `test_kiss_modem`; the fork keeps its + long list and drops only `test_rak3401_board_startup`. The merge removed + `[env:native_rak3401_onboard_radio]`. +- `.github/workflows/run-unit-tests.yml`: the fork's `pio test` line without + `-e native_rak3401_onboard_radio` (27 environments). + +Silent collisions, checked and fine: + +- E2a (`VariantTarget.cpp`, `SENSORS_TARGET_GLOBALS`): the shared `NmeaGpsDriver gps_driver(Serial1);` + now picks up `GPS_BAUD_PROBE_LIST` through the constructor default of #3798. Station G2 and + G3 use the shared block and define the flag, so they get the probe list without a line of + their own. Measured on the built images: `NMEA_GPS_PROBE_BAUDS` is a symbol in + `Station_G2_repeater`, and the byte triple 9600, 115200, 38400 is in the firmware of + `Station_G2_repeater` and `Station_G3_ESP32_repeater`, not in `Heltec_v3_repeater`. +- `variants/promicro/target.cpp` (group B, own `target.cpp`): auto-merged to the plain + `NmeaGpsDriver gps_driver(Serial1);`; upstream dropped the local probe-list branch because + the driver reads the flag itself. `docs/refactoring/0011-variant-target.md` says so now. +- `EnvironmentSensorManager.cpp`: upstream removed the guard alert telemetry; the fork's + `GpsGuard`/GPS code from the 10.11. sync is not touched. `getAlertOffset`, `rej nofix` + appear nowhere else in the tree (grep over `*.cpp`, `*.h`, `*.ini`; `docs/cli_commands.md` + mentions both and was updated by upstream). + +## Docs + +`0013-cli-command-table.md`: `advert.loc` row in the set table, `advert.loc` in the key list of +the get section, test counts for `test_cli_set.cpp` (52) and `test_cli_get.cpp` (25). + +## Checks + +Native, the environments of `run-unit-tests.yml`, one by one with `pio test -e `, exit +code 0 each. + +| | Environments | Cases | Succeeded | Skipped | Failed | +|---|---|---|---|---|---| +| before the merge (5e32b39d) | 28 | 2447 | 2446 | 1 (`native_radio_chips`) | 0 | +| after the merge | 27 | 2456 | 2455 | 1 (`native_radio_chips`) | 0 | + +Difference: the reverted rak13302 tests (4 cases in `native`, 7 in the removed environment) +and the 20 new `advert.loc` cases (4 in each of the five `native_common_cli*`). +`native` 143 to 139, `native_common_cli` 185 to 189, `_esp32` 185 to 189, `_espnow` 193 to +197, `_nrf52` 198 to 202, `_rs232` 192 to 196; all other environments unchanged. + +Firmware: 19 environments, `SOURCE_DATE_EPOCH=1760000000`, merged tree. Not the 211 of +`sync-build-envs.txt` (see open points). Chosen for what the merge touches: E2a variants with +and without the probe list (Station G2 and G3, Heltec V3, V4, V4 R8, tracker V2, T096, +ProMicro), all three mDNS code paths (WiFi companions), CommonCLI on every platform (nRF52, +ESP32, RP2040). + +| Env | RAM | Flash | Result | +|---|---|---|---| +| Station_G2_repeater | 74968 | 1218873 | builds | +| Station_G2_companion_radio_wifi | 184800 | 1153665 | builds | +| Station_G2_companion_radio_ble | 184420 | 1333341 | link error, flash too big (max 1310720) | +| Station_G3_ESP32_repeater | 74976 | 1220477 | builds | +| Station_G3_ESP32_companion_radio_ble | 184428 | 1335009 | link error, flash too big | +| Heltec_v3_repeater | 62768 | 1186005 | builds | +| heltec_v4_repeater | 62740 | 1184149 | builds | +| heltec_v4_companion_radio_wifi | 174492 | 1145681 | builds | +| heltec_v4_r8_repeater | 62656 | 1187681 | builds | +| heltec_tracker_v2_repeater | 74608 | 1237145 | builds | +| Heltec_t096_repeater | 35828 | 432632 | builds | +| RAK_4631_repeater | 37664 | 468524 | builds | +| RAK_4631_companion_radio_ble | 150160 | 492368 | builds | +| ProMicro_repeater | 34156 | 364304 | builds | +| ThinkNode_M1_companion_radio_ble | 151680 | 384564 | builds | +| t1000e_repeater | 33116 | 311128 | builds | +| t1000e_companion_radio_usb | 141396 | 321076 | builds | +| MeshTracker_X1_repeater | 33196 | 318608 | builds | +| PicoW_repeater | 85484 | 532216 | builds | + +The two BLE companions that fail are not caused by this merge. The same two environments +built the same way overflow on `integration` 5e32b39d (`Station_G3_ESP32_companion_radio_ble` +1334945, `Station_G2_companion_radio_ble` 1333265) and `Station_G3_ESP32_companion_radio_ble` +on `upstream/dev` bb870313 (1327237) as well. The merge adds 64 bytes (G3) and 76 bytes (G2) +over `integration`. Caveat: the libdeps of these builds were seeded from existing +`.pio/libdeps` directories to stay under the PlatformIO registry limit (no integrity file), +so absolute sizes may differ from a fresh CI build. Whether the images overflow with freshly +resolved libraries is NOT VERIFIED. The fork premium over `upstream/dev` for +`Station_G3_ESP32_companion_radio_ble` is +7772 bytes, in the range of the 10.11. sync. + +## Open points, NOT VERIFIED + +- Not built: 192 of the 211 environments of `sync-build-envs.txt`, no size comparison against + `upstream/dev` except the one environment above. +- No board run, no image flashed: probe-list baud detection on Station G2/G3 with a Grove + GPS at 115200, the `time wait` guard status, the mDNS name on a device. +- No host test for `get/set advert.loc` outside the CLI harness, none for the GPS guard, + `NmeaGpsDriver` probe list or the MicroNMEA buffer tail (#3819). diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index c534772cd26..b6d6643d73a 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -276,27 +276,30 @@ void setup() { #endif #ifdef HAS_ESP_MDNS - String nodeName = the_mesh.getNodeName(); - String sanitizedNodeName; - sanitizedNodeName.reserve(nodeName.length()); - for (size_t i = 0; i < nodeName.length(); ++i) { + const char* nodeName = the_mesh.getNodeName(); + + // "meshcore_" prefix + sanitized node name, capped at 63 chars (max DNS label length) + char mdnsName[64]; + const size_t prefixLen = snprintf(mdnsName, sizeof(mdnsName), "meshcore_"); + size_t pos = prefixLen; + for (size_t i = 0; nodeName[i] != '\0' && pos < sizeof(mdnsName) - 1; ++i) { const char c = nodeName[i]; if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '-' || c == '_') { - sanitizedNodeName += c; + mdnsName[pos++] = c; } } + mdnsName[pos] = '\0'; - String mdnsName = "meshcore_"; - mdnsName += sanitizedNodeName; - if (!MDNS.begin(mdnsName.c_str())) { + if (!MDNS.begin(mdnsName)) { WIFI_DEBUG_PRINTLN("mDNS failed to start!"); } else { MDNS.addService("meshcore", "tcp", TCP_PORT); - MDNS.addServiceTxt("meshcore", "tcp", "node-name", the_mesh.getNodeName()); + MDNS.addServiceTxt("meshcore", "tcp", "node-name", nodeName); MDNS.addServiceTxt("meshcore", "tcp", "firmware-version", FIRMWARE_VERSION); - String protocol; protocol+=FIRMWARE_VER_CODE; - MDNS.addServiceTxt("meshcore", "tcp", "protocol-version", protocol.c_str()); + char protocol[12]; + snprintf(protocol, sizeof(protocol), "%d", (int)FIRMWARE_VER_CODE); + MDNS.addServiceTxt("meshcore", "tcp", "protocol-version", (const char*)protocol); MDNS.addServiceTxt("meshcore", "tcp", "build-date", __DATE__); MDNS.addServiceTxt("meshcore", "tcp", "build-time", __TIME__); } diff --git a/examples/simple_repeater/MyMesh.cpp b/examples/simple_repeater/MyMesh.cpp index aa5654ff2e7..ac842c5c459 100644 --- a/examples/simple_repeater/MyMesh.cpp +++ b/examples/simple_repeater/MyMesh.cpp @@ -656,7 +656,8 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx, } } - uint8_t temp[166]; + // 5-byte datagram header + 3-byte reflected CLI prefix + 160-byte reply text + NUL + uint8_t temp[169]; char *command = (char *)&data[5]; char *reply = (char *)&temp[5]; if (is_retry) { diff --git a/examples/simple_room_server/MyMesh.cpp b/examples/simple_room_server/MyMesh.cpp index 5b374e3595a..cc2d9bbcfd4 100644 --- a/examples/simple_room_server/MyMesh.cpp +++ b/examples/simple_room_server/MyMesh.cpp @@ -404,7 +404,8 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx, mesh::Utils::sha256((uint8_t *)&ack_hash, 4, data, 5 + strlen((char *)&data[5]), client->id.pub_key, PUB_KEY_SIZE); - uint8_t temp[166]; + // 5-byte datagram header + 3-byte reflected CLI prefix + 160-byte reply text + NUL + uint8_t temp[169]; bool send_ack; if (flags == TXT_TYPE_CLI_DATA || flags == TXT_TYPE_CLI_COMMAND) { if (client->isAdmin()) { diff --git a/examples/simple_sensor/SensorMesh.cpp b/examples/simple_sensor/SensorMesh.cpp index 52c615941f9..ad60657fdaf 100644 --- a/examples/simple_sensor/SensorMesh.cpp +++ b/examples/simple_sensor/SensorMesh.cpp @@ -606,7 +606,8 @@ void SensorMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender_i // len can be > original length, but 'text' will be padded with zeroes data[len] = 0; // need to make a C string again, with null terminator - uint8_t temp[166]; + // 5-byte datagram header + 3-byte reflected CLI prefix + 160-byte reply text + NUL + uint8_t temp[169]; char *command = (char *) &data[5]; char *reply = (char *) &temp[5]; handleCommand(from, sender_timestamp, command, reply); diff --git a/platformio.ini b/platformio.ini index 3bd3d6db78c..0d5a10de4e5 100644 --- a/platformio.ini +++ b/platformio.ini @@ -191,7 +191,6 @@ test_ignore = test_common_cli test_packet_parse test_esp32_rtc_backup - test_rak3401_board_startup build_src_filter = -<*> +<../src/Utils.cpp> @@ -995,15 +994,6 @@ build_src_filter = lib_deps = google/googletest @ 1.17.0 -[env:native_rak3401_onboard_radio] -; Board startup needs isolated GPIO and power-management mocks. -extends = env:native -test_build_src = no -test_filter = test_rak3401_* -test_ignore = -build_flags = -I test/test_rak3401_board_startup/mocks - ${env:native.build_flags} - [env:native_kiss_modem] platform = native test_framework = googletest diff --git a/src/helpers/BaseChatMesh.cpp b/src/helpers/BaseChatMesh.cpp index 4368d17f1c2..58c08deaa3f 100644 --- a/src/helpers/BaseChatMesh.cpp +++ b/src/helpers/BaseChatMesh.cpp @@ -266,7 +266,8 @@ void BaseChatMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender onCommandDataRecv(from, packet, sender_timestamp, text); // let UI know // NOTE: no ack expected for CLI_DATA replies } else if (flags == TXT_TYPE_CLI_COMMAND) { - uint8_t temp[166]; + // 5-byte datagram header + 3-byte reflected CLI prefix + 160-byte reply text + NUL + uint8_t temp[169]; char *command = (char *)&data[5]; char *reply = (char *)&temp[5]; *reply = 0; diff --git a/src/helpers/CommonCLI.cpp b/src/helpers/CommonCLI.cpp index 0e7d3144921..fd7b9de7d4a 100644 --- a/src/helpers/CommonCLI.cpp +++ b/src/helpers/CommonCLI.cpp @@ -609,6 +609,20 @@ struct CommonCLIImpl { strcpy(k.reply, "OK"); } } + static void setAdvertLoc(CommonCLI& c, CliCall& k) { + if (memcmp(k.arg, "none", 4) == 0) { + c._prefs->advert_loc_policy = ADVERT_LOC_NONE; + } else if (memcmp(k.arg, "share", 5) == 0) { + c._prefs->advert_loc_policy = ADVERT_LOC_SHARE; + } else if (memcmp(k.arg, "prefs", 5) == 0) { + c._prefs->advert_loc_policy = ADVERT_LOC_PREFS; + } else { + strcpy(k.reply, "Error, invalid policy"); + return; + } + c.savePrefs(); + strcpy(k.reply, "OK"); + } static void setGuestPassword(CommonCLI& c, CliCall& k) { StrHelper::strncpy(c._prefs->guest_password, k.arg, sizeof(c._prefs->guest_password)); c.savePrefs(); @@ -845,6 +859,21 @@ struct CommonCLIImpl { static void getAdvertInterval(CommonCLI& c, CliCall& k) { sprintf(k.reply, "> %d", ((uint32_t) c._prefs->advert_interval) * 2); } + static void getAdvertLoc(CommonCLI& c, CliCall& k) { + switch (c._prefs->advert_loc_policy) { + case ADVERT_LOC_NONE: + strcpy(k.reply, "> none"); + break; + case ADVERT_LOC_PREFS: + strcpy(k.reply, "> prefs"); + break; + case ADVERT_LOC_SHARE: + strcpy(k.reply, "> share"); + break; + default: + strcpy(k.reply, "Error, invalid policy"); + } + } static void getGuestPassword(CommonCLI& c, CliCall& k) { sprintf(k.reply, "> %s", c._prefs->guest_password); } @@ -1183,6 +1212,7 @@ const CliCmd kSetCmds[] = { CLI_CMD("allow.read.only ", CLI_PREFIX, CLI_ANY, CommonCLIImpl::setAllowReadOnly), CLI_CMD("flood.advert.interval ", CLI_PREFIX, CLI_ANY, CommonCLIImpl::setFloodAdvertInterval), CLI_CMD("advert.interval ", CLI_PREFIX, CLI_ANY, CommonCLIImpl::setAdvertInterval), + CLI_CMD("advert.loc ", CLI_PREFIX, CLI_ANY, CommonCLIImpl::setAdvertLoc), CLI_CMD("guest.password ", CLI_PREFIX, CLI_ANY, CommonCLIImpl::setGuestPassword), CLI_CMD("prv.key ", CLI_PREFIX, CLI_ANY, CommonCLIImpl::setPrvKey), CLI_CMD("name ", CLI_PREFIX, CLI_ANY, CommonCLIImpl::setName), @@ -1219,6 +1249,7 @@ const CliCmd kGetCmds[] = { CLI_CMD("allow.read.only", CLI_PREFIX, CLI_ANY, CommonCLIImpl::getAllowReadOnly), CLI_CMD("flood.advert.interval", CLI_PREFIX, CLI_ANY, CommonCLIImpl::getFloodAdvertInterval), CLI_CMD("advert.interval", CLI_PREFIX, CLI_ANY, CommonCLIImpl::getAdvertInterval), + CLI_CMD("advert.loc", CLI_PREFIX, CLI_ANY, CommonCLIImpl::getAdvertLoc), CLI_CMD("guest.password", CLI_PREFIX, CLI_ANY, CommonCLIImpl::getGuestPassword), CLI_CMD("prv.key", CLI_PREFIX, CLI_SERIAL, CommonCLIImpl::getPrvKey), CLI_CMD("name", CLI_PREFIX, CLI_ANY, CommonCLIImpl::getName), diff --git a/src/helpers/sensors/EnvironmentSensorManager.cpp b/src/helpers/sensors/EnvironmentSensorManager.cpp index 8d2b2c845a8..0237624991a 100644 --- a/src/helpers/sensors/EnvironmentSensorManager.cpp +++ b/src/helpers/sensors/EnvironmentSensorManager.cpp @@ -1,9 +1,6 @@ #include "EnvironmentSensorManager.h" #include -#if ENV_INCLUDE_GPS && defined(GPS_GUARD) -#include -#endif #if ENV_PIN_SDA && ENV_PIN_SCL #define TELEM_WIRE &Wire1 // Use Wire1 as the I2C bus for Environment Sensors @@ -655,13 +652,6 @@ bool EnvironmentSensorManager::querySensors(uint8_t requester_permissions, Cayen _active_sensors[i].query(next_available_channel, _active_sensors[i].sub_channel, telemetry); next_available_channel++; } - #if ENV_INCLUDE_GPS && defined(GPS_GUARD) - // GPS-vs-clock offset in hours on its own channel while the guard's time alert is active - GpsGuard* guard = _location->getGuard(); - if (guard != nullptr && guard->isTimeAlert()) { - telemetry.addAnalogInput(next_available_channel++, guard->getAlertOffset() / 3600.0f); - } - #endif } return true; diff --git a/src/helpers/sensors/GpsGuard.h b/src/helpers/sensors/GpsGuard.h index cf7130333aa..46b1936caae 100644 --- a/src/helpers/sensors/GpsGuard.h +++ b/src/helpers/sensors/GpsGuard.h @@ -133,7 +133,6 @@ class GpsGuard { strcpy(_time_status, "-"); } bool isTimeAlert() const { return _time_alert; } - long getAlertOffset() const { return _time_disagree_offset; } // Fix as reported by the receiver: lat/lon in micro-degrees, HDOP in tenths (255 = unknown), // gps_time = UTC epoch of the fix. Returns true if the fix can be stored as trusted. @@ -280,16 +279,17 @@ class GpsGuard { return true; } - // e.g. "ok 7sat time ok +1s", "rej region time rej nofix", + // e.g. "ok 7sat time ok +1s", "ok 7sat time wait", "rej region time rej nofix", // "ok 9sat time rej step 3600s ALERT gps-clk +3600s 75m" void formatStatus(char* out, size_t out_size) const { if (!_enabled) { snprintf(out, out_size, "off"); return; } - // The time status is only refreshed when a sync is due: without a current trusted fix, - // do not keep showing an old "ok" as if GPS time were usable now. - const char* time_status = (_time_status[0] == 'o' && !trustedFixIsCurrent()) ? "rej nofix" : _time_status; + // The time status is only refreshed when a sync is due. Without a current trusted fix + // (e.g. GPS asleep between periodic fixes) an old "ok" is not shown as current: the last + // check passed and the next one waits for a trusted fix. + const char* time_status = (_time_status[0] == 'o' && !trustedFixIsCurrent()) ? "wait" : _time_status; if (_time_alert) { snprintf(out, out_size, "%s time %s ALERT gps-clk %+lds %lum", _fix_status, time_status, _time_disagree_offset, (unsigned long)((uint32_t)(millis() - _time_disagree_since_ms) / 60000)); diff --git a/src/helpers/sensors/MicroNMEALocationProvider.h b/src/helpers/sensors/MicroNMEALocationProvider.h index bc9f5efa764..09b4d955461 100644 --- a/src/helpers/sensors/MicroNMEALocationProvider.h +++ b/src/helpers/sensors/MicroNMEALocationProvider.h @@ -23,7 +23,12 @@ #endif class MicroNMEALocationProvider : public LocationProvider { - char _nmeaBuffer[100]; + // MicroNMEA never writes past the length it is given, but its fixed-width field + // skips can read a few bytes past the end of a malformed sentence. The zeroed tail + // lets those reads stop on NUL bytes instead of reading the members that follow. + static constexpr size_t NMEA_BUFFER_LEN = 100; + static constexpr size_t NMEA_BUFFER_TAIL = 16; + char _nmeaBuffer[NMEA_BUFFER_LEN + NMEA_BUFFER_TAIL] = {}; MicroNMEA nmea; mesh::RTCClock* _clock; NmeaGpsDriver* _driver; @@ -135,7 +140,7 @@ class MicroNMEALocationProvider : public LocationProvider { public: MicroNMEALocationProvider(NmeaGpsDriver& driver, mesh::RTCClock* clock = nullptr) - : nmea(_nmeaBuffer, sizeof(_nmeaBuffer)), _clock(clock), _driver(&driver) {} + : nmea(_nmeaBuffer, NMEA_BUFFER_LEN), _clock(clock), _driver(&driver) {} void begin() override { _begin_calls++; diff --git a/src/helpers/sensors/NmeaGpsDriver.h b/src/helpers/sensors/NmeaGpsDriver.h index dfe75a4f8f4..9beacdc2fde 100644 --- a/src/helpers/sensors/NmeaGpsDriver.h +++ b/src/helpers/sensors/NmeaGpsDriver.h @@ -64,6 +64,18 @@ #endif #endif +// Optional rates detect() tries after GPS_BAUD_RATE, for GPS modules whose baud rate is +// not known in advance (e.g. -D GPS_BAUD_PROBE_LIST=9600,115200,38400). Used by every +// NmeaGpsDriver that does not pass its own list. +#ifdef GPS_BAUD_PROBE_LIST + static const uint32_t NMEA_GPS_PROBE_BAUDS[] = { GPS_BAUD_PROBE_LIST }; + #define GPS_PROBE_BAUDS NMEA_GPS_PROBE_BAUDS + #define GPS_PROBE_COUNT ((uint8_t)(sizeof(NMEA_GPS_PROBE_BAUDS) / sizeof(NMEA_GPS_PROBE_BAUDS[0]))) +#else + #define GPS_PROBE_BAUDS nullptr + #define GPS_PROBE_COUNT 0 +#endif + #ifndef PIN_GPS_SWITCH #define PIN_GPS_SWITCH (-1) #endif @@ -199,7 +211,7 @@ class NmeaGpsDriver : public GpsDriver { uint32_t baudRate = GPS_BAUD_RATE, int hardwareEnablePin = PIN_GPS_SWITCH, int hardwareEnableActive = GPS_SWITCH_ACTIVE, - const uint32_t* probeBauds = nullptr, uint8_t probeCount = 0) + const uint32_t* probeBauds = GPS_PROBE_BAUDS, uint8_t probeCount = GPS_PROBE_COUNT) : _hardwareSerial(&serial), _peripheralPower(peripheralPower), _txPin(txPin), _rxPin(rxPin), _resetPin(resetPin), _enablePin(enablePin), _enableActive(enableActive), _resetActive(resetActive), _baudRate(baudRate), diff --git a/test/test_common_cli/test_cli_get.cpp b/test/test_common_cli/test_cli_get.cpp index 17ee654262a..f4a253bf5f8 100644 --- a/test/test_common_cli/test_cli_get.cpp +++ b/test/test_common_cli/test_cli_get.cpp @@ -246,3 +246,11 @@ TEST_F(CliTest, RadioSettingsKeepTheirOwnAnswersInTheGetChain) { EXPECT_EQ(run("get freq"), "> 869.6179809"); EXPECT_TRUE(takeCalls().empty()); } + +TEST_F(CliTest, GetAdvertLocShowsThePolicy) { + prefs.advert_loc_policy = ADVERT_LOC_NONE; EXPECT_EQ(run("get advert.loc"), "> none"); + prefs.advert_loc_policy = ADVERT_LOC_PREFS; EXPECT_EQ(run("get advert.loc"), "> prefs"); + prefs.advert_loc_policy = ADVERT_LOC_SHARE; EXPECT_EQ(run("get advert.loc"), "> share"); + prefs.advert_loc_policy = 9; EXPECT_EQ(run("get advert.loc"), "Error, invalid policy"); + EXPECT_TRUE(takeCalls().empty()); +} diff --git a/test/test_common_cli/test_cli_set.cpp b/test/test_common_cli/test_cli_set.cpp index ab8e9b016d7..183a24335e0 100644 --- a/test/test_common_cli/test_cli_set.cpp +++ b/test/test_common_cli/test_cli_set.cpp @@ -521,3 +521,28 @@ TEST_F(CliTest, RadioSettingsKeepTheirOwnAnswersInTheSetChain) { EXPECT_EQ(run("set cad on"), "OK"); EXPECT_EQ(takeCalls().size(), 4u); // each one saved } + +// ---- advert.loc (upstream #3815, replaces "gps advert", which stays in GPS builds) ------- + +TEST_F(CliTest, SetAdvertLocTakesEachPolicyAndSaves) { + EXPECT_EQ(run("set advert.loc none"), "OK"); + EXPECT_EQ(prefs.advert_loc_policy, ADVERT_LOC_NONE); + EXPECT_EQ(run("set advert.loc share"), "OK"); + EXPECT_EQ(prefs.advert_loc_policy, ADVERT_LOC_SHARE); + EXPECT_EQ(run("set advert.loc prefs"), "OK"); + EXPECT_EQ(prefs.advert_loc_policy, ADVERT_LOC_PREFS); + EXPECT_EQ(takeCalls().size(), 3u); // each one saved +} + +TEST_F(CliTest, SetAdvertLocWithAnUnknownPolicyAnswersErrorAndChangesNothing) { + prefs.advert_loc_policy = ADVERT_LOC_SHARE; + EXPECT_EQ(run("set advert.loc bogus"), "Error, invalid policy"); + EXPECT_EQ(run("set advert.loc "), "Error, invalid policy"); + EXPECT_EQ(prefs.advert_loc_policy, ADVERT_LOC_SHARE); + EXPECT_TRUE(takeCalls().empty()); +} + +TEST_F(CliTest, SetAdvertLocNeedsItsTrailingSpaceAndKeepsAdvertIntervalApart) { + EXPECT_EQ(run("set advert.loc"), "unknown config: advert.loc"); + EXPECT_EQ(run("set advert.interval 90"), "OK"); // still the interval row +} diff --git a/test/test_rak3401_board_startup/mocks/Arduino.h b/test/test_rak3401_board_startup/mocks/Arduino.h deleted file mode 100644 index d505af36a2f..00000000000 --- a/test/test_rak3401_board_startup/mocks/Arduino.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "../../mocks/Arduino.h" - -#define NRF52_POWER_MANAGEMENT 1 -#define PWRMGT_LPCOMP_AIN 3 -#define PWRMGT_LPCOMP_REFSEL 4 -#define PWRMGT_VOLTAGE_BOOTLOCK 3300 -#define SX126X_POWER_EN 21 -#define INPUT 0 -#define OUTPUT 1 -#define LOW 0 -#define HIGH 1 - -void pinMode(uint32_t pin, uint32_t mode); -void digitalWrite(uint32_t pin, uint32_t value); -void analogReadResolution(uint32_t bits); -uint32_t analogRead(uint32_t pin); diff --git a/test/test_rak3401_board_startup/mocks/Wire.h b/test/test_rak3401_board_startup/mocks/Wire.h deleted file mode 100644 index c24e6306529..00000000000 --- a/test/test_rak3401_board_startup/mocks/Wire.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -struct StartupWire { - void begin() {} -}; -inline StartupWire Wire; diff --git a/test/test_rak3401_board_startup/mocks/helpers/NRF52Board.h b/test/test_rak3401_board_startup/mocks/helpers/NRF52Board.h deleted file mode 100644 index 96c892ae2a6..00000000000 --- a/test/test_rak3401_board_startup/mocks/helpers/NRF52Board.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -#include -#include -#include - -#define SHUTDOWN_REASON_LOW_VOLTAGE 0x4C -#define SHUTDOWN_REASON_BOOT_PROTECT 0x42 - -struct PowerMgtConfig { - uint8_t lpcomp_ain_channel; - uint8_t lpcomp_refsel; - uint16_t voltage_bootlock; -}; - -namespace startup_test { -extern std::vector events; -extern bool permitBoot; -struct SystemOff { uint8_t reason; }; -} - -class NRF52Board { -protected: - bool checkBootVoltage(const PowerMgtConfig*) { - startup_test::events.push_back("voltage"); - if (!startup_test::permitBoot) initiateShutdown(SHUTDOWN_REASON_BOOT_PROTECT); - return true; - } - virtual void initiateShutdown(uint8_t reason) { enterSystemOff(reason); } - void configureVoltageWake(uint8_t, uint8_t) {} - void enterSystemOff(uint8_t reason) { - startup_test::events.push_back("off"); - throw startup_test::SystemOff{reason}; - } -public: - explicit NRF52Board(const char* = nullptr) {} - virtual uint16_t getBattMilliVolts() = 0; - virtual const char* getManufacturerName() const = 0; -}; - -class NRF52BoardDCDC : virtual public NRF52Board { -public: - void begin() {} -}; diff --git a/test/test_rak3401_board_startup/test_board_startup.cpp b/test/test_rak3401_board_startup/test_board_startup.cpp deleted file mode 100644 index 0bbf2e5aa08..00000000000 --- a/test/test_rak3401_board_startup/test_board_startup.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include -#include -// Exercise the real startup code with a power-management stub that stops at SYSTEMOFF. -#include "../../variants/rak3401/RAK3401Board.cpp" - -namespace startup_test { -std::vector events; -bool permitBoot; -std::array outputs; -rak3401::OnboardRadioState radioState; -} - -void pinMode(uint32_t, uint32_t) {} -void digitalWrite(uint32_t pin, uint32_t value) { startup_test::outputs.at(pin) = value; } -void analogReadResolution(uint32_t) {} -uint32_t analogRead(uint32_t) { return 2500; } - -rak3401::OnboardRadioState rak3401::sleepOnboardRadio() { - startup_test::events.push_back("onboard"); - return startup_test::radioState; -} - -class RakBoardStartup : public testing::Test { -protected: - void SetUp() override { - startup_test::events.clear(); - startup_test::outputs.fill(HIGH); - startup_test::permitBoot = true; - startup_test::radioState = rak3401::OnboardRadioState::Asleep; - } -}; - -TEST_F(RakBoardStartup, OnboardRadioHandledBeforeVoltageCheck) { - RAK3401Board board; - board.begin(); - EXPECT_EQ(startup_test::events, (std::vector{"onboard", "voltage"})); - EXPECT_EQ(startup_test::outputs.at(SX126X_POWER_EN), HIGH); - EXPECT_EQ(startup_test::outputs.at(PIN_3V3_EN), HIGH); -} - -TEST_F(RakBoardStartup, LowVoltageExitStillHandlesOnboardRadio) { - startup_test::permitBoot = false; - RAK3401Board board; - try { - board.begin(); - FAIL() << "Expected protective shutdown"; - } catch (const startup_test::SystemOff& off) { - EXPECT_EQ(off.reason, SHUTDOWN_REASON_BOOT_PROTECT); - } - EXPECT_EQ(startup_test::events, (std::vector{"onboard", "voltage", "off"})); - EXPECT_EQ(startup_test::outputs.at(SX126X_POWER_EN), LOW); - EXPECT_EQ(startup_test::outputs.at(PIN_3V3_EN), LOW); -} - -TEST_F(RakBoardStartup, OptionalRadioFailuresDoNotBypassBootProtection) { - for (auto state : {rak3401::OnboardRadioState::Absent, rak3401::OnboardRadioState::BusyTimeout, - rak3401::OnboardRadioState::SleepFailed}) { - startup_test::events.clear(); - startup_test::permitBoot = false; - startup_test::radioState = state; - RAK3401Board board; - EXPECT_THROW(board.begin(), startup_test::SystemOff); - EXPECT_EQ(startup_test::events, (std::vector{"onboard", "voltage", "off"})); - } -} - -int main(int argc, char** argv) { - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/test/test_rak3401_onboard_radio/test_onboard_radio.cpp b/test/test_rak3401_onboard_radio/test_onboard_radio.cpp deleted file mode 100644 index cc616612940..00000000000 --- a/test/test_rak3401_onboard_radio/test_onboard_radio.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include -#include -#include -#include "../../variants/rak3401/OnboardRadioSleep.h" - -namespace { -struct FakeRadioIO { - std::string version = "SX1261"; - std::array ready = {true, true, true}; - std::string calls; - unsigned waits = 0; - bool probePulls = true; - - void begin() { calls += "begin "; } - void reset() { calls += "reset "; } - bool waitBusy(bool high, unsigned timeout) { - calls += high ? "busy-high " : "busy-low "; - EXPECT_EQ(timeout, 20u); - if (high) EXPECT_FALSE(probePulls); - const bool result = ready.at(waits++); - return result; - } - void readVersion(char* out) { calls += "version "; memcpy(out, version.data(), 6); } - void releaseProbePulls() { calls += "release-pulls "; probePulls = false; } - void sleep() { EXPECT_FALSE(probePulls); calls += "sleep "; } - void end() { calls += "end "; } -}; -} - -TEST(RakOnboardRadio, PresentRadioSleepsBeforeBusRelease) { - FakeRadioIO io; - EXPECT_EQ(rak3401::sleepOnboardRadio(io, "SX1261"), rak3401::OnboardRadioState::Asleep); - EXPECT_EQ(io.calls, "begin reset busy-low version release-pulls busy-low sleep busy-high end "); -} - -TEST(RakOnboardRadio, AbsentAndFloatingResponsesNeverReceiveSleep) { - for (const std::string version : {std::string(6, '\0'), std::string(6, '\xff'), std::string("SX126X")}) { - FakeRadioIO io; - io.version = version; - EXPECT_EQ(rak3401::sleepOnboardRadio(io, "SX1261"), rak3401::OnboardRadioState::Absent); - EXPECT_EQ(io.calls, "begin reset busy-low version end "); - } -} - -TEST(RakOnboardRadio, BusyTimeoutsReleaseBusWithoutSleep) { - for (unsigned failure = 0; failure < 2; failure++) { - FakeRadioIO io; - io.ready[failure] = false; - EXPECT_EQ(rak3401::sleepOnboardRadio(io, "SX1261"), rak3401::OnboardRadioState::BusyTimeout); - EXPECT_EQ(io.calls.find("sleep "), std::string::npos); - EXPECT_EQ(io.calls, failure == 0 ? "begin reset busy-low end " : - "begin reset busy-low version release-pulls busy-low end "); - } -} - -TEST(RakOnboardRadio, MissingSleepReadbackIsReportedAndBusReleased) { - FakeRadioIO io; - io.ready[2] = false; - EXPECT_EQ(rak3401::sleepOnboardRadio(io, "SX1261"), rak3401::OnboardRadioState::SleepFailed); - EXPECT_EQ(io.calls.substr(io.calls.size() - 4), "end "); -} - -int main(int argc, char** argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/variants/promicro/target.cpp b/variants/promicro/target.cpp index 1c3e7a8d083..cd9d78df4df 100644 --- a/variants/promicro/target.cpp +++ b/variants/promicro/target.cpp @@ -6,12 +6,7 @@ PromicroBoard board; #if ENV_INCLUDE_GPS #include - #ifdef GPS_BAUD_PROBE_LIST // e.g. -D GPS_BAUD_PROBE_LIST=9600,38400,115200 - static const uint32_t gps_probe_bauds[] = { GPS_BAUD_PROBE_LIST }; - NmeaGpsDriver gps_driver(Serial1, gps_probe_bauds, sizeof(gps_probe_bauds) / sizeof(gps_probe_bauds[0])); - #else - NmeaGpsDriver gps_driver(Serial1); - #endif + NmeaGpsDriver gps_driver(Serial1); MicroNMEALocationProvider nmea(gps_driver, &rtc_clock); EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea); #else diff --git a/variants/station_g2/platformio.ini b/variants/station_g2/platformio.ini index c1ae765fede..c4fd344ddea 100644 --- a/variants/station_g2/platformio.ini +++ b/variants/station_g2/platformio.ini @@ -25,6 +25,7 @@ build_flags = -D PIN_USER_BTN=38 -D PIN_GPS_RX=15 -D PIN_GPS_TX=7 + -D GPS_BAUD_PROBE_LIST=9600,115200,38400 ; Grove UART GPS units (e.g. M5Stack Unit GPS v1.1) default to 115200 -D SX126X_DIO2_AS_RF_SWITCH=true -D SX126X_DIO3_TCXO_VOLTAGE=1.8 -D SX126X_CURRENT_LIMIT=140 diff --git a/variants/station_g3_esp32/platformio.ini b/variants/station_g3_esp32/platformio.ini index 7006d939ee5..2ce8bb39244 100644 --- a/variants/station_g3_esp32/platformio.ini +++ b/variants/station_g3_esp32/platformio.ini @@ -29,6 +29,7 @@ build_flags = -D PIN_USER_BTN=38 -D PIN_GPS_RX=15 -D PIN_GPS_TX=7 + -D GPS_BAUD_PROBE_LIST=9600,115200,38400 ; Grove UART GPS units (e.g. M5Stack Unit GPS v1.1) default to 115200 -D SX126X_DIO2_AS_RF_SWITCH=true -D SX126X_DIO3_TCXO_VOLTAGE=1.8 -D SX126X_CURRENT_LIMIT=140