Files
Thomas Göttgens 9fbc176e91 Extend userPrefs coverage to the whole channel table and the missing config fields (#11624)
* Extend userPrefs coverage to the whole channel table and the missing config fields

initDefaultChannel() handled only indices 0-2, so USERPREFS_CHANNELS_TO_WRITE above 3 produced live secondary channels carrying the public default PSK; it now covers all eight slots, with bin/platformio-custom.py completing every field of a configured index so indices 0-2 stay byte-identical. Adds USERPREFS_CHANNEL_<n>_IS_MUTED, USERPREFS_CONFIG_DEVICE_REBROADCAST_MODE, USERPREFS_CONFIG_DEVICE_NODE_INFO_BROADCAST_SECS, USERPREFS_CONFIG_LORA_CONFIG_OK_TO_MQTT, USERPREFS_CONFIG_SECURITY_IS_MANAGED and USERPREFS_CANNED_MESSAGES, applied after installRoleDefaults() and validated the way AdminModule validates a set-config. Adds test_userprefs_channels, covering the configured table under coverage-channel-table and the stock defaults under every other env.

* Address review: hex channel count, PSK width assert, canned-message termination

USERPREFS_CHANNELS_TO_WRITE now parses 0x-prefixed hex, matching the format
userPrefs.jsonc documents, without int(x, 0)'s rejection of a leading-zero
decimal such as "03". A static_assert rejects a USERPREFS_CHANNEL_<n>_PSK
literal wider than psk.bytes, which memcpy would otherwise write over the fields
after it. The USERPREFS_CANNED_MESSAGES copy keeps strncpy's zero-padding and
terminates explicitly, rather than shortening the length, which would have left
the last byte unwritten.
2026-08-27 15:00:59 +00:00

51 lines
2.9 KiB
C

// What bin/platformio-custom.py emits for a userPrefs.jsonc configuring five channels. -include'd
// rather than passed as -D flags, which would overrun the Windows command-line limit.
#pragma once
#define USERPREFS_CHANNELS_TO_WRITE 5
// Every field set, with is_muted and uplink on but downlink off, so a test can tell an applied
// value from a zeroed one.
#define USERPREFS_CHANNEL_0_PSK \
{ \
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 \
}
#define USERPREFS_CHANNEL_0_NAME "Ops"
#define USERPREFS_CHANNEL_0_PRECISION 14
#define USERPREFS_CHANNEL_0_IS_MUTED true
#define USERPREFS_CHANNEL_0_UPLINK_ENABLED true
#define USERPREFS_CHANNEL_0_DOWNLINK_ENABLED false
// Name longer than ChannelSettings.name (char[12]); the switch this table replaces used strcpy().
#define USERPREFS_CHANNEL_2_PSK \
{ \
1 \
}
#define USERPREFS_CHANNEL_2_NAME "LongerThanTwelve"
#define USERPREFS_CHANNEL_2_PRECISION 0
#define USERPREFS_CHANNEL_2_IS_MUTED false
#define USERPREFS_CHANNEL_2_UPLINK_ENABLED false
#define USERPREFS_CHANNEL_2_DOWNLINK_ENABLED false
// The index the old switch could not reach at all.
#define USERPREFS_CHANNEL_3_PSK \
{ \
16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 \
}
#define USERPREFS_CHANNEL_3_NAME "Three"
#define USERPREFS_CHANNEL_3_PRECISION 0
#define USERPREFS_CHANNEL_3_IS_MUTED false
#define USERPREFS_CHANNEL_3_UPLINK_ENABLED false
#define USERPREFS_CHANNEL_3_DOWNLINK_ENABLED false
#define USERPREFS_CHANNEL_4_PSK \
{ \
1 \
}
#define USERPREFS_CHANNEL_4_NAME "Four"
#define USERPREFS_CHANNEL_4_PRECISION 0
#define USERPREFS_CHANNEL_4_IS_MUTED false
#define USERPREFS_CHANNEL_4_UPLINK_ENABLED false
#define USERPREFS_CHANNEL_4_DOWNLINK_ENABLED false