Compare commits

...
Author SHA1 Message Date
mikecarper bf389b34a1 Document Keymind branch settings 2026-05-22 15:15:36 -07:00
mikecarper 0b245d51bf Update Halo Keymind settings docs 2026-05-22 15:12:41 -07:00
mikecarper 1ded5b34e6 build.sh: show on-off prompts as on(1)/off(0) 2026-05-22 14:59:47 -07:00
mikecarper 815bd2c1c3 build.sh: accept 1/0 for on/off prompts 2026-05-22 14:59:47 -07:00
mikecarper 6d7dfa6814 build.sh: add interactive Wi-Fi build settings overrides 2026-05-22 14:59:47 -07:00
mikecarper f47b0872ac build.sh: fix radio override flags for PlatformIO ordering 2026-05-22 14:59:11 -07:00
mikecarper e1ba591a31 build.sh: retry radio preset API fetch with browser headers 2026-05-22 14:59:11 -07:00
mikecarper c3712737e9 build.sh: add optional Cascadia profile overrides 2026-05-22 14:41:37 -07:00
mikecarper c93d907e85 Make battery alert thresholds configurable 2026-05-22 14:34:19 -07:00
mikecarper f693bdb212 Add opt-in battery alert flood text 2026-05-22 14:28:03 -07:00
mikecarper c0e3860c3c Add repeater flood text command 2026-05-22 14:21:10 -07:00
mikecarper b59966b6fa Add direct path override support 2026-05-22 14:16:14 -07:00
mikecarper f32f12ccde Merge upstream main into keymind 2026-05-18 11:43:13 -07:00
ripplebiz c940ea5f30 Merge pull request #2567 from recrof/patch-4
Change MeshCore intro video link to The Comms Channel's MC intro playlist
2026-05-16 13:03:00 +10:00
Rastislav Vysoky d4c99dec65 Change MeshCore intro video link to The Comms Channel's MC intro playlist 2026-05-15 16:42:29 +02:00
ripplebiz 181a54e718 Merge pull request #2532 from swaits/fix/trace-offset-widening
fix(mesh): widen TRACE offset to uint16 to avoid narrowing
2026-05-15 13:17:03 +10:00
mikecarper 9ef5310651 Merge branch 'meshcore-dev:main' into keymind 2026-05-12 23:54:30 -07:00
Liam Cottle 910b1bee5b Merge pull request #2541 from AI7NC/patch-2
Update cli_commands.md to include 'ver'
2026-05-13 14:43:10 +12:00
AI7NC 16cb6d518f Update cli_commands.md to include 'ver'
Include the 'ver' command for retrieving the firmware version
2026-05-12 12:42:33 -07:00
Stephen Waits 09a27a2591 fix(mesh): widen TRACE offset to uint16 to avoid narrowing 2026-05-11 19:32:56 -06:00
12 changed files with 1266 additions and 39 deletions

No files matched your search

