From 4f0ab0ad21ce450b7856d50f98322a7899361386 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期二, 22 九月 2020 10:30:01 +0800
Subject: [PATCH] 不要下载这个备份
---
ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs | 2408 +++++++++++++++++++++-------------------------------------
1 files changed, 878 insertions(+), 1,530 deletions(-)
diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs
index a600b98..92b8ced 100755
--- a/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs
+++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs
@@ -8,10 +8,11 @@
using System.Net.Sockets;
using System.Net;
using Newtonsoft.Json.Linq;
-using MQTTnet.Core.Client;
using MQTTnet;
using Shared.Common;
using Shared.Phone.UserView;
+using MQTTnet.Client;
+using System.Threading.Tasks;
namespace ZigBee.Device
{
@@ -21,12 +22,7 @@
[System.Serializable]
public class ZbGateway : ZbGatewayData
{
- public ZbGateway()
- {
- this.Type = DeviceType.ZbGateway;
- }
-
- #region 缃戝叧鐗规畩淇℃伅澶勭悊
+ #region 涓�鍫嗗彉閲�
/// <summary>
/// 涓荤綉鍏�
/// </summary>
@@ -34,54 +30,75 @@
public static ZbGateway MainGateWay
{
get
- {
- return GateWayList.Find((obj) => { return obj.getGatewayBaseInfo.HomeId == Shared.Common.Config.Instance.HomeId && obj.getGatewayBaseInfo.IsMainGateWay; });
+ {
+ ZbGateway mainWay = null;
+ for (int i = 0; i < GateWayList.Count; i++)
+ {
+ if (GateWayList[i].HomeId == Config.Instance.HomeId)
+ {
+ //2020.07.16鍙樻洿:鍒閭d箞澶�,濡傛灉浣忓畢ID涓�鏍�,鍏堢‘瀹氬氨鏄畠浜�(涓嶇劧鏈夋椂鍊欑粡甯歌繑鍥瀗ull,鏈夊彲鑳芥槸鍒锋柊涓嶅埌)
+ mainWay = GateWayList[i];
+ if (mainWay.IsMainGateWay == true)
+ {
+ //鐒跺悗濡傛灉瀹冪‘瀹炴槸涓荤綉鍏�,鐩存帴break
+ break;
+ }
+ }
+ }
+ return mainWay;
}
}
/// <summary>
- /// 涓荤綉鍏�
- /// </summary>
- [Newtonsoft.Json.JsonIgnore]
- public bool IsMainGateWay
- {
- get
- {
- return getGatewayBaseInfo != null && getGatewayBaseInfo.IsMainGateWay;
- }
- }
-
- /// <summary>
- /// 杩滅▼缃戝叧
+ /// 鏄惁浣跨敤杩滅▼杩炴帴妯″紡
/// </summary>
/// <value><c>true</c> if is remote; otherwise, <c>false</c>.</value>
- public static bool IsRemote
- {
- get
- {
- return ZigBee.Device.ZbGateway.RemoteMqttClient != null && ZigBee.Device.ZbGateway.RemoteMqttClient.IsConnected;
- }
- }
+ public static bool IsRemote;
+
+ /// <summary>
+ /// 鏄惁鎷ユ湁杩滅▼杩炴帴鐨勬潈闄�
+ /// </summary>
+ [Newtonsoft.Json.JsonIgnore]
+ public static bool AllowRemoteCtrl = true;
/// <summary>
/// 缃戝叧淇濆瓨璺緞
/// </summary>
/// <value>The file path.</value>
[Newtonsoft.Json.JsonIgnore]
- public override string FilePath
+ public string FilePath
{
get
{
- var deviceType = Type.ToString();
- var fileName = "Gateway_" + deviceType + "_" + this.getGatewayBaseInfo?.gwID;
+ var fileName = "Gateway_" + DeviceType.ZbGateway.ToString() + "_" + this.GwId;
return fileName;
+ }
+ }
+
+ /// <summary>
+ /// 绛夊緟浠庣綉鍏虫帴鏀舵暟鎹殑鏃堕棿
+ /// </summary>
+ /// <value>The wait receive data time.</value>
+ [Newtonsoft.Json.JsonIgnore]
+ public int WaitReceiveDataTime
+ {
+ get
+ {
+ if (Device.ZbGateway.RemoteMqttClient != null && Device.ZbGateway.RemoteMqttClient.IsConnected)
+ {
+ return 10000;
+ }
+ else
+ {
+ return 3000;
+ }
}
}
/// <summary>
/// 灞�鍩熺綉鍔犲瘑瀵嗙爜
/// </summary>
- string password;
+ private string password;
/// <summary>
/// 灞�鍩熺綉鍔犲瘑瀵嗛挜
/// </summary>
@@ -98,27 +115,6 @@
}
}
- #region variable
- /// <summary>
- /// 杩滅▼杩炴帴鎴愬姛鏃剁殑鏃堕棿
- /// </summary>
- public static DateTime LoginRemoteDateTime = DateTime.Now;
-
- /// <summary>
- /// 鍚屾鍒拌繙绋嬬殑褰撳墠鏃堕棿鎴�
- /// </summary>Re
- public static ulong CurrentTimeStamp
- {
- get
- {
- return RemoteTimeStamp + (ulong)(DateTime.Now - LoginRemoteDateTime).TotalSeconds;
- }
- }
-
- /// <summary>
- /// 杩滅▼杩炴帴鎴愬姛鏃剁殑鏃堕棿鎴�
- /// </summary>
- public static ulong RemoteTimeStamp;
/// <summary>
/// 缃戝叧鏄惁鍔犲瘑
/// </summary>
@@ -135,71 +131,6 @@
[Newtonsoft.Json.JsonIgnore]
public static List<ZbGateway> GateWayList = new List<ZbGateway>();
- //褰撳墠缃戝叧涓殑璁惧鍒楄〃
- [Newtonsoft.Json.JsonIgnore]
- public List<CommonDevice> DeviceList = new List<CommonDevice>();
-
- /// <summary>
- /// 鎵�鏈夌綉鍏充腑鐨勮澶囧垪琛�
- /// </summary>
- [Newtonsoft.Json.JsonIgnore]
- public List<CommonDevice> AllGatewayDeviceList = new List<CommonDevice>();
-
- /// <summary>
- /// 缃戝叧涓満鏅垪琛�
- /// 涓�涓満鏅腑鍖呭惈鎵�鏈変俊鎭紝鍖呮嫭鍦烘櫙璁惧淇℃伅
- /// </summary>
- [Newtonsoft.Json.JsonIgnore]
- public static List<Scene.GetSceneAllInfo> AllSceneList = new List<Scene.GetSceneAllInfo>();
-
- /// <summary>
- /// 缃戝叧涓満鏅殑璁惧鍒楄〃
- /// </summary>
- [Newtonsoft.Json.JsonIgnore]
- public List<Scene.GetSceneDeviceListInfo> SceneDeviceList = new List<Scene.GetSceneDeviceListInfo>();
-
- /// <summary>
- /// 缃戝叧涓�昏緫鍒楄〃
- /// </summary>
- [Newtonsoft.Json.JsonIgnore]
- public static List<Logic.GetLogicInfoResponseData> LogicList = new List<Logic.GetLogicInfoResponseData>();
-
- /// <summary>
- /// 缃戝叧涓環dl绉佹湁鎸夐敭缁戝畾鍒楄〃
- /// </summary>
- [Newtonsoft.Json.JsonIgnore]
- public List<HDLbutton> HdlButtonList = new List<HDLbutton>();
-
- //缃戝叧涓柊鐨勮澶囧垪琛�
- [Newtonsoft.Json.JsonIgnore]
- public List<CommonDevice> ListNewDeviceInfoData = new List<CommonDevice>();
-
- /// <summary>
- /// 绉佹湁鎸夐敭淇℃伅鍒楄〃
- /// </summary>
- [Newtonsoft.Json.JsonIgnore]
- public System.Collections.Generic.Dictionary<string, HDLbutton> hdlButtonInfoList = new Dictionary<string, HDLbutton>();
-
- /// <summary>
- /// 浼犳劅鍣ㄤ俊鎭垪琛�
- /// </summary>
- [Newtonsoft.Json.JsonIgnore]
- public System.Collections.Generic.Dictionary<string, Scene.TaskListInfo> sceneTaskInfoList = new Dictionary<string, Scene.TaskListInfo>();
-
- #region action variable
- /// <summary>
- /// 鎺ユ敹鏁版嵁鍚庡洖璋�
- /// </summary>
- [Newtonsoft.Json.JsonIgnore]
- Action<object> action;
- /// <summary>
- /// 璁剧疆鏁版嵁鍥炶皟
- /// </summary>
- public void SetAction(Action<object> action, int timeOut = 1000)
- {
- this.action = action;
- }
-
/// <summary>
/// 缃戝叧鎺ㄩ�佹暟鎹�
/// <para>绗竴涓弬鏁帮細濡傛灉涓� DeviceInComingRespon:璁惧鏂颁笂鎶�</para>
@@ -214,24 +145,15 @@
/// <para>绗竴涓弬鏁帮細濡傛灉涓� ZoneTriggerReport:闃插尯琚Е鍙戞椂鎶ュ憡</para>
/// <para>绗竴涓弬鏁帮細濡傛灉涓� LogicExecuteReport:閫昏緫琚皟鐢ㄥ弽棣�</para>
/// <para>绗竴涓弬鏁帮細濡傛灉涓� TimingWillArrive:鏃堕棿鐐规潯浠舵帹杩熸墽琛�</para>
- /// para>绗竴涓弬鏁帮細 濡傛灉涓� ModeTriggerReport:妯″紡瀹夐槻鍔ㄤ綔琚渶缁堟縺娲绘椂鍙戦�佹姤璀︿俊鎭�</para>
+ /// <para>绗竴涓弬鏁帮細 濡傛灉涓� ModeTriggerReport:妯″紡瀹夐槻鍔ㄤ綔琚渶缁堟縺娲绘椂鍙戦�佹姤璀︿俊鎭�</para>
/// <para>绗竴涓弬鏁帮細濡傛灉涓� EnOrWithdrawSucceedReport:閫氳繃澶栭儴鏂瑰紡甯冮槻鎾ら槻鎴愬姛鏃舵姤鍛婃伅</para>
/// <para>绗竴涓弬鏁帮細濡傛灉涓� PushTargetInfoReport:鑳佽揩瀵嗙爜鎾ら槻鏃剁煭淇℃帹閫�</para>
- /// <para>绗竴涓弬鏁帮細濡傛灉涓� DeviceDefaultAck:鑺傜偣璁惧榛樿鍙嶉</para>
/// <para>绗竴涓弬鏁帮細濡傛灉涓� DDevice/IsGetEpointInfo:鏈夋柊璁惧鍔犲叆zigbee缃戠粶鍙嶉</para>璁惧璇锋眰APP鑾峰彇鍗囩骇鏁版嵁
/// <para>绗竴涓弬鏁帮細濡傛灉涓� Device/DeviceJoinZbNet:鑾峰彇鏂拌澶囨墍鏈夌鐐逛俊鎭槸鍚︽垚鍔熷弽棣�</para>
/// <para>绗竴涓弬鏁帮細濡傛灉涓� DeviceRequestAcUpdateData: 璁惧璇锋眰绌鸿皟鍙戝崌绾ф暟鎹�</para>
/// </summary>
[Newtonsoft.Json.JsonIgnore]
public Action<string, object> ReportAction;
- /// <summary>
- /// 浜戠閫氳閿欒鏁版嵁涓婃姤
- ///<para>"ForwardGatewayNoOnLine", "褰撳墠鎿嶄綔鐨勭綉鍏充笉鍦ㄧ嚎"</para>
- ///<para>"AppTimeOut", "浠庝簯绔幏鍙栨暟鎹秴鏃讹紝璇烽噸鏂拌幏鍙�"</para>
- ///<para>"AppNoLogin", "鐧诲綍杩囨湡锛岃閲嶆柊鐧诲綍"</para>
- /// </summary>
- [Newtonsoft.Json.JsonIgnore]
- public Action<string, string> CloudErrorAction;
/// <summary>
/// 缃戝叧鏂囦欢娴佸唴瀹归�氱煡
@@ -250,8 +172,7 @@
/// </summary>
[Newtonsoft.Json.JsonIgnore]
public Action<string, string> Actions;
- #endregion
- #endregion
+
#endregion
#region 缃戝叧API
@@ -272,8 +193,7 @@
if (topic == gatewayID + "/" + "Error_Respon")
{
- var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
if (temp == null)
{
@@ -281,24 +201,21 @@
}
else
{
- d = new GetGwVersionAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+ d = new GetGwVersionAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "GetZbGwVersionRespon")
{
- var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
- gatewayTemp.getGwVersion = Newtonsoft.Json.JsonConvert.DeserializeObject<GetGwVersionData>(jobject["Data"].ToString());
+ var getGwVersion = Newtonsoft.Json.JsonConvert.DeserializeObject<GetGwVersionData>(jobject["Data"].ToString());
- if (gatewayTemp.getGwVersion == null)
+ if (getGwVersion == null)
{
d = new GetGwVersionAllData { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" };
}
else
{
- d = new GetGwVersionAllData { getGwVersion = gatewayTemp.getGwVersion };
- AppVersion = gatewayTemp.getGwVersion.AppVersion;
- ZigbeeVersion = gatewayTemp.getGwVersion.ZigbeeVersion;
+ d = new GetGwVersionAllData { getGwVersion = getGwVersion };
//Save();
DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{topic}");
}
@@ -350,16 +267,15 @@
if (topic == gatewayID + "/" + "GetZbGwInfo_Respon")
{
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
- var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID };
- gatewayTemp.getGwInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<GetGwData>(jobject["Data"].ToString());
+ var getGwInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<GetGwData>(jobject["Data"].ToString());
- if (gatewayTemp.getGwInfo == null)
+ if (getGwInfo == null)
{
data = new GetGwAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
}
else
{
- data = new GetGwAllData { getGwData = gatewayTemp.getGwInfo };
+ data = new GetGwAllData { getGwData = getGwInfo };
DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{topic}");
}
}
@@ -404,8 +320,7 @@
if (topic == gatewayID + "/" + "Error_Respon")
{
- var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
if (temp == null)
{
@@ -413,13 +328,12 @@
}
else
{
- d = new GetMacResponData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+ d = new GetMacResponData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "ZbGw/GetMac_Respon")
{
- var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<MacAddrData>(jobject["Data"].ToString());
if (tempData == null)
@@ -474,8 +388,7 @@
if (topic == gatewayID + "/" + "Error_Respon")
{
- var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
if (temp == null)
{
@@ -483,22 +396,21 @@
}
else
{
- d = new GwReNameAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+ d = new GwReNameAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "GwReName_Respon")
{
- var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
- gatewayTemp.gwRename = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.GwReNameData>(jobject["Data"].ToString());
+ var gwRename = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.GwReNameData>(jobject["Data"].ToString());
- if (gatewayTemp.gwRename == null)
+ if (gwRename == null)
{
d = new GwReNameAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
}
else
{
- d = new GwReNameAllData { gwReNameData = gatewayTemp.gwRename };
+ d = new GwReNameAllData { gwReNameData = gwRename };
DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
}
}
@@ -557,8 +469,7 @@
if (topic == gatewayID + "/" + "Error_Respon")
{
- var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
if (temp == null)
{
@@ -566,21 +477,20 @@
}
else
{
- d = new GwSetHomeIdAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+ d = new GwSetHomeIdAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "GwSetHomeId_Respon")
{
- var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
- gatewayTemp.gwSetHomeId = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.GwSetHomeIdData>(jobject["Data"].ToString());
- if (gatewayTemp.gwSetHomeId == null)
+ var gwSetHomeId = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.GwSetHomeIdData>(jobject["Data"].ToString());
+ if (gwSetHomeId == null)
{
d = new GwSetHomeIdAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
}
else
{
- d = new GwSetHomeIdAllData { gwSetHomeIdData = gatewayTemp.gwSetHomeId };
+ d = new GwSetHomeIdAllData { gwSetHomeIdData = gwSetHomeId };
DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
}
}
@@ -589,10 +499,25 @@
DebugPrintLog("GwReName_Actions 鍚姩" + System.DateTime.Now.ToString());
try
{
+ //璐﹀彿ID
+ string accountId = string.Empty;
+ if (homeId != string.Empty)
+ {
+ if (Shared.Phone.UserCenter.UserCenterResourse.UserInfo.AuthorityNo == 1)
+ {
+ //涓昏处鍙�
+ accountId = Config.Instance.Guid;
+ }
+ else
+ {
+ accountId = Config.Instance.Home.MainUserDistributedMark;
+ }
+ }
var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 82 } };
- var data = new JObject { { "HomeId", homeId } };
+ var data = new JObject { { "HomeId", homeId }, { "AccountId", accountId } };
jObject.Add("Data", data);
- Send("GwSetHomeId", jObject.ToString());
+ //浣忓畢ID鐨勮缃�,鍥哄畾浣跨敤灞�鍩熺綉,涓嶅瓨鍦ㄨ繙绋嬬殑璇存硶
+ SendLocation("GwSetHomeId", System.Text.Encoding.UTF8.GetBytes(jObject.ToString()));
}
catch { }
@@ -619,498 +544,6 @@
}
#endregion
- #region 鑾峰彇宸插叆缃戣澶囦俊鎭�
- /// <summary>
- /// 鑾峰彇缃戝叧璁惧淇℃伅(娉ㄦ剰锛岃繖涓帴鍙d細琚幓鎺夛級
- /// </summary>
- public async System.Threading.Tasks.Task<List<CommonDevice>> GetGwDeviceList()
- {
- DeviceList.Clear();
- return await System.Threading.Tasks.Task.Run((Func<System.Threading.Tasks.Task<List<CommonDevice>>>)(async () =>
- {
- var dateTime = DateTime.Now;
- bool canBreak = false;
- Action<string, string> action = (topic, message) =>
- {
- var gatewayID = topic.Split('/')[0];
- var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
-
- if (topic == gatewayID + "/" + "DeviceInfoRespon")
- {
- dateTime = DateTime.Now;
- var totalNum = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["TotalNum"].ToString());
- if (totalNum == 0)
- {
- canBreak = true;
- return;
- }
- var deviceID = jobject.Value<int>("Device_ID");
- switch ((DeviceType)(deviceID))
- {
- //case DeviceType.DimmableLight:
- // var dimmableLight = new DimmableLight() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
- // dimmableLight.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<DimmableLight.DeviceInfoData>(jobject["Data"].ToString());
- // if (dimmableLight.DeviceInfo == null)
- // {
- // return;
- // }
- // var light = DeviceList.Find(obj => obj.DeviceID == dimmableLight.DeviceID && obj.DeviceAddr == dimmableLight.DeviceAddr && obj.DeviceEpoint == dimmableLight.DeviceEpoint);
- // if (light == null)
- // {
- // DeviceList.Add(dimmableLight);
- // dimmableLight.DeviceName = dimmableLight.DeviceInfo.MacName;
- // dimmableLight.DeviceEpointName = dimmableLight.DeviceInfo.DeviceName;
- // dimmableLight.ImgVersion = dimmableLight.DeviceInfo.ImgVersion;
- // dimmableLight.HwVersion = dimmableLight.DeviceInfo.HwVersion;
- // dimmableLight.IsOnline = dimmableLight.DeviceInfo.IsOnline;
- // dimmableLight.DriveCode = dimmableLight.DeviceInfo.DriveCode;
- // dimmableLight.ImgTypeId = dimmableLight.DeviceInfo.ImgTypeId;
- // dimmableLight.IasDeviceType = dimmableLight.DeviceInfo.DeviceType;
- // dimmableLight.Profile = dimmableLight.DeviceInfo.Profile;
- // dimmableLight.InClusterList = dimmableLight.DeviceInfo.InClusterList;
- // dimmableLight.OutClusterList = dimmableLight.DeviceInfo.OutClusterList;
- // dimmableLight.AttributeStatus = dimmableLight.DeviceInfo.AttributeStatus;
- // //dimmableLight.Save();
- // }
- // else
- // {
- // light.DeviceInfo = dimmableLight.DeviceInfo;
- // light.DeviceName = dimmableLight.DeviceInfo.MacName;
- // light.DeviceEpointName = dimmableLight.DeviceInfo.DeviceName;
- // light.ImgVersion = dimmableLight.DeviceInfo.ImgVersion;
- // light.HwVersion = dimmableLight.DeviceInfo.HwVersion;
- // light.IsOnline = dimmableLight.DeviceInfo.IsOnline;
- // light.DriveCode = dimmableLight.DeviceInfo.DriveCode;
- // light.ImgTypeId = dimmableLight.DeviceInfo.ImgTypeId;
- // light.IasDeviceType = dimmableLight.DeviceInfo.DeviceType;
- // light.Profile = dimmableLight.DeviceInfo.Profile;
- // light.InClusterList = dimmableLight.DeviceInfo.InClusterList;
- // light.OutClusterList = dimmableLight.DeviceInfo.OutClusterList;
- // light.AttributeStatus = dimmableLight.DeviceInfo.AttributeStatus;
- // //dimmableLight.ReSave();
- // }
- // DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
-
- // break;
- //case DeviceType.OnOffSwitch:
- // var panel = new Panel() { Time = jobject.Value<int>("Time"), DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
- // panel.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.DeviceInfoData>(jobject["Data"].ToString());
- // if (panel.DeviceInfo == null)
- // {
- // return;
- // }
- // var panelInfo = DeviceList.Find(obj => obj.DeviceID == panel.DeviceID && obj.DeviceAddr == panel.DeviceAddr && obj.DeviceEpoint == panel.DeviceEpoint);
- // if (panelInfo == null)
- // {
- // DeviceList.Add(panel);
- // panel.DeviceName = panel.DeviceInfo.MacName;
- // panel.DeviceEpointName = panel.DeviceInfo.DeviceName;
- // panel.ImgTypeId = panel.DeviceInfo.ImgTypeId;
- // panel.ImgVersion = panel.DeviceInfo.ImgVersion;
- // panel.HwVersion = panel.DeviceInfo.HwVersion;
- // panel.IasDeviceType = panel.DeviceInfo.DeviceType;
- // panel.IsOnline = panel.DeviceInfo.IsOnline;
- // panel.DriveCode = panel.DeviceInfo.DriveCode;
- // panel.Profile = panel.DeviceInfo.Profile;
- // panel.InClusterList = panel.DeviceInfo.InClusterList;
- // panel.OutClusterList = panel.DeviceInfo.OutClusterList;
- // panel.AttributeStatus = panel.DeviceInfo.AttributeStatus;
- // //panel.Save();
- // }
- // else
- // {
- // panelInfo.DeviceInfo = panel.DeviceInfo;
- // panelInfo.DeviceName = panel.DeviceInfo.MacName;
- // panelInfo.DeviceEpointName = panel.DeviceInfo.DeviceName;
- // panelInfo.ImgVersion = panel.DeviceInfo.ImgVersion;
- // panelInfo.HwVersion = panel.DeviceInfo.HwVersion;
- // panelInfo.IsOnline = panel.DeviceInfo.IsOnline;
- // panelInfo.DriveCode = panel.DeviceInfo.DriveCode;
- // panelInfo.IasDeviceType = panel.DeviceInfo.DeviceType;
- // panelInfo.Profile = panel.DeviceInfo.Profile;
- // panelInfo.ImgTypeId = panel.DeviceInfo.ImgTypeId;
- // panelInfo.InClusterList = panel.DeviceInfo.InClusterList;
- // panelInfo.OutClusterList = panel.DeviceInfo.OutClusterList;
- // panelInfo.AttributeStatus = panel.DeviceInfo.AttributeStatus;
- // //panel.ReSave();
- // }
- // DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
-
- // break;
- //case DeviceType.OnOffOutput:
- // var toggleLight = new ToggleLight() { Time = jobject.Value<int>("Time"), DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
- // toggleLight.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ToggleLight.DeviceInfoData>(jobject["Data"].ToString());
- // if (toggleLight.DeviceInfo == null)
- // {
- // return;
- // }
- // var toggleLightInfo = DeviceList.Find(obj => obj.DeviceID == toggleLight.DeviceID && obj.DeviceAddr == toggleLight.DeviceAddr && obj.DeviceEpoint == toggleLight.DeviceEpoint);
- // if (toggleLightInfo == null)
- // {
- // DeviceList.Add(toggleLight);
- // toggleLight.DeviceName = toggleLight.DeviceInfo.MacName;
- // toggleLight.DeviceEpointName = toggleLight.DeviceInfo.DeviceName;
- // toggleLight.ImgVersion = toggleLight.DeviceInfo.ImgVersion;
- // toggleLight.HwVersion = toggleLight.DeviceInfo.HwVersion;
- // toggleLight.IsOnline = toggleLight.DeviceInfo.IsOnline;
- // toggleLight.DriveCode = toggleLight.DeviceInfo.DriveCode;
- // toggleLight.IasDeviceType = toggleLight.DeviceInfo.DeviceType;
- // toggleLight.Profile = toggleLight.DeviceInfo.Profile;
- // toggleLight.ImgTypeId = toggleLight.DeviceInfo.ImgTypeId;
- // toggleLight.InClusterList = toggleLight.DeviceInfo.InClusterList;
- // toggleLight.OutClusterList = toggleLight.DeviceInfo.OutClusterList;
- // toggleLight.AttributeStatus = toggleLight.DeviceInfo.AttributeStatus;
- // //toggleLight.Save();
- // }
- // else
- // {
- // toggleLightInfo.DeviceName = toggleLight.DeviceInfo.MacName;
- // toggleLightInfo.DeviceEpointName = toggleLight.DeviceInfo.DeviceName;
- // toggleLightInfo.ImgVersion = toggleLight.DeviceInfo.ImgVersion;
- // toggleLightInfo.HwVersion = toggleLight.DeviceInfo.HwVersion;
- // toggleLightInfo.IsOnline = toggleLight.DeviceInfo.IsOnline;
- // toggleLightInfo.DriveCode = toggleLight.DeviceInfo.DriveCode;
- // toggleLightInfo.IasDeviceType = toggleLight.DeviceInfo.DeviceType;
- // toggleLightInfo.Profile = toggleLight.DeviceInfo.Profile;
- // toggleLightInfo.ImgTypeId = toggleLight.DeviceInfo.ImgTypeId;
- // toggleLightInfo.InClusterList = toggleLight.DeviceInfo.InClusterList;
- // toggleLightInfo.OutClusterList = toggleLight.DeviceInfo.OutClusterList;
- // toggleLightInfo.AttributeStatus = toggleLight.DeviceInfo.AttributeStatus;
- // toggleLightInfo.DeviceInfo = toggleLight.DeviceInfo;
- // //toggleLightInfo.ReSave();
- // }
- // DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
-
- // break;
- //case DeviceType.AirSwitch:
- // var airSwitch = new AirSwitch() { Time = jobject.Value<int>("Time"), DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
- // airSwitch.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<AirSwitch.DeviceInfoData>(jobject["Data"].ToString());
- // if (airSwitch.DeviceInfo == null)
- // {
- // return;
- // }
- // var airSwitchInfo = DeviceList.Find(obj => obj.DeviceID == airSwitch.DeviceID && obj.DeviceAddr == airSwitch.DeviceAddr && obj.DeviceEpoint == airSwitch.DeviceEpoint);
- // if (airSwitchInfo == null)
- // {
- // DeviceList.Add(airSwitch);
- // airSwitch.DeviceName = airSwitch.DeviceInfo.MacName;
- // airSwitch.DeviceEpointName = airSwitch.DeviceInfo.DeviceName;
- // airSwitch.ImgVersion = airSwitch.DeviceInfo.ImgVersion;
- // airSwitch.HwVersion = airSwitch.DeviceInfo.HwVersion;
- // airSwitch.IsOnline = airSwitch.DeviceInfo.IsOnline;
- // airSwitch.DriveCode = airSwitch.DeviceInfo.DriveCode;
- // airSwitch.IasDeviceType = airSwitch.DeviceInfo.DeviceType;
- // airSwitch.Profile = airSwitch.DeviceInfo.Profile;
- // airSwitch.ImgTypeId = airSwitch.DeviceInfo.ImgTypeId;
- // airSwitch.InClusterList = airSwitch.DeviceInfo.InClusterList;
- // airSwitch.OutClusterList = airSwitch.DeviceInfo.OutClusterList;
- // airSwitch.AttributeStatus = airSwitch.DeviceInfo.AttributeStatus;
- // //airSwitch.Save();
- // }
- // else
- // {
- // airSwitchInfo.DeviceName = airSwitch.DeviceInfo.MacName;
- // airSwitchInfo.DeviceEpointName = airSwitch.DeviceInfo.DeviceName;
- // airSwitchInfo.ImgVersion = airSwitch.DeviceInfo.ImgVersion;
- // airSwitchInfo.HwVersion = airSwitch.DeviceInfo.HwVersion;
- // airSwitchInfo.IsOnline = airSwitch.DeviceInfo.IsOnline;
- // airSwitchInfo.DriveCode = airSwitch.DeviceInfo.DriveCode;
- // airSwitchInfo.IasDeviceType = airSwitch.DeviceInfo.DeviceType;
- // airSwitchInfo.Profile = airSwitch.DeviceInfo.Profile;
- // airSwitchInfo.ImgTypeId = airSwitch.DeviceInfo.ImgTypeId;
- // airSwitchInfo.InClusterList = airSwitch.DeviceInfo.InClusterList;
- // airSwitchInfo.OutClusterList = airSwitch.DeviceInfo.OutClusterList;
- // airSwitchInfo.AttributeStatus = airSwitch.DeviceInfo.AttributeStatus;
- // airSwitchInfo.DeviceInfo = airSwitch.DeviceInfo;
- // // airSwitchInfo.ReSave();
- // }
- // DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
-
- // break;
- //case DeviceType.WindowCoveringDevice:
- // var windowCovering = new Rollershade() { DeviceID = jobject.Value<int>((object)"Device_ID"), DeviceAddr = jobject.Value<string>((object)"DeviceAddr"), DeviceEpoint = jobject.Value<int>((object)"Epoint"), DataID = jobject.Value<int>((object)"Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
- // windowCovering.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<Rollershade.DeviceInfoData>(jobject["Data"].ToString());
- // if (windowCovering.DeviceInfo == null)
- // {
- // return;
- // }
- // var wc = DeviceList.Find(obj => obj.DeviceID == windowCovering.DeviceID && obj.DeviceAddr == windowCovering.DeviceAddr && obj.DeviceEpoint == windowCovering.DeviceEpoint);
- // if (wc == null)
- // {
- // DeviceList.Add(windowCovering);
- // windowCovering.DeviceName = windowCovering.DeviceInfo.MacName;
- // windowCovering.DeviceEpointName = windowCovering.DeviceInfo.DeviceName;
- // windowCovering.ImgVersion = windowCovering.DeviceInfo.ImgVersion;
- // windowCovering.HwVersion = windowCovering.DeviceInfo.HwVersion;
- // windowCovering.IsOnline = windowCovering.DeviceInfo.IsOnline;
- // windowCovering.DriveCode = windowCovering.DeviceInfo.DriveCode;
- // windowCovering.IasDeviceType = windowCovering.DeviceInfo.DeviceType;
- // windowCovering.Profile = windowCovering.DeviceInfo.Profile;
- // windowCovering.ImgTypeId = windowCovering.DeviceInfo.ImgTypeId;
- // windowCovering.InClusterList = windowCovering.DeviceInfo.InClusterList;
- // windowCovering.OutClusterList = windowCovering.DeviceInfo.OutClusterList;
- // windowCovering.AttributeStatus = windowCovering.DeviceInfo.AttributeStatus;
- // //windowCovering.Save();
- // }
- // else
- // {
- // wc.DeviceName = windowCovering.DeviceInfo.MacName;
- // wc.DeviceEpointName = windowCovering.DeviceInfo.DeviceName;
- // wc.DeviceInfo = windowCovering.DeviceInfo;
- // wc.ImgVersion = windowCovering.DeviceInfo.ImgVersion;
- // wc.HwVersion = windowCovering.DeviceInfo.HwVersion;
- // wc.IsOnline = windowCovering.DeviceInfo.IsOnline;
- // wc.DriveCode = windowCovering.DeviceInfo.DriveCode;
- // wc.IasDeviceType = windowCovering.DeviceInfo.DeviceType;
- // wc.Profile = windowCovering.DeviceInfo.Profile;
- // wc.ImgTypeId = windowCovering.DeviceInfo.ImgTypeId;
- // wc.InClusterList = windowCovering.DeviceInfo.InClusterList;
- // wc.OutClusterList = windowCovering.DeviceInfo.OutClusterList;
- // wc.AttributeStatus = windowCovering.DeviceInfo.AttributeStatus;
- // // wc.ReSave();
- // }
- // DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
- // break;
- //case DeviceType.IASZone:
- // var ias = new IASZone() { Time = jobject.Value<int>("Time"), DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
- // ias.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone.DeviceInfoData>(jobject["Data"].ToString());
- // if (ias.DeviceInfo == null)
- // {
- // return;
- // }
- // var infoIAS = DeviceList.Find(obj => obj.DeviceID == ias.DeviceID && obj.DeviceAddr == ias.DeviceAddr && obj.DeviceEpoint == ias.DeviceEpoint);
- // if (infoIAS == null)
- // {
- // DeviceList.Add(ias);
- // ias.DeviceName = ias.DeviceInfo.MacName;
- // ias.DeviceEpointName = ias.DeviceInfo.DeviceName;
- // ias.ImgVersion = ias.DeviceInfo.ImgVersion;
- // ias.HwVersion = ias.DeviceInfo.HwVersion;
- // ias.IsOnline = ias.DeviceInfo.IsOnline;
- // ias.DriveCode = ias.DeviceInfo.DriveCode;
- // ias.IasDeviceType = ias.DeviceInfo.DeviceType;
- // ias.Profile = ias.DeviceInfo.Profile;
- // ias.ImgTypeId = ias.DeviceInfo.ImgTypeId;
- // ias.InClusterList = ias.DeviceInfo.InClusterList;
- // ias.OutClusterList = ias.DeviceInfo.OutClusterList;
- // ias.AttributeStatus = ias.DeviceInfo.AttributeStatus;
- // //ias.Save();
- // }
- // else
- // {
- // infoIAS.DeviceName = ias.DeviceInfo.MacName;
- // infoIAS.DeviceEpointName = ias.DeviceInfo.DeviceName;
- // infoIAS.DeviceEpointName = ias.DeviceInfo.DeviceName;
- // infoIAS.ImgVersion = ias.DeviceInfo.ImgVersion;
- // infoIAS.HwVersion = ias.DeviceInfo.HwVersion;
- // infoIAS.IsOnline = ias.DeviceInfo.IsOnline;
- // infoIAS.DriveCode = ias.DeviceInfo.DriveCode;
- // infoIAS.IasDeviceType = ias.DeviceInfo.DeviceType;
- // infoIAS.Profile = ias.DeviceInfo.Profile;
- // infoIAS.ImgTypeId = ias.DeviceInfo.ImgTypeId;
- // infoIAS.InClusterList = ias.DeviceInfo.InClusterList;
- // infoIAS.OutClusterList = ias.DeviceInfo.OutClusterList;
- // infoIAS.AttributeStatus = ias.DeviceInfo.AttributeStatus;
- // infoIAS.DeviceInfo = ias.DeviceInfo;
- // //ias.ReSave();
- // }
- // DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
- // break;
- //case DeviceType.OtaDevice:
- //case DeviceType.OtaPanelDevice:
- //var ota = new OTADevice() { Time = jobject.Value<int>("Time"), DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
- //ota.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceInfoData>(jobject["Data"].ToString());
- //if (ota.DeviceInfo == null)
- //{
- // return;
- //}
- //var infoOta = DeviceList.Find(obj => obj.DeviceID == ota.DeviceID && obj.DeviceAddr == ota.DeviceAddr && obj.DeviceEpoint == ota.DeviceEpoint);
- //if (infoOta == null)
- //{
- // DeviceList.Add(ota);
- // ota.DeviceName = ota.DeviceInfo.MacName;
- // ota.DeviceEpointName = ota.DeviceInfo.DeviceName;
- // ota.ImgVersion = ota.DeviceInfo.ImgVersion;
- // ota.HwVersion = ota.DeviceInfo.HwVersion;
- // ota.IsOnline = ota.DeviceInfo.IsOnline;
- // ota.DriveCode = ota.DeviceInfo.DriveCode;
- // ota.IasDeviceType = ota.DeviceInfo.DeviceType;
- // ota.Profile = ota.DeviceInfo.Profile;
- // ota.ImgTypeId = ota.DeviceInfo.ImgTypeId;
- // ota.InClusterList = ota.DeviceInfo.InClusterList;
- // ota.OutClusterList = ota.DeviceInfo.OutClusterList;
- // ota.AttributeStatus = ota.DeviceInfo.AttributeStatus;
- // //ota.Save();
- //}
- //else
- //{
- // infoOta.DeviceName = ota.DeviceInfo.MacName;
- // infoOta.DeviceEpointName = ota.DeviceInfo.DeviceName;
- // infoOta.DeviceEpointName = ota.DeviceInfo.DeviceName;
- // infoOta.ImgVersion = ota.DeviceInfo.ImgVersion;
- // infoOta.HwVersion = ota.DeviceInfo.HwVersion;
- // infoOta.IsOnline = ota.DeviceInfo.IsOnline;
- // infoOta.DriveCode = ota.DeviceInfo.DriveCode;
- // infoOta.IasDeviceType = ota.DeviceInfo.DeviceType;
- // infoOta.Profile = ota.DeviceInfo.Profile;
- // infoOta.ImgTypeId = ota.DeviceInfo.ImgTypeId;
- // infoOta.InClusterList = ota.DeviceInfo.InClusterList;
- // infoOta.OutClusterList = ota.DeviceInfo.OutClusterList;
- // infoOta.AttributeStatus = ota.DeviceInfo.AttributeStatus;
- // infoOta.DeviceInfo = ota.DeviceInfo;
- // //ota.ReSave();
- //}
- //DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
- //break;
- //case DeviceType.Thermostat:
- //var thermostat = new ThermostatObj() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gateway.getGatewayBaseInfo.gwID };
- //thermostat.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ThermostatObj.DeviceInfoData>(jobject["Data"].ToString());
- //if (thermostat.DeviceInfo == null)
- //{
- // return;
- //}
- //var ther = gateway.DeviceList.Find(obj => obj.DeviceID == thermostat.DeviceID && obj.DeviceAddr == thermostat.DeviceAddr && obj.DeviceEpoint == thermostat.DeviceEpoint);
- //if (ther == null)
- //{
- // gateway.DeviceList.Add(thermostat);
- // thermostat.DeviceName = thermostat.DeviceInfo.DeviceName;
- // IO.LocalFileUtils.SaveDeviceInfo(thermostat, thermostat.DeviceEpoint.ToString());
- //}
- //else
- //{
- // ther.DeviceName = thermostat.DeviceInfo.DeviceName;
- // ther.DeviceInfo = thermostat.DeviceInfo;
- // ZigBee.IO.LocalFileUtils.SaveDeviceInfo(ther, ther.DeviceEpoint.ToString());
- //}
- //break;
- //case DeviceType.TemperatureSensor:
- //var temperatureSensor = new TemperatureSensor() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gateway.getGatewayBaseInfo.gwID };
- //temperatureSensor.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<TemperatureSensor.DeviceInfoData>(jobject["Data"].ToString());
- //if (temperatureSensor.DeviceInfo == null)
- //{
- // return;
- //}
- //var ts = gateway.DeviceList.Find(obj => obj.DeviceID == temperatureSensor.DeviceID && obj.DeviceAddr == temperatureSensor.DeviceAddr && obj.DeviceEpoint == temperatureSensor.DeviceEpoint);
- //if (ts == null)
- //{
- // gateway.DeviceList.Add(temperatureSensor);
- // temperatureSensor.DeviceName = temperatureSensor.DeviceInfo.DeviceName;
- // IO.LocalFileUtils.SaveDeviceInfo(temperatureSensor, temperatureSensor.DeviceEpoint.ToString());
- //}
- //else
- //{
- // ts.DeviceName = temperatureSensor.DeviceInfo.DeviceName;
- // ts.DeviceInfo = temperatureSensor.DeviceInfo;
- // IO.LocalFileUtils.SaveDeviceInfo(ts, ts.DeviceEpoint.ToString());
- //}
- //break;
-
- }
- }
- else if (topic == gatewayID + "/" + "DeviceInfoResponEnd")
- {
- canBreak = true;
- }
- };
-
- Actions += action;
- DebugPrintLog("DeviceInfo Actions 鍚姩" + "_" + System.DateTime.Now.ToString());
-
- try
- {
- var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 93 } };
- Send("GetDeviceInfo", jObject.ToString());
- }
- catch { }
-
- while (canBreak == false && (DateTime.Now - dateTime).TotalMilliseconds < 6000)
- {
- await System.Threading.Tasks.Task.Delay(10);
- }
-
- Actions -= action;
- DebugPrintLog("DeviceInfo_Actions 閫�鍑�" + System.DateTime.Now.ToString());
- return DeviceList;
- }));
- }
- #endregion
-
- #region 鑾峰彇缃戝叧璁板綍鐨勮澶囧睘鎬х姸鎬�
- /// <summary>
- ///鑾峰彇缃戝叧璁板綍鐨勮澶囧睘鎬х姸鎬�
- /// </summary>
- public async System.Threading.Tasks.Task<GetStatusRecordAllInfo> GetStatusRecordAsync(string deviceAddr, int deviceEpoint)
- {
- return await System.Threading.Tasks.Task.Run(async () =>
- {
- GetStatusRecordAllInfo d = null;
- Action<string, string> action = (topic, message) =>
- {
- var gatewayID = topic.Split('/')[0];
- var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
-
- if (topic == gatewayID + "/" + "Error_Respon")
- {
- var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
-
- if (temp == null)
- {
- d = new GetStatusRecordAllInfo { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" };
- }
- else
- {
- d = new GetStatusRecordAllInfo { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
- }
- }
-
- if (topic == gatewayID + "/" + "GetStatusRecord_Respon")
- {
- var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
- gatewayTemp.getStatusRecordInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.GetStatusRecordInfo>(jobject["Data"].ToString());
-
- if (gatewayTemp.getStatusRecordInfo == null)
- {
- d = new GetStatusRecordAllInfo { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
- }
- else
- {
- d = new GetStatusRecordAllInfo { getStatusRecordInfo = gatewayTemp.getStatusRecordInfo };
- DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
- }
- }
- };
- Actions += action;
- DebugPrintLog("GetStatusRecord_Actions 鍚姩" + System.DateTime.Now.ToString());
- try
- {
- var jObject = new JObject { { "DeviceAddr", deviceAddr }, { "Epoint", deviceEpoint }, { "Cluster_ID", 0 }, { "Command", 80 } };
- Send("GetStatusRecord", jObject.ToString());
-
- }
- catch { }
-
- var dateTime = DateTime.Now;
- while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
- {
- await System.Threading.Tasks.Task.Delay(10);
- if (d != null)
- {
- break;
- }
- }
- if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
- {
- d = new GetStatusRecordAllInfo { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" };
- }
- Actions -= action;
- DebugPrintLog("GetStatusRecord_Actions 閫�鍑�" + System.DateTime.Now.ToString());
-
- return d;
- });
- }
- #endregion
-
#region 鍏佽璁惧鍏ョ綉
///<summary >
/// 鎼滅储鏂板叆缃戠殑璁惧锛堝厑璁歌澶囧叆缃戯級
@@ -1120,7 +553,6 @@
{
await System.Threading.Tasks.Task.Run(async () =>
{
- CommonDevice commonDev = null;
Action<string, string> action1 = (topic, message) => { };
Actions += action1;
var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 94 } };
@@ -1175,8 +607,7 @@
if (topic == gatewayID + "/" + "Error_Respon")
{
- var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
if (temp == null)
{
@@ -1184,13 +615,12 @@
}
else
{
- d = new GwLinuxResetResponData { errorMessageBase = ErrorMess(temp.Error) };
+ d = new GwLinuxResetResponData { errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "GwLinuxReset_Respon")
{
- var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
var result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"].ToString());
if (result == null)
@@ -1253,8 +683,7 @@
if (topic == gatewayID + "/" + "Error_Respon")
{
- var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
if (temp == null)
{
@@ -1262,13 +691,12 @@
}
else
{
- d = new GwRebootResponAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+ d = new GwRebootResponAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "GwReboot_Respon")
{
- var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
var result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"].ToString());
if (result == null)
@@ -1329,8 +757,7 @@
if (topic == gatewayID + "/" + "Error_Respon")
{
- var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
if (temp == null)
{
@@ -1338,22 +765,21 @@
}
else
{
- d = new SaveNVFileResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+ d = new SaveNVFileResponseAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "ZbGwOperation/SaveNVFile_Respon")
{
- var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
- gatewayTemp.zbGwOperationSaveNVFileData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.SaveNVFileResponseData>(jobject["Data"].ToString());
+ var zbGwOperationSaveNVFileData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.SaveNVFileResponseData>(jobject["Data"].ToString());
- if (gatewayTemp.zbGwOperationSaveNVFileData == null)
+ if (zbGwOperationSaveNVFileData == null)
{
d = new SaveNVFileResponseAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
}
else
{
- d = new SaveNVFileResponseAllData { saveNVFileResponseData = gatewayTemp.zbGwOperationSaveNVFileData };
+ d = new SaveNVFileResponseAllData { saveNVFileResponseData = zbGwOperationSaveNVFileData };
DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
}
}
@@ -1407,8 +833,7 @@
if (topic == gatewayID + "/" + "Error_Respon")
{
- var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
if (temp == null)
{
@@ -1416,14 +841,13 @@
}
else
{
- d = new RestoreNVAllDtta { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+ d = new RestoreNVAllDtta { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "ZbGwOperation/RestoreNV_Respon")
{
- var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.RestoreNVDtta>(jobject["Data"].ToString());
if (tempData == null)
@@ -1487,21 +911,19 @@
if (topic == gatewayID + "/" + "Error_Respon")
{
- var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
if (temp == null)
{
d = new GwGetChannelResponData { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" };
}
else
{
- d = new GwGetChannelResponData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+ d = new GwGetChannelResponData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "ZbGw/GetChannel_Respon")
{
- var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
var channel = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Channel"].ToString());
d = new GwGetChannelResponData { channel = channel };
DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
@@ -1555,8 +977,7 @@
if (topic == gatewayID + "/" + "Error_Respon")
{
- var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
if (temp == null)
{
@@ -1564,13 +985,12 @@
}
else
{
- d = new ChangeChannelResponAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+ d = new ChangeChannelResponAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "ZbGw/ChangeChannel_Respon")
{
- var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
var tempInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ChangeChannelResponData>(jobject["Data"].ToString());
if (tempInfo == null)
@@ -1649,8 +1069,11 @@
/// </summary>
public async System.Threading.Tasks.Task<Panel.PanelSwitchLevelInfo> ClientDataPassthroughBytesAsync(string deviceAddr, int devicePoint, long dataLength, byte[] passData)
{
+ var myDevice = Shared.Common.LocalDevice.Current.GetDevice(deviceAddr, devicePoint);
+
Panel.PanelSwitchLevelInfo result = null;
- if (Gateway == null)
+
+ if (myDevice.Gateway == null)
{
result = new Panel.PanelSwitchLevelInfo { errorMessageBase = "褰撳墠娌℃湁缃戝叧" };
return result;
@@ -1664,8 +1087,7 @@
if (topic == gatewayID + "/" + "Error_Respon")
{
- var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
if (temp == null)
{
@@ -1674,24 +1096,23 @@
else
{
- result = new Panel.PanelSwitchLevelInfo { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+ result = new Panel.PanelSwitchLevelInfo { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "ZbDataPassthrough")
{
- var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
- gatewayTemp.clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString());
+ var clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ClientDataPassthroughResponseData>(jobject["Data"].ToString());
- if (gatewayTemp.clientDataPassthroughResponseData == null)
+ if (clientDataPassthroughResponseData == null)
{
result = new Panel.PanelSwitchLevelInfo { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
}
else
{
- if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null)
+ if (clientDataPassthroughResponseData?.PassData != null)
{
- var data = gatewayTemp.clientDataPassthroughResponseData.PassData;
+ var data = clientDataPassthroughResponseData.PassData;
if (data.Length == 14)
{
var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
@@ -1708,7 +1129,7 @@
}
};
- Gateway.Actions += action;
+ myDevice.Gateway.Actions += action;
System.Console.WriteLine("ClientDataPassthrough_Actions 鍚姩" + System.DateTime.Now.ToString());
try
@@ -1749,7 +1170,7 @@
{
result = new Panel.PanelSwitchLevelInfo { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" };
}
- Gateway.Actions -= action;
+ myDevice.Gateway.Actions -= action;
System.Console.WriteLine("ClientDataPassthrough_Actions 閫�鍑�" + System.DateTime.Now.ToString());
return result;
@@ -1778,8 +1199,7 @@
if (topic == gatewayID + "/" + "Error_Respon")
{
- var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
if (temp == null)
{
@@ -1787,24 +1207,16 @@
}
else
{
- d = new PassthroughAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+ d = new PassthroughAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "ZbDataPassthrough")
{
- var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<string>(jobject["Data"].ToString());
- if (gatewayTemp.getGwVersion == null)
- {
- d = new PassthroughAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
- }
- else
- {
- d = new PassthroughAllData { passData = temp };
- DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
- }
+ d = new PassthroughAllData { passData = temp };
+ DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
}
};
Actions += action;
@@ -1857,8 +1269,7 @@
if (topic == gatewayID + "/" + "Error_Respon")
{
- var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID };
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
if (temp == null)
{
@@ -1867,13 +1278,12 @@
else
{
- d = new LinuxUpgradeAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+ d = new LinuxUpgradeAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "ZbGwOperation/LinuxUpgrade_Respon")
{
- var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
var result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString());
d = new LinuxUpgradeAllData { Result = result };
DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
@@ -1934,8 +1344,7 @@
if (topic == gatewayID + "/" + "Error_Respon")
{
- var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID };
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
if (temp == null)
{
@@ -1944,22 +1353,21 @@
else
{
- d = new ZbGwOperationUpgradeAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+ d = new ZbGwOperationUpgradeAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "ZbGwOperation/Upgrade_Respon")
{
- var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
- gatewayTemp.zbGwOperationUpgradeData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ZbGwOperationUpgradeData>(jobject["Data"].ToString());
+ zbGwOperationUpgradeData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ZbGwOperationUpgradeData>(jobject["Data"].ToString());
- if (gatewayTemp.zbGwOperationUpgradeData == null)
+ if (zbGwOperationUpgradeData == null)
{
d = new ZbGwOperationUpgradeAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
}
else
{
- d = new ZbGwOperationUpgradeAllData { bGwOperationUpgradeData = gatewayTemp.zbGwOperationUpgradeData };
+ d = new ZbGwOperationUpgradeAllData { bGwOperationUpgradeData = zbGwOperationUpgradeData };
DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
}
}
@@ -2005,11 +1413,11 @@
/// <returns>The file async.</returns>
/// <param name="distributedMark">Distributed mark:鍥轰欢鍞竴鏍囪瘑</param>
/// <param name="imageName">Image name:鍥轰欢鐗堟湰</param>
- public async System.Threading.Tasks.Task<DownloadFileResponAllData> DownloadFileAsync(string distributedMark, string imageName)
+ public async System.Threading.Tasks.Task<CommonDevice.DownloadFileResponAllData> DownloadFileAsync(string distributedMark, string imageName)
{
return await System.Threading.Tasks.Task.Run(async () =>
{
- DownloadFileResponAllData d = null; ;
+ CommonDevice.DownloadFileResponAllData d = null; ;
Action<string, string> action = (topic, message) =>
{
var gatewayID = topic.Split('/')[0];
@@ -2017,32 +1425,30 @@
if (topic == gatewayID + "/" + "Error_Respon")
{
- var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID };
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
if (temp == null)
{
- d = new DownloadFileResponAllData { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" };
+ d = new CommonDevice.DownloadFileResponAllData { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" };
}
else
{
- d = new DownloadFileResponAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+ d = new CommonDevice.DownloadFileResponAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "DownloadFile_Respon")
{
- var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
- gatewayTemp.downloadFileResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<DownloadFileResponData>(jobject["Data"].ToString());
+ var downloadFileResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DownloadFileResponData>(jobject["Data"].ToString());
- if (gatewayTemp.downloadFileResponData == null)
+ if (downloadFileResponData == null)
{
- d = new DownloadFileResponAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
+ d = new CommonDevice.DownloadFileResponAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
}
else
{
- d = new DownloadFileResponAllData { downloadFileResponData = gatewayTemp.downloadFileResponData };
+ d = new CommonDevice.DownloadFileResponAllData { downloadFileResponData = downloadFileResponData };
DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
}
}
@@ -2073,7 +1479,7 @@
}
if ((DateTime.Now - dateTime).TotalMilliseconds > 30 * 1000)
{
- d = new DownloadFileResponAllData { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" };
+ d = new CommonDevice.DownloadFileResponAllData { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" };
}
Actions -= action;
@@ -2100,8 +1506,7 @@
if (topic == gatewayID + "/" + "Error_Respon")
{
- var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID };
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
if (temp == null)
{
@@ -2110,22 +1515,21 @@
else
{
- d = new CheckVDDriveCodeResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+ d = new CheckVDDriveCodeResponseAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "VirtualDrive/CatDriveCode_Respon")
{
- var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
- gatewayTemp.vDriveDriveCodeResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<VDriveDriveCodeResponData>(jobject["Data"].ToString());
+ var vDriveDriveCodeResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<VDriveDriveCodeResponData>(jobject["Data"].ToString());
- if (gatewayTemp.vDriveDriveCodeResponData == null)
+ if (vDriveDriveCodeResponData == null)
{
d = new CheckVDDriveCodeResponseAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
}
else
{
- d = new CheckVDDriveCodeResponseAllData { vDriveDriveCodeResponData = gatewayTemp.vDriveDriveCodeResponData };
+ d = new CheckVDDriveCodeResponseAllData { vDriveDriveCodeResponData = vDriveDriveCodeResponData };
DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
}
}
@@ -2180,8 +1584,7 @@
if (topic == gatewayID + "/" + "Error_Respon")
{
- var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID };
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
if (temp == null)
{
@@ -2190,22 +1593,21 @@
else
{
- d = new VirtualDriveUpgradeResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+ d = new VirtualDriveUpgradeResponseAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "VirtualDrive/Upgrade_Respon")
{
- var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
- gatewayTemp.virtualDriveUpgradeResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<VirtualDriveUpgradeResponData>(jobject["Data"].ToString());
+ virtualDriveUpgradeResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<VirtualDriveUpgradeResponData>(jobject["Data"].ToString());
- if (gatewayTemp.virtualDriveUpgradeResponData == null)
+ if (virtualDriveUpgradeResponData == null)
{
d = new VirtualDriveUpgradeResponseAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
}
else
{
- d = new VirtualDriveUpgradeResponseAllData { virtualDriveUpgradeResponData = gatewayTemp.virtualDriveUpgradeResponData };
+ d = new VirtualDriveUpgradeResponseAllData { virtualDriveUpgradeResponData = virtualDriveUpgradeResponData };
DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{topic}");
}
}
@@ -2243,115 +1645,6 @@
#endregion
- //#region 涓婁紶绉佹湁鏁版嵁
- //private bool backupSuccess = false;
- /// <summary>
- /// 涓婁紶绉佹湁鏁版嵁
- /// </summary>
- /// <returns>The data to gateway.</returns>
- /// <param name="fileName">File name.</param>
- /// <param name="dev">Dev.</param>
- //public async System.Threading.Tasks.Task<SendFileResponseAllData> BackupDataToGateway(string fileName, CommonDevice dev)
- //{
- // return await System.Threading.Tasks.Task.Run(async () =>
- // {
- // SendFileResponseAllData backUpStatus = null;
- // var file = await System.Threading.Tasks.Task.Factory.StartNew(() => Newtonsoft.Json.JsonConvert.SerializeObject(dev));
- // var data = System.Text.Encoding.UTF8.GetBytes(file);
- // //缃戝叧涓垱寤哄瓨鍌ㄦ暟鎹殑鏂囦欢
- // var saveFileName = await dev.Gateway.CreateFileAsync(fileName);
- // if (saveFileName != null && saveFileName.Result == 0)
- // {
- // backupSuccess = false;
- // //涓婁紶鏁版嵁鍒扮綉鍏�
- // var saveData = await dev.Gateway.SendFileAsync(data);
- // if (saveData != null)
- // {
- // backUpStatus = new SendFileResponseAllData { Result = saveData.Result };
- // }
- // }
- // var dateTime = DateTime.Now;
- // while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
- // {
- // await System.Threading.Tasks.Task.Delay(10);
- // if (backUpStatus != null)
- // {
- // break;
- // }
- // }
- // if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
- // {
- // backUpStatus = new SendFileResponseAllData { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" };
- // };
- // return backUpStatus;
- // });
- //}
-
- /// <summary>
- /// 涓嬭浇绉佹湁鏁版嵁
- /// </summary>
- /// <returns>The data from gateway.</returns>
- /// <param name="fileName">File name.</param>
- /// <param name="dev">Dev.</param>
- //public async System.Threading.Tasks.Task<System.Collections.Generic.List<byte>> DownloadDataFromGateway(string fileName, CommonDevice dev)
- //{
- // return await System.Threading.Tasks.Task.Run(async () =>
- // {
- // byteSource.Clear();
- // System.Collections.Generic.List<byte> backUpData = null;
- // var dateTime = DateTime.Now;
- // //鑾峰彇褰撳墠鏂囦欢鐨勫叿浣撲俊鎭�
- // //var getFileSize = await currentKey.Gateway.GetCurrentFileInfoAsync(fileName);
- // //涓嬭浇鏂囦欢
- // var saveFileName = await dev.Gateway.SetDownloadFileAsync(fileName);
- // Action<string, byte[]> action = (topic, dataContent) =>
- // {
- // if (topic.Split('/')[0] + "/" + topic.Split('/')[1] + "/" + topic.Split('/')[2] == topic.Split('/')[0] + "/" + "FileTransfer/DownloadFile")
- // {
- // dateTime = DateTime.Now;
- // byte[] fileBytes = dataContent;
- // if (fileBytes[5] != 1)
- // {
- // if (fileBytes.Length == 2056)
- // {
- // var tempBytes = new byte[2048];
- // System.Array.Copy(fileBytes, 8, tempBytes, 0, 2048);
- // byteSource.AddRange(tempBytes);
- // }
- // else
- // {
- // var tempBytes = new byte[fileBytes.Length - 8];
- // System.Array.Copy(fileBytes, 8, tempBytes, 0, tempBytes.Length);
- // byteSource.AddRange(tempBytes);
- // }
- // }
- // else
- // {
- // var tempBytes = new byte[fileBytes.Length - 8];
- // System.Array.Copy(fileBytes, 8, tempBytes, 0, tempBytes.Length);
- // byteSource.AddRange(tempBytes);
-
- // if (byteSource != null )
- // {
- // backUpData = byteSource;
- // }
- // }
-
- // }
- // };
- // dev.Gateway.FileContentAction += action;
-
- // while ((DateTime.Now - dateTime).TotalMilliseconds < 2000)
- // {
- // await System.Threading.Tasks.Task.Delay(10);
- // }
- // dev.Gateway.FileContentAction -= action;
- // return byteSource;
- // });
- //}
-
- //#endregion
-
#region 瀹㈡埛绔笂浼犳枃浠跺埌缃戝叧.
/// <summary>
/// 瀹㈡埛绔笂浼犳枃浠跺埌缃戝叧
@@ -2372,8 +1665,7 @@
if (topic == gatewayID + "/" + "Error_Respon")
{
- var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID };
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorResponData>(jobject["Data"].ToString());
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
if (temp == null)
{
@@ -2381,13 +1673,12 @@
}
else
{
- dataRes = new CreateFileResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+ dataRes = new CreateFileResponseAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "FileTransfer/CreateFile_Respon")
{
- var security = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID };
var result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString());
dataRes = new CreateFileResponseAllData { Result = result };
DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
@@ -2451,7 +1742,6 @@
if (topic == gatewayID + "/FileTransfer/SendFile_Respon")
{
- var gateway = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
var result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString());
dataRes = new SendFileResponseAllData { Result = result };
if (result == 0)
@@ -2541,8 +1831,7 @@
if (topic == gatewayID + "/" + "Error_Respon")
{
- var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID };
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorResponData>(jobject["Data"].ToString());
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
if (temp == null)
{
@@ -2550,13 +1839,12 @@
}
else
{
- dataRes = new FileTransferLsDiResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+ dataRes = new FileTransferLsDiResponseAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "FileTransfer/lsDir_Respon")
{
- var lsDir = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID };
var resultlsDir = Newtonsoft.Json.JsonConvert.DeserializeObject<FileTransferLsDiResponseData>(jobject["Data"].ToString());
if (resultlsDir != null)
{
@@ -2619,8 +1907,7 @@
if (topic == gatewayID + "/" + "Error_Respon")
{
- var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID };
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorResponData>(jobject["Data"].ToString());
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
if (temp == null)
{
@@ -2628,13 +1915,12 @@
}
else
{
- dataRes = new FileTransferGetFileInfoResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+ dataRes = new FileTransferGetFileInfoResponseAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "FileTransfer/GetFileInfo_Respon")
{
- var lsDir = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID };
var resultlsDir = Newtonsoft.Json.JsonConvert.DeserializeObject<FileTransferGetFileInfoResponseData>(jobject["Data"].ToString());
if (resultlsDir != null)
{
@@ -2699,8 +1985,7 @@
if (topic == gatewayID + "/" + "Error_Respon")
{
- var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID };
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorResponData>(jobject["Data"].ToString());
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
if (temp == null)
{
@@ -2708,13 +1993,12 @@
}
else
{
- dataRes = new SetDownloadFileResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+ dataRes = new SetDownloadFileResponseAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "FileTransfer/SetDownloadFile_Respon")
{
- var lsDir = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = CurrentGateWayId };
var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<SetDownloadFileResponseData>(jobject["Data"].ToString());
if (tempData != null)
{
@@ -2722,7 +2006,7 @@
var tempDa = new SetDownloadFileResponseData();
if (tempData.Result == 0)
{
- ZbGateway.byteSource.Clear();
+ this.byteSource.Clear();
}
tempDa.Result = tempData.Result;
dataRes.setDownloadFileResponseData = tempDa;
@@ -2770,7 +2054,7 @@
#endregion
#region 缃戝叧鍙戦�佹枃浠舵祦鍒板鎴风
- static System.Collections.Generic.List<byte> byteSource = new System.Collections.Generic.List<byte>();
+ private List<byte> byteSource = new List<byte>();
///<summary >
/// 涓嬭浇鏂囦欢涓殑鏁版嵁
/// </summary>
@@ -2833,8 +2117,7 @@
if (topic == gatewayID + "/" + "Error_Respon")
{
- var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID };
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorResponData>(jobject["Data"].ToString());
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
if (temp == null)
{
@@ -2842,13 +2125,12 @@
}
else
{
- dataRes = new DelFileOrDirResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+ dataRes = new DelFileOrDirResponseAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "FileTransfer/DelFileOrDir_Respon")
{
- var lsDir = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = CurrentGateWayId };
var resultDelFileOrDir = Newtonsoft.Json.JsonConvert.DeserializeObject<DelFileOrDirResponseData>(jobject["Data"].ToString());
if (resultDelFileOrDir != null)
{
@@ -2912,8 +2194,7 @@
if (topic == gatewayID + "/" + "Error_Respon")
{
- var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID };
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorResponData>(jobject["Data"].ToString());
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
if (temp == null)
{
@@ -2921,13 +2202,12 @@
}
else
{
- dataRes = new CreateDirResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
+ dataRes = new CreateDirResponseAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "FileTransfer/CreateDir_Respon")
{
- var lsDir = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = CurrentGateWayId };
var resultCreateDir = Newtonsoft.Json.JsonConvert.DeserializeObject<CreateDirResponseData>(jobject["Data"].ToString());
if (resultCreateDir != null)
{
@@ -2988,7 +2268,6 @@
if (topic == gatewayID + "/" + "SendAESKey_Respon")
{
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
- var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
var result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString());
sendKeyResponData = new SendKeyResponData { Result = result };
DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
@@ -3033,23 +2312,7 @@
/// <para>杩涘叆褰撳墠鐣岄潰鏃惰娣诲姞</para>
/// <para>閫�鍑哄綋鍓嶇晫闈㈡椂瑕佸叧闂�</para>
/// </summary>
- public static readonly System.Collections.Generic.List<IStatus> StatusList = new System.Collections.Generic.List<IStatus>();
-
- /// <summary>
- /// 璁惧鐘舵�佹洿鏂�
- /// </summary>
- /// <param name="commonDevice">Common device.</param>
- public static void UpdateDeviceStatus(CommonDevice commonDevice)
- {
- if (commonDevice == null)
- {
- return;
- }
- for (int i = 0; i < StatusList.Count; i++)
- {
- StatusList[i].Changed(commonDevice);
- }
- }
+ public static readonly List<IStatus> StatusList = new List<IStatus>();
/// <summary>
/// 璁惧淇℃伅鍙樺寲
@@ -3077,260 +2340,457 @@
/// <summary>
/// 灞�鍩熺綉鐨凪QTT
/// </summary>
- IMqttClient mqttClient;
+ IMqttClient localMqttClient = new MqttFactory().CreateMqttClient();
+ bool localMqttIsConnecting;
+ [Newtonsoft.Json.JsonIgnore]
+ public bool localIsConnected;
/// <summary>
/// 鎵嬫満鏍囪瘑
/// </summary>
static Guid currentGuid = Guid.NewGuid();
- /// <summary>
- /// 灞�鍩熺綉鐨凪QTT鏄惁姝e湪杩炴帴
- /// </summary>
- object mqttIsConnecting = false.ToString();
- public async System.Threading.Tasks.Task StartLocalMqtt(string brokerName)
- {
+ public async Task SendAesKey()
+ {
+ if (PubKey != null)
+ {
+ IsEncry = false;
+ var rsaString = ZigBee.Common.SecuritySet.RSAEncrypt(PubKey, Password);
+ var resultVerityfy = await SendAesKeyAsync(rsaString);
+ if (resultVerityfy == null)
+ {
+ resultVerityfy = await SendAesKeyAsync(rsaString);
+ }
+
+ if (resultVerityfy != null && resultVerityfy.Result == 0)
+ {
+ IsEncry = true;
+ }
+ }
+ }
+
+ public async Task StartLocalMqtt(string brokerName)
+ {
+ if (localMqttIsConnecting
+ || Shared.Common.Config.Instance.HomeId == ""
+ || localIsConnected)
+ {
+ return;
+ }
await System.Threading.Tasks.Task.Factory.StartNew(async () =>
{
try
{
- lock (mqttIsConnecting)
+ lock (localMqttClient)
{
- if (mqttIsConnecting.ToString() == true.ToString() || brokerName == null)
- {
- return;
- }
- mqttIsConnecting = true.ToString();
+ //琛ㄧず鍚庨潰灏嗚繘琛岃繛鎺�
+ localMqttIsConnecting = true;
- if (mqttClient == null)
+ //(3)褰揫杩炴帴Mqtt鎴愬姛鍚嶿鎴栬�匸Mqtt杞彂鏁版嵁缁欑綉鍏虫垚鍔熷悗],澶勭悊鎺ユ敹鍒版暟鎹寘鍝嶅簲鏃跺湪mqttClient_ApplicationMessageReceived杩欎釜鏂规硶澶勭悊
+ if (localMqttClient.ApplicationMessageReceivedHandler == null)
{
- //(2)鍒涘缓Mqtt瀹㈡埛绔�
- mqttClient = new MqttClientFactory().CreateMqttClient();
- //(3)褰揫杩炴帴Mqtt鎴愬姛鍚嶿鎴栬�匸Mqtt杞彂鏁版嵁缁欑綉鍏虫垚鍔熷悗],澶勭悊鎺ユ敹鍒版暟鎹寘鍝嶅簲鏃跺湪mqttClient_ApplicationMessageReceived杩欎釜鏂规硶澶勭悊
- mqttClient.ApplicationMessageReceived += (sender, e) =>
- {
- if (mqttClient == null || !mqttClient.IsConnected)
+ localMqttClient.UseApplicationMessageReceivedHandler((e) =>
{
- return;
- }
- mqttClient_MqttMsgPublishReceived(sender, e);
- };
- mqttClient.Disconnected += (sender, e) =>
- {
- IsEncry = false;
-#if DEBUG
- DebugPrintLog($" 鏈湴杩炴帴鏂紑_缃戝叧IP:{brokerName}_缃戝叧鏄惁鍔�:{IsEncry}_{System.DateTime.Now.ToString()}");
-#endif
- };
- mqttClient.Connected += async (sender, e) =>
+ if (!localMqttClient.IsConnected)
+ {
+ return;
+ }
+ mqttClient_MqttMsgPublishReceived(e);
+ });
+ }
+
+ if (localMqttClient.DisconnectedHandler == null)
+ {
+ localMqttClient.UseDisconnectedHandler(async (e) =>
{
-#if DEBUG
- DebugPrintLog($" 鏈湴杩炴帴鎴愬姛_缃戝叧IP:{brokerName}_缃戝叧鏄惁鍔�:{IsEncry}_褰撳墠瀵嗙爜:{Password}_{System.DateTime.Now.ToString()}");
-#endif
-
- if (PubKey != null)
+ DebugPrintLog($" 鏈湴杩炴帴鏂紑_缃戝叧IP:{brokerName}_缃戝叧鏄惁鍔�:{IsEncry}");
+ await DisConnectLocalMqttClient("StartLocalMqtt.DisconnectedHandler");
+ //await StartLocalMqtt("ReConnect");
+ });
+ }
+ if (localMqttClient.ConnectedHandler == null)
+ {
+ localMqttClient.UseConnectedHandler(async (e) =>
+ {
+ DebugPrintLog($" 鏈湴杩炴帴鎴愬姛_缃戝叧IP:{brokerName}_缃戝叧鏄惁鍔�:{IsEncry}_褰撳墠瀵嗙爜:{Password}");
+ IsRemote = false;
+ //Log鍐欏叆(璋冭瘯鐢�)
+ if (Shared.Phone.UserCenter.UserCenterResourse.HideOption.WriteSendAndReceveDataToFile == 1)
{
- var rsaString = ZigBee.Common.SecuritySet.RSAEncrypt(PubKey, Password);
- var resultVerityfy = await SendAesKeyAsync(rsaString);
- if (resultVerityfy == null)
- {
- resultVerityfy = await SendAesKeyAsync(rsaString);
- }
- if (resultVerityfy != null && resultVerityfy.Result == 0)
- {
- IsEncry = true;
- }
+ Shared.Phone.UserCenter.HdlLogLogic.Current.WriteLog(2, "鏈湴杩炴帴鎴愬姛");
}
- Shared.Phone.UserCenter.HdlGatewayLogic.Current.CheckGatewayByConnectChanged(Shared.Phone.UserCenter.GatewayConnectMode.WIFI);
- System.Console.WriteLine($"褰撳墠鏄綉鍏砏i-Fi鍦ㄩ�氳_{System.DateTime.Now.ToString()}");
+ });
+ }
- };
- }
-
- if (RemoteMqttClient != null && RemoteMqttClient.IsConnected == true)
- {
- RemoteMqttClient?.DisconnectAsync();
- System.Console.WriteLine($"鏀跺埌灞�鍩熺綉缃戝叧锛岃繙绋嬭繛鎺ヤ富鍔ㄦ柇寮�_{System.DateTime.Now.ToString()}");
- RemoteMqttClient = null;
- }
-
- if (mqttClient.IsConnected)
- {
- return;
- }
- }
- //(1)杩炴帴鍒癕qtt瀹㈡埛绔繛鎺ュ弬鏁�
- var connectCloudMqttClientOptions = new MqttClientTcpOptions
- {
- Server = brokerName, //ip鍦板潃
- ClientId = currentGuid.ToString(),
- CleanSession = true,// 璁剧疆鏄惁娓呯┖session,杩欓噷濡傛灉璁剧疆涓篺alse琛ㄧず鏈嶅姟鍣ㄤ細淇濈暀瀹㈡埛绔殑杩炴帴璁板綍锛岃繖閲岃缃负true琛ㄧず姣忔杩炴帴鍒版湇鍔″櫒閮戒互鏂扮殑韬唤杩炴帴
- KeepAlivePeriod = new TimeSpan(0, 5, 0),//璁剧疆蹇冭烦鏃堕棿锛堟渶澶у�硷紝2^16-1 = 65535绉� = 18灏忔椂銆傛渶灏忓�煎彲浠ヤ负0锛岃〃绀哄鎴风涓嶆柇寮�銆備竴鑸涓哄嚑鍒嗛挓锛屾瘮濡傚井淇″績璺冲懆鏈熶负300绉掋�傦級
- DefaultCommunicationTimeout = new TimeSpan(0, 0, 100),//璁剧疆瓒呮椂鏃堕棿
- };
- await mqttClient.ConnectAsync(connectCloudMqttClientOptions);
+ var dateTime = DateTime.Now;
+
+ new System.Threading.Thread(async () =>
+ {
+ try
+ {
+ if (localMqttClient.Options == null)
+ {
+ var options = new MQTTnet.Client.Options.MqttClientOptionsBuilder()//MQTT杩炴帴鍙傛暟濉厖
+ .WithClientId(currentGuid.ToString())//瀹㈡埛绔疘D
+ .WithTcpServer(brokerName, 1883)//TCP鏈嶅姟绔� 1883 锛屽嵆MQTT鏈嶅姟绔�
+ .WithCredentials("", "")//"", "")//鍑瘉 甯愬彿 瀵嗙爜
+ .WithCommunicationTimeout(new TimeSpan(0, 0, 60)) //閲嶈繛瓒呮椂鏃堕棿锛岄粯璁�5s
+ .WithKeepAlivePeriod(new TimeSpan(0, 0, 15)) //淇濇寔杩炴帴鏃堕棿锛岄粯璁�5s锛屽績璺冲寘
+ .Build();//
+ await localMqttClient.ConnectAsync(options);
+ }
+ else
+ {
+ await DisConnectLocalMqttClient("StartLocalMqtt");
+ await localMqttClient.ReconnectAsync();
+ }
+ localIsConnected = true;
+ await SendAesKey();
+ }
+ catch { }
+ dateTime = DateTime.MinValue;
+ })
+ { IsBackground = true }.Start();
+ while (dateTime != DateTime.MinValue)
+ {
+ System.Threading.Thread.Sleep(100);
+ }
+ }
}
catch (Exception ex)
- {
-#if DEBUG
+ {
+ //Log鍐欏叆(璋冭瘯鐢�)
+ if (Shared.Phone.UserCenter.UserCenterResourse.HideOption.WriteSendAndReceveDataToFile == 1)
+ {
+ Shared.Phone.UserCenter.HdlLogLogic.Current.WriteLog(2, "鏈湴杩炴帴寮傚父:\r\n" + ex.Message);
+ }
DebugPrintLog($"灞�鍩熺綉閫氳杩炴帴鍑哄紓甯�:{ex.Message}");
-#endif
}
finally
{
- mqttIsConnecting = false.ToString();
+ localMqttIsConnecting = false;
}
});
}
/// <summary>
+ /// 褰撳墠鏈夊笎鍙蜂笅鎵�鏈夌殑缃戝叧鍒楄〃鍙婁俊鎭�
+ /// </summary>
+ public static Dictionary<string, Shared.Phone.UserCenter.GatewayResult> GateWayBaseInfomations = new Dictionary<string, Shared.Phone.UserCenter.GatewayResult> { };
+ /// <summary>
+ /// 鑾峰彇褰撳墠甯愬彿鎵�鏈夌殑缃戝叧淇℃伅
+ /// </summary>
+ /// <returns></returns>
+ static async Task initGateWayBaseInfomation()
+ {
+ if (AllowRemoteCtrl == false)
+ {
+ //娌℃湁杩滅▼杩炴帴鐨勬潈闄�
+ return;
+ }
+ string loginToken = Config.Instance.Token;
+ if (Config.Instance.Home.IsOthreShare == true)
+ {
+ //鑾峰彇鎴愬憳鐨勭壒娈奣oken
+ var pra = new
+ {
+ CommonPage.RequestVersion,
+ LoginAccessToken = Config.Instance.Token,
+ MainAccountId = Config.Instance.Home.MainUserDistributedMark,
+ SharedHid = Config.Instance.Home.Id
+ };
+ var resultData = Shared.Phone.UserCenter.UserCenterLogic.GetByteResponseDataByRequestHttps("App/GetSharedHomeApiControl", false, pra, new List<string> { "NotCheck" });
+ if (resultData == null)
+ {
+ return;
+ }
+ var revertObj = Newtonsoft.Json.JsonConvert.DeserializeObject<Shared.Common.ResponseEntity.ResponsePack>(Encoding.UTF8.GetString(resultData));
+ //鍒嗕韩閾炬帴
+ var info = Newtonsoft.Json.JsonConvert.DeserializeObject<Shared.Phone.UserCenter.MemberAdministratorResult>(revertObj.ResponseData.ToString());
+ loginToken = info.RequestToken;
+ }
+
+ try
+ {
+ //璁剧疆璁块棶鎺ュ彛鐨勫弬鏁�
+ var pra2 = new Shared.Phone.UserCenter.GetGatewayPra();
+ pra2.IsOtherAccountCtrl = Config.Instance.Home.IsOthreShare;
+ pra2.ReqDto.PageSetting.Page = 1;
+ pra2.ReqDto.PageSetting.PageSize = 20;
+ pra2.ReqDto.LoginAccessToken = loginToken;
+ var bytes = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(pra2));
+
+ var result = CommonPage.Instance.DoRequestZigbeeHttpsInterface("https://global.hdlcontrol.com/HangZhouHdlCloudApi/App/GetSingleHomeGatewayPagger", bytes, loginToken);
+ if (result != null)
+ {
+ var jobject = Newtonsoft.Json.Linq.JObject.Parse(Encoding.UTF8.GetString(result));
+
+ var statuCode = jobject["StateCode"].ToString();
+ if (statuCode != "Success")
+ {
+ //搴忓垪鍖栧璞�
+ var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(pra2);
+ //Log鍑哄姏
+ string errorMsg = "鎺ュ彛璁块棶澶辫触鈽咃細App/GetSingleHomeGatewayPagger " + statuCode + "\r\n";
+ errorMsg += "鍙傛暟锛歕r\n" + requestJson;
+ Shared.Phone.UserCenter.HdlLogLogic.Current.WriteLog(-1, errorMsg);
+ return;
+ }
+
+ var responseData = jobject["ResponseData"];
+ if (responseData != null)
+ {
+ if (responseData["PageData"] != null)
+ {
+ var list = JArray.Parse(responseData["PageData"].ToString());
+ foreach (var v in list)
+ {
+ GateWayBaseInfomations[v["GatewayUniqueId"].ToString()] = new Shared.Phone.UserCenter.GatewayResult { AesKey = v["AesKey"].ToString(), MacMark = v["MacMark"].ToString(), MqttOnlineStatus = bool.Parse(v["MqttOnlineStatus"].ToString()) };
+ //if (RemoteMqttClient.IsConnected)
+ {
+ await RemoteMqttClient.SubscribeAsync($"/ZigbeeGateWayToClient/{v["MacMark"].ToString()}/#", MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce);
+ }
+ }
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ Shared.Phone.UserCenter.HdlLogLogic.Current.WriteLog(ex);
+ }
+ }
+
+ /// <summary>
/// 澶栫綉鐨凪QTT鏄惁姝e湪杩炴帴
/// </summary>
- static bool remoteMqttIsConnecting; static bool IsLoginAgain;
+ static bool remoteMqttIsConnecting;
+
/// <summary>
/// 杩滅▼MqttClient
/// </summary>
- public static IMqttClient RemoteMqttClient;
- private int IsLogin = 0;
- [Newtonsoft.Json.JsonIgnore]
- static Action actionTemp;
+ public static IMqttClient RemoteMqttClient = new MqttFactory().CreateMqttClient();
+ static bool remoteIsConnected;
+
+ /// <summary>
+ /// 杩滅▼寮�濮嬭繛鎺ョ殑鏃堕棿鐐�
+ /// </summary>
+ private static DateTime RemoteConnectTime = DateTime.Now;
/// <summary>
/// 鍚姩杩滅▼Mqtt
/// </summary>
/// <returns>The start.</returns>
/// <param name="brokerName">Broker name.</param>
- public static async System.Threading.Tasks.Task StartCloudMqtt()
- {
- await System.Threading.Tasks.Task.Factory.StartNew(async () =>
+ public static async Task StartRemoteMqtt()
+ {
+ //杩藉姞锛氭病鏈夎繙绋嬭繛鎺ョ殑鏉冮檺
+ if (AllowRemoteCtrl == false
+ || Shared.Common.Config.Instance.HomeId == ""
+ || remoteIsConnected)
+ {
+ return;
+ }
+ //濡傛灉杩滅▼杩樺湪杩炴帴涓�
+ if (remoteMqttIsConnecting == true)
+ {
+ //濡傛灉杩欎釜鍙橀噺涓�鐩村浜庤繛鎺ヤ腑鐨勭姸鎬�,浣嗘槸宸茬粡杩囧幓浜�10绉掍簡,杩樻槸true鐨勮瘽,璇存槑杩欓噷鏄湁鐐归棶棰樼殑,闇�瑕侀噸鏂板垱寤�
+ if ((DateTime.Now - RemoteConnectTime).TotalMilliseconds < 10 * 1000)
+ {
+ return;
+ }
+ }
+ //璁板綍璧疯繖娆¤繙绋嬭繛鎺ョ殑鏃堕棿鐐�
+ RemoteConnectTime = DateTime.Now;
+
+ await Task.Factory.StartNew(async () =>
{
try
{
- if (remoteMqttIsConnecting || Shared.Common.Config.Instance.HomeId == "")
+ lock (RemoteMqttClient)
{
- return;
- }
- remoteMqttIsConnecting = true;
+ //琛ㄧず鍚庨潰灏嗚繘琛岃繛鎺�
+ remoteMqttIsConnecting = true;
- var url = Shared.Common.Config.Instance.ZigbeeMqttBrokerLoadSubDomain;//.Replace("6688","6689");
- if (string.IsNullOrEmpty(url) || !url.StartsWith("tcp://") || url.Split(':').Length != 3)
- {
- remoteMqttIsConnecting = false;
- return;
- }
- if (RemoteMqttClient == null)
- {
- //(2)鍒涘缓Mqtt瀹㈡埛绔�
- RemoteMqttClient = new MqttClientFactory().CreateMqttClient();
+ #region 鍒濆鍖栬繙绋婱qtt
//(3)褰揫杩炴帴浜戠鐨凪qtt鎴愬姛鍚嶿鎴栬�匸浠ュ強鍚庨潰App閫氳繃浜戠Mqtt杞彂鏁版嵁缁欑綉鍏虫垚鍔熷悗],澶勭悊鎺ユ敹鍒颁簯绔暟鎹寘鍝嶅簲鏃跺湪mqttServerClient_ApplicationMessageReceived杩欎釜鏂规硶澶勭悊
- RemoteMqttClient.ApplicationMessageReceived += (sender, e) =>
+ if (RemoteMqttClient.ApplicationMessageReceivedHandler == null)
{
- if (RemoteMqttClient == null || !RemoteMqttClient.IsConnected)
- {
- return;
- }
- mqttRemoteClient_MqttMsgPublishReceived(sender, e);
- };
- RemoteMqttClient.Disconnected += (sender, e) =>
- {
-#if DEBUG
- DebugPrintLog($"杩滅▼杩炴帴鏂紑_{System.DateTime.Now.ToString()}");
-#endif
- };
- RemoteMqttClient.Connected += async (sender, e) =>
- {
-#if DEBUG
- DebugPrintLog($"杩滅▼杩炴帴鎴愬姛_{System.DateTime.Now.ToString()}");
-#endif
- Shared.Phone.UserCenter.HdlGatewayLogic.Current.CheckGatewayByConnectChanged(Shared.Phone.UserCenter.GatewayConnectMode.Remote);
- //娌℃湁涓荤綉鍏虫椂涓诲姩璇诲彇锛岃幏鍙栦富缃戝叧淇℃伅
- var gateWayList = GateWayList.FindAll(obj => obj.getGatewayBaseInfo.HomeId == Shared.Common.Config.Instance.HomeId);
- if (gateWayList.Find(obj => obj.getGatewayBaseInfo.IsMainGateWay == true) == null)
+ RemoteMqttClient.UseApplicationMessageReceivedHandler((e) =>
{
- if (gateWayList.Count == 1)
+ //杩欓噷鏄壒娈婄殑涓婚
+ if (e.ApplicationMessage.Topic == "/ZigbeeGateWayToClient/" + Config.Instance.ConnEmqClientId + "/Push/NotifySqueeze"//韪汉涓嬬嚎
+ || e.ApplicationMessage.Topic == "/ZigbeeGateWayToClient/" + Config.Instance.Guid + "/Push/Deleted"//鍒嗕韩鍒犻櫎
+ || e.ApplicationMessage.Topic == "/ZigbeeGateWayToClient/" + Config.Instance.Guid + "/Push/DeletedShareData"//鍒嗕韩鍒犻櫎
+ || e.ApplicationMessage.Topic == "/ZigbeeGateWayToClient/" + Config.Instance.Guid + "/Push/Update"//鎴愬憳鏉冮檺鍙樻洿
+ || e.ApplicationMessage.Topic == "/ZigbeeGateWayToClient/" + Config.Instance.Home.Id + "_" + Config.Instance.Guid + "/PrimaryUserDelYou")//瀛愯处鍙疯鍒犻櫎
{
- gateWayList[0].getGatewayBaseInfo.IsMainGateWay = true;
+ mqttRemoteClient_MqttMsgPublishReceived(e);
+ return;
}
- else
+ if (!RemoteMqttClient.IsConnected || !IsRemote)
{
- for (int i = 0; i < gateWayList.Count; i++)
+ return;
+ }
+ mqttRemoteClient_MqttMsgPublishReceived(e);
+ });
+ }
+
+ if (RemoteMqttClient.DisconnectedHandler == null)
+ {
+ RemoteMqttClient.UseDisconnectedHandler(async (e) =>
+ {
+ DebugPrintLog($"杩滅▼杩炴帴鏂紑");
+ await DisConnectRemoteMqttClient("StartRemoteMqtt.DisconnectedHandler");
+ //await StartRemoteMqtt();
+ });
+ }
+ if (RemoteMqttClient.ConnectedHandler == null)
+ {
+ RemoteMqttClient.UseConnectedHandler(async (e) =>
+ {
+ DebugPrintLog($"杩滅▼杩炴帴鎴愬姛");
+
+ if (Config.Instance.Home.IsOthreShare == true)
+ {
+ //璁㈤槄涓�涓垚鍛樿鍒犻櫎鐨勪富棰�
+ string myGuid = Config.Instance.Guid;
+ await RemoteMqttClient.SubscribeAsync("/ZigbeeGateWayToClient/" + myGuid + "/Push/Deleted");
+ //璁㈤槄涓�涓垎浜暟鎹凡缁忓彉鏇寸殑涓婚
+ await RemoteMqttClient.SubscribeAsync("/ZigbeeGateWayToClient/" + myGuid + "/Push/DeletedShareData");
+ //璁㈤槄涓�涓瓙璐﹀彿琚垹闄ょ殑涓婚
+ await RemoteMqttClient.SubscribeAsync("/ZigbeeGateWayToClient/" + Config.Instance.Home.Id + "_" + myGuid + "/PrimaryUserDelYou");
+ //璁㈤槄涓�涓垚鍛樻潈闄愬凡缁忓彉鏇寸殑涓婚
+ await RemoteMqttClient.SubscribeAsync("/ZigbeeGateWayToClient/" + myGuid + "/Push/Update");
+ }
+ //璁㈤槄涓�涓尋涓嬬嚎鐨勪富棰�
+ await RemoteMqttClient.SubscribeAsync("/ZigbeeGateWayToClient/" + Config.Instance.ConnEmqClientId + "/Push/NotifySqueeze");
+
+ await initGateWayBaseInfomation();
+
+ //娌℃湁涓荤綉鍏虫椂涓诲姩璇诲彇锛岃幏鍙栦富缃戝叧淇℃伅
+ var gateWayList = GateWayList.FindAll(obj => obj.HomeId == Shared.Common.Config.Instance.HomeId);
+ if (gateWayList.Find(obj => obj.IsMainGateWay == true) == null)
+ {
+ if (gateWayList.Count == 1)
{
- var gateWay = gateWayList[i];
- var info = await gateWay.GetZbGwInfoAsync();
- if (info == null || info.getGwData == null)
+ gateWayList[0].IsMainGateWay = true;
+ }
+ else
+ {
+ for (int i = 0; i < gateWayList.Count; i++)
{
- continue;
- }
- if (info.getGwData.IsDominant == 1)
- {
- gateWay.getGatewayBaseInfo.IsMainGateWay = true;
- for (int j = i + 1; j < gateWayList.Count; j++)
+ var gateWay = gateWayList[i];
+ var info = await gateWay.GetZbGwInfoAsync();
+ if (info == null || info.getGwData == null)
{
- gateWayList[j].getGatewayBaseInfo.IsMainGateWay = false;
+ continue;
}
- break;
+ if (info.getGwData.IsDominant == 1)
+ {
+ for (int j = 0; j < gateWayList.Count; j++)
+ {
+ if (gateWayList[i].GwId == info.getGwData.GwId)
+ {
+ gateWayList[i].IsMainGateWay = true;
+ }
+ else
+ {
+ gateWayList[i].IsMainGateWay = false;
+ }
+ }
+ break;
+ }
}
}
}
- }
- };
- }
-
- if (RemoteMqttClient.IsConnected)
- {
- //褰撶綉鍏崇殑杩炴帴鏂瑰紡鏀瑰彉鏃�,妫�娴嬬綉鍏�,鐒跺悗鏄剧ず鐗规晥(鍙噸澶嶈皟鐢�)
- return;
- }
- for (int i = 0; i < GateWayList.Count; i++)
- {
- var gateWay = GateWayList[i];
- try
- {
- gateWay.IsVirtual = true;
- await gateWay.DisConnect("鏈湴鎼滅礌涓嶅埌缃戝叧锛屽噯澶囪皟鐢ㄨ繙绋嬶紝鍏抽棴褰撳墠灞�鍩熺綉涓墍鏈夌綉鍏�");
+ });
}
- catch { }
- }
- //鏂紑鍚庨噸鏂伴摼鎺ラ渶瑕侀噸鏂扮櫥褰曡幏鍙栬繛鎺ョ殑瀵嗙爜
- var tempResult = await Shared.Phone.UserView.HomePage.Instance.LoginByPWDAsync(Shared.Common.Config.Instance.Account, Shared.Common.Config.Instance.Password);
- if (tempResult != 1)
- {
-#if DEBUG
- DebugPrintLog($"閲嶆柊杩炴帴杩滅▼閫氳澶辫触锛屽洜涓鸿幏鍙栨柊鐨凨EY澶辫触");
-#endif
- return;
+ #endregion
}
- //杩樻湁绉嶆儏鍐垫槸鍚屼竴涓狪D 鏈夊涓澶囩敤杩欎釜id杩炴帴锛堜細瀵艰嚧涓柇锛�
- string clientId = Shared.Common.Config.Instance.ConnectZigbeeMqttClientId;
- string username = Shared.Common.Config.Instance.ConnectGuid;
- string passwordRemote = Shared.Common.Config.Instance.ConnectZigbeeMqttBrokerPwd;
- //(1)杩炴帴鍒颁簯绔殑Mqtt瀹㈡埛绔繛鎺ュ弬鏁�
- var connectCloudMqttClientOptions = new MqttClientTcpOptions
- {
- Server = url.Split(':')[1].Substring("//".Length), //114.215.173.87 鍏堝啓ip鍚э紝杩欎釜鍦板潃鍙兘鍚庨潰浼氭崲鎴愬煙鍚�
- Port = int.Parse(url.Split(':')[2]),
- ClientId = clientId,
- UserName = username,//杩炴帴鐨勭敤鎴峰悕
- Password = passwordRemote,//杩炴帴鐨勫瘑鐮侊紙App鐧诲綍鍚庤幏鍙栧埌鐨勮繛鎺ヤ簯绔疢qtt瀵嗙爜鍙兘杩炴帴涓�娆℃垚鍔熶箣鍚庝笉鑳藉啀浣跨敤鐩稿悓鐨勫瘑鐮佽繘琛岃繛鎺qtt鍚﹀垯浼氭彁绀虹敤鎴峰悕瀵嗙爜澶辫触锛岃繛鎺ヤ笉涓婁簯绔�;锛�
- CleanSession = true,// 璁剧疆鏄惁娓呯┖session,杩欓噷濡傛灉璁剧疆涓篺alse琛ㄧず鏈嶅姟鍣ㄤ細淇濈暀瀹㈡埛绔殑杩炴帴璁板綍锛岃繖閲岃缃负true琛ㄧず姣忔杩炴帴鍒版湇鍔″櫒閮戒互鏂扮殑韬唤杩炴帴
- KeepAlivePeriod = new TimeSpan(0, 5, 0),//璁剧疆蹇冭烦鏃堕棿锛堟渶澶у�硷紝2^16-1 = 65535绉� = 18灏忔椂銆傛渶灏忓�煎彲浠ヤ负0锛岃〃绀哄鎴风涓嶆柇寮�銆備竴鑸涓哄嚑鍒嗛挓锛屾瘮濡傚井淇″績璺冲懆鏈熶负300绉掋�傦級
- DefaultCommunicationTimeout = new TimeSpan(0, 0, 100),//璁剧疆瓒呮椂鏃堕棿
- };
- //杩滅▼閫氳杩炴帴锛岃繛鎺ヤ簯绔湇鍔″櫒
- if (RemoteMqttClient != null)
+ try
{
- await RemoteMqttClient.ConnectAsync(connectCloudMqttClientOptions);
- }
+ byte[] result = null;
+ if (Config.Instance.Home.IsOthreShare == false)
+ {
+ //涓讳汉
+ var jsonData = new Dictionary<string, object>
+ {
+ ["RequestVersion"] = CommonPage.RequestVersion,
+ ["RequestSource"] = 0,
+ ["LoginAccessToken"] = Config.Instance.Token,
+ ["RequestProtocolType"] = 0,
+ ["PlatformStr"] = "h",//杩欎袱涓�煎鏋滀笉璁剧疆,鍒欎簯绔笉鍙戝竷涓婚
+ ["PublishPayloadJsonStr"] = "1"
+ };
+ var bytes = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(jsonData));
+ result = CommonPage.Instance.DoRequestZigbeeHttpsInterface("https://global.hdlcontrol.com/HangZhouHdlCloudApi/EmqMqtt/GetConnMqttInfo", bytes, Config.Instance.Token);
+ }
+ else
+ {
+ //鍒嗕韩鐨�
+ var jsonData = new Dictionary<string, object>
+ {
+ ["RequestVersion"] = CommonPage.RequestVersion,
+ ["RequestSource"] = 0,
+ ["LoginAccessToken"] = Config.Instance.Token,
+ ["RequestProtocolType"] = 0,
+ ["MainUserDistributedMark"] = Config.Instance.Home.MainUserDistributedMark,
+ ["HomeId"] = Config.Instance.Home.Id,
+ ["PlatformStr"] = "h",//杩欎袱涓�煎鏋滀笉璁剧疆,鍒欎簯绔笉鍙戝竷涓婚
+ ["PublishPayloadJsonStr"] = "1"
+ };
+ var bytes = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(jsonData));
+ result = CommonPage.Instance.DoRequestZigbeeHttpsInterface("https://global.hdlcontrol.com/HangZhouHdlCloudApi/EmqMqtt/ShareMemberConnMqttInfo", bytes, Config.Instance.Token);
+ }
+ if (result != null)
+ {
+ var jobject = Newtonsoft.Json.Linq.JObject.Parse(Encoding.UTF8.GetString(result));
+ if (jobject["StateCode"].ToString() == "NotAllowRemoteCtrl")
+ {
+ //娌℃湁杩滅▼杩炴帴鐨勬潈闄�
+ AllowRemoteCtrl = false;
+ return;
+ }
+ var responseData = jobject["ResponseData"];
+ if (responseData != null)
+ {
+ var connEmqDomainPort = responseData["ConnEmqDomainPort"]?.ToString();
+ var connEmqClientId = responseData["ConnEmqClientId"]?.ToString();
+ var connEmqUserName = responseData["ConnEmqUserName"]?.ToString();
+ var connEmqPwd = responseData["ConnEmqPwd"]?.ToString();
+ //璁板綍璧峰綋鍓嶇殑瀹㈡埛绔疘D
+ Config.Instance.ConnEmqClientId = connEmqClientId;
+
+ var connEmqDomainPorts = connEmqDomainPort.Replace("//", "").Split(':');
+ var domain = connEmqDomainPorts[1];
+ var port = connEmqDomainPorts[2];
+
+ var options = new MQTTnet.Client.Options.MqttClientOptionsBuilder()
+ .WithClientId(connEmqClientId)
+ .WithTcpServer(domain, int.Parse(port))
+ .WithCredentials(connEmqUserName, connEmqPwd)
+ .WithKeepAlivePeriod(TimeSpan.FromSeconds(20))
+ .WithCleanSession()
+ //.WithCommunicationTimeout(TimeSpan.FromSeconds(10))
+ .Build();
+ await DisConnectRemoteMqttClient("StartRemoteMqtt");
+ await RemoteMqttClient.ConnectAsync(options, CancellationToken.None);
+
+ remoteIsConnected = true;
+ }
+ }
+ }
+ catch { }
+ finally
+ {
+ //鏈�缁堣閲婃斁杩炴帴鐘舵��
+ remoteMqttIsConnecting = false;
+ }
}
catch (Exception ex)
{
-#if DEBUG
DebugPrintLog($"杩滅▼杩炴帴閫氳杩炴帴鍑哄紓甯�:{ex.Message}");
-#endif
- }
- finally
- {
- remoteMqttIsConnecting = false;
}
});
}
@@ -3338,26 +2798,52 @@
/// <summary>
/// 鏂紑鏈嶅姟鍣ㄨ繛鎺�
/// </summary>
- public async System.Threading.Tasks.Task DisConnect(string s)
+ public async Task DisConnectLocalMqttClient(string s)
{
try
{
-#if DEBUG
- DebugPrintLog($"涓诲姩鏂紑_{System.DateTime.Now.ToString()}_{s}");
-#endif
- if (mqttClient != null && mqttClient.IsConnected == true)
+ if (localIsConnected)
{
- await mqttClient.DisconnectAsync();
- }
+ localIsConnected = false;
+ //杩欎釜涓滆タ涔熻寮�
+ localMqttIsConnecting = false;
+ DebugPrintLog($"Local涓诲姩鏂紑_{s}");
+ //await localMqttClient.DisconnectAsync(new MQTTnet.Client.Disconnecting.MqttClientDisconnectOptions { }, CancellationToken.None);
+ await localMqttClient.DisconnectAsync();
+ }
}
catch (Exception ex)
{
-#if DEBUG
- DebugPrintLog($"鏂紑閫氳杩炴帴鍑哄紓甯�:{ex.Message}");
-#endif
+ DebugPrintLog($"Local鏂紑閫氳杩炴帴鍑哄紓甯�:{ex.Message}");
}
}
+
+ /// <summary>
+ /// 鏂紑杩滅▼Mqtt鐨勯摼鎺�
+ /// </summary>
+ public static async Task DisConnectRemoteMqttClient(string s = "")
+ {
+ try
+ {
+ if (remoteIsConnected)
+ {
+ remoteIsConnected = false;
+ //杩欎釜涓滆タ涔熻寮�
+ remoteMqttIsConnecting = false;
+ DebugPrintLog($"Remote涓诲姩鏂紑_{s}");
+ //await RemoteMqttClient.DisconnectAsync(new MQTTnet.Client.Disconnecting.MqttClientDisconnectOptions { }, CancellationToken.None);
+ await RemoteMqttClient.DisconnectAsync();
+ }
+ }
+ catch (Exception e)
+ {
+ DebugPrintLog($"Remote鏂紑閫氳杩炴帴鍑哄紓甯�:{e.Message}");
+ }
+ }
+
#endregion
+
+ #region 鏁版嵁鍙戦��
/// <summary>
/// 鍙戦�佹秷鎭埌鏈嶅姟鍣�
@@ -3385,32 +2871,38 @@
/// <summary>
/// 杩滅▼鍙戦�佹暟鎹牸寮�
/// </summary>
- async System.Threading.Tasks.Task SendRemoteMsg(string topicName, byte[] message, MQTTnet.Core.Protocol.MqttQualityOfServiceLevel qosLevel = MQTTnet.Core.Protocol.MqttQualityOfServiceLevel.ExactlyOnce, bool retain = false)
+ async System.Threading.Tasks.Task SendRemoteMsg(string topicName, byte[] message, bool retain = false)
{
- //(1)鐢熸垚[鐢ㄦ埛鍚�:瀵嗙爜]
- var userNameAndPwdStr = string.Concat(Shared.Common.Config.Instance.Guid, RemoteOperatorConsts.CAP_NUMBER, Shared.Common.Config.Instance.MD5PWD);
- DebugPrintLog($"userNameAndPwdStr锛歿userNameAndPwdStr} ");
-
- //(2)灏�(1)杞垚Base64瀛楃涓�,鐢熸垚鏍煎紡[Base64(鐢ㄦ埛鍚�:瀵嗙爜)]
- var userNameAndPwdStrBaseSexFour = Convert.ToBase64String(ZigBee.Common.CommonInfo.EncodingUTF8.GetBytes(userNameAndPwdStr));
-
- //(3)灏�(2)缁х画鐢熸垚鏍煎紡[Base64(鐢ㄦ埛鍚�:瀵嗙爜):Timestamp]
- var userNameAndPwdStrBaseSexFourAndTimestamp = string.Concat(userNameAndPwdStrBaseSexFour, RemoteOperatorConsts.CAP_NUMBER, CurrentTimeStamp.ToString());
-
- //[Zigbee.Buspro]App/id(甯愬彿Id)/Base64(DES[Base64(鐢ㄦ埛鍚�:瀵嗙爜):Timestamp ]/缃戝叧鍞竴Id/杞彂缁欑綉鍏崇殑涓婚/XX/XX
- //(4)鐢熸垚涓婃姤涓婚锛屼富棰樻ā寮忛渶瑕佷负 /ZigbeeApp/id(涓诲瓙璋冭瘯甯愬彿Id)/Base64(DES[Base64(鐢ㄦ埛鍚�:瀵嗙爜):Timestamp ]/缃戝叧鍞竴Id/topicName "000204022022" GateWayId 000204022022
- var reportTopic = string.Format("/{0}/{1}/{2}/{3}/{4}", RemoteOperatorConsts.ZIGBEE_APP_STARTS_WITH, Shared.Common.Config.Instance.Guid, userNameAndPwdStrBaseSexFourAndTimestamp, this.getGatewayBaseInfo?.gwID, topicName);
- var aa = System.Text.Encoding.UTF8.GetString(message);
-
- string topicEncStr = reportTopic;
- //鏂囦欢娴佷笉鐢ㄥ姞瀵�
- topicEncStr = ZigBee.Common.SecuritySet.AesEncrypt(System.Text.Encoding.UTF8.GetBytes(topicEncStr), Shared.Common.Config.Instance.MqttKey);
- topicEncStr = topicEncStr.Replace("/", "[[$-MQTT_TILT_SYMBOL_REPLACE-$]]").Replace("+", "[[$-MQTT_PLUS_SYMBOL_REPLACE-$]]");
- message = System.Text.Encoding.UTF8.GetBytes(SecuritySet.AesEncrypt(message, Shared.Common.Config.Instance.MqttKey));
- var bb = System.Text.Encoding.UTF8.GetString(message);
-
- //(6)鏋勫缓Mqtt闇�瑕佸彂甯冪殑鏁版嵁鍖�,鍙戝竷缁欎簯绔殑MqttBroker
- await RemoteMqttClient.PublishAsync(new MQTTnet.Core.MqttApplicationMessage(topicEncStr, message, qosLevel, retain));
+ try
+ {
+ if (this.GwId == string.Empty || !GateWayBaseInfomations.ContainsKey(this.GwId))
+ {
+ return;
+ }
+ var gateWayBaseInfomation = GateWayBaseInfomations[this.GwId];
+ message = SecuritySet.AesEncryptBytes(message, gateWayBaseInfomation.AesKey);
+ var topicEncStr = $"/ClientToZigbeeGateWay/{gateWayBaseInfomation.MacMark}/Common/{topicName}";
+ //(6)鏋勫缓Mqtt闇�瑕佸彂甯冪殑鏁版嵁鍖�,鍙戝竷缁欎簯绔殑MqttBroker
+ if (remoteIsConnected)
+ {
+ try
+ {
+ await RemoteMqttClient.PublishAsync(new MqttApplicationMessage { Topic = topicEncStr, Payload = message, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce });
+ }
+ catch (Exception e)
+ {
+ await DisConnectRemoteMqttClient(e.Message);
+ await StartRemoteMqtt();
+ if (remoteIsConnected)
+ {
+ await RemoteMqttClient.PublishAsync(new MqttApplicationMessage { Topic = topicEncStr, Payload = message, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce });
+ }
+ }
+ }
+ }
+ catch
+ {
+ }
}
/// <summary>
@@ -3419,59 +2911,71 @@
/// <returns></returns>
/// <param name="topic"></param>
/// <param name="message"></param>
- /// <param name="qosLevel"></param>
/// <param name="retain"></param>
- public async System.Threading.Tasks.Task Send(string topic, byte[] message, MQTTnet.Core.Protocol.MqttQualityOfServiceLevel qosLevel = MQTTnet.Core.Protocol.MqttQualityOfServiceLevel.ExactlyOnce, bool retain = false)
+ public async System.Threading.Tasks.Task Send(string topic, byte[] message, bool retain = false)
{
try
{
if (Shared.Common.Config.Instance.HomeId == "")
{
return;
+ }
+
+ //Log鍐欏叆(璋冭瘯鐢�)
+ if (Shared.Phone.UserCenter.UserCenterResourse.HideOption.WriteSendAndReceveDataToFile == 1)
+ {
+ string text = "杩滅▼鍙戦��:";
+ if (IsRemote == false) { text = "鏈湴鍙戦��:"; }
+ text += topic + "\r\n";
+ text += Encoding.UTF8.GetString(message) + "\r\n";
+ Shared.Phone.UserCenter.HdlLogLogic.Current.WriteLog(2, text);
}
if (IsRemote)
{
-
- await SendRemoteMsg(topic, message, qosLevel, retain);
-#if DEBUG
- DebugPrintLog($"杩滅▼ 鈥斺�斿彂閫佸埌缃戝叧鐨勪富棰�:{topic}_鍙戦�佸埌缃戝叧鐨勬暟鎹�:{System.Text.Encoding.UTF8.GetString(message)}_褰撳墠缃戝叧{CurrentGateWayId}_{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")}");//{System.DateTime.Now.ToString()}");// DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")
-#endif
+ await SendRemoteMsg(topic, message, retain);
+ DebugPrintLog($"杩滅▼鈥斺�斿彂閫佸埌缃戝叧鐨勪富棰�:{topic}_鍙戦�佸埌缃戝叧鐨勬暟鎹�:{System.Text.Encoding.UTF8.GetString(message)}");//{System.DateTime.Now.ToString()}");// DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")
}
else
{
-#if DEBUG
- DebugPrintLog($"灞�鍩熺綉鈥斺�斿彂閫佸埌缃戝叧鐨勪富棰�:{topic}_鍙戦�佸埌缃戝叧鐨勬暟鎹�:{System.Text.Encoding.UTF8.GetString(message)}_褰撳墠缃戝叧{CurrentGateWayId}_{System.DateTime.Now.ToString()}");
-#endif
- if (mqttClient == null || !mqttClient.IsConnected)
- {
- await StartLocalMqtt(getGatewayBaseInfo.IpAddress);
- }
-
+ DebugPrintLog($"灞�鍩熺綉鈥斺�斿彂閫佸埌缃戝叧鐨勪富棰�:{topic}_鍙戦�佸埌缃戝叧鐨勬暟鎹�:{System.Text.Encoding.UTF8.GetString(message)}_鏄惁鍔犲瘑:{IsEncry}");
+
if (IsEncry)
{
//鏂囦欢娴佷笉鐢ㄥ姞瀵�
if (topic != "FileTransfer/SendFile")
{
- topic = ZigBee.Common.SecuritySet.AesEncrypt(System.Text.Encoding.UTF8.GetBytes(topic), Password);
- message = System.Text.Encoding.UTF8.GetBytes(SecuritySet.AesEncrypt(message, password));
- DebugPrintLog($"灞�鍩熺綉鈥斺�斿彂閫佸埌缃戝叧鐨勪富棰橈紙绉樻枃锛�:{topic}_褰撳墠绉橀挜{Password}_鍙戦�佸埌缃戝叧鐨勬暟鎹紙绉樻枃锛�:{System.Text.Encoding.UTF8.GetString(message)}_褰撳墠缃戝叧{CurrentGateWayId}_{System.DateTime.Now.ToString()}");
-
+ message = SecuritySet.AesEncryptBytes(message, password);
}
-
- await mqttClient.PublishAsync(new MQTTnet.Core.MqttApplicationMessage(topic, message, qosLevel, retain));
- }
- else
- {
- await mqttClient.PublishAsync(new MQTTnet.Core.MqttApplicationMessage(topic, message, qosLevel, retain));
- }
+ }
+ if (localIsConnected)
+ {
+ try
+ {
+ await localMqttClient.PublishAsync(new MqttApplicationMessage { Topic = topic, Payload = message, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce, Retain = retain });
+ }
+ catch (Exception e)
+ {
+ DebugPrintLog($"Local涓诲姩鏂紑_{e.Message}");
+ await DisConnectLocalMqttClient(e.Message);
+ await StartLocalMqtt("ReConnect");
+ if (localIsConnected)
+ {
+ DebugPrintLog($"灞�鍩熺綉鈥斺�斾簩娆″彂閫佸埌缃戝叧鐨勪富棰�:{topic}_鍙戦�佸埌缃戝叧鐨勬暟鎹�:{System.Text.Encoding.UTF8.GetString(message)}_鏄惁鍔犲瘑:{IsEncry}");
+ await localMqttClient.PublishAsync(new MqttApplicationMessage { Topic = topic, Payload = message, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce, Retain = retain });
+ }
+ //Log鍐欏叆(璋冭瘯鐢�)
+ if (Shared.Phone.UserCenter.UserCenterResourse.HideOption.WriteSendAndReceveDataToFile == 1)
+ {
+ Shared.Phone.UserCenter.HdlLogLogic.Current.WriteLog(2, "鏈湴杩炴帴寮傚父鏂紑");
+ }
+ }
+ }
}
}
catch (Exception ex)
{
-#if DEBUG
DebugPrintLog($"Send:{ex.Message}");
-#endif
}
}
@@ -3481,125 +2985,130 @@
/// <returns></returns>
/// <param name="topic"></param>
/// <param name="message"></param>
- /// <param name="qosLevel"></param>
/// <param name="retain"></param>
- public async System.Threading.Tasks.Task Send(string topic, string message, MQTTnet.Core.Protocol.MqttQualityOfServiceLevel qosLevel = MQTTnet.Core.Protocol.MqttQualityOfServiceLevel.ExactlyOnce, bool retain = false)
+ public async System.Threading.Tasks.Task Send(string topic, string message, bool retain = false)
{
if (string.IsNullOrEmpty(message))
{
return;
}
- await Send(topic, System.Text.Encoding.UTF8.GetBytes(message), qosLevel, retain);
- }
-
-
- [Serializable]
- public class CloudTimeResponse
+ await Send(topic, System.Text.Encoding.UTF8.GetBytes(message), retain);
+ }
+
+ /// <summary>
+ /// 寮哄埗鎸囧畾浣跨敤鏈湴灞�鍩熺綉鍙戦�佹秷鎭埌鏈嶅姟鍣�
+ /// </summary>
+ /// <returns></returns>
+ /// <param name="topic"></param>
+ /// <param name="message"></param>
+ /// <param name="retain"></param>
+ public async Task SendLocation(string topic, byte[] message, bool retain = false)
{
- public string StateCode;
- public string Info;
- public string CloudTimestamp;
+ try
+ {
+ if (Shared.Common.Config.Instance.HomeId == "")
+ {
+ return;
+ }
+
+ DebugPrintLog($"灞�鍩熺綉鈥斺�斿彂閫佸埌缃戝叧鐨勪富棰�:{topic}_鍙戦�佸埌缃戝叧鐨勬暟鎹�:{System.Text.Encoding.UTF8.GetString(message)}_鏄惁鍔犲瘑:{IsEncry}");
+
+ if (IsEncry)
+ {
+ //鏂囦欢娴佷笉鐢ㄥ姞瀵�
+ if (topic != "FileTransfer/SendFile")
+ {
+ message = SecuritySet.AesEncryptBytes(message, password);
+ }
+ }
+ if (localIsConnected)
+ {
+ try
+ {
+ await localMqttClient.PublishAsync(new MqttApplicationMessage { Topic = topic, Payload = message, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce, Retain = retain });
+ }
+ catch (Exception e)
+ {
+ DebugPrintLog($"Local涓诲姩鏂紑_{e.Message}");
+ await DisConnectLocalMqttClient(e.Message);
+ await StartLocalMqtt("ReConnect");
+ if (localIsConnected)
+ {
+ DebugPrintLog($"灞�鍩熺綉鈥斺�斾簩娆″彂閫佸埌缃戝叧鐨勪富棰�:{topic}_鍙戦�佸埌缃戝叧鐨勬暟鎹�:{System.Text.Encoding.UTF8.GetString(message)}_鏄惁鍔犲瘑:{IsEncry}");
+ await localMqttClient.PublishAsync(new MqttApplicationMessage { Topic = topic, Payload = message, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce, Retain = retain });
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ DebugPrintLog($"Send:{ex.Message}");
+ }
}
+
+ #endregion
+
+ #region 鏁版嵁鎺ユ敹澶勭悊
/// <summary>
/// 鎺ユ敹杩滅▼鏁版嵁澶勭悊
/// </summary>
/// <param name="sender">Sender.</param>
/// <param name="e">E.</param>
- static void mqttRemoteClient_MqttMsgPublishReceived(object sender, MqttApplicationMessageReceivedEventArgs e)
+ static void mqttRemoteClient_MqttMsgPublishReceived(MqttApplicationMessageReceivedEventArgs e)
{
try
{
var topic = e.ApplicationMessage.Topic.TrimStart('/');
+ var payload = e.ApplicationMessage.Payload;
+
var message = string.Empty;
//浣犲綋鍓嶇殑IP鍙婄鍙e湪浜戠涓嶅瓨鍦�,璇烽噸鏂扮櫥褰曡繛鎺ヤ笅!
- if (topic == "YouIpAndPortNoRecord")
+
+ var topics = topic.Split("/");
+ if (topics.Length < 3)
{
- message = System.Text.Encoding.UTF8.GetString(e.ApplicationMessage.Payload);
- }
- else if (topic == "BeingSqueezedOffline")
- {
- //浜戠涓殑褰撳墠杩炴帴琚尋涓嬬嚎锛岄渶瑕侀�氱煡app
- //鍏ㄥ眬鎺ユ敹缃戝叧鎺ㄩ�佺殑鐨勯�昏緫(涓轰簡鎵ц閫熷害,灏藉彲鑳界殑鍒姞鑰楁椂鐨勬搷浣�)
- message = "BeingSqueezedOffline";
- Shared.Phone.UserCenter.HdlGatewayReceiveLogic.GatewayOverallMsgReceive("", topic, null);
- DebugPrintLog($"琚尋涓嬬嚎閫氱煡:{ topic}_杩滅▼杩斿洖鐨勬暟鎹甠{message}_{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")}");//{System.DateTime.Now.ToString()}");// DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")
return;
}
- //閲嶆柊鐧诲綍:甯愬彿鎴栬�呭叡浜繛鎺ヤ腑鐨刐瀛愬笎鍙峰垎甯冨紡Id$Share$鍒嗗竷寮忎綇瀹匢d=XXX灏氭湭鐧诲綍,璇烽噸鏂扮櫥褰曞悗鍐嶈繛鎺ュ悗鍐嶈繘琛屽彂甯冩搷浣�,濡傛灉鎮ㄥ綋鍓嶆槸鍒汉鍏变韩缁欎綘鐨勮繛鎺�,鍒欒閲嶆柊璇锋眰鑾峰彇杩炴帴淇℃伅涓�涓�,鍐嶅垵濮嬪寲杩炴帴鍐嶆鍙戝竷杩滅▼鎺у埗鍗冲彲!!
- else if (topic == "AppNoLogin")
+ if (topics[0] != "ZigbeeGateWayToClient")
{
- message = System.Text.Encoding.UTF8.GetString(e.ApplicationMessage.Payload);
+ return;
}
- else
+ if (topics[2] == "NotifyGateWayInfoChange")
{
- topic = topic.Replace("[[$-MQTT_TILT_SYMBOL_REPLACE-$]]", "/");
- topic = topic.Replace("[[$-MQTT_PLUS_SYMBOL_REPLACE-$]]", "+");
- topic = ZigBee.Common.SecuritySet.AesDecrypt(System.Text.Encoding.UTF8.GetBytes(topic), Shared.Common.Config.Instance.MqttKey).TrimStart('/'); ;
-
- if (!message.EndsWith("}"))
- {
- message = ZigBee.Common.SecuritySet.AesDecrypt(e.ApplicationMessage.Payload, Shared.Common.Config.Instance.MqttKey);
- }
+ initGateWayBaseInfomation();
+ return;
}
-#if DEBUG
- DebugPrintLog($"杩滅▼杩斿洖鐨勪富棰�:{ topic}_杩滅▼杩斿洖鐨勬暟鎹甠{message}_{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")}");//{System.DateTime.Now.ToString()}");// DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")
-#endif
- var cloudMqttResult = Newtonsoft.Json.JsonConvert.DeserializeObject<ZigBee.Common.CloudMqttResponsePack>(message);
- if (cloudMqttResult != null)
+ if (topics[2] == "Common")
{
- if (topic == "AppConnectMqttBrokerSuccess")
+ var macMark = topics[1];
+ topic = topic.Substring(topics[0].Length + topics[1].Length + topics[2].Length + 3);
+ if (payload[0] == (byte)'{' && payload[payload.Length - 1] == (byte)'}')
{
- RemoteTimeStamp = ulong.Parse(cloudMqttResult.CloudTimestamp);
- LoginRemoteDateTime = System.DateTime.Now;
-#if DEBUG
- DebugPrintLog($"杩滅▼杩斿洖涓婚:{topic}_褰撳墠鏃堕棿鎴�:_+{CurrentTimeStamp} + _+{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")}");//{System.DateTime.Now.ToString()}");// DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff" // {System.DateTime.Now.ToString()}");
-#endif
- return;
+ message = System.Text.Encoding.UTF8.GetString(payload);
}
else
{
- switch (cloudMqttResult.StateCode)
+ foreach (var key in GateWayBaseInfomations.Keys)
{
- case "GatewayIdNoIsYou":
- message = cloudMqttResult.StateCode + ":" + cloudMqttResult.Info;
-#if DEBUG
- DebugPrintLog($"杩滅▼杩斿洖杩斿洖鐨勬彁绀哄唴瀹�:{message}_褰撳墠鏃堕棿鎴�:_+{CurrentTimeStamp} + _+ {System.DateTime.Now.ToString()}");
-#endif
- return;
- case "AppTimeOut":
- RemoteTimeStamp = ulong.Parse(cloudMqttResult.CloudTimestamp);
- LoginRemoteDateTime = System.DateTime.Now;
- message = cloudMqttResult.StateCode + ":" + cloudMqttResult.Info;
-#if DEBUG
- DebugPrintLog($"杩滅▼杩斿洖杩斿洖鐨勬彁绀哄唴瀹�:{message}_褰撳墠鏃堕棿鎴�:_+{CurrentTimeStamp} + _+ {System.DateTime.Now.ToString()}");
-#endif
- return;
- case "AppReportSuccess":
- RemoteTimeStamp = ulong.Parse(cloudMqttResult.CloudTimestamp);
- LoginRemoteDateTime = System.DateTime.Now;
- message = cloudMqttResult.StateCode + ":" + cloudMqttResult.Info;
-#if DEBUG
- DebugPrintLog($"杩滅▼杩斿洖杩斿洖鐨勬彁绀哄唴瀹�:{message}_褰撳墠鏃堕棿鎴�:_+{CurrentTimeStamp} + _+ {System.DateTime.Now.ToString()}");
-#endif
- return;
- case "ForwardGatewayNoOnLine":
- message = cloudMqttResult.StateCode + ":" + cloudMqttResult.Info;
-#if DEBUG
- DebugPrintLog($"杩滅▼杩斿洖杩斿洖鐨勬彁绀哄唴瀹�:{message}_褰撳墠鏃堕棿鎴�:_+{CurrentTimeStamp} + _+ {System.DateTime.Now.ToString()}");
-#endif
- return;
+ var value = GateWayBaseInfomations[key];
+ if (value.MacMark == macMark)
+ {
+ topic = $"{key}/{topic}";
+ message = System.Text.Encoding.UTF8.GetString(ZigBee.Common.SecuritySet.AesDecryptBytes(e.ApplicationMessage.Payload, value.AesKey));
+ break;
+ }
}
}
}
- ReceiveMessage(topic, message, e);
+ DebugPrintLog($"杩滅▼杩斿洖鐨勪富棰�:{ topic}_杩滅▼杩斿洖鐨勬暟鎹甠{message}");//{System.DateTime.Now.ToString()}");// DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")
+
+ ReceiveMessage(topic, message, payload);
}
catch (Exception ex)
{
-#if DEBUG
- DebugPrintLog($"鎺ユ敹浜戠鏁版嵁寮傚父:{ex.Message}");
-#endif
+ DebugPrintLog($"鎺ユ敹浜戠鏁版嵁寮傚父:{ex.Message} ");
}
}
@@ -3609,45 +3118,40 @@
/// </summary>
/// <param name="sender">Sender.</param>
/// <param name="e">E.</param>
- void mqttClient_MqttMsgPublishReceived(object sender, MqttApplicationMessageReceivedEventArgs e)
+ void mqttClient_MqttMsgPublishReceived(MqttApplicationMessageReceivedEventArgs e)
{
try
{
var topic = e.ApplicationMessage.Topic;
- var message = System.Text.Encoding.UTF8.GetString(e.ApplicationMessage.Payload);
+ string payloadString = "";
if (IsEncry)
{
//涓婚
- topic = Common.SecuritySet.AesDecrypt(System.Text.Encoding.UTF8.GetBytes(topic), Password);
//涓嬭浇鐨勫瓧鑺傛祦涓嶉渶瑕佽В瀵�
if (topic.Split('/')[0] + "/" + topic.Split('/')[1] == topic.Split('/')[0] + "/" + "FileTransfer")
{
if (topic.Split('/')[2] != "DownloadFile")
{
- message = Common.SecuritySet.AesDecrypt(e.ApplicationMessage.Payload, Password);
+ payloadString = System.Text.Encoding.UTF8.GetString(Common.SecuritySet.AesDecryptBytes(e.ApplicationMessage.Payload, Password));
}
}
else if (topic == topic.Split('/')[0] + "/" + "SendAESKey_Respon") { }//鍥炲涓婚鏄鏂囷紝鏁版嵁鏄槑鏂�
else
{
- message = Common.SecuritySet.AesDecrypt(e.ApplicationMessage.Payload, Password);
+ payloadString = System.Text.Encoding.UTF8.GetString(Common.SecuritySet.AesDecryptBytes(e.ApplicationMessage.Payload, Password));
}
}
- else
- {
- topic = e.ApplicationMessage.Topic;
+ else
+ {
+ payloadString = System.Text.Encoding.UTF8.GetString(e.ApplicationMessage.Payload);
}
-#if DEBUG
- DebugPrintLog($"缃戝叧杩斿洖鐨勪富棰�:{topic}_缃戝叧杩斿洖鐨勮礋杞�:{message}_{System.DateTime.Now.ToString()}");
-#endif
- ReceiveMessage(topic, message, e);
+ DebugPrintLog($"缃戝叧杩斿洖鐨勪富棰�:{topic}_缃戝叧杩斿洖鐨勮礋杞�:{payloadString}");
+ ReceiveMessage(topic, payloadString, e.ApplicationMessage.Payload);
}
catch (Exception ex)
{
-#if DEBUG
DebugPrintLog($"鎺ユ敹缃戝叧鏁版嵁寮傚父:{ex.Message}");
-#endif
}
}
@@ -3657,7 +3161,7 @@
/// <param name="topic">Topic.</param>
/// <param name="message">Message.</param>
/// <param name="e">E.</param>
- static void ReceiveMessage(string topic, string message, MqttApplicationMessageReceivedEventArgs e)
+ static void ReceiveMessage(string topic, string message, byte[] payload)
{
try
{
@@ -3678,9 +3182,20 @@
epoint = topic.Split('/')[3];
cluID = topic.Split('/')[4];
attrId = topic.Split('/')[5];
- }
+ }
+
+ //Log鍐欏叆(璋冭瘯鐢�)
+ if (Shared.Phone.UserCenter.UserCenterResourse.HideOption.WriteSendAndReceveDataToFile == 1)
+ {
+ string text = "缃戝叧鍥炲:" + topic + "\r\n";
+ text += message + "\r\n";
+ Shared.Phone.UserCenter.HdlLogLogic.Current.WriteLog(2, text);
+ }
+
+ //鍏ㄥ眬鎺ユ敹缃戝叧鎺ㄩ�佺殑鐨勯�昏緫(涓轰簡鎵ц閫熷害,灏藉彲鑳界殑鍒姞鑰楁椂鐨勬搷浣�)
+ Shared.Phone.UserCenter.HdlGatewayReceiveLogic.Current.GatewayOverallMsgReceive(gatewayID, topic, reportStatus, message);
- var gwa = ZigBee.Device.ZbGateway.GateWayList.Find(obj => obj.getGatewayBaseInfo.gwID == gatewayID);
+ var gwa = GateWayList.Find(obj => obj.GwId == gatewayID);
if (gwa == null)
{
return;
@@ -3691,24 +3206,17 @@
gwa?.Actions(topic, message);
}
- if (gwa.GwResDataAction != null)
- {
- gwa.GwResDataAction(topic, message);
- }
- gwa.CurrentGateWayId = gatewayID;
+ gwa.GwResDataAction?.Invoke(topic, message);
- Newtonsoft.Json.Linq.JObject jobject = new Newtonsoft.Json.Linq.JObject();
+ var jobject = new Newtonsoft.Json.Linq.JObject();
if (topic.Split('/')[0] + "/" + topic.Split('/')[1] == topic.Split('/')[0] + "/" + "FileTransfer")
{
if (topic.Split('/')[2] == "DownloadFile")
{
- gwa.DownloadFileConfirmAsync(e.ApplicationMessage.Payload);
- message = System.Text.Encoding.UTF8.GetString(e.ApplicationMessage.Payload);
- if (gwa.FileContentAction != null)
- {
- gwa.FileContentAction(topic, e.ApplicationMessage.Payload);
- }
- DebugPrintLog($"缃戝叧杩斿洖鏁版嵁娴乢{message}_{System.DateTime.Now.ToString()}");
+ gwa.DownloadFileConfirmAsync(payload);
+ message = System.Text.Encoding.UTF8.GetString(payload);
+ gwa.FileContentAction?.Invoke(topic, payload);
+ DebugPrintLog($"缃戝叧杩斿洖鏁版嵁娴乢{message}");
return;
}
}
@@ -3717,41 +3225,6 @@
jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
}
- //鍏ㄥ眬鎺ユ敹缃戝叧鎺ㄩ�佺殑鐨勯�昏緫(涓轰簡鎵ц閫熷害,灏藉彲鑳界殑鍒姞鑰楁椂鐨勬搷浣�)
- Shared.Phone.UserCenter.HdlGatewayReceiveLogic.GatewayOverallMsgReceive(gatewayID, topic, jobject);
-
- #region 浜戠閫氱煡
- var cloudMqttResult = Newtonsoft.Json.JsonConvert.DeserializeObject<ZigBee.Common.CloudMqttResponsePack>(message);
- if (cloudMqttResult != null)
- {
- switch (cloudMqttResult.StateCode)
- {
- case "AppNoLogin":
- if (gwa.CloudErrorAction != null)
- {
- DebugPrintLog("AppNoLogin宸茬粡閫氱煡");
- gwa.CloudErrorAction("AppNoLogin", "鐧诲綍杩囨湡锛岃閲嶆柊鐧诲綍");
- }
- //鍏ㄥ眬鎺ユ敹缃戝叧鎺ㄩ�佺殑鐨勯�昏緫(涓轰簡鎵ц閫熷害,灏藉彲鑳界殑鍒姞鑰楁椂鐨勬搷浣�)
- Shared.Phone.UserCenter.HdlGatewayReceiveLogic.GatewayOverallMsgReceive(gatewayID, "AppNoLogin", jobject);
- break;
- case "AppTimeOut":
- if (gwa.CloudErrorAction != null)
- {
- DebugPrintLog("AppTimeOut宸茬粡閫氱煡");
- gwa.CloudErrorAction("AppTimeOut", "浠庝簯绔幏鍙栨暟鎹秴鏃讹紝璇烽噸鏂拌幏鍙�");
- }
- break;
- case "ForwardGatewayNoOnLine":
- if (gwa.CloudErrorAction != null)
- {
- DebugPrintLog("ForwardGatewayNoOnLine宸茬粡閫氱煡");
- gwa.CloudErrorAction("ForwardGatewayNoOnLine", "褰撳墠鎿嶄綔鐨勭綉鍏充笉鍦ㄧ嚎");
- }
- break;
- }
- }
- #endregion
#region 杩滅▼,涓荤綉鍏充笂鎶ラ�氱煡
if (IsRemote)
{
@@ -3760,18 +3233,16 @@
var gwData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.GetGwData>(jobject["Data"].ToString());
if (gwData != null)
{
- var gwList = GateWayList.FindAll(obj => obj.getGatewayBaseInfo.HomeId == Shared.Common.Config.Instance.HomeId);
-
+ var gwList = GateWayList.FindAll(obj => obj.HomeId == Shared.Common.Config.Instance.HomeId);
for (int i = 0; i < gwList.Count; i++)
{
- var gwTemp = gwList[i];
- if (gwData.IsDominant == 1)
- {
- gwTemp.getGatewayBaseInfo.IsMainGateWay = true;
- for (int j = i + 1; j < gwList.Count; j++)
- {
- gwList[j].getGatewayBaseInfo.IsMainGateWay = false;
- }
+ if (gwList[i].GwId == gatewayID)
+ {
+ gwList[i].IsMainGateWay = true;
+ }
+ else
+ {
+ gwList[i].IsMainGateWay = false;
}
}
}
@@ -3779,136 +3250,23 @@
}
#endregion
- #region 璁惧鏂颁笂鎶�
- //姝ラ1锛夌綉鍏冲憡鐭ュ鎴风鏈夋柊璁惧鍔犲叆zigbee缃戠粶銆�
- if (topic == gatewayID + "/" + "Device/DeviceJoinZbNet_Respon")
- {
- var gatewayTemp = new ZbGateway() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
- gatewayTemp.deviceDeviceJoinZbNetResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceDeviceJoinZbNetResponData>(jobject["Data"].ToString());
- if (gatewayTemp.deviceDeviceJoinZbNetResponData == null)
- {
- return;
- }
- //涓婃姤绫诲瀷閫氱煡
- if (gwa.ReportAction != null)
- {
- DebugPrintLog("Device/DeviceJoinZbNet宸茬粡閫氱煡");
- gatewayTemp.CurrentGateWayId = gatewayID;//杩欓噷鐨凜urrentGateWayId鏄綋鍓嶆柊new ZbGateway鐨勫��
- gwa.ReportAction("Device/DeviceJoinZbNet", gatewayTemp);
- }
- }
- //姝ラ2锛夌綉鍏冲憡鐭ュ鎴风鑾峰彇鏂拌澶囨墍鏈夌鐐逛俊鎭槸鍚︽垚鍔�
- if (topic == gatewayID + "/" + "Device/IsGetEpointInfo_Respon")
- {
- var gatewayTemp = new ZbGateway() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
- gatewayTemp.deviceIsGetEpointInfoResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceIsGetEpointInfoResponData>(jobject["Data"].ToString());
- if (gatewayTemp.deviceIsGetEpointInfoResponData == null)
- {
- return;
- }
- //涓婃姤绫诲瀷閫氱煡
- if (gwa.ReportAction != null)
- {
- DebugPrintLog("Device/IsGetEpointInfo宸茬粡閫氱煡");
- gatewayTemp.CurrentGateWayId = gatewayID;//杩欓噷鐨凜urrentGateWayId鏄綋鍓嶆柊new ZbGateway鐨勫��
- gwa.ReportAction("Device/IsGetEpointInfo", gatewayTemp);
- }
- }
- //姝ラ3锛夌綉鍏充笂鎶ヨ妭鐐硅澶囨墍鏈夌鐐逛俊鎭�
- if (topic == gatewayID + "/" + "DeviceInComingRespon")
- {
- //鏂拌澶囦笂鎶ワ紝閲嶆柊鍙戣幏鍙栨墍鏈夌殑璁惧
- var tempDevice = new CommonDevice() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
- tempDevice.getNewDeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.NewDeviceInfoData>(jobject["Data"].ToString());
- if (gwa.ReportAction != null)
- {
- DebugPrintLog("DeviceInComingRespon宸茬粡閫氱煡");
- gwa.ReportAction("DeviceInComingRespon", tempDevice.getNewDeviceInfo);
- }
- UpdateDeviceInfo(tempDevice, "DeviceInComingRespon");
- UpdateDeviceStatus(gwa);
- }
- #endregion
+
#region 璁惧鍦ㄧ嚎鐘舵�佹洿鏂板弽棣�
- else if (topic == gatewayID + "/" + "OnlineStatusChange_Respon")
- {
- var tempDevice = new CommonDevice() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
- tempDevice.IsOnline = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["IsOnline"].ToString());
-
- if (gwa.ReportAction != null)
- {
- DebugPrintLog("OnlineStatusChange宸茬粡閫氱煡");
- gwa.ReportAction("OnlineStatusChange", tempDevice);
- }
- var infoTempDevice = gwa.DeviceList.Find(obj => obj.DeviceID == tempDevice.DeviceID && obj.DeviceAddr == tempDevice.DeviceAddr);
- if (infoTempDevice == null)
- {
- gwa.DeviceList.Add(tempDevice);
- UpdateDeviceStatus(tempDevice);
- UpdateDeviceInfo(tempDevice, "OnlineStatusChange");
- }
- else
- {
- if (infoTempDevice.DeviceInfo != null)
- {
- infoTempDevice.DeviceInfo.IsOnline = infoTempDevice.IsOnline;
- }
- UpdateDeviceInfo(infoTempDevice, "OnlineStatusChange");
- UpdateDeviceStatus(infoTempDevice);
- }
- }
- #endregion
- #region 璁惧琚垹闄や笂鎶�
- else if (topic == gatewayID + "/" + "RemoveDeviceRespon")
- {
- var gatewayTemp = new ZbGateway() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
- gatewayTemp.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.RemoveDeviceResponseData>(jobject["Data"].ToString());
- if (gatewayTemp.removeDeviceResponseData != null)
- {
- try
- {
- if (gatewayTemp.removeDeviceResponseData.Result == 0)
- {
- foreach (var delD in gatewayTemp.removeDeviceResponseData.DeviceList)
- {
- var tempDevice = new CommonDevice() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
- tempDevice.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.RemoveDeviceResponseData>(jobject["Data"].ToString());
- if (tempDevice.removeDeviceResponseData == null)
- {
- return;
- }
- else
- {
- UpdateDeviceStatus(tempDevice);
- UpdateDeviceInfo(tempDevice, "RemoveDeviceRespon");
- if (tempDevice.removeDeviceResponseData.Result == 0)
- {
- var infoTempDevice = gwa.DeviceList.Find((CommonDevice obj) => obj.DeviceID == tempDevice.DeviceID && obj.DeviceAddr == tempDevice.DeviceAddr && obj.DeviceEpoint == tempDevice.DeviceEpoint);
- if (infoTempDevice != null)
- {
- gwa.DeviceList.Remove(infoTempDevice);
- }
- }
- }
- }
- }
- }
- catch { }
- }
- }
+ //2020.05.11 鍒犻櫎
+
#endregion
+
#region 璁惧鐘舵�佷笂鎶�
- else if (topic == gatewayID + "/" + "DeviceStatusReport" + "/" + addr + "/" + epoint + "/" + cluID + "/" + attrId)
+ if (topic == gatewayID + "/" + "DeviceStatusReport" + "/" + addr + "/" + epoint + "/" + cluID + "/" + attrId)
{
var deviceID = jobject.Value<int>("Device_ID");
var deviceAddr = jobject.Value<string>("DeviceAddr");
var tempEpoint = jobject.Value<int>("Epoint");
var dataId = jobject.Value<int>("Data_ID");
- var tempDevice = new CommonDevice { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId };
+ var tempDevice = new CommonDevice { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint };
tempDevice.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DeviceStatusReportData>(jobject["Data"].ToString());
- UpdateDeviceStatus(tempDevice);
UpdateDeviceInfo(tempDevice, "DeviceStatusReport");
}
#endregion
@@ -3919,7 +3277,7 @@
switch ((DeviceType)(deviceID))
{
case DeviceType.DoorLock:
- var doorLock = new DoorLock() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
+ var doorLock = new DoorLock() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), CurrentGateWayId = gwa.GwId };
var OperatingEventNotificationDatad = Newtonsoft.Json.JsonConvert.DeserializeObject<ZigBee.Device.DoorLock.DoorLockOperatingEventNotificationCommand>(jobject["Data"].ToString());
if (OperatingEventNotificationDatad != null)
{
@@ -3930,7 +3288,6 @@
DebugPrintLog("DoorLockProgrammingEventNotificationCommand宸茬粡閫氱煡");
gwa.ReportAction("DoorLockProgrammingEventNotificationCommand", doorLock);
}
- UpdateDeviceStatus(doorLock);
UpdateDeviceInfo(doorLock, "DoorLockProgrammingEventNotificationCommand");
break;
}
@@ -3943,7 +3300,7 @@
switch ((DeviceType)(deviceID))
{
case DeviceType.DoorLock:
- var doorLock = new DoorLock() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
+ var doorLock = new DoorLock() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), CurrentGateWayId = gwa.GwId };
var ProgrammingEventNotificationData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZigBee.Device.DoorLock.DoorLockProgrammingEventNotificationCommand>(jobject["Data"].ToString());
if (ProgrammingEventNotificationData != null)
{
@@ -3954,41 +3311,21 @@
DebugPrintLog("DoorLockProgrammingEventNotificationCommand宸茬粡閫氱煡");
gwa.ReportAction("DoorLockProgrammingEventNotificationCommand", doorLock);
}
- UpdateDeviceStatus(doorLock);
UpdateDeviceInfo(doorLock, "DoorLockProgrammingEventNotificationCommand");
break;
}
- }
+ }
#endregion
#region IAS瀹夐槻淇℃伅涓婃姤
- else if (topic == gatewayID + "/" + "IASInfoReport")
- {
- var deviceID = jobject.Value<int>("Device_ID");
- switch ((DeviceType)(deviceID))
- {
- case DeviceType.IASZone:
- var ias = new IASZone() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
- ias.iASInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone.IASInfoData>(jobject["Data"].ToString());
- //涓婃姤绫诲瀷閫氱煡锛屽繀闇�鍏堣皟鐢紝鐒跺悗鎵嶆湁閫氱煡锛屽惁鍒欐槸绌轰笉浼氶�氱煡鐨�
- if (gwa.ReportAction != null)
- {
- DebugPrintLog("IASInfoReport宸茬粡閫氱煡");
- //ias.Save();
- gwa.ReportAction("IASInfoReport", ias.iASInfo);
- }
-
- UpdateDeviceStatus(ias);
- UpdateDeviceInfo(ias, "IASInfoReport");
- break;
- }
- }
+
+ //2020.05.11 鍒犻櫎
+
#endregion
#region 涓嬭浇杩涘害涓婃姤
else if (topic == gatewayID + "/" + "DownloadFile_Progress")
{
- var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
- gatewayTemp.downloadFileProgressResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<DownloadFileProgressResponData>(jobject["Data"].ToString());
- if (gatewayTemp.downloadFileProgressResponData == null)
+ gwa.downloadFileProgressResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DownloadFileProgressResponData>(jobject["Data"].ToString());
+ if (gwa.downloadFileProgressResponData == null)
{
return;
}
@@ -3996,15 +3333,13 @@
if (gwa.ReportAction != null)
{
DebugPrintLog("DownloadFileProgress");
- gatewayTemp.CurrentGateWayId = gatewayID;//杩欓噷鐨凜urrentGateWayId鏄綋鍓嶆柊new ZbGateway鐨勫��
- gwa.ReportAction("DownloadFileProgress", gatewayTemp);
+ gwa.ReportAction("DownloadFileProgress", gwa);
}
}
else if (topic == gatewayID + "/" + "ZbGwOperation/Upgrade_Respon")
{
- var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
- gatewayTemp.zbGwOperationUpgradeData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGwOperationUpgradeData>(jobject["Data"].ToString());
- if (gatewayTemp.zbGwOperationUpgradeData == null)
+ gwa.zbGwOperationUpgradeData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGwOperationUpgradeData>(jobject["Data"].ToString());
+ if (gwa.zbGwOperationUpgradeData == null)
{
return;
}
@@ -4012,16 +3347,14 @@
if (gwa.ReportAction != null)
{
DebugPrintLog("鍗忚皟鍣ㄥ崌绾х櫨鍒嗘瘮");
- gatewayTemp.CurrentGateWayId = gatewayID;//杩欓噷鐨凜urrentGateWayId鏄綋鍓嶆柊new ZbGateway鐨勫��
- gwa.ReportAction("CordinatorUpgradePercent", gatewayTemp);
+ gwa.ReportAction("CordinatorUpgradePercent", gwa);
}
}
else if (topic == gatewayID + "/" + "OTA/Schedule_Respon")
{
- var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
- gatewayTemp.oTAScheduleResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<OTAScheduleResponData>(jobject["Data"].ToString());
+ gwa.oTAScheduleResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.OTAScheduleResponData>(jobject["Data"].ToString());
- if (gatewayTemp.oTAScheduleResponData == null)
+ if (gwa.oTAScheduleResponData == null)
{
return;
}
@@ -4030,16 +3363,14 @@
if (gwa.ReportAction != null)
{
DebugPrintLog("鑺傜偣璁惧鍗囩骇鐧惧垎姣�");
- gatewayTemp.CurrentGateWayId = gatewayID;//杩欓噷鐨凜urrentGateWayId鏄綋鍓嶆柊new ZbGateway鐨勫��
- gwa.ReportAction("DeviceUpgradePercent", gatewayTemp);
+ gwa.ReportAction("DeviceUpgradePercent", gwa);
}
}
else if (topic == gatewayID + "/" + "VirtualDrive/Upgrade_Respon")
{
- var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
- gatewayTemp.virtualDriveUpgradeResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<VirtualDriveUpgradeResponData>(jobject["Data"].ToString());
+ gwa.virtualDriveUpgradeResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<VirtualDriveUpgradeResponData>(jobject["Data"].ToString());
- if (gatewayTemp.virtualDriveUpgradeResponData == null)
+ if (gwa.virtualDriveUpgradeResponData == null)
{
return;
}
@@ -4047,18 +3378,16 @@
if (gwa.ReportAction != null)
{
DebugPrintLog("铏氭嫙椹卞姩鍗囩骇鐧惧垎姣�");
- gatewayTemp.CurrentGateWayId = gatewayID;//杩欓噷鐨凜urrentGateWayId鏄綋鍓嶆柊new ZbGateway鐨勫��
- gwa.ReportAction("VirtualDriveUpgrade", gatewayTemp);
+ gwa.ReportAction("VirtualDriveUpgrade", gwa);
}
}
#endregion
#region 閲嶅惎缃戝叧绯荤粺
else if (topic == gatewayID + "/" + "GwReboot_Respon")
{
- var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID") };
- gatewayTemp.gwRebootResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<GwRebootResponData>(jobject["Data"].ToString());
+ var gwRebootResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<GwRebootResponData>(jobject["Data"].ToString());
- if (gatewayTemp.gwRebootResponData == null)
+ if (gwRebootResponData == null)
{
return;
}
@@ -4066,15 +3395,14 @@
if (gwa.ReportAction != null)
{
DebugPrintLog("GwReboot_Respon宸茬粡閫氱煡");
- gatewayTemp.CurrentGateWayId = gatewayID;//杩欓噷鐨凜urrentGateWayId鏄綋鍓嶆柊new ZbGateway鐨勫��
- gwa.ReportAction("GwReboot_Respon", gatewayTemp);
+ gwa.ReportAction("GwReboot_Respon", gwRebootResponData);
}
}
#endregion
#region 闃插尯琚Е鍙戞椂鎶ュ憡
else if (topic == gatewayID + "/" + "Security/ZoneTriggerReport")
{
- var ias = new Safeguard() { DataID = jobject.Value<int>("Data_ID"), GateWayId = gwa.getGatewayBaseInfo.gwID };
+ var ias = new Safeguard() { DataID = jobject.Value<int>("Data_ID"), GateWayId = gwa.GwId };
ias.zoneTriggerReportData = Newtonsoft.Json.JsonConvert.DeserializeObject<Safeguard.ZoneTriggerReportData>(jobject["Data"].ToString());
if (ias.zoneTriggerReportData == null)
@@ -4092,43 +3420,43 @@
#region 閫昏緫琚皟鐢ㄥ弽棣�
else if (topic == gatewayID + "/" + "Logic/Execute_Respon")
{
- var logic = new Logic() { DataID = jobject.Value<int>("Data_ID"), GateWayId = gwa.getGatewayBaseInfo.gwID };
- logic.logicExecuteRespo = Newtonsoft.Json.JsonConvert.DeserializeObject<Logic.ExecuteResponse>(jobject["Data"].ToString());
+ //var logic = new Logic() { DataID = jobject.Value<int>("Data_ID"), GateWayId = gwa.GwId };
+ //logic.logicExecuteRespo = Newtonsoft.Json.JsonConvert.DeserializeObject<Logic.ExecuteResponse>(jobject["Data"].ToString());
- if (logic.logicExecuteRespo == null)
- {
- return;
- }
- //涓婃姤绫诲瀷閫氱煡
- if (gwa.ReportAction != null)
- {
- DebugPrintLog("LogicExecuteReport宸茬粡閫氱煡");
- gwa.ReportAction("LogicExecuteReport", logic.logicExecuteRespo);
- }
+ //if (logic.logicExecuteRespo == null)
+ //{
+ // return;
+ //}
+ ////涓婃姤绫诲瀷閫氱煡
+ //if (gwa.ReportAction != null)
+ //{
+ // DebugPrintLog("LogicExecuteReport宸茬粡閫氱煡");
+ // gwa.ReportAction("LogicExecuteReport", logic.logicExecuteRespo);
+ //}
}
#endregion
#region 鏃堕棿鐐规潯浠舵帹杩熸墽琛�
else if (topic == gatewayID + "/" + "Logic/TimingWillArrive")
{
- var logic = new Logic() { DataID = jobject.Value<int>("Data_ID"), GateWayId = gwa.getGatewayBaseInfo.gwID };
- logic.timingWillArriveData = Newtonsoft.Json.JsonConvert.DeserializeObject<Logic.TimingWillArriveData>(jobject["Data"].ToString());
+ //var logic = new Logic() { DataID = jobject.Value<int>("Data_ID"), GateWayId = gwa.GwId };
+ //logic.timingWillArriveData = Newtonsoft.Json.JsonConvert.DeserializeObject<Logic.TimingWillArriveData>(jobject["Data"].ToString());
- if (logic.timingWillArriveData == null)
- {
- return;
- }
- //涓婃姤绫诲瀷閫氱煡
- if (gwa.ReportAction != null)
- {
- DebugPrintLog("TimingWillArrive宸茬粡閫氱煡");
- gwa.ReportAction("TimingWillArrive", logic.timingWillArriveData);
- }
+ //if (logic.timingWillArriveData == null)
+ //{
+ // return;
+ //}
+ ////涓婃姤绫诲瀷閫氱煡
+ //if (gwa.ReportAction != null)
+ //{
+ // DebugPrintLog("TimingWillArrive宸茬粡閫氱煡");
+ // gwa.ReportAction("TimingWillArrive", logic.timingWillArriveData);
+ //}
}
#endregion
#region 妯″紡瀹夐槻鍔ㄤ綔琚渶缁堟縺娲绘椂鍙戦�佹姤璀︿俊鎭�
else if (topic == gatewayID + "/" + "Security/ModeTriggerReport")
{
- var ias = new Safeguard() { DataID = jobject.Value<int>("Data_ID"), GateWayId = gwa.getGatewayBaseInfo.gwID };
+ var ias = new Safeguard() { DataID = jobject.Value<int>("Data_ID"), GateWayId = gwa.GwId };
ias.modeTriggerReportData = Newtonsoft.Json.JsonConvert.DeserializeObject<Safeguard.ModeTriggerReportData>(jobject["Data"].ToString());
if (ias.modeTriggerReportData == null)
{
@@ -4145,7 +3473,7 @@
#region 閫氳繃澶栭儴鏂瑰紡甯冮槻鎾ら槻鎴愬姛鏃舵姤鍛婃伅
else if (topic == gatewayID + "/" + "Security/EnOrWithdrawSucceedReport")
{
- var ias = new Safeguard() { DataID = jobject.Value<int>("Data_ID"), GateWayId = gwa.getGatewayBaseInfo.gwID };
+ var ias = new Safeguard() { DataID = jobject.Value<int>("Data_ID"), GateWayId = gwa.GwId };
ias.enOrWithdrawSucceedReportData = Newtonsoft.Json.JsonConvert.DeserializeObject<Safeguard.EnOrWithdrawSucceedReportData>(jobject["Data"].ToString());
if (ias.enOrWithdrawSucceedReportData == null)
{
@@ -4162,7 +3490,7 @@
#region 鑳佽揩瀵嗙爜鎾ら槻鏃剁煭淇℃帹閫�
else if (topic == gatewayID + "/" + "Security/PushTargetInfo")
{
- var ias = new Safeguard() { DataID = jobject.Value<int>("Data_ID"), GateWayId = gwa.getGatewayBaseInfo.gwID };
+ var ias = new Safeguard() { DataID = jobject.Value<int>("Data_ID"), GateWayId = gwa.GwId };
ias.coercedPWDWithdrawReportData = Newtonsoft.Json.JsonConvert.DeserializeObject<Safeguard.CoercedPWDWithdrawReportData>(jobject["Data"].ToString());
if (ias.coercedPWDWithdrawReportData == null)
{
@@ -4176,42 +3504,22 @@
}
}
#endregion
- #region 鑺傜偣璁惧榛樿鍙嶉
- else if (topic == gatewayID + "/" + "DeviceDefaultAck")
- {
- var deviceDefaultAck = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
- if (deviceDefaultAck == null)
- {
- return;
- }
- //涓婃姤绫诲瀷閫氱煡
- if (gwa.ReportAction != null)
- {
- DebugPrintLog("DeviceDefaultAck");
- gwa.ReportAction("DeviceDefaultAck", deviceDefaultAck);
- }
- }
- #endregion
#region 璁惧璇锋眰APP鑾峰彇鍗囩骇鏁版嵁
else if (topic == gatewayID + "/" + "ZbDataPassthrough")
{
- var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
- gatewayTemp.clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString());
- if (gatewayTemp.clientDataPassthroughResponseData == null)
- {
- return;
- }
-
//涓婃姤绫诲瀷閫氱煡
if (gwa.ReportAction != null)
- {
- DebugPrintLog("DeviceRequestAcUpdateData");
- gwa.ReportAction("DeviceRequestAcUpdateData", gatewayTemp.clientDataPassthroughResponseData);
+ {
+ var clientDataPassthrough = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ClientDataPassthroughResponseData>(jobject["Data"].ToString());
+ if (clientDataPassthrough != null)
+ {
+ DebugPrintLog("DeviceRequestAcUpdateData");
+ gwa.ReportAction("DeviceRequestAcUpdateData", clientDataPassthrough);
+ }
}
}
#endregion
- DebugPrintLog("缃戝叧杩斿洖鏁版嵁閫氱煡");
}
catch (Exception ex)
{
@@ -4219,5 +3527,45 @@
}
}
+
+ #endregion
+
+ #region 淇濆瓨缂撳瓨
+
+ /// <summary>
+ /// 閲嶆柊淇濆瓨璁惧
+ /// </summary>
+ public void ReSave()
+ {
+ if (Shared.Common.Config.Instance.Home.IsShowTemplate == true)
+ {
+ //灞曠ず妯℃澘鏃�,涓嶅厑璁镐繚瀛樻枃浠�(闃叉灞炴�т笂鎶ョ敤鐨�)
+ return;
+ }
+ Global.WriteFileByBytesByHomeId(FilePath, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)));
+ }
+ #endregion
+
+ #region 璋冭瘯鎵撳嵃
+
+ /// <summary>
+ /// 璋冭瘯鏃舵墦寮�鎵撳嵃淇℃伅锛宼rue:鎵撳嵃锛宖alse:涓嶆墦鍗�
+ /// </summary>
+ /// <param name="msg">Message.</param>
+ /// <param name="flage">If set to <c>true</c> flage.</param>
+ public static void DebugPrintLog(string msg, bool flage = true)
+ {
+#if DEBUG
+ if (flage == true)
+ {
+ //if (msg.Contains("DeviceStatusReport") == false)
+ {
+ System.Console.WriteLine(msg + " " + System.DateTime.Now.ToLongTimeString() + " " + System.DateTime.Now.Millisecond);
+ }
+ }
+#endif
+ }
+
+ #endregion
}
}
--
Gitblit v1.8.0