using System.Collections; using System.Collections.Generic; using UnityEngine; using LitJson; using System; using JXSoft; namespace DYData { public struct BluetoothGatewayData:IResponse { /// /// /// public int v { get; set; } /// /// /// public int mid { get; set; } /// /// /// public int time { get; set; } /// /// 用时 /// public string ip { get; set; } /// /// 地址 /// public string mac { get; set; } /// /// 设备信息 /// public List> devices { get; set; } private string exceptionMsg; 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() { 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) { try { BluetoothGatewayData 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() { return exceptionMsg; } } }