Refactor LoRa airtime tests and add new functionality
- Updated LoRa airtime calculations in `lora_airtime_test.dart` to reflect new reference values. - Introduced new tests for LDRO behavior and preamble symbol calculations. - Added `contact_path_width_test.dart` to validate path hash width handling in contacts. - Enhanced `model_changes_test.dart` to ensure legacy data migration works correctly. - Created `remote_node_stats_test.dart` to decode and validate remote node statistics. - Implemented `map_marker_parse_test.dart` for parsing marker text with coordinate validation. - Developed `map_tile_cache_key_test.dart` to ensure API keys are excluded from cache keys. - Added `message_retry_failure_test.dart` to test message retry service behavior on failures. - Extended `path_history_service_test.dart` to preserve learned state across path attempts. - Enhanced `received_image_store_test.dart` to handle concurrent writes and review fixes. - Implemented `repeater_command_service_test.dart` to validate command response handling. - Created `store_tolerant_parsing_test.dart` to ensure stores skip malformed records gracefully. - Cleared untranslated JSON file for localization updates.
This commit is contained in:
1 parent
d5f54dfa11
commit
d74587c167
105 files changed
+6419
-2072
No files matched your search
@@ -2112,8 +2112,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
BottomSheetHeader(
|
||||
title: message.text.length > 40
|
||||
? '${message.text.substring(0, 40)}…'
|
||||
title: message.text.characters.length > 40
|
||||
? '${message.text.characters.take(40)}…'
|
||||
: message.text,
|
||||
subtitle: message.senderName.isNotEmpty
|
||||
? message.senderName
|
||||
@@ -2253,6 +2253,13 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
context.read<MeshCoreConnector>().clearMessagesForChannel(
|
||||
widget.channel.index,
|
||||
);
|
||||
try {
|
||||
await context.read<ReceivedImageStore>().deleteImagesForChannel(
|
||||
widget.channel.index,
|
||||
);
|
||||
} on ProviderNotFoundException {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import 'package:uuid/uuid.dart';
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../services/app_settings_service.dart';
|
||||
import '../services/received_image_store.dart';
|
||||
import '../services/ui_view_state_service.dart';
|
||||
import '../models/channel.dart';
|
||||
import '../models/community.dart';
|
||||
@@ -814,6 +815,13 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
connector.channels,
|
||||
connector.maxChannels,
|
||||
);
|
||||
if (nextIndex == null) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.channels_noFreeSlots),
|
||||
);
|
||||
return;
|
||||
}
|
||||
final hasPublicChannel = connector.channels.any((c) => c.isPublicChannel);
|
||||
int? selectedOption;
|
||||
final nameController = TextEditingController();
|
||||
@@ -1737,6 +1745,12 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
ChannelMessageStore channelMessageStore,
|
||||
Channel channel,
|
||||
) {
|
||||
ReceivedImageStore? imageStore;
|
||||
try {
|
||||
imageStore = context.read<ReceivedImageStore>();
|
||||
} on ProviderNotFoundException {
|
||||
imageStore = null;
|
||||
}
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
@@ -1756,6 +1770,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
await connector.deleteChannel(channel.index);
|
||||
|
||||
await channelMessageStore.clearChannelMessages(channel.index);
|
||||
await imageStore?.deleteImagesForChannel(channel.index);
|
||||
|
||||
if (!context.mounted) return;
|
||||
|
||||
@@ -1800,12 +1815,12 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
);
|
||||
}
|
||||
|
||||
int _findNextAvailableIndex(List<Channel> channels, int maxChannels) {
|
||||
int? _findNextAvailableIndex(List<Channel> channels, int maxChannels) {
|
||||
final usedIndices = channels.map((c) => c.index).toSet();
|
||||
for (int i = 0; i < maxChannels; i++) {
|
||||
if (!usedIndices.contains(i)) return i;
|
||||
}
|
||||
return 0;
|
||||
return null;
|
||||
}
|
||||
|
||||
void _showManageCommunitiesDialog(BuildContext context) {
|
||||
|
||||
@@ -557,6 +557,11 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
}
|
||||
return ByteCountedTextField(
|
||||
maxBytes: maxBytes,
|
||||
softLimitBytes:
|
||||
maxTextPayloadBytesAfterFullLengthAttempts,
|
||||
softLimitNote: context.l10n.chat_longMessageRetryNote(
|
||||
maxFullLengthTextAttempt + 1,
|
||||
),
|
||||
controller: _textController,
|
||||
focusNode: _textFieldFocusNode,
|
||||
hintText: context.l10n.chat_typeMessage,
|
||||
@@ -827,7 +832,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
final hopCount = _displayHopCount(
|
||||
contact.path,
|
||||
contact.pathLength,
|
||||
connector.pathHashByteWidth,
|
||||
contact.pathHashWidth,
|
||||
);
|
||||
return context.l10n.chat_hopsCount(hopCount);
|
||||
}
|
||||
@@ -1170,8 +1175,8 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
BottomSheetHeader(
|
||||
title: message.text.length > 40
|
||||
? '${message.text.substring(0, 40)}…'
|
||||
title: message.text.characters.length > 40
|
||||
? '${message.text.characters.take(40)}…'
|
||||
: message.text,
|
||||
),
|
||||
// Can't react to your own messages
|
||||
|
||||
@@ -46,8 +46,8 @@ class _CompanionRadioStatsScreenState extends State<CompanionRadioStatsScreen> {
|
||||
@override
|
||||
void dispose() {
|
||||
_connector?.radioStatsNotifier.removeListener(_onStatsUpdate);
|
||||
_connector?.releaseRadioStatsPolling();
|
||||
_connector?.setPollingInterval(30);
|
||||
_connector?.releaseRadioStatsPolling();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
||||
@@ -185,6 +185,14 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
}
|
||||
final hexString = pubKeyToHex(advertPacket);
|
||||
Clipboard.setData(ClipboardData(text: "meshcore://$hexString"));
|
||||
_pendingOperations.remove(ContactOperationType.export);
|
||||
if (mounted) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.contacts_contactAdvertCopied),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Generic OK/ERR acks carry no command correlation, so consume only
|
||||
|
||||
+32
-29
@@ -22,6 +22,7 @@ import '../services/path_history_service.dart';
|
||||
import '../services/map_marker_service.dart';
|
||||
import '../services/map_tile_cache_service.dart';
|
||||
import '../utils/contact_search.dart';
|
||||
import '../utils/disconnect_navigation_mixin.dart';
|
||||
import '../utils/battery_utils.dart';
|
||||
import '../utils/route_transitions.dart';
|
||||
import '../widgets/quick_switch_bar.dart';
|
||||
@@ -59,7 +60,8 @@ class MapScreen extends StatefulWidget {
|
||||
State<MapScreen> createState() => _MapScreenState();
|
||||
}
|
||||
|
||||
class _MapScreenState extends State<MapScreen> {
|
||||
class _MapScreenState extends State<MapScreen>
|
||||
with DisconnectNavigationMixin {
|
||||
// Zoom level at which node labels start to appear
|
||||
static const double _labelZoomThreshold = 14.0;
|
||||
// Below this zoom, nearby nodes collapse into clusters.
|
||||
@@ -345,6 +347,9 @@ class _MapScreenState extends State<MapScreen> {
|
||||
_MapConnectorSnapshot.fromConnector,
|
||||
);
|
||||
final connector = connectorSnapshot.connector;
|
||||
if (!checkConnectionAndNavigate(connector)) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
final settings = context.select<AppSettingsService, AppSettings>(
|
||||
(service) => service.settings,
|
||||
);
|
||||
@@ -428,20 +433,17 @@ class _MapScreenState extends State<MapScreen> {
|
||||
|
||||
// Compute guessed locations with caching
|
||||
final maxRangeKm = _estimateLoRaRangeKm(connector);
|
||||
final pathHashByteWidth = connector.pathHashByteWidth
|
||||
.clamp(1, 4)
|
||||
.toInt();
|
||||
final filteredKeys = guessCandidates
|
||||
.map((c) => '${c.publicKeyHex}:${c.path.join("-")}')
|
||||
.join(',');
|
||||
final anchorKeys = allContactsWithLocation
|
||||
.map(
|
||||
(c) =>
|
||||
'${c.publicKeyHex}:${c.latitude}:${c.longitude}:${PathHelper.formatHopHex(c.path.isNotEmpty ? c.path.sublist(max(0, c.path.length - pathHashByteWidth)) : const [])}',
|
||||
'${c.publicKeyHex}:${c.latitude}:${c.longitude}:${PathHelper.formatHopHex(c.path.isNotEmpty ? c.path.sublist(max(0, c.path.length - c.pathHashWidth)) : const [])}',
|
||||
)
|
||||
.join(',');
|
||||
final cacheKey =
|
||||
'$filteredKeys|$anchorKeys|$pathHistoryVersion:$pathHashByteWidth:${connector.currentFreqHz}:${connector.currentSf}:${connector.currentBwHz}:${connector.currentTxPower}:${settings.mapShowGuessedLocations}';
|
||||
'$filteredKeys|$anchorKeys|$pathHistoryVersion:${connector.currentFreqHz}:${connector.currentSf}:${connector.currentBwHz}:${connector.currentTxPower}:${settings.mapShowGuessedLocations}';
|
||||
if (cacheKey != _guessedLocationsCacheKey) {
|
||||
_guessedLocationsCacheKey = cacheKey;
|
||||
_cachedGuessedLocations = settings.mapShowGuessedLocations
|
||||
@@ -450,7 +452,6 @@ class _MapScreenState extends State<MapScreen> {
|
||||
allContactsWithLocation,
|
||||
pathHistory,
|
||||
maxRangeKm,
|
||||
pathHashByteWidth,
|
||||
)
|
||||
: [];
|
||||
}
|
||||
@@ -1012,18 +1013,19 @@ class _MapScreenState extends State<MapScreen> {
|
||||
List<Contact> withLocation,
|
||||
PathHistoryService pathHistory,
|
||||
double? maxRangeKm,
|
||||
int pathHashByteWidth,
|
||||
) {
|
||||
final result = <_GuessedLocation>[];
|
||||
final hopWidth = pathHashByteWidth.clamp(1, 4).toInt();
|
||||
// Paths keep the width they were learned with, so index every width.
|
||||
final anchorsByPrefix = <String, List<Contact>>{};
|
||||
for (final repeater in withLocation) {
|
||||
if (repeater.type != advTypeRepeater) continue;
|
||||
if (repeater.publicKey.length < hopWidth) continue;
|
||||
final prefix = PathHelper.formatHopHex(
|
||||
repeater.publicKey.sublist(0, hopWidth),
|
||||
);
|
||||
anchorsByPrefix.putIfAbsent(prefix, () => []).add(repeater);
|
||||
for (var width = 1; width <= 3; width++) {
|
||||
if (repeater.publicKey.length < width) continue;
|
||||
final prefix = PathHelper.formatHopHex(
|
||||
repeater.publicKey.sublist(0, width),
|
||||
);
|
||||
anchorsByPrefix.putIfAbsent(prefix, () => []).add(repeater);
|
||||
}
|
||||
}
|
||||
|
||||
for (final contact in allContacts) {
|
||||
@@ -1039,13 +1041,18 @@ class _MapScreenState extends State<MapScreen> {
|
||||
// Collect the contact-side (last-hop) repeater from every known path.
|
||||
// path = [device-side hop, ..., contact-side hop]
|
||||
// Only the last hop chunk is actually within radio range of the contact.
|
||||
final pathSets = <List<int>>[
|
||||
contact.path.toList(),
|
||||
final pathSets = <(List<int>, int)>[
|
||||
(contact.path.toList(), contact.pathHashWidth),
|
||||
...pathHistory
|
||||
.getRecentPaths(contact.publicKeyHex)
|
||||
.map((r) => r.pathBytes),
|
||||
.map(
|
||||
(r) => (
|
||||
r.pathBytes,
|
||||
Contact.inferPathHashWidth(r.hopCount, r.pathBytes.length),
|
||||
),
|
||||
),
|
||||
];
|
||||
for (final pathBytes in pathSets) {
|
||||
for (final (pathBytes, hopWidth) in pathSets) {
|
||||
if (pathBytes.isEmpty) continue;
|
||||
final lastHop = pathBytes.sublist(max(0, pathBytes.length - hopWidth));
|
||||
if (lastHop.isEmpty) continue;
|
||||
@@ -1081,22 +1088,16 @@ class _MapScreenState extends State<MapScreen> {
|
||||
continue; // discard implausible guesses near (0, 0)
|
||||
}
|
||||
} else {
|
||||
double lat = 0, lon = 0, weight = 1.0;
|
||||
int counted = 0;
|
||||
double lat = 0, lon = 0, weight = 1.0, totalWeight = 0;
|
||||
for (final a in anchors) {
|
||||
if (counted == 0) {
|
||||
lat = a.latitude;
|
||||
lon = a.longitude;
|
||||
} else {
|
||||
lat += a.latitude * weight;
|
||||
lon += a.longitude * weight;
|
||||
}
|
||||
lat += a.latitude * weight;
|
||||
lon += a.longitude * weight;
|
||||
totalWeight += weight;
|
||||
// weight subsequent anchors less to create a bias towards the first (if more than 2)
|
||||
weight = weight / 2;
|
||||
counted++;
|
||||
}
|
||||
position = _offsetGuessedPosition(
|
||||
LatLng(lat / anchors.length, lon / anchors.length),
|
||||
LatLng(lat / totalWeight, lon / totalWeight),
|
||||
contact,
|
||||
radiusMeters: anchors.length >= 3 ? 80 : 120,
|
||||
);
|
||||
@@ -3794,6 +3795,7 @@ int _mapContactSignature(Contact contact) {
|
||||
contact.flags,
|
||||
contact.pathLength,
|
||||
_bytesSignature(contact.path),
|
||||
contact.pathHashWidth,
|
||||
contact.pathOverride,
|
||||
_bytesSignature(contact.pathOverrideBytes),
|
||||
contact.latitude,
|
||||
@@ -4029,6 +4031,7 @@ MarkerPayload? parseMarkerText(String text) {
|
||||
final lat = double.tryParse(match.group(1) ?? '');
|
||||
final lon = double.tryParse(match.group(2) ?? '');
|
||||
if (lat == null || lon == null) return null;
|
||||
if (lat.abs() > 90 || lon.abs() > 180) return null;
|
||||
final label = (match.group(3) ?? '').trim();
|
||||
final flags = (match.group(4) ?? '').trim();
|
||||
return MarkerPayload(position: LatLng(lat, lon), label: label, flags: flags);
|
||||
|
||||
@@ -31,12 +31,16 @@ class NeighborsScreen extends StatefulWidget {
|
||||
|
||||
class _NeighborsScreenState extends State<NeighborsScreen> {
|
||||
static const int _reqNeighborsKeyLen = 4;
|
||||
// Firmware packs results into a 130-byte buffer (simple_repeater/MyMesh.cpp).
|
||||
static const int _reqNeighborsPageSize = 130 ~/ (_reqNeighborsKeyLen + 5);
|
||||
static const int _statusPayloadOffset = 8;
|
||||
static const int _statusStatsSize = 52;
|
||||
static const int _statusResponseBytes =
|
||||
_statusPayloadOffset + _statusStatsSize;
|
||||
Uint8List _tagData = Uint8List(4);
|
||||
bool _awaitingSent = false;
|
||||
int _neighborCount = 0;
|
||||
int _pageOffset = 0;
|
||||
|
||||
bool _isLoading = false;
|
||||
bool _isLoaded = false;
|
||||
@@ -82,12 +86,14 @@ class _NeighborsScreenState extends State<NeighborsScreen> {
|
||||
_frameSubscription = connector.receivedFrames.listen((frame) {
|
||||
if (frame.isEmpty) return;
|
||||
|
||||
if (frame[0] == respCodeSent) {
|
||||
if (frame[0] == respCodeSent && _awaitingSent && frame.length >= 6) {
|
||||
_awaitingSent = false;
|
||||
_tagData = frame.sublist(2, 6);
|
||||
}
|
||||
|
||||
// Check if it's a binary response
|
||||
if (frame[0] == pushCodeBinaryResponse &&
|
||||
frame.length >= 6 &&
|
||||
listEquals(frame.sublist(2, 6), _tagData)) {
|
||||
_handleNeighborsResponse(connector, frame.sublist(6));
|
||||
}
|
||||
@@ -148,7 +154,11 @@ class _NeighborsScreenState extends State<NeighborsScreen> {
|
||||
final contacts = connector.allContactsUnfiltered;
|
||||
try {
|
||||
final neighborCount = buffer.readUInt16LE();
|
||||
final parsedNeighbors = parseNeighborsData(buffer, buffer.readUInt16LE());
|
||||
final page = parseNeighborsData(buffer, buffer.readUInt16LE());
|
||||
final parsedNeighbors = [
|
||||
if (_pageOffset > 0) ...?_parsedNeighbors,
|
||||
...page,
|
||||
];
|
||||
contacts.where((c) => c.type == advTypeRepeater).forEach((repeater) {
|
||||
for (var neighborData in parsedNeighbors) {
|
||||
final publicKey = neighborData['publicKey'];
|
||||
@@ -166,13 +176,19 @@ class _NeighborsScreenState extends State<NeighborsScreen> {
|
||||
_neighborCount = neighborCount;
|
||||
});
|
||||
|
||||
_tagData = Uint8List(4);
|
||||
_statusTimeout?.cancel();
|
||||
_recordStatusResult(true);
|
||||
if (!mounted) return;
|
||||
if (page.isNotEmpty && parsedNeighbors.length < neighborCount) {
|
||||
_loadNeighbors(offset: parsedNeighbors.length);
|
||||
return;
|
||||
}
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.neighbors_receivedData),
|
||||
backgroundColor: Theme.of(context).colorScheme.tertiary,
|
||||
);
|
||||
_statusTimeout?.cancel();
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_isLoaded = true;
|
||||
@@ -183,9 +199,10 @@ class _NeighborsScreenState extends State<NeighborsScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadNeighbors() async {
|
||||
Future<void> _loadNeighbors({int offset = 0}) async {
|
||||
if (_commandService == null) return;
|
||||
|
||||
_pageOffset = offset;
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
_isLoaded = false;
|
||||
@@ -202,13 +219,14 @@ class _NeighborsScreenState extends State<NeighborsScreen> {
|
||||
payload: Uint8List.fromList([
|
||||
reqTypeGetNeighbors,
|
||||
0x00,
|
||||
0x0F,
|
||||
0x00,
|
||||
0x00,
|
||||
_reqNeighborsPageSize,
|
||||
offset & 0xFF,
|
||||
(offset >> 8) & 0xFF,
|
||||
0x00,
|
||||
_reqNeighborsKeyLen,
|
||||
]),
|
||||
);
|
||||
_awaitingSent = true;
|
||||
await connector.sendFrame(frame);
|
||||
|
||||
final pathLengthValue = selection.useFlood ? -1 : selection.hopCount;
|
||||
@@ -234,6 +252,7 @@ class _NeighborsScreenState extends State<NeighborsScreen> {
|
||||
_recordStatusResult(false);
|
||||
});
|
||||
} catch (e) {
|
||||
_awaitingSent = false;
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
|
||||
@@ -91,6 +91,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
Timer? _timeoutTimer;
|
||||
|
||||
bool _isLoading = false;
|
||||
bool _awaitingTraceSent = false;
|
||||
bool _failed2Loaded = false;
|
||||
bool _hasData = false;
|
||||
PathTraceData? _traceData;
|
||||
@@ -112,6 +113,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
// Live path resolved at trace time; used by the response handler for
|
||||
// endpoint inference so it matches the path that was actually traced.
|
||||
Uint8List _tracedPath = Uint8List(0);
|
||||
int _tracedPathHashWidth = 1;
|
||||
|
||||
// Packet-flow animation + multi-path view state.
|
||||
late final PathPlaybackController _playback;
|
||||
@@ -184,9 +186,13 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
Uint8List? _tracePathFromBytes(
|
||||
Uint8List pathBytes,
|
||||
int traceHashByteWidth,
|
||||
MeshCoreConnector connector,
|
||||
) {
|
||||
final hops = PathHelper.splitPathBytes(pathBytes, widget.pathHashByteWidth);
|
||||
MeshCoreConnector connector, {
|
||||
int? pathHashByteWidth,
|
||||
}) {
|
||||
final hops = PathHelper.splitPathBytes(
|
||||
pathBytes,
|
||||
pathHashByteWidth ?? widget.pathHashByteWidth,
|
||||
);
|
||||
final traceBytes = <int>[];
|
||||
for (final hop in hops) {
|
||||
final traceHop = _expandHopForTrace(hop, traceHashByteWidth, connector);
|
||||
@@ -316,11 +322,12 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
Uint8List? buildPath(
|
||||
Uint8List pathBytes,
|
||||
int traceHashByteWidth,
|
||||
MeshCoreConnector connector,
|
||||
) {
|
||||
MeshCoreConnector connector, {
|
||||
int? pathHashByteWidth,
|
||||
}) {
|
||||
final pathHops = PathHelper.splitPathBytes(
|
||||
pathBytes,
|
||||
widget.pathHashByteWidth,
|
||||
pathHashByteWidth ?? widget.pathHashByteWidth,
|
||||
);
|
||||
final hopWidth = traceHashByteWidth.clamp(1, pubKeySize).toInt();
|
||||
|
||||
@@ -375,17 +382,21 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
/// route (flipPathAround), re-read that contact's live forced/auto path from
|
||||
/// the connector so a path the user just changed (force flood / set path /
|
||||
/// reset to auto) is honored immediately, instead of the value captured when
|
||||
/// this screen was first pushed.
|
||||
Uint8List _resolveLivePath(MeshCoreConnector connector) {
|
||||
/// this screen was first pushed. Also returns the path's bytes per hop: the
|
||||
/// contact's learned width for its device path, the local mode otherwise.
|
||||
(Uint8List, int) _resolveLivePath(MeshCoreConnector connector) {
|
||||
final target = widget.targetContact;
|
||||
if (!widget.flipPathAround || target == null) {
|
||||
return widget.path;
|
||||
return (widget.path, widget.pathHashByteWidth);
|
||||
}
|
||||
final live = connector.allContactsUnfiltered.firstWhere(
|
||||
(c) => c.publicKeyHex == target.publicKeyHex,
|
||||
orElse: () => target,
|
||||
);
|
||||
return live.pathBytesForDisplay;
|
||||
final width = live.pathOverride == null && live.path.isNotEmpty
|
||||
? live.pathHashWidth
|
||||
: widget.pathHashByteWidth;
|
||||
return (live.pathBytesForDisplay, width);
|
||||
}
|
||||
|
||||
Future<void> _doPathTrace() async {
|
||||
@@ -398,17 +409,28 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
}
|
||||
|
||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
final traceHashByteWidth = _traceHashByteWidth(widget.pathHashByteWidth);
|
||||
final livePath = _resolveLivePath(connector);
|
||||
final (livePath, hopWidth) = _resolveLivePath(connector);
|
||||
final traceHashByteWidth = _traceHashByteWidth(hopWidth);
|
||||
_tracedPath = livePath;
|
||||
_tracedPathHashWidth = hopWidth;
|
||||
|
||||
final pathTmp = widget.reversePathAround
|
||||
? _reversePathByHop(livePath, widget.pathHashByteWidth)
|
||||
? _reversePathByHop(livePath, hopWidth)
|
||||
: livePath;
|
||||
|
||||
final path = widget.flipPathAround
|
||||
? buildPath(pathTmp, traceHashByteWidth, connector)
|
||||
: _tracePathFromBytes(pathTmp, traceHashByteWidth, connector);
|
||||
? buildPath(
|
||||
pathTmp,
|
||||
traceHashByteWidth,
|
||||
connector,
|
||||
pathHashByteWidth: hopWidth,
|
||||
)
|
||||
: _tracePathFromBytes(
|
||||
pathTmp,
|
||||
traceHashByteWidth,
|
||||
connector,
|
||||
pathHashByteWidth: hopWidth,
|
||||
);
|
||||
|
||||
if (path == null) {
|
||||
if (!mounted) return;
|
||||
@@ -442,6 +464,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
flags, // flag
|
||||
payload: tracePayload,
|
||||
);
|
||||
_awaitingTraceSent = true;
|
||||
connector.sendFrame(frame);
|
||||
}
|
||||
|
||||
@@ -455,7 +478,8 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
try {
|
||||
final code = frameBuffer.readUInt8();
|
||||
|
||||
if (code == respCodeSent) {
|
||||
if (code == respCodeSent && _awaitingTraceSent) {
|
||||
_awaitingTraceSent = false;
|
||||
frameBuffer.skipBytes(1); //reserved
|
||||
tagData = frameBuffer.readBytes(4);
|
||||
final timeoutMilliseconds = frameBuffer.readUInt32LE();
|
||||
@@ -474,7 +498,8 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
);
|
||||
}
|
||||
|
||||
if (code == respCodeErr) {
|
||||
if (code == respCodeErr && _awaitingTraceSent) {
|
||||
_awaitingTraceSent = false;
|
||||
_timeoutTimer?.cancel();
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
@@ -593,7 +618,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
c.hasLocation &&
|
||||
c.path.isNotEmpty &&
|
||||
_matchesHopPrefix(
|
||||
_lastHopChunk(c.path, widget.pathHashByteWidth),
|
||||
_lastHopChunk(c.path, c.pathHashWidth),
|
||||
hop,
|
||||
),
|
||||
)
|
||||
@@ -633,7 +658,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
// sits in the middle of the symmetric sequence; .last is the local side.
|
||||
final tracedHops = PathHelper.splitPathBytes(
|
||||
_tracedPath,
|
||||
widget.pathHashByteWidth,
|
||||
_tracedPathHashWidth,
|
||||
);
|
||||
final hopsForEndpoint = tracedHops.isNotEmpty
|
||||
? tracedHops
|
||||
@@ -649,7 +674,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
c.hasLocation &&
|
||||
c.path.isNotEmpty &&
|
||||
_matchesHopPrefix(
|
||||
_lastHopChunk(c.path, widget.pathHashByteWidth),
|
||||
_lastHopChunk(c.path, c.pathHashWidth),
|
||||
lastHop,
|
||||
),
|
||||
)
|
||||
@@ -795,7 +820,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
c.hasLocation &&
|
||||
c.path.isNotEmpty &&
|
||||
_matchesHopPrefix(
|
||||
_lastHopChunk(c.path, widget.pathHashByteWidth),
|
||||
_lastHopChunk(c.path, c.pathHashWidth),
|
||||
hop,
|
||||
),
|
||||
)
|
||||
@@ -837,7 +862,10 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen>
|
||||
if (record.pathBytes.isEmpty) continue;
|
||||
final recordHops = PathHelper.splitPathBytes(
|
||||
record.pathBytes,
|
||||
widget.pathHashByteWidth,
|
||||
Contact.inferPathHashWidth(
|
||||
record.hopCount,
|
||||
record.pathBytes.length,
|
||||
),
|
||||
);
|
||||
if (!seen.add(_pathKeyForHops(recordHops))) continue;
|
||||
if (altIndex >= kAlternatePathColors.length) break;
|
||||
|
||||
@@ -440,7 +440,12 @@ class _RegionManagementScreenState extends State<RegionManagementScreen> {
|
||||
await connector.clearContactPath(repeater);
|
||||
return;
|
||||
}
|
||||
await connector.setContactPath(repeater, originalPath, originalPathLength);
|
||||
await connector.setContactPath(
|
||||
repeater,
|
||||
originalPath,
|
||||
originalPathLength,
|
||||
pathHashWidth: repeater.pathHashWidth,
|
||||
);
|
||||
}
|
||||
|
||||
Set<Region> _parseRegionsResponse(Uint8List frame) {
|
||||
|
||||
@@ -34,6 +34,8 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
int _historyIndex = -1;
|
||||
StreamSubscription<Uint8List>? _frameSubscription;
|
||||
RepeaterCommandService? _commandService;
|
||||
bool _regionLoadActive = false;
|
||||
static final RegExp _regionLoadPattern = RegExp(r'^region +load( |$)');
|
||||
|
||||
late final List<Map<String, String>> _quickCommands = [
|
||||
{'labelKey': 'advertise', 'command': 'advert'},
|
||||
@@ -111,8 +113,13 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
}
|
||||
|
||||
void _sendCommand({bool showDebug = false}) async {
|
||||
if (_regionLoadActive) {
|
||||
_sendRegionLoadLine();
|
||||
return;
|
||||
}
|
||||
final command = _commandController.text.trim();
|
||||
if (command.isEmpty) return;
|
||||
final startsRegionLoad = _regionLoadPattern.hasMatch(command.toLowerCase());
|
||||
|
||||
setState(() {
|
||||
_commandHistory.add({
|
||||
@@ -121,6 +128,9 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
'timestamp': DateTime.now().toString(),
|
||||
});
|
||||
});
|
||||
_commandController.clear();
|
||||
_historyIndex = -1;
|
||||
_commandFocusNode.requestFocus();
|
||||
|
||||
if (showDebug && mounted) {
|
||||
final frame = buildSendCliCommandFrame(
|
||||
@@ -168,12 +178,79 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
// The reply to `region load` may be lost even though the repeater entered
|
||||
// load mode, so enter it regardless; a blank line always ends it safely.
|
||||
if (startsRegionLoad && mounted) {
|
||||
setState(() {
|
||||
_regionLoadActive = true;
|
||||
_commandHistory.add({
|
||||
'type': 'response',
|
||||
'text': context.l10n.repeater_cliRegionLoadActive,
|
||||
'timestamp': DateTime.now().toString(),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
_scrollToBottom();
|
||||
}
|
||||
|
||||
/// In `region load` mode lines go out verbatim: no `XX|` prefix and no
|
||||
/// trimming, since indentation encodes the parent. Region lines get no
|
||||
/// reply; a blank line commits the load and is answered with
|
||||
/// "OK - loaded N regions".
|
||||
Future<void> _sendRegionLoadLine() async {
|
||||
final line = _commandController.text;
|
||||
final isTerminator = line.trim().isEmpty;
|
||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
final repeater = _resolveRepeater(connector);
|
||||
setState(() {
|
||||
_commandHistory.add({
|
||||
'type': 'command',
|
||||
'text': isTerminator ? context.l10n.repeater_cliRegionLoadEnd : line,
|
||||
'timestamp': DateTime.now().toString(),
|
||||
});
|
||||
});
|
||||
_commandController.clear();
|
||||
_historyIndex = -1;
|
||||
_commandFocusNode.requestFocus();
|
||||
|
||||
String? response;
|
||||
var ended = false;
|
||||
try {
|
||||
if (isTerminator) {
|
||||
response = await _commandService!.sendCommand(
|
||||
repeater,
|
||||
'',
|
||||
retries: 1,
|
||||
raw: true,
|
||||
);
|
||||
ended = true;
|
||||
} else {
|
||||
await _commandService!.sendUnansweredLine(repeater, line);
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
response = context.l10n.repeater_cliCommandError(e.toString());
|
||||
}
|
||||
}
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
if (ended) _regionLoadActive = false;
|
||||
if (response != null) {
|
||||
_commandHistory.add({
|
||||
'type': 'response',
|
||||
'text': response,
|
||||
'timestamp': DateTime.now().toString(),
|
||||
});
|
||||
}
|
||||
});
|
||||
_scrollToBottom();
|
||||
}
|
||||
|
||||
void _scrollToBottom() {
|
||||
if (!mounted) return;
|
||||
Future.delayed(const Duration(milliseconds: 100), () {
|
||||
if (_scrollController.hasClients) {
|
||||
if (mounted && _scrollController.hasClients) {
|
||||
_scrollController.animateTo(
|
||||
_scrollController.position.maxScrollExtent,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
@@ -337,7 +414,9 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
backgroundColor: MeshPalette.blueBg,
|
||||
side: const BorderSide(color: MeshPalette.blueLine),
|
||||
visualDensity: VisualDensity.compact,
|
||||
onPressed: () => _useQuickCommand(cmd['command']!),
|
||||
onPressed: _regionLoadActive
|
||||
? null
|
||||
: () => _useQuickCommand(cmd['command']!),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
@@ -392,12 +471,14 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
color: MeshPalette.ink,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
hintText: context.l10n.repeater_enterCommandHint,
|
||||
hintText: _regionLoadActive
|
||||
? context.l10n.repeater_cliRegionLoadHint
|
||||
: context.l10n.repeater_enterCommandHint,
|
||||
hintStyle: MeshTheme.mono(
|
||||
fontSize: 13,
|
||||
color: MeshPalette.ink4,
|
||||
),
|
||||
prefixText: '> ',
|
||||
prefixText: _regionLoadActive ? '' : '> ',
|
||||
prefixStyle: MeshTheme.mono(
|
||||
fontSize: 13,
|
||||
color: MeshPalette.blue,
|
||||
@@ -609,22 +690,6 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
command: 'powersaving {on|off}',
|
||||
description: l10n.repeater_cliHelpPowersavingOnOff,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'erase',
|
||||
description: l10n.repeater_cliHelpErase,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'stats-packets',
|
||||
description: l10n.repeater_cliHelpStatsPackets,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'stats-radio',
|
||||
description: l10n.repeater_cliHelpStatsRadio,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'stats-core',
|
||||
description: l10n.repeater_cliHelpStatsCore,
|
||||
),
|
||||
];
|
||||
|
||||
final settingsCommands = [
|
||||
@@ -648,6 +713,14 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
command: 'set flood.max {max-hops}',
|
||||
description: l10n.repeater_cliHelpSetFloodMax,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set flood.max.unscoped {0-64}',
|
||||
description: l10n.repeater_cliHelpSetFloodMaxUnscoped,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set flood.max.advert {0-64}',
|
||||
description: l10n.repeater_cliHelpSetFloodMaxAdvert,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set int.thresh {db}',
|
||||
description: l10n.repeater_cliHelpSetIntThresh,
|
||||
@@ -700,26 +773,6 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
command: 'set direct.txdelay {factor}',
|
||||
description: l10n.repeater_cliHelpSetDirectTxDelay,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set bridge.enabled {on|off}',
|
||||
description: l10n.repeater_cliHelpSetBridgeEnabled,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set bridge.delay {0-10000}',
|
||||
description: l10n.repeater_cliHelpSetBridgeDelay,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set bridge.source {rx|tx}',
|
||||
description: l10n.repeater_cliHelpSetBridgeSource,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set bridge.baud {speed}',
|
||||
description: l10n.repeater_cliHelpSetBridgeBaud,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set bridge.secret {shared-secret}',
|
||||
description: l10n.repeater_cliHelpSetBridgeSecret,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set adc.multiplier {factor}',
|
||||
description: l10n.repeater_cliHelpSetAdcMultiplier,
|
||||
@@ -744,6 +797,14 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
command: 'set radio.rxgain {on|off}',
|
||||
description: l10n.repeater_cliHelpSetRadioRxGain,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set radio.fem.rxgain {on|off}',
|
||||
description: l10n.repeater_cliHelpSetRadioFemRxGain,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set radio.fem.txgain {on|off}',
|
||||
description: l10n.repeater_cliHelpSetRadioFemTxGain,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set owner.info {text}',
|
||||
description: l10n.repeater_cliHelpSetOwnerInfo,
|
||||
@@ -756,17 +817,57 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
command: 'set loop.detect {off|minimal|moderate|strict}',
|
||||
description: l10n.repeater_cliHelpSetLoopDetect,
|
||||
),
|
||||
];
|
||||
|
||||
final bridgeCommands = [
|
||||
_CommandHelpEntry(
|
||||
command: 'set freq {mhz}',
|
||||
description: l10n.repeater_cliHelpSetFreq,
|
||||
command: 'set bridge.enabled {on|off}',
|
||||
description: l10n.repeater_cliHelpSetBridgeEnabled,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set bridge.delay {0-10000}',
|
||||
description: l10n.repeater_cliHelpSetBridgeDelay,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set bridge.source {rx|tx}',
|
||||
description: l10n.repeater_cliHelpSetBridgeSource,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set bridge.baud {speed}',
|
||||
description: l10n.repeater_cliHelpSetBridgeBaud,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set bridge.secret {shared-secret}',
|
||||
description: l10n.repeater_cliHelpSetBridgeSecret,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'set bridge.channel {1-14}',
|
||||
description: l10n.repeater_cliHelpSetBridgeChannel,
|
||||
),
|
||||
];
|
||||
|
||||
final bridgeCommands = [
|
||||
_CommandHelpEntry(
|
||||
command: 'get bridge.enabled',
|
||||
description: l10n.repeater_cliHelpGetBridgeEnabled,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get bridge.delay',
|
||||
description: l10n.repeater_cliHelpGetBridgeDelay,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get bridge.source',
|
||||
description: l10n.repeater_cliHelpGetBridgeSource,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get bridge.baud',
|
||||
description: l10n.repeater_cliHelpGetBridgeBaud,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get bridge.channel',
|
||||
description: l10n.repeater_cliHelpGetBridgeChannel,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get bridge.secret',
|
||||
description: l10n.repeater_cliHelpGetBridgeSecret,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get bridge.type',
|
||||
description: l10n.repeater_cliHelpGetBridgeType,
|
||||
@@ -808,6 +909,10 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
command: 'region load',
|
||||
description: l10n.repeater_cliHelpRegionLoad,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'region def {name}[,{jump-prefix}] ...',
|
||||
description: l10n.repeater_cliHelpRegionDef,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'region get {* | name-prefix}',
|
||||
description: l10n.repeater_cliHelpRegionGet,
|
||||
@@ -871,10 +976,6 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
command: 'get public.key',
|
||||
description: l10n.repeater_cliHelpGetPublicKey,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get prv.key',
|
||||
description: l10n.repeater_cliHelpGetPrvKey,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get repeat',
|
||||
description: l10n.repeater_cliHelpGetRepeat,
|
||||
@@ -895,6 +996,14 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
command: 'get radio.rxgain',
|
||||
description: l10n.repeater_cliHelpGetRadioRxGain,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get radio.fem.rxgain',
|
||||
description: l10n.repeater_cliHelpGetRadioFemRxGain,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get radio.fem.txgain',
|
||||
description: l10n.repeater_cliHelpGetRadioFemTxGain,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get af',
|
||||
description: l10n.repeater_cliHelpGetAf,
|
||||
@@ -955,6 +1064,14 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
command: 'get flood.max',
|
||||
description: l10n.repeater_cliHelpGetFloodMax,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get flood.max.unscoped',
|
||||
description: l10n.repeater_cliHelpGetFloodMaxUnscoped,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get flood.max.advert',
|
||||
description: l10n.repeater_cliHelpGetFloodMaxAdvert,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get owner.info',
|
||||
description: l10n.repeater_cliHelpGetOwnerInfo,
|
||||
@@ -967,34 +1084,6 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
command: 'get loop.detect',
|
||||
description: l10n.repeater_cliHelpGetLoopDetect,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get acl',
|
||||
description: l10n.repeater_cliHelpGetAcl,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get bridge.enabled',
|
||||
description: l10n.repeater_cliHelpGetBridgeEnabled,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get bridge.delay',
|
||||
description: l10n.repeater_cliHelpGetBridgeDelay,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get bridge.source',
|
||||
description: l10n.repeater_cliHelpGetBridgeSource,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get bridge.baud',
|
||||
description: l10n.repeater_cliHelpGetBridgeBaud,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get bridge.channel',
|
||||
description: l10n.repeater_cliHelpGetBridgeChannel,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get bridge.secret',
|
||||
description: l10n.repeater_cliHelpGetBridgeSecret,
|
||||
),
|
||||
_CommandHelpEntry(
|
||||
command: 'get bootloader.ver',
|
||||
description: l10n.repeater_cliHelpGetBootloaderVer,
|
||||
@@ -1103,7 +1192,12 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
||||
const SizedBox(height: 16),
|
||||
_buildHelpSection(context, l10n.repeater_sensors, sensorCommands),
|
||||
const SizedBox(height: 16),
|
||||
_buildHelpSection(context, l10n.repeater_bridge, bridgeCommands),
|
||||
_buildHelpSection(
|
||||
context,
|
||||
l10n.repeater_bridge,
|
||||
bridgeCommands,
|
||||
note: l10n.repeater_bridgeNote,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildHelpSection(
|
||||
context,
|
||||
|
||||
@@ -218,23 +218,26 @@ class RepeaterHubScreen extends StatelessWidget {
|
||||
},
|
||||
),
|
||||
|
||||
_HubActionTile(
|
||||
index: 2,
|
||||
icon: Icons.group,
|
||||
title: l10n.repeater_neighbors,
|
||||
subtitle: l10n.repeater_neighborsSubtitle,
|
||||
accentColor: MeshPalette.signal,
|
||||
onTap: () {
|
||||
HapticFeedback.selectionClick();
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
NeighborsScreen(repeater: repeater, password: password),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
if (repeater.type != advTypeRoom)
|
||||
_HubActionTile(
|
||||
index: 2,
|
||||
icon: Icons.group,
|
||||
title: l10n.repeater_neighbors,
|
||||
subtitle: l10n.repeater_neighborsSubtitle,
|
||||
accentColor: MeshPalette.signal,
|
||||
onTap: () {
|
||||
HapticFeedback.selectionClick();
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => NeighborsScreen(
|
||||
repeater: repeater,
|
||||
password: password,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
if (isAdmin) ...[
|
||||
_HubActionTile(
|
||||
|
||||
@@ -7,6 +7,7 @@ import '../l10n/l10n.dart';
|
||||
import '../models/contact.dart';
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../connector/meshcore_protocol.dart';
|
||||
import '../helpers/utf8_length_limiter.dart';
|
||||
import '../services/repeater_command_service.dart';
|
||||
import '../services/storage_service.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
@@ -191,6 +192,13 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
];
|
||||
final List<int> _spreadingFactorOptions = [5, 6, 7, 8, 9, 10, 11, 12];
|
||||
final List<int> _codingRateOptions = [5, 6, 7, 8];
|
||||
static const int _minRepeaterTxPower = -9;
|
||||
static const int _maxRepeaterTxPower = 30;
|
||||
// CommonCLI.h: password[16], node_name[32], owner_info[120].
|
||||
static const int _maxPasswordBytes = 15;
|
||||
static const int _maxNameBytes = 31;
|
||||
static const int _maxOwnerInfoBytes = 119;
|
||||
static const int _maxAgcResetInterval = 255 * 4;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -287,7 +295,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
break;
|
||||
case 'tx':
|
||||
final dbm = int.tryParse(value.replaceAll(RegExp(r'[^0-9-]'), ''));
|
||||
if (dbm != null && dbm >= 1 && dbm <= 30) {
|
||||
if (dbm != null && dbm >= -128 && dbm <= 127) {
|
||||
_txPowerController.text = dbm.toString();
|
||||
}
|
||||
break;
|
||||
@@ -364,7 +372,9 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
break;
|
||||
case 'agc.reset.interval':
|
||||
final v = int.tryParse(value.trim());
|
||||
if (v != null && v >= 0) _agcResetInterval = v;
|
||||
if (v != null && v >= 0) {
|
||||
_agcResetInterval = v.clamp(0, _maxAgcResetInterval);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -388,10 +398,18 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
}
|
||||
}
|
||||
if (parts.length > 2) {
|
||||
_spreadingFactor = int.tryParse(parts[2].trim()) ?? _spreadingFactor;
|
||||
final sf = int.tryParse(parts[2].trim());
|
||||
if (sf != null && _spreadingFactorOptions.contains(sf)) {
|
||||
_spreadingFactor = sf;
|
||||
}
|
||||
}
|
||||
if (parts.length > 3) {
|
||||
_codingRate = int.tryParse(parts[3].trim()) ?? _codingRate;
|
||||
final cr = int.tryParse(parts[3].trim());
|
||||
// Some firmware reports CR as 1-4 instead of 5-8.
|
||||
final uiCr = cr != null && cr <= 4 ? cr + 4 : cr;
|
||||
if (uiCr != null && _codingRateOptions.contains(uiCr)) {
|
||||
_codingRate = uiCr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -734,11 +752,18 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
});
|
||||
|
||||
try {
|
||||
final l10n = context.l10n;
|
||||
// Each pending command remembers the dirty-field it came from (null for
|
||||
// password commands, which always re-send when text is present). On
|
||||
// failure we keep that field in `_dirtyFields` so the Save button stays
|
||||
// available and the user can retry.
|
||||
final pending = <({_SettingField? field, String command})>[];
|
||||
final failures = <String>[];
|
||||
final retainDirty = <_SettingField>{};
|
||||
void reject(_SettingField field, String message) {
|
||||
failures.add(message);
|
||||
retainDirty.add(field);
|
||||
}
|
||||
|
||||
if (_dirtyFields.contains(_SettingField.name) &&
|
||||
_nameController.text.isNotEmpty) {
|
||||
@@ -768,9 +793,24 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
_bandwidth != null &&
|
||||
_spreadingFactor != null &&
|
||||
_codingRate != null) {
|
||||
final freqText = _freqController.text.trim();
|
||||
if (double.tryParse(freqText) != null) {
|
||||
final bwKHz = _bandwidth! / 1000;
|
||||
final freqText = _normalizeDecimal(_freqController.text);
|
||||
final freq = double.tryParse(freqText);
|
||||
final bwKHz = _bandwidth! / 1000;
|
||||
if (freq == null || freq < 150 || freq > 2500) {
|
||||
reject(_SettingField.radio, l10n.repeater_frequencyInvalid);
|
||||
} else if (bwKHz < 7.8 || bwKHz > 500) {
|
||||
reject(_SettingField.radio, '${l10n.repeater_bandwidth}: $bwKHz');
|
||||
} else if (_spreadingFactor! < 5 || _spreadingFactor! > 12) {
|
||||
reject(
|
||||
_SettingField.radio,
|
||||
'${l10n.repeater_spreadingFactor}: $_spreadingFactor',
|
||||
);
|
||||
} else if (_codingRate! < 5 || _codingRate! > 8) {
|
||||
reject(
|
||||
_SettingField.radio,
|
||||
'${l10n.repeater_codingRate}: $_codingRate',
|
||||
);
|
||||
} else {
|
||||
pending.add((
|
||||
field: _SettingField.radio,
|
||||
command:
|
||||
@@ -782,26 +822,46 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
if (_dirtyFields.contains(_SettingField.txPower) &&
|
||||
_txPowerController.text.isNotEmpty) {
|
||||
final dbm = int.tryParse(_txPowerController.text.trim());
|
||||
if (dbm != null) {
|
||||
if (dbm == null ||
|
||||
dbm < _minRepeaterTxPower ||
|
||||
dbm > _maxRepeaterTxPower) {
|
||||
reject(
|
||||
_SettingField.txPower,
|
||||
'${l10n.repeater_txPower}: ${_txPowerController.text.trim()} '
|
||||
'($_minRepeaterTxPower-$_maxRepeaterTxPower dBm)',
|
||||
);
|
||||
} else {
|
||||
pending.add((field: _SettingField.txPower, command: 'set tx $dbm'));
|
||||
}
|
||||
}
|
||||
|
||||
if (_dirtyFields.contains(_SettingField.lat) &&
|
||||
_latController.text.isNotEmpty &&
|
||||
_isValidCoordinate(_latController.text, 90)) {
|
||||
pending.add((
|
||||
field: _SettingField.lat,
|
||||
command: 'set lat ${_latController.text}',
|
||||
));
|
||||
_latController.text.isNotEmpty) {
|
||||
if (_isValidCoordinate(_latController.text, 90)) {
|
||||
pending.add((
|
||||
field: _SettingField.lat,
|
||||
command: 'set lat ${_normalizeDecimal(_latController.text)}',
|
||||
));
|
||||
} else {
|
||||
reject(
|
||||
_SettingField.lat,
|
||||
'${l10n.repeater_latitude}: ${_latController.text.trim()}',
|
||||
);
|
||||
}
|
||||
}
|
||||
if (_dirtyFields.contains(_SettingField.lon) &&
|
||||
_lonController.text.isNotEmpty &&
|
||||
_isValidCoordinate(_lonController.text, 180)) {
|
||||
pending.add((
|
||||
field: _SettingField.lon,
|
||||
command: 'set lon ${_lonController.text}',
|
||||
));
|
||||
_lonController.text.isNotEmpty) {
|
||||
if (_isValidCoordinate(_lonController.text, 180)) {
|
||||
pending.add((
|
||||
field: _SettingField.lon,
|
||||
command: 'set lon ${_normalizeDecimal(_lonController.text)}',
|
||||
));
|
||||
} else {
|
||||
reject(
|
||||
_SettingField.lon,
|
||||
'${l10n.repeater_longitude}: ${_lonController.text.trim()}',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (_dirtyFields.contains(_SettingField.repeat)) {
|
||||
@@ -882,32 +942,50 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
}
|
||||
if (_dirtyFields.contains(_SettingField.txDelay) &&
|
||||
_txDelayController.text.isNotEmpty) {
|
||||
final v = double.tryParse(_txDelayController.text.trim());
|
||||
final v = double.tryParse(_normalizeDecimal(_txDelayController.text));
|
||||
if (v != null) {
|
||||
pending.add((
|
||||
field: _SettingField.txDelay,
|
||||
command: 'set txdelay $v',
|
||||
));
|
||||
} else {
|
||||
reject(
|
||||
_SettingField.txDelay,
|
||||
'${l10n.repeater_txDelay}: ${_txDelayController.text.trim()}',
|
||||
);
|
||||
}
|
||||
}
|
||||
if (_dirtyFields.contains(_SettingField.directTxDelay) &&
|
||||
_directTxDelayController.text.isNotEmpty) {
|
||||
final v = double.tryParse(_directTxDelayController.text.trim());
|
||||
final v = double.tryParse(
|
||||
_normalizeDecimal(_directTxDelayController.text),
|
||||
);
|
||||
if (v != null) {
|
||||
pending.add((
|
||||
field: _SettingField.directTxDelay,
|
||||
command: 'set direct.txdelay $v',
|
||||
));
|
||||
} else {
|
||||
reject(
|
||||
_SettingField.directTxDelay,
|
||||
'${l10n.repeater_directTxDelay}: '
|
||||
'${_directTxDelayController.text.trim()}',
|
||||
);
|
||||
}
|
||||
}
|
||||
if (_dirtyFields.contains(_SettingField.intThresh) &&
|
||||
_intThreshController.text.isNotEmpty) {
|
||||
final v = int.tryParse(_intThreshController.text.trim());
|
||||
if (v != null) {
|
||||
if (v != null && v >= 0 && v <= 255) {
|
||||
pending.add((
|
||||
field: _SettingField.intThresh,
|
||||
command: 'set int.thresh $v',
|
||||
));
|
||||
} else {
|
||||
reject(
|
||||
_SettingField.intThresh,
|
||||
'${l10n.repeater_intThresh}: ${_intThreshController.text.trim()}',
|
||||
);
|
||||
}
|
||||
}
|
||||
if (_dirtyFields.contains(_SettingField.agcResetInterval)) {
|
||||
@@ -917,8 +995,6 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
));
|
||||
}
|
||||
|
||||
final failures = <String>[];
|
||||
final retainDirty = <_SettingField>{};
|
||||
var passwordsFailed = false;
|
||||
var rebootNeeded = false;
|
||||
for (final entry in pending) {
|
||||
@@ -951,6 +1027,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
}
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
}
|
||||
if (!mounted) return;
|
||||
|
||||
// Only clear password fields if every password command succeeded —
|
||||
// otherwise the user keeps their typed value to retry.
|
||||
@@ -967,7 +1044,6 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
});
|
||||
|
||||
if (mounted) {
|
||||
final l10n = context.l10n;
|
||||
if (failures.isEmpty && rebootNeeded) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
@@ -990,11 +1066,10 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(
|
||||
@@ -1011,9 +1086,12 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
_flagHasChanges();
|
||||
}
|
||||
|
||||
static String _normalizeDecimal(String text) =>
|
||||
text.trim().replaceAll(',', '.');
|
||||
|
||||
static bool _isValidCoordinate(String text, double max) {
|
||||
if (text.trim().isEmpty) return true;
|
||||
final value = double.tryParse(text.trim());
|
||||
final value = double.tryParse(_normalizeDecimal(text));
|
||||
return value != null && value >= -max && value <= max;
|
||||
}
|
||||
|
||||
@@ -1157,6 +1235,9 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
labelText: l10n.repeater_repeaterName,
|
||||
helperText: l10n.repeater_repeaterNameHelper,
|
||||
),
|
||||
inputFormatters: const [
|
||||
Utf8LengthLimitingTextInputFormatter(_maxNameBytes),
|
||||
],
|
||||
onChanged: (_) => _markChanged(_SettingField.name),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
@@ -1167,6 +1248,9 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
helperText: l10n.repeater_adminPasswordHelper,
|
||||
),
|
||||
obscureText: true,
|
||||
inputFormatters: const [
|
||||
Utf8LengthLimitingTextInputFormatter(_maxPasswordBytes),
|
||||
],
|
||||
onChanged: (_) => _flagHasChanges(),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
@@ -1177,6 +1261,9 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
helperText: l10n.repeater_guestPasswordHelper,
|
||||
),
|
||||
obscureText: true,
|
||||
inputFormatters: const [
|
||||
Utf8LengthLimitingTextInputFormatter(_maxPasswordBytes),
|
||||
],
|
||||
onChanged: (_) => _flagHasChanges(),
|
||||
),
|
||||
],
|
||||
@@ -1213,7 +1300,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
controller: _freqController,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.repeater_frequencyMhz,
|
||||
helperText: l10n.repeater_frequencyHelper,
|
||||
helperText: l10n.repeater_frequencyRangeHelper,
|
||||
suffixText: 'MHz',
|
||||
),
|
||||
keyboardType: const TextInputType.numberWithOptions(
|
||||
@@ -1230,10 +1317,12 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
controller: _txPowerController,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.repeater_txPower,
|
||||
helperText: l10n.repeater_txPowerHelper,
|
||||
helperText: l10n.repeater_txPowerRangeHelper,
|
||||
suffixText: 'dBm',
|
||||
),
|
||||
keyboardType: TextInputType.number,
|
||||
keyboardType: const TextInputType.numberWithOptions(
|
||||
signed: true,
|
||||
),
|
||||
onChanged: (_) => _markChanged(_SettingField.txPower),
|
||||
),
|
||||
),
|
||||
@@ -1561,9 +1650,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
],
|
||||
),
|
||||
Slider(
|
||||
value: _advertInterval == 0
|
||||
? 60.toDouble()
|
||||
: _advertInterval.toDouble(),
|
||||
value: _advertInterval.clamp(60, 240).toDouble(),
|
||||
min: 60,
|
||||
max: 240,
|
||||
divisions: 18,
|
||||
@@ -1620,9 +1707,7 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
],
|
||||
),
|
||||
Slider(
|
||||
value: _floodAdvertInterval == 0
|
||||
? 3.toDouble()
|
||||
: _floodAdvertInterval.toDouble(),
|
||||
value: _floodAdvertInterval.clamp(3, 168).toDouble(),
|
||||
min: 3,
|
||||
max: 168,
|
||||
divisions: 165,
|
||||
@@ -1813,6 +1898,9 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
),
|
||||
maxLines: 4,
|
||||
minLines: 2,
|
||||
inputFormatters: const [
|
||||
Utf8LengthLimitingTextInputFormatter(_maxOwnerInfoBytes),
|
||||
],
|
||||
onChanged: (_) => _markChanged(_SettingField.ownerInfo),
|
||||
),
|
||||
),
|
||||
@@ -2017,10 +2105,10 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
||||
],
|
||||
),
|
||||
Slider(
|
||||
value: _agcResetInterval.toDouble(),
|
||||
value: _agcResetInterval.clamp(0, _maxAgcResetInterval).toDouble(),
|
||||
min: 0,
|
||||
max: 240,
|
||||
divisions: 60,
|
||||
max: _maxAgcResetInterval.toDouble(),
|
||||
divisions: _maxAgcResetInterval ~/ 4,
|
||||
label: '${_agcResetInterval}s',
|
||||
onChanged: (v) {
|
||||
setState(() {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../models/contact.dart';
|
||||
import '../models/path_selection.dart';
|
||||
import '../models/remote_node_stats.dart';
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../connector/meshcore_protocol.dart';
|
||||
import '../services/app_settings_service.dart';
|
||||
@@ -32,10 +32,7 @@ class RepeaterStatusScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
static const int _statusPayloadOffset = 8;
|
||||
static const int _statusStatsSize = 52;
|
||||
static const int _statusResponseBytes =
|
||||
_statusPayloadOffset + _statusStatsSize;
|
||||
static const int _statusResponseBytes = RemoteNodeStats.payloadOffset + 56;
|
||||
|
||||
bool _isLoading = false;
|
||||
StreamSubscription<Uint8List>? _frameSubscription;
|
||||
@@ -50,6 +47,9 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
int? _noiseFloor;
|
||||
int? _txAirSecs;
|
||||
int? _rxAirSecs;
|
||||
int? _recvErrors;
|
||||
int? _posted;
|
||||
int? _postPushes;
|
||||
int? _packetsSent;
|
||||
int? _packetsRecv;
|
||||
int? _floodTx;
|
||||
@@ -124,72 +124,39 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
if (frame.length < 8) return;
|
||||
final prefix = frame.sublist(2, 8);
|
||||
if (!_matchesRepeaterPrefix(prefix)) return;
|
||||
if (frame.length < _statusResponseBytes) return;
|
||||
|
||||
final data = ByteData.sublistView(
|
||||
frame,
|
||||
_statusPayloadOffset,
|
||||
_statusResponseBytes,
|
||||
);
|
||||
int offset = 0;
|
||||
|
||||
final batteryMv = data.getUint16(offset, Endian.little);
|
||||
offset += 2;
|
||||
final queueLen = data.getUint16(offset, Endian.little);
|
||||
offset += 2;
|
||||
final noiseFloor = data.getInt16(offset, Endian.little);
|
||||
offset += 2;
|
||||
final lastRssi = data.getInt16(offset, Endian.little);
|
||||
offset += 2;
|
||||
final packetsRecv = data.getUint32(offset, Endian.little);
|
||||
offset += 4;
|
||||
final packetsSent = data.getUint32(offset, Endian.little);
|
||||
offset += 4;
|
||||
final txAirSecs = data.getUint32(offset, Endian.little);
|
||||
offset += 4;
|
||||
final uptimeSecs = data.getUint32(offset, Endian.little);
|
||||
offset += 4;
|
||||
final floodTx = data.getUint32(offset, Endian.little);
|
||||
offset += 4;
|
||||
final directTx = data.getUint32(offset, Endian.little);
|
||||
offset += 4;
|
||||
final floodRx = data.getUint32(offset, Endian.little);
|
||||
offset += 4;
|
||||
final directRx = data.getUint32(offset, Endian.little);
|
||||
offset += 4;
|
||||
final errEvents = data.getUint16(offset, Endian.little);
|
||||
offset += 2;
|
||||
final lastSnrRaw = data.getInt16(offset, Endian.little);
|
||||
offset += 2;
|
||||
final directDups = data.getUint16(offset, Endian.little);
|
||||
offset += 2;
|
||||
final floodDups = data.getUint16(offset, Endian.little);
|
||||
offset += 2;
|
||||
final rxAirSecs = data.getUint32(offset, Endian.little);
|
||||
final stats = RemoteNodeStats.tryParse(frame, isRoom: _isRoom);
|
||||
if (stats == null) return;
|
||||
|
||||
_statusTimeout?.cancel();
|
||||
if (!mounted) return;
|
||||
final rxAirSecs = stats.rxAirSecs;
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_batteryMv = batteryMv;
|
||||
_queueLen = queueLen;
|
||||
_noiseFloor = noiseFloor;
|
||||
_lastRssi = lastRssi;
|
||||
_packetsRecv = packetsRecv;
|
||||
_packetsSent = packetsSent;
|
||||
_txAirSecs = txAirSecs;
|
||||
_batteryMv = stats.batteryMv;
|
||||
_queueLen = stats.queueLen;
|
||||
_noiseFloor = stats.noiseFloor;
|
||||
_lastRssi = stats.lastRssi;
|
||||
_packetsRecv = stats.packetsRecv;
|
||||
_packetsSent = stats.packetsSent;
|
||||
_txAirSecs = stats.txAirSecs;
|
||||
_rxAirSecs = rxAirSecs;
|
||||
_uptimeSecs = uptimeSecs;
|
||||
_floodTx = floodTx;
|
||||
_directTx = directTx;
|
||||
_floodRx = floodRx;
|
||||
_directRx = directRx;
|
||||
_debugFlags = errEvents;
|
||||
_lastSnr = lastSnrRaw / 4.0;
|
||||
_dupDirect = directDups;
|
||||
_dupFlood = floodDups;
|
||||
_chanUtil = ((txAirSecs + rxAirSecs) / uptimeSecs) * 100;
|
||||
_recvErrors = stats.recvErrors;
|
||||
_posted = stats.posted;
|
||||
_postPushes = stats.postPushes;
|
||||
_uptimeSecs = stats.uptimeSecs;
|
||||
_floodTx = stats.floodTx;
|
||||
_directTx = stats.directTx;
|
||||
_floodRx = stats.floodRx;
|
||||
_directRx = stats.directRx;
|
||||
_debugFlags = stats.errEvents;
|
||||
_lastSnr = stats.lastSnr;
|
||||
_dupDirect = stats.directDups;
|
||||
_dupFlood = stats.floodDups;
|
||||
_chanUtil = rxAirSecs != null && stats.uptimeSecs > 0
|
||||
? ((stats.txAirSecs + rxAirSecs) / stats.uptimeSecs) * 100
|
||||
: null;
|
||||
});
|
||||
final batteryMv = stats.batteryMv;
|
||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
connector.updateRepeaterBatterySnapshot(
|
||||
widget.repeater.publicKeyHex,
|
||||
@@ -199,6 +166,8 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
_recordStatusResult(true);
|
||||
}
|
||||
|
||||
bool get _isRoom => widget.repeater.type == advTypeRoom;
|
||||
|
||||
bool _matchesRepeaterPrefix(Uint8List prefix) {
|
||||
final target = widget.repeater.publicKey;
|
||||
if (target.length < 6 || prefix.length < 6) return false;
|
||||
@@ -266,6 +235,9 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
_noiseFloor = null;
|
||||
_txAirSecs = null;
|
||||
_rxAirSecs = null;
|
||||
_recvErrors = null;
|
||||
_posted = null;
|
||||
_postPushes = null;
|
||||
_packetsSent = null;
|
||||
_packetsRecv = null;
|
||||
_floodTx = null;
|
||||
@@ -551,12 +523,13 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
value: _formatDuration(_txAirSecs),
|
||||
color: MeshPalette.warn,
|
||||
),
|
||||
_StatItem(
|
||||
icon: Icons.download,
|
||||
label: l10n.repeater_rxAirtime,
|
||||
value: _formatDuration(_rxAirSecs),
|
||||
color: MeshPalette.signal,
|
||||
),
|
||||
if (!_isRoom)
|
||||
_StatItem(
|
||||
icon: Icons.download,
|
||||
label: l10n.repeater_rxAirtime,
|
||||
value: _formatDuration(_rxAirSecs),
|
||||
color: MeshPalette.signal,
|
||||
),
|
||||
]),
|
||||
),
|
||||
|
||||
@@ -583,16 +556,39 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
||||
value: _duplicateText(),
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
_StatItem(
|
||||
icon: Icons.percent,
|
||||
label: l10n.repeater_chanUtil,
|
||||
value: _chanUtilText(),
|
||||
color: _chanUtil != null && _chanUtil! > 80
|
||||
? MeshPalette.alert
|
||||
: _chanUtil != null && _chanUtil! > 50
|
||||
? MeshPalette.warn
|
||||
: MeshPalette.signal,
|
||||
),
|
||||
if (_isRoom) ...[
|
||||
_StatItem(
|
||||
icon: Icons.forum_outlined,
|
||||
label: l10n.room_postsStored,
|
||||
value: _formatValue(_posted),
|
||||
color: MeshPalette.blue,
|
||||
),
|
||||
_StatItem(
|
||||
icon: Icons.outbox,
|
||||
label: l10n.room_postsPushed,
|
||||
value: _formatValue(_postPushes),
|
||||
color: MeshPalette.signal,
|
||||
),
|
||||
] else
|
||||
_StatItem(
|
||||
icon: Icons.error_outline,
|
||||
label: l10n.repeater_recvErrors,
|
||||
value: _formatValue(_recvErrors),
|
||||
color: _recvErrors != null && _recvErrors! > 0
|
||||
? MeshPalette.warn
|
||||
: scheme.onSurfaceVariant,
|
||||
),
|
||||
if (!_isRoom)
|
||||
_StatItem(
|
||||
icon: Icons.percent,
|
||||
label: l10n.repeater_chanUtil,
|
||||
value: _chanUtilText(),
|
||||
color: _chanUtil != null && _chanUtil! > 80
|
||||
? MeshPalette.alert
|
||||
: _chanUtil != null && _chanUtil! > 50
|
||||
? MeshPalette.warn
|
||||
: MeshPalette.signal,
|
||||
),
|
||||
]),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
@@ -29,15 +29,24 @@ int _toUiCodingRate(int deviceCr) {
|
||||
return deviceCr <= 4 ? deviceCr + 4 : deviceCr;
|
||||
}
|
||||
|
||||
/// Convert UI coding-rate value (5-8) back to firmware encoding.
|
||||
/// Uses the current device CR to detect which encoding the firmware expects.
|
||||
int _toDeviceCodingRate(int uiCr, int? deviceCr) {
|
||||
if (deviceCr != null && deviceCr <= 4) {
|
||||
return uiCr - 4;
|
||||
const Set<int> _defaultRepeatFreqsKHz = {433000, 869495, 918000};
|
||||
|
||||
/// Whether the firmware accepts [freqKHz] for off-grid client repeat, using
|
||||
/// the ranges from CMD_GET_ALLOWED_REPEAT_FREQ when known.
|
||||
bool _isAllowedRepeatFreqKHz(MeshCoreConnector connector, int freqKHz) {
|
||||
final ranges = connector.allowedRepeatFreqRanges;
|
||||
if (ranges == null || ranges.isEmpty) {
|
||||
return _defaultRepeatFreqsKHz.contains(freqKHz);
|
||||
}
|
||||
return uiCr;
|
||||
return ranges.any((r) => freqKHz >= r.lowKHz && freqKHz <= r.highKHz);
|
||||
}
|
||||
|
||||
/// Companion firmware version that added CMD_SET_PATH_HASH_MODE (v1.14.0).
|
||||
const int _minFirmwareVerCodeForPathHashMode = 10;
|
||||
|
||||
/// Lowest TX power companion firmware accepts (CMD_SET_RADIO_TX_POWER).
|
||||
const int _minTxPowerDbm = -9;
|
||||
|
||||
class SettingsScreen extends StatefulWidget {
|
||||
const SettingsScreen({super.key});
|
||||
|
||||
@@ -510,7 +519,10 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
icon: Icons.route_outlined,
|
||||
title: l10n.repeater_pathHashMode,
|
||||
subtitle: _pathHashModeSubtitle(context, connector.pathHashByteWidth),
|
||||
onTap: connector.isConnected
|
||||
onTap:
|
||||
connector.isConnected &&
|
||||
(connector.firmwareVerCode ?? 0) >=
|
||||
_minFirmwareVerCodeForPathHashMode
|
||||
? () => _editPathHashMode(context, connector)
|
||||
: null,
|
||||
),
|
||||
@@ -818,12 +830,12 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
|
||||
void _editPathHashMode(BuildContext context, MeshCoreConnector connector) {
|
||||
final l10n = context.l10n;
|
||||
var selectedMode = (connector.pathHashByteWidth - 1).clamp(0, 3).toInt();
|
||||
var selectedMode = (connector.pathHashByteWidth - 1).clamp(0, 2).toInt();
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) => StatefulBuilder(
|
||||
builder: (context, setDialogState) => AlertDialog(
|
||||
builder: (builderContext, setDialogState) => AlertDialog(
|
||||
title: Text(l10n.repeater_pathHashMode),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -848,10 +860,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
value: 2,
|
||||
child: Text(l10n.repeater_pathHashModeOption2),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: 3,
|
||||
child: Text(l10n.repeater_pathHashModeOption3),
|
||||
),
|
||||
],
|
||||
onChanged: (value) {
|
||||
if (value == null) return;
|
||||
@@ -861,7 +869,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
l10n.repeater_pathHashModeHelper,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
style: Theme.of(builderContext).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -921,7 +929,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) => StatefulBuilder(
|
||||
builder: (context, setDialogState) => AlertDialog(
|
||||
builder: (builderContext, setDialogState) => AlertDialog(
|
||||
title: Text(l10n.settings_location),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -987,7 +995,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
child: Text(l10n.common_cancel),
|
||||
),
|
||||
TextButton(
|
||||
@@ -1008,7 +1016,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(dialogContext);
|
||||
|
||||
if (interval != null) {
|
||||
await settingsService.setGpsIntervalSeconds(
|
||||
@@ -1340,7 +1348,7 @@ void _privacySettings(BuildContext context, MeshCoreConnector connector) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) => StatefulBuilder(
|
||||
builder: (context, setDialogState) => AlertDialog(
|
||||
builder: (builderContext, setDialogState) => AlertDialog(
|
||||
title: Text(l10n.settings_privacy),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
@@ -1427,12 +1435,12 @@ void _privacySettings(BuildContext context, MeshCoreConnector connector) {
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
child: Text(l10n.common_cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(dialogContext);
|
||||
await connector.setTelemetryModeBase(
|
||||
telemetryMode,
|
||||
telemetryLocMode,
|
||||
@@ -1610,9 +1618,15 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
||||
}
|
||||
|
||||
double _offGridFrequencyForBaseFrequency(double baseFrequencyMHz) {
|
||||
if (baseFrequencyMHz < 500) return 433.0;
|
||||
if (baseFrequencyMHz < 900) return 869.0;
|
||||
return 918.0;
|
||||
final baseKHz = (baseFrequencyMHz * 1000).round();
|
||||
final ranges = widget.connector.allowedRepeatFreqRanges;
|
||||
final candidates = ranges == null || ranges.isEmpty
|
||||
? _defaultRepeatFreqsKHz
|
||||
: {for (final r in ranges) baseKHz.clamp(r.lowKHz, r.highKHz)};
|
||||
final closestKHz = candidates.reduce(
|
||||
(a, b) => (a - baseKHz).abs() <= (b - baseKHz).abs() ? a : b,
|
||||
);
|
||||
return closestKHz / 1000.0;
|
||||
}
|
||||
|
||||
double _normalFrequencyForBand(double frequencyMHz) {
|
||||
@@ -1753,14 +1767,15 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
||||
void _validateFields() {
|
||||
final l10n = context.l10n;
|
||||
final freqMHz = double.tryParse(_frequencyController.text);
|
||||
_frequencyError = (freqMHz == null || freqMHz < 300 || freqMHz > 2500)
|
||||
_frequencyError = (freqMHz == null || freqMHz < 150 || freqMHz > 2500)
|
||||
? l10n.settings_frequencyInvalid
|
||||
: null;
|
||||
|
||||
final maxTxPower = widget.connector.maxTxPower ?? 22;
|
||||
final txPower = int.tryParse(_txPowerController.text);
|
||||
_txPowerError = (txPower == null || txPower < 0 || txPower > maxTxPower)
|
||||
? '${l10n.settings_txPowerInvalid} (0-$maxTxPower dBm)'
|
||||
_txPowerError =
|
||||
(txPower == null || txPower < _minTxPowerDbm || txPower > maxTxPower)
|
||||
? '${l10n.settings_txPowerInvalid} ($_minTxPowerDbm-$maxTxPower dBm)'
|
||||
: null;
|
||||
}
|
||||
|
||||
@@ -1797,7 +1812,7 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
||||
final freqMHz = double.tryParse(_frequencyController.text);
|
||||
final txPower = int.tryParse(_txPowerController.text);
|
||||
|
||||
if (freqMHz == null || freqMHz < 300 || freqMHz > 2500) {
|
||||
if (freqMHz == null || freqMHz < 150 || freqMHz > 2500) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_frequencyInvalid),
|
||||
@@ -1806,10 +1821,12 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
||||
}
|
||||
|
||||
final maxTxPower = widget.connector.maxTxPower ?? 22;
|
||||
if (txPower == null || txPower < 0 || txPower > maxTxPower) {
|
||||
if (txPower == null || txPower < _minTxPowerDbm || txPower > maxTxPower) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text('${l10n.settings_txPowerInvalid} (0-$maxTxPower dBm)'),
|
||||
content: Text(
|
||||
'${l10n.settings_txPowerInvalid} ($_minTxPowerDbm-$maxTxPower dBm)',
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -1817,18 +1834,14 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
||||
final freqHz = (freqMHz * 1000).round();
|
||||
final bwHz = _bandwidth.hz;
|
||||
final sf = _spreadingFactor.value;
|
||||
final cr = _toDeviceCodingRate(
|
||||
_codingRate.value,
|
||||
widget.connector.currentCr,
|
||||
);
|
||||
final cr = _codingRate.value;
|
||||
|
||||
// if the client repeat isnt null then we know its supported
|
||||
//otherwise we leave it out of the frame to avoid accidentally enabling
|
||||
final knownRepeat = widget.connector.clientRepeat != null;
|
||||
|
||||
if (knownRepeat) {
|
||||
const validRepeatFreqsKHz = {433000, 869000, 918000};
|
||||
if (_clientRepeat && !validRepeatFreqsKHz.contains(freqHz)) {
|
||||
if (_clientRepeat && !_isAllowedRepeatFreqKHz(widget.connector, freqHz)) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_clientRepeatFreqWarning),
|
||||
@@ -1839,23 +1852,53 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
||||
|
||||
try {
|
||||
_logRadioSettingsState('Saving radio settings');
|
||||
await widget.connector.sendFrame(
|
||||
buildSetRadioParamsFrame(
|
||||
freqHz,
|
||||
bwHz,
|
||||
sf,
|
||||
cr,
|
||||
final accepted = await widget.connector.setRadioParams(
|
||||
freqHz,
|
||||
bwHz,
|
||||
sf,
|
||||
cr,
|
||||
clientRepeat: knownRepeat ? _clientRepeat : null,
|
||||
);
|
||||
if (!accepted) {
|
||||
_logRadioSettingsState('Radio rejected requested settings');
|
||||
if (!mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_radioSettingsNotApplied),
|
||||
);
|
||||
return;
|
||||
}
|
||||
await widget.connector.sendFrame(buildSetRadioTxPowerFrame(txPower));
|
||||
final selfInfo = widget.connector.receivedFrames
|
||||
.firstWhere((f) => f.isNotEmpty && f[0] == respCodeSelfInfo)
|
||||
.timeout(const Duration(seconds: 5));
|
||||
await widget.connector.refreshDeviceInfo();
|
||||
final applied = await selfInfo.then(
|
||||
(_) => _deviceMatches(
|
||||
freqHz: freqHz,
|
||||
bwHz: bwHz,
|
||||
sf: sf,
|
||||
cr: cr,
|
||||
txPower: txPower,
|
||||
clientRepeat: knownRepeat ? _clientRepeat : null,
|
||||
),
|
||||
onError: (_) => true,
|
||||
);
|
||||
await widget.connector.sendFrame(buildSetRadioTxPowerFrame(txPower));
|
||||
await widget.connector.refreshDeviceInfo();
|
||||
if (!applied) {
|
||||
_logRadioSettingsState('Radio did not apply requested settings');
|
||||
if (!mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_radioSettingsNotApplied),
|
||||
);
|
||||
return;
|
||||
}
|
||||
final rememberedSnapshot = _clientRepeat
|
||||
? _lastNonRepeatSnapshot
|
||||
: _currentSnapshot();
|
||||
if (rememberedSnapshot != null) {
|
||||
widget.connector.rememberNonRepeatRadioState(
|
||||
rememberedSnapshot.toMeshCoreSnapshot(widget.connector.currentCr),
|
||||
rememberedSnapshot.toMeshCoreSnapshot(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1877,6 +1920,27 @@ class _RadioSettingsDialogState extends State<_RadioSettingsDialog> {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
|
||||
bool _deviceMatches({
|
||||
required int freqHz,
|
||||
required int bwHz,
|
||||
required int sf,
|
||||
required int cr,
|
||||
required int txPower,
|
||||
required bool? clientRepeat,
|
||||
}) {
|
||||
final c = widget.connector;
|
||||
// Firmware stores freq/bw as float MHz/kHz, so allow 1 unit of rounding.
|
||||
return c.currentFreqHz != null &&
|
||||
(c.currentFreqHz! - freqHz).abs() <= 1 &&
|
||||
c.currentBwHz != null &&
|
||||
(c.currentBwHz! - bwHz).abs() <= 1 &&
|
||||
c.currentSf == sf &&
|
||||
c.currentCr != null &&
|
||||
_toUiCodingRate(c.currentCr!) == cr &&
|
||||
c.currentTxPower == txPower &&
|
||||
(clientRepeat == null || c.clientRepeat == clientRepeat);
|
||||
}
|
||||
|
||||
String _presetLabel(int? index) {
|
||||
if (index == null) {
|
||||
return 'custom';
|
||||
@@ -2108,12 +2172,12 @@ class _RadioSettingsSnapshot {
|
||||
}
|
||||
|
||||
/// Convert back to the connector's raw-int snapshot.
|
||||
MeshCoreRadioStateSnapshot toMeshCoreSnapshot(int? deviceCr) {
|
||||
MeshCoreRadioStateSnapshot toMeshCoreSnapshot() {
|
||||
return MeshCoreRadioStateSnapshot(
|
||||
freqHz: frequencyHz,
|
||||
bwHz: bandwidth.hz,
|
||||
sf: spreadingFactor.value,
|
||||
cr: _toDeviceCodingRate(codingRate.value, deviceCr),
|
||||
cr: codingRate.value,
|
||||
txPowerDbm: txPowerDbm,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
||||
static const int _autoRefreshMaxQuantity = 10;
|
||||
|
||||
int _tagData = 0;
|
||||
bool _awaitingSent = false;
|
||||
|
||||
bool _isLoading = false;
|
||||
bool _isLoaded = false;
|
||||
@@ -101,7 +102,8 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
||||
final reader = BufferReader(frame);
|
||||
try {
|
||||
final cmd = reader.readByte();
|
||||
if (cmd == respCodeSent) {
|
||||
if (cmd == respCodeSent && _awaitingSent) {
|
||||
_awaitingSent = false;
|
||||
reader.skipBytes(1); // Skip the reserved byte
|
||||
_tagData = reader.readUInt32LE();
|
||||
_tripTime = reader.readUInt32LE();
|
||||
@@ -183,6 +185,7 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
||||
);
|
||||
}
|
||||
_statusTimeout?.cancel();
|
||||
_recordTelemetryResult(true);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
@@ -217,8 +220,10 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
||||
} else {
|
||||
frame = buildSendTelemetryReq(widget.contact.publicKey);
|
||||
}
|
||||
_awaitingSent = true;
|
||||
await connector.sendFrame(frame);
|
||||
} catch (e) {
|
||||
_awaitingSent = false;
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
|
||||
Reference in new issue
Block a user