From 014abc547ffd1a9f23c58fd7a471dffc5933fdd3 Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期四, 17 十二月 2020 14:27:56 +0800
Subject: [PATCH] Merge branch 'master' into NewFilePath
---
HDL_ON/DAL/DriverLayer/UdpSocket.cs | 10 +-
HDL_ON/UI/UI2/4-PersonalCenter/SearchDevice/SearchDevicePage.cs | 62 +++++++-------
HDL_ON/DAL/DriverLayer/Packet.cs | 4
HDL_ON/DAL/DriverLayer/Control.cs | 45 ++++-------
HDL_ON/DAL/DriverLayer/Control_Udp.cs | 59 +++++++-------
HDL_ON/DAL/Mqtt/MqttClient.cs | 2
6 files changed, 85 insertions(+), 97 deletions(-)
diff --git a/HDL_ON/DAL/DriverLayer/Control.cs b/HDL_ON/DAL/DriverLayer/Control.cs
index e8215ad..dcd5410 100644
--- a/HDL_ON/DAL/DriverLayer/Control.cs
+++ b/HDL_ON/DAL/DriverLayer/Control.cs
@@ -123,7 +123,7 @@
/// <summary>
/// 鏈湴udp
/// </summary>
- public Control_Udp myUdp = null;
+ public Control_Udp myUdp1 = null;
/// <summary>
/// 閫氳鏂瑰紡
@@ -144,11 +144,6 @@
/// </summary>
public void OpenUdp(int port)
{
- if (myUdp == null)
- {
- myUdp = new Control_Udp();
- }
-
UdpSocket._BusSocket.Start(port);
}
/// <summary>
@@ -156,10 +151,6 @@
/// </summary>
public void CloseUdp()
{
- if (myUdp != null)
- {
- myUdp = null;
- }
UdpSocket._BusSocket.Stop();
}
@@ -197,11 +188,11 @@
break;
if (DB_ResidenceData.Instance.GatewayType == 0)
{
- myUdp.ControlBytesSend(Command.ReadGateway, 255, 255, new byte[] { (byte)new Random().Next(255), (byte)new Random().Next(255) });
+ 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)
{
- myUdp.SearchLocalGateway();
+ new Control_Udp().SearchLocalGateway();
}
System.Threading.Thread.Sleep(500);
}
@@ -227,7 +218,7 @@
{
if (DB_ResidenceData.Instance.GatewayType == 0)
{
- myUdp.ControlBusScenes(scene);
+ new Control_Udp().ControlBusScenes(scene);
}
}
}
@@ -264,10 +255,7 @@
{
try
{
- if (myUdp != null)
- {
- myUdp.WriteBusData(function, commandDictionary);
- }
+ new Control_Udp().WriteBusData(function, commandDictionary);
}
catch (Exception ex)
{
@@ -277,13 +265,10 @@
//ALink鎺у埗
else
{
- if (myUdp != null)
- {
- var functionControlDataObj = function.GetGatewayAlinkControlData(commandDictionary);
- var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(functionControlDataObj);
- var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlFunctionTopic, functionControlDataJson);
- Ins.myUdp.SendLocalHdlLinkData(sendBytes);
- }
+ var functionControlDataObj = function.GetGatewayAlinkControlData(commandDictionary);
+ var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(functionControlDataObj);
+ var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlFunctionTopic, functionControlDataJson);
+ new Control_Udp().SendLocalHdlLinkData(sendBytes, functionControlDataObj.id);
}
}
}
@@ -312,7 +297,7 @@
{
try
{
- Ins.myUdp.ReadBusData(function);
+ new Control_Udp().ReadBusData(function);
}
catch (Exception ex)
{
@@ -335,7 +320,7 @@
};
var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(readDataObj);
var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ReadStatus, functionControlDataJson);
- Ins.myUdp.SendLocalHdlLinkData(sendBytes);
+ new Control_Udp().SendLocalHdlLinkData(sendBytes,readDataObj.id);
}
}
}
@@ -381,7 +366,7 @@
};
var aLinkJson = Newtonsoft.Json.JsonConvert.SerializeObject(aLinkData);
var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlScene, aLinkJson);
- Ins.myUdp.SendLocalHdlLinkData(sendBytes);
+ new Control_Udp().SendLocalHdlLinkData(sendBytes,aLinkData.id);
}
}
/// <summary>
@@ -469,7 +454,8 @@
else if(receiveObj.Topic == CommunicationTopic.ct.ReadStatus+"_reply" ||
receiveObj.Topic == CommunicationTopic.ct.GatewayUpStatus)
{
- UpdataFunctionStatus(receiveObj.BodyDataString);
+ //TODO 鏆傛椂涓嶄紶姝g‘鐨勬暟鎹笂鍘伙紝濡傛灉鍚庨潰瑕佷紭鍖栧墠闈㈣繖浜涗唬鐮�
+ UpdataFunctionStatus(receiveObj.BodyDataString,null);
}
}
return receiveObj;
@@ -480,7 +466,7 @@
/// A鍗忚鏁版嵁
/// </summary>
/// <param name="updateBytes"></param>
- public void UpdataFunctionStatus(string revString)
+ public void UpdataFunctionStatus(string revString,byte []usefulBytes)
{
MainPage.Log($"A鍗忚鏇存柊鐘舵��:{revString}");
if(Control.Ins.myUdp!= null)
@@ -491,6 +477,7 @@
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<AlinkFunctionStatusObj>(revString);
if (temp != null)
{
+ Control_Udp.ReceiveRepeatManager(temp.id,usefulBytes);
var allLocalFuntion = FunctionList.List.GetDeviceFunctionList();
foreach (var updateTemp in temp.objects)
{
diff --git a/HDL_ON/DAL/DriverLayer/Control_Udp.cs b/HDL_ON/DAL/DriverLayer/Control_Udp.cs
index 58f56f0..f678509 100644
--- a/HDL_ON/DAL/DriverLayer/Control_Udp.cs
+++ b/HDL_ON/DAL/DriverLayer/Control_Udp.cs
@@ -29,6 +29,7 @@
/// 鎵�鏈夊涓�绔彛鐨勬帶鍒堕兘浼氭斁鍒拌繖涓泦鍚堥噷
/// </summary>
static List<Control_Udp> controlList = new List<Control_Udp>(50);
+
public System.Net.IPEndPoint EndPoint
{
@@ -65,7 +66,7 @@
/// <summary>
/// 閲嶅彂楠岃瘉
/// </summary>
- public void ReceiveRepeatManager(string receiveFlag)
+ public static void ReceiveRepeatManager(string receiveFlag,byte []usefulBytes)
{
for (int i = 0; i < controlList.Count; i++)
{
@@ -623,7 +624,7 @@
{
for (int i = 0; i < controlList.Count;)
{
- if (controlList[i] == null || 3 <= controlList[i].Packet.HaveSendCount)
+ if (controlList[i] == null || 3 <= controlList[i].packet.HaveSendCount)
{
controlList.RemoveAt(i);
}
@@ -692,7 +693,7 @@
void run()
{
allDone.Set();
- Packet.HaveSendCount = 4;
+ packet.HaveSendCount = 4;
}
//鏁版嵁鍙戦�佸鐞�
@@ -706,7 +707,7 @@
new System.Threading.Thread(() =>
{
System.Threading.Thread.Sleep(1000);
- UdpSocket._BusSocket.Start(6000);
+ UdpSocket._BusSocket.Start(UdpSocket._BusSocket.Port);
controlLostCount = 0;
})
{ IsBackground = true }.Start();
@@ -714,17 +715,17 @@
try
{
- MainPage.Log("鍙戦�佹暟鎹�:" + SendFlag);
- UdpSocket._BusSocket.AsyncBeginSend(Packet);
- Packet.HaveSendCount--;
+ //MainPage.Log("鍙戦�佹暟鎹�:" + SendFlag);
+ UdpSocket._BusSocket.AsyncBeginSend(packet);
+ packet.HaveSendCount--;
//杩欓噷鏄噸鍙戜袱娆�
- while (Packet.HaveSendCount < 3)
+ while (packet.HaveSendCount < 3)
{
- if (Packet.FlagDateTime.AddMilliseconds(1000).Ticks <= DateTime.Now.Ticks)
+ if (packet.FlagDateTime.AddMilliseconds(1000).Ticks <= DateTime.Now.Ticks)
{
MainPage.Log("閲嶅彂鏁版嵁:" + SendFlag);
- UdpSocket._BusSocket.AsyncBeginSend(Packet);
+ UdpSocket._BusSocket.AsyncBeginSend(packet);
controlLostCount++;
}
System.Threading.Thread.Sleep(100);
@@ -743,7 +744,7 @@
/// <summary>
/// 褰撳墠鏁版嵁鍖�
/// </summary>
- Packet Packet;
+ Packet packet;
/// <summary>
/// 璁板綍鍙戦�佹暟鎹寘
/// </summary>
@@ -800,14 +801,14 @@
{
try
{
- Packet = new Packet(target.SendBytes, target.IPEndPoint);
- Packet.HaveSendCount = 3 - sendCount;
+ packet = new Packet(target.SendBytes, target.IPEndPoint);
+ packet.HaveSendCount = 3 - sendCount;
signPacket(target);
System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(managerSendCount));
thread.IsBackground = true;
- thread.Start(Packet);
+ thread.Start(packet);
if (isWait)
{
@@ -832,11 +833,11 @@
var sendBytes = Control.Ins.ConvertSendBodyData(CommunicationTopic.SearchLoaclGateway, bodyString);
//缁勬挱鍙戦��
- Packet = new Packet(sendBytes, new System.Net.IPEndPoint(System.Net.IPAddress.Parse("239.0.168.188"), 8585));
- Packet.HaveSendCount = 4;//ps锛氭病鏈夐噸鍙戯紝鍚庢湡鏈夋椂闂村彲浠ュ鍔犻噸鍙戝垽鏂�
+ packet = new Packet(sendBytes, new System.Net.IPEndPoint(System.Net.IPAddress.Parse("239.0.168.188"), 8585));
+ packet.HaveSendCount = 4;//ps锛氭病鏈夐噸鍙戯紝鍚庢湡鏈夋椂闂村彲浠ュ鍔犻噸鍙戝垽鏂�
System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(managerSendCount));
thread.IsBackground = true;
- thread.Start(Packet);
+ thread.Start(packet);
//wait();涓嶉渶瑕佺瓑寰�
}
catch (Exception ex)
@@ -844,24 +845,24 @@
MainPage.Log($"Send bus data error {ex.Message}");
}
}
+
+
/// <summary>
/// 鍙戦�乽dp A鍗忚鏁版嵁
/// </summary>
- public void SendLocalHdlLinkData(byte[] sendBytes)
+ public void SendLocalHdlLinkData(byte[] sendBytes,string id, bool isWait=false)
{
- if (controlLostCount > 3)
- {
- UdpSocket._BusSocket.Stop();
- UdpSocket._BusSocket.Start(8585);
- controlLostCount = 0;
- }
- Packet = new Packet(sendBytes, new System.Net.IPEndPoint(System.Net.IPAddress.Parse(Control.Ins.reportIp), 8585));
- Packet.HaveSendCount = 2;//ps锛氭病鏈夐噸鍙戯紝鍚庢湡鏈夋椂闂村彲浠ュ鍔犻噸鍙戝垽鏂�
-
+ packet = new Packet(sendBytes, new System.Net.IPEndPoint(System.Net.IPAddress.Parse(Control.Ins.reportIp), 8585));
+ sendFlag = id;
System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(managerSendCount));
thread.IsBackground = true;
- thread.Start(Packet);
- controlLostCount++;
+ thread.Start(packet);
+ if (isWait)
+ {
+ wait();
+ }
+ //MainPage.Log($"鍙戦�丠dl-Link鏁版嵁锛孖P:{Control.Ins.reportIp}:8585");
}
}
+
}
diff --git a/HDL_ON/DAL/DriverLayer/Packet.cs b/HDL_ON/DAL/DriverLayer/Packet.cs
index 3e18471..4fb8e85 100644
--- a/HDL_ON/DAL/DriverLayer/Packet.cs
+++ b/HDL_ON/DAL/DriverLayer/Packet.cs
@@ -642,12 +642,12 @@
receiveFlag += string.Format("{0},{1}", usefulBytes[0], usefulBytes[1]);
break;
case Command.ReadRemark:
- DriverLayer.Control.Ins.myUdp.ReceiveReadRemark(usefulBytes);
+ new Control_Udp().ReceiveReadRemark(usefulBytes);
break;
default:
break;
}
- DriverLayer.Control.Ins.myUdp.ReceiveRepeatManager(receiveFlag);
+ Control_Udp.ReceiveRepeatManager(receiveFlag,usefulBytes);
}
catch (Exception ex)
{
diff --git a/HDL_ON/DAL/DriverLayer/UdpSocket.cs b/HDL_ON/DAL/DriverLayer/UdpSocket.cs
index 3ffb628..ab3cb02 100644
--- a/HDL_ON/DAL/DriverLayer/UdpSocket.cs
+++ b/HDL_ON/DAL/DriverLayer/UdpSocket.cs
@@ -21,7 +21,7 @@
//鏈湴Socket
private Socket busSocket;
- int _port = 0;
+ public int Port = 0;
/// <summary>
/// 鍚姩Socket鎺ユ敹鍜屽彂閫佸姛鑳�
/// </summary>
@@ -29,7 +29,7 @@
{
if (IsRunning)
{
- if (port == _port)
+ if (port == Port)
{
return;
}
@@ -39,15 +39,15 @@
}
}
if (port != 0)
- _port = port;
- if (_port == 0)
+ Port = port;
+ if (Port == 0)
return;
busSocket = new Socket (AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
busSocket.EnableBroadcast = true;
try {
//busSocket.Bind (new IPEndPoint (IPAddress.Any, 6000));
- busSocket.Bind(new IPEndPoint(IPAddress.Any, _port));
+ busSocket.Bind(new IPEndPoint(IPAddress.Any, Port));
busSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(IPAddress.Parse("239.0.168.188")));
}
diff --git a/HDL_ON/DAL/Mqtt/MqttClient.cs b/HDL_ON/DAL/Mqtt/MqttClient.cs
index b9b58d5..4ddfc8e 100644
--- a/HDL_ON/DAL/Mqtt/MqttClient.cs
+++ b/HDL_ON/DAL/Mqtt/MqttClient.cs
@@ -289,7 +289,7 @@
{
//A鍗忚鏁版嵁澶勭悊
var revString = Encoding.UTF8.GetString(bytes);
- Control.Ins.UpdataFunctionStatus(revString);
+ Control.Ins.UpdataFunctionStatus(revString,null);
}
}
}
diff --git a/HDL_ON/UI/UI2/4-PersonalCenter/SearchDevice/SearchDevicePage.cs b/HDL_ON/UI/UI2/4-PersonalCenter/SearchDevice/SearchDevicePage.cs
index 2077630..22ece99 100644
--- a/HDL_ON/UI/UI2/4-PersonalCenter/SearchDevice/SearchDevicePage.cs
+++ b/HDL_ON/UI/UI2/4-PersonalCenter/SearchDevice/SearchDevicePage.cs
@@ -4,7 +4,7 @@
using Newtonsoft.Json;
using HDL_ON.Entity;
using System.Collections.Generic;
-
+using HDL_ON.DriverLayer;
namespace HDL_ON.UI
{
@@ -35,36 +35,36 @@
deviceIpList.Clear();
contentView.RemoveAll();
//DriverLayer.Control.ins.ChangeCommunicationMode(DriverLayer.CommunicationMode.local_BusUdp);
-// UdpSocket._BusSocket.SearchNetDeviceAction = (jto) =>
-// {
-// var device = JsonConvert.DeserializeObject<DeviceModule>(jto.ToString());
-// if (device != null)
-// {
-// lock (deviceIpList)
-// {
-// if (!deviceIpList.Contains(device.ip_address))
-// {
-// deviceIpList.Add(device.ip_address);
-// MainPage.Log($"鎼滅储鍒扮綉缁滆澶囷細{device.ip_address}");
-// Application.RunOnMainThread(() =>
-// {
-//#if DEBUG
-//#else
-// if(device.gateway_type== 4)
-//#endif
-// {
-// LoadRow(device);
-// }
-// });
-// }
-// else
-// {
-// MainPage.Log($"宸插姞杞借IP璁惧:{device.ip_address}");
-// }
-// }
-// }
-// };
- DriverLayer.Control.Ins.myUdp.SearchLocalGateway();
+ // UdpSocket._BusSocket.SearchNetDeviceAction = (jto) =>
+ // {
+ // var device = JsonConvert.DeserializeObject<DeviceModule>(jto.ToString());
+ // if (device != null)
+ // {
+ // lock (deviceIpList)
+ // {
+ // if (!deviceIpList.Contains(device.ip_address))
+ // {
+ // deviceIpList.Add(device.ip_address);
+ // MainPage.Log($"鎼滅储鍒扮綉缁滆澶囷細{device.ip_address}");
+ // Application.RunOnMainThread(() =>
+ // {
+ //#if DEBUG
+ //#else
+ // if(device.gateway_type== 4)
+ //#endif
+ // {
+ // LoadRow(device);
+ // }
+ // });
+ // }
+ // else
+ // {
+ // MainPage.Log($"宸插姞杞借IP璁惧:{device.ip_address}");
+ // }
+ // }
+ // }
+ // };
+ new Control_Udp().SearchLocalGateway();
contentView.EndHeaderRefreshing();
};
--
Gitblit v1.8.0