Compare commits
30
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
021df7116a | ||
|
|
4017dea175 | ||
|
|
f112d66a32 | ||
|
|
c097b08b62 | ||
|
|
c935ddf930 | ||
|
|
713b2f8815 | ||
|
|
5f31fc8e50 | ||
|
|
0dcc9c6e06 | ||
|
|
5a83c230cd | ||
|
|
e9501d0437 | ||
|
|
7dafdf239a | ||
|
|
c36ac45865 | ||
|
|
108245e55b | ||
|
|
976038717f | ||
|
|
36ffbe86f2 | ||
|
|
39fa6597c6 | ||
|
|
16a68f218a | ||
|
|
96db79dbc0 | ||
|
|
39da9ce46e | ||
|
|
5a86072ec6 | ||
|
|
74246f79b7 | ||
|
|
7fe08cffb1 | ||
|
|
2a324bd9c3 | ||
|
|
bc8e3acb2b | ||
|
|
62f6f7faef | ||
|
|
d6cd80e0e6 | ||
|
|
a72a75cd08 | ||
|
|
9f81305068 | ||
|
|
3633402e59 | ||
|
|
ae8cc34e10 |
No files matched your search
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env bash
|
||||
# The docs website of this fork (https://tth-pub.pages.rfa.cz/meshcore-tth/):
|
||||
# mkdocs (theme mkdocs-terminal) over docs/, in English: the English half of
|
||||
# the fork's README is the home page, the Czech half one page (cs.md); the
|
||||
# fork's own docs first, upstream's below.
|
||||
#
|
||||
# Usage: .github/docs-site.sh <out dir> (run from the repo root)
|
||||
# Needs mkdocs-terminal and markdown-callouts, e.g.
|
||||
# uvx --with mkdocs-terminal --with markdown-callouts mkdocs --version
|
||||
# The script stages a copy of docs/ (README split into index.md / cs.md,
|
||||
# links that leave docs/ pointed at the repo) and builds it with
|
||||
# mkdocs.tth.yml. Upstream's mkdocs.yml (Material) stays as it is (no
|
||||
# conflicts in upstream-sync merges).
|
||||
# Build only from the PUBLIC tree (tth-pub): the export leaves our operations
|
||||
# docs out, a build of the private repo would publish them.
|
||||
set -euo pipefail
|
||||
case "${1:-}" in -h | --help | "")
|
||||
sed -n '2,/^[^#]/{/^#/s/^# \{0,1\}//p}' "$0"
|
||||
[ -n "${1:-}" ] || exit 2
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
out=$(realpath -m "$1")
|
||||
repo=https://git.rfa.cz/tth-pub/meshcore-tth
|
||||
src="$repo/src/branch/main"
|
||||
stage=$(mktemp -d)
|
||||
trap 'rm -rf "$stage"' EXIT
|
||||
|
||||
cp -r docs "$stage/docs"
|
||||
# upstream's own introduction gets a page of its own; ours is the home page
|
||||
mv "$stage/docs/index.md" "$stage/docs/meshcore.md"
|
||||
rm -f "$stage/docs/docs.md" # how to build upstream's site, not for readers
|
||||
|
||||
# README of the fork: "## O tomto forku" .. "## About this fork" = Czech,
|
||||
# from there to "## About MeshCore" = English. One heading level up, links
|
||||
# into docs/ made site-relative, any other repo path absolute.
|
||||
readme_part() {
|
||||
sed -n "/^## $1/,/^## $2/p" README.md | sed '$d' |
|
||||
sed -E 's/^#(#+) /\1 /' |
|
||||
sed -E 's#\]\((\./)?docs/([^)]+)\)#](\2)#g' |
|
||||
sed -E "s#\\]\\((\\./)?([a-zA-Z][^):]*)\\)#](${src//#/\\#}/\\2)#g"
|
||||
}
|
||||
readme_part 'About this fork' 'About MeshCore' >"$stage/docs/index.md"
|
||||
readme_part 'O tomto forku' 'About this fork' >"$stage/docs/cs.md"
|
||||
if ! grep -q . "$stage/docs/index.md" || ! grep -q . "$stage/docs/cs.md"; then
|
||||
echo "docs-site: README sections not found (headings changed?)" >&2
|
||||
exit 1
|
||||
fi
|
||||
# the two languages link to each other by anchor, and "above"/"below"
|
||||
# is a separate page here
|
||||
sed -i -E 's#Česká verze \[výše\]#[Česká verze]#' "$stage/docs/index.md"
|
||||
sed -i -E 's#English version \[below\]#[English version]#' "$stage/docs/cs.md"
|
||||
sed -i -E 's#\]\(\#about-this-fork[^)]*\)#](index.md)#g' "$stage/docs/cs.md"
|
||||
sed -i -E 's#\]\(\#o-tomto-forku[^)]*\)#](cs.md)#g' "$stage/docs/index.md"
|
||||
# GFM (Gitea) needs `\|` for a pipe in code inside a table cell; Python-
|
||||
# Markdown keeps the backslash and does not split cells on a pipe in code
|
||||
perl -0pi -e 's/(`[^`\n]*`)/ (my $c = $1) =~ s#\\\|#|#g; $c /ge' "$stage"/docs/*.md
|
||||
# our docs link back to ../README.md
|
||||
sed -i -E 's#\]\(\.\./README\.md#](index.md#g' "$stage"/docs/*.md
|
||||
|
||||
cp mkdocs.tth.yml "$stage/"
|
||||
cd "$stage"
|
||||
mkdocs build --strict -f mkdocs.tth.yml -d "$out"
|
||||
Executable
+155
@@ -0,0 +1,155 @@
|
||||
#!/usr/bin/env bash
|
||||
# The changes part of a public release's notes (pub-release.yml): our commits
|
||||
# since BASE, one computed line for the build dependencies that moved, and
|
||||
# upstream's merged PRs. Prints Markdown to stdout.
|
||||
#
|
||||
# Usage: .github/release-notes.sh <base> <sha> <web url of this repo>
|
||||
# Preview: in a clone of tth-pub/meshcore-tth checked out at <sha> (the
|
||||
# library line compares platformio.lock in the working tree with <base>).
|
||||
#
|
||||
# What a commit puts into the notes (body lines, AGENTS.md "Commit = řádek
|
||||
# veřejného changelogu"; .tth/tools/git-hooks/commit-msg enforces them):
|
||||
# Changelog: <English line> replaces the subject; "Changelog: -" = left out
|
||||
# Changelog-cs: <Czech line> the notes show "<cs> · *<en>*"
|
||||
# Changelog-topic: <slug> commits with the same topic in one release are
|
||||
# ONE item: the newest one's text, all links --
|
||||
# a fix of a fix, a pin moved twice, a
|
||||
# superseded step no longer show up as two items
|
||||
# Commits that touch the firmware (paths in $fwre) come first, the rest is
|
||||
# folded. Build dependencies are not taken from commit messages but diffed:
|
||||
# the nRF52 platform and toolchain pins in platformio.ini and every library in
|
||||
# platformio.lock (tools/pio_lock.py moved), so the daily lock refresh and
|
||||
# Renovate commits carry "Changelog: -" and a release still says what moved.
|
||||
set -euo pipefail
|
||||
case "${1:-}" in -h | --help)
|
||||
sed -n '2,/^[^#]/{/^#/s/^# \{0,1\}//p}' "$0"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
[ $# -eq 3 ] || {
|
||||
echo "usage: $0 <base> <sha> <web url>" >&2
|
||||
exit 2
|
||||
}
|
||||
base=$1 sha=$2 web=$3
|
||||
gh=https://github.com/meshcore-dev/MeshCore
|
||||
max=60
|
||||
fwre='^(src|examples|variants|lib|boards|arch)/|^platformio\.(ini|lock)$'
|
||||
|
||||
trailer() { git log -1 --format=%b "$1" | sed -n "s/^$2: *//p" | head -1; }
|
||||
|
||||
# ours: commits on our main itself (first parent); a merge of one of our own
|
||||
# branches (feat/...) is unfolded into the branch's commits, an upstream merge
|
||||
# is left to the upstream list below
|
||||
ourc=()
|
||||
for c in $(git log --first-parent --format=%H "$base..$sha"); do
|
||||
if git rev-parse -q --verify "$c^2" >/dev/null; then
|
||||
git log -1 --format=%s "$c" | grep -q '^Merge upstream' && continue
|
||||
# ^base: a merge of main into a branch carries what is released already
|
||||
mapfile -t -O "${#ourc[@]}" ourc < <(git log --no-merges --format=%H "$c^1..$c^2" "^$base")
|
||||
else
|
||||
ourc+=("$c")
|
||||
fi
|
||||
done
|
||||
|
||||
# items, newest first; a topic seen before only adds its link
|
||||
declare -A text=() links=() isfw=()
|
||||
keys=()
|
||||
for c in "${ourc[@]}"; do
|
||||
en=$(trailer "$c" Changelog)
|
||||
[ "$en" = "-" ] && continue
|
||||
[ -n "$en" ] || en=$(git log -1 --format=%s "$c")
|
||||
cs=$(trailer "$c" Changelog-cs)
|
||||
key=$(trailer "$c" Changelog-topic)
|
||||
key=${key:-$c}
|
||||
link="[${c:0:8}]($web/commit/$c)"
|
||||
if [ -z "${text[$key]+x}" ]; then
|
||||
keys+=("$key")
|
||||
if [ -n "$cs" ]; then text[$key]="$cs · *$en*"; else text[$key]=$en; fi
|
||||
links[$key]=$link
|
||||
else
|
||||
links[$key]+=", $link"
|
||||
fi
|
||||
git diff-tree --no-commit-id --name-only -r "$c" | grep -qE "$fwre" && isfw[$key]=1
|
||||
done
|
||||
|
||||
# build dependencies that moved between base and sha
|
||||
deps=()
|
||||
pin() { git show "$1:platformio.ini" 2>/dev/null | grep -m1 -oE "$2@[0-9][^[:space:]]*" | cut -d@ -f2 || true; }
|
||||
for p in nordicnrf52 toolchain-gccarmnoneeabi; do
|
||||
o=$(pin "$base" "platformio/$p") n=$(pin "$sha" "platformio/$p")
|
||||
[ "$o" = "$n" ] || deps+=("$p ${o:-unpinned} → ${n:-unpinned}")
|
||||
done
|
||||
if git cat-file -e "$base:platformio.lock" 2>/dev/null && [ -f platformio.lock ]; then
|
||||
if [ "$(git rev-parse HEAD)" = "$(git rev-parse "$sha^{commit}")" ]; then
|
||||
while IFS= read -r l; do
|
||||
[ -n "$l" ] && deps+=("${l/ -> / → }")
|
||||
done < <(python3 tools/pio_lock.py moved --base "$base")
|
||||
else
|
||||
echo "release-notes: checkout is not $sha, libraries left out" >&2
|
||||
fi
|
||||
fi
|
||||
|
||||
fw="" other="" nother=0
|
||||
for k in "${keys[@]}"; do
|
||||
line="- ${text[$k]} (${links[$k]})"
|
||||
if [ -n "${isfw[$k]:-}" ]; then
|
||||
fw+="$line"$'\n'
|
||||
else
|
||||
other+="$line"$'\n'
|
||||
nother=$((nother + 1))
|
||||
fi
|
||||
done
|
||||
if [ "${#deps[@]}" -gt 0 ]; then
|
||||
d=$(printf '%s, ' "${deps[@]}")
|
||||
fw+="- Závislosti buildu · *build dependencies*: ${d%, }"$'\n'
|
||||
fi
|
||||
fw=${fw%$'\n'} other=${other%$'\n'}
|
||||
|
||||
# upstream: the first-parent line of each merged upstream branch, PR merges as
|
||||
# their title, direct commits as their subject. A direct upstream commit (no
|
||||
# PR) links to GitHub by its ORIGINAL id: the public export (filter-repo)
|
||||
# gives every upstream commit a new one, which GitHub does not know
|
||||
# (30. 11. 2026: "* sec patch" linked to a 404). Author email + author time
|
||||
# survive the rewrite.
|
||||
declare -A seen=() upid=()
|
||||
if git fetch -q --no-tags "$gh.git" '+refs/heads/main:refs/upstream/main' '+refs/heads/dev:refs/upstream/dev'; then
|
||||
while read -r h k; do upid[$k]=$h; done < <(git log --format='%H %ae/%at' refs/upstream/main refs/upstream/dev)
|
||||
fi
|
||||
ups=()
|
||||
for m in $(git log --first-parent --merges --grep='^Merge upstream' --format=%H "$base..$sha"); do
|
||||
for c in $(git log --first-parent --format=%H "$m^1..$m^2"); do
|
||||
s=$(git log -1 --format=%s "$c")
|
||||
if [[ $s =~ ^Merge\ pull\ request\ \#([0-9]+)\ from\ ([^/]+)/(.*)$ ]]; then
|
||||
pr=${BASH_REMATCH[1]}
|
||||
[ -z "${seen[$pr]:-}" ] || continue
|
||||
seen[$pr]=1
|
||||
t=$(git log -1 --format=%b "$c" | sed -n '/./{p;q}')
|
||||
ups+=("- ${t:-${BASH_REMATCH[3]}} ([#$pr]($gh/pull/$pr), ${BASH_REMATCH[2]})")
|
||||
elif [[ $s != Merge* ]]; then
|
||||
[ -z "${seen[$c]:-}" ] || continue
|
||||
seen[$c]=1
|
||||
u=${upid[$(git log -1 --format='%ae/%at' "$c")]:-}
|
||||
if [ -n "$u" ]; then
|
||||
ups+=("- $s ([${u:0:7}]($gh/commit/$u))")
|
||||
else
|
||||
ups+=("- $s ([${c:0:7}]($web/commit/$c))")
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done
|
||||
n=${#ups[@]}
|
||||
|
||||
echo "### Změny firmwaru · firmware changes"
|
||||
echo "${fw:-- žádné · none}"
|
||||
echo
|
||||
if [ "$nother" -gt 0 ]; then
|
||||
echo "<details><summary>Dokumentace, nástroje, CI · docs, tools, CI ($nother)</summary>"
|
||||
echo
|
||||
echo "$other"
|
||||
echo
|
||||
echo "</details>"
|
||||
echo
|
||||
fi
|
||||
echo "### Z upstreamu MeshCore · from upstream ($n)"
|
||||
if [ "$n" -gt 0 ]; then printf '%s\n' "${ups[@]:0:$max}"; else echo "- žádné · none"; fi
|
||||
[ "$n" -le "$max" ] || echo "- … a dalších $((n - max)) · and $((n - max)) more"
|
||||
@@ -11,6 +11,9 @@ permissions:
|
||||
|
||||
jobs:
|
||||
github-pages:
|
||||
# CUSTOM (TeTeHacko): upstream's site only; this fork publishes its own
|
||||
# (tth-docs.yml), and here the job only filled an unread gh-pages branch
|
||||
if: github.repository == 'meshcore-dev/MeshCore'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
|
||||
@@ -21,7 +21,9 @@
|
||||
# the newest KEEP releases stay, older ones are deleted. The body is a
|
||||
# changelog since the previous release: our own firmware commits, our docs /
|
||||
# tools / CI commits folded, then the upstream PRs the upstream merges brought
|
||||
# in. A "Changelog: <text>" line in a commit body replaces its subject there.
|
||||
# in, generated by .github/release-notes.sh (preview it locally; its header
|
||||
# lists the commit trailers: Changelog, Changelog-cs, Changelog-topic) with
|
||||
# one computed line for the build dependencies that moved.
|
||||
# nRF52: .uf2 (drag onto the bootloader drive) and .zip (DFU over BLE or
|
||||
# serial); ESP32: -merged.bin (fresh install at 0x0) and .bin (update).
|
||||
#
|
||||
@@ -451,8 +453,6 @@ jobs:
|
||||
EOF
|
||||
)
|
||||
web="$GITEA/$GITHUB_REPOSITORY"
|
||||
gh=https://github.com/meshcore-dev/MeshCore
|
||||
max=60
|
||||
# changelog against the newest older release that HEAD descends from
|
||||
prev="" base=""
|
||||
while read -r t c; do
|
||||
@@ -470,73 +470,9 @@ jobs:
|
||||
| sort_by(.created_at) | reverse | .[] | "\(.tag_name) \(.target_commitish)"')
|
||||
# no older release: the last 20 commits of our own line
|
||||
[ -n "$base" ] || base=$(git rev-list --first-parent --max-count=21 "$SHA" | tail -1)
|
||||
# ours: commits on our main itself (first parent); a merge of one of
|
||||
# our own branches (feat/...) is unfolded into the branch's commits,
|
||||
# an upstream merge is left to the upstream list below
|
||||
ourc=()
|
||||
for c in $(git log --first-parent --format=%H "$base..$SHA"); do
|
||||
if git rev-parse -q --verify "$c^2" >/dev/null; then
|
||||
git log -1 --format=%s "$c" | grep -q '^Merge upstream' && continue
|
||||
# ^base: a merge of main into a branch carries what is released already
|
||||
mapfile -t -O "${#ourc[@]}" ourc < <(git log --no-merges --format=%H "$c^1..$c^2" "^$base")
|
||||
else
|
||||
ourc+=("$c")
|
||||
fi
|
||||
done
|
||||
# Firmware changes first; docs, CI, tools and tests folded away. Sorted
|
||||
# by the files a commit touches, so it holds even for a poor subject.
|
||||
# A "Changelog: <text>" line in the body replaces the subject in the
|
||||
# notes ("Changelog: -" leaves the commit out), so the subject can stay
|
||||
# technical while the notes say what changes for the node.
|
||||
fw="" other="" nother=0
|
||||
for c in "${ourc[@]}"; do
|
||||
line=$(git log -1 --format=%b "$c" | sed -n 's/^Changelog: *//p' | head -1)
|
||||
[ "$line" = "-" ] && continue
|
||||
[ -n "$line" ] || line=$(git log -1 --format=%s "$c")
|
||||
line="- $line ([${c:0:8}]($web/commit/$c))"
|
||||
if git diff-tree --no-commit-id --name-only -r "$c" |
|
||||
grep -qE '^(src|examples|variants|lib|boards|arch)/|^platformio\.ini$'; then
|
||||
fw+="$line"$'\n'
|
||||
else
|
||||
other+="$line"$'\n'
|
||||
nother=$((nother + 1))
|
||||
fi
|
||||
done
|
||||
fw=${fw%$'\n'} other=${other%$'\n'}
|
||||
# upstream: the first-parent line of each merged upstream branch,
|
||||
# PR merges as their title, direct commits as their subject
|
||||
declare -A seen=()
|
||||
# A direct upstream commit (no PR) links to GitHub by its ORIGINAL
|
||||
# id: the public export (filter-repo) gives every upstream commit a
|
||||
# new one, which GitHub does not know (30. 11. 2026: "* sec patch"
|
||||
# linked to a 404). Author email + author time survive the rewrite.
|
||||
declare -A upid=()
|
||||
if git fetch -q --no-tags "$gh.git" '+refs/heads/main:refs/upstream/main' '+refs/heads/dev:refs/upstream/dev'; then
|
||||
while read -r h k; do upid[$k]=$h; done < <(git log --format='%H %ae/%at' refs/upstream/main refs/upstream/dev)
|
||||
fi
|
||||
ups=()
|
||||
for m in $(git log --first-parent --merges --grep='^Merge upstream' --format=%H "$base..$SHA"); do
|
||||
for c in $(git log --first-parent --format=%H "$m^1..$m^2"); do
|
||||
s=$(git log -1 --format=%s "$c")
|
||||
if [[ $s =~ ^Merge\ pull\ request\ \#([0-9]+)\ from\ ([^/]+)/(.*)$ ]]; then
|
||||
pr=${BASH_REMATCH[1]}
|
||||
[ -z "${seen[$pr]:-}" ] || continue
|
||||
seen[$pr]=1
|
||||
t=$(git log -1 --format=%b "$c" | sed -n '/./{p;q}')
|
||||
ups+=("- ${t:-${BASH_REMATCH[3]}} ([#$pr]($gh/pull/$pr), ${BASH_REMATCH[2]})")
|
||||
elif [[ $s != Merge* ]]; then
|
||||
[ -z "${seen[$c]:-}" ] || continue
|
||||
seen[$c]=1
|
||||
u=${upid[$(git log -1 --format='%ae/%at' "$c")]:-}
|
||||
if [ -n "$u" ]; then
|
||||
ups+=("- $s ([${u:0:7}]($gh/commit/$u))")
|
||||
else
|
||||
ups+=("- $s ([${c:0:7}]($web/commit/$c))")
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done
|
||||
n=${#ups[@]}
|
||||
# our commits, moved build dependencies, upstream PRs -- the
|
||||
# generator is a script so the notes can be previewed locally
|
||||
changes=$(bash .github/release-notes.sh "$base" "$SHA" "$web")
|
||||
body=$(
|
||||
echo "$TITLE"
|
||||
echo
|
||||
@@ -546,20 +482,7 @@ jobs:
|
||||
echo "Od předchozího vydání · since [$prev]($web/releases/tag/$(jq -rn --arg s "$prev" '$s|@uri'))"
|
||||
echo
|
||||
fi
|
||||
echo "### Změny firmwaru · firmware changes"
|
||||
echo "${fw:-- žádné · none}"
|
||||
echo
|
||||
if [ "$nother" -gt 0 ]; then
|
||||
echo "<details><summary>Dokumentace, nástroje, CI · docs, tools, CI ($nother)</summary>"
|
||||
echo
|
||||
echo "$other"
|
||||
echo
|
||||
echo "</details>"
|
||||
echo
|
||||
fi
|
||||
echo "### Z upstreamu MeshCore · from upstream ($n)"
|
||||
[ "$n" -gt 0 ] && printf '%s\n' "${ups[@]:0:$max}" || echo "- žádné · none"
|
||||
[ "$n" -le "$max" ] || echo "- … a dalších $((n - max)) · and $((n - max)) more"
|
||||
echo "$changes"
|
||||
echo
|
||||
echo "### Po flashi · after flashing"
|
||||
echo
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
# Docs website of this fork: https://tth-pub.pages.rfa.cz/meshcore-tth/
|
||||
#
|
||||
# Runs only in the published repo (tth-pub/meshcore-tth), after a push to main
|
||||
# that touches the docs: .github/docs-site.sh builds the site (mkdocs, theme
|
||||
# mkdocs-terminal, mkdocs.tth.yml) from the public tree -- the export leaves
|
||||
# our operations docs out, so nothing private can end up on it -- and the
|
||||
# result is force-pushed as the only commit of the branch `pages`. A webhook
|
||||
# of the repo (push, branch filter `pages`) tells git-pages on pages.rfa.cz,
|
||||
# which clones the branch anonymously: no token outside this repo's own.
|
||||
# git-pages: roles/git_pages in the proxmox.rfa.cz repo.
|
||||
name: tth-docs
|
||||
|
||||
"on":
|
||||
push:
|
||||
branches: [main]
|
||||
paths:
|
||||
- "docs/**"
|
||||
- "README.md"
|
||||
- "mkdocs.tth.yml"
|
||||
- ".github/docs-site.sh"
|
||||
- ".github/workflows/tth-docs.yml"
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: tth-docs
|
||||
cancel-in-progress: true
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
env:
|
||||
MKDOCS_VERSION: "1.6.1"
|
||||
MKDOCS_TERMINAL_VERSION: "4.8.0"
|
||||
MARKDOWN_CALLOUTS_VERSION: "0.4.0"
|
||||
PYMDOWN_EXTENSIONS_VERSION: "13.1.2"
|
||||
|
||||
jobs:
|
||||
site:
|
||||
if: github.repository == 'tth-pub/meshcore-tth'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
# No actions/setup-python: its builds need x86-64-v3, the runner has v2
|
||||
# (see tth-tools-lint.yml). mkdocs goes into a venv of the image's python3.
|
||||
- name: Install mkdocs
|
||||
run: |
|
||||
set -euo pipefail
|
||||
SUDO="$(command -v sudo || true)"
|
||||
if ! python3 -m venv "$RUNNER_TEMP/docs"; then
|
||||
$SUDO apt-get update -qq
|
||||
$SUDO apt-get install -y -qq python3 python3-venv
|
||||
python3 -m venv --clear "$RUNNER_TEMP/docs"
|
||||
fi
|
||||
"$RUNNER_TEMP/docs/bin/pip" install --quiet \
|
||||
"mkdocs==$MKDOCS_VERSION" "mkdocs-terminal==$MKDOCS_TERMINAL_VERSION" \
|
||||
"markdown-callouts==$MARKDOWN_CALLOUTS_VERSION" \
|
||||
"pymdown-extensions==$PYMDOWN_EXTENSIONS_VERSION"
|
||||
echo "$RUNNER_TEMP/docs/bin" >>"$GITHUB_PATH"
|
||||
|
||||
- name: Build
|
||||
env:
|
||||
NO_MKDOCS_2_WARNING: "1"
|
||||
run: bash .github/docs-site.sh "$RUNNER_TEMP/site"
|
||||
|
||||
# A worktree shares the checkout's credentials (github.token); the
|
||||
# branch keeps one commit, the site of the newest main.
|
||||
- name: Publish to the pages branch
|
||||
run: |
|
||||
set -euo pipefail
|
||||
git config --global user.name "tth-docs"
|
||||
git config --global user.email "tth-docs@localhost"
|
||||
wt="$RUNNER_TEMP/pages"
|
||||
git worktree add -q --detach "$wt"
|
||||
cd "$wt"
|
||||
git checkout -q --orphan pages-build
|
||||
git rm -rqf .
|
||||
cp -r "$RUNNER_TEMP/site/." .
|
||||
git add -A
|
||||
git commit -q -m "docs site from main ${GITHUB_SHA:0:8}"
|
||||
git push -q -f origin HEAD:refs/heads/pages
|
||||
echo "published ${GITHUB_SHA:0:8} to pages"
|
||||
@@ -18,6 +18,9 @@ meshi (869,432 MHz). Upstreamové větve `main` a `dev` se slučují automaticky
|
||||
dvakrát denně; všechno níže je navíc nad nimi. Náš kód je ve zdrojácích
|
||||
označený `CUSTOM (TeTeHacko)`. Nic z toho nemění protokol na rádiu.
|
||||
|
||||
Dokumentace forku i upstreamu jako web (anglicky, tahle část česky):
|
||||
<https://tth-pub.pages.rfa.cz/meshcore-tth/>
|
||||
|
||||
### Repeater: antispam (všechno vypínatelné, nic z toho není v upstreamu)
|
||||
|
||||
**Po nahrání je zapnutý jen FairnessLimiter**, s limity se zhruba
|
||||
@@ -32,22 +35,22 @@ vypnuté, dokud je nezapnete.
|
||||
hash odesílatele, původce advertu). Port návrhu Beanowa
|
||||
[#1502](https://github.com/meshcore-dev/MeshCore/pull/1502), limity
|
||||
přepočítané z 30 dní skutečného provozu CZ meshe.
|
||||
`fairness [on|off|grid|cap|refill]`; přímo směrovaný provoz se neomezuje nikdy.
|
||||
`fairness <on|off>`, `fairness cap`, `fairness refill`, `fairness grid`; přímo směrovaný provoz se neomezuje nikdy.
|
||||
* **Okno na adverty podle původce** – flood advert každého uzlu se přepošle
|
||||
nejvýš jednou za N hodin (`fairness advert <h>|clear`), převzato
|
||||
nejvýš jednou za N hodin (`fairness advert <hours>`, `fairness advert clear`), převzato
|
||||
z AdvertLimiteru [DutchMeshCore](https://github.com/Dutch-MeshCore/MeshCore).
|
||||
Míří na uzly, které advertují každou minutu.
|
||||
* **Dry-run** – `fairness dryrun on` započítá každý verdikt, ale přepošle
|
||||
i tak; `fairness air` ukáže ušetřený (nebo ušetřitelný) airtime podle důvodu.
|
||||
* **Filtr kanálů** – na kanálech, jejichž klíč repeater zná (Public
|
||||
a `#hashtag` kanály), přestane přeposílat zprávy uvedených jmen odesílatelů
|
||||
(`filter add|del|list`). Jméno se dá podvrhnout: je to brzda na utrženého
|
||||
(`filter add <name>`, `filter del <name>`, `filter list`). Jméno se dá podvrhnout: je to brzda na utrženého
|
||||
bota, ne bezpečnost.
|
||||
* **Blokace přeposílání podle hashe kanálu** – `filter hash add <hex> [s]`:
|
||||
* **Blokace přeposílání podle hashe kanálu** – `filter hash add <hex> [secs]`:
|
||||
bez klíče, takže funguje i na soukromých kanálech; příjem se nemění, jen
|
||||
přeposílání. S `s` se kanál neodřízne, ale přiškrtí (jeden paket za `s`
|
||||
sekund).
|
||||
* **Limit stáří zprávy** – `filter age <min>|off` (volitelné, 1–10080 min):
|
||||
* **Limit stáří zprávy** – `filter age <minutes>` / `filter age off` (volitelné, 1–10080 min):
|
||||
nepřeposílá skupinové zprávy na dešifrovaných kanálech, jejichž čas od
|
||||
odesílatele je starší; bez nastavených hodin repeateru neplatí. Posuzuje
|
||||
hodiny odesílatele, takže zahodí i companiony bez synchronizace času –
|
||||
@@ -86,7 +89,7 @@ Repeater navíc:
|
||||
(vysílací výkon do restartu, s verdiktem RadioLibu), čítače chyb vysílání
|
||||
ve stavové odpovědi.
|
||||
* Jen observer varianty (`*-observer`): textová konzole přes BLE vedle USB,
|
||||
`ble on|off` uložené přes reboot (`RPT_BLE_DEFAULT_OFF`: startuje vypnuté),
|
||||
`ble <on|off>` uložené přes reboot (`RPT_BLE_DEFAULT_OFF`: startuje vypnuté),
|
||||
vlastní BLE PIN (`ble pin`), uložený vysílací výkon spojení (`blepwr`),
|
||||
`bleconn`, neblokující BLE vysílání a parametry spojení, které vydrží i na
|
||||
slabém linku.
|
||||
@@ -99,7 +102,7 @@ Repeater navíc:
|
||||
`!noise`, `!ping`, `!help`, výběr přes `BOT_COMMANDS`, cooldown na
|
||||
odesílatele, ignore list) – odpovídá, aniž by přeposílal;
|
||||
* `RADIO_DIAG`: `radiostat` (stav přijímače SX1262 bez zásahu) a
|
||||
`radiokick rx|clrirq|standby|agc` (jeden krok obnovy, od nejjemnějšího –
|
||||
`radiokick <rx|clrirq|standby|agc>` (jeden krok obnovy, od nejjemnějšího –
|
||||
první, který pomůže, ukáže rozbitou vrstvu);
|
||||
* `PIN_DIAG`: `dio1` (stav přerušení v čipu proti úrovni na pinu – který
|
||||
konec mrtvé linky DIO1 je přerušený);
|
||||
@@ -144,10 +147,10 @@ Repeater navíc:
|
||||
a záznam o hardfaultu přežijí teplý reset (`.noinit`); `clkreboot`.
|
||||
* Na solárních uzlech žádná blikající LED a pomalejší BLE advertising.
|
||||
* Stav baterie jako ikona na konci advertovaného jména: `set batt.icon on`,
|
||||
prahy `set batt.icon.lo|hi <mV>` (výchozí vypnuté; dlouhé jméno ikonu
|
||||
prahy `set batt.icon.lo <mV>` a `set batt.icon.hi <mV>` (výchozí vypnuté; dlouhé jméno ikonu
|
||||
nepojme a příkaz na to upozorní).
|
||||
* Volitelný RX duty cycle (`set radio.rxps off|on|balanced|max`, jemněji
|
||||
`level <1-10>`; port PowerSaving z EasySkyMesh): SX1262 mezi krátkými okny
|
||||
* Volitelný RX duty cycle (`set radio.rxps <off|on|balanced|max>`, jemněji
|
||||
`set radio.rxps level <level>` 1–10; port PowerSaving z EasySkyMesh): SX1262 mezi krátkými okny
|
||||
poslechu spí. Ve veřejných buildech je zabudovaný a **vypnutý**; `max` na
|
||||
lavici ušetřil ~2,3 mA bez ztráty paketů ([docs/power.md](docs/power.md)),
|
||||
na ostrém meshi ale jeden náš stožár ztratil 16 % příjmu – zapínat s rozmyslem. Jen
|
||||
@@ -161,8 +164,8 @@ Repeater navíc:
|
||||
([#2088](https://github.com/meshcore-dev/MeshCore/pull/2088)). Výjimkou je
|
||||
`SenseCap_Solar_repeater` (Li-ion, naše stožáry): pojistka je zapnutá
|
||||
a oba prahy jdou nastavit za běhu, i přes mesh jako admin –
|
||||
`set pwr.bootlock <mV>|off` (výchozí 3300, pod ním uzel nenaběhne a spí,
|
||||
dokud se článek nezotaví) a `set pwr.cutoff <mV>|off` (výchozí vypnuto,
|
||||
`set pwr.bootlock <mV>` nebo `off` (výchozí 3300, pod ním uzel nenaběhne a spí,
|
||||
dokud se článek nezotaví) a `set pwr.cutoff <mV>` nebo `off` (výchozí vypnuto,
|
||||
pod ním se běžící uzel vypne); `get pwr` ([docs/power.md](docs/power.md)).
|
||||
|
||||
### Senzory a companiony
|
||||
@@ -172,8 +175,8 @@ Repeater navíc:
|
||||
* Senzory, které jinak měří nepřetržitě (INA219, INA226, INA260, INA3221,
|
||||
BMP280), mezi čteními telemetrie spí a měří jen na vyžádání (nápad a první
|
||||
patch pro INA219: Alkel Brostl). Čipy INA se rozlišují podle ID, takže
|
||||
INA226 už se nedetekuje jako INA219. Odpor bočníku se nastavuje za běhu
|
||||
a ukládá se: `sensor set ina.shunt <mΩ>`.
|
||||
INA226 už se nedetekuje jako INA219. Odpor bočníku (INA219, INA226, INA3221; INA260 ho má uvnitř) se
|
||||
nastavuje za běhu a ukládá se: `sensor set ina.shunt <mOhm>`.
|
||||
* Companion: `gps duty` přežije reboot, kopie data sestavení má hlídanou
|
||||
délku. Export privátního klíče, čtení BLE PINu a jeho změna (i přes CLI
|
||||
`set pin`) jdou jen přes spárované BLE, ne přes USB, UART ani WiFi/TCP,
|
||||
@@ -343,6 +346,9 @@ the CZ mesh (869.432 MHz). Upstream `main` and `dev` are merged automatically
|
||||
twice a day; everything below is on top of that. Our code is marked
|
||||
`CUSTOM (TeTeHacko)` in the source. Nothing here changes the wire protocol.
|
||||
|
||||
The fork's and upstream's docs as a website:
|
||||
<https://tth-pub.pages.rfa.cz/meshcore-tth/>
|
||||
|
||||
### Repeater: antispam (all of it off-switchable, none of it upstream)
|
||||
|
||||
**After flashing only the FairnessLimiter is on**, with limits about twice
|
||||
@@ -356,21 +362,21 @@ off until you turn them on.
|
||||
ids already in the clear (channel hash, sender hash, advert origin). Port of
|
||||
Beanow's proposal [#1502](https://github.com/meshcore-dev/MeshCore/pull/1502),
|
||||
limits re-sized from 30 days of real CZ traffic.
|
||||
`fairness [on|off|grid|cap|refill]`; direct-routed traffic is never limited.
|
||||
`fairness <on|off>`, `fairness cap`, `fairness refill`, `fairness grid`; direct-routed traffic is never limited.
|
||||
* **Per-origin advert window** -- each node's flood advert forwarded at most
|
||||
once per N hours (`fairness advert <h>|clear`), ported from
|
||||
once per N hours (`fairness advert <hours>`, `fairness advert clear`), ported from
|
||||
[DutchMeshCore](https://github.com/Dutch-MeshCore/MeshCore)'s AdvertLimiter.
|
||||
Aimed at nodes that re-advertise every minute.
|
||||
* **Dry-run** -- `fairness dryrun on` counts every verdict but forwards anyway;
|
||||
`fairness air` reports the airtime shed (or that would be) per reason.
|
||||
* **Channel filter** -- on channels whose key the repeater knows (Public and
|
||||
`#hashtag` channels), stop forwarding messages of listed sender names
|
||||
(`filter add|del|list`). Names are spoofable: it contains a runaway bot,
|
||||
(`filter add <name>`, `filter del <name>`, `filter list`). Names are spoofable: it contains a runaway bot,
|
||||
it is not security.
|
||||
* **Channel-hash deny-forward** -- `filter hash add <hex> [secs]`: keyless,
|
||||
works on private channels too; reception is unaffected, only forwarding.
|
||||
With `secs` the channel is throttled (one packet per `secs`) instead of cut.
|
||||
* **Message age limit** -- `filter age <min>|off` (opt-in, 1-10080 min): do not
|
||||
* **Message age limit** -- `filter age <minutes>` / `filter age off` (opt-in, 1-10080 min): do not
|
||||
forward group texts on the decrypted channels whose sender timestamp is
|
||||
older; inactive while the repeater clock is unset. It judges the sender's
|
||||
clock, so companions without a time sync are dropped too -- keep it in days.
|
||||
@@ -409,7 +415,7 @@ The repeater also has:
|
||||
`txpwr` (TX power until reboot, with RadioLib's verdict), TX-failure
|
||||
counters in the status reply.
|
||||
* Observer variants only (`*-observer`): text console over BLE next to USB,
|
||||
`ble on|off` saved across reboots (`RPT_BLE_DEFAULT_OFF`: starts off), own
|
||||
`ble <on|off>` saved across reboots (`RPT_BLE_DEFAULT_OFF`: starts off), own
|
||||
BLE PIN (`ble pin`), persisted connection TX power (`blepwr`), `bleconn`, a
|
||||
non-blocking BLE TX pump and connection parameters that hold on a weak
|
||||
link.
|
||||
@@ -422,7 +428,7 @@ The repeater also has:
|
||||
`!noise`, `!ping`, `!help`, narrowed by `BOT_COMMANDS`, per-sender
|
||||
cooldown, ignore list) -- answers without repeating;
|
||||
* `RADIO_DIAG`: `radiostat` (SX1262 receiver state, hands off) and
|
||||
`radiokick rx|clrirq|standby|agc` (one recovery step at a time, gentlest
|
||||
`radiokick <rx|clrirq|standby|agc>` (one recovery step at a time, gentlest
|
||||
first -- the first that helps names the broken layer);
|
||||
* `PIN_DIAG`: `dio1` (the chip's IRQ status against the level on the pin --
|
||||
which end of a dead DIO1 line is broken);
|
||||
@@ -467,10 +473,10 @@ The repeater also has:
|
||||
hardfault record survive a warm reset (`.noinit`); `clkreboot`.
|
||||
* No blinking LED and slower BLE advertising on solar nodes.
|
||||
* Battery level as an icon at the end of the advertised name: `set batt.icon
|
||||
on`, thresholds `set batt.icon.lo|hi <mV>` (off by default; a long name has
|
||||
on`, thresholds `set batt.icon.lo <mV>` and `set batt.icon.hi <mV>` (off by default; a long name has
|
||||
no room for it and the command says so).
|
||||
* Optional RX duty cycle (`set radio.rxps off|on|balanced|max`, finer
|
||||
`level <1-10>`; ported from EasySkyMesh PowerSaving): the SX1262 sleeps
|
||||
* Optional RX duty cycle (`set radio.rxps <off|on|balanced|max>`, finer
|
||||
`set radio.rxps level <level>` 1-10; ported from EasySkyMesh PowerSaving): the SX1262 sleeps
|
||||
between short listening windows. Built into the public releases and
|
||||
**off**; `max` saved ~2.3 mA on the bench with no packet loss
|
||||
([docs/power.md](docs/power.md)), but on the live mesh one of our masts lost
|
||||
@@ -485,8 +491,8 @@ The repeater also has:
|
||||
for upstream ([#2088](https://github.com/meshcore-dev/MeshCore/pull/2088)). The exception
|
||||
is `SenseCap_Solar_repeater` (Li-ion, our masts): the lock is on and both
|
||||
thresholds are settable at runtime, also as an admin over the mesh --
|
||||
`set pwr.bootlock <mV>|off` (default 3300; below it the node does not start
|
||||
and sleeps until the cell recovers) and `set pwr.cutoff <mV>|off` (default
|
||||
`set pwr.bootlock <mV>` or `off` (default 3300; below it the node does not start
|
||||
and sleeps until the cell recovers) and `set pwr.cutoff <mV>` or `off` (default
|
||||
off; below it a running node switches off); `get pwr`
|
||||
([docs/power.md](docs/power.md)).
|
||||
|
||||
@@ -497,8 +503,9 @@ The repeater also has:
|
||||
* Sensors that would otherwise convert continuously (INA219, INA226, INA260,
|
||||
INA3221, BMP280) sleep between telemetry reads and measure on demand (idea
|
||||
and first INA219 patch: Alkel Brostl). INA chips are told apart by their ID,
|
||||
so an INA226 is no longer taken for an INA219. The shunt is set at runtime
|
||||
and saved: `sensor set ina.shunt <mOhm>`.
|
||||
so an INA226 is no longer taken for an INA219. The shunt (INA219, INA226,
|
||||
INA3221; the INA260 has it inside) is set at runtime and saved:
|
||||
`sensor set ina.shunt <mOhm>`.
|
||||
* Companion: `gps duty` persists, bounded build-date copy. Private key
|
||||
export, reading the BLE PIN and changing it (CLI `set pin` included) work
|
||||
only over paired BLE, never over USB, a UART or WiFi/TCP, and the reply that
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
{
|
||||
"build": {
|
||||
"arduino": {
|
||||
"ldscript": "nrf52840_s140_v6.ld"
|
||||
},
|
||||
"core": "nRF5",
|
||||
"cpu": "cortex-m4",
|
||||
"extra_flags": "-DNRF52840_XXAA",
|
||||
"f_cpu": "64000000L",
|
||||
"hwids": [
|
||||
["0x239A", "0x4405"],
|
||||
["0x239A", "0x0029"],
|
||||
["0x239A", "0x002A"],
|
||||
["0x1915", "0x1667"]
|
||||
],
|
||||
"usb_product": "pocket-v2",
|
||||
"mcu": "nrf52840",
|
||||
"variant": "heltec_meshpocket_v2",
|
||||
"bsp": {
|
||||
"name": "adafruit"
|
||||
},
|
||||
"softdevice": {
|
||||
"sd_flags": "-DS140",
|
||||
"sd_name": "s140",
|
||||
"sd_version": "6.1.1",
|
||||
"sd_fwid": "0x00B6"
|
||||
},
|
||||
"bootloader": {
|
||||
"settings_addr": "0xFF000"
|
||||
}
|
||||
},
|
||||
"connectivity": ["bluetooth"],
|
||||
"debug": {
|
||||
"jlink_device": "nRF52840_xxAA",
|
||||
"onboard_tools": ["jlink"],
|
||||
"svd_path": "nrf52840.svd",
|
||||
"openocd_target": "nrf52840-mdk-rs"
|
||||
},
|
||||
"frameworks": ["arduino"],
|
||||
"name": "Heltec Mesh Pocket V2 (Adafruit BSP)",
|
||||
"upload": {
|
||||
"maximum_ram_size": 237568,
|
||||
"maximum_size": 815104,
|
||||
"speed": 115200,
|
||||
"protocol": "nrfutil",
|
||||
"protocols": ["jlink", "nrfjprog", "nrfutil", "stlink"],
|
||||
"use_1200bps_touch": true,
|
||||
"require_upload_port": true,
|
||||
"wait_for_upload_port": true
|
||||
},
|
||||
"url": "https://heltec.org",
|
||||
"vendor": "Heltec"
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/* Docs site of the meshcore-tth fork (mkdocs.tth.yml, theme mkdocs-terminal,
|
||||
palette "dark"): only what the palette lacks. Green instead of its blue,
|
||||
and the GitHub callouts (> [!WARNING]) the theme does not style. */
|
||||
:root {
|
||||
--primary-color: #5fd38d;
|
||||
--progress-bar-fill: #5fd38d;
|
||||
/* plain black; the palette's 60em column was a thin noodle on a wide
|
||||
screen (user, 2. 12. 2026) */
|
||||
--background-color: #000;
|
||||
--invert-font-color: #000;
|
||||
--code-bg-color: #161616;
|
||||
--page-width: min(110em, 94vw);
|
||||
}
|
||||
|
||||
.admonition {
|
||||
border: 1px solid var(--secondary-color);
|
||||
padding: 0.2em 1em;
|
||||
margin: var(--global-line-height) 0;
|
||||
}
|
||||
.admonition-title {
|
||||
font-weight: bold;
|
||||
margin: 0.4em 0 0;
|
||||
}
|
||||
.admonition.warning, .admonition.caution, .admonition.danger {
|
||||
border-color: #e5a50a;
|
||||
}
|
||||
.admonition.warning > .admonition-title,
|
||||
.admonition.caution > .admonition-title,
|
||||
.admonition.danger > .admonition-title {
|
||||
color: #e5a50a;
|
||||
}
|
||||
.admonition.note > .admonition-title,
|
||||
.admonition.tip > .admonition-title,
|
||||
.admonition.important > .admonition-title {
|
||||
color: var(--primary-color);
|
||||
}
|
||||
@@ -198,7 +198,7 @@ know whether a change like `f6e9aeca` (widening the requested interval to
|
||||
from the last one; before any client has ever connected it answers
|
||||
`nothing seen yet`.
|
||||
|
||||
### `blepwr [dBm]` — connection TX power, saved
|
||||
### `blepwr [dBm|default]` — connection TX power, saved
|
||||
|
||||
```
|
||||
blepwr # report: BLE conn tx: 0 dBm, adv tx: 8 dBm
|
||||
|
||||
+27
-9
@@ -44,6 +44,8 @@ This document provides an overview of CLI commands that can be sent to MeshCore
|
||||
---
|
||||
|
||||
### Reset the clock and reboot
|
||||
*meshcore-tth addition.*
|
||||
|
||||
**Usage:**
|
||||
- `clkreboot`
|
||||
|
||||
@@ -74,7 +76,7 @@ locally.
|
||||
|
||||
**Reply:** `HH:MM - D/M/YYYY UTC (epoch <seconds>)`
|
||||
|
||||
The epoch is a TeTeHacko addition. The human part is minutes only, so a host
|
||||
The epoch is a meshcore-tth addition. The human part is minutes only, so a host
|
||||
comparing clocks cannot see a difference smaller than a minute and has to leave
|
||||
a deadband of over 59 s; the epoch makes the comparison exact. It is appended,
|
||||
so anything that only prints the reply is unaffected.
|
||||
@@ -398,13 +400,13 @@ Refer to the node's manual for the correct settings to use.
|
||||
|
||||
#### Show battery state as an icon on the advertised name
|
||||
|
||||
*(TeTeHacko fork)* Appends a solar marker and a charge level to the name
|
||||
*meshcore-tth addition.* Appends a solar marker and a charge level to the name
|
||||
carried in adverts, so anyone who hears the node can see its state without
|
||||
logging in for telemetry. Off by default.
|
||||
|
||||
**Usage:**
|
||||
- `get batt.icon`
|
||||
- `set batt.icon on|off`
|
||||
- `set batt.icon <on|off>`
|
||||
|
||||
**Default:** `off`
|
||||
|
||||
@@ -431,6 +433,8 @@ changes roughly once a week.
|
||||
---
|
||||
|
||||
#### Battery scale for the name icon
|
||||
*meshcore-tth addition.*
|
||||
|
||||
**Usage:**
|
||||
- `get batt.icon.lo` / `set batt.icon.lo <millivolts>`
|
||||
- `get batt.icon.hi` / `set batt.icon.hi <millivolts>`
|
||||
@@ -581,12 +585,16 @@ so the icon and the Grafana percentage tell one story.
|
||||
|
||||
---
|
||||
|
||||
#### View or change the RX duty cycle (rxps) -- CUSTOM (TeTeHacko)
|
||||
#### View or change the RX duty cycle (rxps)
|
||||
*meshcore-tth addition.*
|
||||
|
||||
**Usage:**
|
||||
- `get radio.rxps`
|
||||
- `set radio.rxps off|on|balanced|max`
|
||||
- `set radio.rxps level <1-10> [preamble <16|32>]`
|
||||
- `set radio.rxps max preamble <16|32>`
|
||||
- `set radio.rxps <off|on|balanced|max|overdrive|riskyWorkingMax>`
|
||||
- `set radio.rxps <max|overdrive|riskyWorkingMax> preamble <16|32>`
|
||||
- `set radio.rxps level <level> [preamble <16|32>]`
|
||||
- `set radio.rxps <level>`
|
||||
- `set radio.rxps <rx_us> <sleep_us>`
|
||||
|
||||
The SX1262 sleeps between short listening windows (`SetRxDutyCycle`) instead
|
||||
of listening all the time, and stays awake through a packet once it hears a
|
||||
@@ -600,7 +608,7 @@ off until you set it; the setting is saved.
|
||||
higher the level, the longer the sleep. The named presets assume senders
|
||||
with a 16-symbol preamble (the MeshCore default), so they are safe on a
|
||||
mixed mesh.
|
||||
- `level <n>`: the same scale by number; without `preamble` it follows the SF.
|
||||
- `level`: the same scale by number, 1..10; without `preamble` it follows the SF.
|
||||
9 (`overdrive`) and 10 (`riskyWorkingMax`) are past the datasheet's timing
|
||||
condition -- 10 is known to lose packets.
|
||||
- `<rx_us> <sleep_us>`: raw window lengths.
|
||||
@@ -797,6 +805,8 @@ also runs in continuous RX.
|
||||
---
|
||||
|
||||
#### Radio silence watchdog (repeater, sensor, room server)
|
||||
*meshcore-tth addition.*
|
||||
|
||||
**Usage:**
|
||||
- `get radio.silence`
|
||||
- `set radio.silence <minutes>`
|
||||
@@ -814,6 +824,8 @@ To keep a quiet site out of a reboot loop, each such reboot doubles the threshol
|
||||
---
|
||||
|
||||
#### TX stall watchdog (repeater)
|
||||
*meshcore-tth addition.*
|
||||
|
||||
**Usage:**
|
||||
- `get radio.txstall`
|
||||
- `set radio.txstall <minutes>`
|
||||
@@ -828,6 +840,8 @@ To keep a quiet site out of a reboot loop, each such reboot doubles the threshol
|
||||
---
|
||||
|
||||
#### Reboot into the bootloader (repeater, sensor, room server; nRF52, local console only)
|
||||
*meshcore-tth addition.*
|
||||
|
||||
**Usage:**
|
||||
- `dfu [uf2|serial|ota]`
|
||||
|
||||
@@ -836,6 +850,8 @@ To keep a quiet site out of a reboot loop, each such reboot doubles the threshol
|
||||
---
|
||||
|
||||
#### Why the board last reset (repeater, sensor, room server)
|
||||
*meshcore-tth addition.*
|
||||
|
||||
**Usage:**
|
||||
- `get boot`
|
||||
|
||||
@@ -1227,7 +1243,7 @@ region save
|
||||
|
||||
**Note:** In duty-cycle mode `gps` answers `duty, {awake|asleep}, {fix|no fix}, {sat count} sats`.
|
||||
|
||||
`gps duty` powers the receiver only around a clock sync and cuts it in between.
|
||||
*meshcore-tth addition:* `gps duty` powers the receiver only around a clock sync and cuts it in between.
|
||||
It is meant for a node that runs GPS purely to keep its (volatile) RTC set — a
|
||||
mast or solar repeater — where a receiver drawing tens of mA continuously
|
||||
dwarfs the rest of the power budget. Unlike `gps period`, every attempt is
|
||||
@@ -1378,6 +1394,8 @@ Covers serial NMEA receivers (`MicroNMEALocationProvider`).
|
||||
---
|
||||
|
||||
#### Set the INA current sensor's shunt resistor
|
||||
*meshcore-tth addition.*
|
||||
|
||||
**Usage:**
|
||||
- `sensor get ina.shunt`
|
||||
- `sensor set ina.shunt <mOhm>`
|
||||
|
||||
@@ -22,6 +22,7 @@ Once you have a working app/project, you need to be able to demonstrate it exist
|
||||
| 0140 | Nelos | support@nelos.app — https://nelos.app |
|
||||
| 0150 | Road Events | juraj@bednar.io — https://github.com/jooray/roadbeacon/blob/main/nips/road-events.md |
|
||||
| 0160 | Knit | jeff@getknit.app — https://getknit.app |
|
||||
| 0170 | MeshTrax | venahamtrack@gmail.com — https://github.com/venamartin/meshtrax |
|
||||
| FF00 - FFFF | -reserved for testing/dev- | |
|
||||
|
||||
(add rows, inside the range 0100 - FEFF for custom apps)
|
||||
+3
-3
@@ -212,10 +212,10 @@ wired in `variants/sensecap_solar`) and `PWRMGT_RUNTIME` (ours), which gives
|
||||
two thresholds, both saved on the node and settable from the console or as an
|
||||
admin over the mesh:
|
||||
|
||||
| | default | |
|
||||
| command | default | what |
|
||||
|---|---|---|
|
||||
| `set pwr.bootlock <mV>\|off` | 3300 mV (`variant.h`) | at boot, below it the node goes to SYSTEMOFF and the LPCOMP wakes it when the battery recovers |
|
||||
| `set pwr.cutoff <mV>\|off` | off | while running, three readings in a row (one a minute) below it switch the node off into the same SYSTEMOFF |
|
||||
| `set pwr.bootlock <mV>` | 3300 mV (`variant.h`) | 3000..4200 or `off`; at boot, below it the node goes to SYSTEMOFF and the LPCOMP wakes it when the battery recovers |
|
||||
| `set pwr.cutoff <mV>` | off | 3000..4200 or `off`; while running, three readings in a row (one a minute) below it switch the node off into the same SYSTEMOFF |
|
||||
| `get pwr` | | both, the battery now and at boot, USB, the reason of the last switch-off |
|
||||
|
||||
The cutoff must stay below the bootlock -- a node switched off at the cutoff
|
||||
|
||||
+80
-50
@@ -9,6 +9,10 @@ Everything this fork adds to the text console of a node, on top of upstream's
|
||||
(the watchdogs, `rxps`, `batt.icon`, `gps duty`, `dfu`, `get boot`), this page
|
||||
gives the short form and points to it.
|
||||
|
||||
**How commands are written** (as in cli_commands.md): `<value>` is required,
|
||||
`[value]` optional, `<on|off>` one of the listed words. One command per line;
|
||||
ranges, units and defaults are in the description.
|
||||
|
||||
**Where a command exists** depends on the role and on build flags:
|
||||
|
||||
| mark | builds |
|
||||
@@ -33,18 +37,19 @@ Token buckets on forwarded floods, keyed on the 1-byte ids already in the
|
||||
clear: channel hash, sender hash, advert origin. Buckets collide (the hash is
|
||||
masked), and every key is chosen by the sender: it contains runaway floods,
|
||||
it is not security. Direct-routed traffic is never limited.
|
||||
**On after flashing** (`FAIRNESS_ENABLED_DEFAULT`).
|
||||
|
||||
| command | |
|
||||
| command | what |
|
||||
|---|---|
|
||||
| `fairness` | state, denials per category, caps and refill intervals |
|
||||
| `fairness on\|off` | the buckets on/off |
|
||||
| `fairness cap <group> <sender> <advert>` | burst caps 0..255, `0` = build default (100 / 150 / 30) |
|
||||
| `fairness refill <group_s> <sender_s> <advert_s>` | one token per interval, seconds, `0` = default (30 / 10 / 600) |
|
||||
| `fairness <on\|off>` | the buckets on or off. Default: on (`FAIRNESS_ENABLED_DEFAULT`) |
|
||||
| `fairness cap <group> <sender> <advert>` | burst caps, 0..255 each; `0` = build default (100 / 150 / 30) |
|
||||
| `fairness refill <group> <sender> <advert>` | one token per interval, seconds, 0..65535 each; `0` = build default (30 / 10 / 600) |
|
||||
| `fairness grid` | the busiest denied buckets per category -- what is being shed |
|
||||
| `fairness air` | estimated airtime shed per reason |
|
||||
| `fairness advert [<hours>\|clear]` | per-origin advert window: one flood advert per origin per `<hours>` (0..720, `0` = off, default off); `clear` forgets the origins seen |
|
||||
| `fairness dryrun [on\|off]` | count every verdict but forward anyway (default off) |
|
||||
| `fairness advert` | the per-origin advert window: hours, held adverts, cache |
|
||||
| `fairness advert <hours>` | one flood advert per origin per `hours`, 0..720; `0` = off. Default: off |
|
||||
| `fairness advert clear` | forget the origins seen |
|
||||
| `fairness dryrun [on\|off]` | count every verdict but forward anyway; without an argument shows the state. Default: off |
|
||||
|
||||
The defaults keep about twice the headroom over 30 days of CZ mesh traffic
|
||||
(the zero-loss frontier was 60 s / cap 60 per channel, 10 s / 60 per sender,
|
||||
@@ -57,11 +62,12 @@ know Public, `#meshcore` and `#test`) the node decrypts each group text and
|
||||
refuses to forward listed senders. The sender name is plain text in the
|
||||
message: anyone can rename around it.
|
||||
|
||||
| command | |
|
||||
| command | what |
|
||||
|---|---|
|
||||
| `filter` / `filter list` | channels known, drops, the deny list |
|
||||
| `filter add <name>` / `filter del <name>` | exact, case-insensitive; spaces allowed, commas not |
|
||||
| `filter clear` | empty the list |
|
||||
| `filter [list]` | channels known, drops, the deny list |
|
||||
| `filter add <name>` | deny a sender name: exact, case-insensitive; spaces allowed, commas not |
|
||||
| `filter del <name>` | remove a name from the deny list |
|
||||
| `filter clear` | empty the deny list |
|
||||
|
||||
### Channel-hash deny-forward -- `filter hash` (every repeater)
|
||||
|
||||
@@ -70,41 +76,48 @@ so this works on private channels too. One byte is coarse -- every other
|
||||
channel whose key hashes to the same byte is hit as well; check what else
|
||||
lives on it before adding one.
|
||||
|
||||
| command | |
|
||||
| command | what |
|
||||
|---|---|
|
||||
| `filter hash` | drops, passes by a throttle, the list (`43` blocked, `43/60` throttled) |
|
||||
| `filter hash add <hex> [secs]` | block the byte, or let one packet through per `secs` (1..65535); re-adding changes the interval |
|
||||
| `filter hash del <hex>` / `filter hash clear` | |
|
||||
| `filter hash [list]` | drops, passes by a throttle, the list (`43` blocked, `43/60` throttled) |
|
||||
| `filter hash add <hex> [secs]` | block the byte, or with `secs` (1..65535) let one packet through per `secs`; re-adding changes the interval |
|
||||
| `filter hash del <hex>` | remove one byte |
|
||||
| `filter hash clear` | empty the list |
|
||||
|
||||
A throttle's window lives in RAM: the first match after a boot passes.
|
||||
|
||||
### Message age -- `filter age` (repeater with channel keys)
|
||||
|
||||
`filter age <min>|off` (1..10080, default off): do not forward a group text
|
||||
on a decrypted channel whose sender timestamp is older than `<min>` by this
|
||||
node's clock. It judges the sender's clock, so a companion that never got a
|
||||
time sync (it stamps 2024) is dropped too -- keep it in days. Inactive while
|
||||
the node's own clock reads before 2026; a clock running ahead makes
|
||||
everything look old.
|
||||
| command | what |
|
||||
|---|---|
|
||||
| `filter age` | the limit and how many were dropped |
|
||||
| `filter age <minutes>` | do not forward a group text on a decrypted channel whose sender timestamp is older than `minutes` (1..10080) by this node's clock |
|
||||
| `filter age off` | no age limit. Default: off |
|
||||
|
||||
### `filter dryrun [on|off]`
|
||||
It judges the sender's clock, so a companion that never got a time sync (it
|
||||
stamps 2024) is dropped too -- keep it in days. Inactive while the node's own
|
||||
clock reads before 2026; a clock running ahead makes everything look old.
|
||||
|
||||
Count every `filter` verdict (sender, hash, age) but forward anyway -- try a
|
||||
rule on a live node before it bites. Default off.
|
||||
### Dry run -- `filter dryrun`
|
||||
|
||||
| command | what |
|
||||
|---|---|
|
||||
| `filter dryrun [on\|off]` | count every `filter` verdict (sender, hash, age) but forward anyway -- try a rule on a live node before it bites; without an argument shows the state. Default: off |
|
||||
|
||||
## Radio watchdogs and board upkeep (all)
|
||||
|
||||
Details: [cli_commands.md](cli_commands.md), "Radio silence watchdog", "TX
|
||||
stall watchdog", "Reboot into the bootloader" and "Why the board last reset".
|
||||
|
||||
| command | |
|
||||
| command | what |
|
||||
|---|---|
|
||||
| `set radio.silence <min>\|off` / `get radio.silence` | deaf receiver: re-arm RX, then reboot after `<min>` without a received frame (CRC errors count as heard); each such reboot doubles the threshold for the next boot (up to 16x), the first frame clears it. 1..1440, persisted, **default off** |
|
||||
| `set radio.txstall <min>\|off` / `get radio.txstall` | repeater only: packets queued and nothing sent for `<min>` -> re-arm, then reboot. An empty queue never counts. **On, 15 min** (`RADIO_TXSTALL_MIN`); a change holds until reboot |
|
||||
| `get radio.silence` | threshold, current multiplier, quiet time, stage |
|
||||
| `set radio.silence <minutes>` | deaf receiver: re-arm RX, then reboot after `minutes` (1..1440) without a received frame (CRC errors count as heard); each such reboot doubles the threshold for the next boot (up to 16x), the first frame clears it. `0` or `off` = off. Saved. Default: off |
|
||||
| `get radio.txstall` | threshold, queue, time without TX, stage |
|
||||
| `set radio.txstall <minutes>` | repeater only: packets queued and nothing sent for `minutes` (1..1440) -> re-arm, then reboot. An empty queue never counts. `0` or `off` = off. Not saved: a reboot returns to the build value. Default: 15 (`RADIO_TXSTALL_MIN`) |
|
||||
| `get radio.reboots` | reboots done by the watchdogs, survives power loss |
|
||||
| `get boot` | reset reason and the hardfault record (also printed at boot) |
|
||||
| `dfu [uf2\|serial\|ota]` | *local only*: reboot into the bootloader -- UF2 drive (default), CDC port for `adafruit-nrfutil`, or BLE DFU |
|
||||
| `fw ...` | `-ota` images only: admin-pushed firmware update, see [ota.md](ota.md) |
|
||||
| `dfu [uf2\|serial\|ota]` | *local only*, nRF52: reboot into the bootloader -- UF2 drive (default), CDC port for `adafruit-nrfutil`, or BLE DFU |
|
||||
| `fw <subcommand>` | `-ota` images only: admin-pushed firmware update, see [ota.md](ota.md) |
|
||||
|
||||
## Number arguments of `set` (all, and the companion's serial CLI)
|
||||
|
||||
@@ -123,15 +136,17 @@ tz.offset`. No exponent (`1e3`), no `nan`/`inf`.
|
||||
|
||||
## Diagnostics
|
||||
|
||||
| command | where | |
|
||||
| command | where | what |
|
||||
|---|---|---|
|
||||
| `blink [n]` / `blink on\|off` | repeater | flash a spare LED (not the BLE or TX one) `n` times (default 6, max 999), or until `blink off` (gives up after 10 min); finds a board on a bench or a node on a mast |
|
||||
| `txpwr [dBm]` | repeater | LoRa output power until reboot, with RadioLib's status; takes -9..30 |
|
||||
| `blink [count]` | repeater | flash a spare LED (not the BLE or TX one) `count` times (1..999, default 6); finds a board on a bench or a node on a mast |
|
||||
| `blink <on\|off>` | repeater | blink until `blink off` (gives up after 10 min) |
|
||||
| `txpwr` | repeater | the last requested LoRa output power and RadioLib's status |
|
||||
| `txpwr <dBm>` | repeater | LoRa output power until reboot, -9..30 (SX1262 takes -9..22), with RadioLib's status |
|
||||
| `i2c` | all | scan the I2C bus |
|
||||
| `get chip` | nRF52 (repeater, room server, sensor) | the silicon (`nRF52840 AAD0`; variant `xxF0` and later = rev3) and `UICR.APPROTECT`: `open` means SWD can read the whole flash, keys included ([locked-bootloader.md](locked-bootloader.md)) |
|
||||
| `get chip` | nRF52 (repeater, room server, sensor) | the silicon (`nRF52840 AAD0`; variant `xxF0` and later = rev3) and `UICR.APPROTECT`: `open` means SWD can read the whole flash, keys included |
|
||||
| `dio1` | own build: `PIN_DIAG` | has the SX1262 raise TX_DONE and compares its IRQ register with the level on the DIO1 pin -- which end of a dead IRQ line is broken |
|
||||
| `radiostat` | own build: `RADIO_DIAG` | receiver state, interrupt and RX counters, without touching the radio |
|
||||
| `radiokick rx\|clrirq\|standby\|agc` | own build: `RADIO_DIAG` | one recovery step, gentlest first: re-arm RX, clear latched IRQs, standby + RX, AGC reset; the first that brings `recv` back names the broken layer |
|
||||
| `radiokick <rx\|clrirq\|standby\|agc>` | own build: `RADIO_DIAG` | one recovery step, gentlest first: re-arm RX, clear latched IRQs, standby + RX, AGC reset; the first that brings `recv` back names the broken layer |
|
||||
|
||||
A board with a dead DIO1 line still runs with `LORA_POLL_IRQ` (own build):
|
||||
the IRQ status is polled over SPI.
|
||||
@@ -142,12 +157,15 @@ The text console over BLE (Nordic UART), next to USB. No login of its own:
|
||||
the BLE PIN is the only lock, and the release PIN is the public placeholder
|
||||
`123456`. These commands also work as admin over the mesh.
|
||||
|
||||
| command | |
|
||||
| command | what |
|
||||
|---|---|
|
||||
| `ble` | on/off, PIN `own` or `build default` -- never the PIN itself |
|
||||
| `ble pin <6 digits>` | set your own PIN (saved, survives a reflash; drops every bond, so paired devices pair again) |
|
||||
| `ble on\|off` | persisted; **off after flashing** (`RPT_BLE_DEFAULT_OFF`), and `ble on` is refused while the PIN is the placeholder |
|
||||
| `blepwr [dBm\|default]` | TX power of the connection (-40, -20, -16, -12, -8, -4, 0, 2..8), applied to live connections and saved; `default` returns to the build value (0 dBm) |
|
||||
| `ble` | on or off, PIN `own` or `build default`, connected or not -- never the PIN itself |
|
||||
| `ble <on\|off>` | the BLE console on or off, saved. Default: off (`RPT_BLE_DEFAULT_OFF`); `ble on` is refused while the PIN is the placeholder |
|
||||
| `ble pin` | whether the PIN is your own or the build default |
|
||||
| `ble pin <pin>` | set your own PIN, 6 digits (saved, survives a reflash; drops every bond, so paired devices pair again) |
|
||||
| `blepwr` | TX power of the connection and of advertising |
|
||||
| `blepwr <dBm>` | TX power of the connection: -40, -20, -16, -12, -8, -4, 0, 2..8; applied to live connections and saved |
|
||||
| `blepwr default` | back to the build value (0 dBm) |
|
||||
| `bleconn` | what the central actually agreed to: interval (and what was requested), latency, supervision timeout |
|
||||
|
||||
A connected central stops the node advertising: if the BLE console cannot be
|
||||
@@ -155,9 +173,9 @@ found, look for who is connected (`ble` shows it).
|
||||
|
||||
## Passive analyzer (observer)
|
||||
|
||||
| command | |
|
||||
| command | what |
|
||||
|---|---|
|
||||
| `nodes [offset]` | heard repeaters and room servers with a key to join several paths, paged |
|
||||
| `nodes [offset]` | heard repeaters and room servers with a key to join several paths, paged from `offset` |
|
||||
| `rxlog [cursor]` | every frame heard: type, path, SNR, RSSI; `cursor` from the previous page (`0` = all) |
|
||||
| `pktlog [cursor]` | raw frames heard, for an observer feed ([meshcore-repeater-observer](https://git.rfa.cz/tth-pub/meshcore-repeater-observer)) |
|
||||
|
||||
@@ -173,27 +191,39 @@ console shows its state.
|
||||
|
||||
## Power and clock
|
||||
|
||||
| command | where | |
|
||||
| command | where | what |
|
||||
|---|---|---|
|
||||
| `set radio.rxps off\|on\|balanced\|max`, `level <1-10> [preamble 16\|32]` / `get radio.rxps` | all, SX1262 only (`WITH_RX_POWERSAVING`, in the releases) | RX duty cycle: the radio sleeps between short listening windows. **Off by default.** `max` saved ~2.3 mA on the bench, but a mast on the live mesh lost 16 % of its reception -- see cli_commands.md and [power.md](power.md) |
|
||||
| `set batt.icon on\|off`, `set batt.icon.lo\|hi <mV>` | all | battery level as an icon at the end of the advertised name (off by default; with a name too long for it the icon is left out, and the reply says so) |
|
||||
| `gps duty ...` | GPS boards | the receiver runs only around a clock sync; see cli_commands.md |
|
||||
| `get pwr`, `set pwr.bootlock <mV>\|off`, `set pwr.cutoff <mV>\|off` | SenseCAP Solar repeater (`PWRMGT_RUNTIME`) | battery thresholds: don't start below the bootlock, switch a running node off below the cutoff (cutoff < bootlock, none above the battery right now); saved on the node, see [power.md](power.md) |
|
||||
| `get radio.rxps` | all, SX1262 only (`WITH_RX_POWERSAVING`, in the releases) | requested and effective RX duty cycle, window lengths, error counters |
|
||||
| `set radio.rxps <off\|on\|balanced\|max>` | same | RX duty cycle: the radio sleeps between short listening windows. Presets: `on` = level 3, `balanced` = 6, `max` = 8. Saved. Default: off |
|
||||
| `set radio.rxps level <level> [preamble <16\|32>]` | same | the same by number, 1..10 (9 and 10 are past the datasheet's timing condition, 10 is known to lose packets) |
|
||||
| `set radio.rxps <rx_us> <sleep_us>` | same | raw window lengths |
|
||||
| `get batt.icon` | all | whether the icon is on, and whether the name leaves room for it |
|
||||
| `set batt.icon <on\|off>` | all | battery level as an icon at the end of the advertised name; with a name too long for it the icon is left out, and the reply says so. Default: off |
|
||||
| `set batt.icon.lo <mV>` | all | the empty end of the icon's scale, 2500..4500; `0` = build default (3300) |
|
||||
| `set batt.icon.hi <mV>` | all | the full end, 2500..4500; `0` = build default (4200) |
|
||||
| `gps duty` | GPS boards | the receiver runs only around a clock sync; `gps on` / `gps off` leave it. See cli_commands.md |
|
||||
| `get pwr` | SenseCAP Solar repeater (`PWRMGT_RUNTIME`) | both thresholds, the battery now and at boot, why the node last switched off |
|
||||
| `set pwr.bootlock <mV>` | same | do not start below this voltage, 3000..4200 or `off`; saved on the node, see [power.md](power.md) |
|
||||
| `set pwr.cutoff <mV>` | same | switch a running node off below this voltage, 3000..4200 or `off`. Must stay under the bootlock; neither may be above the battery right now |
|
||||
| `clkreboot` | all | reset the clock to the build epoch and reboot -- the only way to move a clock backwards (`time` and `clock sync` refuse to) |
|
||||
|
||||
RX duty cycle: `max` saved ~2.3 mA on the bench, but a mast on the live mesh
|
||||
lost 16 % of its reception -- see cli_commands.md and [power.md](power.md).
|
||||
|
||||
## Sensors
|
||||
|
||||
| command | |
|
||||
| command | what |
|
||||
|---|---|
|
||||
| `sensor read` | the live telemetry decoded into one line (`sensor list` shows only settings) |
|
||||
| `sensor set ina.shunt <mOhm>` | shunt resistance of an INA219/226/260/3221, saved across reboots |
|
||||
| `sensor get ina.shunt` | the shunt the current is computed with |
|
||||
| `sensor set ina.shunt <mOhm>` | shunt resistance of an INA219, INA226 or INA3221 module (`10` for `R010`), saved; `0` = build default (100). The INA260 has its shunt inside and no setting |
|
||||
|
||||
## Build flags
|
||||
|
||||
The ones that change what a node does; set in `platformio.ini` /
|
||||
`platformio.local.ini` (`-D NAME=value`, the last `-D` wins).
|
||||
|
||||
| flag | default | |
|
||||
| flag | default | what |
|
||||
|---|---|---|
|
||||
| `FAIRNESS_ENABLED_DEFAULT` | `1` | FairnessLimiter on for a node without prefs |
|
||||
| `RADIO_SILENCE_MIN_DEFAULT` | `0` | deaf-receiver watchdog for a node without prefs |
|
||||
@@ -206,7 +236,7 @@ The ones that change what a node does; set in `platformio.ini` /
|
||||
| `FW_OTA` | `-ota` images | admin-pushed firmware update |
|
||||
| `PATH_HASH_MODE_DEFAULT` | `1` (2 B per hop) | path hash width for a node without prefs |
|
||||
| `ACL_TS_MAX_AHEAD` | `86400` (s) | a client timestamp further ahead of the node's clock is not stored as the replay floor |
|
||||
| `LOCKED_NODE` | unset | a node that keeps its secrets from whoever holds it: `get prv.key`, `get guest.password` and `get bridge.secret` answer `Error: locked build` to everyone (USB and BLE console, an admin over the mesh); a companion serves only paired BLE (USB, UART and WiFi get the device info and nothing else) and its rescue CLI refuses `set pin`. Only half of it: [locked-bootloader.md](locked-bootloader.md) |
|
||||
| `LOCKED_NODE` | unset | a node that keeps its secrets from whoever holds it: `get prv.key`, `get guest.password` and `get bridge.secret` answer `Error: locked build` to everyone (USB and BLE console, an admin over the mesh); a companion serves only paired BLE (USB, UART and WiFi get the device info and nothing else) and its rescue CLI refuses `set pin`. Only half of it: whoever can rewrite the flash (SWD with `APPROTECT` open, an unsigned DFU) still gets the keys -- the other half is a locked bootloader (SWD closed, signed images only), which these builds do not have |
|
||||
| `LOGIN_FAIL_MAX`, `LOGIN_FAIL_SECS` | `4`, `180` (s) | after that many wrong passwords in the window no password is checked until it ends (an admin already in the ACL always gets in) |
|
||||
| `NRF52_POWER_MANAGEMENT`, `PWRMGT_RUNTIME` | upstream: off; on in `SenseCap_Solar_repeater` (the masts) | boot protection, and with `PWRMGT_RUNTIME` the runtime `pwr.bootlock` / `pwr.cutoff` above |
|
||||
| `PWRMGT_BOOTLOCK_DEFAULT`, `PWRMGT_CUTOFF_DEFAULT` | `PWRMGT_VOLTAGE_BOOTLOCK` (SenseCAP 3300), `0` (mV) | thresholds for a node without `/pwr_guard` |
|
||||
|
||||
@@ -1146,11 +1146,7 @@ void MyMesh::handleCmdFrame(size_t len) {
|
||||
text[tlen] = 0; // ensure null
|
||||
|
||||
reply_buf[0] = 0;
|
||||
if (memcmp(text, "set pin ", 8) == 0 && !_serial->isConnectionSecure()) {
|
||||
// CUSTOM (TeTeHacko): the same gate as CMD_SET_DEVICE_PIN -- through the
|
||||
// CLI, USB set the PIN it may not set directly, then paired over BLE
|
||||
strcpy(reply_buf, "Error: set pin only over paired BLE");
|
||||
} else if (!handleCommand(text, 0, reply_buf)) {
|
||||
if (!handleCommand(text, 0, reply_buf)) {
|
||||
strcat(reply_buf, "Unknown command"); // reply_buf may have cmd prefix from 'text'
|
||||
}
|
||||
out_frame[0] = RESP_CODE_CLI_REPLY;
|
||||
@@ -2130,14 +2126,7 @@ void MyMesh::enterCLIRescue() {
|
||||
extern "C" void retainedClockInvalidate() __attribute__((weak)); // NRF52Board.cpp
|
||||
|
||||
bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char* reply) {
|
||||
while (*command == ' ') command++; // skip leading spaces
|
||||
|
||||
if (strlen(command) > 4 && command[2] == '|') { // optional prefix (for companion radio CLI)
|
||||
memcpy(reply, command, 3); // reflect the prefix back
|
||||
reply += 3;
|
||||
*reply = 0;
|
||||
command += 3;
|
||||
}
|
||||
cli_args::stripPrefix(command, reply);
|
||||
|
||||
if (_prefs.getRadioPrefs()->handleCommand(command, sender_timestamp, reply)) { // is radio CLI command?
|
||||
if (_prefs.getRadioPrefs()->isDirty()) { savePrefs(); }
|
||||
@@ -2211,6 +2200,17 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char*
|
||||
#endif
|
||||
|
||||
if (memcmp(command, "set pin ", 8) == 0) {
|
||||
const char* err = nullptr;
|
||||
#ifdef LOCKED_NODE
|
||||
const bool locked = true;
|
||||
#else
|
||||
const bool locked = false;
|
||||
#endif
|
||||
if (!cli_args::canSetPin(sender_timestamp, _cli_rescue, locked,
|
||||
_serial && _serial->isConnectionSecure(), &err)) {
|
||||
strcpy(reply, err);
|
||||
return true;
|
||||
}
|
||||
long pin; // atoi(): "abc" was PIN 0, i.e. a random one
|
||||
if (!cli_args::parseInt(&command[8], 0, 999999, &pin)) {
|
||||
strcpy(reply, "Error, PIN must be 0-999999");
|
||||
@@ -2495,11 +2495,6 @@ void MyMesh::checkCLIRescueCmd() {
|
||||
cli_command[len - 1] = 0; // replace newline with C string null terminator
|
||||
|
||||
reply_buf[0] = 0;
|
||||
#ifdef LOCKED_NODE
|
||||
if (memcmp(cli_command, "set pin ", 8) == 0) { // CUSTOM (TeTeHacko): a known PIN = pair and read it all
|
||||
Serial.println(" Error: locked build");
|
||||
} else
|
||||
#endif
|
||||
if (handleCommand(cli_command, 0, reply_buf)) {
|
||||
// command was handled, print reply output
|
||||
Serial.print(" "); Serial.print(reply_buf); Serial.println();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "MyMesh.h"
|
||||
#include <algorithm>
|
||||
#include <helpers/CliArgs.h>
|
||||
#include <helpers/sensors/LPPDataHelpers.h>
|
||||
#include <helpers/UTF8Helpers.h>
|
||||
|
||||
@@ -219,9 +220,7 @@ void MyMesh::formatNodesReply(char* reply, int max_len, uint16_t offset) {
|
||||
prefix, (unsigned)n->type, (long)n->lat, (long)n->lon,
|
||||
(int)n->snr, (int)n->rssi, (unsigned long)(now - n->heard_timestamp),
|
||||
(unsigned long)n->pkt_hash, pathhex, n->name);
|
||||
int ll = strlen(line);
|
||||
if (i > offset && (dp - reply) + ll + 24 > max_len) break; // room for trailer; always emit >=1
|
||||
memcpy(dp, line, ll); dp += ll;
|
||||
if (!cli_args::appendLine(dp, reply, max_len, 24, line)) break; // room for trailer; never overflow reply
|
||||
}
|
||||
dp += sprintf(dp, "E,%d,%d", i, total);
|
||||
*dp = 0;
|
||||
@@ -276,9 +275,7 @@ void MyMesh::formatRxLogReply(char* reply, int max_len, uint32_t cursor) {
|
||||
(unsigned long)r->seq, (unsigned long)r->when,
|
||||
(unsigned long)r->pkt_hash, (unsigned)r->header,
|
||||
(int)r->snr, (int)r->rssi, pathhex);
|
||||
int ll = strlen(line);
|
||||
if (i > 0 && (dp - reply) + ll + 40 > max_len) break; // room for trailer; always emit >=1
|
||||
memcpy(dp, line, ll); dp += ll;
|
||||
if (!cli_args::appendLine(dp, reply, max_len, 40, line)) break; // room for trailer; never overflow reply
|
||||
last = r->seq;
|
||||
}
|
||||
dp += sprintf(dp, "E,%lu,%lu,%lu", (unsigned long)last, (unsigned long)oldest, (unsigned long)newest);
|
||||
@@ -1931,11 +1928,9 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, char *command, char *reply
|
||||
}
|
||||
#endif
|
||||
|
||||
if (strlen(command) > 4 && command[2] == '|') { // optional prefix (for companion radio CLI)
|
||||
memcpy(reply, command, 3); // reflect the prefix back
|
||||
reply += 3;
|
||||
command += 3;
|
||||
}
|
||||
const char* cmd = command;
|
||||
cli_args::stripPrefix(cmd, reply, &reply_max);
|
||||
command = const_cast<char*>(cmd);
|
||||
|
||||
// handle ACL related commands
|
||||
if (memcmp(command, "setperm ", 8) == 0) { // format: setperm {pubkey-hex} {permissions-int8}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
# Docs website of this fork (https://tth-pub.pages.rfa.cz/meshcore-tth/),
|
||||
# built by .github/docs-site.sh. Its own file, not an INHERIT of upstream's
|
||||
# mkdocs.yml (that one is Material: logo, features, palette): theme
|
||||
# mkdocs-terminal, palette "dark" with docs/_stylesheets/tth.css on top.
|
||||
site_name: MeshCore TTH
|
||||
site_url: https://tth-pub.pages.rfa.cz/meshcore-tth/
|
||||
site_description: MeshCore fork meshcore-tth -- repeater antispam, diagnostics, OTA, Czech mesh defaults
|
||||
repo_name: tth-pub/meshcore-tth
|
||||
repo_url: https://git.rfa.cz/tth-pub/meshcore-tth
|
||||
edit_uri: src/branch/main/docs/
|
||||
# the theme shows neither repo_url nor edit links for a Gitea repo: the
|
||||
# repository is a top-bar entry (nav) and a line in every footer
|
||||
copyright: 'Source: <a href="https://git.rfa.cz/tth-pub/meshcore-tth">git.rfa.cz/tth-pub/meshcore-tth</a> ·'
|
||||
|
||||
theme:
|
||||
name: terminal
|
||||
palette: dark
|
||||
features:
|
||||
# no blinking cursor after the site name (user, 2. 12. 2026)
|
||||
- navigation.top.cursor_animation.hide
|
||||
- navigation.side.indexes
|
||||
|
||||
extra_css:
|
||||
- _stylesheets/tth.css
|
||||
|
||||
plugins:
|
||||
- search
|
||||
|
||||
markdown_extensions:
|
||||
- admonition
|
||||
- github-callouts
|
||||
- attr_list
|
||||
- tables
|
||||
- toc
|
||||
- pymdownx.details
|
||||
- pymdownx.superfences
|
||||
|
||||
# One language for the site: English (every doc in docs/ is English); the
|
||||
# Czech half of the README is one page, "Česky", in the top bar. Titles in
|
||||
# both languages side by side were confusing (user, 2. 12. 2026).
|
||||
nav:
|
||||
- About the fork: index.md
|
||||
- Česky: cs.md
|
||||
- Repository: https://git.rfa.cz/tth-pub/meshcore-tth
|
||||
- Fork meshcore-tth:
|
||||
- Console commands: tth-commands.md
|
||||
- Firmware update by the admin (OTA): ota.md
|
||||
- Power saving: power.md
|
||||
- Budka as a sensor: budka-sensor.md
|
||||
- BLE/LoRa coexistence: ble-lora-coexistence.md
|
||||
- MeshCore (upstream):
|
||||
- Introduction: meshcore.md
|
||||
- FAQ: faq.md
|
||||
- CLI commands: cli_commands.md
|
||||
- Companion CLI: companion_cli.md
|
||||
- Companion protocol: companion_protocol.md
|
||||
- Terminal chat CLI: terminal_chat_cli.md
|
||||
- KISS modem protocol: kiss_modem_protocol.md
|
||||
- Packet format: packet_format.md
|
||||
- Payloads: payloads.md
|
||||
- Stats binary frames: stats_binary_frames.md
|
||||
- Number allocations: number_allocations.md
|
||||
- QR codes: qr_codes.md
|
||||
- Radio presets: radio_presets.md
|
||||
- nRF52 power management: nrf52_power_management.md
|
||||
@@ -11,7 +11,9 @@
|
||||
// float a '.' and fraction. No exponent, no hex, no trailing text.
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace cli_args {
|
||||
|
||||
@@ -53,4 +55,45 @@ inline bool parseFloat(const char* s, float lo, float hi, float* out) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Strips leading spaces and an optional 3-byte "XX|" prefix (reflected into
|
||||
// `reply`, deducting 3 from `*reply_max` when provided).
|
||||
inline void stripPrefix(const char*& command, char*& reply, int* reply_max = nullptr) {
|
||||
while (*command == ' ') command++;
|
||||
if (strlen(command) > 4 && command[2] == '|') {
|
||||
if (!reply_max || *reply_max >= 3) {
|
||||
memcpy(reply, command, 3);
|
||||
reply += 3;
|
||||
*reply = 0;
|
||||
if (reply_max) *reply_max -= 3;
|
||||
}
|
||||
command += 3;
|
||||
while (*command == ' ') command++;
|
||||
}
|
||||
}
|
||||
|
||||
// Security gate for companion `set pin`: blocked in locked CLI rescue and over
|
||||
// unencrypted local transports (USB), allowed over paired BLE or remote ACL.
|
||||
inline bool canSetPin(uint32_t sender_timestamp, bool cli_rescue, bool locked_node,
|
||||
bool serial_secure, const char** err_out = nullptr) {
|
||||
if (locked_node && cli_rescue) {
|
||||
if (err_out) *err_out = "Error: locked build";
|
||||
return false;
|
||||
}
|
||||
if (sender_timestamp == 0 && !cli_rescue && !serial_secure) {
|
||||
if (err_out) *err_out = "Error: set pin only over paired BLE";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Appends `line` to a paged CLI reply only if it fits with `trailer_reserve`
|
||||
// bytes left for the end marker; returns false when the page is full.
|
||||
inline bool appendLine(char*& dp, const char* reply, int max_len, int trailer_reserve, const char* line) {
|
||||
int ll = (int)strlen(line);
|
||||
if ((dp - reply) + ll + trailer_reserve > max_len) return false;
|
||||
memcpy(dp, line, ll);
|
||||
dp += ll;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace cli_args
|
||||
@@ -63,9 +63,10 @@ void ClientACL::load(FILESYSTEM* fs, const mesh::LocalIdentity& self_id) {
|
||||
#define ACL_TS_RECORD (ACL_TS_PREFIX + 4)
|
||||
|
||||
static const char* tsFilename(uint8_t slot) { return slot ? "/s_acl_ts1" : "/s_acl_ts0"; }
|
||||
static uint8_t s_ts_buf[2 * MAX_CLIENTS * ACL_TS_RECORD + 8];
|
||||
|
||||
void ClientACL::loadTimestamps() {
|
||||
static uint8_t buf[2 * MAX_CLIENTS * ACL_TS_RECORD + 8];
|
||||
uint8_t* buf = s_ts_buf;
|
||||
_num_ts_orphans = 0;
|
||||
_ts_seq = 0;
|
||||
_ts_slot = 0;
|
||||
@@ -78,7 +79,7 @@ void ClientACL::loadTimestamps() {
|
||||
File file = _fs->open(tsFilename(slot));
|
||||
#endif
|
||||
if (!file) continue;
|
||||
int len = file.read(buf, sizeof(buf));
|
||||
int len = file.read(buf, sizeof(s_ts_buf));
|
||||
file.close();
|
||||
if (len < 8 || (len - 8) % ACL_TS_RECORD != 0) continue;
|
||||
|
||||
@@ -121,7 +122,7 @@ void ClientACL::loadTimestamps() {
|
||||
|
||||
void ClientACL::saveTimestamps() {
|
||||
if (!_fs) return;
|
||||
static uint8_t buf[2 * MAX_CLIENTS * ACL_TS_RECORD + 8];
|
||||
uint8_t* buf = s_ts_buf;
|
||||
int len = 0;
|
||||
for (int i = 0; i < num_clients; i++) {
|
||||
if (clients[i].saved_timestamp == 0) continue;
|
||||
@@ -142,10 +143,10 @@ void ClientACL::saveTimestamps() {
|
||||
|
||||
File file = openWrite(_fs, tsFilename(_ts_slot));
|
||||
if (file) {
|
||||
file.write(buf, len);
|
||||
size_t written = file.write(buf, len);
|
||||
file.close();
|
||||
if (written == (size_t)len) _ts_slot ^= 1;
|
||||
}
|
||||
_ts_slot ^= 1;
|
||||
}
|
||||
|
||||
void ClientACL::orphanTimestamp(const ClientInfo* c) {
|
||||
|
||||
@@ -62,7 +62,7 @@ static int in_shift_phase(void) {
|
||||
static int cb_read(void *arg, void *dst, uintptr_t src, size_t size) {
|
||||
fwp_job *j = (fwp_job *)arg;
|
||||
uint8_t *d = (uint8_t *)dst;
|
||||
if (src + size > j->mem_size) return j->err = FWP_ERR_ARGS;
|
||||
if (src > j->mem_size || size > j->mem_size - src) return j->err = FWP_ERR_ARGS;
|
||||
if (!in_shift_phase() && src < j->written_end) return j->err = FWP_ERR_OVERREAD;
|
||||
while (size > 0) {
|
||||
uintptr_t a = src;
|
||||
@@ -106,7 +106,7 @@ static int cb_erase(void *arg, uintptr_t addr, size_t size) {
|
||||
|
||||
static int cb_write(void *arg, uintptr_t dst, void *src, size_t size) {
|
||||
fwp_job *j = (fwp_job *)arg;
|
||||
if (j->page_addr == NO_PAGE || dst < j->page_addr || dst + size > j->page_addr + FWP_PAGE)
|
||||
if (j->page_addr == NO_PAGE || dst < j->page_addr || size > FWP_PAGE - (dst - j->page_addr))
|
||||
return j->err = FWP_ERR_ORDER;
|
||||
fwp_copy(&g_page[dst - j->page_addr], (const uint8_t *)src, (uint32_t)size);
|
||||
if (j->dry && !in_shift_phase()) j->sink(j->sink_ctx, (const uint8_t *)src, (uint32_t)size);
|
||||
|
||||
@@ -743,9 +743,9 @@ void FwUpdate::cmdBegin(uint32_t sender_timestamp, const char *arg, char *reply)
|
||||
strcpy(reply, "ERR: fw begin <bytes>");
|
||||
return;
|
||||
}
|
||||
if (stage + total > FW_OTA_STAGE_END) {
|
||||
if (stage >= FW_OTA_STAGE_END || total > FW_OTA_STAGE_END - stage) {
|
||||
sprintf(reply, "ERR: %lu B does not fit, %lu free", (unsigned long)total,
|
||||
(unsigned long)(FW_OTA_STAGE_END - stage));
|
||||
(unsigned long)(stage < FW_OTA_STAGE_END ? FW_OTA_STAGE_END - stage : 0));
|
||||
return;
|
||||
}
|
||||
_stage = stage;
|
||||
@@ -975,6 +975,7 @@ void FwUpdate::cmdApply(uint32_t sender_timestamp, const char *arg, char *reply)
|
||||
_apply_force = force;
|
||||
_apply_err[0] = 0;
|
||||
_apply_at = millis() + 2000; // let the reply go out first
|
||||
if (_apply_at == 0) _apply_at = 1;
|
||||
sprintf(reply, "OK applying %s in 2 s (batt %umV%s), back in ~20 s", _version, mv,
|
||||
_board.isExternalPowered() ? ", USB" : "");
|
||||
}
|
||||
|
||||
@@ -323,6 +323,7 @@ bool NodeMaintenance::dfuCommand(uint32_t sender_timestamp, const char* command,
|
||||
return true;
|
||||
}
|
||||
_dfu_at = millis() + 700;
|
||||
if (_dfu_at == 0) _dfu_at = 1;
|
||||
_dfu_mode = (strcmp(arg, "serial") == 0) ? 1 : (strcmp(arg, "ota") == 0 ? 2 : 0);
|
||||
#else
|
||||
strcpy(reply, "ERR: not an nRF52 board");
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
// first accepted sync), so a spoofer cannot walk the clock away.
|
||||
// A trusted fix that keeps disagreeing with the clock by the same offset raises an alert;
|
||||
// the operator can then accept that GPS time (acceptAlertedTime()).
|
||||
//
|
||||
// epochFromFields() is always available, with or without GPS_GUARD: the location providers use it
|
||||
// to turn the receiver's date and time into an epoch.
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <MeshCore.h>
|
||||
@@ -106,6 +109,20 @@ class GpsGuard {
|
||||
}
|
||||
|
||||
public:
|
||||
// UTC date and time fields as reported by a receiver -> Unix epoch, or 0 if any field is out of
|
||||
// range. Receivers (and their libraries) hand these over unchecked: MicroNMEA turns any two
|
||||
// characters into a value 0..255, and both RTClib's DateTime and SparkFun's getUnixEpoch() index
|
||||
// their days-per-month tables with the month without a range check.
|
||||
static uint32_t epochFromFields(uint16_t year, uint8_t month, uint8_t day,
|
||||
uint8_t hour, uint8_t minute, uint8_t second) {
|
||||
static const uint8_t days_in_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||
if (year < 2020 || year > 2099 || month < 1 || month > 12) return 0;
|
||||
uint8_t mdays = days_in_month[month - 1];
|
||||
if (month == 2 && year % 4 == 0) mdays = 29; // 2020..2099: every fourth year is a leap year
|
||||
if (day < 1 || day > mdays || hour > 23 || minute > 59 || second > 60) return 0; // 60: leap second
|
||||
return DateTime(year, month, day, hour, minute, second).unixtime();
|
||||
}
|
||||
|
||||
// Plausible GPS time window: not before this firmware was built, at most 10 years after.
|
||||
static uint32_t minEpoch() {
|
||||
static const uint32_t min_epoch = DateTime(__DATE__, __TIME__).unixtime() - 86400;
|
||||
|
||||
@@ -5,9 +5,7 @@
|
||||
#include <MicroNMEA.h>
|
||||
#include <RTClib.h>
|
||||
#include <string.h>
|
||||
#ifdef GPS_GUARD
|
||||
#include "GpsGuard.h"
|
||||
#endif
|
||||
#include "GpsGuard.h" // epochFromFields(); the guard itself only with GPS_GUARD
|
||||
|
||||
#ifndef GPS_PERIODIC_ACQUISITION_TIMEOUT_MS
|
||||
#define GPS_PERIODIC_ACQUISITION_TIMEOUT_MS 300000UL
|
||||
@@ -161,7 +159,7 @@ class MicroNMEALocationProvider : public LocationProvider {
|
||||
(millis() - _last_time_sync) > TIME_SYNC_INTERVAL) {
|
||||
_time_sync_needed = true;
|
||||
}
|
||||
if (_time_sync_needed && time_valid > 2 && _clock != nullptr && timeSyncAllowed()) {
|
||||
if (_time_sync_needed && time_valid > 2 && _clock != nullptr && currentEpoch() != 0 && timeSyncAllowed()) {
|
||||
_clock->setCurrentTime(getTimestamp());
|
||||
_time_sync_needed = false;
|
||||
_last_time_sync = millis();
|
||||
@@ -175,6 +173,12 @@ class MicroNMEALocationProvider : public LocationProvider {
|
||||
return _clock == nullptr || !_time_sync_needed || time_valid > 3;
|
||||
}
|
||||
|
||||
// the receiver's current date and time, or 0 if a field is out of range
|
||||
uint32_t currentEpoch() {
|
||||
return GpsGuard::epochFromFields(nmea.getYear(), nmea.getMonth(), nmea.getDay(),
|
||||
nmea.getHour(), nmea.getMinute(), nmea.getSecond());
|
||||
}
|
||||
|
||||
bool timeSyncAllowed() {
|
||||
#ifdef GPS_GUARD
|
||||
return _guard.acceptTime(getTimestamp(), _clock->getCurrentTime());
|
||||
@@ -299,14 +303,14 @@ public:
|
||||
|
||||
// GPS time minus clock time, from a current fix with a settled time
|
||||
bool getClockOffset(long& offset) override {
|
||||
if (_clock == nullptr || !isValid() || time_valid < 3) return false;
|
||||
if (_clock == nullptr || !isValid() || time_valid < 3 || currentEpoch() == 0) return false;
|
||||
offset = (long)getTimestamp() - (long)_clock->getCurrentTime();
|
||||
return true;
|
||||
}
|
||||
|
||||
// write the current GPS time to the clock now (caller has done its own checks)
|
||||
bool applyTimeNow() override {
|
||||
if (_clock == nullptr || !isValid() || time_valid < 3) return false;
|
||||
if (_clock == nullptr || !isValid() || time_valid < 3 || currentEpoch() == 0) return false;
|
||||
_clock->setCurrentTime(getTimestamp());
|
||||
_time_sync_needed = false;
|
||||
_last_time_sync = millis();
|
||||
@@ -319,9 +323,8 @@ public:
|
||||
|
||||
long getTimestamp() override {
|
||||
if (!nmea.isValid()) return _lastFix.timestamp;
|
||||
DateTime dt(nmea.getYear(), nmea.getMonth(), nmea.getDay(),
|
||||
nmea.getHour(), nmea.getMinute(), nmea.getSecond());
|
||||
return dt.unixtime();
|
||||
uint32_t t = currentEpoch();
|
||||
return t != 0 ? t : _lastFix.timestamp;
|
||||
}
|
||||
|
||||
void drain() override { _driver->drain(); }
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "GpsDriver.h"
|
||||
|
||||
#include <SparkFun_u-blox_GNSS_Arduino_Library.h>
|
||||
#include "GpsGuard.h" // epochFromFields()
|
||||
|
||||
// Driver for the RAK12500 (u-blox, I2C). Serial NMEA modules are handled by NmeaGpsDriver.
|
||||
class RakI2cGpsDriver : public GpsDriver {
|
||||
@@ -11,6 +12,7 @@ class RakI2cGpsDriver : public GpsDriver {
|
||||
uint8_t _powerPin = 0;
|
||||
bool _detected = false;
|
||||
bool _started = false;
|
||||
bool _pvtSeen = false; // a NAV-PVT has been received since boot
|
||||
|
||||
bool probeRak12500(uint8_t powerPin) {
|
||||
#if defined(ETHERNET_ENABLED) && defined(RAK_BOARD)
|
||||
@@ -95,10 +97,24 @@ public:
|
||||
|
||||
bool isDetected() const { return _detected; }
|
||||
|
||||
bool hasFix() { return _started && _gnss.getGnssFixOk(8); }
|
||||
bool hasFix() {
|
||||
if (!_started) return false;
|
||||
// The library allocates its NAV-PVT record without clearing it: until the first reply has
|
||||
// arrived, the fix flag and every other field are whatever was on the heap.
|
||||
if (!_pvtSeen) {
|
||||
if (!_gnss.getPVT(8)) return false;
|
||||
_pvtSeen = true;
|
||||
}
|
||||
return _gnss.getGnssFixOk(8);
|
||||
}
|
||||
long getLatitude() { return _gnss.getLatitude(2) / 10; }
|
||||
long getLongitude() { return _gnss.getLongitude(2) / 10; }
|
||||
long getAltitude() { return _gnss.getAltitude(2); }
|
||||
long getSatellites() { return _gnss.getSIV(2); }
|
||||
long getTimestamp() { return _gnss.getUnixEpoch(2); }
|
||||
// Not getUnixEpoch(): it indexes its day tables with the module's year and month unchecked.
|
||||
// 0 (no time; RakLocationProvider then leaves the clock alone) for a date or time out of range.
|
||||
long getTimestamp() {
|
||||
return GpsGuard::epochFromFields(_gnss.getYear(2), _gnss.getMonth(2), _gnss.getDay(2),
|
||||
_gnss.getHour(2), _gnss.getMinute(2), _gnss.getSecond(2));
|
||||
}
|
||||
};
|
||||
@@ -15,6 +15,7 @@ class DisplayDriver {
|
||||
int _w, _h;
|
||||
protected:
|
||||
DisplayDriver(int w, int h) { _w = w; _h = h; }
|
||||
void setLogicalSize(int w, int h) { _w = w; _h = h; }
|
||||
public:
|
||||
//enum Color { DARK=0, LIGHT, RED, GREEN, BLUE, YELLOW, ORANGE }; // on b/w screen, colors will be !=0 synonym of light
|
||||
|
||||
|
||||
@@ -107,21 +107,27 @@ ColorVal UIColor::popup_bkg = 0x07FF; // CYAN
|
||||
ColorVal UIColor::popup_txt = 0x0000;
|
||||
ColorVal UIColor::corp_blue = 0x001A;
|
||||
|
||||
static int scaleX(int x) {
|
||||
return (int)(x * DISPLAY_SCALE_X);
|
||||
void NV3001BDisplay::setNativePixels(bool enabled) {
|
||||
nativePixels = enabled;
|
||||
setLogicalSize(enabled ? NV3001B_SCREEN_WIDTH : NV3001B_LOGICAL_WIDTH,
|
||||
enabled ? NV3001B_SCREEN_HEIGHT : NV3001B_LOGICAL_HEIGHT);
|
||||
}
|
||||
|
||||
static int scaleY(int y) {
|
||||
return (int)(y * DISPLAY_SCALE_Y);
|
||||
int NV3001BDisplay::scaleX(int x) const {
|
||||
return nativePixels ? x : (int)(x * DISPLAY_SCALE_X);
|
||||
}
|
||||
|
||||
static int scaleWidth(int x, int w) {
|
||||
int NV3001BDisplay::scaleY(int y) const {
|
||||
return nativePixels ? y : (int)(y * DISPLAY_SCALE_Y);
|
||||
}
|
||||
|
||||
int NV3001BDisplay::scaleWidth(int x, int w) const {
|
||||
if (w <= 0) return 0;
|
||||
int scaled = scaleX(x + w) - scaleX(x);
|
||||
return scaled > 0 ? scaled : 1;
|
||||
}
|
||||
|
||||
static int scaleHeight(int y, int h) {
|
||||
int NV3001BDisplay::scaleHeight(int y, int h) const {
|
||||
if (h <= 0) return 0;
|
||||
int scaled = scaleY(y + h) - scaleY(y);
|
||||
return scaled > 0 ? scaled : 1;
|
||||
@@ -183,7 +189,8 @@ static int textPixelScaleX(uint8_t size) {
|
||||
return size <= 1 ? NV3001B_TEXT_SIZE1_SCALE_X : NV3001B_TEXT_SIZE2_SCALE_X;
|
||||
}
|
||||
|
||||
static int textPixelScaleY(uint8_t size) {
|
||||
int NV3001BDisplay::textPixelScaleY(uint8_t size) const {
|
||||
if (nativePixels) return textPixelScaleX(size); // Square glyph pixels on the native canvas.
|
||||
return size <= 1 ? NV3001B_TEXT_SIZE1_SCALE_Y : NV3001B_TEXT_SIZE2_SCALE_Y;
|
||||
}
|
||||
|
||||
@@ -254,10 +261,26 @@ void NV3001BDisplay::writeColor(uint16_t rgb, uint32_t count) {
|
||||
spi.beginTransaction(SPISettings(SPI_FREQUENCY, MSBFIRST, SPI_MODE0));
|
||||
digitalWrite(PIN_TFT_DC, HIGH);
|
||||
digitalWrite(PIN_TFT_CS, LOW);
|
||||
#ifdef NRF52_PLATFORM
|
||||
// EasyDMA needs a RAM buffer. Send repeated pixels in bursts.
|
||||
uint8_t pixels[64];
|
||||
size_t bytes = sizeof(pixels);
|
||||
if (count < bytes / 2) bytes = count * 2;
|
||||
for (size_t i = 0; i < bytes; i += 2) {
|
||||
pixels[i] = hi;
|
||||
pixels[i + 1] = lo;
|
||||
}
|
||||
while (count) {
|
||||
if (count < bytes / 2) bytes = count * 2;
|
||||
spi.transfer(pixels, nullptr, bytes);
|
||||
count -= bytes / 2;
|
||||
}
|
||||
#else
|
||||
while (count--) {
|
||||
spi.transfer(hi);
|
||||
spi.transfer(lo);
|
||||
}
|
||||
#endif
|
||||
digitalWrite(PIN_TFT_CS, HIGH);
|
||||
spi.endTransaction();
|
||||
}
|
||||
@@ -462,6 +485,9 @@ void NV3001BDisplay::turnOff() {
|
||||
if (!is_on) return;
|
||||
|
||||
writeOptionalPin(PIN_TFT_BL, !PIN_TFT_BL_ACTIVE);
|
||||
#ifdef NRF52_PLATFORM
|
||||
spi.end();
|
||||
#endif
|
||||
writeOptionalPin(PIN_TFT_EN, !PIN_TFT_EN_ACTIVE);
|
||||
is_on = false;
|
||||
if (periph_power) periph_power->release();
|
||||
@@ -550,7 +576,8 @@ uint16_t NV3001BDisplay::getTextWidth(const char* str) {
|
||||
|
||||
uint16_t len = 0;
|
||||
while (str[len] && str[len] != '\n' && str[len] != '\r') len++;
|
||||
return (uint16_t)((len * 6 * textPixelScaleX(text_size)) / DISPLAY_SCALE_X);
|
||||
const int pixels = len * 6 * textPixelScaleX(text_size);
|
||||
return nativePixels ? pixels : (uint16_t)(pixels / DISPLAY_SCALE_X);
|
||||
}
|
||||
|
||||
void NV3001BDisplay::endFrame() {
|
||||
|
||||
@@ -34,6 +34,13 @@ class NV3001BDisplay : public DisplayDriver {
|
||||
uint8_t text_size = 1;
|
||||
int cursor_x = 0;
|
||||
int cursor_y = 0;
|
||||
bool nativePixels = false;
|
||||
|
||||
int scaleX(int x) const;
|
||||
int scaleY(int y) const;
|
||||
int scaleWidth(int x, int w) const;
|
||||
int scaleHeight(int y, int h) const;
|
||||
int textPixelScaleY(uint8_t size) const;
|
||||
|
||||
void writeCommand(uint8_t cmd);
|
||||
void writeBytes(const uint8_t* data, size_t len);
|
||||
@@ -59,6 +66,7 @@ public:
|
||||
#endif
|
||||
|
||||
bool begin();
|
||||
void setNativePixels(bool enabled);
|
||||
static const char* driverName() { return "NV3001B"; }
|
||||
static uint16_t physicalWidth() { return NV3001B_PANEL_WIDTH; }
|
||||
static uint16_t physicalHeight() { return NV3001B_PANEL_HEIGHT; }
|
||||
|
||||
@@ -340,53 +340,104 @@ public:
|
||||
}
|
||||
|
||||
if (_page == HomePage::FIRST) {
|
||||
display.setColor(UIColor::primary_txt);
|
||||
#ifdef ENABLE_WIFI_INTERFACE
|
||||
// smaller unread message ui for wifi variants
|
||||
display.setTextSize(1);
|
||||
sprintf(tmp, "Unread Msg: %d", _task->getMsgCount());
|
||||
display.drawTextCentered(display.width() / 2, 22, tmp);
|
||||
#else
|
||||
// larger unread message ui for non wifi variants
|
||||
display.setTextSize(2);
|
||||
sprintf(tmp, "MSG: %d", _task->getMsgCount());
|
||||
display.drawTextCentered(display.width() / 2, 22, tmp);
|
||||
#endif
|
||||
static constexpr uint32_t MIN_VALID_RTC_EPOCH = 1735689600UL; // 2025-01-01 00:00:00 UTC
|
||||
uint32_t raw_now = _rtc->getCurrentTime();
|
||||
bool rtc_valid = (raw_now >= MIN_VALID_RTC_EPOCH);
|
||||
const bool compact_screen = (display.height() < 120);
|
||||
|
||||
char time_str[8] = "--:--";
|
||||
char date_str[12] = "";
|
||||
if (_node_prefs->ui_show_clock) {
|
||||
display.setTextSize(3);
|
||||
uint32_t now = _rtc->getCurrentTime();
|
||||
now += (int32_t)(_node_prefs->tz_offset * 3600);
|
||||
DateTime dt (now);
|
||||
sprintf(tmp, "%02d:%02d", dt.hour(), dt.minute());
|
||||
display.drawTextCentered(display.width() / 2, 60, tmp);
|
||||
display.setTextSize(1);
|
||||
sprintf(tmp, "%02d/%02d/%d", dt.day(), dt.month(), dt.year());
|
||||
display.drawTextCentered(display.width() / 2, 80, tmp);
|
||||
if (rtc_valid) {
|
||||
uint32_t local_now = (uint32_t)((int64_t)raw_now + (int64_t)(_node_prefs->tz_offset * 3600.0f));
|
||||
DateTime dt (local_now);
|
||||
snprintf(time_str, sizeof(time_str), "%02d:%02d", dt.hour(), dt.minute());
|
||||
if (compact_screen) {
|
||||
snprintf(date_str, sizeof(date_str), "%02d/%02d/%02d", dt.day(), dt.month(), dt.year() % 100);
|
||||
} else {
|
||||
snprintf(date_str, sizeof(date_str), "%02d/%02d/%d", dt.day(), dt.month(), dt.year());
|
||||
}
|
||||
} else {
|
||||
strcpy(date_str, compact_screen ? "--/--/--" : "--/--/----");
|
||||
}
|
||||
}
|
||||
#ifdef ENABLE_WIFI_INTERFACE
|
||||
|
||||
if (_node_prefs->ui_show_clock && compact_screen) {
|
||||
display.setColor(UIColor::primary_txt);
|
||||
display.setTextSize(1);
|
||||
snprintf(tmp, sizeof(tmp), "MSG:%d", _task->getMsgCount());
|
||||
display.drawTextLeftAlign(0, 19, tmp);
|
||||
display.setColor(UIColor::secondary_txt);
|
||||
display.drawTextRightAlign(display.width() - 1, 19, date_str);
|
||||
|
||||
display.setColor(UIColor::primary_txt);
|
||||
#ifdef ENABLE_WIFI_INTERFACE
|
||||
display.setTextSize(1);
|
||||
display.drawTextCentered(display.width() / 2, 29, time_str);
|
||||
IPAddress ip = WiFi.localIP();
|
||||
snprintf(tmp, sizeof(tmp), "IP: %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
|
||||
display.setTextSize(1);
|
||||
display.drawTextCentered(display.width() / 2, 32, tmp);
|
||||
#endif
|
||||
if (_task->hasConnection()) {
|
||||
display.setColor(UIColor::warning_txt);
|
||||
display.setTextSize(1);
|
||||
if (_node_prefs->ui_show_clock)
|
||||
display.drawTextCentered(display.width() / 2, 110, "< Connected >");
|
||||
else
|
||||
display.drawTextCentered(display.width() / 2, 43, "< Connected >");
|
||||
// CUSTOM (TeTeHacko): jen kdyz BT opravdu bezi -- jinak displej nabizi PIN
|
||||
// k parovani, ktere neni jak navazat.
|
||||
} else if (_task->getBLEPin() != 0 && _task->isBluetoothEnabled()) { // BT pin
|
||||
display.setColor(UIColor::warning_txt);
|
||||
sprintf(tmp, "Pin:%d", _task->getBLEPin());
|
||||
if (_node_prefs->ui_show_clock) {
|
||||
display.drawTextCentered(display.width() / 2, 40, tmp);
|
||||
#else
|
||||
display.setTextSize(2);
|
||||
display.drawTextCentered(display.width() / 2, 30, time_str);
|
||||
#endif
|
||||
|
||||
if (_task->hasConnection()) {
|
||||
display.setColor(UIColor::warning_txt);
|
||||
display.setTextSize(1);
|
||||
display.drawTextCentered(display.width() / 2, 110, tmp);
|
||||
} else {
|
||||
display.setTextSize(2);
|
||||
display.drawTextCentered(display.width() / 2, 43, tmp);
|
||||
display.drawTextCentered(display.width() / 2, 51, "< Connected >");
|
||||
// CUSTOM (TeTeHacko): jen kdyz BT opravdu bezi -- jinak displej nabizi PIN
|
||||
// k parovani, ktere neni jak navazat.
|
||||
} else if (_task->getBLEPin() != 0 && _task->isBluetoothEnabled()) { // BT pin
|
||||
display.setColor(UIColor::warning_txt);
|
||||
display.setTextSize(1);
|
||||
snprintf(tmp, sizeof(tmp), "Pin:%lu", (unsigned long)_task->getBLEPin());
|
||||
display.drawTextCentered(display.width() / 2, 51, tmp);
|
||||
}
|
||||
} else {
|
||||
display.setColor(UIColor::primary_txt);
|
||||
#ifdef ENABLE_WIFI_INTERFACE
|
||||
// smaller unread message ui for wifi variants
|
||||
display.setTextSize(1);
|
||||
sprintf(tmp, "Unread Msg: %d", _task->getMsgCount());
|
||||
display.drawTextCentered(display.width() / 2, 22, tmp);
|
||||
#else
|
||||
// larger unread message ui for non wifi variants
|
||||
display.setTextSize(2);
|
||||
sprintf(tmp, "MSG: %d", _task->getMsgCount());
|
||||
display.drawTextCentered(display.width() / 2, 22, tmp);
|
||||
#endif
|
||||
if (_node_prefs->ui_show_clock) {
|
||||
display.setTextSize(3);
|
||||
display.drawTextCentered(display.width() / 2, 60, time_str);
|
||||
display.setTextSize(1);
|
||||
display.drawTextCentered(display.width() / 2, 80, date_str);
|
||||
}
|
||||
#ifdef ENABLE_WIFI_INTERFACE
|
||||
IPAddress ip = WiFi.localIP();
|
||||
snprintf(tmp, sizeof(tmp), "IP: %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
|
||||
display.setTextSize(1);
|
||||
display.drawTextCentered(display.width() / 2, 32, tmp);
|
||||
#endif
|
||||
if (_task->hasConnection()) {
|
||||
display.setColor(UIColor::warning_txt);
|
||||
display.setTextSize(1);
|
||||
if (_node_prefs->ui_show_clock)
|
||||
display.drawTextCentered(display.width() / 2, 110, "< Connected >");
|
||||
else
|
||||
display.drawTextCentered(display.width() / 2, 43, "< Connected >");
|
||||
// CUSTOM (TeTeHacko): jen kdyz BT opravdu bezi -- jinak displej nabizi PIN
|
||||
// k parovani, ktere neni jak navazat.
|
||||
} else if (_task->getBLEPin() != 0 && _task->isBluetoothEnabled()) { // BT pin
|
||||
display.setColor(UIColor::warning_txt);
|
||||
sprintf(tmp, "Pin:%lu", (unsigned long)_task->getBLEPin());
|
||||
if (_node_prefs->ui_show_clock) {
|
||||
display.setTextSize(1);
|
||||
display.drawTextCentered(display.width() / 2, 110, tmp);
|
||||
} else {
|
||||
display.setTextSize(2);
|
||||
display.drawTextCentered(display.width() / 2, 43, tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (_page == HomePage::RECENT) {
|
||||
|
||||
@@ -18,11 +18,12 @@ class File {
|
||||
std::string _name;
|
||||
size_t _pos = 0;
|
||||
bool _write = false;
|
||||
size_t _short_write = 0;
|
||||
|
||||
public:
|
||||
File() = default;
|
||||
File(std::map<std::string, std::string>* files, const std::string& name, bool write)
|
||||
: _files(files), _name(name), _write(write) {
|
||||
File(std::map<std::string, std::string>* files, const std::string& name, bool write, size_t short_write = 0)
|
||||
: _files(files), _name(name), _write(write), _short_write(short_write) {
|
||||
if (write) (*_files)[name] = "";
|
||||
}
|
||||
explicit operator bool() const { return _files != nullptr; }
|
||||
@@ -34,8 +35,9 @@ public:
|
||||
return (int)n;
|
||||
}
|
||||
size_t write(const uint8_t* buf, size_t len) {
|
||||
(*_files)[_name].append((const char*)buf, len);
|
||||
return len;
|
||||
size_t n = (_short_write > 0 && _short_write < len) ? _short_write : len;
|
||||
(*_files)[_name].append((const char*)buf, n);
|
||||
return n;
|
||||
}
|
||||
void close() {}
|
||||
};
|
||||
@@ -46,14 +48,22 @@ class Adafruit_LittleFS {
|
||||
public:
|
||||
std::map<std::string, std::string> files;
|
||||
int writes = 0;
|
||||
bool fail_next_write_open = false;
|
||||
size_t short_next_write = 0;
|
||||
|
||||
bool exists(const char* name) { return files.count(name) > 0; }
|
||||
bool remove(const char* name) { return files.erase(name) > 0; }
|
||||
bool mkdir(const char*) { return true; }
|
||||
Adafruit_LittleFS_Namespace::File open(const char* name, uint8_t mode = FILE_O_READ) {
|
||||
if (mode == FILE_O_WRITE) {
|
||||
if (fail_next_write_open) {
|
||||
fail_next_write_open = false;
|
||||
return Adafruit_LittleFS_Namespace::File();
|
||||
}
|
||||
writes++;
|
||||
return Adafruit_LittleFS_Namespace::File(&files, name, true);
|
||||
size_t sw = short_next_write;
|
||||
short_next_write = 0;
|
||||
return Adafruit_LittleFS_Namespace::File(&files, name, true, sw);
|
||||
}
|
||||
if (!exists(name)) return Adafruit_LittleFS_Namespace::File();
|
||||
return Adafruit_LittleFS_Namespace::File(&files, name, false);
|
||||
|
||||
@@ -187,6 +187,44 @@ TEST(AclReplayFloor, AlternatesSlotsAcrossReboots) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(AclReplayFloor, FailedOpenDoesNotRotateSlot) {
|
||||
Node n;
|
||||
ClientInfo* c = n.admin(1);
|
||||
ASSERT_TRUE(n.accept(c, NOW - 30)); // slot 0 -> next slot 1
|
||||
ASSERT_TRUE(n.accept(c, NOW - 20)); // slot 1 -> next slot 0 (oldest)
|
||||
n.acl->save(&n.fs);
|
||||
|
||||
// Open fails on slot 0: must NOT advance to slot 1 (which holds NOW - 20).
|
||||
n.fs.fail_next_write_open = true;
|
||||
ASSERT_TRUE(n.accept(c, NOW - 15));
|
||||
|
||||
// Next write is torn; because slot stayed 0, slot 1 (NOW - 20) stays intact.
|
||||
n.fs.short_next_write = 5;
|
||||
ASSERT_TRUE(n.accept(c, NOW - 10));
|
||||
|
||||
n.boot();
|
||||
c = n.acl->getClient(idFor(1).pub_key, PUB_KEY_SIZE);
|
||||
EXPECT_EQ(c->last_timestamp, NOW - 20);
|
||||
}
|
||||
|
||||
TEST(AclReplayFloor, ShortWriteDoesNotRotateSlot) {
|
||||
Node n;
|
||||
ClientInfo* c = n.admin(1);
|
||||
ASSERT_TRUE(n.accept(c, NOW - 30)); // slot 0
|
||||
ASSERT_TRUE(n.accept(c, NOW - 20)); // slot 1
|
||||
n.acl->save(&n.fs);
|
||||
|
||||
// Two consecutive short writes must both target slot 0 and leave slot 1 intact.
|
||||
n.fs.short_next_write = 4;
|
||||
ASSERT_TRUE(n.accept(c, NOW - 15));
|
||||
n.fs.short_next_write = 4;
|
||||
ASSERT_TRUE(n.accept(c, NOW - 10));
|
||||
|
||||
n.boot();
|
||||
c = n.acl->getClient(idFor(1).pub_key, PUB_KEY_SIZE);
|
||||
EXPECT_EQ(c->last_timestamp, NOW - 20);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
|
||||
@@ -49,6 +49,88 @@ TEST(CliArgsFloat, RefusesNanInfExponentAndGarbage) {
|
||||
EXPECT_FALSE(parseFloat("91", -90, 90, &f));
|
||||
EXPECT_EQ(f, 1);
|
||||
}
|
||||
|
||||
TEST(CliPrefix, StripsSpacesAndReflectsPrefixWithBudget) {
|
||||
char buf[32] = {};
|
||||
char* reply = buf;
|
||||
int max_len = 150;
|
||||
const char* cmd = " 01| set pin 123456";
|
||||
cli_args::stripPrefix(cmd, reply, &max_len);
|
||||
EXPECT_STREQ(cmd, "set pin 123456");
|
||||
EXPECT_STREQ(buf, "01|");
|
||||
EXPECT_EQ(reply, buf + 3);
|
||||
EXPECT_EQ(max_len, 147);
|
||||
}
|
||||
|
||||
TEST(CliPrefix, LeadingSpacesWithoutPrefix) {
|
||||
char buf[16] = {};
|
||||
char* reply = buf;
|
||||
int max_len = 150;
|
||||
const char* cmd = " set pin 123456";
|
||||
cli_args::stripPrefix(cmd, reply, &max_len);
|
||||
EXPECT_STREQ(cmd, "set pin 123456");
|
||||
EXPECT_STREQ(buf, "");
|
||||
EXPECT_EQ(reply, buf);
|
||||
EXPECT_EQ(max_len, 150);
|
||||
}
|
||||
|
||||
TEST(CliPrefix, TinyBudgetDoesNotOverflowOrGoNegative) {
|
||||
char buf[4] = {'X', 'X', 'X', 0};
|
||||
char* reply = buf;
|
||||
int max_len = 2;
|
||||
const char* cmd = "01|nodes";
|
||||
cli_args::stripPrefix(cmd, reply, &max_len);
|
||||
EXPECT_STREQ(cmd, "nodes");
|
||||
EXPECT_EQ(reply, buf);
|
||||
EXPECT_EQ(max_len, 2);
|
||||
}
|
||||
|
||||
TEST(CliSetPinGate, EnforcesTransportAndLockedBuild) {
|
||||
const char* err = nullptr;
|
||||
// Local USB (unsecured, not rescue) -> blocked
|
||||
EXPECT_FALSE(cli_args::canSetPin(0, false, false, false, &err));
|
||||
EXPECT_STREQ(err, "Error: set pin only over paired BLE");
|
||||
|
||||
// Locked CLI rescue -> blocked
|
||||
EXPECT_FALSE(cli_args::canSetPin(0, true, true, false, &err));
|
||||
EXPECT_STREQ(err, "Error: locked build");
|
||||
|
||||
// Paired BLE -> allowed
|
||||
EXPECT_TRUE(cli_args::canSetPin(0, false, true, true, &err));
|
||||
|
||||
// Unlocked CLI rescue -> allowed
|
||||
EXPECT_TRUE(cli_args::canSetPin(0, true, false, false, &err));
|
||||
|
||||
// Remote ACL admin (sender_timestamp != 0) -> allowed
|
||||
EXPECT_TRUE(cli_args::canSetPin(1763400000u, false, true, false, &err));
|
||||
}
|
||||
|
||||
TEST(CliPagedReply, NeverOverflowsSmallMeshBufferWithPrefix) {
|
||||
// Exact mesh CLI size: 150 B reply buffer, 3 B taken by "01|", leaving 147 B.
|
||||
char buf[150] = {};
|
||||
char* reply = buf;
|
||||
int max_len = (int)sizeof(buf);
|
||||
const char* cmd = "01|nodes";
|
||||
cli_args::stripPrefix(cmd, reply, &max_len);
|
||||
|
||||
char* dp = reply;
|
||||
std::string long_line(140, 'A');
|
||||
long_line.push_back('\n');
|
||||
// 141 B line + 24 B trailer reserve > 147 B -> must refuse even as first line
|
||||
EXPECT_FALSE(cli_args::appendLine(dp, reply, max_len, 24, long_line.c_str()));
|
||||
EXPECT_EQ(dp, reply);
|
||||
|
||||
std::string short_line(50, 'B');
|
||||
short_line.push_back('\n');
|
||||
EXPECT_TRUE(cli_args::appendLine(dp, reply, max_len, 24, short_line.c_str()));
|
||||
EXPECT_TRUE(cli_args::appendLine(dp, reply, max_len, 24, short_line.c_str()));
|
||||
EXPECT_FALSE(cli_args::appendLine(dp, reply, max_len, 24, short_line.c_str()));
|
||||
|
||||
dp += sprintf(dp, "E,2,3");
|
||||
*dp = 0;
|
||||
EXPECT_LT((size_t)(dp - buf), sizeof(buf));
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
#include "HeltecMeshPocketV2Board.h"
|
||||
#include <nrf_gpio.h>
|
||||
|
||||
void HeltecMeshPocketV2Board::begin() {
|
||||
NRF52Board::begin();
|
||||
powerBank.begin();
|
||||
pinMode(PIN_USER_BTN, INPUT_PULLUP);
|
||||
}
|
||||
|
||||
uint16_t HeltecMeshPocketV2Board::getBattMilliVolts() {
|
||||
const auto& status = powerBank.snapshot();
|
||||
if (status.cw.ready) return status.cw.voltageMv;
|
||||
return status.hltLive() ? status.hlt.batteryMv : 0;
|
||||
}
|
||||
|
||||
void HeltecMeshPocketV2Board::setUsbDataEnabled(bool enabled) {
|
||||
digitalWrite(PIN_IO_CSA, enabled ? HIGH : LOW);
|
||||
}
|
||||
|
||||
bool HeltecMeshPocketV2Board::toggleUsbData() {
|
||||
const bool enabled = !isUsbDataEnabled();
|
||||
setUsbDataEnabled(enabled);
|
||||
return enabled;
|
||||
}
|
||||
|
||||
bool HeltecMeshPocketV2Board::isUsbDataEnabled() const {
|
||||
return digitalRead(PIN_IO_CSA) == HIGH;
|
||||
}
|
||||
|
||||
void HeltecMeshPocketV2Board::shutdownPeripherals() {
|
||||
NRF52Board::shutdownPeripherals();
|
||||
powerBank.end();
|
||||
setUsbDataEnabled(false);
|
||||
nrf_gpio_cfg_sense_input(PIN_USER_BTN, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
|
||||
pinMode(PIN_9006_IO1, INPUT_PULLDOWN);
|
||||
// A held-high IO1 must not immediately wake the board from SYSTEM OFF.
|
||||
const auto sense = digitalRead(PIN_9006_IO1) ? NRF_GPIO_PIN_SENSE_LOW : NRF_GPIO_PIN_SENSE_HIGH;
|
||||
nrf_gpio_cfg_sense_input(PIN_9006_IO1, NRF_GPIO_PIN_PULLDOWN, sense);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <helpers/NRF52Board.h>
|
||||
#include "PowerBank.h"
|
||||
|
||||
class HeltecMeshPocketV2Board : public NRF52Board {
|
||||
public:
|
||||
HeltecMeshPocketV2Board() : NRF52Board("MeshPocket_V2_OTA") {}
|
||||
PowerBank powerBank;
|
||||
void begin() override;
|
||||
void loop() override { powerBank.poll(); }
|
||||
uint16_t getBattMilliVolts() override;
|
||||
bool isChargerActive() override { return powerBank.snapshot().hasChargingInput(); }
|
||||
bool toggleUsbData();
|
||||
bool isUsbDataEnabled() const;
|
||||
const char* getManufacturerName() const override { return "Heltec MeshPocket V2"; }
|
||||
void shutdownPeripherals() override;
|
||||
|
||||
private:
|
||||
void setUsbDataEnabled(bool enabled);
|
||||
};
|
||||
@@ -0,0 +1,115 @@
|
||||
#include "PowerBank.h"
|
||||
|
||||
namespace {
|
||||
constexpr uint32_t hltPollMs = 100;
|
||||
constexpr uint32_t hltStatusMs = 500;
|
||||
constexpr uint32_t hltStaleMs = 3000;
|
||||
constexpr uint32_t io1WindowMs = 120;
|
||||
constexpr uint32_t gaugeNormalMs = 3000;
|
||||
constexpr uint32_t gaugeFastMs = 500;
|
||||
|
||||
// Only the ISR writes this counter. The main loop consumes a single aligned read.
|
||||
volatile uint32_t io1Pulses = 0;
|
||||
void onIo1Rise() {
|
||||
++io1Pulses;
|
||||
}
|
||||
|
||||
bool stateChanged(const HLT331Serial::Status& before, const HLT331Serial::Status& after) {
|
||||
return !before.valid || before.systemWorking != after.systemWorking ||
|
||||
(after.systemWorking &&
|
||||
(before.charging != after.charging || before.c1State != after.c1State ||
|
||||
before.c2State != after.c2State || before.wirelessWork != after.wirelessWork ||
|
||||
before.wirelessFull != after.wirelessFull));
|
||||
}
|
||||
}
|
||||
|
||||
bool PowerBankSnapshot::hltLive() const {
|
||||
return hlt.valid && hlt.systemWorking && uint32_t(millis() - hlt.lastFrameMs) <= hltStaleMs;
|
||||
}
|
||||
|
||||
bool PowerBankSnapshot::hasChargingInput() const {
|
||||
return hltLive() && (hlt.charging || hlt.c1State == HLT331Serial::PORT_CHARGING ||
|
||||
hlt.c2State == HLT331Serial::PORT_CHARGING);
|
||||
}
|
||||
|
||||
void PowerBank::begin() {
|
||||
gaugeStarted = gauge.begin(Wire);
|
||||
if (gaugeStarted) readGauge();
|
||||
hltStarted = hlt.begin(Serial2, PIN_SERIAL2_RX, PIN_SERIAL2_TX);
|
||||
if (hltStarted) {
|
||||
hlt.configurePins(PIN_CW_INT, PIN_9006_IO1, PIN_9006_IO2, -1);
|
||||
attachInterrupt(digitalPinToInterrupt(PIN_9006_IO1), onIo1Rise, RISING);
|
||||
readHlt();
|
||||
}
|
||||
// Capture the boot sample as a baseline before the UI starts.
|
||||
pageEvent = false;
|
||||
}
|
||||
|
||||
void PowerBank::updateFault(bool& sourceFault, bool active) {
|
||||
const bool wasFault = cwFault || hltFault;
|
||||
sourceFault = active;
|
||||
if (wasFault != (cwFault || hltFault)) {
|
||||
pageEvent = true;
|
||||
fastGaugeReads = 3;
|
||||
}
|
||||
}
|
||||
|
||||
void PowerBank::readGauge() {
|
||||
status.cw.ready = gauge.readStatus(status.cw);
|
||||
lastGauge = millis();
|
||||
if (fastGaugeReads) --fastGaugeReads;
|
||||
if (status.cw.ready) updateFault(cwFault, !status.cw.profile.matches);
|
||||
}
|
||||
|
||||
void PowerBank::readHlt() {
|
||||
const bool valid = hlt.readStatus(status.hlt);
|
||||
lastHlt = millis();
|
||||
if (!valid || status.hlt.ageMs > hltStaleMs) return;
|
||||
|
||||
const auto& sample = status.hlt;
|
||||
if (sample.systemWorking) updateFault(hltFault, sample.ntcOverTemp || sample.wirelessFod);
|
||||
if (stateChanged(previous, sample)) {
|
||||
pageEvent = true;
|
||||
fastGaugeReads = 3;
|
||||
}
|
||||
previous = sample;
|
||||
}
|
||||
|
||||
void PowerBank::poll() {
|
||||
const uint32_t now = millis();
|
||||
if (hltStarted && now - lastPoll >= hltPollMs) {
|
||||
lastPoll = now;
|
||||
hlt.poll();
|
||||
}
|
||||
const uint32_t pulses = io1Pulses;
|
||||
if (pulses != seenPulses) {
|
||||
seenPulses = pulses;
|
||||
drainStarted = now;
|
||||
draining = true;
|
||||
fastGaugeReads = 3;
|
||||
}
|
||||
if (draining && now - drainStarted >= io1WindowMs) {
|
||||
// Collect any bytes received since the regular UART poll.
|
||||
hlt.poll();
|
||||
readHlt();
|
||||
pageEvent = true;
|
||||
draining = false;
|
||||
} else if (hltStarted && !draining && now - lastHlt >= hltStatusMs) {
|
||||
readHlt();
|
||||
}
|
||||
const uint32_t interval = fastGaugeReads ? gaugeFastMs : gaugeNormalMs;
|
||||
if (gaugeStarted && now - lastGauge >= interval) readGauge();
|
||||
}
|
||||
|
||||
bool PowerBank::takePageEvent() {
|
||||
const bool pending = pageEvent;
|
||||
pageEvent = false;
|
||||
return pending;
|
||||
}
|
||||
|
||||
void PowerBank::end() {
|
||||
if (hltStarted) {
|
||||
detachInterrupt(digitalPinToInterrupt(PIN_9006_IO1));
|
||||
Serial2.end();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include <CW221X.h>
|
||||
#include <HLT331Serial.h>
|
||||
|
||||
struct PowerBankSnapshot {
|
||||
CW221X::Status cw{};
|
||||
HLT331Serial::Status hlt{};
|
||||
|
||||
bool hltLive() const;
|
||||
bool hasChargingInput() const;
|
||||
};
|
||||
|
||||
class PowerBank {
|
||||
public:
|
||||
void begin();
|
||||
void poll();
|
||||
void end();
|
||||
const PowerBankSnapshot& snapshot() const { return status; }
|
||||
bool takePageEvent();
|
||||
|
||||
private:
|
||||
void readGauge();
|
||||
void readHlt();
|
||||
void updateFault(bool& sourceFault, bool active);
|
||||
|
||||
CW221X gauge;
|
||||
HLT331Serial hlt;
|
||||
PowerBankSnapshot status;
|
||||
HLT331Serial::Status previous{};
|
||||
bool gaugeStarted = false;
|
||||
bool hltStarted = false;
|
||||
bool cwFault = false;
|
||||
bool hltFault = false;
|
||||
bool pageEvent = false;
|
||||
bool draining = false;
|
||||
uint8_t fastGaugeReads = 0;
|
||||
uint32_t seenPulses = 0;
|
||||
uint32_t drainStarted = 0;
|
||||
uint32_t lastPoll = 0;
|
||||
uint32_t lastHlt = 0;
|
||||
uint32_t lastGauge = 0;
|
||||
};
|
||||
@@ -0,0 +1,334 @@
|
||||
#include "PowerBankPage.h"
|
||||
#include "PowerBank.h"
|
||||
|
||||
namespace {
|
||||
constexpr ColorVal background = 0x0063;
|
||||
constexpr ColorVal blue = 0x653d;
|
||||
constexpr ColorVal purple = 0x611f;
|
||||
constexpr ColorVal card = 0xdefc;
|
||||
constexpr ColorVal dark = 0x31c8;
|
||||
constexpr ColorVal white = 0xffff;
|
||||
constexpr ColorVal green = 0x06ae;
|
||||
constexpr ColorVal gold = 0xff0e;
|
||||
constexpr ColorVal red = 0xfa69;
|
||||
constexpr ColorVal off = 0x3a6b;
|
||||
constexpr ColorVal well = 0x1127, shine = 0x47d5, track = 0x94b8;
|
||||
constexpr ColorVal badgeFace = 0xffbf, tempFace = 0xf776, tempInk = 0xa465;
|
||||
constexpr ColorVal divider = 0x9515, lightDivider = 0xd71e, boltInk = 0x93ba;
|
||||
constexpr int temperatureCenterX = 134;
|
||||
|
||||
void label(DisplayDriver& d, int x, int y, const char* value, ColorVal ink, int size = 1) {
|
||||
d.setColor(ink);
|
||||
d.setTextSize(size);
|
||||
d.setCursor(x, y);
|
||||
d.print(value);
|
||||
}
|
||||
|
||||
void panel(DisplayDriver& d, int x, int y, int w, int h, ColorVal color, int r = 6) {
|
||||
d.setColor(color);
|
||||
if (h > 2 * r) d.fillRect(x, y + r, w, h - 2 * r);
|
||||
int span = 0;
|
||||
for (int row = 0; row < r; ++row) {
|
||||
int dy = r - row;
|
||||
while ((span + 1) * (span + 1) + dy * dy <= r * (r + 1)) ++span;
|
||||
int inset = r - span;
|
||||
d.fillRect(x + inset, y + row, w - 2 * inset, 1);
|
||||
d.fillRect(x + inset, y + h - 1 - row, w - 2 * inset, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void drawPortCard(DisplayDriver& d, int x, const char* name) {
|
||||
panel(d, x, 72, 70, 54, card);
|
||||
label(d, x + 5, 78, name, dark, 2);
|
||||
d.setColor(divider);
|
||||
d.fillRect(x + 5, 97, 60, 1);
|
||||
}
|
||||
|
||||
void drawUsbConnector(DisplayDriver& d, int x, ColorVal ink) {
|
||||
panel(d, x + 33, 82, 25, 10, ink, 4);
|
||||
panel(d, x + 34, 83, 23, 8, card, 3);
|
||||
d.setColor(ink);
|
||||
d.fillRect(x + 38, 87, 15, 1);
|
||||
}
|
||||
|
||||
void drawUsbCard(DisplayDriver& d, int x, const char* name) {
|
||||
drawPortCard(d, x, name);
|
||||
drawUsbConnector(d, x, dark);
|
||||
}
|
||||
|
||||
void drawLayout(DisplayDriver& d) {
|
||||
d.startFrame(background);
|
||||
panel(d, 2, 2, 164, 66, blue);
|
||||
label(d, 8, 10, "Battery", white);
|
||||
panel(d, 89, 23, 4, 9, white, 1);
|
||||
panel(d, 49, 16, 40, 23, white, 4);
|
||||
panel(d, 50, 17, 38, 21, well, 3);
|
||||
d.setColor(white);
|
||||
d.fillRect(8, 50, 85, 8);
|
||||
d.setColor(track);
|
||||
d.fillRect(9, 51, 83, 6);
|
||||
d.setColor(white);
|
||||
for (int i = 1; i < 10; ++i) d.fillRect(9 + i * 83 / 10, 51, 1, 6);
|
||||
d.setColor(lightDivider);
|
||||
d.fillRect(8, 44, 85, 1);
|
||||
d.fillRect(101, 9, 1, 51);
|
||||
panel(d, temperatureCenterX - 11, 13, 23, 23, badgeFace, 11);
|
||||
panel(d, temperatureCenterX - 8, 16, 17, 17, tempFace, 8);
|
||||
label(d, temperatureCenterX - 2, 21, "T", tempInk);
|
||||
panel(d, 169, 2, 49, 66, purple);
|
||||
panel(d, 182, 13, 23, 23, badgeFace, 11);
|
||||
drawUsbCard(d, 2, "C1");
|
||||
drawUsbCard(d, 75, "C2");
|
||||
drawPortCard(d, 148, "Qi2");
|
||||
label(d, 154, 103, "FOD:", dark);
|
||||
}
|
||||
|
||||
bool connected(uint8_t port) {
|
||||
return port == HLT331Serial::PORT_CHARGING || port == HLT331Serial::PORT_DISCHARGING;
|
||||
}
|
||||
|
||||
// Write only the changed span inside each segment, skipping the white dividers.
|
||||
void updateBar(DisplayDriver& d, int x, int y, int w, int h, int before, int after,
|
||||
ColorVal filled, ColorVal empty, int segments = 1) {
|
||||
int oldWidth = before > 0 ? (w * before + 50) / 100 : 0;
|
||||
int newWidth = after > 0 ? (w * after + 50) / 100 : 0;
|
||||
if (oldWidth == newWidth) return;
|
||||
d.setColor(newWidth > oldWidth ? filled : empty);
|
||||
for (int i = 0; i < segments; ++i) {
|
||||
int left = max(min(oldWidth, newWidth), i * w / segments + (i != 0));
|
||||
int right = min(max(oldWidth, newWidth), (i + 1) * w / segments);
|
||||
if (left < right) d.fillRect(x + left, y, right - left, h);
|
||||
}
|
||||
}
|
||||
|
||||
void clearField(DisplayDriver& d, int x, int y, int w, int h, ColorVal color) {
|
||||
d.setColor(color);
|
||||
d.fillRect(x, y, w, h);
|
||||
}
|
||||
|
||||
void drawTemperature(DisplayDriver& d, const char* value) {
|
||||
const bool hasPoint = strchr(value, '.') != nullptr;
|
||||
const int glyphs = strlen(value) - hasPoint;
|
||||
const int size = glyphs <= 3 ? 2 : 1; // Leave room for the unit on longer readings.
|
||||
const int advance = 5 * size + 1;
|
||||
const int width = glyphs * advance + (hasPoint ? 3 : 0);
|
||||
int x = temperatureCenterX - (width - 1) / 2;
|
||||
|
||||
clearField(d, 102, 43, 64, 14, blue);
|
||||
d.setColor(white);
|
||||
d.setTextSize(size);
|
||||
for (const char* p = value; *p; ++p) {
|
||||
if (*p == '.') {
|
||||
d.fillRect(x, 55, 2, 2);
|
||||
x += 3;
|
||||
} else {
|
||||
char glyph[] = {*p, '\0'};
|
||||
d.setCursor(x, 57 - 7 * size);
|
||||
d.print(glyph);
|
||||
x += advance;
|
||||
}
|
||||
}
|
||||
d.drawRect(x + 1, 49, 3, 3);
|
||||
label(d, x + 5, 50, "C", white);
|
||||
}
|
||||
|
||||
void drawPowerRays(DisplayDriver& d, ColorVal ink) {
|
||||
d.setColor(ink);
|
||||
d.fillRect(193, 7, 1, 4);
|
||||
d.fillRect(193, 38, 1, 4);
|
||||
d.fillRect(176, 24, 4, 1);
|
||||
d.fillRect(207, 24, 4, 1);
|
||||
for (int offset = 10; offset <= 12; ++offset) {
|
||||
d.fillRect(193 - offset, 24 - offset, 1, 1);
|
||||
d.fillRect(193 + offset, 24 - offset, 1, 1);
|
||||
d.fillRect(193 - offset, 24 + offset, 1, 1);
|
||||
d.fillRect(193 + offset, 24 + offset, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void drawWatts(DisplayDriver& d, int32_t wattsX10) {
|
||||
char value[16] = "--";
|
||||
if (wattsX10 >= 0) {
|
||||
snprintf(value, sizeof(value), "%ld.%ld", long(wattsX10 / 10), long(wattsX10 % 10));
|
||||
}
|
||||
clearField(d, 170, 43, 47, 14, purple);
|
||||
if (wattsX10 >= 1000) { // Three integer digits only fit in the small font.
|
||||
d.setTextSize(1);
|
||||
int digits = d.getTextWidth(value);
|
||||
int x = 193 - (digits + 7) / 2;
|
||||
label(d, x, 50, value, white);
|
||||
label(d, x + digits + 1, 50, "W", white);
|
||||
return;
|
||||
}
|
||||
// Budget 11 pixels per digit, 3 for the decimal point and 7 for the unit.
|
||||
int width = 7;
|
||||
for (const char* p = value; *p; ++p) width += (*p == '.') ? 3 : 11;
|
||||
int x = 193 - width / 2;
|
||||
d.setColor(white);
|
||||
d.setTextSize(2);
|
||||
for (const char* p = value; *p; ++p) {
|
||||
if (*p == '.') {
|
||||
d.fillRect(x, 55, 2, 2);
|
||||
x += 3;
|
||||
} else {
|
||||
char digit[] = {*p, '\0'};
|
||||
d.setCursor(x, 43);
|
||||
d.print(digit);
|
||||
x += 11;
|
||||
}
|
||||
}
|
||||
label(d, x + 1, 50, "W", white);
|
||||
}
|
||||
}
|
||||
|
||||
void PowerBankPage::drawUsb(DisplayDriver& d, int x, UsbPort& last, uint8_t state, uint8_t mode, bool shared, bool force) {
|
||||
if (!painted || force || state != last.state) {
|
||||
const char* name = "--";
|
||||
ColorVal badge = off;
|
||||
switch (state) {
|
||||
case HLT331Serial::PORT_NOT_CONNECTED: name = "OFF"; break;
|
||||
case HLT331Serial::PORT_CHARGING: name = "CHG"; badge = green; break;
|
||||
case HLT331Serial::PORT_DISCHARGING: name = "DCHG"; badge = gold; break;
|
||||
}
|
||||
clearField(d, x + 5, 102, 60, 10, card);
|
||||
panel(d, x + 6, 102, 28, 10, badge, 5);
|
||||
d.setTextSize(1);
|
||||
label(d, x + 21 - d.getTextWidth(name) / 2, 104, name, badge == off ? white : dark);
|
||||
last.state = state;
|
||||
}
|
||||
char protocol[sizeof(last.protocol)] = "";
|
||||
if (connected(state) && mode != HLT331Serial::FAST_CHARGE_NONE) {
|
||||
snprintf(protocol, sizeof(protocol), "%s%s", HLT331Serial::fastChargeName(mode), shared ? "*" : "");
|
||||
}
|
||||
if (!painted || force || strcmp(last.protocol, protocol) != 0) {
|
||||
clearField(d, x + 6, 116, 63, 7, card);
|
||||
label(d, x + 6, 116, protocol, dark);
|
||||
strcpy(last.protocol, protocol);
|
||||
}
|
||||
}
|
||||
|
||||
void PowerBankPage::drawUsbDataMode(DisplayDriver& d, int x) {
|
||||
drawUsbConnector(d, x, blue);
|
||||
|
||||
clearField(d, x + 5, 102, 60, 10, card);
|
||||
panel(d, x + 21, 102, 28, 10, blue, 5);
|
||||
d.setTextSize(1);
|
||||
const char* badge = "USB";
|
||||
label(d, x + 35 - d.getTextWidth(badge) / 2, 104, badge, white);
|
||||
|
||||
clearField(d, x + 6, 116, 63, 7, card);
|
||||
const char* blocked = "CHG/DCHG";
|
||||
const int width = d.getTextWidth(blocked);
|
||||
const int textX = x + 35 - width / 2;
|
||||
label(d, textX, 116, blocked, dark);
|
||||
d.setColor(red);
|
||||
const int dischargeX = textX + d.getTextWidth("CHG/");
|
||||
d.fillRect(dischargeX, 119, d.getTextWidth("DCHG"), 1);
|
||||
}
|
||||
|
||||
void PowerBankPage::drawBattery(DisplayDriver& d, const PowerBankSnapshot& status) {
|
||||
const auto& cw = status.cw;
|
||||
const int nextPercent = cw.ready ? min(100, int(cw.socPercent)) : -1;
|
||||
char value[16];
|
||||
if (!painted || percent != nextPercent) {
|
||||
if (nextPercent < 0) strcpy(value, "--");
|
||||
else snprintf(value, sizeof(value), "%d", nextPercent);
|
||||
clearField(d, 8, 25, 41, 14, blue);
|
||||
label(d, 8, 25, value, white, 2);
|
||||
label(d, min(43, 10 + d.getTextWidth(value)), 31, "%", white);
|
||||
int before = painted ? percent : 0;
|
||||
updateBar(d, 52, 19, 34, 7, before, nextPercent, shine, well);
|
||||
updateBar(d, 52, 26, 34, 10, before, nextPercent, green, well);
|
||||
updateBar(d, 9, 51, 83, 6, before, nextPercent, green, track, 10);
|
||||
percent = nextPercent;
|
||||
}
|
||||
const int32_t nextTemp = cw.ready ? cw.temperatureX10C : INT32_MIN;
|
||||
if (!painted || nextTemp != temperature) {
|
||||
if (!cw.ready) strcpy(value, "--");
|
||||
else {
|
||||
const int temp = cw.temperatureX10C;
|
||||
snprintf(value, sizeof(value), "%s%d.%d", temp < 0 ? "-" : "", abs(temp) / 10, abs(temp) % 10);
|
||||
}
|
||||
drawTemperature(d, value);
|
||||
temperature = nextTemp;
|
||||
}
|
||||
}
|
||||
|
||||
void PowerBankPage::drawPower(DisplayDriver& d, const PowerBankSnapshot& status, bool live) {
|
||||
const auto& hlt = status.hlt;
|
||||
const bool active = live && (hlt.charging || connected(hlt.c1State) || connected(hlt.c2State) || hlt.wirelessWork);
|
||||
if (!painted || active != boltActive) {
|
||||
static const uint8_t bolt[] = {0x0c, 0x18, 0x30, 0x7e, 0x0c, 0x18, 0x30};
|
||||
drawPowerRays(d, active ? badgeFace : purple);
|
||||
d.setColor(active ? dark : boltInk);
|
||||
d.drawXbm(190, 21, bolt, 8, 7);
|
||||
boltActive = active;
|
||||
}
|
||||
const int32_t nextWatts = live ? int32_t(uint32_t(hlt.busMv) * hlt.busMa / 100000) : -1;
|
||||
if (!painted || nextWatts != wattsX10) {
|
||||
drawWatts(d, nextWatts);
|
||||
wattsX10 = nextWatts;
|
||||
}
|
||||
}
|
||||
|
||||
void PowerBankPage::drawWireless(DisplayDriver& d, const PowerBankSnapshot& status, bool live) {
|
||||
const auto& hlt = status.hlt;
|
||||
const char* state = "--";
|
||||
if (live) {
|
||||
if (hlt.wirelessFod) state = "FOD!";
|
||||
else state = hlt.wirelessWork ? "ON" : "OFF";
|
||||
}
|
||||
if (!painted || strcmp(state, qiState) != 0) {
|
||||
const bool fault = live && hlt.wirelessFod;
|
||||
const bool on = live && hlt.wirelessWork;
|
||||
ColorVal fill = fault ? red : off;
|
||||
if (on && !fault) fill = green;
|
||||
panel(d, 188, 82, 28, 11, fill, 5);
|
||||
if (fault) {
|
||||
label(d, 190, 84, state, dark);
|
||||
} else {
|
||||
panel(d, on ? 207 : 190, 84, 7, 7, white, 3);
|
||||
label(d, on ? 191 : 197, 84, state, on ? dark : white);
|
||||
}
|
||||
qiState = state;
|
||||
}
|
||||
const int nextFod = live ? int(hlt.wirelessFod) : -1;
|
||||
if (!painted || nextFod != fod) {
|
||||
ColorVal fill = off;
|
||||
if (live) fill = hlt.wirelessFod ? red : gold;
|
||||
panel(d, 182, 102, 13, 10, fill, 4);
|
||||
const char* value = "--";
|
||||
if (live) value = hlt.wirelessFod ? "1" : "0";
|
||||
label(d, live ? 186 : 183, 104, value, live ? dark : white);
|
||||
fod = nextFod;
|
||||
}
|
||||
const char* protocol = "";
|
||||
if (live && hlt.wirelessWork && hlt.wirelessProtocol != HLT331Serial::WIRELESS_NULL) {
|
||||
protocol = HLT331Serial::wirelessProtocolName(hlt.wirelessProtocol);
|
||||
}
|
||||
if (!painted || strcmp(protocol, qiProtocol) != 0) {
|
||||
clearField(d, 154, 116, 63, 7, card);
|
||||
label(d, 154, 116, protocol, dark);
|
||||
snprintf(qiProtocol, sizeof(qiProtocol), "%s", protocol);
|
||||
}
|
||||
}
|
||||
|
||||
void PowerBankPage::draw(DisplayDriver& d, const PowerBankSnapshot& status, bool usbDataEnabled) {
|
||||
if (!painted) drawLayout(d);
|
||||
const auto& hlt = status.hlt;
|
||||
const bool live = status.hltLive();
|
||||
const bool shared = !usbDataEnabled && connected(hlt.c1State) && connected(hlt.c2State);
|
||||
const bool usbModeChanged = !painted || usbDataMode != usbDataEnabled;
|
||||
drawBattery(d, status);
|
||||
drawPower(d, status, live);
|
||||
drawUsb(d, 2, c1, live ? hlt.c1State : HLT331Serial::PORT_RESERVED, hlt.fastCharge, shared);
|
||||
if (usbDataEnabled) {
|
||||
if (usbModeChanged) drawUsbDataMode(d, 75);
|
||||
} else {
|
||||
if (usbModeChanged) drawUsbConnector(d, 75, dark);
|
||||
drawUsb(d, 75, c2, live ? hlt.c2State : HLT331Serial::PORT_RESERVED, hlt.fastCharge, shared, usbModeChanged);
|
||||
}
|
||||
drawWireless(d, status, live);
|
||||
usbDataMode = usbDataEnabled;
|
||||
painted = true;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <helpers/ui/DisplayDriver.h>
|
||||
|
||||
struct PowerBankSnapshot;
|
||||
|
||||
class PowerBankPage {
|
||||
public:
|
||||
void invalidate() { painted = false; }
|
||||
void draw(DisplayDriver& display, const PowerBankSnapshot& status, bool usbDataEnabled);
|
||||
|
||||
private:
|
||||
struct UsbPort {
|
||||
uint8_t state = 0;
|
||||
char protocol[16]{};
|
||||
};
|
||||
|
||||
void drawBattery(DisplayDriver& d, const PowerBankSnapshot& status);
|
||||
void drawPower(DisplayDriver& d, const PowerBankSnapshot& status, bool live);
|
||||
void drawUsb(DisplayDriver& d, int x, UsbPort& last, uint8_t state, uint8_t mode, bool shared, bool force = false);
|
||||
void drawUsbDataMode(DisplayDriver& d, int x);
|
||||
void drawWireless(DisplayDriver& d, const PowerBankSnapshot& status, bool live);
|
||||
|
||||
bool painted = false;
|
||||
int percent = -1;
|
||||
int32_t temperature = 0;
|
||||
int32_t wattsX10 = -1;
|
||||
bool boltActive = false;
|
||||
bool usbDataMode = false;
|
||||
UsbPort c1, c2;
|
||||
const char* qiState = "";
|
||||
int fod = -1;
|
||||
char qiProtocol[16]{};
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
#include "PowerBankUi.h"
|
||||
#include "HeltecMeshPocketV2Board.h"
|
||||
#include <helpers/ui/NV3001BDisplay.h>
|
||||
|
||||
PowerBankUi::PowerBankUi(HeltecMeshPocketV2Board& board)
|
||||
: board(board), secondaryButton(PIN_BUTTON2, 1000, true, true, false) {}
|
||||
|
||||
void PowerBankUi::begin() {
|
||||
secondaryButton.begin();
|
||||
}
|
||||
|
||||
uint8_t PowerBankUi::pollEvents() {
|
||||
uint8_t events = 0;
|
||||
const int buttonEvent = secondaryButton.check();
|
||||
if (buttonEvent == BUTTON_EVENT_CLICK) events |= EVENT_SHOW_PAGE;
|
||||
#ifdef MESHPOCKET_V2_USB_SWITCHABLE
|
||||
if (buttonEvent == BUTTON_EVENT_LONG_PRESS) events |= EVENT_PAGE_ACTION;
|
||||
#endif
|
||||
if (board.powerBank.takePageEvent()) events |= EVENT_REQUEST_FOCUS;
|
||||
return events;
|
||||
}
|
||||
|
||||
void PowerBankUi::handlePageAction() {
|
||||
#ifdef MESHPOCKET_V2_USB_SWITCHABLE
|
||||
board.toggleUsbData();
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t PowerBankUi::render(NV3001BDisplay& display, bool fullRefresh) {
|
||||
if (fullRefresh) page.invalidate();
|
||||
display.setNativePixels(true);
|
||||
page.draw(display, board.powerBank.snapshot(), board.isUsbDataEnabled());
|
||||
display.setNativePixels(false);
|
||||
return 500;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <helpers/ui/MomentaryButton.h>
|
||||
#include "PowerBankPage.h"
|
||||
|
||||
class HeltecMeshPocketV2Board;
|
||||
class NV3001BDisplay;
|
||||
|
||||
class PowerBankUi {
|
||||
HeltecMeshPocketV2Board& board;
|
||||
PowerBankPage page;
|
||||
MomentaryButton secondaryButton;
|
||||
|
||||
public:
|
||||
enum Event : uint8_t {
|
||||
EVENT_SHOW_PAGE = 1 << 0,
|
||||
EVENT_PAGE_ACTION = 1 << 1,
|
||||
EVENT_REQUEST_FOCUS = 1 << 2,
|
||||
};
|
||||
|
||||
explicit PowerBankUi(HeltecMeshPocketV2Board& board);
|
||||
void begin();
|
||||
uint8_t pollEvents();
|
||||
void handlePageAction();
|
||||
uint32_t render(NV3001BDisplay& display, bool fullRefresh);
|
||||
};
|
||||
@@ -0,0 +1,87 @@
|
||||
[heltec_meshpocket_v2]
|
||||
extends = nrf52_base
|
||||
board = heltec_meshpocket_v2
|
||||
board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
|
||||
board_upload.maximum_size = 712704
|
||||
build_flags = ${nrf52_base.build_flags}
|
||||
-I variants/heltec_meshpocket_v2
|
||||
-I src/helpers/nrf52
|
||||
-I lib/nrf52/s140_nrf52_6.1.1_API/include
|
||||
-I lib/nrf52/s140_nrf52_6.1.1_API/include/nrf52
|
||||
-D HELTEC_MESH_POCKET_V2
|
||||
-D RADIO_CLASS=CustomSX1262
|
||||
-D WRAPPER_CLASS=CustomSX1262Wrapper
|
||||
-D LORA_TX_POWER=22
|
||||
-D SX126X_CURRENT_LIMIT=140
|
||||
-D SX126X_RX_BOOSTED_GAIN=1
|
||||
-D DISPLAY_CLASS=NV3001BDisplay
|
||||
-D ENV_INCLUDE_GPS=1
|
||||
-D DISABLE_DIAGNOSTIC_OUTPUT
|
||||
build_src_filter = ${nrf52_base.build_src_filter}
|
||||
+<../variants/heltec_meshpocket_v2/*.cpp>
|
||||
+<helpers/sensors/EnvironmentSensorManager.cpp>
|
||||
+<helpers/ui/NV3001BDisplay.cpp>
|
||||
lib_deps = ${nrf52_base.lib_deps}
|
||||
https://github.com/Quency-D/heltec-meshpocket-v2-power/releases/download/v0.2.0/HeltecMeshPocketV2Power-0.2.0.zip
|
||||
stevemarple/MicroNMEA @ ^2.0.6
|
||||
bakercp/CRC32 @ ^2.0.0
|
||||
debug_tool = jlink
|
||||
upload_protocol = nrfutil
|
||||
|
||||
[heltec_meshpocket_v2_companion]
|
||||
extends = heltec_meshpocket_v2
|
||||
build_flags = ${heltec_meshpocket_v2.build_flags}
|
||||
-I variants/heltec_meshpocket_v2/ui-companion
|
||||
-D MAX_CONTACTS=350
|
||||
-D MAX_GROUP_CHANNELS=40
|
||||
build_src_filter = ${heltec_meshpocket_v2.build_src_filter}
|
||||
+<../examples/companion_radio/*.cpp>
|
||||
+<../variants/heltec_meshpocket_v2/ui-companion/*.cpp>
|
||||
lib_deps = ${heltec_meshpocket_v2.lib_deps}
|
||||
densaugeo/base64 @ ~1.4.0
|
||||
|
||||
[env:heltec_meshpocket_v2_companion_radio_ble]
|
||||
extends = heltec_meshpocket_v2_companion
|
||||
build_flags = ${heltec_meshpocket_v2_companion.build_flags}
|
||||
-D BLE_PIN_CODE=123456
|
||||
-D OFFLINE_QUEUE_SIZE=256
|
||||
build_src_filter = ${heltec_meshpocket_v2_companion.build_src_filter}
|
||||
+<helpers/nrf52/SerialBLEInterface.cpp>
|
||||
|
||||
[env:heltec_meshpocket_v2_companion_radio_usb]
|
||||
extends = heltec_meshpocket_v2_companion
|
||||
build_flags = ${heltec_meshpocket_v2_companion.build_flags}
|
||||
-D ENABLE_USB_INTERFACE
|
||||
-D MESHPOCKET_V2_USB_SWITCHABLE
|
||||
|
||||
[heltec_meshpocket_v2_server]
|
||||
extends = heltec_meshpocket_v2
|
||||
build_flags = ${heltec_meshpocket_v2.build_flags}
|
||||
-I variants/heltec_meshpocket_v2/ui-server
|
||||
-D MESHPOCKET_V2_USB_SWITCHABLE
|
||||
build_src_filter = ${heltec_meshpocket_v2.build_src_filter}
|
||||
+<helpers/ui/BaseUITask.cpp>
|
||||
+<../variants/heltec_meshpocket_v2/ui-server/*.cpp>
|
||||
|
||||
[env:heltec_meshpocket_v2_repeater]
|
||||
extends = heltec_meshpocket_v2_server
|
||||
build_flags = ${heltec_meshpocket_v2_server.build_flags}
|
||||
-D ADVERT_NAME='"MeshPocket V2 Repeater"'
|
||||
-D ADVERT_LAT=0.0
|
||||
-D ADVERT_LON=0.0
|
||||
-D ADMIN_PASSWORD='"password"'
|
||||
-D MAX_NEIGHBOURS=50
|
||||
build_src_filter = ${heltec_meshpocket_v2_server.build_src_filter}
|
||||
+<../examples/simple_repeater>
|
||||
|
||||
[env:heltec_meshpocket_v2_room_server]
|
||||
extends = heltec_meshpocket_v2_server
|
||||
build_flags = ${heltec_meshpocket_v2_server.build_flags}
|
||||
-D MESHPOCKET_V2_ROOM_SERVER
|
||||
-D ADVERT_NAME='"MeshPocket V2 Room"'
|
||||
-D ADVERT_LAT=0.0
|
||||
-D ADVERT_LON=0.0
|
||||
-D ADMIN_PASSWORD='"password"'
|
||||
-D ROOM_PASSWORD='"hello"'
|
||||
build_src_filter = ${heltec_meshpocket_v2_server.build_src_filter}
|
||||
+<../examples/simple_room_server>
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "target.h"
|
||||
#include <helpers/sensors/MicroNMEALocationProvider.h>
|
||||
|
||||
HeltecMeshPocketV2Board board;
|
||||
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI);
|
||||
WRAPPER_CLASS radio_driver(radio, board);
|
||||
VolatileRTCClock rtc_clock;
|
||||
NmeaGpsDriver gps_driver(Serial1);
|
||||
MicroNMEALocationProvider gps(gps_driver, &rtc_clock);
|
||||
EnvironmentSensorManager sensors(gps);
|
||||
DISPLAY_CLASS display(&SPI1);
|
||||
MomentaryButton user_btn(PIN_USER_BTN, 1000, true, true);
|
||||
|
||||
bool radio_init() {
|
||||
return radio.std_init(&SPI);
|
||||
}
|
||||
|
||||
mesh::LocalIdentity radio_new_identity() {
|
||||
RadioNoiseListener rng(radio);
|
||||
return mesh::LocalIdentity(&rng);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <helpers/radiolib/CustomSX1262Wrapper.h>
|
||||
#include <helpers/ArduinoHelpers.h>
|
||||
#include <helpers/sensors/EnvironmentSensorManager.h>
|
||||
#include <helpers/ui/MomentaryButton.h>
|
||||
#include <helpers/ui/NV3001BDisplay.h>
|
||||
#include <UITask.h>
|
||||
#include "HeltecMeshPocketV2Board.h"
|
||||
|
||||
extern HeltecMeshPocketV2Board board;
|
||||
extern WRAPPER_CLASS radio_driver;
|
||||
extern VolatileRTCClock rtc_clock;
|
||||
extern EnvironmentSensorManager sensors;
|
||||
extern DISPLAY_CLASS display;
|
||||
extern MomentaryButton user_btn;
|
||||
extern UITask ui_task;
|
||||
|
||||
bool radio_init();
|
||||
mesh::LocalIdentity radio_new_identity();
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,145 @@
|
||||
// Based on src/helpers/ui/companion-new/UITask.h at 88bbae29.
|
||||
#pragma once
|
||||
|
||||
#include <MeshCore.h>
|
||||
#include <helpers/ui/DisplayDriver.h>
|
||||
#include <helpers/ui/UIScreen.h>
|
||||
#include <helpers/SensorManager.h>
|
||||
#include <helpers/BaseChatMesh.h>
|
||||
#include <helpers/MultiSerialInterface.h>
|
||||
#include <Arduino.h>
|
||||
#include <helpers/sensors/LPPDataHelpers.h>
|
||||
|
||||
#ifndef LED_STATE_ON
|
||||
#define LED_STATE_ON 1
|
||||
#endif
|
||||
|
||||
#ifdef PIN_BUZZER
|
||||
#include <helpers/ui/buzzer.h>
|
||||
#endif
|
||||
#ifdef PIN_VIBRATION
|
||||
#include <helpers/ui/GenericVibration.h>
|
||||
#endif
|
||||
|
||||
#include <helpers/ui/AbstractUITask.h>
|
||||
#include <helpers/CompanionNodePrefs.h>
|
||||
#include "HeltecMeshPocketV2Board.h"
|
||||
#include "PowerBankUi.h"
|
||||
|
||||
#ifdef UI_NO_DISCOVER_SCREEN
|
||||
#error "UI_NO_DISCOVER_SCREEN is obsolete - use -D UI_DISCOVER_SCREEN=0 instead"
|
||||
#endif
|
||||
|
||||
#ifndef UI_DISCOVER_SCREEN
|
||||
#define UI_DISCOVER_SCREEN 1
|
||||
#endif
|
||||
|
||||
#if UI_DISCOVER_SCREEN
|
||||
#ifdef UI_RECENT_LIST_SIZE
|
||||
#define DISCOVERED_NODES_TABLE_SIZE UI_RECENT_LIST_SIZE
|
||||
#else
|
||||
#define DISCOVERED_NODES_TABLE_SIZE 4
|
||||
#endif
|
||||
|
||||
struct DiscoveredNode {
|
||||
float snr_in;
|
||||
float snr_out;
|
||||
uint8_t pubkey_prefix[9];
|
||||
uint8_t type;
|
||||
char name[32];
|
||||
};
|
||||
#endif
|
||||
|
||||
class UITask : public AbstractUITask {
|
||||
PowerBankUi powerUi;
|
||||
DisplayDriver* _display;
|
||||
SensorManager* _sensors;
|
||||
BaseChatMesh* the_mesh;
|
||||
uint32_t _ble_pin;
|
||||
#ifdef PIN_BUZZER
|
||||
genericBuzzer buzzer;
|
||||
#endif
|
||||
#ifdef PIN_VIBRATION
|
||||
GenericVibration vibration;
|
||||
#endif
|
||||
unsigned long _next_refresh, _auto_off;
|
||||
NodePrefs* _node_prefs;
|
||||
char _alert[80];
|
||||
unsigned long _alert_expiry;
|
||||
int _msgcount;
|
||||
unsigned long ui_started_at, next_batt_chck;
|
||||
unsigned long next_backlight_btn_check = 0;
|
||||
unsigned long _backlight_off = 0;
|
||||
#ifdef PIN_STATUS_LED
|
||||
int led_state = 0;
|
||||
int next_led_change = 0;
|
||||
int last_led_increment = 0;
|
||||
#endif
|
||||
|
||||
#ifdef PIN_USER_BTN_ANA
|
||||
unsigned long _analogue_pin_read_millis = millis();
|
||||
#endif
|
||||
|
||||
UIScreen* splash;
|
||||
UIScreen* home;
|
||||
UIScreen* msg_preview;
|
||||
UIScreen* curr;
|
||||
bool powerPageHadAlert = false;
|
||||
|
||||
void userLedHandler();
|
||||
|
||||
// Button action handlers
|
||||
char checkDisplayOn(char c);
|
||||
char handleLongPress(char c);
|
||||
char handleDoubleClick(char c);
|
||||
char handleTripleClick(char c);
|
||||
|
||||
void setCurrScreen(UIScreen* c);
|
||||
void handlePowerPageFocus(uint8_t events, bool handlingInput);
|
||||
|
||||
public:
|
||||
|
||||
UITask(HeltecMeshPocketV2Board& board, DisplayDriver* display = NULL) :
|
||||
AbstractUITask(&board), powerUi(board), _display(display), _sensors(NULL) {
|
||||
next_batt_chck = _next_refresh = 0;
|
||||
ui_started_at = 0;
|
||||
curr = NULL;
|
||||
}
|
||||
void begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs, MultiSerialInterface* serial,
|
||||
BaseChatMesh* mesh, uint32_t ble_pin, const char* ver, const char* build_date);
|
||||
|
||||
void gotoHomeScreen() { setCurrScreen(home); }
|
||||
void showAlert(const char* text, int duration_millis);
|
||||
int getMsgCount() const { return _msgcount; }
|
||||
bool hasDisplay() const { return _display != NULL; }
|
||||
bool isButtonPressed() const;
|
||||
|
||||
BaseChatMesh* getMesh() const { return the_mesh; }
|
||||
uint32_t getBLEPin() const { return _ble_pin; }
|
||||
|
||||
bool isBuzzerQuiet() {
|
||||
#ifdef PIN_BUZZER
|
||||
return buzzer.isQuiet();
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
void toggleBuzzer();
|
||||
bool getGPSState();
|
||||
void toggleGPS();
|
||||
void triggerGPS();
|
||||
|
||||
// MeshEventListener
|
||||
void onMessageRecv(mesh::Packet *pkt, const ContactInfo &from, uint8_t txt_type, uint32_t sender_timestamp, const char* text) override;
|
||||
void onChannelMessageRecv(mesh::Packet *pkt, ChannelDetails& channel_details, const char* text) override;
|
||||
void onQueueSizeChanged(int offline_queue_size) override;
|
||||
void onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path_len, const uint8_t* path) override;
|
||||
void onControlDataRecv(const mesh::Packet* pkt) override;
|
||||
|
||||
// from AbstractUITask
|
||||
void notify(UIEventType t = UIEventType::none) override;
|
||||
void loop() override;
|
||||
|
||||
void shutdown(bool restart = false);
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
#include "target.h"
|
||||
|
||||
UITask ui_task(board);
|
||||
@@ -0,0 +1,206 @@
|
||||
// Based on src/helpers/ui/server/UITask.cpp at upstream 88bbae29.
|
||||
#include "UITask.h"
|
||||
#include "target.h"
|
||||
#include <Arduino.h>
|
||||
#include <helpers/CommonCLI.h>
|
||||
|
||||
#ifndef USER_BTN_PRESSED
|
||||
#define USER_BTN_PRESSED LOW
|
||||
#endif
|
||||
|
||||
#define AUTO_OFF_MILLIS 20000 // 20 seconds
|
||||
#define BOOT_SCREEN_MILLIS 4000 // 4 seconds
|
||||
|
||||
#define POWEROFF_DELAY 3000
|
||||
|
||||
// 'meshcore', 128x13px
|
||||
static const uint8_t meshcore_logo [] PROGMEM = {
|
||||
0x3c, 0x01, 0xe3, 0xff, 0xc7, 0xff, 0x8f, 0x03, 0x87, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe,
|
||||
0x3c, 0x03, 0xe3, 0xff, 0xc7, 0xff, 0x8e, 0x03, 0x8f, 0xfe, 0x3f, 0xfe, 0x1f, 0xff, 0x1f, 0xfe,
|
||||
0x3e, 0x03, 0xc3, 0xff, 0x8f, 0xff, 0x0e, 0x07, 0x8f, 0xfe, 0x7f, 0xfe, 0x1f, 0xff, 0x1f, 0xfc,
|
||||
0x3e, 0x07, 0xc7, 0x80, 0x0e, 0x00, 0x0e, 0x07, 0x9e, 0x00, 0x78, 0x0e, 0x3c, 0x0f, 0x1c, 0x00,
|
||||
0x3e, 0x0f, 0xc7, 0x80, 0x1e, 0x00, 0x0e, 0x07, 0x1e, 0x00, 0x70, 0x0e, 0x38, 0x0f, 0x3c, 0x00,
|
||||
0x7f, 0x0f, 0xc7, 0xfe, 0x1f, 0xfc, 0x1f, 0xff, 0x1c, 0x00, 0x70, 0x0e, 0x38, 0x0e, 0x3f, 0xf8,
|
||||
0x7f, 0x1f, 0xc7, 0xfe, 0x0f, 0xff, 0x1f, 0xff, 0x1c, 0x00, 0xf0, 0x0e, 0x38, 0x0e, 0x3f, 0xf8,
|
||||
0x7f, 0x3f, 0xc7, 0xfe, 0x0f, 0xff, 0x1f, 0xff, 0x1c, 0x00, 0xf0, 0x1e, 0x3f, 0xfe, 0x3f, 0xf0,
|
||||
0x77, 0x3b, 0x87, 0x00, 0x00, 0x07, 0x1c, 0x0f, 0x3c, 0x00, 0xe0, 0x1c, 0x7f, 0xfc, 0x38, 0x00,
|
||||
0x77, 0xfb, 0x8f, 0x00, 0x00, 0x07, 0x1c, 0x0f, 0x3c, 0x00, 0xe0, 0x1c, 0x7f, 0xf8, 0x38, 0x00,
|
||||
0x73, 0xf3, 0x8f, 0xff, 0x0f, 0xff, 0x1c, 0x0e, 0x3f, 0xf8, 0xff, 0xfc, 0x70, 0x78, 0x7f, 0xf8,
|
||||
0xe3, 0xe3, 0x8f, 0xff, 0x1f, 0xfe, 0x3c, 0x0e, 0x3f, 0xf8, 0xff, 0xfc, 0x70, 0x3c, 0x7f, 0xf8,
|
||||
0xe3, 0xe3, 0x8f, 0xff, 0x1f, 0xfc, 0x3c, 0x0e, 0x1f, 0xf8, 0xff, 0xf8, 0x70, 0x3c, 0x7f, 0xf8,
|
||||
};
|
||||
|
||||
void UITask::begin(NodePrefs* node_prefs, const char* build_date, const char* firmware_version, const char* role_lbl) {
|
||||
powerUi.begin();
|
||||
#ifdef MESHPOCKET_V2_ROOM_SERVER
|
||||
_prevBtnState = HIGH;
|
||||
_started_at = 0; // The Room Server's splash starts at power-on.
|
||||
#else
|
||||
_started_at = millis();
|
||||
#endif
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS;
|
||||
_node_prefs = node_prefs;
|
||||
_display->turnOn();
|
||||
|
||||
#ifndef MESHPOCKET_V2_ROOM_SERVER
|
||||
user_btn.begin();
|
||||
#endif
|
||||
|
||||
// strip off dash and commit hash by changing dash to null terminator
|
||||
// e.g: v1.2.3-abcdef -> v1.2.3
|
||||
char *version = strdup(firmware_version);
|
||||
char *dash = strchr(version, '-');
|
||||
if (dash){
|
||||
*dash = 0;
|
||||
}
|
||||
|
||||
// v1.2.3 (1 Jan 2025)
|
||||
snprintf(_version_info, sizeof(_version_info), "%s (%s)", version, build_date);
|
||||
free(version);
|
||||
|
||||
_role_label = role_lbl;
|
||||
}
|
||||
|
||||
long UITask::renderCurrScreen() {
|
||||
if (!_powering_off_at && _power_page_selected) {
|
||||
const long interval = powerUi.render(::display, _power_page_full_refresh);
|
||||
_power_page_full_refresh = false;
|
||||
return interval;
|
||||
}
|
||||
_display->startFrame();
|
||||
char tmp[80];
|
||||
if (millis() < _started_at + BOOT_SCREEN_MILLIS) { // boot screen
|
||||
// meshcore logo
|
||||
_display->setColor(UIColor::corp_blue);
|
||||
int logoWidth = 128;
|
||||
_display->drawXbm((_display->width() - logoWidth) / 2, 3, meshcore_logo, logoWidth, 13);
|
||||
|
||||
// meshcore website
|
||||
const char* website = "https://meshcore.io";
|
||||
_display->setColor(UIColor::primary_txt);
|
||||
_display->setTextSize(1);
|
||||
_display->drawTextCentered(_display->width() / 2, 22, website);
|
||||
|
||||
// version info
|
||||
_display->setTextSize(1);
|
||||
_display->drawTextCentered(_display->width() / 2, 35, _version_info);
|
||||
|
||||
// node type
|
||||
_display->drawTextCentered(_display->width() / 2, 48, _role_label);
|
||||
} else if (_powering_off_at > 0) {
|
||||
// meshcore logo
|
||||
_display->setColor(UIColor::corp_blue);
|
||||
int logoWidth = 128;
|
||||
_display->drawXbm((_display->width() - logoWidth) / 2, 3, meshcore_logo, logoWidth, 13);
|
||||
|
||||
// meshcore website
|
||||
const char* website = "https://meshcore.io";
|
||||
_display->setColor(UIColor::primary_txt);
|
||||
_display->setTextSize(1);
|
||||
_display->drawTextCentered(_display->width()/ 2, 22, website);
|
||||
|
||||
// Powering off
|
||||
const char* poweroff_string = "Turning OFF";
|
||||
uint16_t poffWidth = _display->getTextWidth(poweroff_string);
|
||||
_display->setCursor((_display->width() - poffWidth) / 2, 48);
|
||||
_display->drawTextCentered(_display->width()/2, 48, poweroff_string);
|
||||
} else {
|
||||
_display->setCursor(0, 0);
|
||||
_display->setTextSize(1);
|
||||
_display->setColor(UIColor::primary_txt);
|
||||
_display->print(_node_prefs->node_name);
|
||||
|
||||
// freq / sf
|
||||
_display->setCursor(0, 20);
|
||||
sprintf(tmp, "FREQ: %06.3f SF%d", _node_prefs->freq, _node_prefs->sf);
|
||||
_display->print(tmp);
|
||||
|
||||
// bw / cr
|
||||
_display->setCursor(0, 30);
|
||||
sprintf(tmp, "BW: %03.2f CR: %d", _node_prefs->bw, _node_prefs->cr);
|
||||
_display->print(tmp);
|
||||
}
|
||||
return 1000; // 1 sec interval
|
||||
}
|
||||
|
||||
int UITask::readPrimaryButton() {
|
||||
#ifdef MESHPOCKET_V2_ROOM_SERVER
|
||||
if (millis() < _next_read) return BUTTON_EVENT_NONE;
|
||||
const int state = digitalRead(PIN_USER_BTN);
|
||||
const bool pressed = state == USER_BTN_PRESSED && state != _prevBtnState;
|
||||
_prevBtnState = state;
|
||||
_next_read = millis() + 200;
|
||||
return pressed ? BUTTON_EVENT_CLICK : BUTTON_EVENT_NONE;
|
||||
#else
|
||||
return user_btn.check();
|
||||
#endif
|
||||
}
|
||||
|
||||
void UITask::showPowerPage() {
|
||||
if (!_display->isOn()) _display->turnOn();
|
||||
if (!_power_page_selected) _power_page_full_refresh = true;
|
||||
_power_page_selected = true;
|
||||
_next_refresh = 0;
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS;
|
||||
}
|
||||
|
||||
void UITask::loop() {
|
||||
if (!_display->isOn()) _power_page_full_refresh = true;
|
||||
const uint8_t events = powerUi.pollEvents();
|
||||
const bool canChangePage = !_powering_off_at && millis() - _started_at >= BOOT_SCREEN_MILLIS;
|
||||
bool handlingInput = false;
|
||||
if (canChangePage && (events & PowerBankUi::EVENT_SHOW_PAGE)) {
|
||||
showPowerPage();
|
||||
handlingInput = true;
|
||||
} else if (canChangePage && (events & PowerBankUi::EVENT_PAGE_ACTION) &&
|
||||
_display->isOn() && _power_page_selected) {
|
||||
powerUi.handlePageAction();
|
||||
_next_refresh = 0;
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS;
|
||||
handlingInput = true;
|
||||
}
|
||||
|
||||
const int ev = readPrimaryButton();
|
||||
handlingInput = handlingInput || ev != BUTTON_EVENT_NONE;
|
||||
if (ev == BUTTON_EVENT_CLICK) {
|
||||
if (!_display->isOn()) {
|
||||
_display->turnOn();
|
||||
} else if (canChangePage) {
|
||||
_power_page_selected = !_power_page_selected;
|
||||
_power_page_full_refresh = true;
|
||||
_next_refresh = 0;
|
||||
}
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS;
|
||||
} else if (ev == BUTTON_EVENT_LONG_PRESS) {
|
||||
_display->turnOn();
|
||||
Serial.println("Powering Off");
|
||||
_powering_off_at = millis() + POWEROFF_DELAY;
|
||||
_next_refresh = 0;
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS;
|
||||
}
|
||||
|
||||
const bool canTakePowerEvent = !_powering_off_at && millis() - _started_at >= BOOT_SCREEN_MILLIS;
|
||||
if (!handlingInput && canTakePowerEvent && (events & PowerBankUi::EVENT_REQUEST_FOCUS)) {
|
||||
showPowerPage();
|
||||
}
|
||||
|
||||
if (_display->isOn()) {
|
||||
if (millis() >= _next_refresh) {
|
||||
const long interval = renderCurrScreen();
|
||||
_display->endFrame();
|
||||
_next_refresh = millis() + interval;
|
||||
}
|
||||
if (millis() > _auto_off) _display->turnOff();
|
||||
}
|
||||
|
||||
if (_powering_off_at > 0) { // power off timer armed
|
||||
#if defined(LED_PIN) && defined(LED_STATE_ON)
|
||||
digitalWrite(LED_PIN, LED_STATE_ON); // switch on the led until poweroff
|
||||
delay(1000);
|
||||
digitalWrite(LED_PIN, !LED_STATE_ON); // off LED
|
||||
#endif
|
||||
if (millis() > _powering_off_at) {
|
||||
_board->powerOff(); // should not return
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Based on src/helpers/ui/server/UITask.h at upstream 88bbae29.
|
||||
#pragma once
|
||||
|
||||
#include <helpers/ui/BaseUITask.h>
|
||||
#include <helpers/CommonCLI.h>
|
||||
#include "HeltecMeshPocketV2Board.h"
|
||||
#include "PowerBankUi.h"
|
||||
|
||||
class UITask : public BaseUITask {
|
||||
PowerBankUi powerUi;
|
||||
bool _power_page_selected = false;
|
||||
bool _power_page_full_refresh = true;
|
||||
#ifdef MESHPOCKET_V2_ROOM_SERVER
|
||||
unsigned long _next_read = 0;
|
||||
int _prevBtnState;
|
||||
#endif
|
||||
NodePrefs* _node_prefs;
|
||||
char _version_info[32];
|
||||
const char* _role_label;
|
||||
unsigned long _powering_off_at = 0;
|
||||
unsigned long _started_at = 0;
|
||||
|
||||
int readPrimaryButton();
|
||||
void showPowerPage();
|
||||
|
||||
protected:
|
||||
long renderCurrScreen() override;
|
||||
|
||||
public:
|
||||
UITask(HeltecMeshPocketV2Board& board, DisplayDriver* display) : BaseUITask(&board, display), powerUi(board) {}
|
||||
void begin(NodePrefs* node_prefs, const char* build_date, const char* firmware_version, const char* role_lbl);
|
||||
|
||||
void loop() override;
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
#include "target.h"
|
||||
|
||||
UITask ui_task(board, &display);
|
||||
@@ -0,0 +1,13 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
const uint32_t g_ADigitalPinMap[] = {
|
||||
0xff, 0xff, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
||||
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
||||
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47
|
||||
};
|
||||
|
||||
void initVariant() {
|
||||
// Preload the output latch before driving the USB data switch.
|
||||
digitalWrite(PIN_IO_CSA, LOW);
|
||||
pinMode(PIN_IO_CSA, OUTPUT);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
#pragma once
|
||||
|
||||
#include "WVariant.h"
|
||||
|
||||
#define USE_LFXO
|
||||
#define VARIANT_MCK 64000000ul
|
||||
#define PINS_COUNT 48
|
||||
#define NUM_DIGITAL_PINS 48
|
||||
#define NUM_ANALOG_INPUTS 0
|
||||
#define NUM_ANALOG_OUTPUTS 0
|
||||
#define PIN_LED1 (-1)
|
||||
#define LED_BUILTIN PIN_LED1
|
||||
#define LED_BLUE (-1)
|
||||
#define LED_GREEN (-1)
|
||||
#define LED_STATE_ON 1
|
||||
#define PIN_USER_BTN 43
|
||||
#define PIN_BUTTON2 42
|
||||
|
||||
#define WIRE_INTERFACES_COUNT 1
|
||||
#define PIN_WIRE_SDA 13
|
||||
#define PIN_WIRE_SCL 5
|
||||
#define PIN_CW_INT 12
|
||||
#define PIN_IO_CSA 20
|
||||
#define PIN_9006_IO1 4
|
||||
#define PIN_9006_IO2 41
|
||||
#define PIN_SERIAL2_RX 26
|
||||
#define PIN_SERIAL2_TX 15
|
||||
|
||||
// EnvironmentSensorManager names the UART pins from the GPS module's side.
|
||||
#define PIN_GPS_TX 34
|
||||
#define PIN_GPS_RX 36
|
||||
#define PIN_SERIAL1_RX PIN_GPS_TX
|
||||
#define PIN_SERIAL1_TX PIN_GPS_RX
|
||||
#define PIN_GPS_EN 22
|
||||
#define PIN_GPS_EN_ACTIVE LOW
|
||||
#define PIN_GPS_RESET 38
|
||||
#define PIN_GPS_RESET_ACTIVE LOW
|
||||
#define PIN_GPS_PPS 10
|
||||
#define GPS_BAUD_RATE 115200
|
||||
|
||||
#define SPI_INTERFACES_COUNT 2
|
||||
#define PIN_SPI_MISO 2
|
||||
#define PIN_SPI_MOSI 47
|
||||
#define PIN_SPI_SCK 45
|
||||
#define P_LORA_MISO PIN_SPI_MISO
|
||||
#define P_LORA_MOSI PIN_SPI_MOSI
|
||||
#define P_LORA_SCLK PIN_SPI_SCK
|
||||
#define P_LORA_NSS 14
|
||||
#define P_LORA_DIO_1 31
|
||||
#define P_LORA_BUSY 29
|
||||
#define P_LORA_RESET 11
|
||||
#define SX126X_DIO2_AS_RF_SWITCH true
|
||||
#define SX126X_DIO3_TCXO_VOLTAGE 1.8f
|
||||
|
||||
#define PIN_SPI1_MISO 3
|
||||
#define PIN_SPI1_MOSI 39
|
||||
#define PIN_SPI1_SCK 33
|
||||
#define PIN_TFT_SDA PIN_SPI1_MOSI
|
||||
#define PIN_TFT_SCL PIN_SPI1_SCK
|
||||
#define PIN_TFT_CS 16
|
||||
#define PIN_TFT_DC 32
|
||||
#define PIN_TFT_RST 24
|
||||
#define PIN_TFT_EN 9
|
||||
#define PIN_TFT_EN_ACTIVE LOW
|
||||
#define PIN_TFT_BL 25
|
||||
#define PIN_TFT_BL_ACTIVE HIGH
|
||||
#define SPI_FREQUENCY 8000000
|
||||
#define DISPLAY_ROTATION 3 // NV3001B MADCTL MX | MV
|
||||
@@ -223,6 +223,7 @@ build_flags =
|
||||
-D MAX_GROUP_CHANNELS=40
|
||||
-D BLE_PIN_CODE=123456
|
||||
-D ENV_INCLUDE_GPS=1 ; enable the GPS page in UI
|
||||
-D UI_SHOW_CLOCK=1 ; show clock and date on home screen by default
|
||||
; -D BLE_DEBUG_LOGGING=1
|
||||
-D OFFLINE_QUEUE_SIZE=256
|
||||
; -D MESH_PACKET_LOGGING=1
|
||||
@@ -245,6 +246,7 @@ build_flags =
|
||||
-D MAX_CONTACTS=350
|
||||
-D MAX_GROUP_CHANNELS=40
|
||||
-D ENABLE_USB_INTERFACE
|
||||
-D UI_SHOW_CLOCK=1 ; show clock and date on home screen by default
|
||||
; -D BLE_PIN_CODE=123456
|
||||
; -D BLE_DEBUG_LOGGING=1
|
||||
; -D MESH_PACKET_LOGGING=1
|
||||
|
||||
Reference in new issue
Block a user