+1 -1
View File
@@ -28,7 +28,7 @@ MeshCore provides the ability to create wireless mesh networks, similar to Mesht
## 🚀 How to Get Started
- Watch the [MeshCore Intro Video](https://www.youtube.com/watch?v=t1qne8uJBAc) by Andy Kirby.
- Watch the [MeshCore QuickStart Playlist](https://www.youtube.com/watch?v=iaFltojJrAc&list=PLshzThxhw4O4WU_iZo3NmNZOv6KMrUuF9) by The Comms Channel
- Watch the [MeshCore Technical Presentation](https://www.youtube.com/watch?v=OwmkVkZQTf4) by Liam Cottle.
- Read through our [Frequently Asked Questions](./docs/faq.md) and [Documentation](https://docs.meshcore.io).
- Flash the MeshCore firmware on a supported device.
+487 -4
View File
@@ -4,6 +4,19 @@ ALL_PIO_ENVS=()
PIO_CONFIG_JSON=""
MENU_CHOICE=""
SELECTED_TARGET=""
SELECTED_COMMAND_ARGS=()
MESHDEBUG_OVERRIDE=""
PACKET_LOGGING_OVERRIDE=""
RADIO_SETTINGS_API_URL="https://api.meshcore.nz/api/v1/config"
RADIO_SETTING_TITLE=""
RADIO_FREQ_OVERRIDE=""
RADIO_BW_OVERRIDE=""
RADIO_SF_OVERRIDE=""
RADIO_CR_OVERRIDE=""
FIRMWARE_PROFILE_OVERRIDE=""
WIFI_SSID_OVERRIDE=""
WIFI_PWD_OVERRIDE=""
WIFI_DEBUG_LOGGING_OVERRIDE=""
ENV_VARIANT_SUFFIX_PATTERN='companion_radio_serial|companion_radio_wifi|companion_radio_usb|comp_radio_usb|companion_usb|companion_radio_ble|companion_ble|repeater_bridge_rs232_serial1|repeater_bridge_rs232_serial2|repeater_bridge_rs232|repeater_bridge_espnow|terminal_chat|room_server|room_svr|kiss_modem|sensor|repeatr|repeater'
BOARD_MODIFIER_WITHOUT_DISPLAY="_without_display"
@@ -51,7 +64,7 @@ Examples:
Build firmware for the "RAK_4631_repeater" device target
$ bash build.sh build-firmware RAK_4631_repeater
Run without arguments to choose a target from an interactive menu
Run without arguments to choose an interactive build action/target, debug options, radio settings, and (when applicable) Wi-Fi settings
$ bash build.sh
Build all firmwares for device targets containing the string "RAK_4631"
@@ -187,6 +200,399 @@ prompt_menu_choice() {
done
}
prompt_on_off_choice() {
local prompt_label=$1
local default_choice=$2
local normalized_default
local choice
normalized_default=${default_choice,,}
case "$normalized_default" in
1) normalized_default="on" ;;
0) normalized_default="off" ;;
esac
while true; do
read -r -p "${prompt_label} [on(1)/off(0)] (default: ${normalized_default}): " choice
choice=${choice,,}
if [ -z "$choice" ]; then
choice=$normalized_default
fi
case "$choice" in
on|1)
MENU_CHOICE="on"
return 0
;;
off|0)
MENU_CHOICE="off"
return 0
;;
*)
echo "Invalid selection. Choose on(1) or off(0)."
;;
esac
done
}
prompt_for_build_mode() {
local options=(
"Build one firmware target"
"Build all firmwares"
"Build all repeater firmwares"
"Build all companion firmwares"
"Build all chat room server firmwares"
)
echo "No command provided. Select a build action:"
while true; do
print_numbered_menu "${options[@]}"
prompt_menu_choice "Build action" "${#options[@]}"
if [ "$MENU_CHOICE" == "QUIT" ]; then
echo "Cancelled."
exit 1
fi
case "$MENU_CHOICE" in
1)
prompt_for_board_target
SELECTED_COMMAND_ARGS=(build-firmware "$SELECTED_TARGET")
return 0
;;
2)
SELECTED_COMMAND_ARGS=(build-firmwares)
return 0
;;
3)
SELECTED_COMMAND_ARGS=(build-repeater-firmwares)
return 0
;;
4)
SELECTED_COMMAND_ARGS=(build-companion-firmwares)
return 0
;;
5)
SELECTED_COMMAND_ARGS=(build-room-server-firmwares)
return 0
;;
esac
done
}
prompt_for_debug_build_settings() {
echo "Set debug build options:"
prompt_on_off_choice "Mesh debug (MESH_DEBUG)" "off"
MESHDEBUG_OVERRIDE="$MENU_CHOICE"
prompt_on_off_choice "Packet logging (MESH_PACKET_LOGGING)" "off"
PACKET_LOGGING_OVERRIDE="$MENU_CHOICE"
echo "Using debug options: meshdebug=${MESHDEBUG_OVERRIDE}, packet_logging=${PACKET_LOGGING_OVERRIDE}"
}
clear_radio_overrides() {
RADIO_SETTING_TITLE=""
RADIO_FREQ_OVERRIDE=""
RADIO_BW_OVERRIDE=""
RADIO_SF_OVERRIDE=""
RADIO_CR_OVERRIDE=""
}
clear_firmware_profile_overrides() {
FIRMWARE_PROFILE_OVERRIDE=""
}
set_radio_overrides() {
RADIO_SETTING_TITLE=$1
RADIO_FREQ_OVERRIDE=$2
RADIO_BW_OVERRIDE=$3
RADIO_SF_OVERRIDE=$4
RADIO_CR_OVERRIDE=$5
}
fetch_suggested_radio_settings() {
python3 - "$RADIO_SETTINGS_API_URL" <<'PY'
import json
import sys
import urllib.error
import urllib.request
url = sys.argv[1]
header_sets = [
{
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",
"Accept": "application/json,text/plain,*/*",
"Accept-Language": "en-US,en;q=0.9",
"Referer": "https://meshcore.nz/",
"Origin": "https://meshcore.nz",
},
{
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:125.0) Gecko/20100101 Firefox/125.0",
"Accept": "application/json,text/plain,*/*",
"Accept-Language": "en-US,en;q=0.9",
"Referer": "https://meshcore.nz/",
"Origin": "https://meshcore.nz",
},
]
payload = None
errors = []
for index, headers in enumerate(header_sets, start=1):
req = urllib.request.Request(url, headers=headers)
try:
with urllib.request.urlopen(req, timeout=8) as response:
payload = json.load(response)
break
except urllib.error.HTTPError as exc:
errors.append(f"attempt {index}: HTTP {exc.code}")
continue
except Exception as exc:
errors.append(f"attempt {index}: {type(exc).__name__}")
continue
if payload is None:
summary = "; ".join(errors) if errors else "unknown error"
print(f"Failed to fetch radio presets from {url} ({summary})", file=sys.stderr)
raise SystemExit(1)
entries = (
payload.get("config", {})
.get("suggested_radio_settings", {})
.get("entries", [])
)
for entry in entries:
title = str(entry.get("title", "")).strip()
description = str(entry.get("description", "")).strip()
freq = str(entry.get("frequency", "")).strip()
sf = str(entry.get("spreading_factor", "")).strip()
bw = str(entry.get("bandwidth", "")).strip()
cr = str(entry.get("coding_rate", "")).strip()
if title and freq and sf and bw and cr:
print("\t".join([title, description, freq, bw, sf, cr]))
PY
}
is_valid_custom_radio_bandwidth() {
python3 - "$1" <<'PY'
import sys
allowed = [7.81, 10.42, 15.63, 20.83, 31.25, 41.67, 62.5, 125.0, 250.0, 500.0]
try:
value = float(sys.argv[1])
except Exception:
raise SystemExit(1)
raise SystemExit(0 if any(abs(value - option) < 1e-6 for option in allowed) else 1)
PY
}
prompt_for_custom_radio_setting() {
local freq
local sf
local bw
local cr
echo
echo "Custom radio settings:"
while true; do
read -r -p "Center frequency (MHz, e.g. 915.000): " freq
if [[ "$freq" =~ ^[0-9]+([.][0-9]+)?$ ]]; then
break
fi
echo "Please enter a numeric MHz value (e.g. 915.000)."
done
echo "Spreading factor options: 5, 6, 7, 8, 9, 10, 11, 12"
while true; do
read -r -p "SF (5-12): " sf
if [[ "$sf" =~ ^[0-9]+$ ]] && [ "$sf" -ge 5 ] && [ "$sf" -le 12 ]; then
break
fi
echo "Please enter 5, 6, 7, 8, 9, 10, 11, or 12."
done
echo "Bandwidth options (kHz): 7.81 10.42 15.63 20.83 31.25 41.67 62.5 125 250 500"
while true; do
read -r -p "BW (kHz): " bw
if [[ "$bw" =~ ^[0-9]+([.][0-9]+)?$ ]] && is_valid_custom_radio_bandwidth "$bw"; then
break
fi
echo "Please enter one of: 7.81 10.42 15.63 20.83 31.25 41.67 62.5 125 250 500."
done
echo "Coding rate options: CR5, CR6, CR7, CR8"
while true; do
read -r -p "CR (5-8): " cr
if [[ "$cr" =~ ^[0-9]+$ ]] && [ "$cr" -ge 5 ] && [ "$cr" -le 8 ]; then
break
fi
echo "Please enter 5, 6, 7, or 8."
done
set_radio_overrides "Custom" "$freq" "$bw" "$sf" "$cr"
}
prompt_for_cascadia_profile_enable() {
clear_firmware_profile_overrides
echo
echo "Cascadia profile changes:"
echo " - rxdelay: 1"
echo " - agc.reset.interval: 8"
echo " - advert.interval: 0"
echo " - flood.advert.interval: 83"
echo " - multi.acks: 1"
echo " - path.hash.mode: 2"
echo " - loop.detect: minimal"
echo " - powersaving: on"
prompt_on_off_choice "Enable Cascadia profile overrides" "on"
if [ "$MENU_CHOICE" == "on" ]; then
FIRMWARE_PROFILE_OVERRIDE="cascadia"
echo "Using firmware profile override: ${FIRMWARE_PROFILE_OVERRIDE}"
return 0
fi
echo "Using target default firmware profile settings."
return 0
}
prompt_for_radio_build_settings() {
local -a preset_rows=()
local -a options=("Keep target defaults (no radio override)")
local row
local title
local description
local freq
local bw
local sf
local cr
local preset_index
local choice_index
local custom_index
clear_radio_overrides
if mapfile -t preset_rows < <(fetch_suggested_radio_settings); then
for row in "${preset_rows[@]}"; do
IFS=$'\t' read -r title description freq bw sf cr <<< "$row"
options+=("${title}: ${description}")
done
else
echo "Could not fetch radio presets from ${RADIO_SETTINGS_API_URL}."
preset_rows=()
fi
options+=("Custom")
custom_index=${#options[@]}
echo "Set radio build options:"
while true; do
print_numbered_menu "${options[@]}"
prompt_menu_choice "Radio setting" "${#options[@]}"
if [ "$MENU_CHOICE" == "QUIT" ]; then
echo "Cancelled."
exit 1
fi
choice_index=$MENU_CHOICE
if [ "$choice_index" -eq 1 ]; then
echo "Using target default radio settings."
return 0
fi
if [ "$choice_index" -eq "$custom_index" ]; then
prompt_for_custom_radio_setting
echo "Using radio setting: ${RADIO_SETTING_TITLE} (${RADIO_FREQ_OVERRIDE}MHz / SF${RADIO_SF_OVERRIDE} / BW${RADIO_BW_OVERRIDE} / CR${RADIO_CR_OVERRIDE})"
return 0
fi
preset_index=$((choice_index - 2))
if [ "$preset_index" -ge 0 ] && [ "$preset_index" -lt "${#preset_rows[@]}" ]; then
IFS=$'\t' read -r title description freq bw sf cr <<< "${preset_rows[$preset_index]}"
set_radio_overrides "$title" "$freq" "$bw" "$sf" "$cr"
echo "Using radio setting: ${RADIO_SETTING_TITLE} (${RADIO_FREQ_OVERRIDE}MHz / SF${RADIO_SF_OVERRIDE} / BW${RADIO_BW_OVERRIDE} / CR${RADIO_CR_OVERRIDE})"
return 0
fi
done
}
clear_wifi_overrides() {
WIFI_SSID_OVERRIDE=""
WIFI_PWD_OVERRIDE=""
WIFI_DEBUG_LOGGING_OVERRIDE=""
}
is_wifi_build_target() {
local env_name=$1
local is_wifi=1
shopt -s nocasematch
if [[ "$env_name" == *companion_radio_wifi* ]]; then
is_wifi=0
fi
shopt -u nocasematch
return "$is_wifi"
}
selected_command_uses_wifi_target() {
case "${SELECTED_COMMAND_ARGS[0]:-}" in
build-firmware)
is_wifi_build_target "${SELECTED_COMMAND_ARGS[1]:-}"
return $?
;;
*)
return 1
;;
esac
}
prompt_for_wifi_build_settings() {
local -a options=(
"Keep target defaults (no Wi-Fi override)"
"Custom Wi-Fi SSID/password"
)
local choice_index
clear_wifi_overrides
echo "Set Wi-Fi build options:"
while true; do
print_numbered_menu "${options[@]}"
prompt_menu_choice "Wi-Fi setting" "${#options[@]}"
if [ "$MENU_CHOICE" == "QUIT" ]; then
echo "Cancelled."
exit 1
fi
choice_index=$MENU_CHOICE
case "$choice_index" in
1)
echo "Using target default Wi-Fi settings."
return 0
;;
2)
read -r -p "Wi-Fi SSID: " WIFI_SSID_OVERRIDE
read -r -p "Wi-Fi password (blank allowed): " WIFI_PWD_OVERRIDE
prompt_on_off_choice "Wi-Fi debug logging (WIFI_DEBUG_LOGGING)" "off"
WIFI_DEBUG_LOGGING_OVERRIDE="$MENU_CHOICE"
echo "Using Wi-Fi overrides: ssid='${WIFI_SSID_OVERRIDE}', wifi_debug=${WIFI_DEBUG_LOGGING_OVERRIDE}"
return 0
;;
esac
done
}
escape_cpp_string_literal() {
local value=$1
value=${value//\\/\\\\}
value=${value//\"/\\\"}
printf '%s' "$value"
}
get_env_metadata() {
local env_name=$1
local trimmed_env_name
@@ -394,7 +800,7 @@ prompt_for_board_target() {
mapfile -t boards < <(printf '%s\n' "${boards[@]}" | sort_lines_case_insensitive)
echo "No command provided. Select a board family:"
echo "Select a board family:"
while true; do
print_numbered_menu "${boards[@]}"
prompt_menu_choice "Board selection" "${#boards[@]}"
@@ -523,6 +929,71 @@ disable_debug_flags() {
fi
}
apply_debug_overrides() {
case "${MESHDEBUG_OVERRIDE,,}" in
on)
export PLATFORMIO_BUILD_FLAGS="${PLATFORMIO_BUILD_FLAGS} -UMESH_DEBUG -DMESH_DEBUG=1"
;;
off)
export PLATFORMIO_BUILD_FLAGS="${PLATFORMIO_BUILD_FLAGS} -UMESH_DEBUG"
;;
esac
case "${PACKET_LOGGING_OVERRIDE,,}" in
on)
export PLATFORMIO_BUILD_FLAGS="${PLATFORMIO_BUILD_FLAGS} -UMESH_PACKET_LOGGING -DMESH_PACKET_LOGGING=1"
;;
off)
export PLATFORMIO_BUILD_FLAGS="${PLATFORMIO_BUILD_FLAGS} -UMESH_PACKET_LOGGING"
;;
esac
}
apply_radio_overrides() {
if [ -n "$RADIO_FREQ_OVERRIDE" ] && [ -n "$RADIO_BW_OVERRIDE" ] && [ -n "$RADIO_SF_OVERRIDE" ] && [ -n "$RADIO_CR_OVERRIDE" ]; then
export PLATFORMIO_BUILD_FLAGS="${PLATFORMIO_BUILD_FLAGS} -DLORA_FREQ=${RADIO_FREQ_OVERRIDE} -DLORA_BW=${RADIO_BW_OVERRIDE} -DLORA_SF=${RADIO_SF_OVERRIDE} -DLORA_CR=${RADIO_CR_OVERRIDE}"
fi
}
apply_firmware_profile_overrides() {
case "${FIRMWARE_PROFILE_OVERRIDE,,}" in
cascadia)
export PLATFORMIO_BUILD_FLAGS="${PLATFORMIO_BUILD_FLAGS} -DCASCADIA_PROFILE=1 -DDEFAULT_RX_DELAY_BASE=1.0f -DDEFAULT_LOOP_DETECT=1 -DDEFAULT_POWERSAVING_ENABLED=1 -DDEFAULT_AGC_RESET_INTERVAL=2 -DDEFAULT_ADVERT_INTERVAL=0 -DDEFAULT_FLOOD_ADVERT_INTERVAL=83 -DDEFAULT_MULTI_ACKS=1 -DDEFAULT_PATH_HASH_MODE=2"
;;
esac
}
apply_wifi_overrides() {
local env_name=$1
local ssid_escaped
local pwd_escaped
if ! is_wifi_build_target "$env_name"; then
return 0
fi
if [ -n "$WIFI_SSID_OVERRIDE" ]; then
ssid_escaped=$(escape_cpp_string_literal "$WIFI_SSID_OVERRIDE")
export PLATFORMIO_BUILD_FLAGS="${PLATFORMIO_BUILD_FLAGS} -D WIFI_SSID='\"${ssid_escaped}\"'"
fi
if [ -n "$WIFI_SSID_OVERRIDE" ] || [ -n "$WIFI_PWD_OVERRIDE" ]; then
pwd_escaped=$(escape_cpp_string_literal "$WIFI_PWD_OVERRIDE")
export PLATFORMIO_BUILD_FLAGS="${PLATFORMIO_BUILD_FLAGS} -D WIFI_PWD='\"${pwd_escaped}\"'"
fi
case "${WIFI_DEBUG_LOGGING_OVERRIDE,,}" in
on)
export PLATFORMIO_BUILD_FLAGS="${PLATFORMIO_BUILD_FLAGS} -D WIFI_DEBUG_LOGGING=1"
;;
off)
if [ -n "$WIFI_SSID_OVERRIDE" ] || [ -n "$WIFI_PWD_OVERRIDE" ]; then
export PLATFORMIO_BUILD_FLAGS="${PLATFORMIO_BUILD_FLAGS} -D WIFI_DEBUG_LOGGING=0"
fi
;;
esac
}
copy_build_output() {
local source_path=$1
local output_path=$2
@@ -616,6 +1087,10 @@ build_firmware() {
export PLATFORMIO_BUILD_FLAGS="${PLATFORMIO_BUILD_FLAGS} -DFIRMWARE_BUILD_DATE='\"${firmware_build_date}\"' -DFIRMWARE_VERSION='\"${firmware_version_string}\"'"
disable_debug_flags
apply_debug_overrides
apply_radio_overrides
apply_firmware_profile_overrides
apply_wifi_overrides "$env_name"
pio run -e "$env_name"
collect_build_artifacts "$env_name" "$env_platform" "$firmware_filename"
@@ -734,8 +1209,16 @@ main() {
init_project_context
if [ $# -eq 0 ]; then
prompt_for_board_target
set -- build-firmware "$SELECTED_TARGET"
prompt_for_build_mode
prompt_for_debug_build_settings
prompt_for_radio_build_settings
prompt_for_cascadia_profile_enable
if selected_command_uses_wifi_target; then
prompt_for_wifi_build_settings
else
clear_wifi_overrides
fi
set -- "${SELECTED_COMMAND_ARGS[@]}"
fi
prepare_output_dir
+68
View File
@@ -115,6 +115,42 @@ This document provides an overview of CLI commands that can be sent to MeshCore
---
### Send flood text to `#repeaters` channel
**Usage:**
- `send text.flood <message>`
**Notes:**
- Sends a `PAYLOAD_TYPE_GRP_TXT` flood message using the built-in `#repeaters` channel key.
- Message format is `<node_name>: <message>`.
---
### View or change automatic low-battery alerts to `#repeaters`
**Usage:**
- `get battery.alert`
- `set battery.alert <state>`
- `get battery.alert.low`
- `set battery.alert.low <percent>`
- `get battery.alert.critical`
- `set battery.alert.critical <percent>`
**Parameters:**
- `state`: `on` (enable) or `off` (disable)
- `percent`: Battery percentage threshold
**Default:** `off`
**Default thresholds:** `20` for `battery.alert.low`, `10` for `battery.alert.critical`
**Notes:**
- When enabled, sends a `#repeaters` flood text warning if voltage is above `1 V` and the battery estimate is below `battery.alert.low`.
- Warnings repeat every `24` hours, or every `12` hours below `battery.alert.critical`.
- `battery.alert.critical` must be lower than `battery.alert.low`.
---
### Get or set recent repeater fallback prefix/SNR
**Usage:**
- `get recent.repeater`
@@ -134,6 +170,7 @@ This document provides an overview of CLI commands that can be sent to MeshCore
- If a full failure has no row yet, it first seeds the row at the active retry cutoff + `2.5 dB`, then applies the `0.25 dB` penalty.
- Serial CLI page size is fixed at `128` rows; choose page with `get recent.repeater <page>`.
- Over LoRa remote CLI, page size is fixed at `7` rows; choose page with `get recent.repeater <page>`.
- Repeaters can use adjacent entries in this table to short-circuit non-TRACE direct packets when this node appears later in the direct path.
---
@@ -441,6 +478,11 @@ This document provides an overview of CLI commands that can be sent to MeshCore
---
#### View this node's firmware version
**Usage:** `ver`
---
#### View this node's configured role
**Usage:** `get role`
@@ -796,6 +838,8 @@ This document provides an overview of CLI commands that can be sent to MeshCore
**Default:** `2` for `rooftop`, `1` for `infra` and `mobile`
**Note:** Prefixes in `flood.retry.ignore` do not count toward this path length.
---
#### View or change whether advert packets are flood-retried
@@ -895,6 +939,30 @@ This document provides an overview of CLI commands that can be sent to MeshCore
---
#### View or set direct path overrides for the current remote client
**Usage:**
- `get outpath`
- `set outpath <hop1_hex,hop2_hex,...>`
- `set outpath clear`
- `set outpath flood`
- `get altpath`
- `set altpath <hop1_hex,hop2_hex,...>`
- `set altpath clear`
**Parameters:**
- `hopN_hex`: Hop hash, `2`, `4`, or `6` hex characters. All hops must use the same width.
**Notes:**
- These commands require remote client context; they target the caller's ACL entry.
- The path hash size is inferred from the hop hash width.
- `outpath` overrides the primary direct route used for replies to the caller.
- `clear` forgets the current direct path and allows normal path discovery to repopulate it.
- `flood` forces replies to use flood packets until the client logs in again.
- `altpath` is an optional second direct route used for duplicate response attempts.
- `set altpath clear` removes the duplicate route so only one reply is sent.
---
#### View or change this room server's 'read-only' flag
**Usage:**
- `get allow.read.only`
+80 -11
View File
@@ -1,11 +1,10 @@
# Halo and Keymind Branch Settings
This file covers only CLI settings added by the Halo or Keymind branches. Use
`docs/cli_commands.md` for the general MeshCore CLI.
This file covers only CLI settings and helper commands added by the Halo or
Keymind branches. Use `docs/cli_commands.md` for the general MeshCore CLI.
## Quick Start
```text
set retry.preset rooftop
set direct.retry.heard on
@@ -25,7 +24,7 @@ get flood.retry.prefixes
get flood.retry.ignore
```
Use prefixes from the analyzer or neighbors list or `get recent.repeater` after the repeater has been online for a few hours.
Use prefixes from the analyzer or neighbors list or `get recent.repeater` after the repeater has been online for a few hours.
## Common Examples
@@ -36,23 +35,23 @@ set flood.retry.advert off
get flood.retry.advert
```
Ignore a repeater as a successful flood retry echo:
Use this if you have a car repeater and a house repeater; have the house ignore the car.
Ignore a repeater as a successful flood retry echo:
Use this if you have a car repeater and a house repeater; have the house ignore the car.
```text
set flood.retry.ignore 71CE82,C7618C
get flood.retry.ignore
```
Only accept specific downstream relays as flood retry success:
You're in a hole and need to hit a mountain top repeater to get out; keep trying till one you see one of these send out your packet.
Only accept specific downstream relays as flood retry success:
You're in a hole and need to hit a mountain top repeater to get out; keep trying till one you see one of these send out your packet.
```text
set flood.retry.prefixes A58296,860CCA,425E5C
get flood.retry.prefixes
```
Bridge two groups of repeaters:
Bridge two groups of repeaters:
```text
set flood.retry.bridge on
@@ -74,8 +73,44 @@ set flood.retry.ignore none
| Setting | What it does | How to use | Example |
| --- | --- | --- | --- |
| `recent.repeater` | Shows or seeds the recent repeater prefix/SNR table used by direct retry and bridge freshness checks. | `get recent.repeater`, `get recent.repeater <page>`, `set recent.repeater <prefix> <snr_db>` | `set recent.repeater A1B2C3 -8.5` |
| `radio.fem.rxgain` | Controls the external LoRa FEM receive-path LNA where the board supports it. | `get radio.fem.rxgain`, `set radio.fem.rxgain on/off` | `set radio.fem.rxgain on` |
| `battery.alert` | Sends opt-in low-battery warnings to `#repeaters`. | `get battery.alert`, `set battery.alert on/off` | `set battery.alert on` |
| `battery.alert.low` | Warning threshold percentage. Must be greater than `battery.alert.critical`. | `get battery.alert.low`, `set battery.alert.low <1-100>` | `set battery.alert.low 20` |
| `battery.alert.critical` | Critical threshold percentage. Critical warnings repeat more often. | `get battery.alert.critical`, `set battery.alert.critical <0-99>` | `set battery.alert.critical 10` |
| `recent.repeater` | Shows, seeds, or clears the recent repeater prefix/SNR table used by direct retry and bridge freshness checks. | `get recent.repeater`, `get recent.repeater <page>`, `set recent.repeater <prefix> <snr_db>`, `clear recent.repeater` | `set recent.repeater A1B2C3 -8.5` |
| `outpath` | Overrides the primary direct route used for replies to the current remote client. | `get outpath`, `set outpath <hops>`, `set outpath clear`, `set outpath flood` | `set outpath A1B2C3,D4E5F6` |
| `altpath` | Optional second direct route used for duplicate response attempts to the current remote client. | `get altpath`, `set altpath <hops>`, `set altpath clear` | `set altpath A1B2C3,D4E5F6` |
## Other Keymind Commands
| Command | What it does | How to use | Example |
| --- | --- | --- | --- |
| `send text.flood` | Sends a `#repeaters` flood text message formatted as `<node_name>: <message>`. | `send text.flood <message>` | `send text.flood checking ridge link` |
## Battery Alerts
Battery alerts are off by default. When enabled, the repeater checks once per
minute and sends a flood text warning to `#repeaters` when voltage is above
`1 V` and the estimated battery percent is below `battery.alert.low`.
Warnings repeat every `24` hours, or every `12` hours when the estimate is
below `battery.alert.critical`.
Defaults:
| Setting | Default |
| --- | ---: |
| `battery.alert` | `off` |
| `battery.alert.low` | `20` |
| `battery.alert.critical` | `10` |
Example:
```text
set battery.alert.low 20
set battery.alert.critical 10
set battery.alert on
get battery.alert
```
## Recent Repeater Table
@@ -88,6 +123,7 @@ Show learned rows:
```text
get recent.repeater
get recent.repeater 2
get recent.repeater page 3
```
Seed or correct a prefix:
@@ -96,9 +132,42 @@ Seed or correct a prefix:
set recent.repeater A1B2C3 8.5
```
Clear learned and manually seeded rows:
```text
clear recent.repeater
```
Rows are sorted by prefix width, then SNR. A full direct retry failure lowers
the matching row by `0.25 dB`.
Serial CLI pages contain up to `128` rows. Remote LoRa CLI pages contain up to
`7` rows.
## Direct Path Overrides
`outpath` and `altpath` apply to the current remote client ACL entry. They need
remote client context, so they are not useful from the local serial CLI.
Set paths with comma-separated hop hashes. Each hop must be `2`, `4`, or `6`
hex characters, and all hops in one path must use the same width.
```text
get outpath
set outpath A1B2C3,D4E5F6
set outpath clear
set outpath flood
get altpath
set altpath A1B2C3,D4E5F6
set altpath clear
```
`set outpath clear` forgets the override and lets normal path discovery fill it
again. `set outpath flood` forces replies to use flood packets until the client
logs in again. `altpath` sends a duplicate reply over a second direct route;
clearing it returns replies to a single route.
## Direct Retry Settings
Direct retry applies to direct-routed packets. A queued resend is canceled when the next-hop echo is heard.
+553 -17
View File
@@ -20,6 +20,31 @@
#define LORA_TX_POWER 20
#endif
#ifndef DEFAULT_RX_DELAY_BASE
#define DEFAULT_RX_DELAY_BASE 0.0f
#endif
#ifndef DEFAULT_LOOP_DETECT
#define DEFAULT_LOOP_DETECT LOOP_DETECT_OFF
#endif
#ifndef DEFAULT_POWERSAVING_ENABLED
#define DEFAULT_POWERSAVING_ENABLED 0
#endif
#ifndef DEFAULT_AGC_RESET_INTERVAL
#define DEFAULT_AGC_RESET_INTERVAL 0
#endif
#ifndef DEFAULT_ADVERT_INTERVAL
#define DEFAULT_ADVERT_INTERVAL 1
#endif
#ifndef DEFAULT_FLOOD_ADVERT_INTERVAL
#define DEFAULT_FLOOD_ADVERT_INTERVAL 12
#endif
#ifndef DEFAULT_MULTI_ACKS
#define DEFAULT_MULTI_ACKS 0
#endif
#ifndef DEFAULT_PATH_HASH_MODE
#define DEFAULT_PATH_HASH_MODE 0
#endif
#ifndef ADVERT_NAME
#define ADVERT_NAME "repeater"
#endif
@@ -63,6 +88,22 @@
#define CLI_REPLY_DELAY_MILLIS 600
#define LAZY_CONTACTS_WRITE_DELAY 5000
#ifndef REPEATERS_CHANNEL_KEY_HEX
#define REPEATERS_CHANNEL_KEY_HEX "89db441e2814dccf0dbd2e8cc5f501a3"
#endif
#ifndef BATT_MIN_MILLIVOLTS
#define BATT_MIN_MILLIVOLTS 3000
#endif
#ifndef BATT_MAX_MILLIVOLTS
#define BATT_MAX_MILLIVOLTS 4200
#endif
#define LOW_BATTERY_MIN_VALID_MV 1000
#define LOW_BATTERY_WARN_PERCENT_DEFAULT 20
#define LOW_BATTERY_CRITICAL_PERCENT_DEFAULT 10
#define LOW_BATTERY_CHECK_INTERVAL (60UL * 1000UL)
#define LOW_BATTERY_WARN_INTERVAL (24UL * 60UL * 60UL * 1000UL)
#define LOW_BATTERY_CRITICAL_INTERVAL (12UL * 60UL * 60UL * 1000UL)
static void formatRecentRepeaterPrefix(const SimpleMeshTables::RecentRepeaterInfo* info, char* out, size_t out_len) {
if (out == NULL || out_len == 0) {
@@ -529,6 +570,115 @@ void MyMesh::sendFloodReply(mesh::Packet* packet, unsigned long delay_millis, ui
}
}
static bool pathsEqual(const uint8_t* a, uint8_t a_len, const uint8_t* b, uint8_t b_len) {
if (a == NULL || b == NULL || a_len != b_len || !mesh::Packet::isValidPathLen(a_len)) return false;
uint8_t hash_count = a_len & 63;
uint8_t hash_size = (a_len >> 6) + 1;
return memcmp(a, b, hash_count * hash_size) == 0;
}
static bool hasUsablePath(const uint8_t* path, uint8_t path_len) {
return path != NULL && mesh::Packet::isValidPathLen(path_len) && (path_len & 63) > 0;
}
static bool buildRepeatersChannel(mesh::GroupChannel& channel) {
const char* hex = REPEATERS_CHANNEL_KEY_HEX;
size_t hex_len = strlen(hex);
if (!(hex_len == 32 || hex_len == 64)) return false;
for (size_t i = 0; i < hex_len; i++) {
if (!mesh::Utils::isHexChar(hex[i])) return false;
}
memset(channel.secret, 0, sizeof(channel.secret));
size_t key_len = hex_len / 2;
if (!mesh::Utils::fromHex(channel.secret, key_len, hex)) return false;
mesh::Utils::sha256(channel.hash, sizeof(channel.hash), channel.secret, key_len);
return true;
}
static uint8_t batteryPercentFromMilliVolts(uint16_t batt_mv) {
const int min_mv = BATT_MIN_MILLIVOLTS;
const int max_mv = BATT_MAX_MILLIVOLTS;
if (max_mv <= min_mv) return 100;
int pct = (((int)batt_mv - min_mv) * 100) / (max_mv - min_mv);
if (pct < 0) return 0;
if (pct > 100) return 100;
return (uint8_t)pct;
}
static bool parseBatteryAlertPercent(const char* value, uint8_t min_value, uint8_t max_value, uint8_t& result) {
if (value == NULL || *value == 0) {
return false;
}
uint16_t parsed = 0;
while (*value) {
if (*value < '0' || *value > '9') {
return false;
}
parsed = (uint16_t)(parsed * 10 + (*value - '0'));
if (parsed > max_value) {
return false;
}
value++;
}
if (parsed < min_value) {
return false;
}
result = (uint8_t)parsed;
return true;
}
mesh::Packet* MyMesh::createPacketCopy(const mesh::Packet* packet, const char* caller) {
if (packet == NULL) return NULL;
mesh::Packet* copy = obtainNewPacket();
if (copy == NULL) {
MESH_DEBUG_PRINTLN("%s %s: error, packet pool empty", getLogDateTime(), caller);
return NULL;
}
*copy = *packet;
return copy;
}
mesh::Packet* MyMesh::createAltPathCopy(const mesh::Packet* packet,
const uint8_t* primary_path, uint8_t primary_path_len,
const uint8_t* alt_path, uint8_t alt_path_len) {
if (!hasUsablePath(alt_path, alt_path_len)) return NULL;
if (hasUsablePath(primary_path, primary_path_len) && pathsEqual(primary_path, primary_path_len, alt_path, alt_path_len)) {
return NULL;
}
return createPacketCopy(packet, "MyMesh::createAltPathCopy()");
}
void MyMesh::sendFloodReplyWithAltPath(mesh::Packet* packet,
const uint8_t* direct_path, uint8_t direct_path_len,
const uint8_t* alt_path, uint8_t alt_path_len,
unsigned long delay_millis, uint8_t path_hash_size) {
mesh::Packet* direct = hasUsablePath(direct_path, direct_path_len)
? createPacketCopy(packet, "MyMesh::sendFloodReplyWithAltPath(direct)")
: NULL;
mesh::Packet* alt = createAltPathCopy(packet, direct_path, direct_path_len, alt_path, alt_path_len);
sendFloodReply(packet, delay_millis, path_hash_size);
if (direct) sendDirect(direct, direct_path, direct_path_len, delay_millis);
if (alt) sendDirect(alt, alt_path, alt_path_len, delay_millis);
}
void MyMesh::sendDirectWithAltPath(mesh::Packet* packet,
const uint8_t* path, uint8_t path_len,
const uint8_t* alt_path, uint8_t alt_path_len,
uint32_t delay_millis) {
mesh::Packet* alt = createAltPathCopy(packet, path, path_len, alt_path, alt_path_len);
sendDirect(packet, path, path_len, delay_millis);
if (alt) sendDirect(alt, alt_path, alt_path_len, delay_millis);
}
bool MyMesh::allowPacketForward(const mesh::Packet *packet) {
if (_prefs.disable_fwd) return false;
@@ -849,6 +999,54 @@ bool MyMesh::allowDirectRetry(const mesh::Packet* packet, const uint8_t* next_ho
return true;
}
bool MyMesh::maybeShortCircuitDirect(mesh::Packet* packet) {
if (packet == NULL || !packet->isRouteDirect() || packet->getPayloadType() == PAYLOAD_TYPE_TRACE) {
return false;
}
uint8_t hash_count = packet->getPathHashCount();
uint8_t hash_size = packet->getPathHashSize();
if (hash_count < 2 || hash_size == 0 || hash_size > MAX_ROUTE_HASH_BYTES) {
return false;
}
// Normal direct forwarding handles the first path entry. Short-circuit only when we are later in the route.
int self_idx = -1;
for (uint8_t i = 1; i < hash_count; i++) {
if (self_id.isHashMatch(&packet->path[i * hash_size], hash_size)) {
self_idx = i;
break;
}
}
if (self_idx < 0) {
return false;
}
const SimpleMeshTables* tables = (const SimpleMeshTables*)getTables();
bool adjacent_recent = false;
if (self_idx > 0
&& tables->findRecentRepeaterByHash(&packet->path[(self_idx - 1) * hash_size], hash_size) != NULL) {
adjacent_recent = true;
}
if (!adjacent_recent && self_idx + 1 < hash_count
&& tables->findRecentRepeaterByHash(&packet->path[(self_idx + 1) * hash_size], hash_size) != NULL) {
adjacent_recent = true;
}
if (!adjacent_recent) {
return false;
}
uint8_t remaining = hash_count - (uint8_t)self_idx;
memmove(packet->path, &packet->path[self_idx * hash_size], remaining * hash_size);
packet->setPathHashCount(remaining);
MESH_DEBUG_PRINTLN("%s direct short-circuit (type=%d, original_hop=%d, remaining_hops=%d)",
getLogDateTime(),
(uint32_t)packet->getPayloadType(),
self_idx + 1,
(uint32_t)remaining);
return true;
}
uint8_t MyMesh::getDirectRetryCodingRateForSNR(int8_t snr_x4) const {
if (_prefs.direct_retry_cr4_snr_x4 == 0
&& _prefs.direct_retry_cr5_snr_x4 == 0
@@ -992,6 +1190,31 @@ bool MyMesh::floodRetryPrefixIgnored(const uint8_t* prefix, uint8_t prefix_len)
}
return false;
}
uint8_t MyMesh::floodRetryEffectivePathLength(const mesh::Packet* packet, uint8_t max_hops) const {
if (packet == NULL || !packet->isRouteFlood() || packet->getPathHashCount() == 0) {
return 0;
}
uint8_t hash_size = packet->getPathHashSize();
if (hash_size == 0 || hash_size > MAX_ROUTE_HASH_BYTES) {
return packet->getPathHashCount();
}
uint8_t hop_count = packet->getPathHashCount();
if (max_hops < hop_count) {
hop_count = max_hops;
}
uint8_t effective_len = 0;
const uint8_t* path = packet->path;
for (uint8_t hop = 0; hop < hop_count; hop++) {
if (!floodRetryPrefixIgnored(path, hash_size)) {
effective_len++;
}
path += hash_size;
}
return effective_len;
}
bool MyMesh::floodRetryPrefixFresh(const uint8_t* prefix, uint8_t prefix_len) const {
const auto* recent = ((const SimpleMeshTables *)getTables())->findRecentRepeaterByHash(prefix, prefix_len);
if (recent == NULL || recent->last_heard_millis == 0) {
@@ -1413,7 +1636,15 @@ uint8_t MyMesh::getFloodRetryMaxPathLength(const mesh::Packet* packet) const {
if (gate == FLOOD_RETRY_PATH_GATE_DISABLED) {
return FLOOD_RETRY_PATH_GATE_DISABLED;
}
return gate <= 63 ? gate : 2;
if (gate > 63) {
gate = 2;
}
uint8_t raw_hops = packet != NULL ? packet->getPathHashCount() : 0;
uint8_t effective_hops = floodRetryEffectivePathLength(packet);
uint8_t ignored_hops = raw_hops > effective_hops ? raw_hops - effective_hops : 0;
uint16_t adjusted_gate = (uint16_t)gate + ignored_hops;
return adjusted_gate > 63 ? 63 : (uint8_t)adjusted_gate;
}
uint8_t MyMesh::getFloodRetryMaxAttempts(const mesh::Packet* packet) const {
if (_prefs.disable_fwd) {
@@ -1447,7 +1678,7 @@ bool MyMesh::isFloodRetryEchoTarget(const mesh::Packet* packet, uint8_t progress
if (hasFloodRetryPrefixes()) {
return floodRetryLastHopMatches(packet);
}
if (packet->getPathHashCount() <= progress_marker) {
if (floodRetryEffectivePathLength(packet) <= floodRetryEffectivePathLength(packet, progress_marker)) {
return false;
}
return true;
@@ -1607,13 +1838,22 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
// let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
mesh::Packet *path = createPathReturn(client->id, secret, packet->path, packet->path_len,
PAYLOAD_TYPE_RESPONSE, reply_data, reply_len);
if (path) sendFloodReply(path, SERVER_RESPONSE_DELAY, packet->getPathHashSize());
if (path) {
if (hasUsablePath(client->out_path, client->out_path_len)) {
sendFloodReplyWithAltPath(path, client->out_path, client->out_path_len,
client->alt_path, client->alt_path_len,
SERVER_RESPONSE_DELAY, packet->getPathHashSize());
} else {
sendFloodReply(path, SERVER_RESPONSE_DELAY, packet->getPathHashSize());
}
}
} else {
mesh::Packet *reply =
createDatagram(PAYLOAD_TYPE_RESPONSE, client->id, secret, reply_data, reply_len);
if (reply) {
if (client->out_path_len != OUT_PATH_UNKNOWN) { // we have an out_path, so send DIRECT
sendDirect(reply, client->out_path, client->out_path_len, SERVER_RESPONSE_DELAY);
if (hasUsablePath(client->out_path, client->out_path_len)) { // we have an out_path, so send DIRECT
sendDirectWithAltPath(reply, client->out_path, client->out_path_len,
client->alt_path, client->alt_path_len, SERVER_RESPONSE_DELAY);
} else {
sendFloodReply(reply, SERVER_RESPONSE_DELAY, packet->getPathHashSize());
}
@@ -1645,10 +1885,11 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
mesh::Packet *ack = createAck(ack_hash);
if (ack) {
if (client->out_path_len == OUT_PATH_UNKNOWN) {
sendFloodReply(ack, TXT_ACK_DELAY, packet->getPathHashSize());
if (hasUsablePath(client->out_path, client->out_path_len)) {
sendDirectWithAltPath(ack, client->out_path, client->out_path_len,
client->alt_path, client->alt_path_len, TXT_ACK_DELAY);
} else {
sendDirect(ack, client->out_path, client->out_path_len, TXT_ACK_DELAY);
sendFloodReply(ack, TXT_ACK_DELAY, packet->getPathHashSize());
}
}
}
@@ -1659,7 +1900,7 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
if (is_retry) {
*reply = 0;
} else {
handleCommand(sender_timestamp, command, reply);
handleCommand(sender_timestamp, client, command, reply);
}
int text_len = strlen(reply);
if (text_len > 0) {
@@ -1673,10 +1914,11 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
auto reply = createDatagram(PAYLOAD_TYPE_TXT_MSG, client->id, secret, temp, 5 + text_len);
if (reply) {
if (client->out_path_len == OUT_PATH_UNKNOWN) {
sendFloodReply(reply, CLI_REPLY_DELAY_MILLIS, packet->getPathHashSize());
if (hasUsablePath(client->out_path, client->out_path_len)) {
sendDirectWithAltPath(reply, client->out_path, client->out_path_len,
client->alt_path, client->alt_path_len, CLI_REPLY_DELAY_MILLIS);
} else {
sendDirect(reply, client->out_path, client->out_path_len, CLI_REPLY_DELAY_MILLIS);
sendFloodReply(reply, CLI_REPLY_DELAY_MILLIS, packet->getPathHashSize());
}
}
}
@@ -1696,7 +1938,9 @@ bool MyMesh::onPeerPathRecv(mesh::Packet *packet, int sender_idx, const uint8_t
auto client = acl.getClientByIdx(i);
// store a copy of path, for sendDirect()
client->out_path_len = mesh::Packet::copyPath(client->out_path, path, path_len);
if (client->out_path_len != OUT_PATH_FORCE_FLOOD) {
client->out_path_len = mesh::Packet::copyPath(client->out_path, path, path_len);
}
client->last_activity = getRTCClock()->getCurrentTime();
} else {
MESH_DEBUG_PRINTLN("onPeerPathRecv: invalid peer idx: %d", i);
@@ -1799,6 +2043,9 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc
last_millis = 0;
uptime_millis = 0;
next_local_advert = next_flood_advert = 0;
next_battery_alert_check = 0;
last_battery_alert_sent = 0;
battery_alert_sent = false;
dirty_contacts_expiry = 0;
set_radio_at = revert_radio_at = 0;
_logging = false;
@@ -1812,7 +2059,7 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc
// defaults
memset(&_prefs, 0, sizeof(_prefs));
_prefs.airtime_factor = 1.0;
_prefs.rx_delay_base = 0.0f; // turn off by default, was 10.0;
_prefs.rx_delay_base = DEFAULT_RX_DELAY_BASE;
_prefs.tx_delay_factor = 0.5f; // was 0.25f
_prefs.direct_tx_delay_factor = 0.3f; // was 0.2
_prefs.direct_retry_recent_enabled = 1;
@@ -1825,6 +2072,9 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc
_prefs.flood_retry_path_gate = 2;
_prefs.flood_retry_bridge_enabled = 0;
_prefs.flood_retry_advert_enabled = 0;
_prefs.battery_alert_enabled = 0;
_prefs.battery_alert_low_percent = LOW_BATTERY_WARN_PERCENT_DEFAULT;
_prefs.battery_alert_critical_percent = LOW_BATTERY_CRITICAL_PERCENT_DEFAULT;
_prefs.direct_retry_cr4_snr_x4 = DIRECT_RETRY_CR4_MIN_SNR_X4_DEFAULT;
_prefs.direct_retry_cr5_snr_x4 = DIRECT_RETRY_CR5_MIN_SNR_X4_DEFAULT;
_prefs.direct_retry_cr7_snr_x4 = DIRECT_RETRY_CR7_MIN_SNR_X4_DEFAULT;
@@ -1838,10 +2088,15 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc
_prefs.bw = LORA_BW;
_prefs.cr = LORA_CR;
_prefs.tx_power_dbm = LORA_TX_POWER;
_prefs.advert_interval = 1; // default to 2 minutes for NEW installs
_prefs.flood_advert_interval = 12; // 12 hours
_prefs.advert_interval = DEFAULT_ADVERT_INTERVAL;
_prefs.flood_advert_interval = DEFAULT_FLOOD_ADVERT_INTERVAL;
_prefs.flood_max = 64;
_prefs.interference_threshold = 0; // disabled
_prefs.agc_reset_interval = DEFAULT_AGC_RESET_INTERVAL;
_prefs.multi_acks = DEFAULT_MULTI_ACKS;
_prefs.path_hash_mode = DEFAULT_PATH_HASH_MODE;
_prefs.loop_detect = DEFAULT_LOOP_DETECT;
_prefs.powersaving_enabled = DEFAULT_POWERSAVING_ENABLED;
// bridge defaults
_prefs.bridge_enabled = 1; // enabled
@@ -1880,6 +2135,16 @@ void MyMesh::begin(FILESYSTEM *fs) {
_fs = fs;
// load persisted prefs
_cli.loadPrefs(_fs);
#ifdef CASCADIA_PROFILE
_prefs.rx_delay_base = DEFAULT_RX_DELAY_BASE;
_prefs.agc_reset_interval = DEFAULT_AGC_RESET_INTERVAL;
_prefs.advert_interval = DEFAULT_ADVERT_INTERVAL;
_prefs.flood_advert_interval = DEFAULT_FLOOD_ADVERT_INTERVAL;
_prefs.multi_acks = DEFAULT_MULTI_ACKS;
_prefs.path_hash_mode = DEFAULT_PATH_HASH_MODE;
_prefs.loop_detect = DEFAULT_LOOP_DETECT;
_prefs.powersaving_enabled = DEFAULT_POWERSAVING_ENABLED;
#endif
acl.load(_fs, self_id);
// TODO: key_store.begin();
region_map.load(_fs);
@@ -1943,6 +2208,82 @@ void MyMesh::sendFloodScoped(const TransportKey& scope, mesh::Packet* pkt, uint3
}
}
bool MyMesh::sendRepeatersFloodText(const char* text) {
if (text == NULL || *text == 0) return false;
mesh::GroupChannel channel;
if (!buildRepeatersChannel(channel)) {
return false;
}
uint8_t temp[MAX_PACKET_PAYLOAD];
uint32_t timestamp = getRTCClock()->getCurrentTimeUnique();
memcpy(temp, &timestamp, 4);
temp[4] = (TXT_TYPE_PLAIN << 2);
const size_t max_data_len = MAX_PACKET_PAYLOAD - CIPHER_BLOCK_SIZE;
const size_t prefix_cap = max_data_len > 5 ? max_data_len - 5 + 1 : 0;
int prefix_written = prefix_cap > 0
? snprintf((char*)&temp[5], prefix_cap, "%s: ", _prefs.node_name)
: -1;
if (prefix_written < 0) {
return false;
}
size_t prefix_len = (size_t)prefix_written;
if (prefix_len >= prefix_cap) {
prefix_len = prefix_cap - 1;
}
size_t text_len = strlen(text);
size_t max_text_len = max_data_len - 5 - prefix_len;
if (text_len > max_text_len) {
text_len = max_text_len;
}
memcpy(&temp[5 + prefix_len], text, text_len);
auto pkt = createGroupDatagram(PAYLOAD_TYPE_GRP_TXT, channel, temp, 5 + prefix_len + text_len);
if (pkt == NULL) {
return false;
}
sendFloodScoped(default_scope, pkt, 0, _prefs.path_hash_mode + 1);
return true;
}
void MyMesh::checkBatteryAlert() {
if (!_prefs.battery_alert_enabled) {
battery_alert_sent = false;
return;
}
if (next_battery_alert_check && !millisHasNowPassed(next_battery_alert_check)) {
return;
}
next_battery_alert_check = futureMillis(LOW_BATTERY_CHECK_INTERVAL);
uint16_t batt_mv = board.getBattMilliVolts();
uint8_t batt_pct = batteryPercentFromMilliVolts(batt_mv);
if (batt_mv <= LOW_BATTERY_MIN_VALID_MV || batt_pct >= _prefs.battery_alert_low_percent) {
battery_alert_sent = false;
return;
}
unsigned long interval = batt_pct < _prefs.battery_alert_critical_percent
? LOW_BATTERY_CRITICAL_INTERVAL
: LOW_BATTERY_WARN_INTERVAL;
if (battery_alert_sent && !millisHasNowPassed(last_battery_alert_sent + interval)) {
return;
}
char text[96];
snprintf(text, sizeof(text), "LOW BATTERY %u%% (%u mV)", (uint32_t)batt_pct, (uint32_t)batt_mv);
if (sendRepeatersFloodText(text)) {
battery_alert_sent = true;
last_battery_alert_sent = millis();
}
}
void MyMesh::applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) {
set_radio_at = futureMillis(2000); // give CLI reply some time to be sent back, before applying temp radio params
pending_freq = freq;
@@ -2127,7 +2468,100 @@ void MyMesh::clearStats() {
((SimpleMeshTables *)getTables())->resetStats();
}
void MyMesh::handleCommand(uint32_t sender_timestamp, char *command, char *reply) {
static char* trimSpaces(char* s) {
while (*s == ' ') s++;
char* end = s + strlen(s);
while (end > s && end[-1] == ' ') end--;
*end = 0;
return s;
}
static bool parsePathCommand(char* raw, uint8_t* out_path, uint8_t& out_path_len, const char*& err) {
if (raw == NULL || out_path == NULL) {
err = "Err - bad params";
return false;
}
char* spec = trimSpaces(raw);
if (*spec == 0) {
err = "Err - missing path";
return false;
}
if (strcmp(spec, "clear") == 0 || strcmp(spec, "-") == 0 || strcmp(spec, "none") == 0) {
out_path_len = OUT_PATH_UNKNOWN;
return true;
}
if (strcmp(spec, "flood") == 0) {
out_path_len = OUT_PATH_FORCE_FLOOD;
return true;
}
uint8_t hash_size = 0;
uint8_t hop_count = 0;
char* token = spec;
while (token && *token) {
char* comma = strchr(token, ',');
if (comma) *comma = 0;
token = trimSpaces(token);
int hex_len = strlen(token);
if (!(hex_len == 2 || hex_len == 4 || hex_len == 6)) {
err = "Err - each hop must be 1/2/3 bytes hex";
return false;
}
uint8_t hop_hash_size = (uint8_t)(hex_len / 2);
if (hash_size == 0) {
hash_size = hop_hash_size;
} else if (hash_size != hop_hash_size) {
err = "Err - mixed hash sizes in path";
return false;
}
if (hop_count >= 63 || (hop_count + 1) * hash_size > MAX_PATH_SIZE) {
err = "Err - path too long";
return false;
}
if (!mesh::Utils::fromHex(&out_path[hop_count * hash_size], hash_size, token)) {
err = "Err - bad hex";
return false;
}
hop_count++;
token = comma ? comma + 1 : NULL;
}
if (hash_size == 0 || hop_count == 0) {
err = "Err - missing path";
return false;
}
out_path_len = ((hash_size - 1) << 6) | (hop_count & 63);
return true;
}
static void formatPathReply(const uint8_t* path, uint8_t path_len, char* out, size_t out_len) {
if (path_len == OUT_PATH_FORCE_FLOOD) {
snprintf(out, out_len, "> flood");
return;
}
if (path_len == OUT_PATH_UNKNOWN) {
snprintf(out, out_len, "> unknown");
return;
}
if (!mesh::Packet::isValidPathLen(path_len)) {
snprintf(out, out_len, "> invalid");
return;
}
uint8_t hash_size = (path_len >> 6) + 1;
uint8_t hop_count = path_len & 63;
uint8_t byte_len = hop_count * hash_size;
char hex[(MAX_PATH_SIZE * 2) + 1];
mesh::Utils::toHex(hex, path, byte_len);
snprintf(out, out_len, "> hs=%u hops=%u hex=%s", (uint32_t)hash_size, (uint32_t)hop_count, hex);
}
void MyMesh::handleCommand(uint32_t sender_timestamp, ClientInfo* sender, char *command, char *reply) {
if (region_load_active) {
if (StrHelper::isBlank(command)) { // empty/blank line, signal to terminate 'load' operation
region_map = temp_map; // copy over the temp instance as new current map
@@ -2204,6 +2638,107 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, char *command, char *reply
Serial.printf("\n");
}
reply[0] = 0;
} else if (strcmp(command, "get outpath") == 0
|| strcmp(command, "set outpath") == 0
|| strncmp(command, "set outpath ", 12) == 0
|| strcmp(command, "get altpath") == 0
|| strcmp(command, "set altpath") == 0
|| strncmp(command, "set altpath ", 12) == 0) {
bool is_get = strncmp(command, "get ", 4) == 0;
bool is_alt = strstr(command, "altpath") != NULL;
if (sender == NULL) {
strcpy(reply, "Err - command needs remote client context");
} else if (is_get) {
formatPathReply(is_alt ? sender->alt_path : sender->out_path,
is_alt ? sender->alt_path_len : sender->out_path_len,
reply, 160);
} else {
char* spec = command + 11; // length of "set outpath"/"set altpath"
if (*spec == ' ') spec++;
uint8_t path[MAX_PATH_SIZE];
uint8_t path_len = OUT_PATH_UNKNOWN;
const char* err = NULL;
if (!parsePathCommand(spec, path, path_len, err)) {
strcpy(reply, err ? err : "Err - invalid path");
} else if (is_alt && path_len == OUT_PATH_FORCE_FLOOD) {
strcpy(reply, "Err - bad params");
} else {
if (is_alt) {
if (path_len == OUT_PATH_UNKNOWN) {
memset(sender->alt_path, 0, sizeof(sender->alt_path));
sender->alt_path_len = OUT_PATH_UNKNOWN;
} else {
sender->alt_path_len = mesh::Packet::copyPath(sender->alt_path, path, path_len);
}
} else {
if (path_len == OUT_PATH_UNKNOWN || path_len == OUT_PATH_FORCE_FLOOD) {
memset(sender->out_path, 0, sizeof(sender->out_path));
sender->out_path_len = path_len;
} else {
sender->out_path_len = mesh::Packet::copyPath(sender->out_path, path, path_len);
}
}
dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY);
formatPathReply(is_alt ? sender->alt_path : sender->out_path,
is_alt ? sender->alt_path_len : sender->out_path_len,
reply, 160);
}
}
} else if (strncmp(command, "send text.flood ", 16) == 0) {
char* text = trimSpaces(command + 16);
if (*text == 0) {
strcpy(reply, "Err - usage: send text.flood <message>");
} else if (sendRepeatersFloodText(text)) {
strcpy(reply, "OK");
} else {
strcpy(reply, "Err - unable to create packet");
}
} else if (strcmp(command, "get battery.alert") == 0) {
sprintf(reply, "> %s", _prefs.battery_alert_enabled ? "on" : "off");
} else if (strcmp(command, "get battery.alert.low") == 0) {
sprintf(reply, "> %u", (uint32_t)_prefs.battery_alert_low_percent);
} else if (strcmp(command, "get battery.alert.critical") == 0) {
sprintf(reply, "> %u", (uint32_t)_prefs.battery_alert_critical_percent);
} else if (strncmp(command, "set battery.alert ", 18) == 0) {
const char* value = command + 18;
if (strcmp(value, "on") == 0) {
_prefs.battery_alert_enabled = 1;
next_battery_alert_check = 0;
savePrefs();
strcpy(reply, "OK");
} else if (strcmp(value, "off") == 0) {
_prefs.battery_alert_enabled = 0;
battery_alert_sent = false;
savePrefs();
strcpy(reply, "OK");
} else {
strcpy(reply, "Err - usage: set battery.alert <on|off>");
}
} else if (strncmp(command, "set battery.alert.low ", 22) == 0) {
uint8_t percent;
if (!parseBatteryAlertPercent(command + 22, 1, 100, percent)) {
strcpy(reply, "Err - usage: set battery.alert.low <1-100>");
} else if (percent <= _prefs.battery_alert_critical_percent) {
strcpy(reply, "Err - low must be greater than critical");
} else {
_prefs.battery_alert_low_percent = percent;
next_battery_alert_check = 0;
savePrefs();
strcpy(reply, "OK");
}
} else if (strncmp(command, "set battery.alert.critical ", 27) == 0) {
uint8_t percent;
if (!parseBatteryAlertPercent(command + 27, 0, 99, percent)) {
strcpy(reply, "Err - usage: set battery.alert.critical <0-99>");
} else if (percent >= _prefs.battery_alert_low_percent) {
strcpy(reply, "Err - critical must be less than low");
} else {
_prefs.battery_alert_critical_percent = percent;
next_battery_alert_check = 0;
savePrefs();
strcpy(reply, "OK");
}
} else if (strncmp(command, "get recent.repeater", 19) == 0
|| strncmp(command, "set recent.repeater", 19) == 0
|| strncmp(command, "clear recent.repeater", 21) == 0
@@ -2404,6 +2939,7 @@ void MyMesh::loop() {
#endif
mesh::Mesh::loop();
checkBatteryAlert();
if (next_flood_advert && millisHasNowPassed(next_flood_advert)) {
mesh::Packet *pkt = createSelfAdvert();
+23 -1
View File
@@ -85,6 +85,9 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
uint32_t last_millis;
uint64_t uptime_millis;
unsigned long next_local_advert, next_flood_advert;
unsigned long next_battery_alert_check;
unsigned long last_battery_alert_sent;
bool battery_alert_sent;
bool _logging;
NodePrefs _prefs;
ClientACL acl;
@@ -141,6 +144,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
bool floodRetryPrefixMatches(const mesh::Packet* packet) const;
bool floodRetryLastHopMatches(const mesh::Packet* packet) const;
bool floodRetryPrefixIgnored(const uint8_t* prefix, uint8_t prefix_len) const;
uint8_t floodRetryEffectivePathLength(const mesh::Packet* packet, uint8_t max_hops = 0xFF) const;
bool floodRetryPrefixFresh(const uint8_t* prefix, uint8_t prefix_len) const;
int floodRetryBucketForPrefix(const uint8_t* prefix, uint8_t prefix_len, bool require_fresh,
bool include_other) const;
@@ -162,6 +166,8 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
uint8_t handleAnonClockReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data);
int handleRequest(ClientInfo* sender, uint32_t sender_timestamp, uint8_t* payload, size_t payload_len);
mesh::Packet* createSelfAdvert();
bool sendRepeatersFloodText(const char* text);
void checkBatteryAlert();
File openAppend(const char* fname);
bool isLooped(const mesh::Packet* packet, const uint8_t max_counters[]);
@@ -184,6 +190,7 @@ protected:
uint32_t getDirectRetransmitDelay(const mesh::Packet* packet) override;
uint8_t getDefaultTxCodingRate() const override { return active_cr; }
bool allowDirectRetry(const mesh::Packet* packet, const uint8_t* next_hop_hash, uint8_t next_hop_hash_len) const override;
bool maybeShortCircuitDirect(mesh::Packet* packet) override;
void configureDirectRetryPacket(mesh::Packet* retry, const mesh::Packet* original, uint8_t retry_attempt) override;
uint32_t getDirectRetryEchoDelay(const mesh::Packet* packet) const override;
uint8_t getDirectRetryMaxAttempts(const mesh::Packet* packet) const override;
@@ -223,6 +230,18 @@ protected:
void onControlDataRecv(mesh::Packet* packet) override;
void sendFloodReply(mesh::Packet* packet, unsigned long delay_millis, uint8_t path_hash_size);
mesh::Packet* createPacketCopy(const mesh::Packet* packet, const char* caller);
mesh::Packet* createAltPathCopy(const mesh::Packet* packet,
const uint8_t* primary_path, uint8_t primary_path_len,
const uint8_t* alt_path, uint8_t alt_path_len);
void sendFloodReplyWithAltPath(mesh::Packet* packet,
const uint8_t* direct_path, uint8_t direct_path_len,
const uint8_t* alt_path, uint8_t alt_path_len,
unsigned long delay_millis, uint8_t path_hash_size);
void sendDirectWithAltPath(mesh::Packet* packet,
const uint8_t* path, uint8_t path_len,
const uint8_t* alt_path, uint8_t alt_path_len,
uint32_t delay_millis);
public:
MyMesh(mesh::MainBoard& board, mesh::Radio& radio, mesh::MillisecondClock& ms, mesh::RNG& rng, mesh::RTCClock& rtc, mesh::MeshTables& tables);
@@ -272,7 +291,10 @@ public:
void saveIdentity(const mesh::LocalIdentity& new_id) override;
void clearStats() override;
void handleCommand(uint32_t sender_timestamp, char* command, char* reply);
void handleCommand(uint32_t sender_timestamp, ClientInfo* sender, char* command, char* reply);
void handleCommand(uint32_t sender_timestamp, char* command, char* reply) {
handleCommand(sender_timestamp, NULL, command, reply);
}
void loop();
#if defined(WITH_BRIDGE)
+3 -1
View File
@@ -216,6 +216,8 @@ DispatcherAction Mesh::onRecvPacket(Packet* pkt) {
uint8_t flags = pkt->payload[i++];
uint8_t len = pkt->payload_len - i;
uint8_t hash_size = decodeTraceHashSize(flags, len);
// path_len*entry_size can exceed 255 (path_len up to 63, entry_size up to 8);
// a uint8_t offset would wrap and steer the isHashMatch() read to the wrong place.
uint16_t offset = (uint16_t)pkt->path_len * (uint16_t)hash_size;
if (offset >= len) { // TRACE has reached end of given path
onTraceRecv(pkt, trace_tag, auth_code, flags, pkt->path, &pkt->payload[i], len);
@@ -252,7 +254,7 @@ DispatcherAction Mesh::onRecvPacket(Packet* pkt) {
}
}
if (self_id.isHashMatch(pkt->path, pkt->getPathHashSize()) && allowPacketForward(pkt)) {
if ((self_id.isHashMatch(pkt->path, pkt->getPathHashSize()) || maybeShortCircuitDirect(pkt)) && allowPacketForward(pkt)) {
if (pkt->getPayloadType() == PAYLOAD_TYPE_MULTIPART) {
return forwardMultipartDirect(pkt);
} else if (pkt->getPayloadType() == PAYLOAD_TYPE_ACK) {
+5
View File
@@ -135,6 +135,11 @@ protected:
*/
virtual bool allowDirectRetry(const Packet* packet, const uint8_t* next_hop_hash, uint8_t next_hop_hash_len) const;
/**
* \brief Allow subclasses to rewrite a non-TRACE DIRECT packet path when this node can safely skip ahead.
*/
virtual bool maybeShortCircuitDirect(Packet* packet) { return false; }
/**
* \returns milliseconds to wait for the next-hop echo before queueing one retry of the DIRECT packet.
*/
+12 -1
View File
@@ -1,5 +1,7 @@
#include "ClientACL.h"
static const uint8_t CONTACT_RECORD_VERSION_ALT_PATH = 1;
static File openWrite(FILESYSTEM* _fs, const char* filename) {
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
_fs->remove(filename);
@@ -28,6 +30,7 @@ void ClientACL::load(FILESYSTEM* fs, const mesh::LocalIdentity& self_id) {
uint8_t unused[2];
memset(&c, 0, sizeof(c));
c.alt_path_len = OUT_PATH_UNKNOWN;
bool success = (file.read(pub_key, 32) == 32);
success = success && (file.read((uint8_t *) &c.permissions, 1) == 1);
@@ -36,6 +39,10 @@ void ClientACL::load(FILESYSTEM* fs, const mesh::LocalIdentity& self_id) {
success = success && (file.read((uint8_t *)&c.out_path_len, 1) == 1);
success = success && (file.read(c.out_path, 64) == 64);
success = success && (file.read(c.shared_secret, PUB_KEY_SIZE) == PUB_KEY_SIZE); // will be recalculated below
if (success && unused[0] >= CONTACT_RECORD_VERSION_ALT_PATH) {
success = success && (file.read((uint8_t *)&c.alt_path_len, 1) == 1);
success = success && (file.read(c.alt_path, 64) == 64);
}
if (!success) break; // EOF
@@ -57,7 +64,8 @@ void ClientACL::save(FILESYSTEM* fs, bool (*filter)(ClientInfo*)) {
File file = openWrite(_fs, "/s_contacts");
if (file) {
uint8_t unused[2];
memset(unused, 0, sizeof(unused));
unused[0] = CONTACT_RECORD_VERSION_ALT_PATH;
unused[1] = 0;
for (int i = 0; i < num_clients; i++) {
auto c = &clients[i];
@@ -70,6 +78,8 @@ void ClientACL::save(FILESYSTEM* fs, bool (*filter)(ClientInfo*)) {
success = success && (file.write((uint8_t *)&c->out_path_len, 1) == 1);
success = success && (file.write(c->out_path, 64) == 64);
success = success && (file.write(c->shared_secret, PUB_KEY_SIZE) == PUB_KEY_SIZE);
success = success && (file.write((uint8_t *)&c->alt_path_len, 1) == 1);
success = success && (file.write(c->alt_path, 64) == 64);
if (!success) break; // write failed
}
@@ -115,6 +125,7 @@ ClientInfo* ClientACL::putClient(const mesh::Identity& id, uint8_t init_perms) {
c->permissions = init_perms;
c->id = id;
c->out_path_len = OUT_PATH_UNKNOWN;
c->alt_path_len = OUT_PATH_UNKNOWN;
return c;
}
+4 -1
View File
@@ -10,13 +10,16 @@
#define PERM_ACL_READ_WRITE 2
#define PERM_ACL_ADMIN 3
#define OUT_PATH_UNKNOWN 0xFF
#define OUT_PATH_FORCE_FLOOD 0xFE
#define OUT_PATH_UNKNOWN 0xFF
struct ClientInfo {
mesh::Identity id;
uint8_t permissions;
uint8_t out_path_len;
uint8_t out_path[MAX_PATH_SIZE];
uint8_t alt_path_len;
uint8_t alt_path[MAX_PATH_SIZE];
uint8_t shared_secret[PUB_KEY_SIZE];
uint32_t last_timestamp; // by THEIR clock (transient)
uint32_t last_activity; // by OUR clock (transient)
+27 -2
View File
@@ -556,6 +556,15 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
sizeof(_prefs->direct_retry_cr7_snr_x4)); // 662
retry_cr_read += file.read((uint8_t *)&_prefs->direct_retry_cr8_snr_x4,
sizeof(_prefs->direct_retry_cr8_snr_x4)); // 663
_prefs->battery_alert_enabled = 0;
size_t battery_alert_read = file.read((uint8_t *)&_prefs->battery_alert_enabled,
sizeof(_prefs->battery_alert_enabled)); // 664
_prefs->battery_alert_low_percent = 20;
_prefs->battery_alert_critical_percent = 10;
size_t battery_alert_low_read = file.read((uint8_t *)&_prefs->battery_alert_low_percent,
sizeof(_prefs->battery_alert_low_percent)); // 665
size_t battery_alert_critical_read = file.read((uint8_t *)&_prefs->battery_alert_critical_percent,
sizeof(_prefs->battery_alert_critical_percent)); // 666
// PowerSaving-only prefs stored radio_fem_rxgain at 291, before direct retry timing existed.
if (radio_fem_rxgain_read != sizeof(_prefs->radio_fem_rxgain)
&& legacy_retry_attempts_read == sizeof(legacy_retry_attempts_or_radio_fem_rxgain)
@@ -563,7 +572,7 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
|| _prefs->direct_retry_timing_magic[1] != DIRECT_RETRY_TIMING_MAGIC_1)) {
_prefs->radio_fem_rxgain = constrain(legacy_retry_attempts_or_radio_fem_rxgain, 0, 1);
}
// next: 664
// next: 667
// sanitise bad pref values
_prefs->rx_delay_base = constrain(_prefs->rx_delay_base, 0, 20.0f);
@@ -654,6 +663,19 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
} else {
sanitizeDirectRetryCrThresholds(_prefs);
}
if (battery_alert_read != sizeof(_prefs->battery_alert_enabled)) {
_prefs->battery_alert_enabled = 0;
} else {
_prefs->battery_alert_enabled = constrain(_prefs->battery_alert_enabled, 0, 1);
}
if (battery_alert_low_read != sizeof(_prefs->battery_alert_low_percent)
|| battery_alert_critical_read != sizeof(_prefs->battery_alert_critical_percent)
|| _prefs->battery_alert_low_percent < 1
|| _prefs->battery_alert_low_percent > 100
|| _prefs->battery_alert_critical_percent >= _prefs->battery_alert_low_percent) {
_prefs->battery_alert_low_percent = 20;
_prefs->battery_alert_critical_percent = 10;
}
file.close();
}
@@ -739,7 +761,10 @@ void CommonCLI::savePrefs(FILESYSTEM* fs) {
file.write((uint8_t *)&_prefs->direct_retry_cr5_snr_x4, sizeof(_prefs->direct_retry_cr5_snr_x4)); // 661
file.write((uint8_t *)&_prefs->direct_retry_cr7_snr_x4, sizeof(_prefs->direct_retry_cr7_snr_x4)); // 662
file.write((uint8_t *)&_prefs->direct_retry_cr8_snr_x4, sizeof(_prefs->direct_retry_cr8_snr_x4)); // 663
// next: 664
file.write((uint8_t *)&_prefs->battery_alert_enabled, sizeof(_prefs->battery_alert_enabled)); // 664
file.write((uint8_t *)&_prefs->battery_alert_low_percent, sizeof(_prefs->battery_alert_low_percent)); // 665
file.write((uint8_t *)&_prefs->battery_alert_critical_percent, sizeof(_prefs->battery_alert_critical_percent)); // 666
// next: 667
file.close();
}
+3
View File
@@ -132,6 +132,9 @@ struct NodePrefs { // persisted to file
int8_t direct_retry_cr5_snr_x4;
int8_t direct_retry_cr7_snr_x4;
int8_t direct_retry_cr8_snr_x4;
uint8_t battery_alert_enabled;
uint8_t battery_alert_low_percent;
uint8_t battery_alert_critical_percent;
};
class CommonCLICallbacks {