Files
dmc/app/lib/services/database/drone_profile_repository.dart
T
Constantin LeueandClaude Sonnet 5 e902197462 System messages fuer GPS-Fix und Drone connected/disconnected, Batterie-Schwellwerte auf Pro-Zelle umgestellt
- detectSystemMessages() erkennt jetzt auch den Uebergang zu einem GPS-Fix
  (flankengetriggert wie Battery/Failsafe), Meldung "GPS fix acquired (N
  satellites)".
- Die automatisch erkannten Verbindungsmeldungen heissen jetzt "Drone
  connected"/"Drone disconnected" statt "Connected"/"Connection lost" -
  praeziser an die tatsaechliche Bedeutung angelehnt (Eintreffen/Ausbleiben
  echter Telemetrie-Frames, nicht nur des rohen Socket-Zustands).
- DroneProfile: feste Pack-Alarmspannung (batteryVoltageGreenMinV/RedMinV)
  ersetzt durch batteryCellCount + Pro-Zelle-Schwellwerte
  (batteryVoltageGreenMinPerCellV/RedMinPerCellV, LiPo-Standardwerte 3.4/3.2
  V als Default). Die alten Feldnamen bleiben als berechnete Getter
  (Zellenzahl * Pro-Zelle-Wert) erhalten, damit
  telemetry_field_status.dart unveraendert bleibt. T1-Ranger-Standardprofil
  auf 4S gesetzt.
- DB-Schema v8 -> v9 (additiv, alte Pack-Spannungs-Spalten bleiben als tote
  Spalten stehen), Repository und Share-Codec-Im-/Export entsprechend
  angepasst; alte Exportdateien ohne die neuen Felder fallen auf die
  DroneProfile-Defaults zurueck statt eine unbekannte Zellenzahl zu raten.
- DroneProfileEditor: "Battery voltage alarm"-Gruppe um ein Zellenzahl-Feld
  erweitert und auf V/Zelle umbenannt.
- Tests ergaenzt/angepasst: GPS-Fix-Erkennung (Unit + Provider-Integration),
  neuer v8->v9-Migrationstest analog zum bestehenden v7->v8-Test,
  Connected/Disconnected-Umbenennung in Provider- und Widget-Tests,
  Cell-Count-Roundtrip in Repository- und Share-Codec-Tests.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-06 13:06:49 +02:00

107 lines
4.2 KiB
Dart

import 'package:drift/drift.dart';
import '../../domain/mission/drone_profile.dart' as domain;
import 'app_database.dart';
/// Persistenz-Zugriff fuer Drohnenprofile (Doku 3.5/7.3).
///
/// `domain.DroneProfile` (das reine Datenmodell) und `DroneProfile` (die von
/// Drift aus der `DroneProfiles`-Tabelle generierte Zeilenklasse) heissen
/// gleich - hier daher qualifiziert importiert, um beide zu unterscheiden.
class DroneProfileRepository {
DroneProfileRepository(this._db);
final AppDatabase _db;
Stream<List<domain.DroneProfile>> watchAll() {
return _db.select(_db.droneProfiles).watch().map(
(rows) => [for (final row in rows) _fromRow(row)],
);
}
Future<List<domain.DroneProfile>> loadAll() async {
final rows = await _db.select(_db.droneProfiles).get();
return [for (final row in rows) _fromRow(row)];
}
/// Legt beim allerersten Start ein T1-Ranger-Standardprofil an, falls
/// noch keines existiert (analog `if (!drones) drones=[DEFAULT_DRONE]`
/// im HTML-Demonstrator). Gibt dessen id zurueck.
Future<int> ensureSeeded() async {
final existing = await loadAll();
if (existing.isNotEmpty) return existing.first.id!;
return insert(domain.DroneProfile.t1Ranger());
}
Future<int> insert(domain.DroneProfile profile) {
return _db.into(_db.droneProfiles).insert(_toCompanion(profile));
}
Future<void> update(domain.DroneProfile profile) async {
await (_db.update(_db.droneProfiles)..where((d) => d.id.equals(profile.id!)))
.write(_toCompanion(profile));
}
Future<void> delete(int id) async {
await (_db.delete(_db.droneProfiles)..where((d) => d.id.equals(id))).go();
}
domain.DroneProfile _fromRow(DroneProfile row) => domain.DroneProfile(
id: row.id,
name: row.name,
minSpeed: row.minSpeed,
cruiseSpeed: row.cruiseSpeed,
maxSpeed: row.maxSpeed,
minTurnRadius: row.minTurnRadius,
loiterRadius: row.loiterRadius,
catchRadius: row.catchRadius,
maxClimbRate: row.maxClimbRate,
maxDescentRate: row.maxDescentRate,
maxRangeM: row.maxRangeM,
maxEnduranceMin: row.maxEnduranceMin,
maxAltitudeM: row.maxAltitudeM,
gpsSatGreenMin: row.gpsSatGreenMin,
gpsSatRedMin: row.gpsSatRedMin,
hdopGreenMax: row.hdopGreenMax,
hdopRedMax: row.hdopRedMax,
currentGreenMaxA: row.currentGreenMaxA,
currentRedMaxA: row.currentRedMaxA,
batteryCellCount: row.batteryCellCount,
batteryVoltageGreenMinPerCellV: row.batteryVoltageGreenMinPerCellV,
batteryVoltageRedMinPerCellV: row.batteryVoltageRedMinPerCellV,
rxQualityGreenMin: row.rxQualityGreenMin,
rxQualityRedMin: row.rxQualityRedMin,
rxSnrGreenMinDb: row.rxSnrGreenMinDb,
rxSnrRedMinDb: row.rxSnrRedMinDb,
);
DroneProfilesCompanion _toCompanion(domain.DroneProfile profile) =>
DroneProfilesCompanion(
name: Value(profile.name),
minSpeed: Value(profile.minSpeed),
cruiseSpeed: Value(profile.cruiseSpeed),
maxSpeed: Value(profile.maxSpeed),
minTurnRadius: Value(profile.minTurnRadius),
loiterRadius: Value(profile.loiterRadius),
catchRadius: Value(profile.catchRadius),
maxClimbRate: Value(profile.maxClimbRate),
maxDescentRate: Value(profile.maxDescentRate),
maxRangeM: Value(profile.maxRangeM),
maxEnduranceMin: Value(profile.maxEnduranceMin),
maxAltitudeM: Value(profile.maxAltitudeM),
gpsSatGreenMin: Value(profile.gpsSatGreenMin),
gpsSatRedMin: Value(profile.gpsSatRedMin),
hdopGreenMax: Value(profile.hdopGreenMax),
hdopRedMax: Value(profile.hdopRedMax),
currentGreenMaxA: Value(profile.currentGreenMaxA),
currentRedMaxA: Value(profile.currentRedMaxA),
batteryCellCount: Value(profile.batteryCellCount),
batteryVoltageGreenMinPerCellV: Value(profile.batteryVoltageGreenMinPerCellV),
batteryVoltageRedMinPerCellV: Value(profile.batteryVoltageRedMinPerCellV),
rxQualityGreenMin: Value(profile.rxQualityGreenMin),
rxQualityRedMin: Value(profile.rxQualityRedMin),
rxSnrGreenMinDb: Value(profile.rxSnrGreenMinDb),
rxSnrRedMinDb: Value(profile.rxSnrRedMinDb),
);
}