From 47769b2c2554d2b0f37237c1658044bd3a5bb6f7 Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期二, 27 九月 2022 14:05:03 +0800
Subject: [PATCH] 光伏更新
---
HDL_ON/DAL/DriverLayer/Control.cs | 233 +++++++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 196 insertions(+), 37 deletions(-)
diff --git a/HDL_ON/DAL/DriverLayer/Control.cs b/HDL_ON/DAL/DriverLayer/Control.cs
index 9e2364b..c1150a7 100644
--- a/HDL_ON/DAL/DriverLayer/Control.cs
+++ b/HDL_ON/DAL/DriverLayer/Control.cs
@@ -4,26 +4,12 @@
using HDL_ON.DAL.Server;
using HDL_ON.Entity;
using HDL_ON.UI;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
using Shared;
namespace HDL_ON.DriverLayer
{
- /// <summary>
- /// 閫氳鏂瑰紡
- /// </summary>
- public enum CommunicationMode
- {
- none,
- /// <summary>
- /// 鏈湴udp
- /// </summary>
- local_BusUdp,
- /// <summary>
- /// 鏈湴tcp瀹㈡埛绔�
- /// </summary>
- tcp_local_client,
- }
-
public class Control
{
@@ -43,6 +29,27 @@
/// 璁板綍鎺ユ敹鍒扮殑娑堟伅锛屾柟渚縵b鐨勫伐绋嬪笀璋冭瘯浠栦滑鐨勮澶�
/// </summary>
public List<string> MsgInfoList = new List<string>();
+ private bool _LocalTcpClientLogin = false;
+ /// <summary>
+ /// 鏈湴tcp瀹㈡埛绔繛鎺ユ槸鍚︽垚鍔�
+ /// 鏄惁鐧诲綍缃戝叧鎴愬姛
+ /// </summary>
+ public bool LocalTcpClientLogin
+ {
+ get
+ {
+ return _LocalTcpClientLogin;
+ }
+ set
+ {
+ _LocalTcpClientLogin = value;
+ if (!value)
+ {
+ loginGatewayThread?.Abort();
+ loginGatewayThread = null;
+ }
+ }
+ }
int _msg_id = 1;
/// <summary>
@@ -200,11 +207,6 @@
public Control_Udp myUdp1 = null;
/// <summary>
- /// 閫氳鏂瑰紡
- /// </summary>
- public CommunicationMode communicationMode;
-
- /// <summary>
/// 鎵撳紑tcp鏈嶅姟绔�
/// </summary>
public void OpenTcpServer()
@@ -236,8 +238,9 @@
if (myTcpClient == null)
{
myTcpClient = new Control_TcpClient(reportIp);
- myTcpClient.Connect();
}
+ myTcpClient.Connect();
+
}
/// <summary>
@@ -297,6 +300,57 @@
}
}
+
+ private System.Threading.Thread loginGatewayThread;
+
+ /// <summary>
+ /// 鐧诲綍缃戝叧
+ /// </summary>
+ public void LoginGateway()
+ {
+ if(loginGatewayThread== null)
+ {
+ loginGatewayThread = new System.Threading.Thread(() => {
+ while (!Ins.myTcpClient.isConnected)
+ {
+ if (Ins.GatewayOnline_Local && myTcpClient.isConnected)
+ {
+ var sendData = new { clientType = "app", version = "1.0" };
+ var sendJob = new { id = Control.Ins.msg_id.ToString(), time_stamp = Utlis.GetTimestamp(), objects = sendData };
+
+ var bodyString = JsonConvert.SerializeObject(sendJob);
+
+ var sendBytes = ConvertSendBodyData($"/user/{GatewayId}/custom/gateway/login", bodyString);
+
+ Ins.myTcpClient.SendMessage(sendBytes);
+ }
+ System.Threading.Thread.Sleep(2000);
+ }
+ //loginGatewayThread?.Abort();
+ //loginGatewayThread = null;
+
+ });
+ loginGatewayThread.Start();
+ }
+ else
+ {
+ try
+ {
+ loginGatewayThread?.Abort();
+ }catch (Exception ex)
+ {
+ MainPage.Log($"閲嶅惎鐧诲綍缃戝叧绾跨▼寮傚父:{ex.Message}");
+ }
+ finally
+ {
+ loginGatewayThread = null;
+ LoginGateway();
+ }
+ }
+
+ }
+
+
/// <summary>
/// 鍦烘櫙鎺у埗鍏ュ彛
/// </summary>
@@ -342,15 +396,6 @@
}
}
}
- /// <summary>
- /// 瀹夐槻鎺у埗
- /// </summary>
- public void ControlArm()
- {
- DAL.Server.HttpServerRequest httpServer = new DAL.Server.HttpServerRequest();
- //var pack = httpServer.GetSecurityAlarmLogList
- }
-
/// <summary>
/// 鍙戦�佸懡浠�
@@ -792,6 +837,33 @@
new Control_Udp().SendLocalHdlLinkData(sendBytes, aLinkData.id,0);
}
}
+
+
+ /// <summary>
+ /// 鑾峰彇闊充箰鐩綍
+ /// </summary>
+ public void GetMusicDirectory(Function function)
+ {
+ if (Ins.GatewayOnline_Local)
+ {
+ var objects = new List<Dictionary<string, string>>();
+ var readKey = new Dictionary<string, string>();
+ readKey.Add("sid", function.sid);
+ objects.Add(readKey);
+ var readDataObj = new AlinkReadFunctionStatusObj()
+ {
+ id = Ins.msg_id.ToString(),
+ objects = objects,
+ time_stamp = Utlis.GetTimestamp()
+ };
+ var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(readDataObj);
+ var sendBytes = Ins.ConvertSendBodyData($"/base/{DB_ResidenceData.Instance.HomeGateway.gatewayId}/thing/service/MusicPlayGroupListGet/down", functionControlDataJson);
+ MainPage.Log($"鏈湴閫氳 鍙戦�丠DL-Link鏁版嵁:{functionControlDataJson}");
+ new Control_Udp().SendLocalHdlLinkData(sendBytes, readDataObj.id);
+ }
+
+ }
+
/// <summary>
/// 缃戝叧杩涘叆閰嶇綉妯″紡
/// </summary>
@@ -871,7 +943,6 @@
{
LocalCommunicationData receiveObj = new LocalCommunicationData();
- MainPage.Log($"灞�鍩熺綉淇℃伅: \r\n{receiveString}");
var res = receiveString.Split("\r\n\r\n");
@@ -903,13 +974,19 @@
//}
receiveObj.BodyDataString = res[1];
+ if (receiveObj.Topic == CommunicationTopic.ct.HeartBeat + "_reply")
+ {
+ Ins.myTcpClient.ClearHeartBeatLog();
+ MainPage.Log("tcp蹇冭烦鍥炲");
+ return null;
+ }
+
//2021-09-23 杩囨护涓嶉渶瑕佽В瀵嗙殑涓婚 鐩墠鎼滅储缃戝叧涓婚涓嶅姞瀵�
if (receiveObj.Topic != CommunicationTopic.SearchLoaclGatewayReply)
{
//鍒ゆ柇褰撳墠缃戝叧鏄惁寮�鍚簡鏈湴鍔犲瘑
if (IsLocalEncryptAndGetAesKey)
{
- MainPage.Log($"灞�鍩熺綉淇℃伅 寮�濮嬭В瀵�");
if (originalReceiveBytes != null)
{
//鎷垮埌鍘熷Bytes鏁版嵁鍘昏В瀵�
@@ -941,8 +1018,27 @@
}
}
+ else
+ {
+ MainPage.Log($"灞�鍩熺綉淇℃伅: 鏄庢枃锛�" + receiveObj.BodyDataString);
+ }
}
+ try
+ {
+ var idMsg = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack>(res[1]);
+ var hasProcess = hasItBeenProcessed(idMsg.id);
+ if (hasProcess)
+ {
+ return null;
+ }
+ MainPage.Log($"澶勭悊灞�鍩熺綉鏁版嵁id:{idMsg.id}");
+
+ }
+ catch (Exception ex)
+ {
+ MainPage.Log($"瑙f瀽灞�鍩熺綉鏁版嵁寮傚父{ex.Message}");
+ }
if (receiveObj.Topic == CommunicationTopic.SearchLoaclGatewayReply || receiveObj.Topic == CommunicationTopic.GatewayBroadcast)
{
@@ -975,17 +1071,21 @@
//2021-09-23 鏂板鑾峰彇褰撳墠缃戝叧鏄惁鏈湴鍔犲瘑
Ins.IsLocalEncrypt = device.isLocalEncrypt;
//MainPage.Log("缃戝叧鏈湴鍔犲瘑鐘舵�侊細" + device.local_encrypt.ToString());
+
+ OpenTcpClent();
+
+
}
}
else if (receiveObj.Topic == CommunicationTopic.ct.ReadStatus + "_reply" ||
receiveObj.Topic == CommunicationTopic.ct.ControlFunctionTopic + "_reply" ||
receiveObj.Topic == CommunicationTopic.ct.GatewayUpStatus ||
- receiveObj.Topic.Contains( CommunicationTopic.ct.GatewayUpSortTopic))
+ receiveObj.Topic.Contains(CommunicationTopic.ct.GatewayUpSortTopic))
{
//TODO 鏆傛椂涓嶄紶姝g‘鐨勬暟鎹笂鍘伙紝濡傛灉鍚庨潰瑕佷紭鍖栧墠闈㈣繖浜涗唬鐮�
UpdataFunctionStatus(receiveObj.BodyDataString, null);
}
- else if (receiveObj.Topic == CommunicationTopic.ct.ControlSeurity +"_reply"
+ else if (receiveObj.Topic == CommunicationTopic.ct.ControlSeurity + "_reply"
|| receiveObj.Topic == CommunicationTopic.ct.ReadSecurityStatus + "_reply"
|| receiveObj.Topic == CommunicationTopic.ct.SecurityStatusUp)
{
@@ -993,7 +1093,8 @@
{
MainPage.Log($"灞�鍩熺綉瀹夐槻淇℃伅: {receiveObj.Topic} : 鍐呭: {res[1]}");
var tt = "";
- lock (tt) {
+ lock (tt)
+ {
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<SecurityStatusObj>(receiveObj.BodyDataString);
if (temp != null)
{
@@ -1012,8 +1113,29 @@
}
}
}
- catch (Exception ex){
+ catch (Exception ex)
+ {
MainPage.Log($"瀹夐槻灞�鍩熺綉寮傚父锛歿ex.Message}");
+ }
+ }
+ else if (receiveObj.Topic == $"/user/{GatewayId}/custom/gateway/login_reply") {
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<JObject>(receiveObj.BodyDataString);
+ if (temp.GetValue("objects").ToString().Contains("success"))
+ {
+ LocalTcpClientLogin = true;
+ try
+ {
+ loginGatewayThread?.Abort();
+ }
+ catch (Exception ex)
+ {
+ MainPage.Log($"缁堟鐧诲綍缃戝叧tcp寮傚父锛歿ex.Message}");
+ }
+ finally
+ {
+ loginGatewayThread = null;
+ }
+ MainPage.Log("灞�鍩熺綉tcp杩炴帴鐧诲綍缃戝叧鎴愬姛");
}
}
else
@@ -1023,6 +1145,29 @@
}
}
return receiveObj;
+ }
+
+
+ private List<string> processedDataList = new List<string>();
+ /// <summary>
+ /// 鏄惁宸茬粡澶勭悊杩囨暟鎹�
+ /// </summary>
+ /// <returns></returns>
+ private bool hasItBeenProcessed(string msgId)
+ {
+ if (processedDataList.Contains(msgId))
+ {
+ return true;
+ }
+ else
+ {
+ if(processedDataList.Count> 50)
+ {
+ processedDataList.RemoveAt(0);
+ }
+ return false;
+ }
+
}
/// <summary>
@@ -1102,6 +1247,13 @@
//鏇存柊鐣岄潰鐘舵��
switch (localFunction.spk)
{
+ case SPK.AcstParent:
+ AcstParentPage.UpdateAcstParentInfo(localFunction);
+ break;
+ case SPK.AcstSub:
+ AcstParentPage.UpdateAcstSubInfo(localFunction);
+ AcstSubPage.UpdateStatus(localFunction);
+ break;
case SPK.AirSwitch:
AirSwitchPage.UpdataState(localFunction);
if(localFunction.GetAttribute(FunctionAttributeKey.Power)!=null)//濡傛灉鏄甫鐢甸噺鐨勭┖寮�涔熻鏇存柊鑳芥簮鐣岄潰
@@ -1281,6 +1433,7 @@
case SPK.HvacAirFresh:
case SPK.SensorGas:
case SPK.HvacCac:
+ case SPK.SensorHelp:
//璁惧鐘舵�佹帹閫�
//鐘舵�佹洿鏂�
Stan.HdlDeviceStatuPushLogic.Current.UpdateDeviceStatu(updateTemp.sid, updateTemp.status);
@@ -1334,6 +1487,12 @@
//Console.WriteLine("闊充箰鎾斁鍣ㄦ樉绀虹姸鎬�======="+ revString);
//wjc
break;
+ case SPK.Inverter:
+ MainPage.Log("閫嗗彉鍣ㄦ暟鎹洿鏂�");
+ var status = new Dictionary<string, object> { ["method"] = "status", ["data"] = temp.objects };
+ //var dd = Newtonsoft.Json.JsonConvert.SerializeObject(status);
+ Inverter.Ins.H5Page.CallJS($"nativeToJs(\'{Newtonsoft.Json.JsonConvert.SerializeObject(status)}\')");
+ break;
}
HomePage.UpdataFunctionStates(localFunction);
--
Gitblit v1.8.0