| | |
| | | |
| | | public class Control |
| | | { |
| | | |
| | | |
| | | static Control _control; |
| | | public static Control Ins |
| | | { |
| | |
| | | return t.ToString(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 是否搜索本地网关成功 |
| | | /// </summary> |
| | | public bool IsSearchLocalGatewaySuccessful = false; |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | bool _gatewayOnline = false; |
| | | /// <summary> |
| | | /// 网关是否在线 |
| | |
| | | { |
| | | MainPage.Log($"搜索本地网关列表,网关类型:{DB_ResidenceData.Instance.GatewayType}"); |
| | | if (MainPage.InternetStatus == 0) |
| | | return; |
| | | OpenUdp(DB_ResidenceData.Instance.GatewayType == 0 ? 6000 : 8585); |
| | | new System.Threading.Thread(() => |
| | | { |
| | | for (int i = 0; i < 5; i++) |
| | | { |
| | | if (GatewayOnline) |
| | | break; |
| | | if (DB_ResidenceData.Instance.GatewayType == 0) |
| | | { |
| | | new Control_Udp().ControlBytesSend(Command.ReadGateway, 255, 255, new byte[] { (byte)new Random().Next(255), (byte)new Random().Next(255) }); |
| | | } |
| | | else if (DB_ResidenceData.Instance.GatewayType == 1) |
| | | { |
| | | new Control_Udp().SearchLocalGateway(); |
| | | } |
| | | System.Threading.Thread.Sleep(500); |
| | | } |
| | | if (!GatewayOnline)//网关不在线的时候才可尝试远程连接 |
| | | Ins.GatewayOnline = false; |
| | | return; |
| | | } |
| | | else if (MainPage.InternetStatus == 1) |
| | | { |
| | | if (!Ins.IsRemote) |
| | | { |
| | | Ins.IsRemote = true; |
| | | DAL.Mqtt.MqttClient.InitState(); |
| | | } |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | } |
| | | else if (MainPage.InternetStatus == 2) |
| | | { |
| | | OpenUdp(DB_ResidenceData.Instance.GatewayType == 0 ? 6000 : 8585); |
| | | //重置搜索网关标志 |
| | | IsSearchLocalGatewaySuccessful = false; |
| | | |
| | | new System.Threading.Thread(() => |
| | | { |
| | | for (int i = 0; i < 5; i++) |
| | | { |
| | | if (IsSearchLocalGatewaySuccessful) |
| | | break; |
| | | if (DB_ResidenceData.Instance.GatewayType == 0) |
| | | { |
| | | new Control_Udp().ControlBytesSend(Command.ReadGateway, 255, 255, new byte[] { (byte)new Random().Next(255), (byte)new Random().Next(255) }); |
| | | } |
| | | else if (DB_ResidenceData.Instance.GatewayType == 1) |
| | | { |
| | | new Control_Udp().SearchLocalGateway(); |
| | | } |
| | | System.Threading.Thread.Sleep(500); |
| | | } |
| | | |
| | | if (!IsSearchLocalGatewaySuccessful) |
| | | { |
| | | //本地搜索不到网关 |
| | | if (!Ins.IsRemote) |
| | | { |
| | | Ins.IsRemote = true; |
| | | DAL.Mqtt.MqttClient.InitState(); |
| | | } |
| | | } |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceModule>(bodyJObj.objects.ToString()); |
| | | if (device.device_mac == DB_ResidenceData.Instance.residenceGatewayMAC) |
| | | { |
| | | //本地搜索网关成功 |
| | | Control.Ins.IsSearchLocalGatewaySuccessful = true; |
| | | Ins.GatewayOnline = true; |
| | | if (!string.IsNullOrEmpty(device.gatewayId)) |
| | | { |