From 7e0da80982dbf1e4601cc096a2a0257c68c6c688 Mon Sep 17 00:00:00 2001 From: "DESKTOP-B25GA9E\\W35" <1733709035@qq.com> Date: Thu, 2 Mar 2023 17:18:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=93=9D=E7=89=99=E7=BD=91?= =?UTF-8?q?=E5=85=B3=E6=95=B0=E6=8D=AE=E7=AD=9B=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataClass/BluetoothGateway.cs | 43 +++++++++++++++++-- .../HttpServer/HttpServerModel.cs | 4 +- .../HttpServer/HttpServerView.cs | 27 ++++++++++-- 3 files changed, 64 insertions(+), 10 deletions(-) diff --git a/Assets/MsgTransmitTools/DataClass/BluetoothGateway.cs b/Assets/MsgTransmitTools/DataClass/BluetoothGateway.cs index 7b2866f..6590d4a 100644 --- a/Assets/MsgTransmitTools/DataClass/BluetoothGateway.cs +++ b/Assets/MsgTransmitTools/DataClass/BluetoothGateway.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using UnityEngine; using LitJson; +using System; namespace JXSoft { public class BluetoothGateway:IResponse @@ -29,21 +30,55 @@ namespace JXSoft { /// /// 设备信息 /// - public List> devices { get; set; } + public List> devices { get; set; } + + private string exceptionMsg; + + public BluetoothGateway() { + + } + + + public string findDataByMac(string mac) { + foreach (List deviceMsg in devices) { + if (mac.Equals(deviceMsg[1])) { + return deviceMsg[3].ToString(); + } + } + return "no data"; + } public string toProtocolData() { - return ""; + string watchMac = "535708030130"; + string counter_1Mac = "90380C3BEF1A"; + string counter_2Mac = "90380C3C0416"; + string result = "watch:" + findDataByMac(watchMac) + "\ncounter_1:" + findDataByMac(counter_1Mac) + "\ncounter_2:" + findDataByMac(counter_2Mac); + return result; } public bool trySetData(string protocolData) { - throw new System.NotImplementedException(); + try + { + BluetoothGateway blg = JsonMapper.ToObject(protocolData); + this.v = blg.v; + this.time = blg.time; + this.mid = blg.mid; + this.ip = blg.ip; + this.mac = blg.mac; + this.devices = blg.devices; + return true; + } + catch (Exception e) { + Debug.Log(e.ToString()); + return false; + } } public string getException() { - throw new System.NotImplementedException(); + return exceptionMsg; } } } diff --git a/Assets/MsgTransmitTools/ExtendLinkModel/HttpServer/HttpServerModel.cs b/Assets/MsgTransmitTools/ExtendLinkModel/HttpServer/HttpServerModel.cs index d5061d5..b0ab03b 100644 --- a/Assets/MsgTransmitTools/ExtendLinkModel/HttpServer/HttpServerModel.cs +++ b/Assets/MsgTransmitTools/ExtendLinkModel/HttpServer/HttpServerModel.cs @@ -11,10 +11,10 @@ using System.IO; namespace JXSoft { public class HttpServerModel : DataEventModel { - + protected override void OnInit() { - + } public override void setLinkState(int linkState) diff --git a/Assets/MsgTransmitTools/ExtendLinkModel/HttpServer/HttpServerView.cs b/Assets/MsgTransmitTools/ExtendLinkModel/HttpServer/HttpServerView.cs index 6903f98..6674ada 100644 --- a/Assets/MsgTransmitTools/ExtendLinkModel/HttpServer/HttpServerView.cs +++ b/Assets/MsgTransmitTools/ExtendLinkModel/HttpServer/HttpServerView.cs @@ -8,14 +8,28 @@ using UnityEngine; using QFrameworkCP; namespace JXSoft { - public class HttpServerView : MonoBehaviour + public class HttpServerArchitecture : Architecture + { + protected override void Init() + { + this.RegisterUtility(new HttpServerUtility()); + this.RegisterModel(new HttpServerModel()); + } + } + public class HttpServerView : MonoBehaviour,IController { public string[] prefixes; - public HttpServerUtility httpServer = new HttpServerUtility(); + public HttpServerUtility httpServer; // Start is called before the first frame update void Start() { - //httpServer.startServer(prefixes); + this.httpServer = this.GetUtility(); + this.RegisterEvent(e => { + if (e.res.GetType() == typeof(BluetoothGateway)) { + // + } + }).UnRegisterWhenGameObjectDestroyed(gameObject); + this.GetModel().onReceive(); } // Update is called once per frame @@ -27,7 +41,7 @@ namespace JXSoft { item.GetComponentInChildren().text = tcpUtil.receivedData; this.GetModel().onDataRecived.Invoke(tcpUtil.receivedData); */ - Debug.Log(httpServer.receivedData); + this.GetModel().onDataRecived.Invoke(httpServer.receivedData); } } public void startServer() { @@ -38,6 +52,11 @@ namespace JXSoft { { httpServer.closeServer(); } + + public IArchitecture GetArchitecture() + { + return HttpServerArchitecture.Interface; + } } }