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/UserCenter/CommonBase/Logic/HdlDevicePanelLogic.cs | 858 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 752 insertions(+), 106 deletions(-)
diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDevicePanelLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDevicePanelLogic.cs
index ef8c355..468e4bc 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDevicePanelLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDevicePanelLogic.cs
@@ -3,6 +3,7 @@
using System.Text;
using ZigBee.Device;
using System.Threading.Tasks;
+using Newtonsoft.Json.Linq;
namespace Shared.Phone.UserCenter
{
@@ -59,10 +60,10 @@
/// </summary>
/// <param name="panel">鎸夐敭闈㈡澘鐨勬煇涓�涓洖璺�</param>
/// <returns></returns>
- public async Task<Panel.KeyColorData> GetPanelEpointColorInfo(Panel panel)
+ public Panel.KeyColorData GetPanelEpointColorInfo(CommonDevice panel)
{
Panel.KeyNum keyNum = (Panel.KeyNum)panel.DeviceEpoint;
- var result = await panel.GetPanelColorInfoAsync(keyNum);
+ var result = this.GetPanelColorInfoAsync(panel, keyNum);
//鍏遍�氶敊璇娴�
string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
if (error != null)
@@ -82,18 +83,85 @@
}
/// <summary>
+ /// 鑾峰彇闈㈡澘棰滆壊鐨勪俊鎭�(鍑洪敊浼氳繑鍥瀗ull)
+ /// </summary>
+ /// <param name="panel">鎸夐敭闈㈡澘鐨勬煇涓�涓洖璺�</param>
+ /// <returns></returns>
+ public Panel.KeyColorData GetPanelColorInfo(CommonDevice panel)
+ {
+ panel.DeviceEpoint = 1;
+ Panel.KeyNum keyNum = (Panel.KeyNum)panel.DeviceEpoint;
+ var result = this.GetPanelColorInfoAsync(panel, keyNum);
+ //鍏遍�氶敊璇娴�
+ string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
+ if (error != null)
+ {
+ this.ShowErrorMsg(error);
+ return null;
+ }
+
+ if (result == null || result.keyColorData == null)
+ {
+ //鑾峰彇鎸夐敭闈㈡澘棰滆壊璋冭妭淇℃伅澶辫触
+ string msg = Language.StringByID(R.MyInternationalizationString.uGetPanelColorRegulationInfoFail);
+ this.ShowErrorMsg(msg);
+ return null;
+ }
+ return result.keyColorData;
+ }
+
+ ///<summary >
+ ///鑾峰彇鎸夐敭鎸囩ず鐏紑鍏抽鑹�.
+ /// </summary>
+ public Panel.KeyColorDataResponseAllData GetPanelColorInfoAsync(CommonDevice device, Panel.KeyNum keyNum)
+ {
+ //濡傛灉褰撳墠鏄櫄鎷熶綇瀹�
+ if (Common.Config.Instance.Home.IsVirtually == true)
+ {
+ //杩欓噷鐗规畩,杩欓噷鏄寜鍥炶矾鍒嗙殑
+ return TemplateData.TemplateDeviceDataLogic.Current.GetPanelColorInfo(device.DeviceAddr, device.DeviceEpoint, keyNum);
+ }
+ //鍙戦�佹暟鎹� keyNum杞负16杩涘埗 鑼冨洿锛�01~10
+ var passData = "0504040101" + Convert.ToString((int)keyNum, 16).ToUpper().PadLeft(2, '0');
+ var jObject = new JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
+ var dataObject = new JObject { { "PassData", passData } };
+ jObject.Add("Data", dataObject);
+
+ var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway2(device, jObject.ToString(), "0405", 24, 9);
+ if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
+ {
+ return null;
+ }
+ string data = result.ReceiptData;
+
+ var tempR = new Panel.KeyColorData();
+ tempR.OpenColorR = data[12].ToString() + data[13].ToString();
+ tempR.OpenColorG = data[14].ToString() + data[15].ToString();
+ tempR.OpenColorB = data[16].ToString() + data[17].ToString();
+ tempR.CloseColorR = data[18].ToString() + data[19].ToString();
+ tempR.CloseColorG = data[20].ToString() + data[21].ToString();
+ tempR.CloseColorB = data[22].ToString() + data[23].ToString();
+
+ var key = data[10].ToString() + data[11].ToString();
+ int keyEnum1 = Convert.ToInt32(key, 16);
+ tempR.keyNum = (Panel.KeyNum)keyEnum1;
+
+ return new Panel.KeyColorDataResponseAllData { keyColorData = tempR };
+ }
+
+ /// <summary>
/// 璁剧疆鎸夐敭闈㈡澘鎸囧畾绔偣鐨勩�愭寚绀虹伅寮�鍏抽鑹层�戠殑淇℃伅
/// </summary>
/// <param name="panel">鎸夐敭闈㈡澘鐨勬煇涓�涓洖璺�</param>
/// <param name="colorData">寮�鍜屽叧鐨勯鑹查兘闇�瑕佷竴璧疯缃�</param>
/// <returns></returns>
- public async Task<bool> SetPanelEpointColorInfo(Panel panel, Panel.KeyColorData colorData)
+ public bool SetPanelEpointColorInfo(CommonDevice panel, Panel.KeyColorData colorData)
{
var keyNum = new Panel.KeyNumStatus();
Type type = keyNum.GetType();
type.InvokeMember("Key" + panel.DeviceEpoint, System.Reflection.BindingFlags.SetField, null, keyNum, new object[] { true });
- var result = await panel.SetPanelColorInfoAsync(colorData, keyNum);
+ var result = this.SetPanelColorInfoAsync(panel, colorData, keyNum);
if (result == null || result.responseData == null)
{
//璁剧疆鎸夐敭闈㈡澘鎸囩ず鐏鑹插け璐�
@@ -108,73 +176,269 @@
this.ShowErrorMsg(msg);
return false;
}
- //澶囦唤璁惧
- await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(panel, GatewayBackupEnum.A骞叉帴鐐归鑹茶皟鑺�, colorData);
return true;
+ }
+
+ /// <summary>
+ /// 璁剧疆闈㈡澘棰滆壊
+ /// </summary>
+ /// <param name="panel">鎸夐敭闈㈡澘鐨�</param>
+ /// <param name="colorData">鍙缃紑鐨勯鑹�</param>
+ /// <returns></returns>
+ public bool SetPanelColorInfo(CommonDevice panel, Panel.KeyColorData colorData)
+ {
+ var keyNum = new Panel.KeyNumStatus();
+ //榛樿绗竴涓敤闈㈡澘绗竴涓寜閿鑹蹭綔涓烘暣涓潰鏉跨殑棰滆壊
+ keyNum.Key1 = true;
+ var result = this.SetPanelColorInfoAsync(panel, colorData, keyNum);
+ if (result == null || result.responseData == null)
+ {
+ //璁剧疆鎸夐敭闈㈡澘鎸囩ず鐏鑹插け璐�
+ string msg = Language.StringByID(R.MyInternationalizationString.uSetPanelPilolightSettionFail);
+ this.ShowErrorMsg(msg);
+ return false;
+ }
+ if (result.responseData.status != 0)
+ {
+ //璁剧疆鎸夐敭闈㈡澘鎸囩ず鐏鑹插け璐�
+ string msg = Language.StringByID(R.MyInternationalizationString.uSetPanelPilolightSettionFail);
+ this.ShowErrorMsg(msg);
+ return false;
+ }
+ return true;
+ }
+
+ ///<summary >
+ ///閰嶇疆鎸夐敭鎸囩ず鐏鑹�
+ /// </summary>
+ public CommonDevice.ResponseAllData SetPanelColorInfoAsync(CommonDevice device, Panel.KeyColorData keyColorData, Panel.KeyNumStatus keyNumStatus)
+ {
+ //濡傛灉褰撳墠鏄櫄鎷熶綇瀹�
+ if (Common.Config.Instance.Home.IsVirtually == true)
+ {
+ //杩欎釜涔熸槸鐗规畩,鎸夊洖璺潵鍒�
+ return TemplateData.TemplateDeviceDataLogic.Current.SetPanelColorInfo(device.DeviceAddr, device.DeviceEpoint, keyColorData, keyNumStatus, null);
+ }
+ //鑾峰彇閰嶇疆鎸夐敭鎸囩ず鐏鑹茬殑鍛戒护瀛楃
+ var sendData = this.GetPanelColorCommandText(device.DeviceAddr, keyColorData, keyNumStatus);
+ var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway2(device, sendData, "0002", 16, 9);
+ if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
+ {
+ return null;
+ }
+ var data = result.ReceiptData;
+ var tempD = new CommonDevice.ResponseData();
+ tempD.command = data[12].ToString() + data[13].ToString() + data[10].ToString() + data[11].ToString();
+ tempD.status = Convert.ToInt32(data[14].ToString() + data[15].ToString(), 16);
+
+ //娣诲姞缂撳瓨
+ TemplateData.TemplateDeviceDataLogic.Current.SetPanelColorInfo(device.DeviceAddr, device.DeviceEpoint, keyColorData, keyNumStatus, result.JsonData[0]);
+
+ return new CommonDevice.ResponseAllData { responseData = tempD };
+ }
+
+ /// <summary>
+ /// 鑾峰彇閰嶇疆鎸夐敭鎸囩ず鐏鑹茬殑鍛戒护瀛楃
+ /// </summary>
+ /// <param name="DeviceAddr"></param>
+ /// <param name="keyColorData"></param>
+ /// <param name="keyNumStatus"></param>
+ /// <returns></returns>
+ public string GetPanelColorCommandText(string DeviceAddr, Panel.KeyColorData keyColorData, Panel.KeyNumStatus keyNumStatus)
+ {
+ var passData = this.GetPanelColorPassData(keyColorData, keyNumStatus);
+ var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
+ var data = new JObject { { "PassData", passData } };
+ jObject.Add("Data", data);
+
+ return jObject.ToString();
+ }
+
+ /// <summary>
+ /// 閰嶇疆鎸夐敭鎸囩ず鐏鑹叉暟鎹�
+ /// <para>鍙戦厤缃寜閿寚绀虹伅棰滆壊鍛戒护鏃讹紝姝ゆ椂涓哄彂閫佸埌缃戝叧鐨勯�忎紶鏁版嵁</para>
+ /// </summary>
+ /// <returns>The passthorugh data.</returns>
+ /// <param name="keyColorData">Key color data.</param>
+ /// <param name="keyNum">Key number.</param>
+ private string GetPanelColorPassData(Panel.KeyColorData keyColorData, Panel.KeyNumStatus keyNumStatus)
+ {
+ string data = "";
+ string dataLength = "0c";
+ string dataComand1 = "01";
+ string dataComand2 = "04";
+ string dataSerialNum = "01";
+ string addDataLength = "08";
+ int attributeData = 0;
+
+ try
+ {
+ for (int i = 1; i <= 16; i++)
+ {
+ Type type = keyNumStatus.GetType();
+ var obj = type.InvokeMember("Key" + i, System.Reflection.BindingFlags.GetField, null, keyNumStatus, null);
+ int value0 = 0;
+ if (Convert.ToBoolean(obj) == true)
+ {
+ value0 = 1;
+ }
+ int v = (int)Math.Pow(2, i - 1);
+ attributeData += value0 * v;
+ }
+
+ string td = attributeData.ToString("X4");
+ char[] td1 = td.ToCharArray();
+ string tempAttributeData = string.Concat(td1[2].ToString(), td1[3].ToString(), td1[0].ToString(), td1[1].ToString());
+ string temp = "";
+ var tempColor1 = keyColorData.OpenColorR.ToString();
+ var sbString1 = new System.Text.StringBuilder();
+ switch (tempColor1.Length)
+ {
+ case 1:
+ temp = "0" + tempColor1;
+ break;
+ case 2:
+ temp = tempColor1;
+ break;
+ }
+ sbString1.Append(temp.ToUpper());
+
+ var tempColor2 = keyColorData.OpenColorG.ToString();
+ var sbString2 = new System.Text.StringBuilder();
+ switch (tempColor2.Length)
+ {
+ case 1:
+ temp = "0" + tempColor2;
+ break;
+ case 2:
+ temp = tempColor2;
+ break;
+ }
+ sbString2.Append(temp.ToUpper());
+
+ var tempColor3 = keyColorData.OpenColorB.ToString();
+ var sbString3 = new System.Text.StringBuilder();
+ switch (tempColor3.Length)
+ {
+ case 1:
+ temp = "0" + tempColor3;
+ break;
+ case 2:
+ temp = tempColor3;
+ break;
+ }
+ sbString3.Append(temp.ToUpper());
+
+ var tempColor4 = keyColorData.CloseColorR.ToString();
+ var sbString4 = new System.Text.StringBuilder();
+ switch (tempColor3.Length)
+ {
+ case 1:
+ temp = "0" + tempColor4;
+ break;
+ case 2:
+ temp = tempColor4;
+ break;
+ }
+ sbString4.Append(temp.ToUpper());
+
+ var tempColor5 = keyColorData.CloseColorG.ToString();
+ var sbString5 = new System.Text.StringBuilder();
+ switch (tempColor5.Length)
+ {
+ case 1:
+ temp = "0" + tempColor5;
+ break;
+ case 2:
+ temp = tempColor5;
+ break;
+ }
+ sbString5.Append(temp.ToUpper());
+
+ var tempColor6 = keyColorData.CloseColorB.ToString();
+ var sbString6 = new System.Text.StringBuilder();
+ switch (tempColor6.Length)
+ {
+ case 1:
+ temp = "0" + tempColor6;
+ break;
+ case 2:
+ temp = tempColor6;
+ break;
+ }
+ sbString6.Append(temp.ToUpper());
+
+ if (keyColorData != null)
+ {
+ data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
+ tempAttributeData + sbString1 + sbString2 + sbString3 +
+ sbString4 + sbString5 + sbString6;
+ }
+ }
+ catch { };
+
+ return data;
}
#endregion
#region 鈻� 浜害璋冭妭___________________________
- /// <summary>
- /// 鑾峰彇璁惧浜害閰嶇疆锛坲i鍙寒搴﹁皟鑺�,浣跨敤杩斿洖鍊肩殑panelDirectionsLevel锛�
+
+ ///<summary >
+ ///鑾峰彇璁惧浜害閰嶇疆锛坲i鍙寒搴﹁皟鑺�,浣跨敤杩斿洖鍊肩殑panelDirectionsLevel锛�
/// </summary>
- /// <param name="device">璁惧瀵硅薄</param>
- /// <returns></returns>
- public async Task<Panel.PanelSwitchLevelInfo> GetDeviceLightSettion(CommonDevice device)
+ public Panel.PanelSwitchLevelInfo GetDeviceLightSettion(CommonDevice device)
{
- //鍊熺敤瀹冪殑鍑芥暟
- var panel = new Panel();
- panel.DeviceAddr = device.DeviceAddr;
- panel.DeviceEpoint = device.DeviceEpoint;
- panel.CurrentGateWayId = device.CurrentGateWayId;
-
- var result = await panel.GetPanelSwitchLevelAsync();
- panel = null;
- //鍏遍�氶敊璇娴�
- string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
- if (error != null)
+ //濡傛灉褰撳墠鏄櫄鎷熶綇瀹�
+ if (Common.Config.Instance.Home.IsVirtually == true)
{
- this.ShowErrorMsg(error);
- return null;
+ return TemplateData.TemplateDeviceDataLogic.Current.GetDeviceLightSettion(device.DeviceAddr, 200);
}
+ //鑾峰彇鍙戦�佺殑鍛戒护瀛楃
+ var passData = "050604010101";
+ var jObject = new Newtonsoft.Json.Linq.JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
+ var data = new Newtonsoft.Json.Linq.JObject { { "PassData", passData } };
+ jObject.Add("Data", data);
+ var sendData = jObject.ToString();
- if (result == null || string.IsNullOrEmpty(result.errorMessageBase) == false)
+ var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway2(device, sendData, "0407", 14, 9);
+ if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
{
//鑾峰彇鎸夐敭闈㈡澘浜害璋冭妭淇℃伅澶辫触
string msg = Language.StringByID(R.MyInternationalizationString.uGetPanelLightRegulationInfoFail);
this.ShowErrorMsg(msg);
return null;
}
- return result;
+ var receiptData = result.ReceiptData;
+ var level1 = Convert.ToInt32(receiptData[10].ToString() + receiptData[11].ToString(), 16);
+ var level2 = Convert.ToInt32(receiptData[12].ToString() + receiptData[13].ToString(), 16);
+
+ return new Panel.PanelSwitchLevelInfo { panelDirectionsLevel = level1, panelBacklightLevel = level2 };
}
/// <summary>
/// 璁剧疆璁惧浜害锛坲i鍙寒搴﹁皟鑺傦級
/// </summary>
/// <param name="panel">璁惧瀵硅薄</param>
- /// <param name="directionsLevel">鎸囩ず鐏寒搴� 0-100(鐜伴樁娈典笉鐢ㄨ繖涓�)</param>
- /// <param name="backlightLevel">鑳屽厜鐏寒搴� 0-100(ui鍙寒搴﹁皟鑺�)</param>
+ /// <param name="directionsLevel">0-100(杩欎釜鏄偣鍑诲悗鐨勫��)</param>
+ /// <param name="backlightLevel">0-100(杩欎釜鏄偣鍑诲墠鐨勫��)</param>
/// <returns></returns>
- public async Task<bool> SetDeviceLightSettion(CommonDevice device, int directionsLevel, int backlightLevel)
+ public bool SetDeviceLightSettion(CommonDevice device, int directionsLevel, int backlightLevel)
{
- //鍊熺敤瀹冪殑鍑芥暟
- var panel = new Panel();
- panel.DeviceAddr = device.DeviceAddr;
- panel.DeviceEpoint = device.DeviceEpoint;
- panel.CurrentGateWayId = device.CurrentGateWayId;
-
- var result = await panel.SetKeyLevelAsync(directionsLevel, backlightLevel);
- panel = null;
- //鍏遍�氶敊璇娴�
- string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
- if (error != null)
+ //濡傛灉褰撳墠鏄櫄鎷熶綇瀹�
+ if (Common.Config.Instance.Home.IsVirtually == true)
{
- this.ShowTipMsg(error);
+ return TemplateData.TemplateDeviceDataLogic.Current.SetDeviceLightSettion(device.DeviceAddr, 200, directionsLevel, backlightLevel, null);
+ }
+ //鑾峰彇淇敼闈㈡澘鐨勪寒搴﹁皟鑺傜殑鍛戒护瀛楃
+ var sendData = this.GetPanelLevelCommadText(device.DeviceAddr, directionsLevel, backlightLevel);
+ var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway2(device, sendData, "0002", 16, 9);
+ if (result.ErrorMsg != null)
+ {
+ this.ShowTipMsg(result.ErrorMsg);
return false;
}
-
- if (result == null || result.responseData == null)
+ if (result.ErrorMsgDiv == 0)
{
//璁剧疆浜害璋冭妭澶辫触
string msg = Language.StringByID(R.MyInternationalizationString.uSetLightRegulationFail);
@@ -185,33 +449,97 @@
return false;
}
- if (result.responseData.status != 0)
+ //杩欓噷杩樻湁涓�涓� 0402
+ //tempD.command = data[12].ToString() + data[13].ToString() + data[10].ToString() + data[11].ToString();
+
+ var status = Convert.ToInt32(result.ReceiptData[14].ToString() + result.ReceiptData[15].ToString(), 16);
+ if (status != 0)
{
//璁剧疆浜害璋冭妭澶辫触
string msg = Language.StringByID(R.MyInternationalizationString.uSetLightRegulationFail);
this.ShowTipMsg(msg);
return false;
}
- //澶囦唤璁惧
- var backData = new Newtonsoft.Json.Linq.JObject
- {
- { "directionsLevel",directionsLevel },
- { "backlightLevel", backlightLevel }
- };
- //澶囦唤璁惧
- await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(device, GatewayBackupEnum.A骞叉帴鐐逛寒搴﹁皟鑺�, backData);
+
+ //淇敼缂撳瓨
+ TemplateData.TemplateDeviceDataLogic.Current.SetDeviceLightSettion(device.DeviceAddr, 200, directionsLevel, backlightLevel, result.JsonData[0]);
+
return true;
}
+ /// <summary>
+ /// 鑾峰彇淇敼闈㈡澘鐨勪寒搴﹁皟鑺傜殑鍛戒护瀛楃
+ /// </summary>
+ /// <param name="DeviceAddr"></param>
+ /// <param name="directionsLevel">0-100(杩欎釜鏄偣鍑诲悗鐨勫��)</param>
+ /// <param name="backlightLevel">0-100(杩欎釜鏄偣鍑诲墠鐨勫��)</param>
+ /// <returns></returns>
+ public string GetPanelLevelCommadText(string DeviceAddr, int directionsLevel, int backlightLevel)
+ {
+ var passData = this.GetSetPanelLevelPassData(directionsLevel, backlightLevel);
+ var jObject = new Newtonsoft.Json.Linq.JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
+ var data = new Newtonsoft.Json.Linq.JObject { { "PassData", passData } };
+ jObject.Add("Data", data);
+
+ return jObject.ToString();
+ }
+
+ /// <summary>
+ /// 鑾峰彇閰嶇疆鎸夐敭鎸囩ず鐏潰鏉夸寒搴︾殑鍛戒护瀛楃
+ /// </summary>
+ private string GetSetPanelLevelPassData(int level1, int level2)
+ {
+ string data = "";
+ string dataLength = "06";
+ string dataComand1 = "02";
+ string dataComand2 = "04";
+ string dataSerialNum = "01";
+ string addDataLength = "02";
+ string l1 = "";
+ string l2 = "";
+ try
+ {
+ var sbString1 = new System.Text.StringBuilder();
+ var sbString2 = new System.Text.StringBuilder();
+ string temp1 = Convert.ToString(level1, 16);
+ string temp2 = Convert.ToString(level2, 16);
+
+ switch (temp1.Length)
+ {
+ case 1:
+ l1 = "0" + temp1;
+ break;
+ case 2:
+ l1 = temp1;
+ break;
+ }
+ switch (temp2.Length)
+ {
+ case 1:
+ l2 = "0" + temp2;
+ break;
+ case 2:
+ l2 = temp2;
+ break;
+ }
+ sbString1.Append(l1.ToString().ToUpper());
+ sbString2.Append(l2.ToString().ToUpper());
+ data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
+ sbString1 + sbString2;
+ }
+ catch { };
+
+ return data;
+ }
#endregion
- #region 鈻� 鑺傝兘妯″紡___________________________
+ #region 鈻� 鎺ヨ繎鎰熷簲___________________________
/// <summary>
- /// 鑾峰彇璁惧鑺傝兘妯″紡鐨勯厤缃姸鎬�(ui鍙妭鑳芥ā寮�)
+ /// 鑾峰彇鎺ヨ繎鎰熷簲閰嶇疆锛坲i鍙帴杩戞劅搴�,浣跨敤杩斿洖鍊肩殑panelProximitySensorInfo锛�
/// </summary>
/// <param name="device">璁惧瀵硅薄</param>
/// <returns></returns>
- public async Task<Panel.PanelSaveEnergyModeInfo> GetDeviceEnergyConservationMode(CommonDevice device)
+ public async Task<Panel.PanelProximitySensorInfo> GetDeviceProximitySensorsSettion(CommonDevice device)
{
//鍊熺敤瀹冪殑鍑芥暟
var panel = new Panel();
@@ -219,9 +547,8 @@
panel.DeviceEpoint = device.DeviceEpoint;
panel.CurrentGateWayId = device.CurrentGateWayId;
- var result = await panel.GetPanelSaveEnergyModeAsync();
+ var result = await panel.GetProximitySensorAsync();
panel = null;
-
//鍏遍�氶敊璇娴�
string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
if (error != null)
@@ -229,8 +556,124 @@
this.ShowErrorMsg(error);
return null;
}
+ if (result == null || result.panelProximitySensorInfo == null || string.IsNullOrEmpty(result.errorMessageBase) == false)
+ {
+ //鑾峰彇鎺ヨ繎鎰熷簲淇℃伅澶辫触
+ string msg = Language.StringByID(R.MyInternationalizationString.GetPanelProximityFail);
+ this.ShowErrorMsg(msg);
+ return null;
+ }
+ return result.panelProximitySensorInfo;
+ }
- if (result == null || result.panelSaveEnergyModeInfo == null)
+
+ /// <summary>
+ /// 閰嶇疆鎺ヨ繎浼犳劅
+ /// </summary>
+ /// <param name="device">璁惧瀵硅薄</param>
+ /// <para>sensorEnable:浼犳劅鍣ㄤ娇鑳�</para>
+ /// <returns></returns>
+ public async Task<bool> SetProximitySensorStatus(CommonDevice device, bool sensorEnable)
+ {
+ //鍊熺敤瀹冪殑鍑芥暟
+ var panel = new Panel();
+ panel.DeviceAddr = device.DeviceAddr;
+ panel.DeviceEpoint = device.DeviceEpoint;
+ panel.CurrentGateWayId = device.CurrentGateWayId;
+
+ var result = await panel.SetProximitySensor(sensorEnable);
+ panel = null;
+
+ //鍏遍�氶敊璇娴�
+ string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
+ if (error != null)
+ {
+ this.ShowErrorMsg(error);
+ return false;
+ }
+
+ if (result == null || result.responseData == null)
+ {
+ //鎺ヨ繎浼犳劅閰嶇疆澶辫触
+ string msg = Language.StringByID(R.MyInternationalizationString.SetPannelProximityFail);
+ //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
+ msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
+
+ this.ShowTipMsg(msg);
+ return false;
+ }
+ return true;
+ }
+ #endregion
+
+ #region 鈻� 鏍℃娓╁害___________________________
+ /// <summary>
+ /// 鏍℃娓╁害
+ /// </summary>
+ /// <param name="device">璁惧瀵硅薄</param>
+ /// <param name="correctValue">鏍℃娓╁害鍊�</param>
+ /// <param name="direction">琛ュ伩鏂瑰悜0涓嶈ˉ鍋� 1锛氭鍚戯紱2锛氬弽鍚�</param>
+ /// <param name="type">0 娓╁害 锛�1 婀垮害</param>
+ /// <returns></returns>
+ public async Task<bool> CorrectTemperature(CommonDevice device, double correctValue, int direction = 0, int type = 0)
+ {
+ //鍊熺敤瀹冪殑鍑絫
+ var panel = new Panel();
+ panel.DeviceAddr = device.DeviceAddr;
+ panel.DeviceEpoint = 200;
+ panel.CurrentGateWayId = device.CurrentGateWayId;
+
+ var result = await panel.CorrectTemperature(correctValue, direction, type);
+ panel = null;
+
+ //鍏遍�氶敊璇娴�
+ string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
+ if (error != null)
+ {
+ this.ShowErrorMsg(error);
+ return false;
+ }
+
+ if (result == null || result.responseData == null)
+ {
+ //鐭娓╁害澶辫触
+ string msg = Language.StringByID(R.MyInternationalizationString.DataCorrectionFailed);
+ //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg
+ msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
+
+ this.ShowTipMsg(msg);
+ return false;
+ }
+ return true;
+ }
+ #endregion
+
+ #region 鈻� 鑺傝兘妯″紡___________________________
+ /// <summary>
+ /// 鑾峰彇璁惧鑺傝兘妯″紡鐨勯厤缃姸鎬�(ui鍙妭鑳芥ā寮�)
+ /// </summary>
+ /// <param name="device">璁惧瀵硅薄</param>
+ /// <returns></returns>
+ public Panel.PanelSaveEnergyModeInfo GetDeviceEnergyConservationMode(CommonDevice device)
+ {
+ //濡傛灉褰撳墠浣忓畢鏄櫄鎷熶綇瀹�
+ if (Common.Config.Instance.Home.IsVirtually == true)
+ {
+ return TemplateData.TemplateDeviceDataLogic.Current.GetDeviceEnergyConservationMode(device.DeviceAddr, 200);
+ }
+ //鍙戦�佸懡浠�
+ string passData = "050804010101";
+ var jObject = new JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
+ var data = new JObject { { "PassData", passData } };
+ jObject.Add("Data", data);
+ //16:鏃х増鏈� 18:鏂扮増鏈�
+ var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway2(device, jObject.ToString(), "0409", 16, 9, new List<int> { 18 });
+ if (result.ErrorMsg != null)
+ {
+ this.ShowTipMsg(result.ErrorMsg);
+ return null;
+ }
+ if (result.ErrorMsgDiv == 0)
{
//鑾峰彇鎸夐敭闈㈡澘鑺傝兘妯″紡淇℃伅澶辫触
string msg = Language.StringByID(R.MyInternationalizationString.uGetPanelEnergyConservationInfoFail);
@@ -240,7 +683,33 @@
this.ShowErrorMsg(msg);
return null;
}
- return result.panelSaveEnergyModeInfo;
+
+ var energyInfo = new Panel.PanelSaveEnergyModeInfo();
+
+ if (result.ReceiptData[10].ToString() + result.ReceiptData[11].ToString() == "01")
+ {
+ energyInfo.enable = true;
+ }
+ else
+ {
+ energyInfo.enable = false;
+ }
+
+ //鏂扮増鏈�:07 0904 11 04 01 3C00 32
+ if (result.ReceiptData.Length == 18)
+ {
+ energyInfo.time = Convert.ToInt32(result.ReceiptData[14].ToString() + result.ReceiptData[15].ToString() +
+ result.ReceiptData[12].ToString() + result.ReceiptData[13].ToString(), 16);
+
+ energyInfo.level = Convert.ToInt32(result.ReceiptData[16].ToString() + result.ReceiptData[17].ToString(), 16);
+ }
+ //鏃х増鏈�:07 0904 11 03 01 3C 32
+ else
+ {
+ energyInfo.time = Convert.ToInt32(result.ReceiptData[12].ToString() + result.ReceiptData[13].ToString(), 16);
+ energyInfo.level = Convert.ToInt32(result.ReceiptData[14].ToString() + result.ReceiptData[15].ToString(), 16);
+ }
+ return energyInfo;
}
/// <summary>
@@ -251,25 +720,22 @@
/// <param name="modeTime">鏃犳搷浣滆繘鍏ヨ妭鑳芥ā寮忔椂闂� 0-255</param>
/// <param name="level">鑺傝兘妯″紡浜害:0-100</param>
/// <returns></returns>
- public async Task<bool> SetDeviceEnergyConservationMode(CommonDevice device, bool modeEnable, int modeTime, int level)
+ public bool SetDeviceEnergyConservationMode(CommonDevice device, bool modeEnable, int modeTime, int level)
{
- //鍊熺敤瀹冪殑鍑芥暟
- var panel = new Panel();
- panel.DeviceAddr = device.DeviceAddr;
- panel.DeviceEpoint = device.DeviceEpoint;
- panel.CurrentGateWayId = device.CurrentGateWayId;
-
- var result = await panel.SetKeyModeAsync(modeEnable, modeTime, level);
- panel = null;
- //鍏遍�氶敊璇娴�
- string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
- if (error != null)
+ //濡傛灉褰撳墠鏄櫄鎷熶綇瀹�
+ if (Common.Config.Instance.Home.IsVirtually == true)
{
- this.ShowErrorMsg(error);
+ return TemplateData.TemplateDeviceDataLogic.Current.SetDeviceEnergyConservationMode(device.DeviceAddr, 200, modeEnable, modeTime, level, null);
+ }
+ //鑾峰彇璁剧疆璁惧鐨勮妭鑳芥ā寮忕殑鍛戒护瀛楃
+ var sendData = this.GetDeviceEnergyConservationModeCommandText(device.DeviceAddr, modeEnable, modeTime, level);
+ var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway2(device, sendData, "0002", 16, 9);
+ if (result.ErrorMsg != null)
+ {
+ this.ShowTipMsg(result.ErrorMsg);
return false;
}
-
- if (result == null || result.responseData == null)
+ if (result.ErrorMsgDiv == 0)
{
//鑺傝兘妯″紡閰嶇疆澶辫触
string msg = Language.StringByID(R.MyInternationalizationString.uSetEnergyConservationFail);
@@ -279,25 +745,109 @@
this.ShowTipMsg(msg);
return false;
}
-
- if (result.responseData.status != 0)
+ var status = Convert.ToInt32(result.ReceiptData[14].ToString() + result.ReceiptData[15].ToString(), 16);
+ if (status != 0)
{
//鑺傝兘妯″紡閰嶇疆澶辫触
string msg = Language.StringByID(R.MyInternationalizationString.uSetEnergyConservationFail);
this.ShowTipMsg(msg);
return false;
}
- //澶囦唤璁惧
- var backData = new Newtonsoft.Json.Linq.JObject
- {
- { "modeEnable",modeEnable },
- { "modeTime", modeTime },
- { "level", level }
- };
- //澶囦唤璁惧
- await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(device, GatewayBackupEnum.A骞叉帴鐐硅妭鑳芥ā寮�, backData);
+
+ //淇敼缂撳瓨
+ TemplateData.TemplateDeviceDataLogic.Current.SetDeviceEnergyConservationMode(device.DeviceAddr, 200, modeEnable, modeTime, level, result.JsonData[0]);
+
return true;
}
+
+ /// <summary>
+ /// 鑾峰彇璁剧疆璁惧鐨勮妭鑳芥ā寮忕殑鍛戒护瀛楃
+ /// </summary>
+ /// <param name="DeviceAddr"></param>
+ /// <param name="modeEnable"></param>
+ /// <param name="modeTime"></param>
+ /// <param name="level"></param>
+ /// <returns></returns>
+ public string GetDeviceEnergyConservationModeCommandText(string DeviceAddr, bool modeEnable, int modeTime, int level)
+ {
+ var passData = this.GetPanelModeModePassData(modeEnable, modeTime, level);
+ var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
+ var data = new JObject { { "PassData", passData } };
+ jObject.Add("Data", data);
+
+ return jObject.ToString();
+ }
+
+ /// <summary>
+ /// 鑾峰彇璁剧疆璁惧鐨勮妭鑳芥ā寮忕殑鍛戒护瀛楃
+ /// </summary>
+ private string GetPanelModeModePassData(bool modeEnable, int modeTime, int modelevel)
+ {
+ string data = "";
+ string dataLength = "08";
+ string dataComand1 = "03";
+ string dataComand2 = "04";
+ string dataSerialNum = "01";
+ string addDataLength = "04";
+ string mode = "";
+ string time = "";
+ string level = "";
+ try
+ {
+ if (modeEnable)
+ {
+ mode = "01";
+ }
+ else
+ {
+ mode = "00";
+ }
+
+ if (modeTime == -1)
+ {
+ //褰撹妭鑳芥ā寮忔病鏈夌粰鏃堕棿锛岄粯璁ょ粰60绉�
+ modeTime = 60;
+ }
+
+ var tempBytes = new byte[2];
+ for (int i = 0; i < 2; i++)
+ {
+ tempBytes[i] = (byte)(modeTime >> (i * 8) & 0xff);
+ }
+ var time1 = Convert.ToString(tempBytes[0], 16);
+ var time2 = Convert.ToString(tempBytes[1], 16);
+ if (time1.Length == 1)
+ {
+ time1 = "0" + time1;
+ }
+ if (time2.Length == 1)
+ {
+ time2 = "0" + time2;
+ }
+
+ time = (time1 + time2).ToUpper();
+
+ var sbString2 = new System.Text.StringBuilder();
+ string temp2 = Convert.ToString(modelevel, 16);
+ switch (temp2.Length)
+ {
+ case 1:
+ level = "0" + temp2;
+ break;
+ case 2:
+ level = temp2;
+ break;
+ }
+
+ sbString2.Append(level.ToUpper());
+ data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
+ mode + time + sbString2;
+ }
+ catch { };
+
+ return data;
+ }
+
#endregion
@@ -308,16 +858,9 @@
/// </summary>
/// <param name="panel">骞叉帴鐐瑰璞�</param>
/// <returns></returns>
- public async Task<List<CommonDevice.AttributeDataObj>> GetDryContactConfigureInfo(CommonDevice device)
+ public List<CommonDevice.AttributeDataObj> GetDryContactConfigureInfo(CommonDevice device)
{
- //鍊熺敤瀹冪殑鍑芥暟
- var panel = new Panel();
- panel.DeviceAddr = device.DeviceAddr;
- panel.DeviceEpoint = device.DeviceEpoint;
- panel.CurrentGateWayId = device.CurrentGateWayId;
-
- var result = await panel.ReadPanelConfigureInfoAsync();
- panel = null;
+ var result = HdlDeviceBindLogic.Current.ReadPanelConfigureInfoAsync(device);
//鍏遍�氶敊璇娴�
string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
@@ -479,14 +1022,14 @@
#region 鈻� 淇敼骞叉帴鐐圭鏈夊睘鎬________________
/// <summary>
- /// 淇敼骞叉帴鐐圭鏈夊睘鎬�
+ /// 淇敼骞叉帴鐐圭涓夌骇鍒殑绉佹湁灞炴��
/// </summary>
/// <param name="panel">骞叉帴鐐瑰璞�</param>
/// <param name="i_value">骞叉帴鐐圭殑绗笁绾у埆灞炴�х殑鍊�,鍏蜂綋璇峰弬鐓х涓夌骇鍒睘鎬�</param>
/// <returns></returns>
- public async Task<bool> EditorDryContactFunction(Panel panel, int i_value)
+ public bool EditorDryContactThirdFunction(Panel panel, int i_value)
{
- var result = await panel.ConfigureHdlKeyValueAsync((Panel.KeyMode)i_value);
+ var result = HdlDeviceBindLogic.Current.ConfigureHdlKeyValueAsync(panel, (Panel.KeyMode)i_value);
//鍏遍�氶敊璇娴�
string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
if (error != null)
@@ -536,10 +1079,116 @@
this.ShowErrorMsg(msg);
return false;
}
- //澶囦唤璁惧
- await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(panel, GatewayBackupEnum.A骞叉帴鐐圭鏈夊睘鎬�, i_value);
+ return true;
+ }
+
+ #endregion
+
+ #region 鈻� 绠�绾﹂潰鏉块渿鍔ㄥ姛鑳絖__________________
+
+ /// <summary>
+ /// 鑾峰彇绠�绾﹂潰鏉块渿鍔ㄥ姛鑳界殑淇℃伅(null琛ㄧず鍑洪敊)
+ /// </summary>
+ /// <param name="device">鏌愪竴鍥炶矾</param>
+ /// <returns></returns>
+ public PanelVibrationInfo GetPanelVibrationData(CommonDevice device)
+ {
+ //濡傛灉鏄櫄鎷熶綇瀹�
+ if (Common.Config.Instance.Home.IsVirtually == true)
+ {
+ return TemplateData.TemplateDeviceDataLogic.Current.GetPanelVibrationInfo(device.DeviceAddr, 200);
+ }
+ //鍙戦�佹暟鎹�
+ var jObject = new Newtonsoft.Json.Linq.JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
+ var data = new Newtonsoft.Json.Linq.JObject { { "PassData", "050108110101" } };
+ jObject.Add("Data", data);
+ var sendData = jObject.ToString();
+ var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway2(device, sendData, "0802", 18, 6);
+ if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
+ {
+ //鑾峰彇闇囧姩鍙嶉閰嶇疆淇℃伅澶辫触
+ string errorMsg = Language.StringByID(R.MyInternationalizationString.uGetVibrationFeedbackSettionFail);
+ errorMsg = UserCenterLogic.CombineGatewayTimeOutMsg(errorMsg, null, "鍥炲瓒呮椂", false);
+ this.ShowTipMsg(errorMsg);
+ return null;
+ }
+ var returnData = new PanelVibrationInfo();
+ returnData.A闇囧姩浣胯兘 = result.ReceiptData.Substring(10, 2) == "01" ? true : false;
+ returnData.A闇囧姩寮哄害 = Convert.ToInt32(result.ReceiptData.Substring(12, 2), 16);
+ returnData.A闇囧姩鏃堕棿 = Convert.ToInt32(result.ReceiptData.Substring(14, 4), 16);
+
+ return returnData;
+ }
+
+ /// <summary>
+ /// 璁剧疆绠�绾﹂潰鏉块渿鍔ㄥ姛鑳界殑淇℃伅
+ /// </summary>
+ /// <param name="device">鏌愪竴鍥炶矾</param>
+ /// <param name="datainfo">璁剧疆鐨勪俊鎭�</param>
+ /// <returns></returns>
+ public bool SetPanelVibrationData(CommonDevice device, PanelVibrationInfo datainfo)
+ {
+ //濡傛灉鏄櫄鎷熶綇瀹�
+ if (Common.Config.Instance.Home.IsVirtually == true)
+ {
+ return TemplateData.TemplateDeviceDataLogic.Current.SetPanelVibrationInfo(device.DeviceAddr, 200, datainfo, null);
+ }
+ //鑾峰彇缂栬緫闈㈡澘闇囧姩鍔熻兘鐨勫懡浠ゅ瓧绗�
+ var sendData = this.GetPanelVibrationCommandText(device.DeviceAddr, datainfo);
+ var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway2(device, sendData, "0002", 16, 6);
+ if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
+ {
+ //璁剧疆闇囧姩鍙嶉閰嶇疆淇℃伅澶辫触
+ string errorMsg = Language.StringByID(R.MyInternationalizationString.uSetVibrationFeedbackSettionFail);
+ errorMsg = UserCenterLogic.CombineGatewayTimeOutMsg(errorMsg, null, "鍥炲瓒呮椂", false);
+ this.ShowTipMsg(errorMsg);
+ return false;
+ }
+ //娣诲姞缂撳瓨
+ TemplateData.TemplateDeviceDataLogic.Current.SetPanelVibrationInfo(device.DeviceAddr, 200, datainfo, result.JsonData[0]);
return true;
+ }
+
+ /// <summary>
+ /// 鑾峰彇缂栬緫闈㈡澘闇囧姩鍔熻兘鐨勫懡浠ゅ瓧绗�
+ /// </summary>
+ /// <param name="DeviceAddr"></param>
+ /// <param name="datainfo"></param>
+ /// <returns></returns>
+ public string GetPanelVibrationCommandText(string DeviceAddr, PanelVibrationInfo datainfo)
+ {
+ string passData = "0800081104";
+ passData += datainfo.A闇囧姩浣胯兘 ? "01" : "00";
+ passData += Convert.ToString(datainfo.A闇囧姩寮哄害, 16).PadLeft(2, '0');
+ string time = Convert.ToString(datainfo.A闇囧姩鏃堕棿, 16).PadLeft(4, '0');
+ //浣庝綅鍦ㄥ墠锛岄珮浣嶅湪鍚�
+ passData += time.Substring(2, 2);
+ passData += time.Substring(0, 2);
+
+ var jObject = new Newtonsoft.Json.Linq.JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
+ var data = new Newtonsoft.Json.Linq.JObject { { "PassData", passData } };
+ jObject.Add("Data", data);
+ return jObject.ToString();
+ }
+
+ /// <summary>
+ /// 绠�绾﹂潰鏉块渿鍔ㄥ姛鑳戒俊鎭�
+ /// </summary>
+ public class PanelVibrationInfo
+ {
+ /// <summary>
+ /// 闇囧姩浣胯兘
+ /// </summary>
+ public bool A闇囧姩浣胯兘 = false;
+ /// <summary>
+ /// 闇囧姩寮哄害(鍗佽繘鍒�)
+ /// </summary>
+ public int A闇囧姩寮哄害 = 0;
+ /// <summary>
+ /// 闇囧姩鏃堕棿(鍗佽繘鍒�)
+ /// </summary>
+ public int A闇囧姩鏃堕棿 = 0;
}
#endregion
@@ -651,10 +1300,7 @@
/// </summary>
private void SaveDryContactFunctionToLocaltion()
{
- var file = Newtonsoft.Json.JsonConvert.SerializeObject(dicDryContactFunction);
-
- var bytes = System.Text.Encoding.UTF8.GetBytes(file);
- Common.Global.WriteFileByBytesByHomeId(DirNameResourse.DryContactFunctionFile, bytes);
+ HdlFileLogic.Current.SaveFileContent(DirNameResourse.DryContactFunctionFile, dicDryContactFunction);
}
/// <summary>
@@ -662,12 +1308,12 @@
/// </summary>
private void LoadDryContactFunctionFromLocaltion()
{
- if (Common.Global.IsExistsByHomeId(DirNameResourse.DryContactFunctionFile) == false)
+ this.dicDryContactFunction = new Dictionary<string, DryContactFunctionInfo>();
+ byte[] filebyte = HdlFileLogic.Current.ReadFileByteContent(DirNameResourse.DryContactFunctionFile);
+ if (filebyte == null)
{
return;
}
-
- byte[] filebyte = Common.Global.ReadFileByHomeId(DirNameResourse.DryContactFunctionFile);
string strvalue = System.Text.Encoding.UTF8.GetString(filebyte);
this.dicDryContactFunction = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, DryContactFunctionInfo>>(strvalue);
}
--
Gitblit v1.8.0