Browse Source

新增蓝牙网关数据筛选

master
DESKTOP-B25GA9E\W35 2 years ago
parent
commit
7e0da80982
  1. 43
      Assets/MsgTransmitTools/DataClass/BluetoothGateway.cs
  2. 27
      Assets/MsgTransmitTools/ExtendLinkModel/HttpServer/HttpServerView.cs

43
Assets/MsgTransmitTools/DataClass/BluetoothGateway.cs

@ -2,6 +2,7 @@ @@ -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 { @@ -29,21 +30,55 @@ namespace JXSoft {
/// <summary>
/// 设备信息
/// </summary>
public List<List<int>> devices { get; set; }
public List<List<object>> devices { get; set; }
private string exceptionMsg;
public BluetoothGateway() {
}
public string findDataByMac(string mac) {
foreach (List<object> 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<BluetoothGateway>(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;
}
}
}

27
Assets/MsgTransmitTools/ExtendLinkModel/HttpServer/HttpServerView.cs

@ -8,14 +8,28 @@ using UnityEngine; @@ -8,14 +8,28 @@ using UnityEngine;
using QFrameworkCP;
namespace JXSoft {
public class HttpServerView : MonoBehaviour
public class HttpServerArchitecture : Architecture<HttpServerArchitecture>
{
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<HttpServerUtility>();
this.RegisterEvent<ResponseMsgEvent>(e => {
if (e.res.GetType() == typeof(BluetoothGateway)) {
//
}
}).UnRegisterWhenGameObjectDestroyed(gameObject);
this.GetModel<HttpServerModel>().onReceive<BluetoothGateway>();
}
// Update is called once per frame
@ -27,7 +41,7 @@ namespace JXSoft { @@ -27,7 +41,7 @@ namespace JXSoft {
item.GetComponentInChildren<Text>().text = tcpUtil.receivedData;
this.GetModel<TCPClientModel>().onDataRecived.Invoke(tcpUtil.receivedData);
*/
Debug.Log(httpServer.receivedData);
this.GetModel<HttpServerModel>().onDataRecived.Invoke(httpServer.receivedData);
}
}
public void startServer() {
@ -38,6 +52,11 @@ namespace JXSoft { @@ -38,6 +52,11 @@ namespace JXSoft {
{
httpServer.closeServer();
}
public IArchitecture GetArchitecture()
{
return HttpServerArchitecture.Interface;
}
}
}

Loading…
Cancel
Save