Compare commits
32
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a44b5ff52 | ||
|
|
44f7566337 | ||
|
|
bda1c586f1 | ||
|
|
736691cbd2 | ||
|
|
540f87ca77 | ||
|
|
ba6f6cd073 | ||
|
|
14f5892033 | ||
|
|
e730d2ecb2 | ||
|
|
3accaf358d | ||
|
|
6ae61bbb40 | ||
|
|
c58274a2e1 | ||
|
|
47c1388450 | ||
|
|
6b9943740c | ||
|
|
137b9a9f05 | ||
|
|
e86ed1373b | ||
|
|
0be43965aa | ||
|
|
505ae195dd | ||
|
|
388d9064e8 | ||
|
|
04efa6d119 | ||
|
|
19fb356e85 | ||
|
|
8322949af8 | ||
|
|
b9054f61a4 | ||
|
|
5c73a3b582 | ||
|
|
76bf7afa11 | ||
|
|
a5bdc6db81 | ||
|
|
2593015f4a | ||
|
|
b5ae48e2e4 | ||
|
|
9883dca417 | ||
|
|
ebde355a60 | ||
|
|
00520b8bb0 | ||
|
|
f69fab7759 | ||
|
|
2bbc96b303 |
No files matched your search
@@ -322,6 +322,11 @@ jobs:
|
||||
# changelog against the newest older release that HEAD descends from
|
||||
prev="" base=""
|
||||
while read -r t c; do
|
||||
# the tag, not the release's target_commitish: Gitea keeps the
|
||||
# commitish from creation, and after a rewrite of the public
|
||||
# history (26. 11. 2026) it named commits no longer in it -- no
|
||||
# base was found and the notes listed the last 20 commits
|
||||
c=$(git rev-parse -q --verify "refs/tags/$t^{commit}" 2>/dev/null || echo "$c")
|
||||
if [ "$c" != "$SHA" ] && git merge-base --is-ancestor "$c" "$SHA" 2>/dev/null; then
|
||||
prev=$t base=$c
|
||||
break
|
||||
|
||||
@@ -274,7 +274,7 @@ Refer to the node's manual for the correct settings to use.
|
||||
- `set tx <dbm>`
|
||||
|
||||
**Parameters:**
|
||||
- `dbm`: Power level in dBm (1-22)
|
||||
- `dbm`: Power level in dBm (-9 to 22 on SX126x; meshcore-tth refuses values out of range or not taken by the radio)
|
||||
|
||||
**Set by build flag:** `LORA_TX_POWER`
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ Radio parameters are common to all roles and handled by `CommonRadioPrefs`.
|
||||
- `set tx <dbm>`
|
||||
|
||||
**Parameters:**
|
||||
- `dbm`: Power level in dBm (1-22)
|
||||
- `dbm`: Power level in dBm (-9 to 22 on SX126x; meshcore-tth refuses values out of range or not taken by the radio)
|
||||
|
||||
**Set by build flag:** `LORA_TX_POWER`
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ Once you have a working app/project, you need to be able to demonstrate it exist
|
||||
| 0130 - 013F | StreamSensor | william@housedillon.com - https://housedillon.com/blog/lora-e5-with-seeed-fusion |
|
||||
| 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 |
|
||||
| FF00 - FFFF | -reserved for testing/dev- | |
|
||||
|
||||
(add rows, inside the range 0100 - FEFF for custom apps)
|
||||
+132
-1
@@ -12,7 +12,8 @@ figures are.
|
||||
|---|---|---|
|
||||
| **GPS running continuously** | **46.0 mA** (spread 43.7-47.5) | `gps duty` recovers 42-45 of it |
|
||||
| BLE advertising + Bluefruit's blinking LED | see below | defaults changed, LED off, 1 s interval |
|
||||
| `powersaving on` (MCU light sleep) | **~1 mA, not separable from zero** | keep it on (free), but it is not a lever |
|
||||
| `powersaving on` (MCU light sleep) | **~1 mA** with USB, **2.7 mA** without (XIAO, 11/2026) | keep it on |
|
||||
| CC310 IRQ cleared before sleep (nRF52) | **2.6 mA** after every boot | fixed in firmware, see below |
|
||||
| RX duty cycle (`set radio.rxps`, from EasySkyMesh) | **~2.3 mA** at `max` (XIAO, 12. 11. 2026) | **no** on a live node: -16 % received and a TX stall on mast-three, see below |
|
||||
| `radio.rxgain off` | ~0.7 mA | **no** — 1-3 dB of sensitivity is what a mast node is for |
|
||||
| FEM LNA control | n/a | SenseCap has no FEM, only an RXEN switch |
|
||||
@@ -218,6 +219,136 @@ then shows `RESETREAS=0x00020000`, bit 17, wake from LPCOMP); with a cutoff
|
||||
set, lowering the supply below it must switch the node off within ~3 minutes
|
||||
and `get pwr` after the wake must say `last off: Low Voltage`.
|
||||
|
||||
## nRF52 sleep & peripheral fixes
|
||||
|
||||
An audit of the nRF52840 firmware and the Adafruit core found several sources of
|
||||
idle draw that apply to all nRF52 boards, not only SenseCAP Solar. They were
|
||||
measured on 25./26. 11. 2026 on XIAO x4 (nRF52840 + Wio-SX1262, repeater build,
|
||||
bench preset). Setup: no USB host, fed at 5 V through an INA226 read every
|
||||
~1 s. Each cell was 10 min (20 min for rxps), 38 cells over two rounds. Every
|
||||
knob was switched at runtime between two baseline cells. The baseline
|
||||
repeatability was **0.05 mA**, so an effect counts only above 0.1 mA and with
|
||||
the same sign in both rounds. The 5 V pin is VBUS, so USBD and HFXO stay up;
|
||||
read the absolute numbers as this rig and the deltas as the result.
|
||||
|
||||
**The one that matters: `CRYPTOCELL_IRQn` sleep insomnia (+2.6 mA).**
|
||||
`USE_CC310_HW_CRYPTO=1` runs CC310 in polling mode with `CRYPTOCELL_IRQn`
|
||||
disabled in NVIC. A completed operation leaves the IRQ pending, and a pending
|
||||
IRQ ends `sd_app_evt_wait()`/`__WFE()` immediately. `NRF52Board::sleep()` now
|
||||
clears it before sleeping, as the Adafruit core's `wiring.c` does. Without the
|
||||
clear, a node comes out of every boot stuck at **14.1 mA instead of 11.5**:
|
||||
|
||||
| boot with | before first BLE connection | after it |
|
||||
|---|---|---|
|
||||
| both fixes | 11.51 / 11.51 mA | 11.48 / 11.49 mA |
|
||||
| no CC clear | **14.13 / 14.15 mA** | 11.38 / 11.52 mA |
|
||||
| no CC clear, no late DC/DC (= old main) | **14.04 / 14.14 mA** | 11.50 / 11.55 mA |
|
||||
| no late DC/DC | 11.43 / 11.53 mA | 11.51 / 11.53 mA |
|
||||
|
||||
Values are round 1 / round 2. In the stuck state the core wakes
|
||||
~15 000 times a second, against ~990 for the 1024 Hz tick, and it is awake
|
||||
for 80 % of the time. It is not an occasional spike either: 98–100 % of the
|
||||
samples sit above 13 mA. Received LoRa packets do not end it (5 per window). The
|
||||
first BLE connection does; the mechanism is not traced. A mast node that nobody
|
||||
connects to over BLE stays in it. Toggling the clear at runtime
|
||||
on an already clean node changes nothing (+0.01 / +0.02 mA), because the state
|
||||
is decided at boot.
|
||||
|
||||
**The same run again at 3.3 V without VBUS (27. 11. 2026).** Here x4 is fed on
|
||||
its 3V3 pin at 3.25 V, so `bench duty` reads `vbus 0 usbd 0` and HFXO is
|
||||
off. This is the closer match to a node on a cell. The setup was the same:
|
||||
38 cells, two rounds, all of them valid. Baseline repeatability (detrended SD of
|
||||
the base cells) was **0.009 / 0.015 mA**, so the threshold here is 0.03 mA.
|
||||
The baseline is **6.90 mA** (22 mW, against 57 mW on the 5 V pin).
|
||||
|
||||
| boot with | before first BLE connection | after it |
|
||||
|---|---|---|
|
||||
| both fixes | 6.91 / 6.92 mA | 6.89 / 6.88 mA |
|
||||
| no CC clear | **10.16 / 10.16 mA** | 6.91 / 6.89 mA |
|
||||
| no CC clear, no late DC/DC (= old main) | **10.18 / 10.18 mA** | 6.89 / 6.94 mA |
|
||||
| no late DC/DC | 6.90 / 6.91 mA | 6.93 / 6.92 mA |
|
||||
|
||||
The CC310 insomnia costs **+3.3 mA, almost half of the whole node**. Every
|
||||
sample of those windows sits above 8.5 mA. The core wakes 14 900 times a
|
||||
second, against 986, it is awake 79 % of the time, and `cc_pend` reads 1.
|
||||
|
||||
At this voltage **DC/DC is worth 0.6 mA**. `bench dcdc off` at runtime gives
|
||||
+0.63 / +0.60 mA, and `A_like` (DC/DC off, CC clear off, nfcal 2 s) gives
|
||||
+0.59 / +0.61 mA, the same thing. On the 5 V pin the same switch was below
|
||||
resolution. The late re-enable still changes nothing, because `DCDCEN` reads 1
|
||||
after every boot with or without it. So the regulator mode matters, and
|
||||
SoftDevice simply does not turn it off.
|
||||
|
||||
| knob (3.3 V) | round 1 | round 2 |
|
||||
|---|---|---|
|
||||
| `bench dcdc off` | +0.63 mA | +0.60 mA |
|
||||
| `bench cc off` (runtime) | +0.00 mA | −0.01 mA |
|
||||
| `bench nfcal 2000` | −0.04 mA (one pair) | |
|
||||
| `set radio.rxps max` | −2.30 mA | −2.30 mA |
|
||||
| `set radio.rxps balanced` | −1.98 mA | −1.82 mA |
|
||||
| `set radio.rxgain off` | −0.45 mA | −0.51 mA |
|
||||
| `powersaving off` | +2.37 mA (one pair) | |
|
||||
|
||||
The rxps, rxgain and powersaving deltas match the 5 V run to within 0.3 mA.
|
||||
In relative terms, rxps max now takes a third off the node. Reception from the
|
||||
x1 witness matched what it sent in every cell (base 82 received for 72 sent;
|
||||
x4 also hears other bench traffic). The witness again only detects a gross
|
||||
loss, not a sensitivity loss.
|
||||
|
||||
**Measured to make no difference, kept anyway** (each below 0.1 mA):
|
||||
- **DC/DC re-enabled after SoftDevice start** (`onBootComplete()`):
|
||||
+0.02 / −0.10 mA at runtime on the 5 V pin, and no difference as a boot flag
|
||||
at either voltage. The premise that S140 puts `NRF_POWER` back to LDO did not
|
||||
hold on this board. `DCDCEN` read 1 after every boot, with or without the
|
||||
late enable. The late enable is kept as a harmless safeguard. DC/DC itself
|
||||
does matter at 3.3 V (see above).
|
||||
- **Noise-floor calibration every 10 s instead of 2 s**
|
||||
(`NOISE_FLOOR_CALIB_INTERVAL`): +0.08 mA at 5 V and −0.04 mA at 3.3 V, one
|
||||
pair each. That is at the edge of resolution and of no practical weight.
|
||||
|
||||
**Not measured** (compile-time or other hardware):
|
||||
- **Avoid `NRF_SPIM3` (Nordic Errata 195)**: `[nrf52_base]` sets
|
||||
`-D SPI_32MHZ_INTERFACE=1`, which moves the SX1262 `SPI` bus from `NRF_SPIM3`
|
||||
to `NRF_SPIM2`. `SPIClass::endTransaction()` disables `SPIM3` without the
|
||||
errata workaround, which is worth ~1.2–2 mA idle per the errata. A clean
|
||||
baseline of 11.5 mA on this board leaves little room for that.
|
||||
- **GPS UART pins disconnected while the GPS is off**:
|
||||
`NmeaGpsDriver::stopHardware()` resets TX/RX via `nrf_gpio_cfg_default()`
|
||||
after `Uart::end()`, so the unpowered receiver is not back-powered.
|
||||
- **Unused I2C bus switched off**: `EnvironmentSensorManager::begin()` calls
|
||||
`Wire.end()` when the bus scan finds no device, and enables it again for the
|
||||
`i2c` CLI command.
|
||||
- **SenseCAP Solar battery divider (`VBAT_ENABLE`)**: held `HIGH` (off) at boot
|
||||
and set back to `HIGH` right after `getBattMilliVolts()`, instead of staying
|
||||
`LOW`. `initiateShutdown()` still drives it `LOW` when it arms the LPCOMP
|
||||
wake. It saves ~2.8 µA (4.2 V over 1.5 MOhm). With the old 10 ms settle the
|
||||
reading came out 110-150 mV high (mast-three and second-mast after the OTA of
|
||||
26.-27. 11. 2026, both at night, remote-mast without the change flat): the ADC
|
||||
node starts high with the divider off. The settle is 100 ms now; still to be
|
||||
checked against a meter, and whether the ADC pin sits near VDD + 0.3 V on a
|
||||
full cell.
|
||||
|
||||
**Runtime knobs from the same night**, for comparison (paired deltas):
|
||||
|
||||
| knob | round 1 | round 2 | reception (x1 witness) |
|
||||
|---|---|---|---|
|
||||
| `set radio.rxps max` | −2.47 mA | −2.33 mA | 20/21 |
|
||||
| `set radio.rxps balanced` | −1.98 mA | −1.88 mA | 20/21 |
|
||||
| `set radio.rxgain off` | −0.49 mA | −0.45 mA | 10/12 |
|
||||
| `powersaving off` | +2.66 mA | (one pair) | 5/6 |
|
||||
| baseline | | | 83/90 |
|
||||
|
||||
The x1 witness sends zero-hop adverts every ~130 s at 2 dBm. Reception counts
|
||||
are approximate at cell edges, and no knob showed a gross loss. The bench
|
||||
signal is strong, so this does not test sensitivity, and the rxps failure on
|
||||
the live mesh (see above) still stands. `powersaving` is worth 2.7 mA here
|
||||
without USB, much more than the ~1 mA measured with USB attached (USB keeps
|
||||
HFCLK running).
|
||||
|
||||
Tools: `tools/power_ab.py --ina <url>` (INA226 of a solar controller as the
|
||||
meter, raw samples saved), firmware bench knobs and the night driver are kept with
|
||||
the run log, outside the repository.
|
||||
|
||||
## Measuring this yourself — two traps
|
||||
|
||||
1. **A solar node measured on its USB side measures the CHARGER.** With a
|
||||
|
||||
+16
-1
@@ -106,12 +106,27 @@ stall watchdog", "Reboot into the bootloader" and "Why the board last reset".
|
||||
| `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) |
|
||||
|
||||
## Number arguments of `set` (all, and the companion's serial CLI)
|
||||
|
||||
Upstream parses the value of a `set` with `atoi()`/`atof()`: text became 0,
|
||||
`300` became 44 in a one-byte setting, and the result was saved with `OK`. This
|
||||
fork refuses a value that is not a number or lies outside the range and keeps
|
||||
the old one (`Error, must be ...`). It applies to `set tx` (-9 up to the
|
||||
board's `MAX_LORA_TX_POWER`, else 30, and saved only if the radio takes it:
|
||||
SX1262 -9..22), `set radio` and `tempradio` (each field; the timeout 1-10080
|
||||
min), `set freq`, `set lat`/`set lon`, `set flood.max`, `set
|
||||
flood.max.unscoped`, `set flood.max.advert` (0-64), `set int.thresh` (0-255),
|
||||
`set multi.acks` (0-1), `set path.hash.mode` (0-2), `set agc.reset.interval`
|
||||
(0-1020), `set rxdelay`, `set txdelay`, `set direct.txdelay`, `set
|
||||
adc.multiplier`, and on the companion `set pin`, `set adc.multiplier`, `set
|
||||
tz.offset`. No exponent (`1e3`), no `nan`/`inf`.
|
||||
|
||||
## Diagnostics
|
||||
|
||||
| command | where | |
|
||||
|---|---|---|
|
||||
| `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 (`set tx` saves and says OK even when the radio refused) |
|
||||
| `txpwr [dBm]` | repeater | LoRa output power until reboot, with RadioLib's status; takes -9..30 |
|
||||
| `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)) |
|
||||
| `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 |
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <WiFi.h>
|
||||
#endif
|
||||
#include <Mesh.h>
|
||||
#include <helpers/CliArgs.h>
|
||||
|
||||
#define CMD_APP_START 1
|
||||
#define CMD_SEND_TXT_MSG 2
|
||||
@@ -202,6 +203,7 @@ void MyMesh::updateContactFromFrame(ContactInfo &contact, uint32_t& last_mod, co
|
||||
memcpy(contact.out_path, &frame[i], MAX_PATH_SIZE);
|
||||
i += MAX_PATH_SIZE;
|
||||
memcpy(contact.name, &frame[i], 32);
|
||||
contact.name[sizeof(contact.name) - 1] = 0; // the app is not trusted to NUL-terminate
|
||||
i += 32;
|
||||
memcpy(&contact.last_advert_timestamp, &frame[i], 4);
|
||||
i += 4;
|
||||
@@ -2209,7 +2211,12 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char*
|
||||
#endif
|
||||
|
||||
if (memcmp(command, "set pin ", 8) == 0) {
|
||||
_prefs.ble_pin = atoi(&command[8]);
|
||||
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");
|
||||
return true;
|
||||
}
|
||||
_prefs.ble_pin = pin;
|
||||
savePrefs();
|
||||
sprintf(reply, "> pin is now %06d", _prefs.ble_pin);
|
||||
return true;
|
||||
@@ -2302,8 +2309,8 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char*
|
||||
}
|
||||
|
||||
if (memcmp(command, "set adc.multiplier ", 19) == 0) { // same as CommonCLI
|
||||
float mult = atof(&command[19]);
|
||||
if (mult < 0.0f || mult > 10.0f) {
|
||||
float mult = 0;
|
||||
if (!cli_args::parseFloat(&command[19], 0.0f, 10.0f, &mult)) {
|
||||
strcpy(reply, "Error, must be from 0 to 10");
|
||||
} else if (board.setAdcMultiplier(mult)) {
|
||||
_prefs.adc_multiplier = mult;
|
||||
@@ -2334,8 +2341,8 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char*
|
||||
return true;
|
||||
}
|
||||
if (memcmp(command, "set tz.offset ", 14) == 0) {
|
||||
float tz = atof(&command[14]);
|
||||
if (tz < -12 || tz > 14) {
|
||||
float tz = 0;
|
||||
if (!cli_args::parseFloat(&command[14], -12.0f, 14.0f, &tz)) {
|
||||
strcpy(reply, "Error, must be from -12 to +14");
|
||||
} else {
|
||||
_prefs.tz_offset = tz;
|
||||
|
||||
@@ -397,6 +397,7 @@ uint8_t MyMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t* secr
|
||||
}
|
||||
|
||||
client = acl.putClient(sender, 0); // add to contacts (if not already known)
|
||||
if (client == NULL) return 0;
|
||||
if (sender_timestamp <= client->last_timestamp) {
|
||||
MESH_DEBUG_PRINTLN("Possible login replay attack!");
|
||||
return 0; // FATAL: client table is full -OR- replay attack
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "MyMesh.h"
|
||||
#include <helpers/NodeMaintenance.h>
|
||||
#include <helpers/CliArgs.h>
|
||||
|
||||
// ===========================================================================
|
||||
// CUSTOM (TeTeHacko): `blink [n]` -- make THIS board flash its LED on demand,
|
||||
@@ -625,7 +626,12 @@ MyMesh the_mesh(board, radio_driver, *new ArduinoMillis(), fast_rng, rtc_clock,
|
||||
bool txPwrHandleCommand(const char* command, char* reply) {
|
||||
if (memcmp(command, "txpwr", 5) != 0 || (command[5] != 0 && command[5] != ' ')) return false;
|
||||
if (command[5] == ' ') {
|
||||
int dbm = atoi(&command[6]);
|
||||
long dbm_l; // atoi() into int8_t: "250" went out as -6 dBm, "abc" as 0
|
||||
if (!cli_args::parseInt(&command[6], -9, 30, &dbm_l)) {
|
||||
strcpy(reply, "ERR - txpwr <-9..30 dBm>");
|
||||
return true;
|
||||
}
|
||||
int dbm = dbm_l;
|
||||
radio_driver.setTxPower((int8_t) dbm);
|
||||
int16_t st = radio_driver.getLastTxPowerStatus();
|
||||
sprintf(reply, "%s - txpwr %d dBm, RadioLib status %d%s", st == RADIOLIB_ERR_NONE ? "OK" : "ERR",
|
||||
|
||||
@@ -378,6 +378,8 @@ void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const m
|
||||
}
|
||||
|
||||
client = acl.putClient(sender, 0); // add to known clients (if not already known)
|
||||
if (client == NULL) return;
|
||||
|
||||
if (sender_timestamp <= client->last_timestamp) {
|
||||
MESH_DEBUG_PRINTLN("possible replay attack!");
|
||||
return;
|
||||
|
||||
@@ -392,6 +392,7 @@ uint8_t SensorMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t*
|
||||
}
|
||||
|
||||
client = acl.putClient(sender, PERM_RECV_ALERTS_HI | PERM_RECV_ALERTS_LO); // add to contacts (if not already known)
|
||||
if (client == NULL) return 0;
|
||||
if (sender_timestamp <= client->last_timestamp) {
|
||||
MESH_DEBUG_PRINTLN("Possible login replay attack!");
|
||||
return 0; // FATAL: client table is full -OR- replay attack
|
||||
|
||||
@@ -142,6 +142,7 @@ build_flags = ${arduino_base.build_flags}
|
||||
-D EXTRAFS=1
|
||||
-D FW_OTA_PUBKEY='"${ota.pubkey}"'
|
||||
-D USE_CC310_HW_CRYPTO=1
|
||||
-D SPI_32MHZ_INTERFACE=1
|
||||
lib_deps =
|
||||
${arduino_base.lib_deps}
|
||||
https://github.com/oltaco/CustomLFS#0.2.3
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ namespace mesh {
|
||||
#define MIN_TX_BUDGET_AIRTIME_DIV 2 // require at least 1/N of estimated airtime as budget before TX
|
||||
|
||||
#ifndef NOISE_FLOOR_CALIB_INTERVAL
|
||||
#define NOISE_FLOOR_CALIB_INTERVAL 2000 // 2 seconds
|
||||
#define NOISE_FLOOR_CALIB_INTERVAL 10000 // 10 seconds
|
||||
#endif
|
||||
|
||||
void Dispatcher::begin() {
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
// CUSTOM (TeTeHacko): strict number arguments for CLI `set` commands.
|
||||
//
|
||||
// atoi()/atof() take any text: "abc" is 0, "300" goes into a uint8_t as 44,
|
||||
// and "nan" is a float that no range check refuses (under -ffast-math, which
|
||||
// the nRF52 builds use, the compiler may even fold that check away). The set
|
||||
// commands then saved the result and answered "OK" -- `set tx 30` on an
|
||||
// SX1262, `set freq abc` (150 MHz after the next boot's clamp), `set flood.max
|
||||
// 300` (44). These helpers accept a whole number (or decimal) in a range and
|
||||
// nothing else: optional surrounding white space and sign, digits, and for the
|
||||
// float a '.' and fraction. No exponent, no hex, no trailing text.
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace cli_args {
|
||||
|
||||
// Returns true and sets *out when `s` is an integer in [lo, hi].
|
||||
inline bool parseInt(const char* s, long lo, long hi, long* out) {
|
||||
if (!s) return false;
|
||||
while (isspace((unsigned char)*s)) s++;
|
||||
const char* p = s;
|
||||
if (*p == '+' || *p == '-') p++;
|
||||
if (!isdigit((unsigned char)*p)) return false;
|
||||
char* end;
|
||||
long v = strtol(s, &end, 10);
|
||||
while (isspace((unsigned char)*end)) end++;
|
||||
if (*end != 0) return false;
|
||||
if (v < lo || v > hi) return false;
|
||||
*out = v;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Returns true and sets *out when `s` is a decimal number in [lo, hi].
|
||||
inline bool parseFloat(const char* s, float lo, float hi, float* out) {
|
||||
if (!s) return false;
|
||||
while (isspace((unsigned char)*s)) s++;
|
||||
const char* p = s;
|
||||
if (*p == '+' || *p == '-') p++;
|
||||
bool digits = false;
|
||||
while (isdigit((unsigned char)*p)) { p++; digits = true; }
|
||||
if (*p == '.') {
|
||||
p++;
|
||||
while (isdigit((unsigned char)*p)) { p++; digits = true; }
|
||||
}
|
||||
if (!digits) return false;
|
||||
const char* rest = p;
|
||||
while (isspace((unsigned char)*rest)) rest++;
|
||||
if (*rest != 0) return false; // exponent, "nan", "inf" or trailing text
|
||||
float v = strtof(s, nullptr);
|
||||
if (!(v >= lo && v <= hi)) return false;
|
||||
*out = v;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace cli_args
|
||||
@@ -219,7 +219,7 @@ ClientInfo* ClientACL::getClient(const uint8_t* pubkey, int key_len) {
|
||||
|
||||
ClientInfo* ClientACL::putClient(const mesh::Identity& id, uint8_t init_perms) {
|
||||
uint32_t min_time = 0xFFFFFFFF;
|
||||
ClientInfo* oldest = &clients[MAX_CLIENTS - 1];
|
||||
ClientInfo* oldest = NULL;
|
||||
for (int i = 0; i < num_clients; i++) {
|
||||
if (id.matches(clients[i].id)) return &clients[i]; // already known
|
||||
if (!clients[i].isAdmin() && clients[i].last_activity < min_time) {
|
||||
@@ -232,6 +232,7 @@ ClientInfo* ClientACL::putClient(const mesh::Identity& id, uint8_t init_perms) {
|
||||
if (num_clients < MAX_CLIENTS) {
|
||||
c = &clients[num_clients++];
|
||||
} else {
|
||||
if (oldest == NULL) return NULL; // every entry is an admin, so don't evict
|
||||
c = oldest; // evict least active contact
|
||||
orphanTimestamp(c);
|
||||
}
|
||||
@@ -268,6 +269,7 @@ bool ClientACL::applyPermissions(const mesh::LocalIdentity& self_id, const uint8
|
||||
|
||||
mesh::Identity id(pubkey);
|
||||
c = putClient(id, 0);
|
||||
if (c == NULL) return false; // couldn't put client
|
||||
|
||||
c->permissions = perms; // update their permissions
|
||||
self_id.calcSharedSecret(c->shared_secret, pubkey);
|
||||
|
||||
@@ -86,7 +86,7 @@ public:
|
||||
void persistTimestamp(ClientInfo* c, uint32_t sender_timestamp, uint32_t now);
|
||||
|
||||
ClientInfo* getClient(const uint8_t* pubkey, int key_len);
|
||||
ClientInfo* putClient(const mesh::Identity& id, uint8_t init_perms);
|
||||
ClientInfo* putClient(const mesh::Identity& id, uint8_t init_perms); // returns NULL if table is full and all entries are admins
|
||||
bool applyPermissions(const mesh::LocalIdentity& self_id, const uint8_t* pubkey, int key_len, uint8_t perms);
|
||||
|
||||
int getNumClients() const { return num_clients; }
|
||||
|
||||
+47
-24
@@ -1,4 +1,5 @@
|
||||
#include <Arduino.h>
|
||||
#include "CliArgs.h"
|
||||
#include "CommonCLI.h"
|
||||
#include "TxtDataHelpers.h"
|
||||
#include "AdvertDataHelpers.h"
|
||||
@@ -354,12 +355,14 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, char* command, char* re
|
||||
StrHelper::strncpy(tmp, &command[10], sizeof(tmp));
|
||||
const char *parts[5];
|
||||
int num = mesh::Utils::parseTextParts(tmp, parts, 5);
|
||||
float freq = num > 0 ? strtof(parts[0], nullptr) : 0.0f;
|
||||
float bw = num > 1 ? strtof(parts[1], nullptr) : 0.0f;
|
||||
uint8_t sf = num > 2 ? atoi(parts[2]) : 0;
|
||||
uint8_t cr = num > 3 ? atoi(parts[3]) : 0;
|
||||
int temp_timeout_mins = num > 4 ? atoi(parts[4]) : 0;
|
||||
if (freq >= 150.0f && freq <= 2500.0f && sf >= 5 && sf <= 12 && cr >= 5 && cr <= 8 && bw >= 7.0f && bw <= 500.0f && temp_timeout_mins > 0) {
|
||||
float freq = 0, bw = 0;
|
||||
long sf_l = 0, cr_l = 0, mins_l = 0;
|
||||
if (num == 5 && cli_args::parseFloat(parts[0], 150.0f, 2500.0f, &freq) &&
|
||||
cli_args::parseFloat(parts[1], 7.0f, 500.0f, &bw) &&
|
||||
cli_args::parseInt(parts[2], 5, 12, &sf_l) && cli_args::parseInt(parts[3], 5, 8, &cr_l) &&
|
||||
cli_args::parseInt(parts[4], 1, 10080, &mins_l)) {
|
||||
uint8_t sf = sf_l, cr = cr_l;
|
||||
int temp_timeout_mins = mins_l;
|
||||
_callbacks->applyTempRadioParams(freq, bw, sf, cr, temp_timeout_mins);
|
||||
sprintf(reply, "OK - temp params for %d mins", temp_timeout_mins);
|
||||
} else {
|
||||
@@ -733,18 +736,28 @@ void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* rep
|
||||
savePrefs();
|
||||
strcpy(reply, _prefs->disable_fwd ? "OK - repeat is now OFF" : "OK - repeat is now ON");
|
||||
} else if (memcmp(config, "lat ", 4) == 0) {
|
||||
_prefs->node_lat = atof(&config[4]);
|
||||
_prefs->getGpsPrefs()->applyGuardReference(*_sensors);
|
||||
savePrefs();
|
||||
strcpy(reply, "OK");
|
||||
float v;
|
||||
if (cli_args::parseFloat(&config[4], -90.0f, 90.0f, &v)) {
|
||||
_prefs->node_lat = v;
|
||||
_prefs->getGpsPrefs()->applyGuardReference(*_sensors);
|
||||
savePrefs();
|
||||
strcpy(reply, "OK");
|
||||
} else {
|
||||
strcpy(reply, "Error, must be -90..90");
|
||||
}
|
||||
} else if (memcmp(config, "lon ", 4) == 0) {
|
||||
_prefs->node_lon = atof(&config[4]);
|
||||
_prefs->getGpsPrefs()->applyGuardReference(*_sensors);
|
||||
savePrefs();
|
||||
strcpy(reply, "OK");
|
||||
float v;
|
||||
if (cli_args::parseFloat(&config[4], -180.0f, 180.0f, &v)) {
|
||||
_prefs->node_lon = v;
|
||||
_prefs->getGpsPrefs()->applyGuardReference(*_sensors);
|
||||
savePrefs();
|
||||
strcpy(reply, "OK");
|
||||
} else {
|
||||
strcpy(reply, "Error, must be -180..180");
|
||||
}
|
||||
} else if (memcmp(config, "flood.max.unscoped ", 19) == 0) {
|
||||
uint8_t m = atoi(&config[19]);
|
||||
if (m <= 64) {
|
||||
long m; // was uint8_t = atoi(): "300" became 44 and passed
|
||||
if (cli_args::parseInt(&config[19], 0, 64, &m)) {
|
||||
_prefs->flood_max_unscoped = m;
|
||||
savePrefs();
|
||||
strcpy(reply, "OK");
|
||||
@@ -752,8 +765,8 @@ void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* rep
|
||||
strcpy(reply, "Error, max 64");
|
||||
}
|
||||
} else if (memcmp(config, "flood.max.advert ", 17) == 0) {
|
||||
uint8_t m = atoi(&config[17]);
|
||||
if (m <= 64) {
|
||||
long m; // was uint8_t = atoi(): "300" became 44 and passed
|
||||
if (cli_args::parseInt(&config[17], 0, 64, &m)) {
|
||||
_prefs->flood_max_advert = m;
|
||||
savePrefs();
|
||||
strcpy(reply, "OK");
|
||||
@@ -761,8 +774,8 @@ void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* rep
|
||||
strcpy(reply, "Error, max 64");
|
||||
}
|
||||
} else if (memcmp(config, "flood.max ", 10) == 0) {
|
||||
uint8_t m = atoi(&config[10]);
|
||||
if (m <= 64) {
|
||||
long m; // was uint8_t = atoi(): "300" became 44 and passed
|
||||
if (cli_args::parseInt(&config[10], 0, 64, &m)) {
|
||||
_prefs->flood_max = m;
|
||||
savePrefs();
|
||||
strcpy(reply, "OK");
|
||||
@@ -800,9 +813,14 @@ void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* rep
|
||||
strcpy(reply, "OK");
|
||||
}
|
||||
} else if (sender_timestamp == 0 && memcmp(config, "freq ", 5) == 0) {
|
||||
_prefs->freq = atof(&config[5]);
|
||||
savePrefs();
|
||||
strcpy(reply, "OK - reboot to apply");
|
||||
float f; // was atof(): "abc" saved 0, i.e. 150 MHz after the next boot's clamp
|
||||
if (cli_args::parseFloat(&config[5], 150.0f, 2500.0f, &f)) {
|
||||
_prefs->freq = f;
|
||||
savePrefs();
|
||||
strcpy(reply, "OK - reboot to apply");
|
||||
} else {
|
||||
strcpy(reply, "Error, must be 150-2500 MHz");
|
||||
}
|
||||
#ifdef WITH_BRIDGE
|
||||
} else if (memcmp(config, "bridge.enabled ", 15) == 0) {
|
||||
_prefs->bridge_enabled = memcmp(&config[15], "on", 2) == 0;
|
||||
@@ -885,7 +903,12 @@ void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* rep
|
||||
strcpy(reply, "on - shows on next advert");
|
||||
}
|
||||
} else if (memcmp(config, "adc.multiplier ", 15) == 0) {
|
||||
_prefs->adc_multiplier = atof(&config[15]);
|
||||
float m;
|
||||
if (!cli_args::parseFloat(&config[15], 0.0f, 10.0f, &m)) {
|
||||
strcpy(reply, "Error, must be 0-10 (0 = board default)");
|
||||
return;
|
||||
}
|
||||
_prefs->adc_multiplier = m;
|
||||
if (_board->setAdcMultiplier(_prefs->adc_multiplier)) {
|
||||
savePrefs();
|
||||
if (_prefs->adc_multiplier == 0.0f) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "CommonRadioPrefs.h"
|
||||
#include "CliArgs.h"
|
||||
#include "TxtDataHelpers.h"
|
||||
#include "Utils.h"
|
||||
#include "target.h"
|
||||
@@ -30,6 +31,19 @@ RxPowerSavingControl* rxpsControl() {
|
||||
}
|
||||
#endif
|
||||
|
||||
// CUSTOM (TeTeHacko): the radio's verdict on the last setTxPower(), where the
|
||||
// driver keeps one (RadioLibWrapper); other drivers (ESP-NOW) count as accepted.
|
||||
template <class R>
|
||||
auto lastTxPowerStatus(R& r, int) -> decltype(r.getLastTxPowerStatus()) { return r.getLastTxPowerStatus(); }
|
||||
template <class R>
|
||||
int16_t lastTxPowerStatus(R&, long) { return 0; }
|
||||
|
||||
#ifdef MAX_LORA_TX_POWER
|
||||
constexpr long TX_POWER_MAX = MAX_LORA_TX_POWER;
|
||||
#else
|
||||
constexpr long TX_POWER_MAX = 30; // the same ceiling as the prefs load clamp
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
|
||||
#ifdef WITH_RX_POWERSAVING
|
||||
@@ -62,12 +76,12 @@ bool CommonRadioPrefs::getByKey(const char* key, char* value, size_t max_len) {
|
||||
}
|
||||
bool CommonRadioPrefs::setByKey(const char* key, const char* value) {
|
||||
if (strcmp(key, "fem_rxgain") == 0) {
|
||||
setFEMRxGain(atoi(value));
|
||||
setFEMRxGain(atoi(value) ? 1 : 0); // boolean, as the prefs load clamps it
|
||||
markDirty();
|
||||
return true;
|
||||
}
|
||||
if (strcmp(key, "fem_txgain") == 0) {
|
||||
setFEMTxGain(atoi(value));
|
||||
setFEMTxGain(atoi(value) ? 1 : 0); // boolean, as the prefs load clamps it
|
||||
markDirty();
|
||||
return true;
|
||||
}
|
||||
@@ -111,11 +125,12 @@ bool CommonRadioPrefs::handleCommand(const char* command, uint32_t sender_timest
|
||||
strcpy(tmp, &command[10]);
|
||||
const char *parts[4];
|
||||
int num = mesh::Utils::parseTextParts(tmp, parts, 4);
|
||||
float freq = num > 0 ? strtof(parts[0], nullptr) : 0.0f;
|
||||
float bw = num > 1 ? strtof(parts[1], nullptr) : 0.0f;
|
||||
uint8_t sf = num > 2 ? atoi(parts[2]) : 0;
|
||||
uint8_t cr = num > 3 ? atoi(parts[3]) : 0;
|
||||
if (freq >= 150.0f && freq <= 2500.0f && sf >= 5 && sf <= 12 && cr >= 5 && cr <= 8 && bw >= 7.0f && bw <= 500.0f) {
|
||||
float freq = 0, bw = 0;
|
||||
long sf_l = 0, cr_l = 0;
|
||||
if (num == 4 && cli_args::parseFloat(parts[0], 150.0f, 2500.0f, &freq) &&
|
||||
cli_args::parseFloat(parts[1], 7.0f, 500.0f, &bw) &&
|
||||
cli_args::parseInt(parts[2], 5, 12, &sf_l) && cli_args::parseInt(parts[3], 5, 8, &cr_l)) {
|
||||
uint8_t sf = sf_l, cr = cr_l;
|
||||
setSpreadFactor(sf);
|
||||
setCodingRate(cr);
|
||||
setFreq(freq);
|
||||
@@ -186,8 +201,13 @@ bool CommonRadioPrefs::handleCommand(const char* command, uint32_t sender_timest
|
||||
return true;
|
||||
}
|
||||
if (memcmp(command, "set int.thresh ", 15) == 0) {
|
||||
setIntThresh(atoi(&command[15]));
|
||||
strcpy(reply, "OK");
|
||||
long t;
|
||||
if (cli_args::parseInt(&command[15], 0, 255, &t)) {
|
||||
setIntThresh(t);
|
||||
strcpy(reply, "OK");
|
||||
} else {
|
||||
strcpy(reply, "Error, must be 0-255");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -221,8 +241,23 @@ bool CommonRadioPrefs::handleCommand(const char* command, uint32_t sender_timest
|
||||
return true;
|
||||
}
|
||||
if (memcmp(command, "set tx ", 7) == 0) {
|
||||
setTxPower(atoi(&command[7]));
|
||||
radio_driver.setTxPower(getTxPower());
|
||||
// CUSTOM (TeTeHacko): was atoi() straight into the prefs and "OK" -- out of
|
||||
// range or not a number got saved, and the radio could refuse it silently
|
||||
// (SX1262 takes -9..22 and keeps its old power). Only a power the radio
|
||||
// took is saved now.
|
||||
long dbm;
|
||||
if (!cli_args::parseInt(&command[7], -9, TX_POWER_MAX, &dbm)) {
|
||||
sprintf(reply, "Error, must be -9..%d", (int)TX_POWER_MAX);
|
||||
return true;
|
||||
}
|
||||
int8_t old_dbm = getTxPower();
|
||||
radio_driver.setTxPower((int8_t)dbm);
|
||||
if (lastTxPowerStatus(radio_driver, 0) != 0) {
|
||||
radio_driver.setTxPower(old_dbm);
|
||||
sprintf(reply, "Error, radio refuses %d dBm (kept %d)", (int)dbm, (int)old_dbm);
|
||||
return true;
|
||||
}
|
||||
setTxPower((int8_t)dbm);
|
||||
strcpy(reply, "OK");
|
||||
return true;
|
||||
}
|
||||
@@ -232,8 +267,8 @@ bool CommonRadioPrefs::handleCommand(const char* command, uint32_t sender_timest
|
||||
return true;
|
||||
}
|
||||
if (memcmp(command, "set rxdelay ", 12) == 0) {
|
||||
float db = atof(&command[12]);
|
||||
if (db >= 0 && db <= 20.0f) {
|
||||
float db;
|
||||
if (cli_args::parseFloat(&command[12], 0, 20.0f, &db)) {
|
||||
setRxDelay(db);
|
||||
strcpy(reply, "OK");
|
||||
} else {
|
||||
@@ -247,8 +282,11 @@ bool CommonRadioPrefs::handleCommand(const char* command, uint32_t sender_timest
|
||||
return true;
|
||||
}
|
||||
if (memcmp(command, "set agc.reset.interval ", 23) == 0) {
|
||||
int secs = atoi(&command[23]);
|
||||
secs = constrain(secs, 0, 255 * 4);
|
||||
long secs;
|
||||
if (!cli_args::parseInt(&command[23], 0, 255 * 4, &secs)) {
|
||||
strcpy(reply, "Error, must be 0-1020");
|
||||
return true;
|
||||
}
|
||||
setAgcResetInt((uint16_t) secs);
|
||||
sprintf(reply, "OK - interval rounded to %d", (uint32_t) getAgcResetInt());
|
||||
return true;
|
||||
@@ -260,8 +298,8 @@ bool CommonRadioPrefs::handleCommand(const char* command, uint32_t sender_timest
|
||||
}
|
||||
if (memcmp(command, "set path.hash.mode ", 19) == 0) {
|
||||
const char* config = command + 19;
|
||||
uint8_t mode = atoi(config);
|
||||
if (mode < 3) {
|
||||
long mode;
|
||||
if (cli_args::parseInt(config, 0, 2, &mode)) {
|
||||
setHashMode(mode);
|
||||
strcpy(reply, "OK");
|
||||
} else {
|
||||
@@ -275,8 +313,13 @@ bool CommonRadioPrefs::handleCommand(const char* command, uint32_t sender_timest
|
||||
return true;
|
||||
}
|
||||
if (memcmp(command, "set multi.acks ", 15) == 0) {
|
||||
setMultiAcks(atoi(&command[15]));
|
||||
strcpy(reply, "OK");
|
||||
long n;
|
||||
if (cli_args::parseInt(&command[15], 0, 1, &n)) {
|
||||
setMultiAcks(n);
|
||||
strcpy(reply, "OK");
|
||||
} else {
|
||||
strcpy(reply, "Error, must be 0 or 1");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -285,8 +328,8 @@ bool CommonRadioPrefs::handleCommand(const char* command, uint32_t sender_timest
|
||||
return true;
|
||||
}
|
||||
if (memcmp(command, "set txdelay ", 12) == 0) {
|
||||
float f = atof(&command[12]);
|
||||
if (f >= 0 && f <= 2.0f) {
|
||||
float f;
|
||||
if (cli_args::parseFloat(&command[12], 0, 2.0f, &f)) {
|
||||
setFloodTxDelay(f);
|
||||
strcpy(reply, "OK");
|
||||
} else {
|
||||
@@ -300,8 +343,8 @@ bool CommonRadioPrefs::handleCommand(const char* command, uint32_t sender_timest
|
||||
return true;
|
||||
}
|
||||
if (memcmp(command, "set direct.txdelay ", 19) == 0) {
|
||||
float f = atof(&command[19]);
|
||||
if (f >= 0 && f <= 2.0f) {
|
||||
float f;
|
||||
if (cli_args::parseFloat(&command[19], 0, 2.0f, &f)) {
|
||||
setDirectTxDelay(f);
|
||||
strcpy(reply, "OK");
|
||||
} else {
|
||||
|
||||
@@ -288,10 +288,7 @@ void NRF52Board::pwrmgtWakeArmVbus() {
|
||||
}
|
||||
#endif
|
||||
|
||||
void NRF52BoardDCDC::begin() {
|
||||
NRF52Board::begin();
|
||||
|
||||
// Enable DC/DC converter for improved power efficiency
|
||||
static void enableNrf52Dcdc() {
|
||||
uint8_t sd_enabled = 0;
|
||||
sd_softdevice_is_enabled(&sd_enabled);
|
||||
if (sd_enabled) {
|
||||
@@ -301,6 +298,22 @@ void NRF52BoardDCDC::begin() {
|
||||
}
|
||||
}
|
||||
|
||||
void NRF52BoardDCDC::begin() {
|
||||
NRF52Board::begin();
|
||||
|
||||
// Enable DC/DC converter for improved power efficiency
|
||||
enableNrf52Dcdc();
|
||||
}
|
||||
|
||||
void NRF52BoardDCDC::onBootComplete() {
|
||||
NRF52Board::onBootComplete();
|
||||
|
||||
// SoftDevice (Bluefruit.begin()) starts after board.begin(). On XIAO x4
|
||||
// (11/2026) DCDCEN read 1 after boot with or without this call, so it is a
|
||||
// safeguard in case a SoftDevice/board combination resets NRF_POWER to LDO.
|
||||
enableNrf52Dcdc();
|
||||
}
|
||||
|
||||
bool NRF52Board::isExternalPowered() {
|
||||
// Check if SoftDevice is enabled before using its API
|
||||
uint8_t sd_enabled = 0;
|
||||
@@ -324,6 +337,14 @@ void NRF52Board::sleep(uint32_t secs) {
|
||||
NVIC_ClearPendingIRQ(FPU_IRQn);
|
||||
#endif
|
||||
|
||||
// Clear pending CRYPTOCELL interrupt to avoid WFE/sd_app_evt_wait() insomnia.
|
||||
// Adafruit_nRFCrypto polls CC310 with CRYPTOCELL_IRQn disabled in NVIC, so
|
||||
// completed crypto/TRNG calls leave it pending (same workaround as Adafruit
|
||||
// core wiring.c / port_cmsis_systick.c).
|
||||
#ifdef NRF_CRYPTOCELL
|
||||
NVIC_ClearPendingIRQ(CRYPTOCELL_IRQn);
|
||||
#endif
|
||||
|
||||
// On nRF52, we use event-driven sleep instead of timed sleep
|
||||
// The 'secs' parameter is ignored - we wake on any interrupt
|
||||
uint8_t sd_enabled = 0;
|
||||
|
||||
@@ -93,5 +93,6 @@ class NRF52BoardDCDC : virtual public NRF52Board {
|
||||
public:
|
||||
NRF52BoardDCDC() {}
|
||||
virtual void begin() override;
|
||||
virtual void onBootComplete() override;
|
||||
};
|
||||
#endif
|
||||
@@ -8,6 +8,10 @@
|
||||
#define TELEM_WIRE &Wire // Use default I2C bus for Environment Sensors
|
||||
#endif
|
||||
|
||||
#ifdef NRF52_PLATFORM
|
||||
static bool telem_wire_stopped = false;
|
||||
#endif
|
||||
|
||||
// ============================================================
|
||||
// Sensor library includes and static driver instances
|
||||
// ============================================================
|
||||
@@ -715,6 +719,11 @@ bool EnvironmentSensorManager::begin() {
|
||||
bool detected[128] = {};
|
||||
scanI2CBus(TELEM_WIRE, detected);
|
||||
|
||||
bool any_i2c_device = false;
|
||||
for (uint8_t addr = 0x08; addr < 0x78; addr++) {
|
||||
if (detected[addr]) { any_i2c_device = true; break; }
|
||||
}
|
||||
|
||||
// Walk the sensor table and initialize only detected devices.
|
||||
_active_sensor_count = 0;
|
||||
for (size_t i = 0; i < SENSOR_TABLE_SIZE && _active_sensor_count < MAX_ACTIVE_SENSORS; i++) {
|
||||
@@ -741,6 +750,15 @@ bool EnvironmentSensorManager::begin() {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef NRF52_PLATFORM
|
||||
if (!any_i2c_device) {
|
||||
// No device ACKed anywhere on the bus (neither sensor nor RTC/display):
|
||||
// disable TWIM to avoid idle peripheral/pull-up draw.
|
||||
(TELEM_WIRE)->end();
|
||||
telem_wire_stopped = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -765,6 +783,13 @@ static size_t appendWhole(char* dest, size_t used, size_t max_len, const char* s
|
||||
}
|
||||
|
||||
int EnvironmentSensorManager::scanI2C(char* dest, size_t max_len) {
|
||||
#ifdef NRF52_PLATFORM
|
||||
bool restarted = telem_wire_stopped;
|
||||
if (restarted) {
|
||||
(TELEM_WIRE)->begin();
|
||||
telem_wire_stopped = false;
|
||||
}
|
||||
#endif
|
||||
bool found[128] = {};
|
||||
scanI2CBus(TELEM_WIRE, found);
|
||||
|
||||
@@ -790,6 +815,13 @@ int EnvironmentSensorManager::scanI2C(char* dest, size_t max_len) {
|
||||
n++;
|
||||
}
|
||||
|
||||
#ifdef NRF52_PLATFORM
|
||||
if (restarted && n == 0) {
|
||||
(TELEM_WIRE)->end();
|
||||
telem_wire_stopped = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (n == 0) {
|
||||
used = appendWhole(dest, 0, max_len, "no I2C device answered");
|
||||
}
|
||||
|
||||
@@ -204,7 +204,13 @@ class NmeaGpsDriver : public GpsDriver {
|
||||
// core's own Uart::end()) for all the hours `gps duty` keeps the GPS off, and
|
||||
// its idle-high TX line feeds the unpowered module. sendNmeaSentence() is
|
||||
// gated on _started: a write to a closed Uart takes a deleted semaphore.
|
||||
if (_hardwareSerial != nullptr) _hardwareSerial->end();
|
||||
// Uart::end() clears PSEL but leaves GPIO PIN_CNF unchanged, so disconnect
|
||||
// the pins explicitly to avoid back-powering the unpowered GPS module.
|
||||
if (_hardwareSerial != nullptr) {
|
||||
_hardwareSerial->end();
|
||||
if (_txPin != -1) nrf_gpio_cfg_default(g_ADigitalPinMap[_txPin]);
|
||||
if (_rxPin != -1) nrf_gpio_cfg_default(g_ADigitalPinMap[_rxPin]);
|
||||
}
|
||||
#endif
|
||||
_started = false;
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ public:
|
||||
auto p = &recent[recent_next_idx];
|
||||
recent_next_idx = (recent_next_idx + 1) % UI_RECENT_LIST_SIZE;
|
||||
|
||||
strcpy(p->name, contact.name);
|
||||
StrHelper::strncpy(p->name, contact.name, sizeof(p->name));
|
||||
p->recv_timestamp = _rtc->getCurrentTime();
|
||||
}
|
||||
|
||||
@@ -456,12 +456,14 @@ public:
|
||||
bool hw_gps_state = nmea != NULL && nmea->isHardwareEnabled();
|
||||
uint32_t period = nmea != NULL ? nmea->getGpsPeriod() : 0;
|
||||
char fix_buf[12] = "";
|
||||
bool hasFix = false;
|
||||
if (nmea != NULL) {
|
||||
uint32_t fix_age = nmea->getLastFixAge();
|
||||
if (fix_age == UINT32_MAX) {
|
||||
strcpy(fix_buf, "no fix");
|
||||
} else {
|
||||
formatFixAge(fix_buf, sizeof(fix_buf), fix_age);
|
||||
hasFix = true;
|
||||
}
|
||||
}
|
||||
if (nmea != NULL && nmea->hasHardwareEnableState() && gps_state != hw_gps_state) {
|
||||
@@ -490,6 +492,7 @@ public:
|
||||
display.setColor(UIColor::primary_txt);
|
||||
sprintf(buf, "%d", nmea->satellitesCount());
|
||||
display.drawTextRightAlign(display.width()-1, y, buf);
|
||||
if (!hasFix) return 5000;
|
||||
y = y + 12;
|
||||
display.setColor(UIColor::secondary_txt);
|
||||
display.drawTextLeftAlign(0, y, "pos");
|
||||
@@ -738,9 +741,9 @@ public:
|
||||
auto p = &unread[head];
|
||||
p->timestamp = _rtc->getCurrentTime();
|
||||
if (path_count == 0xFF) {
|
||||
sprintf(p->origin, "(D) %s:", from_name);
|
||||
snprintf(p->origin, sizeof(p->origin), "(D) %s:", from_name);
|
||||
} else {
|
||||
sprintf(p->origin, "(%d) %s:", (uint32_t) path_count, from_name);
|
||||
snprintf(p->origin, sizeof(p->origin), "(%d) %s:", (uint32_t) path_count, from_name);
|
||||
}
|
||||
StrHelper::strncpy(p->msg, msg, sizeof(p->msg));
|
||||
}
|
||||
|
||||
@@ -155,9 +155,9 @@ void UITask::onMessageRecv(mesh::Packet *pkt, const ContactInfo &from, uint8_t t
|
||||
|
||||
uint8_t path_len = pkt->isRouteFlood() ? pkt->path_len : 0xFF;
|
||||
if (path_len == 0xFF) {
|
||||
sprintf(_origin, "(F) %s", from.name);
|
||||
snprintf(_origin, sizeof(_origin), "(F) %s", from.name);
|
||||
} else {
|
||||
sprintf(_origin, "(%d) %s", (uint32_t) path_len, from.name);
|
||||
snprintf(_origin, sizeof(_origin), "(%d) %s", (uint32_t) path_len, from.name);
|
||||
}
|
||||
StrHelper::strncpy(_msg, text, sizeof(_msg));
|
||||
|
||||
@@ -182,9 +182,9 @@ void UITask::onChannelMessageRecv(mesh::Packet *pkt, ChannelDetails& channel_det
|
||||
|
||||
uint8_t path_len = pkt->isRouteFlood() ? pkt->path_len : 0xFF;
|
||||
if (path_len == 0xFF) {
|
||||
sprintf(_origin, "(F) %s", channel_details.name);
|
||||
snprintf(_origin, sizeof(_origin), "(F) %s", channel_details.name);
|
||||
} else {
|
||||
sprintf(_origin, "(%d) %s", (uint32_t) path_len, channel_details.name);
|
||||
snprintf(_origin, sizeof(_origin), "(%d) %s", (uint32_t) path_len, channel_details.name);
|
||||
}
|
||||
StrHelper::strncpy(_msg, text, sizeof(_msg));
|
||||
|
||||
|
||||
@@ -159,7 +159,7 @@ public:
|
||||
auto p = &recent[recent_next_idx];
|
||||
recent_next_idx = (recent_next_idx + 1) % UI_RECENT_LIST_SIZE;
|
||||
|
||||
strcpy(p->name, contact.name);
|
||||
StrHelper::strncpy(p->name, contact.name, sizeof(p->name));
|
||||
p->recv_timestamp = _rtc->getCurrentTime();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "helpers/CliArgs.h"
|
||||
|
||||
using cli_args::parseFloat;
|
||||
using cli_args::parseInt;
|
||||
|
||||
TEST(CliArgsInt, AcceptsWholeNumbersInRange) {
|
||||
long v = 0;
|
||||
EXPECT_TRUE(parseInt("22", -9, 22, &v)); EXPECT_EQ(v, 22);
|
||||
EXPECT_TRUE(parseInt("-9", -9, 22, &v)); EXPECT_EQ(v, -9);
|
||||
EXPECT_TRUE(parseInt(" +5 ", -9, 22, &v)); EXPECT_EQ(v, 5);
|
||||
EXPECT_TRUE(parseInt("0", 0, 64, &v)); EXPECT_EQ(v, 0);
|
||||
}
|
||||
|
||||
TEST(CliArgsInt, RefusesOutOfRangeAndGarbage) {
|
||||
long v = 7;
|
||||
EXPECT_FALSE(parseInt("23", -9, 22, &v));
|
||||
EXPECT_FALSE(parseInt("-10", -9, 22, &v));
|
||||
EXPECT_FALSE(parseInt("300", 0, 64, &v)); // would be 44 in a uint8_t
|
||||
EXPECT_FALSE(parseInt("abc", 0, 64, &v)); // atoi() says 0
|
||||
EXPECT_FALSE(parseInt("", 0, 64, &v));
|
||||
EXPECT_FALSE(parseInt("12abc", 0, 64, &v));
|
||||
EXPECT_FALSE(parseInt("1.5", 0, 64, &v));
|
||||
EXPECT_FALSE(parseInt("-", 0, 64, &v));
|
||||
EXPECT_FALSE(parseInt(nullptr, 0, 64, &v));
|
||||
EXPECT_EQ(v, 7); // untouched on failure
|
||||
}
|
||||
|
||||
TEST(CliArgsFloat, AcceptsDecimalsInRange) {
|
||||
float f = 0;
|
||||
EXPECT_TRUE(parseFloat("869.432", 150, 2500, &f)); EXPECT_FLOAT_EQ(f, 869.432f);
|
||||
EXPECT_TRUE(parseFloat("-12.5", -90, 90, &f)); EXPECT_FLOAT_EQ(f, -12.5f);
|
||||
EXPECT_TRUE(parseFloat(".5", 0, 2, &f)); EXPECT_FLOAT_EQ(f, 0.5f);
|
||||
EXPECT_TRUE(parseFloat("2", 0, 2, &f)); EXPECT_FLOAT_EQ(f, 2.0f);
|
||||
EXPECT_TRUE(parseFloat("3. ", 0, 9, &f)); EXPECT_FLOAT_EQ(f, 3.0f);
|
||||
}
|
||||
|
||||
TEST(CliArgsFloat, RefusesNanInfExponentAndGarbage) {
|
||||
float f = 1;
|
||||
EXPECT_FALSE(parseFloat("nan", -1e9f, 1e9f, &f));
|
||||
EXPECT_FALSE(parseFloat("inf", -1e9f, 1e9f, &f));
|
||||
EXPECT_FALSE(parseFloat("1e3", 0, 1e9f, &f));
|
||||
EXPECT_FALSE(parseFloat("abc", 0, 2500, &f));
|
||||
EXPECT_FALSE(parseFloat("", 0, 2500, &f));
|
||||
EXPECT_FALSE(parseFloat(".", 0, 2500, &f));
|
||||
EXPECT_FALSE(parseFloat("869,4", 150, 2500, &f));
|
||||
EXPECT_FALSE(parseFloat("100", 150, 2500, &f));
|
||||
EXPECT_FALSE(parseFloat("91", -90, 90, &f));
|
||||
EXPECT_EQ(f, 1);
|
||||
}
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
+1
-1
@@ -73,7 +73,7 @@ How it works: [docs/ota.md](../docs/ota.md).
|
||||
| `mesh_sniffer.py` | passive sniffer: every frame the radio hears, decoded on the host |
|
||||
| `preset_trace.py` | TRACE along a fixed path on a chosen radio preset |
|
||||
| `fw_room_smoke.py` | smoke test of a firmware room server over the air |
|
||||
| `power_ab.py` | A/B current measurement with a UC96 meter (alternating cells) |
|
||||
| `power_ab.py` | A/B current measurement with a UC96 meter (alternating cells); `--ina <url>` uses a solar controller's live INA226 instead, without USB, and saves the raw samples |
|
||||
| `companion_backup.py` | back up a companion (contacts, channels, settings) before flashing, diff and restore after |
|
||||
| `gen_node_id.py` | a node identity whose path hash collides with no known repeater |
|
||||
|
||||
|
||||
+99
-7
@@ -36,6 +36,7 @@ polluted cell looks like a real regression.
|
||||
import argparse
|
||||
import glob
|
||||
import json
|
||||
import random
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
@@ -98,6 +99,73 @@ def cbprom_sample(url, meter, device):
|
||||
out.get("cb_meter_last_seen_timestamp_seconds", 0.0))
|
||||
|
||||
|
||||
_ina = {"t": None, "i": None, "mah": 0.0}
|
||||
|
||||
|
||||
def ina_sample(url):
|
||||
"""Live INA226 on a Chytra Budka, read from its own /sensors page.
|
||||
|
||||
No counter here: the box reports instantaneous current (0.25 mA steps on its
|
||||
10 mOhm shunt), so this integrates it (trapezoid) into a synthetic mAh
|
||||
counter and the rest of the tool fits it like the meter's staircase. Not via
|
||||
cbprom: its `cb_solar_*` series lags the live page by minutes (25. 11. 2026
|
||||
it held 3.26 V while /sensors read 4.98 V). The shunt offset (~0.3 mA) is in
|
||||
every cell alike, so it cancels in an A/B delta but not in the absolute mA.
|
||||
The box serves a self-signed cert on the LAN, hence no verification.
|
||||
"""
|
||||
import ssl
|
||||
ctx = ssl.create_default_context()
|
||||
ctx.check_hostname = False
|
||||
ctx.verify_mode = ssl.CERT_NONE
|
||||
# The box now and then serves the page without the INA rows (a bus read
|
||||
# that lost the race, 25. 11. 2026 on the first minute of a run): retry
|
||||
# those like a network error. Only a page that never shows them is fatal.
|
||||
v = i = None
|
||||
for _ in range(10):
|
||||
try:
|
||||
with urllib.request.urlopen(url, timeout=10, context=ctx) as r:
|
||||
body = r.read().decode()
|
||||
v = re.search(r"solar_v\s*=\s*([-\d.]+)", body)
|
||||
i = re.search(r"solar_i\s*=\s*([-\d.]+)", body)
|
||||
if v and i:
|
||||
break
|
||||
except OSError:
|
||||
pass
|
||||
time.sleep(1)
|
||||
if not (v and i):
|
||||
# An overnight run makes ~20 000 requests; one dead stretch of the box
|
||||
# must not throw the whole cell away. Before the first reading there is
|
||||
# nothing to hold, so that is still fatal; later, skip the gap: the next
|
||||
# good sample integrates across it, and the raw series shows the hole.
|
||||
if _ina["t"] is None:
|
||||
raise SystemExit(f"{url} neukazuje solar_v/solar_i -- INA226 nepritomen?")
|
||||
_ina["gaps"] = _ina.get("gaps", 0) + 1
|
||||
return _ina["mah"], _ina.get("v", 0.0), _ina["i"], _ina["t"]
|
||||
now, amps = time.time(), float(i.group(1))
|
||||
if _ina["t"] is not None:
|
||||
_ina["mah"] += (amps + _ina["i"]) / 2 * 1000.0 * (now - _ina["t"]) / 3600.0
|
||||
_ina["t"], _ina["i"], _ina["v"] = now, amps, float(v.group(1))
|
||||
# Raw (epoch, mA) for the run's JSON: the fit over an integral hides a bimodal
|
||||
# cell (11.5 <-> 14 mA flips) and cannot be lined up against other logs.
|
||||
_ina.setdefault("raw", []).append((round(now, 2), round(amps * 1000.0, 3)))
|
||||
return _ina["mah"], _ina["v"], amps, now
|
||||
|
||||
|
||||
def ina_stats():
|
||||
"""Mean/SD of the raw INA samples of the cell, plus the series itself.
|
||||
|
||||
Mean of samples is the honest estimator here: the fit's standard error over
|
||||
an integrated series is autocorrelated nonsense (it reads +-0.00)."""
|
||||
raw = _ina.get("raw") or []
|
||||
if not raw:
|
||||
return {}
|
||||
ma = [x[1] for x in raw]
|
||||
mean = sum(ma) / len(ma)
|
||||
sd = (sum((x - mean) ** 2 for x in ma) / max(1, len(ma) - 1)) ** 0.5
|
||||
return {"ina_mean_ma": round(mean, 3), "ina_sd_ma": round(sd, 3), "ina_n": len(ma),
|
||||
"ina_gaps": _ina.get("gaps", 0), "ina_raw": raw}
|
||||
|
||||
|
||||
def meter_sample(url, meter=None, device=None):
|
||||
"""One reading of the exporter: (capacity_mAh, volts, amps, unix_ts)."""
|
||||
if device:
|
||||
@@ -299,6 +367,9 @@ def main():
|
||||
ap.add_argument("--url", default=None, help=f"exporter (vychozi {EXPORTER}, s --budka {CBPROM})")
|
||||
ap.add_argument("--budka", metavar="DEVICE",
|
||||
help="merak cte Chytra Budka: id (napr. fbfe18), seznam id pres carku, nebo any = nejcerstvejsi ramec z kterekoli; data z cbprom, vyzaduje --meter")
|
||||
ap.add_argument("--ina", metavar="URL",
|
||||
help="misto meraku zivy INA226 Chytre Budky, napr. https://<budka>/sensors "
|
||||
"(proud se integruje, vzorkuj --poll 2)")
|
||||
ap.add_argument("--json", help="ulozit vysledek jako JSON")
|
||||
args = ap.parse_args()
|
||||
|
||||
@@ -309,8 +380,19 @@ def main():
|
||||
if args.url is None:
|
||||
args.url = CBPROM if args.budka else EXPORTER
|
||||
|
||||
# +-1 counter step over the window; through a budka the step is 10 mWh ~ 2 mAh
|
||||
err_ma = (2.0 if args.budka else 1.0) * 60.0 / args.minutes
|
||||
def sample_ina():
|
||||
return ina_sample(args.ina)
|
||||
|
||||
def sample_meter():
|
||||
return meter_sample(args.url, args.meter, args.budka)
|
||||
|
||||
sample = sample_ina if args.ina else sample_meter
|
||||
if args.ina:
|
||||
# no counter to quantise: one 0.25 mA LSB is the floor (offset cancels in A/B)
|
||||
err_ma = 0.25
|
||||
else:
|
||||
# +-1 counter step over the window; through a budka the step is 10 mWh ~ 2 mAh
|
||||
err_ma = (2.0 if args.budka else 1.0) * 60.0 / args.minutes
|
||||
print(f"okno {args.minutes:g} min => kvantizace merice je +-{err_ma:.2f} mA na bunku")
|
||||
if err_ma > 1.5:
|
||||
print(" POZOR: to je vic, nez kolik ceka vetsina uspor. Delsi --minutes, nebo "
|
||||
@@ -369,7 +451,9 @@ def main():
|
||||
"state": state, "tx_air_delta": None, "rx_air_delta": None,
|
||||
"samples": 0, "invalid": "neaplikovano"})
|
||||
continue
|
||||
cap0, v0, _, _ = meter_sample(args.url, args.meter, args.budka)
|
||||
_ina["raw"] = []
|
||||
_ina["gaps"] = 0
|
||||
cap0, v0, _, _ = sample()
|
||||
t0 = time.time()
|
||||
print(f" start: cap={cap0:.0f} mAh, U={v0:.2f} V, stav={state}")
|
||||
|
||||
@@ -380,8 +464,11 @@ def main():
|
||||
# exactly how a good run got killed two minutes before it finished.
|
||||
next_beat = t0 + 60
|
||||
while time.time() < deadline:
|
||||
time.sleep(min(args.poll, max(0.0, deadline - time.time())))
|
||||
cap, v1, i1, _ = meter_sample(args.url, args.meter, args.budka)
|
||||
# INA samples are snapshots: jitter the period so they cannot lock
|
||||
# onto a periodic load (BLE advertising, rxps cycle) and alias.
|
||||
period = args.poll * random.uniform(0.5, 1.5) if args.ina else args.poll
|
||||
time.sleep(min(period, max(0.0, deadline - time.time())))
|
||||
cap, v1, i1, _ = sample()
|
||||
now = time.time()
|
||||
series.append((now - t0, cap))
|
||||
if now >= next_beat:
|
||||
@@ -390,7 +477,7 @@ def main():
|
||||
print(f" ... {el:.0f}/{args.minutes:g} min, +{cap-cap0:.0f} mAh, "
|
||||
f"zatim {(cap-cap0)/((now-t0)/3600.0):.1f} mA", flush=True)
|
||||
|
||||
cap1, v1, i1, _ = meter_sample(args.url, args.meter, args.budka)
|
||||
cap1, v1, i1, _ = sample()
|
||||
series.append((time.time() - t0, cap1))
|
||||
dt_h = (time.time() - t0) / 3600.0
|
||||
tx1, rx1 = con.air() if con else (None, None)
|
||||
@@ -417,6 +504,10 @@ def main():
|
||||
print(f" ==> endpoint {avg:.2f} +-{err_ma:.2f} mA | fit {fit_ma:.2f} "
|
||||
f"+-{se_ma:.2f} mA (rezidua {resid:.2f} mAh) @ {v1:.2f} V "
|
||||
f"(instant {i1*1000:.0f} mA, 10mA krok)")
|
||||
st = ina_stats() if args.ina else {}
|
||||
if st:
|
||||
print(f" ==> INA prumer vzorku {st['ina_mean_ma']:.2f} mA, SD {st['ina_sd_ma']:.2f}, "
|
||||
f"n={st['ina_n']}, mezer {st['ina_gaps']}")
|
||||
if abs(fit_ma - avg) > err_ma:
|
||||
print(" POZOR: estimatory se rozchazi vic nez chyba -- bunka nebyla "
|
||||
"stacionarni, zopakuj ji")
|
||||
@@ -430,7 +521,8 @@ def main():
|
||||
"resid_mah": resid, "se_ma": se_ma, "delta_mah": dcap,
|
||||
"minutes": dt_h * 60, "err_ma": err_ma, "volts": v1,
|
||||
"state": state, "tx_air_delta": d_tx, "rx_air_delta": d_rx,
|
||||
"samples": len(series)})
|
||||
"samples": len(series), "t0": t0, "t1": time.time(),
|
||||
**ina_stats()})
|
||||
finally:
|
||||
if con:
|
||||
con.close()
|
||||
|
||||
@@ -28,6 +28,7 @@ build_flags = ${nrf52_base.build_flags}
|
||||
-D SX126X_DIO3_TCXO_VOLTAGE=1.8
|
||||
-D SX126X_CURRENT_LIMIT=140
|
||||
-D SX126X_RX_BOOSTED_GAIN=1
|
||||
-D SX126X_REGISTER_PATCH=1 ; Patch register 0x8B5 for improved RX
|
||||
-D PIN_VEXT_EN=26 ; Vext is connected to VDD which is also connected to TFT & GPS
|
||||
-D PIN_VEXT_EN_ACTIVE=HIGH
|
||||
-D PIN_GPS_RX=25
|
||||
|
||||
@@ -31,10 +31,9 @@ void SenseCapSolarBoard::begin() {
|
||||
|
||||
pinMode(BATTERY_PIN, INPUT);
|
||||
pinMode(VBAT_ENABLE, OUTPUT);
|
||||
digitalWrite(VBAT_ENABLE, LOW);
|
||||
digitalWrite(VBAT_ENABLE, HIGH);
|
||||
analogReadResolution(12);
|
||||
analogReference(AR_INTERNAL_3_0);
|
||||
delay(50);
|
||||
|
||||
#ifdef PIN_USER_BTN
|
||||
pinMode(PIN_USER_BTN, INPUT_PULLUP);
|
||||
|
||||
@@ -57,8 +57,12 @@ public:
|
||||
int adcvalue = 0;
|
||||
analogReadResolution(12);
|
||||
analogReference(AR_INTERNAL_3_0);
|
||||
delay(10);
|
||||
// CUSTOM (TeTeHacko): the divider is off (VBAT_ENABLE HIGH) between reads
|
||||
// since #27, so the ADC node starts high. 10 ms left ~+110..150 mV on the
|
||||
// reading (mast-three and second-mast, 26.-27. 11. 2026); 100 ms settles it.
|
||||
delay(100);
|
||||
adcvalue = analogRead(BATTERY_PIN);
|
||||
digitalWrite(VBAT_ENABLE, HIGH);
|
||||
return (adcvalue * ADC_MULTIPLIER * AREF_VOLTAGE) / 4.096;
|
||||
}
|
||||
|
||||
|
||||
@@ -130,6 +130,7 @@ build_flags =
|
||||
-D PIN_BUZZER=6
|
||||
-D AUTO_SHUTDOWN_MILLIVOLTS=3300
|
||||
-D ENABLE_USB_INTERFACE
|
||||
-D ENV_INCLUDE_GPS=1
|
||||
build_src_filter = ${ThinkNode_M1.build_src_filter}
|
||||
+<helpers/ui/GxEPDDisplay.cpp>
|
||||
+<helpers/ui/buzzer.cpp>
|
||||
|
||||
@@ -5,9 +5,28 @@
|
||||
|
||||
#include <Wire.h>
|
||||
|
||||
// A reset in the middle of an RTC read can leave the RTC holding SDA low,
|
||||
// and the RTC probe at boot then hangs forever. Up to nine clock pulses let
|
||||
// it finish its byte and release the bus.
|
||||
static void recoverI2cBus() {
|
||||
pinMode(PIN_WIRE_SDA, INPUT_PULLUP);
|
||||
pinMode(PIN_WIRE_SCL, INPUT_PULLUP);
|
||||
MESH_DEBUG_PRINTLN("I2C at boot: SDA=%d SCL=%d", digitalRead(PIN_WIRE_SDA), digitalRead(PIN_WIRE_SCL));
|
||||
pinMode(PIN_WIRE_SCL, OUTPUT);
|
||||
digitalWrite(PIN_WIRE_SCL, HIGH);
|
||||
for (int i = 0; i < 9 && digitalRead(PIN_WIRE_SDA) == LOW; i++) {
|
||||
digitalWrite(PIN_WIRE_SCL, LOW);
|
||||
delayMicroseconds(5);
|
||||
digitalWrite(PIN_WIRE_SCL, HIGH);
|
||||
delayMicroseconds(5);
|
||||
}
|
||||
pinMode(PIN_WIRE_SCL, INPUT_PULLUP);
|
||||
}
|
||||
|
||||
void ThinkNodeM6Board::begin() {
|
||||
NRF52Board::begin();
|
||||
|
||||
recoverI2cBus();
|
||||
Wire.begin();
|
||||
|
||||
#ifdef P_LORA_TX_LED
|
||||
|
||||
Reference in new issue
Block a user