import 'dart:math'; import 'dart:developer' as developer; import 'dart:typed_data'; import 'dart:ui'; import 'package:cpnav/pages/setting/child_pages/XyChange/xy_change.dart'; import 'package:get/get.dart'; import 'package:scence_map/controllers/controller.dart'; import 'package:scence_map/record_entity.dart'; // import 'package:flutter_webrtc/flutter_webrtc.dart'; import '../../models/pilePoint/coord_trans.dart'; import '../setting/child_pages/XyChange/coor_trans.dart'; import '../setting/setting_controller.dart'; import 'process.dart'; // pile_cm // class RealController extends GetxController { // var sightOffset1 = const Offset(3, 3).obs; // var sightOffsetInit1 = const Offset(0, 0).obs; // var sightInit1 = const Offset(0, 0).obs; // var initDx = 0.0.obs; // reset() { // sightOffset1.value = const Offset(3, 3); // sightOffsetInit1.value = const Offset(0, 0); // sightInit1.value = const Offset(0, 0); // initDx.value = 0.0; // update(); // } // // RTCPeerConnection? peerConnection; // // RTCDataChannel? dataChannel; // final speed = 0.0.obs; // final depth = 0.0.obs; // final tiltX = 0.0.obs; // final tiltY = 0.0.obs; // final centerX = 0.0.obs; // final centerY = 0.0.obs; // final current1 = 0.0.obs; // final current2 = 0.0.obs; // final totalFlow2 = 0.0.obs; // final totalFlow1 = 0.0.obs; // final flow10cm1 = 0.0.obs; // final flow10cm2 = 0.0.obs; // final subtotalFlow2 = 0.0.obs; // final subtotalFlow1 = 0.0.obs; // final recvTime = ''.obs; // final alt = 0.0.obs; // final lng = 0.0.obs; // final lat = 0.0.obs; // final pileId = ''.obs; // final time = "0".obs; // final startIndex = 0.obs; // // 折线数组 // final processList = [].obs; // var isDataVisible = false.obs; // void updateProcessList(List newList) { // processList.assignAll(newList); // 使用 assignAll 方法更新 RxList // } // DateTime? sliderTime; // updateSlider(double newValue, [isHand = true]) { // if (isHand) { // sliderTime = DateTime.now(); // } // startIndex.value = newValue.toInt(); // update(); // } // @override // void onInit() { // super.onInit(); // // 定时器每秒更新时间 // // Timer.periodic(const Duration(milliseconds: 1000), (_) { // // time.value = DateTime.now(); // // }); // initializePeerConnection(); // } // void initializePeerConnection() async { // // final configuration = { // // 'iceServers': [ // // {'url': 'stun:stun.l.google.com:19302'}, // // ], // // }; // // peerConnection = await createPeerConnection(configuration); // // initializeDataChannel(); // } // // void initializeDataChannel() async { // // // 创建数据通道 // // dataChannel = await peerConnection! // // .createDataChannel('dataChannel', RTCDataChannelInit()..id = 1); // // // 监听数据通道的消息事件 // // dataChannel!.onMessage = (RTCDataChannelMessage message) { // // // 处理接收到的消息 // // if (message.isBinary) { // // onBleData(message.binary); // // } // // }; // // } // onBleData(Uint8List data) { // ByteData byteData = data.buffer.asByteData(); // int tag = byteData.getUint8(0); // // int length = byteData.getUint8(1); // if (tag == 161) { // speed.value = byteData.getInt16(2, Endian.little) * 0.1; // int timeInt = byteData.getUint16(4, Endian.little); // // log(timeInt); // time.value = convertSecondsToMinSec(timeInt); // depth.value = byteData.getInt16(6, Endian.little) * 0.001; // pileId.value = byteData.getUint16(8, Endian.little).toString(); // subtotalFlow1.value = byteData.getInt16(10, Endian.little) * 0.01; // flow10cm1.value = byteData.getUint16(12, Endian.little) * 0.01; // totalFlow1.value = byteData.getInt32(14, Endian.little) * 0.01; // subtotalFlow2.value = byteData.getInt16(18, Endian.little) * 0.01; // flow10cm2.value = byteData.getUint16(20, Endian.little) * 0.01; // totalFlow2.value = byteData.getInt32(22, Endian.little) * 0.01; // current1.value = byteData.getUint16(26, Endian.little) * 0.01; // current2.value = byteData.getUint16(28, Endian.little) * 0.01; // // current3.value = byteData.getUint16(30, Endian.little) * 0.01; // int tag1 = byteData.getUint8(34); // // int length = byteData.getUint8(35); // if (tag1 == 162) { // // var gpsStatus = byteData.getUint8(36); // // var gpsView = byteData.getUint8(37); // // var gpsUse = byteData.getUint8(38); // // var reg = byteData.getUint8(39); // // var utc = byteData.getUint32(40, Endian.little); // // 中心坐标 // centerX.value = byteData.getFloat64(44, Endian.little); // centerY.value = byteData.getFloat64(52, Endian.little); // // log("中心---$centerX,$centerY"); // // tiltX.value = byteData.getFloat64(44, Endian.little); // // tiltY.value = byteData.getFloat64(52, Endian.little); // // var direction = byteData.getFloat64(60, Endian.little); // // var pitch = byteData.getFloat64(68, Endian.little); // // log("$gpsUse,$gpsView,$utc,$direction,$pitch"); // } // } // } // String convertSecondsToMinSec(int totalSeconds) { // int minutes = totalSeconds ~/ 60; // int seconds = totalSeconds % 60; // String formattedTime = '$minutes:${seconds.toString().padLeft(2, '0')}'; // return formattedTime; // } // @override // void dispose() { // // dataChannel?.close(); // 关闭数据通道 // // peerConnection?.close(); // 关闭对等连接 // super.dispose(); // } // } final ScenceMapController mapController = Get.find(); SettingController settingController = Get.find(); XYChangeController xyChangeController = Get.put(XYChangeController()); class RealController extends GetxController { var sightOffset1 = const Offset(3, 3).obs; var sightOffsetInit1 = const Offset(0, 0).obs; var sightInit1 = const Offset(0, 0).obs; var initDx = 0.0.obs; var processdata = ProcessEntity( tid: 0, speed: 0, alt: 0, lng: 0, lat: 0, tp_id: 0, utc: DateTime.now().millisecond, impact_force: []).obs; var dataCount = 0.obs; CoordTrans? coordTrans; var status = 0.obs; var sa = 0.obs; var sv = 0.obs; reset() { sightOffset1.value = const Offset(3, 3); sightOffsetInit1.value = const Offset(0, 0); sightInit1.value = const Offset(0, 0); initDx.value = 0.0; update(); } var isDataVisible = false.obs; onBleData(Uint8List data) { String str = String.fromCharCodes(data); String first = str.split("#POSA")[1]; List list = first.split(","); double baseLine = double.parse(list[7]); double heading = double.parse(list[8]); double pitch = double.parse(list[9]); status.value = int.parse(list[1]); sa.value = int.parse(list[10]); List svStr = list[11].trim().split(" "); sv.value = int.parse(svStr[0]); ProcessEntity process = ProcessEntity.fromList(list); processdata.update((value) { // value.speed = process.speed; value?.lat = process.lat; value?.lng = process.lng; value?.alt = process.height; value?.utc = process.utc; }); dataCount.value++; CoorTransModel trans = xyChangeController.coorTrans.value; coordTrans ??= CoordTrans(TransOptions( L0: trans.L0, // dstEllipsoid: trans.dstEllipsoid, // srcEllipsoid: trans.srcEllipsoid, dx: trans.dx, dy: trans.dy, type: trans.type)); var xyh = coordTrans! .d2p(CoordBLH(B: process.lat, L: process.lng, H: process.alt)); Offset offset = Offset(xyh.X, xyh.Y); if ((mapController.centerXY - offset).distance > 40) { mapController.centerXY = offset; } RecordEntity record = RecordEntity( tid: 0, tpId: -1, id: 0, startTime: DateTime.now(), endTime: DateTime.now(), lat: process.lat, lng: process.lng, name: "实时", times: 1, x: xyh.X, y: xyh.Y, strongDrop: 0, ); if (mapController.recordList.isEmpty) { mapController.recordList.add(record); } else { int index = mapController.recordList .lastIndexWhere((element) => element.tpId == -1); if (index == -1) { mapController.recordList.add(record); } else { mapController.recordList[index] = record; } } mapController.updateCount++; var centerDev = mapController.deviceList[settingController.currentDevice.value?.tid]; if (centerDev != null) { // log("center${xyh.X},${xyh.Y}"); centerDev.update.value++; double pitchRad = pitch * pi / 180; double headingRad = (heading) * pi / 180; //(270-) centerDev.rotation.value = (heading + 90) * pi / 180; // 计算水平投影距离 double dXY = baseLine * cos(pitchRad); // 计算副天线的坐标 double carX = xyh.X + dXY * cos(headingRad); double carY = xyh.Y + dXY * sin(headingRad); centerDev.x.value = carX; centerDev.y.value = carY; developer.log("carX:$carX,carY:$carY"); } } }