39 lines
988 B
Dart
39 lines
988 B
Dart
// lib/features/devices/data/models/route_plan_send_entity.dart
|
|
import 'dart:typed_data'; // ✅ 必须添加
|
|
|
|
class RoutePlanSendEntity {
|
|
final int commandType;
|
|
final int pointCounts;
|
|
final double targetLatitude;
|
|
final double targetLongitude;
|
|
final int speed;
|
|
|
|
RoutePlanSendEntity({
|
|
required this.commandType,
|
|
required this.pointCounts,
|
|
required this.targetLatitude,
|
|
required this.targetLongitude,
|
|
required this.speed,
|
|
});
|
|
|
|
|
|
List<int> toBytes() {
|
|
final bytes = <int>[];
|
|
bytes.add(commandType);
|
|
bytes.addAll(_shortToBytes(pointCounts));
|
|
bytes.addAll(_doubleToBytes(targetLatitude));
|
|
bytes.addAll(_doubleToBytes(targetLongitude));
|
|
bytes.addAll(_shortToBytes(speed));
|
|
return bytes;
|
|
}
|
|
|
|
List<int> _shortToBytes(int value) {
|
|
return [(value >> 8) & 0xFF, value & 0xFF];
|
|
}
|
|
|
|
List<int> _doubleToBytes(double value) {
|
|
final byteData = ByteData(8)..setFloat64(0, value);
|
|
return byteData.buffer.asUint8List();
|
|
}
|
|
}
|