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; + } } }