GNSS szervíz refraktorálás, hibajavítás, PhoneGpsConnection osztály

This commit is contained in:
2026-05-17 15:04:48 +02:00
parent ee0f90e247
commit 24a6b7d513
8 changed files with 221 additions and 112 deletions
@@ -1,6 +1,9 @@
// lib/services/gnss/ble_gnss_connection.dart
import 'dart:async';
import 'dart:io';
import 'dart:typed_data';
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
import 'package:geolocator/geolocator.dart';
import 'gnss_connection.dart';
import 'gnss_device_service.dart';
@@ -24,6 +27,7 @@ class BleGnssConnection implements GnssConnection {
BluetoothDevice? _device;
StreamSubscription? _notifySub;
String _lineBuffer = '';
BluetoothCharacteristic? _rxChar;
final _nmeaController = StreamController<String>.broadcast();
final _stateController = StreamController<GnssConnectionState>.broadcast();
@@ -46,6 +50,10 @@ class BleGnssConnection implements GnssConnection {
autoConnect: false,
license: License.free);
if (Platform.isAndroid) {
await _device!.requestMtu(512);
}
// Kapcsolat megszakadás figyelése
_device!.connectionState.listen((state) {
if (state == BluetoothConnectionState.disconnected) {
@@ -68,6 +76,10 @@ class BleGnssConnection implements GnssConnection {
orElse: () => throw Exception('TX char nem található: $txCharUuid'),
);
_rxChar = gnssService.characteristics.firstWhere((c) =>
c.characteristicUuid.str.toLowerCase() ==
_nusRxCharUuid.toLowerCase());
// Notify engedélyezése
await txChar.setNotifyValue(true);
@@ -109,4 +121,14 @@ class BleGnssConnection implements GnssConnection {
_nmeaController.close();
_stateController.close();
}
@override
void sendData(Uint8List data) {
if (_rxChar == null) return;
_rxChar!.write(data, withoutResponse: true);
}
@override
Stream<Position> get positionStream => const Stream.empty();
}