- 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>
168 lines
6.9 KiB
Dart
168 lines
6.9 KiB
Dart
import 'dart:convert';
|
|
|
|
import '../../app_info.dart';
|
|
import '../../domain/mission/drone_profile.dart';
|
|
|
|
/// Baut die Export-Datei fuer ein Drohnenprofil (Doku 3.5, analog
|
|
/// buildDroneExportObject()/shareDrone() im HTML-Demonstrator). Die id wird
|
|
/// bewusst nicht mitexportiert - beim Import entsteht immer ein neues,
|
|
/// eigenstaendiges Profil (siehe parseDroneImportJson()).
|
|
String buildDroneExportJson(DroneProfile profile) {
|
|
final map = {
|
|
'appVersion': kAppVersion,
|
|
'exportedAt': DateTime.now().toUtc().toIso8601String(),
|
|
'drone': {
|
|
'name': profile.name,
|
|
'minSpeed': profile.minSpeed,
|
|
'cruiseSpeed': profile.cruiseSpeed,
|
|
'maxSpeed': profile.maxSpeed,
|
|
'minTurnRadius': profile.minTurnRadius,
|
|
'loiterRadius': profile.loiterRadius,
|
|
'catchRadius': profile.catchRadius,
|
|
'maxClimbRate': profile.maxClimbRate,
|
|
'maxDescentRate': profile.maxDescentRate,
|
|
'maxRangeM': profile.maxRangeM,
|
|
'maxEnduranceMin': profile.maxEnduranceMin,
|
|
'maxAltitudeM': profile.maxAltitudeM,
|
|
'gpsSatGreenMin': profile.gpsSatGreenMin,
|
|
'gpsSatRedMin': profile.gpsSatRedMin,
|
|
'hdopGreenMax': profile.hdopGreenMax,
|
|
'hdopRedMax': profile.hdopRedMax,
|
|
'currentGreenMaxA': profile.currentGreenMaxA,
|
|
'currentRedMaxA': profile.currentRedMaxA,
|
|
'batteryCellCount': profile.batteryCellCount,
|
|
'batteryVoltageGreenMinPerCellV': profile.batteryVoltageGreenMinPerCellV,
|
|
'batteryVoltageRedMinPerCellV': profile.batteryVoltageRedMinPerCellV,
|
|
'rxQualityGreenMin': profile.rxQualityGreenMin,
|
|
'rxQualityRedMin': profile.rxQualityRedMin,
|
|
'rxSnrGreenMinDb': profile.rxSnrGreenMinDb,
|
|
'rxSnrRedMinDb': profile.rxSnrRedMinDb,
|
|
},
|
|
};
|
|
return const JsonEncoder.withIndent(' ').convert(map);
|
|
}
|
|
|
|
/// Vorschlagsname fuer die geteilte Datei (Doku 3.5, analog
|
|
/// `'drone-' + safeName + '.json'` im HTML-Demonstrator).
|
|
String droneExportFilename(String name) {
|
|
final safeName = name.replaceAll(RegExp(r'[^a-zA-Z0-9]'), '_');
|
|
return 'drone-$safeName.json';
|
|
}
|
|
|
|
class ParsedDroneImport {
|
|
const ParsedDroneImport({required this.profile, this.versionMismatch});
|
|
|
|
final DroneProfile profile;
|
|
|
|
/// Enthaelt die appVersion der Datei, falls sie sich von [kAppVersion] in
|
|
/// der Hauptversionsnummer unterscheidet - sonst null.
|
|
final String? versionMismatch;
|
|
}
|
|
|
|
const _requiredNumericFields = [
|
|
'minSpeed',
|
|
'cruiseSpeed',
|
|
'maxSpeed',
|
|
'minTurnRadius',
|
|
'loiterRadius',
|
|
'catchRadius',
|
|
'maxClimbRate',
|
|
'maxDescentRate',
|
|
'maxRangeM',
|
|
'maxEnduranceMin',
|
|
'maxAltitudeM',
|
|
];
|
|
|
|
/// Parst eine importierte Drohnenprofil-Datei - wirft [FormatException] bei
|
|
/// ungueltigem JSON oder fehlenden Pflichtfeldern (Doku 3.5, analog dem
|
|
/// `change`-Handler von importDroneInput im HTML-Demonstrator).
|
|
ParsedDroneImport parseDroneImportJson(String jsonText) {
|
|
final Object? decoded;
|
|
try {
|
|
decoded = jsonDecode(jsonText);
|
|
} on FormatException {
|
|
throw const FormatException('Invalid drone profile file');
|
|
}
|
|
if (decoded is! Map<String, dynamic>) {
|
|
throw const FormatException('Invalid drone profile file');
|
|
}
|
|
final droneData = decoded['drone'] ?? decoded;
|
|
if (droneData is! Map<String, dynamic>) {
|
|
throw const FormatException('Invalid drone profile file');
|
|
}
|
|
|
|
final name = droneData['name'];
|
|
if (name is! String || name.isEmpty) {
|
|
throw const FormatException('File is not a valid drone profile');
|
|
}
|
|
for (final field in _requiredNumericFields) {
|
|
if (droneData[field] is! num) {
|
|
throw const FormatException('File is not a valid drone profile');
|
|
}
|
|
}
|
|
|
|
// Ampel-Schwellwerte (siehe DroneProfile-Doku) sind bewusst NICHT Teil von
|
|
// _requiredNumericFields - aeltere, vor deren Einfuehrung exportierte
|
|
// Profildateien haben diese Felder noch nicht und sollen trotzdem
|
|
// importierbar bleiben (dann gelten die DroneProfile.default*-Werte).
|
|
double numOrDefault(String field, double fallback) {
|
|
final v = droneData[field];
|
|
return v is num ? v.toDouble() : fallback;
|
|
}
|
|
|
|
int intOrDefault(String field, int fallback) {
|
|
final v = droneData[field];
|
|
return v is num ? v.round() : fallback;
|
|
}
|
|
|
|
final profile = DroneProfile(
|
|
name: name,
|
|
minSpeed: (droneData['minSpeed'] as num).toDouble(),
|
|
cruiseSpeed: (droneData['cruiseSpeed'] as num).toDouble(),
|
|
maxSpeed: (droneData['maxSpeed'] as num).toDouble(),
|
|
minTurnRadius: (droneData['minTurnRadius'] as num).toDouble(),
|
|
loiterRadius: (droneData['loiterRadius'] as num).toDouble(),
|
|
catchRadius: (droneData['catchRadius'] as num).toDouble(),
|
|
maxClimbRate: (droneData['maxClimbRate'] as num).toDouble(),
|
|
maxDescentRate: (droneData['maxDescentRate'] as num).toDouble(),
|
|
maxRangeM: (droneData['maxRangeM'] as num).toDouble(),
|
|
maxEnduranceMin: (droneData['maxEnduranceMin'] as num).toDouble(),
|
|
maxAltitudeM: (droneData['maxAltitudeM'] as num).toDouble(),
|
|
gpsSatGreenMin: numOrDefault('gpsSatGreenMin', DroneProfile.defaultGpsSatGreenMin),
|
|
gpsSatRedMin: numOrDefault('gpsSatRedMin', DroneProfile.defaultGpsSatRedMin),
|
|
hdopGreenMax: numOrDefault('hdopGreenMax', DroneProfile.defaultHdopGreenMax),
|
|
hdopRedMax: numOrDefault('hdopRedMax', DroneProfile.defaultHdopRedMax),
|
|
currentGreenMaxA: numOrDefault('currentGreenMaxA', DroneProfile.defaultCurrentGreenMaxA),
|
|
currentRedMaxA: numOrDefault('currentRedMaxA', DroneProfile.defaultCurrentRedMaxA),
|
|
// batteryCellCount/*PerCellV sind Schema-v9-Felder (Doku: "zellen anzahl
|
|
// ... hinzufuegen") - Dateien, die vor deren Einfuehrung exportiert
|
|
// wurden, haben stattdessen ggf. noch die alten absoluten
|
|
// batteryVoltage*MinV-Felder (feste Pack-Spannung). Die werden hier
|
|
// bewusst NICHT mehr gelesen (koennten ohne bekannte Zellenzahl der
|
|
// Quelldrohne nicht sinnvoll in Pro-Zelle-Werte umgerechnet werden) -
|
|
// stattdessen gelten wie bei allen anderen Schwellwerten die
|
|
// DroneProfile.default*-Werte.
|
|
batteryCellCount: intOrDefault('batteryCellCount', DroneProfile.defaultBatteryCellCount),
|
|
batteryVoltageGreenMinPerCellV: numOrDefault(
|
|
'batteryVoltageGreenMinPerCellV',
|
|
DroneProfile.defaultBatteryVoltageGreenMinPerCellV,
|
|
),
|
|
batteryVoltageRedMinPerCellV: numOrDefault(
|
|
'batteryVoltageRedMinPerCellV',
|
|
DroneProfile.defaultBatteryVoltageRedMinPerCellV,
|
|
),
|
|
rxQualityGreenMin: numOrDefault('rxQualityGreenMin', DroneProfile.defaultRxQualityGreenMin),
|
|
rxQualityRedMin: numOrDefault('rxQualityRedMin', DroneProfile.defaultRxQualityRedMin),
|
|
rxSnrGreenMinDb: numOrDefault('rxSnrGreenMinDb', DroneProfile.defaultRxSnrGreenMinDb),
|
|
rxSnrRedMinDb: numOrDefault('rxSnrRedMinDb', DroneProfile.defaultRxSnrRedMinDb),
|
|
);
|
|
|
|
final appVersion = decoded['appVersion'] as String?;
|
|
final mismatch = appVersion != null &&
|
|
appVersion.split('.').first != kAppVersion.split('.').first
|
|
? appVersion
|
|
: null;
|
|
|
|
return ParsedDroneImport(profile: profile, versionMismatch: mismatch);
|
|
}
|