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:flutter/material.dart';
|
||||||
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
||||||
import 'package:meshcore_open/models/companion_radio_stats.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/l10n/l10n.dart';
|
||||||
import 'package:meshcore_open/theme/mesh_theme.dart';
|
import 'package:meshcore_open/theme/mesh_theme.dart';
|
||||||
import 'package:meshcore_open/widgets/mesh_ui.dart';
|
import 'package:meshcore_open/widgets/mesh_ui.dart';
|
||||||
@@ -77,6 +78,18 @@ class _CompanionRadioStatsScreenState extends State<CompanionRadioStatsScreen> {
|
|||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(l10n.radioStats_screenTitle),
|
title: Text(l10n.radioStats_screenTitle),
|
||||||
centerTitle: true,
|
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})>(
|
body: Selector<MeshCoreConnector, ({bool connected, bool supported})>(
|
||||||
selector: (_, c) => (
|
selector: (_, c) => (
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import 'app_settings_screen.dart';
|
|||||||
import 'app_debug_log_screen.dart';
|
import 'app_debug_log_screen.dart';
|
||||||
import 'ble_debug_log_screen.dart';
|
import 'ble_debug_log_screen.dart';
|
||||||
import '../widgets/radio_stats_entry.dart';
|
import '../widgets/radio_stats_entry.dart';
|
||||||
|
import 'telemetry_screen.dart';
|
||||||
import '../widgets/sync_progress_overlay.dart';
|
import '../widgets/sync_progress_overlay.dart';
|
||||||
import 'region_management_screen.dart';
|
import 'region_management_screen.dart';
|
||||||
|
|
||||||
@@ -517,6 +518,16 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
|||||||
: null,
|
: null,
|
||||||
),
|
),
|
||||||
const Divider(height: 1, indent: 16),
|
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(
|
_tappableTile(
|
||||||
context,
|
context,
|
||||||
icon: Icons.route_outlined,
|
icon: Icons.route_outlined,
|
||||||
|
|||||||
@@ -22,10 +22,36 @@ import '../widgets/telemetry_location_map.dart';
|
|||||||
import '../theme/mesh_theme.dart';
|
import '../theme/mesh_theme.dart';
|
||||||
import '../widgets/mesh_ui.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 {
|
class TelemetryScreen extends StatefulWidget {
|
||||||
final Contact contact;
|
final Contact contact;
|
||||||
|
final bool isSelf;
|
||||||
|
|
||||||
const TelemetryScreen({super.key, required this.contact});
|
const TelemetryScreen({
|
||||||
|
super.key,
|
||||||
|
required this.contact,
|
||||||
|
this.isSelf = false,
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<TelemetryScreen> createState() => _TelemetryScreenState();
|
State<TelemetryScreen> createState() => _TelemetryScreenState();
|
||||||
@@ -160,7 +186,7 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
|||||||
void _handleTelemetryResponse(Uint8List frame) {
|
void _handleTelemetryResponse(Uint8List frame) {
|
||||||
final parsedTelemetry = CayenneLpp.parseByChannel(frame);
|
final parsedTelemetry = CayenneLpp.parseByChannel(frame);
|
||||||
final batteryMv = _extractTelemetryBatteryMillivolts(parsedTelemetry);
|
final batteryMv = _extractTelemetryBatteryMillivolts(parsedTelemetry);
|
||||||
if (batteryMv != null) {
|
if (batteryMv != null && !widget.isSelf) {
|
||||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||||
connector.updateRepeaterBatterySnapshot(
|
connector.updateRepeaterBatterySnapshot(
|
||||||
widget.contact.publicKeyHex,
|
widget.contact.publicKeyHex,
|
||||||
@@ -207,23 +233,55 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
|||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||||
final selection = await connector.preparePathForContactSend(
|
|
||||||
_resolveContact(connector),
|
|
||||||
);
|
|
||||||
_pendingStatusSelection = selection;
|
|
||||||
Uint8List frame;
|
Uint8List frame;
|
||||||
if (widget.contact.type != advTypeChat) {
|
if (widget.isSelf) {
|
||||||
frame = buildSendBinaryReq(
|
// ask the connected node for its own telemetry, no mesh path involved
|
||||||
widget.contact.publicKey,
|
frame = buildSendTelemetryReq(null);
|
||||||
payload: buildTelemetryBinaryPayload(),
|
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 {
|
} 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);
|
await connector.sendFrame(frame);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_awaitingSent = false;
|
_awaitingSent = false;
|
||||||
|
_statusTimeout?.cancel();
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_isLoading = false;
|
_isLoading = false;
|
||||||
@@ -358,12 +416,13 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
|||||||
centerTitle: true,
|
centerTitle: true,
|
||||||
bottom: const SyncProgressAppBarBottom(),
|
bottom: const SyncProgressAppBarBottom(),
|
||||||
actions: [
|
actions: [
|
||||||
IconButton(
|
if (!widget.isSelf)
|
||||||
icon: Icon(isFloodMode ? Icons.waves : Icons.route),
|
IconButton(
|
||||||
tooltip: l10n.repeater_routingMode,
|
icon: Icon(isFloodMode ? Icons.waves : Icons.route),
|
||||||
onPressed: () =>
|
tooltip: l10n.repeater_routingMode,
|
||||||
ContactRoutingSheet.show(context, contact: widget.contact),
|
onPressed: () =>
|
||||||
),
|
ContactRoutingSheet.show(context, contact: widget.contact),
|
||||||
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: _isLoading
|
icon: _isLoading
|
||||||
? const SizedBox(
|
? const SizedBox(
|
||||||
@@ -500,7 +559,7 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
|||||||
_temperatureText(value, isImperialUnits),
|
_temperatureText(value, isImperialUnits),
|
||||||
);
|
);
|
||||||
case 'humidity':
|
case 'humidity':
|
||||||
return _TelemetryFieldDisplay(l10n.telemetry_humidityLabel, text);
|
return _TelemetryFieldDisplay(l10n.telemetry_humidityLabel, '$text%');
|
||||||
case 'accelerometer':
|
case 'accelerometer':
|
||||||
return _TelemetryFieldDisplay(
|
return _TelemetryFieldDisplay(
|
||||||
l10n.telemetry_accelerometerLabel,
|
l10n.telemetry_accelerometerLabel,
|
||||||
|
|||||||
Reference in new issue
Block a user