Merge pull request #513 from Hacuchino-hash/self-telemetry
Add self node telemetry screen
This commit is contained in:
3 files changed
+103
-20
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
||||
import 'package:meshcore_open/models/companion_radio_stats.dart';
|
||||
import 'package:meshcore_open/screens/telemetry_screen.dart';
|
||||
import 'package:meshcore_open/l10n/l10n.dart';
|
||||
import 'package:meshcore_open/theme/mesh_theme.dart';
|
||||
import 'package:meshcore_open/widgets/mesh_ui.dart';
|
||||
@@ -77,6 +78,18 @@ class _CompanionRadioStatsScreenState extends State<CompanionRadioStatsScreen> {
|
||||
appBar: AppBar(
|
||||
title: Text(l10n.radioStats_screenTitle),
|
||||
centerTitle: true,
|
||||
actions: [
|
||||
Selector<MeshCoreConnector, bool>(
|
||||
selector: (_, c) => c.isConnected,
|
||||
builder: (context, connected, _) => IconButton(
|
||||
icon: const Icon(Icons.thermostat),
|
||||
tooltip: l10n.contact_telemetry,
|
||||
onPressed: connected
|
||||
? () => pushSelfTelemetryScreen(context)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Selector<MeshCoreConnector, ({bool connected, bool supported})>(
|
||||
selector: (_, c) => (
|
||||
|
||||
@@ -20,6 +20,7 @@ import 'app_settings_screen.dart';
|
||||
import 'app_debug_log_screen.dart';
|
||||
import 'ble_debug_log_screen.dart';
|
||||
import '../widgets/radio_stats_entry.dart';
|
||||
import 'telemetry_screen.dart';
|
||||
import '../widgets/sync_progress_overlay.dart';
|
||||
import 'region_management_screen.dart';
|
||||
|
||||
@@ -517,6 +518,16 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
: null,
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
_tappableTile(
|
||||
context,
|
||||
icon: Icons.thermostat_outlined,
|
||||
title: l10n.contact_telemetry,
|
||||
subtitle: l10n.repeater_telemetrySubtitle,
|
||||
onTap: connector.isConnected
|
||||
? () => pushSelfTelemetryScreen(context)
|
||||
: null,
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
_tappableTile(
|
||||
context,
|
||||
icon: Icons.route_outlined,
|
||||
|
||||
@@ -22,10 +22,36 @@ import '../widgets/telemetry_location_map.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
|
||||
/// Opens the telemetry screen for the locally connected node.
|
||||
void pushSelfTelemetryScreen(BuildContext context) {
|
||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
final selfKey = connector.selfPublicKey;
|
||||
if (selfKey == null || selfKey.isEmpty) return;
|
||||
final selfContact = Contact(
|
||||
publicKey: selfKey,
|
||||
name: connector.selfName ?? '',
|
||||
type: advTypeChat,
|
||||
pathLength: 0,
|
||||
path: Uint8List(0),
|
||||
lastSeen: DateTime.now(),
|
||||
);
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute<void>(
|
||||
builder: (context) => TelemetryScreen(contact: selfContact, isSelf: true),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class TelemetryScreen extends StatefulWidget {
|
||||
final Contact contact;
|
||||
final bool isSelf;
|
||||
|
||||
const TelemetryScreen({super.key, required this.contact});
|
||||
const TelemetryScreen({
|
||||
super.key,
|
||||
required this.contact,
|
||||
this.isSelf = false,
|
||||
});
|
||||
|
||||
@override
|
||||
State<TelemetryScreen> createState() => _TelemetryScreenState();
|
||||
@@ -160,7 +186,7 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
||||
void _handleTelemetryResponse(Uint8List frame) {
|
||||
final parsedTelemetry = CayenneLpp.parseByChannel(frame);
|
||||
final batteryMv = _extractTelemetryBatteryMillivolts(parsedTelemetry);
|
||||
if (batteryMv != null) {
|
||||
if (batteryMv != null && !widget.isSelf) {
|
||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
connector.updateRepeaterBatterySnapshot(
|
||||
widget.contact.publicKeyHex,
|
||||
@@ -207,23 +233,55 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
||||
});
|
||||
try {
|
||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||
final selection = await connector.preparePathForContactSend(
|
||||
_resolveContact(connector),
|
||||
);
|
||||
_pendingStatusSelection = selection;
|
||||
Uint8List frame;
|
||||
if (widget.contact.type != advTypeChat) {
|
||||
frame = buildSendBinaryReq(
|
||||
widget.contact.publicKey,
|
||||
payload: buildTelemetryBinaryPayload(),
|
||||
);
|
||||
if (widget.isSelf) {
|
||||
// ask the connected node for its own telemetry, no mesh path involved
|
||||
frame = buildSendTelemetryReq(null);
|
||||
final isAutoRefreshRequest = _activeTelemetryRequestIsAutoRefresh;
|
||||
_statusTimeout?.cancel();
|
||||
_statusTimeout = Timer(const Duration(seconds: 5), () {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_isLoaded = false;
|
||||
if (isAutoRefreshRequest && _isAutoRefreshEnabled) {
|
||||
_autoRefreshLastAttemptFailed = true;
|
||||
}
|
||||
_activeTelemetryRequestIsAutoRefresh = false;
|
||||
});
|
||||
if (!isAutoRefreshRequest) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(context.l10n.telemetry_requestTimeout),
|
||||
backgroundColor: Theme.of(context).colorScheme.error,
|
||||
);
|
||||
}
|
||||
if (isAutoRefreshRequest && _isAutoRefreshEnabled) {
|
||||
_scheduleNextAutoRefreshAttempt();
|
||||
}
|
||||
_recordTelemetryResult(false);
|
||||
});
|
||||
} else {
|
||||
frame = buildSendTelemetryReq(widget.contact.publicKey);
|
||||
final selection = await connector.preparePathForContactSend(
|
||||
_resolveContact(connector),
|
||||
);
|
||||
_pendingStatusSelection = selection;
|
||||
if (widget.contact.type != advTypeChat) {
|
||||
frame = buildSendBinaryReq(
|
||||
widget.contact.publicKey,
|
||||
payload: buildTelemetryBinaryPayload(),
|
||||
);
|
||||
} else {
|
||||
frame = buildSendTelemetryReq(widget.contact.publicKey);
|
||||
}
|
||||
}
|
||||
_awaitingSent = true;
|
||||
// A local self request gets no respCodeSent, so any that arrives belongs
|
||||
// to another send and must not replace the 5s self timeout.
|
||||
_awaitingSent = !widget.isSelf;
|
||||
await connector.sendFrame(frame);
|
||||
} catch (e) {
|
||||
_awaitingSent = false;
|
||||
_statusTimeout?.cancel();
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
@@ -358,12 +416,13 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
||||
centerTitle: true,
|
||||
bottom: const SyncProgressAppBarBottom(),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(isFloodMode ? Icons.waves : Icons.route),
|
||||
tooltip: l10n.repeater_routingMode,
|
||||
onPressed: () =>
|
||||
ContactRoutingSheet.show(context, contact: widget.contact),
|
||||
),
|
||||
if (!widget.isSelf)
|
||||
IconButton(
|
||||
icon: Icon(isFloodMode ? Icons.waves : Icons.route),
|
||||
tooltip: l10n.repeater_routingMode,
|
||||
onPressed: () =>
|
||||
ContactRoutingSheet.show(context, contact: widget.contact),
|
||||
),
|
||||
IconButton(
|
||||
icon: _isLoading
|
||||
? const SizedBox(
|
||||
@@ -500,7 +559,7 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
||||
_temperatureText(value, isImperialUnits),
|
||||
);
|
||||
case 'humidity':
|
||||
return _TelemetryFieldDisplay(l10n.telemetry_humidityLabel, text);
|
||||
return _TelemetryFieldDisplay(l10n.telemetry_humidityLabel, '$text%');
|
||||
case 'accelerometer':
|
||||
return _TelemetryFieldDisplay(
|
||||
l10n.telemetry_accelerometerLabel,
|
||||
|
||||
Reference in new issue
Block a user