From bfb9e8297311985a2614f73ce288051ecbf9f8b5 Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期四, 04 十一月 2021 11:52:02 +0800
Subject: [PATCH] 2021-11-04-01
---
HDL_ON/DAL/DriverLayer/Control.cs | 45 +++++++++++++++++++++++++++++++++++++--------
1 files changed, 37 insertions(+), 8 deletions(-)
diff --git a/HDL_ON/DAL/DriverLayer/Control.cs b/HDL_ON/DAL/DriverLayer/Control.cs
index f0d20ac..be5293d 100644
--- a/HDL_ON/DAL/DriverLayer/Control.cs
+++ b/HDL_ON/DAL/DriverLayer/Control.cs
@@ -38,6 +38,11 @@
return _control;
}
}
+ /// <summary>
+ /// 璁板綍鎺ユ敹鍒扮殑娑堟伅锛屾柟渚縵b鐨勫伐绋嬪笀璋冭瘯浠栦滑鐨勮澶�
+ /// </summary>
+ public List<string> MsgInfoList = new List<string>();
+
int _msg_id = 1;
/// <summary>
/// 閫氳ID
@@ -279,6 +284,7 @@
else if (DB_ResidenceData.Instance.GatewayType == 1)
{
new Control_Udp().SearchLocalGateway();
+ new Control_Udp().SearchLocalGateway(true);
}
System.Threading.Thread.Sleep(500);
}
@@ -353,7 +359,7 @@
/// <param name="function"></param>
/// <param name="useRemote">鏄惁鐩存帴浣跨敤杩滅▼鍙戦��</param>
/// <returns></returns>
- public void SendWriteCommand(Function function, Dictionary<string, string> commandDictionary, bool useRemote = false)
+ public void SendWriteCommand(Function function, Dictionary<string, string> commandDictionary, bool useRemote = false,int resend = 3)
{
function.controlCounter++;
function.refreshTime = DateTime.Now;
@@ -450,7 +456,7 @@
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);
+ new Control_Udp().SendLocalHdlLinkData(sendBytes, functionControlDataObj.id,resend);
MainPage.Log($"鏈湴閫氳 鍙戦�丠DL-Link鏁版嵁:{functionControlDataJson}");
}
}
@@ -698,9 +704,24 @@
};
var aLinkJson = Newtonsoft.Json.JsonConvert.SerializeObject(aLinkData);
var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlScene, aLinkJson);
- new Control_Udp().SendLocalHdlLinkData(sendBytes, aLinkData.id);
+ new Control_Udp().SendLocalHdlLinkData(sendBytes, aLinkData.id,0);
}
}
+ /// <summary>
+ /// 缃戝叧杩涘叆閰嶇綉妯″紡
+ /// </summary>
+ public void AuthGateway()
+ {
+ var objects1 = new { spk = "", time = "180" };
+ //{"objects":[{"spk":"","time":"180"}],"id":"8","time_stamp":"1635241216669"}
+ var sendId = Ins.msg_id.ToString();
+ var sendObj = new { objects = objects1, id = sendId, time_stamp = Utlis.GetTimestamp() };
+
+ var aLinkJson = Newtonsoft.Json.JsonConvert.SerializeObject(sendObj);
+ var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.AuthGateway, aLinkJson);
+ new Control_Udp().SendLocalHdlLinkData(sendBytes, Ins.msg_id.ToString());
+ }
+
/// <summary>
/// 杞崲鍙戦�佹暟鎹�
/// </summary>
@@ -723,7 +744,7 @@
//1.鎷兼帴澶�
string topicString = "Topic:" + topic + "\r\n";
//2.Body瀛楃涓茶浆涓篵yte鏁扮粍
- byte[] bodyBytes = Encoding.ASCII.GetBytes(bodyDataString);
+ byte[] bodyBytes = Encoding.UTF8.GetBytes(bodyDataString);
//鍒ゆ柇鏄惁闇�鍔犲瘑Body鏁版嵁
if (isEncryption && IsLocalEncryptAndGetAesKey)
{
@@ -734,7 +755,7 @@
//3.鎷兼帴body鐨凩ength闀垮害鏁版嵁
string lengthString = "Length:" + bodyBytes.Length.ToString() + "\r\n" + "\r\n";
string topicAndLengthString = topicString + lengthString;
- byte[] topicAndLengthBytes = Encoding.ASCII.GetBytes(topicAndLengthString);
+ byte[] topicAndLengthBytes = Encoding.UTF8.GetBytes(topicAndLengthString);
//4.鎷兼帴鍚堝苟 Topic 鍜� body鐨刡yte鏁扮粍鏁版嵁
byte[] sendDataBytes = new byte[topicAndLengthBytes.Length + bodyBytes.Length];
topicAndLengthBytes.CopyTo(sendDataBytes, 0);
@@ -750,10 +771,10 @@
/// 杞崲鎺ユ敹鍒扮殑鏁版嵁
/// </summary>
/// <returns></returns>
- public void ConvertReceiveData(byte[] receiveBytes)
+ public void ConvertReceiveData(byte[] receiveBytes,string ip)
{
var reString = Encoding.UTF8.GetString(receiveBytes);
- AnalysisReceiveData(reString, receiveBytes);
+ AnalysisReceiveData(reString, receiveBytes,ip);
}
/// <summary>
/// 杞崲鎺ユ敹鍒扮殑鏁版嵁
@@ -761,7 +782,7 @@
/// <param name="receiveString">杞琒tring鍚庣殑鏁版嵁</param>
/// <param name="originalReceiveBytes"鍘熷Bytes鏁版嵁</param>
/// <returns></returns>
- public LocalCommunicationData AnalysisReceiveData(string receiveString, byte[] originalReceiveBytes)
+ public LocalCommunicationData AnalysisReceiveData(string receiveString, byte[] originalReceiveBytes , string sIp = null)
{
LocalCommunicationData receiveObj = new LocalCommunicationData();
@@ -814,6 +835,10 @@
var revString = Encoding.UTF8.GetString(receiveBytes);
receiveObj.BodyDataString = revString;
MainPage.Log($"灞�鍩熺綉淇℃伅: 瑙e瘑鍚庯細" + receiveObj.BodyDataString);
+ if(receiveObj.Topic.EndsWith("/thing/property/up"))
+ {
+ MsgInfoList.Add(revString + "\r\n");
+ }
}
else
{
@@ -854,6 +879,10 @@
{
Ins.GatewayId = device.device_mac;
}
+ if (!string.IsNullOrEmpty(sIp))
+ {
+ device.ip_address = sIp;
+ }
reportIp = device.ip_address;//涓绘挱鍦板潃涔熻兘鎺у埗璁惧//"239.0.168.188";//
//2021-09-23 鏂板鑾峰彇褰撳墠缃戝叧鏄惁鏈湴鍔犲瘑
Ins.IsLocalEncrypt = device.isLocalEncrypt;
--
Gitblit v1.8.0