Files
tajniak81andClaude Opus 5.5 3dd31b257a Add the Fly Agent App, a Remote ID companion to DJI Fly
A Flutter app that runs next to DJI Fly without the DJI SDK. It receives the
aircraft's Remote ID (Bluetooth, BT5, Wi-Fi NaN and Beacon) in a foreground
service, streams the paired aircraft to the hub over /ws/device, and turns
take-off to landing into a logbook entry filed through /api/flights, queued
when offline. Covers phases A0-A3 of the Fly Agent plan; needs no server change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 19:25:52 +02:00

91 lines
2.6 KiB
Dart

import 'dart:typed_data';
/// Builds OpenDroneID messages byte-for-byte as an aircraft would broadcast
/// them, so the decoder is tested against the wire format, not against itself.
Uint8List basicId(String serial, {int idType = 1, int uaType = 2}) {
final Uint8List b = Uint8List(25);
b[0] = 0x02; // type 0, protocol version 2
b[1] = (idType << 4) | uaType;
final List<int> s = serial.codeUnits;
for (int i = 0; i < s.length && i < 20; i++) {
b[2 + i] = s[i];
}
return b;
}
Uint8List location({
int status = 2,
double lat = 55.6761,
double lon = 12.5683,
double? height = 42.5,
double? geo = 80,
double? speed = 5.25,
int track = 270,
double vSpeed = 1.5,
int tenthsIntoHour = 12345,
}) {
final ByteData d = ByteData(25);
int flags = status << 4;
int dir = track;
if (dir >= 180) {
flags |= 0x02;
dir -= 180;
}
int speedRaw = 255;
if (speed != null) {
if (speed <= 255 * 0.25) {
speedRaw = (speed / 0.25).round();
} else {
flags |= 0x01;
speedRaw = ((speed - 255 * 0.25) / 0.75).round();
}
}
d.setUint8(0, 0x12);
d.setUint8(1, flags);
d.setUint8(2, dir);
d.setUint8(3, speedRaw);
d.setInt8(4, (vSpeed / 0.5).round());
d.setInt32(5, (lat * 1e7).round(), Endian.little);
d.setInt32(9, (lon * 1e7).round(), Endian.little);
d.setUint16(13, 0, Endian.little); // pressure altitude unknown
d.setUint16(15, geo == null ? 0 : ((geo + 1000) / 0.5).round(), Endian.little);
d.setUint16(17, height == null ? 0 : ((height + 1000) / 0.5).round(), Endian.little);
d.setUint8(19, (4 << 4) | 10); // vertical < 10 m, horizontal < 10 m
d.setUint16(21, tenthsIntoHour, Endian.little);
return d.buffer.asUint8List();
}
Uint8List system({double opLat = 55.6760, double opLon = 12.5680, int category = 1, int cls = 2}) {
final ByteData d = ByteData(25);
d.setUint8(0, 0x42);
d.setUint8(1, (1 << 2) | 1); // EU classification, live GNSS operator position
d.setInt32(2, (opLat * 1e7).round(), Endian.little);
d.setInt32(6, (opLon * 1e7).round(), Endian.little);
d.setUint16(10, 1, Endian.little);
d.setUint8(17, (category << 4) | cls);
d.setUint32(20, 3600, Endian.little); // 2019-01-01T01:00:00Z
return d.buffer.asUint8List();
}
Uint8List operatorId(String id) {
final Uint8List b = Uint8List(25);
b[0] = 0x52;
final List<int> s = id.codeUnits;
for (int i = 0; i < s.length && i < 20; i++) {
b[2 + i] = s[i];
}
return b;
}
Uint8List pack(List<Uint8List> messages) {
final BytesBuilder b = BytesBuilder()
..addByte(0xF2)
..addByte(25)
..addByte(messages.length);
for (final Uint8List m in messages) {
b.add(m);
}
return b.toBytes();
}