lte service (backend) and ui handling

This commit is contained in:
Mikkeli Matlock
2026-02-09 02:36:03 +09:00
parent 12a0d58800
commit 47b3427e63
5 changed files with 261 additions and 3 deletions

View File

@@ -65,11 +65,13 @@ class WebSocketService {
// Latest values for sync access (backward compat)
ArduinoData? _latestArduino;
GpsData? _latestGps;
LteData? _latestLte;
BackendStatus? _latestStatus;
// Stream controllers
late StreamController<ArduinoData> _arduinoController;
late StreamController<GpsData> _gpsController;
late StreamController<LteData> _lteController;
late StreamController<BackendStatus> _statusController;
late StreamController<CommandAck> _ackController;
late StreamController<BackendAlert> _alertController;
@@ -83,6 +85,7 @@ class WebSocketService {
void _setupStreams() {
_arduinoController = StreamController<ArduinoData>.broadcast();
_gpsController = StreamController<GpsData>.broadcast();
_lteController = StreamController<LteData>.broadcast();
_statusController = StreamController<BackendStatus>.broadcast();
_ackController = StreamController<CommandAck>.broadcast();
_alertController = StreamController<BackendAlert>.broadcast();
@@ -107,6 +110,9 @@ class WebSocketService {
/// Stream of GPS updates
Stream<GpsData> get gpsStream => _gpsController.stream;
/// Stream of LTE status updates
Stream<LteData> get lteStream => _lteController.stream;
/// Stream of backend status updates
Stream<BackendStatus> get statusStream => _statusController.stream;
@@ -139,6 +145,9 @@ class WebSocketService {
/// Latest GPS data (may be null if not yet received)
GpsData? get latestGps => _latestGps;
/// Latest LTE data (may be null if not yet received)
LteData? get latestLte => _latestLte;
/// Latest backend status
BackendStatus? get latestStatus => _latestStatus;
@@ -208,6 +217,15 @@ class WebSocketService {
}
});
_socket!.on('lte', (data) {
if (data is Map<String, dynamic>) {
final lte = LteData.fromJson(data);
_latestLte = lte;
_lteController.add(lte);
_log('lte: ${lte.signal ?? "-"}% ${lte.operator_ ?? "-"} ${lte.accessTech ?? "-"}');
}
});
_socket!.on('status', (data) {
if (data is Map<String, dynamic>) {
final status = BackendStatus(
@@ -323,6 +341,7 @@ class WebSocketService {
disconnect();
_arduinoController.close();
_gpsController.close();
_lteController.close();
_statusController.close();
_ackController.close();
_alertController.close();