From 07d3835cc614af1affeca1391b41d5655bdd32ab Mon Sep 17 00:00:00 2001 From: LiXiaoqi <2360211477@qq.com> Date: Fri, 6 Sep 2024 15:16:09 +0800 Subject: [PATCH] play --- lib/pages/pass_track/controller.dart | 19 +-- lib/pages/pass_track/sevice/file_handle.dart | 136 +++++++++++-------- lib/pages/pass_track/view.dart | 47 +++++-- lib/service/base.dart | 19 ++- plugins/pass_track | 2 +- 5 files changed, 138 insertions(+), 85 deletions(-) diff --git a/lib/pages/pass_track/controller.dart b/lib/pages/pass_track/controller.dart index 4c747eb..3d854bf 100644 --- a/lib/pages/pass_track/controller.dart +++ b/lib/pages/pass_track/controller.dart @@ -19,13 +19,13 @@ class PassTrackController extends GetxController { late final GetServices service; // final PassTrack _passTrackPlugin; PassTrackController(this.projCode, this.projType); - + Map deviceMap = {}; @override void onInit() { super.onInit(); service = GetServices(projCode: projCode, projType: projType); loadProject(); - loadSideLine(); + // loadSideLine(); loadBindDevice(); // getHisFileList(); } @@ -34,7 +34,8 @@ class PassTrackController extends GetxController { var binddevices = await service.getDeviceBind(); for (var device in binddevices) { var dev = DeviceItem.fromJson(device); - mapController.deviceList[dev.TID] = dev; + deviceMap[dev.TID.toString()] = 0; + // deviceMap[dev.TID as String] = dev[int.parse(dev["width"])]; } } @@ -80,17 +81,19 @@ class PassTrackController extends GetxController { } } - getHisFileList(PassTrack passTrackPlugin) async { + Future getHisFileList(PassTrack passTrackPlugin) async { Map textlist = await GetServices().getHisFileList(); List fileList = textlist['list']; for (var i = 0; i < fileList.length; i++) { var file = fileList[i]; - var jsData = await GetServices().getHisFile(file); + var jsData = await GetServices().getHisFil1(file); + print("have message"); int len = fileHandle.resolveJson(jsData, passTrackPlugin); allLen += len; - // print("$pointList"); - // var totalList =fileHandle.allPointData; + if (allLen >= 20000) { + break; + } } - print("allLen: $allLen"); + return allLen; } } diff --git a/lib/pages/pass_track/sevice/file_handle.dart b/lib/pages/pass_track/sevice/file_handle.dart index 8bf1101..0e3f25f 100644 --- a/lib/pages/pass_track/sevice/file_handle.dart +++ b/lib/pages/pass_track/sevice/file_handle.dart @@ -9,7 +9,6 @@ import 'package:ffi/ffi.dart'; import 'package:web_socket_channel/io.dart'; import 'package:web_socket_channel/status.dart' as status; - import 'package:pass_track/binding.dart' as Binding; import '../../../service/base.dart'; @@ -17,8 +16,8 @@ import '../model/coord_trans.dart'; import '../model/draw_context.dart'; import '../model/recievemodel.dart'; - DrawContext drawCtx = DrawContext(); + class FileHandle { int textureId = -1; int index = 0; @@ -250,66 +249,83 @@ class FileHandle { List allPointData = []; int start = 0; var allPointLen = 0; - // 记录当前数组的长度 - while (true) { - int end = res.indexOf('\n', start); - if (end < 0) { - break; - } - String str = res.substring(start, end); - try { - if (str[str.length - 1] == ",") { - str = str.substring(0, str.length - 1); - } - var item = jsonDecode(str); - RecieveModel recieveModel = RecieveModel.fromJson(item); - if (drawCtx.zeroDX == 0 || drawCtx.zeroDY == 0) { - //dart重置中心 - drawCtx.setCenter( - // {"x": recieveModel.x / 20, "y": recieveModel.y / 20});//532863.8,4208668.95 - {"x": 10656637 / 20, "y": 84172941 / 20});//532863.8,4208668.95 - } - int x = recieveModel.x; - int y = recieveModel.y; - int tid = recieveModel.TID; - int type = recieveModel.type; - var p = passTrackPlugin.wantPoint(); - p.ref.X = x.toDouble(); - p.ref.Y = y.toDouble(); - p.ref.TID = tid; - p.ref.type = type; - // var data = item['data']; - // if (data != null) { - // item['TID'] = - // item['TID'] is int ? item['TID'] : num.parse(item['TID']); - // item['type'] = - // item['type'] is int ? item['type'] : num.parse(item['type']); - // item['obj'] = DecodeDataObj.fromBase64(item['data']); - // // this.updateDevice(item); - // // this.sportsData.push(item); - - allPointData.add(recieveModel); - // } - } catch (e) { - print("----$e\r\n$str"); - } - allPointLen++; - start = end + 1; + // data 是一个列表 + var data = jsonDecode(res)["data"]; + for (var item in data) { + // RecieveModel recieveModel = RecieveModel.fromJson(item); + var X = item["X"].toDouble(); + var Y = item["Y"].toDouble(); + var TID = item["TID"]; + var type = int.parse(item["type"]); + var p = passTrackPlugin.wantPoint(); + p.ref.X = X; + p.ref.Y = Y; + p.ref.TID = TID; + p.ref.type = type; } - return allPointLen; - } else { - //只有一条数据的时候 - var item = res; - var data = item['data']; - if (data != null) { - item['obj'] = DecodeDataObj.fromBase64(item['data']); - item['type'] = num.parse(item['type']); - item['TID'] = num.parse(item['TID']); - // this.updateDevice(item); - // this.sportsData.push(item); - } - return 1; + return data.length; } + return 0; + // 记录当前数组的长度 + // while (true) { + // int end = res.indexOf('\n', start); + // if (end < 0) { + // break; + // } + // String str = res.substring(start, end); + // try { + // if (str[str.length - 1] == ",") { + // str = str.substring(0, str.length - 1); + // } + // var item = jsonDecode(str); + // RecieveModel recieveModel = RecieveModel.fromJson(item); + // if (drawCtx.zeroDX == 0 || drawCtx.zeroDY == 0) { + // //dart重置中心 + // drawCtx.setCenter( + // // {"x": recieveModel.x / 20, "y": recieveModel.y / 20});//532863.8,4208668.95 + // {"x": 10656637 / 20, "y": 84172941 / 20}); //532863.8,4208668.95 + // } + // int x = recieveModel.x; + // int y = recieveModel.y; + // int tid = recieveModel.TID; + // int type = recieveModel.type; + // var p = passTrackPlugin.wantPoint(); + // p.ref.X = x.toDouble(); + // p.ref.Y = y.toDouble(); + // p.ref.TID = tid; + // p.ref.type = type; + // // var data = item['data']; + // // if (data != null) { + // // item['TID'] = + // // item['TID'] is int ? item['TID'] : num.parse(item['TID']); + // // item['type'] = + // // item['type'] is int ? item['type'] : num.parse(item['type']); + // // item['obj'] = DecodeDataObj.fromBase64(item['data']); + // // // this.updateDevice(item); + // // // this.sportsData.push(item); + + // allPointData.add(recieveModel); + // // } + // } catch (e) { + // print("----$e\r\n$str"); + // } + // allPointLen++; + // start = end + 1; + // } + // return allPointLen; + // } else { + // //只有一条数据的时候 + // var item = res; + // var data = item['data']; + // if (data != null) { + // item['obj'] = DecodeDataObj.fromBase64(item['data']); + // item['type'] = num.parse(item['type']); + // item['TID'] = num.parse(item['TID']); + // // this.updateDevice(item); + // // this.sportsData.push(item); + // } + // return 1; + // } } //修改点的bits和typeBits diff --git a/lib/pages/pass_track/view.dart b/lib/pages/pass_track/view.dart index 796efe6..6b638d3 100644 --- a/lib/pages/pass_track/view.dart +++ b/lib/pages/pass_track/view.dart @@ -39,15 +39,16 @@ class PassTrackWidget extends StatefulWidget { class _PasstrackState extends State { final GlobalKey> _popupMenuKey = GlobalKey>(); - final controller = Get.put(PassTrackController("WXLMB", "cp_orad")); + final controller = Get.put(PassTrackController("WXLMB", "cp_road")); String str = "播放"; - int sWidth = 0; + int sWidth = 800; + int sHeight = 800; int bits = -1; int speed = 50; List speedList = [1, 2, 10, 20, 50, 100, 200, 500]; // int maxLength = 200; late SfRangeValues _rangevalues; - final _passTrackPlugin = PassTrack(); + final PassTrack _passTrackPlugin = PassTrack(); @override initState() { @@ -84,14 +85,20 @@ class _PasstrackState extends State { // } // }); }); - initPlatformState(); - controller.getHisFileList(_passTrackPlugin); - if (controller.allLen <= 0) { - return; - } - _passTrackPlugin.generateTile(0, controller.allLen); - _passTrackPlugin.waitForTile(); - _passTrackPlugin.playTrack(0, controller.allLen, true, 0, ffi.nullptr); + var f = initPlatformState(); + + f.then((void _) { + var future = controller.getHisFileList(_passTrackPlugin); + future.then((value) { + _passTrackPlugin.setScale(1); + for (var TID in controller.deviceMap.keys) { + _passTrackPlugin.addDevice(int.parse(TID), 0); + } + _passTrackPlugin.generateTile(0, value); + _passTrackPlugin.waitForTile(); + _passTrackPlugin.playTrack(0, value, true, 0, ffi.nullptr); + }); + }); } Future initPlatformState() async { @@ -106,11 +113,12 @@ class _PasstrackState extends State { fileHandle.textureId = await _passTrackPlugin.getTextureId() ?? -1; print("textureId: ${fileHandle.textureId}"); - if (!mounted) return; + if (!mounted) Exception('Failed to get textureId.'); setState(() { platformVersion = platformVersion; }); + return; } @override @@ -121,7 +129,16 @@ class _PasstrackState extends State { return Stack( children: [ ScenceMapView( - children: [], + children: [ + Positioned( + top: 0, + left: 0, + child: SizedBox( + width: sWidth * 1.0, + height: sWidth * 1.0, + // child: Text('Running on: $_platformVersion\n'), + child: Texture(textureId: fileHandle.textureId))), + ], onUpdate: (Offset center, double scale, double rotation) { print("center:$center scale:$scale rotation:$rotation"); }, @@ -235,6 +252,7 @@ class _PasstrackState extends State { ), const SizedBox(width: 12), Column( + children: [ const Text("此处遍数:0"), StreamBuilder( @@ -264,7 +282,8 @@ class _PasstrackState extends State { }, ), ], - ) + ), + ], ), ), diff --git a/lib/service/base.dart b/lib/service/base.dart index d0b5282..2f448b0 100644 --- a/lib/service/base.dart +++ b/lib/service/base.dart @@ -10,7 +10,7 @@ class BaseService { //创建client实例 final _client = http.Client(); final String token = - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc1IiOjAsInJvbGVJZHMiOlsiMSIsIjI0Il0sInVzZXJuYW1lIjoiYWRtaW4iLCJ1c2VySWQiOjEsIlBWIjo1LCJvcmciOiJhIiwiaWF0IjoxNzIyODY1MTE0LCJleHAiOjE3MjQxNjExMTR9.zuY366ldKkbtd1TTfcYIZfvhrovMlXLzzRk3j65Ua7o"; + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc1IiOjAsInJvbGVJZHMiOlsiODMiXSwidXNlcm5hbWUiOiJseWNzIiwidXNlcklkIjozNTYsIlBWIjoyLCJvcmciOiJhIiwiaWF0IjoxNzI1NTI2MDc0LCJleHAiOjE3MjY4MjIwNzR9.l47sd4L8OswBcHJxamGe9M5ttWqiukoJvE5QfwPARlw"; // String baseUrl = "http://192.168.1.189:8001";//本地 String baseUrl = "http://1.82.251.83:8001"; //线上 @@ -74,7 +74,7 @@ class GetServices { // int tid = 109; String projType; String projCode; - GetServices({this.projCode = "", this.projType = ""}); + GetServices({this.projCode = "WXLMB", this.projType = "cp_road"}); // int tid = 1000; // String projType = "pile_cm"; // 道路边线 @@ -114,6 +114,21 @@ class GetServices { return res; } + getHisFil1(String file) async { + file = file.substring(file.length - 18, file.length); + String fullUrl = + "http://192.168.1.154:8300/api/cp_road/record/data1/$projCode/$file"; + Map headers = { + // HttpHeaders.contentTypeHeader: "text/plain", + HttpHeaders.authorizationHeader: + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc1JlZnJlc2giOmZhbHNlLCJpc1IiOjAsInJvbGVJZHMiOlsiMSIsIjI0Il0sInVzZXJuYW1lIjoiYWRtaW4iLCJ1c2VySWQiOjEsIlBWIjo1LCJvcmciOiJhIiwiZXhwIjoxNzI2NzE1ODE3LCJpYXQiOjE3MjU0MTk4MTd9.RZ5MpHavsF_akOZALiHo-Y3bx-f_tTp5tfgNatR-98k", + }; + Response response = + await http.Client().get(Uri.parse(fullUrl), headers: headers); + var res = response.body; + return res; + } + // 项目列表 getproject() async { Map res = await service diff --git a/plugins/pass_track b/plugins/pass_track index 30a101b..5145127 160000 --- a/plugins/pass_track +++ b/plugins/pass_track @@ -1 +1 @@ -Subproject commit 30a101b8415cd162ab14f661f6f75ac7751962d3 +Subproject commit 5145127697ac2f0e3c8b80ae44d49fad9da760cf