155 lines
4.9 KiB
Dart
155 lines
4.9 KiB
Dart
import 'dart:typed_data';
|
|
import 'dart:ui';
|
|
import 'package:get/get.dart';
|
|
// import 'package:flutter_webrtc/flutter_webrtc.dart';
|
|
|
|
import 'process.dart';
|
|
|
|
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 = <ProcessEntity>[].obs;
|
|
var isDataVisible = false.obs;
|
|
|
|
void updateProcessList(List<ProcessEntity> 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 = <String, dynamic>{
|
|
// '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();
|
|
}
|
|
}
|