using System;
|
using System.Collections.Generic;
|
using System.Threading.Tasks;
|
using Newtonsoft.Json.Linq;
|
using Shared.Common;
|
|
namespace ZigBee.Device
|
{
|
[System.Serializable]
|
public class Panel : BindObj
|
{
|
public Panel()
|
{
|
this.Type = DeviceType.OnOffSwitch;
|
}
|
/// <summary>
|
/// 按键模式(私有功能)
|
/// </summary>
|
public int panelMode = 65535;
|
/// <summary>
|
///按键开状态(指示)亮度
|
/// </summary>
|
public int panelDirectionsLevel = -1;
|
|
/// <summary>
|
/// 按键关状态(背光)亮度
|
/// </summary>
|
public int panelBacklightLevel = -1;
|
|
/// <summary>
|
/// 当前选择模式
|
/// </summary>
|
public string currentKeySelectModeText = "";
|
/// <summary>
|
/// 当前选择的楼层ID
|
/// </summary>
|
public string currentSelectFloorId = string.Empty;
|
/// <summary>
|
/// 当前开关模式
|
/// </summary>
|
public string CurrentSwitchMode = "";
|
/// <summary>
|
/// 当前属性模式
|
/// </summary>
|
public int currentClusterID;
|
|
/// <summary>
|
/// 当前调光模式
|
/// </summary>
|
public string CurrentDimmerMode = "";
|
|
/// <summary>
|
/// 当前遮阳模式
|
/// </summary>
|
public string CurrentCurtainMode = "";
|
|
/// <summary>
|
/// 当前房间ID
|
/// </summary>
|
public string RoomId = "";
|
|
/// <summary>
|
/// 当前房间ID
|
/// </summary>
|
public string curSelectSceneID = "";
|
|
/// <summary>
|
/// 本地楼层房间绑定列表
|
/// </summary>
|
public Dictionary<int, FloorRoomBindObj> FloorRoomBindObjList = new Dictionary<int, FloorRoomBindObj> { };
|
/// <summary>
|
/// 绑定的楼层房间信息
|
/// </summary>
|
[System.Serializable]
|
public class FloorRoomBindObj
|
{
|
/// <summary>
|
/// 楼层ID
|
/// </summary>
|
public string floodID;
|
/// <summary>
|
/// 楼层名称
|
/// </summary>
|
public string floodName;
|
/// <summary>
|
/// 房间ID
|
/// </summary>
|
public string roomID;
|
/// <summary>
|
/// 房间名称
|
/// </summary>
|
public string roomName;
|
/// <summary>
|
/// 绑定目标ID
|
/// </summary>
|
public string BindID;
|
/// <summary>
|
/// 绑定目标名称
|
/// </summary>
|
public string BindName;
|
/// <summary>
|
/// 图片路径
|
/// </summary>
|
public string IconPath = "";
|
|
}
|
|
// <summary>
|
/// 按键中被绑定的目标列表
|
/// </summary>
|
public System.Collections.Generic.List<BindListResponseObj> bindList = new System.Collections.Generic.List<BindListResponseObj> { };
|
|
/// <summary>
|
/// 按键支持的私有模式列表
|
/// </summary>
|
public System.Collections.Generic.Dictionary<int, string> priDeviceModeFunList = new System.Collections.Generic.Dictionary<int, string> { };
|
|
/// <summary>
|
/// 私有功能类
|
/// <para>256:Key,按键类类 </para>
|
/// <para>768:PIR,PIR类</para>
|
/// <para>1024:Light,灯类</para>
|
/// </summary>
|
public List<int> privateFuncFirstLevelList = new List<int>();
|
|
/// <summary>
|
/// 第二级信息
|
/// <para>1:特殊功能</para>
|
/// <para>100:Switch,开关(按键类)</para>
|
/// <para>200:Dimmer,调光(按键类)</para>
|
/// <para>300:Curtain,窗帘(按键类)</para>
|
/// <para>0:EnergySavingMode,节能模式(灯类)</para>
|
/// <para>1:SleepMode,睡眠模式(灯类)</para>
|
/// <para>100:WhiteBalance,白平衡(灯类)</para>
|
/// <para>101:RGBColor,RGB指示灯颜色(灯类)</para>
|
/// <para>102:RGBLevel,RGB指示灯亮度(灯类)</para>
|
/// </summary>
|
public List<int> privateFuncSecondLevelList = new List<int>();
|
|
/// <summary>
|
/// 第三级信息
|
/// <para>1:场景触发(特殊功能)</para>
|
/// <para>65535:禁止发送功能(特殊功能)</para>
|
/// <para>100:SwitchOpen,开关开(按键类)</para>
|
/// <para>101:SwitchClose,开关关(按键类)</para>
|
/// <para>102:SwitchChange,开关切换(按键类)</para>
|
/// <para>200:DimmerStepUp,增大调光(按键类)</para>
|
/// <para>201:DimmerStepDown,降低调光(按键类)</para>
|
/// <para>202:DimmerStepChange,调光切换(按键类)</para>
|
/// <para>300:CurtainOpen,窗帘开(按键类)</para>
|
/// <para>301:CurtainClose,窗帘关(按键类)</para>
|
/// <para>302:CurtainStop,窗帘停</para>
|
/// <para>303:CurtainUpStop,窗帘上升停</para>
|
/// <para>304:CurtainDownstop,窗帘下降停</para>
|
/// </summary>
|
public List<int> privateFuncThirdLevelList = new List<int>();
|
#region 获取面板的私有信息.
|
/// <summary>
|
///获取面板的私有信息
|
/// <para>注意params传入参数如下:</para>
|
/// <para>方法1:当int[]传空,返回值是“面板具有的功能大类,即返回“第一级别。1024:灯类,256:按键类,768:PIR类</para>
|
/// <para>方法2:、当int[]值为第一级别PrivateFuncTypeFir中选择一个。</para>
|
/// <para>返回值是“面按键发送功能类”,即返回“第二级别。</para>
|
/// <para>1:特殊功能;100:Switch,开关(按键类);200:Dimmer,调光(按键类);300:Curtain,窗帘(按键类)</para>
|
/// <para>0:EnergySavingMode,节能模式(灯类);1:SleepMode,睡眠模式(灯类);100:WhiteBalance,白平衡(灯类);101:RGBColor,RGB指示灯颜色(灯类);102:RGBLevel,RGB指示灯亮度(灯类)</para>
|
/// <para>方法3:当int[]值为第一级别PrivateFuncTypeFir中选择一个,接着再选第二级别PrivateFunTypeSec中选择一个 </para>
|
/// <para>返回值是“面按键具体功能配置”,即返回“第二级别。</para>
|
/// <para>1:场景触发;65535:禁止发送功能
|
/// <para>100:SwitchOpen,开关开(按键类);101:SwitchClose,开关关(按键类);102:SwitchChange,开关切换(按键类)</para>
|
/// <para>200:DimmerStepUp,增大调光(按键类);201:DimmerStepDown,降低调光(按键类);202:DimmerStepChange,调光切换(按键类)</para>
|
/// <para>300:CurtainOpen,窗帘开(按键类);301:CurtainClose,窗帘关(按键类);302:CurtainStop,窗帘停;303:CurtainUpStop,窗帘上升停;304:CurtainDownstop,窗帘下降停</para>
|
/// </summary>
|
public async System.Threading.Tasks.Task<PanelPrivateFunctionsResponseAllInfo> GetPanelPrivateFunctionsAsync(params int[] args)
|
{
|
PanelPrivateFunctionsResponseAllInfo result = null;
|
if (Gateway == null)
|
{
|
result = new PanelPrivateFunctionsResponseAllInfo { errorMessageBase = "当前没有网关" };
|
return result;
|
}
|
return await System.Threading.Tasks.Task.Run(async () =>
|
{
|
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 = Gateway.getGatewayBaseInfo.gwID };
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
|
|
if (temp == null)
|
{
|
result = new PanelPrivateFunctionsResponseAllInfo { errorMessageBase = "网关错误回复,且数据是空" };
|
}
|
|
else
|
{
|
result = new PanelPrivateFunctionsResponseAllInfo { errorResponData = temp, errorMessageBase = 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());
|
|
if (gatewayTemp.clientDataPassthroughResponseData == null)
|
{
|
result = new PanelPrivateFunctionsResponseAllInfo { errorMessageBase = "网关返回的数据为空" };
|
}
|
else
|
{
|
if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null)
|
{
|
var data = gatewayTemp.clientDataPassthroughResponseData.PassData;
|
|
if (data.Length > 12)
|
{
|
var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
|
if (command == "0004")
|
{
|
var tempD = new PanelPrivateFunctionsResponseInfo();
|
int len = 2 + 2 * Convert.ToInt32(data[0].ToString() + data[1].ToString(), 16);
|
int usefulLength = (len - 12);
|
tempD.funLevel = Convert.ToInt32(data[10].ToString() + data[11].ToString(), 16);
|
int tempCount = 0;
|
var listData = new List<string>();
|
|
switch (tempD.funLevel)
|
{
|
case 1:
|
while (tempCount < usefulLength)
|
{
|
listData.Add(data[12 + tempCount].ToString());
|
tempCount++;
|
}
|
for (int j = 0; j < listData.Count / 4; j++)
|
{
|
int curIndex = 4 * j;
|
tempD.privateFuncTypeLevelFirstList.Add(Convert.ToInt32(listData[curIndex + 2] + listData[curIndex + 3].ToString() + listData[curIndex].ToString() + listData[curIndex + 1].ToString(), 16));
|
//if (privateFuncFirstLevelList.Contains(256) == false)
|
//{
|
// privateFuncFirstLevelList.Add(Convert.ToInt32(listData[curIndex + 2] + listData[curIndex + 3].ToString() + listData[curIndex].ToString() + listData[curIndex + 1].ToString(), 16));
|
|
//}
|
}
|
break;
|
case 2:
|
while (tempCount < usefulLength)
|
{
|
listData.Add(data[12 + tempCount].ToString());
|
tempCount++;
|
}
|
for (int j = 0; j < listData.Count / 4; j++)
|
{
|
int curIndex = 4 * j;
|
if (j == 0)
|
{
|
tempD.privateFuncTypeLevelFirstList.Add(Convert.ToInt32(listData[curIndex + 2] + listData[curIndex + 3].ToString() + listData[curIndex].ToString() + listData[curIndex + 1].ToString(), 16));
|
//if (privateFuncFirstLevelList.Contains(256) == false)
|
//{
|
// privateFuncFirstLevelList.Add(Convert.ToInt32(listData[curIndex + 2] + listData[curIndex + 3].ToString() + listData[curIndex].ToString() + listData[curIndex + 1].ToString(), 16));
|
//}
|
}
|
else
|
{
|
tempD.privateFuncTypeLevelSecondList.Add(Convert.ToInt32(listData[curIndex + 2] + listData[curIndex + 3].ToString() + listData[curIndex].ToString() + listData[curIndex + 1].ToString(), 16));
|
//if (privateFuncSecondLevelList.Contains(1) == false || privateFuncSecondLevelList.Contains(100) == false || privateFuncSecondLevelList.Contains(200) == false || privateFuncSecondLevelList.Contains(300) == false)
|
//{
|
// privateFuncSecondLevelList.Add(Convert.ToInt32(listData[curIndex + 2] + listData[curIndex + 3].ToString() + listData[curIndex].ToString() + listData[curIndex + 1].ToString(), 16));
|
//}
|
}
|
}
|
break;
|
case 3:
|
while (tempCount < usefulLength)
|
{
|
listData.Add(data[12 + tempCount].ToString());
|
tempCount++;
|
}
|
for (int j = 0; j < listData.Count / 4; j++)
|
{
|
int curIndex = 4 * j;
|
if (j == 0)
|
{
|
tempD.privateFuncTypeLevelFirstList.Add(Convert.ToInt32(listData[curIndex + 2] + listData[curIndex + 3].ToString() + listData[curIndex].ToString() + listData[curIndex + 1].ToString(), 16));
|
//if (privateFuncFirstLevelList.Contains(256) == false)
|
//{
|
// privateFuncFirstLevelList.Add(Convert.ToInt32(listData[curIndex + 2] + listData[curIndex + 3].ToString() + listData[curIndex].ToString() + listData[curIndex + 1].ToString(), 16));
|
//}
|
}
|
else if (j == 1)
|
{
|
tempD.privateFuncTypeLevelSecondList.Add(Convert.ToInt32(listData[curIndex + 2] + listData[curIndex + 3].ToString() + listData[curIndex].ToString() + listData[curIndex + 1].ToString(), 16));
|
//if (privateFuncSecondLevelList.Contains(1) == false || privateFuncSecondLevelList.Contains(100) == false || privateFuncSecondLevelList.Contains(200) == false || privateFuncSecondLevelList.Contains(300) == false)
|
//{
|
// privateFuncSecondLevelList.Add(Convert.ToInt32(listData[curIndex + 2] + listData[curIndex + 3].ToString() + listData[curIndex].ToString() + listData[curIndex + 1].ToString(), 16));
|
//}
|
}
|
else
|
{
|
tempD.privateFuncTypeLevelThirdList.Add(Convert.ToInt32(listData[curIndex + 2] + listData[curIndex + 3].ToString() + listData[curIndex].ToString() + listData[curIndex + 1].ToString(), 16));
|
//if (privateFuncThirdLevelList.Contains(1) == false || privateFuncThirdLevelList.Contains(65535) == false || privateFuncThirdLevelList.Contains(100) == false || privateFuncThirdLevelList.Contains(101) == false || privateFuncThirdLevelList.Contains(102) == false || privateFuncThirdLevelList.Contains(200) == false || privateFuncThirdLevelList.Contains(201) == false || privateFuncThirdLevelList.Contains(202) == false || privateFuncThirdLevelList.Contains(300) == false || privateFuncThirdLevelList.Contains(301) == false || privateFuncThirdLevelList.Contains(302) == false || privateFuncThirdLevelList.Contains(303) == false || privateFuncThirdLevelList.Contains(304) == false)
|
//{
|
// privateFuncThirdLevelList.Add(Convert.ToInt32(listData[curIndex + 2] + listData[curIndex + 3].ToString() + listData[curIndex].ToString() + listData[curIndex + 1].ToString(), 16)); ;
|
//}
|
}
|
}
|
break;
|
}
|
panelPrivateFunctionsResponseInfo = tempD;
|
result = new PanelPrivateFunctionsResponseAllInfo { panelPrivateFunctionsResponseInfo = tempD };
|
System.Console.WriteLine($"UI收到通知后的主题_command:0003_{topic}");
|
}
|
}
|
}
|
}
|
}
|
};
|
|
Gateway.Actions += action;
|
System.Console.WriteLine("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString());
|
|
try
|
{
|
var passData = SendPanelPrivateFunctions(args);
|
var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
|
var data = new JObject { { "PassData", passData } };
|
jObject.Add("Data", data);
|
Gateway.Send("ClientDataPassthrough", jObject.ToString());
|
}
|
catch { }
|
|
var dateTime = DateTime.Now;
|
while ((DateTime.Now - dateTime).TotalMilliseconds < 9000) //WaitReceiveDataTime)
|
{
|
await System.Threading.Tasks.Task.Delay(10);
|
if (result != null)
|
{
|
break;
|
}
|
}
|
if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
|
{
|
result = new PanelPrivateFunctionsResponseAllInfo { errorMessageBase = " 回复超时,请重新操作" };
|
}
|
Gateway.Actions -= action;
|
System.Console.WriteLine("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString());
|
|
return result;
|
});
|
}
|
|
/// <summary>
|
/// PIR配置参数回复
|
/// </summary>
|
[System.Serializable]
|
public class PanelPrivateFunctionsResponseAllInfo
|
{
|
/// <summary>
|
/// 错误信息
|
/// </summary>
|
public string errorMessageBase;
|
/// <summary>
|
/// 网关信息错误反馈
|
/// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
|
/// </summary>
|
public ErrorResponData errorResponData;
|
/// <summary>
|
/// 光感等级个数(Lux能力)
|
/// <para>有几个等级就显示几个刻度</para>
|
/// </summary>
|
public PanelPrivateFunctionsResponseInfo panelPrivateFunctionsResponseInfo;
|
}
|
|
/// <summary>
|
/// 配置参数回复
|
/// </summary>
|
public PanelPrivateFunctionsResponseInfo panelPrivateFunctionsResponseInfo;
|
[System.Serializable]
|
public class PanelPrivateFunctionsResponseInfo
|
{
|
/// <summary>
|
/// 功能类级别梯度
|
/// <para>1:第一级别</para>
|
/// <para>2:第二级别</para>
|
/// <para>3:第三级别</para>
|
/// </summary>
|
public int funLevel = -1;
|
|
/// <summary>
|
/// 私有功能类
|
/// <para>256:Key,按键类类 </para>
|
/// <para>768:PIR,PIR类</para>
|
/// <para>1024:Light,灯类</para>
|
/// </summary>
|
public List<int> privateFuncTypeLevelFirstList = new List<int>();
|
|
/// <summary>
|
/// 第二级信息
|
/// <para>1:特殊功能</para>
|
/// <para>100:Switch,开关(按键类)</para>
|
/// <para>200:Dimmer,调光(按键类)</para>
|
/// <para>300:Curtain,窗帘(按键类)</para>
|
/// <para>0:EnergySavingMode,节能模式(灯类)</para>
|
/// <para>1:SleepMode,睡眠模式(灯类)</para>
|
/// <para>100:WhiteBalance,白平衡(灯类)</para>
|
/// <para>101:RGBColor,RGB指示灯颜色(灯类)</para>
|
/// <para>102:RGBLevel,RGB指示灯亮度(灯类)</para>
|
/// </summary>
|
public List<int> privateFuncTypeLevelSecondList = new List<int>();
|
|
/// <summary>
|
/// 第三级信息
|
/// <para>1:场景触发(特殊功能)</para>
|
/// <para>65535:禁止发送功能(特殊功能)</para>
|
/// <para>100:SwitchOpen,开关开(按键类)</para>
|
/// <para>101:SwitchClose,开关关(按键类)</para>
|
/// <para>102:SwitchChange,开关切换(按键类)</para>
|
/// <para>200:DimmerStepUp,增大调光(按键类)</para>
|
/// <para>201:DimmerStepDown,降低调光(按键类)</para>
|
/// <para>202:DimmerStepChange,调光切换(按键类)</para>
|
/// <para>300:CurtainOpen,窗帘开(按键类)</para>
|
/// <para>301:CurtainClose,窗帘关(按键类)</para>
|
/// <para>302:CurtainStop,窗帘停</para>
|
/// <para>303:CurtainUpStop,窗帘上升停</para>
|
/// <para>304:CurtainDownstop,窗帘下降停</para>
|
/// </summary>
|
public List<int> privateFuncTypeLevelThirdList = new List<int>();
|
|
}
|
|
/// <summary>
|
///读取面板的私有信息
|
/// <para>注意params取值如下:</para>
|
/// <para>1、当int[]传空,返回值是“面板具有的功能大类”:1024:灯类,256:按键类,768:PIR类</para>
|
/// <para>2、当int[]值为第一级别PrivateFuncTypeFir中选择一个。返回值是“面按键发送功能类”</para>
|
/// <para>3、当int[]值为第一级别PrivateFuncTypeFir中选择一个,接着再选第二级别PrivateFunTypeSec中选择一个,返回值是“面按键具体功能配置”</para>
|
/// </summary>
|
string SendPanelPrivateFunctions(params int[] args)
|
{
|
string data = "";
|
string dataLength = "";
|
string dataComand1 = "03";
|
string dataComand2 = "00";
|
string dataSerialNum = "01";
|
string addDataLength = "";
|
string value0 = "";
|
string value1 = "";
|
string value2 = "";
|
try
|
{
|
|
if (args.Length != 0)
|
{
|
if (Convert.ToString(2 * args.Length + 5, 16).Length == 1)
|
{
|
dataLength = string.Concat(0, 2 * args.Length + 5);
|
}
|
else
|
{
|
dataLength = Convert.ToString(2 * args.Length + 5, 16);
|
}
|
|
|
if (Convert.ToString(2 * args.Length, 16).Length == 1)
|
{
|
addDataLength = string.Concat(0, 2 * args.Length + 1);
|
}
|
else
|
{
|
addDataLength = Convert.ToString(2 * args.Length + 1, 16);
|
}
|
|
for (int i = 0; i < args.Length; i++)
|
{
|
switch (args.Length)
|
{
|
case 1:
|
value0 = "02";
|
switch (args[0])
|
{
|
case 1024:
|
value1 = "0004";
|
break;
|
case 256:
|
value1 = "0001";
|
break;
|
case 768:
|
value1 = "0003";
|
break;
|
}
|
break;
|
case 2:
|
value0 = "03";
|
switch (args[0])
|
{
|
case 1024:
|
value1 = "0004";
|
switch (args[1])
|
{
|
case 0:
|
value2 = "0000";
|
break;
|
case 1:
|
value2 = "0100";
|
break;
|
case 100:
|
value2 = "6400";
|
break;
|
case 101:
|
value2 = "6500";
|
break;
|
case 102:
|
value2 = "6600";
|
break;
|
}
|
break;
|
case 256:
|
value1 = "0001";
|
switch (args[1])
|
{
|
case 1:
|
value2 = "0100";
|
break;
|
case 100:
|
value2 = "6400";
|
break;
|
case 200:
|
value2 = "C800";
|
break;
|
case 300:
|
value2 = "2C01";
|
break;
|
}
|
break;
|
case 768:
|
value1 = "0003";
|
break;
|
}
|
|
break;
|
}
|
}
|
|
}
|
else
|
{
|
dataLength = "05";
|
addDataLength = "01";
|
value0 = "01";
|
}
|
data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
|
value0 + value1 + value2;
|
}
|
catch { };
|
|
return data;
|
}
|
|
/// <summary>
|
/// 私有功能类(第一级别)信息
|
/// </summary>
|
public class PrivateFuncTypeFir
|
{
|
/// <summary>
|
/// 私有功能类
|
/// <para>256:Key,按键类类 </para>
|
/// <para>768:PIR,PIR类</para>
|
/// <para>1024:Light,灯类</para>
|
/// </summary>
|
public int privateFuncTypeOne;
|
}
|
|
/// <summary>
|
/// 私有功能类(第二级别)信息
|
/// </summary>
|
public class PrivateFunTypeSec
|
{
|
/// <summary>
|
/// 第二级信息
|
/// <para>100:Switch,开关(按键类)</para>
|
/// <para>200:Dimmer,调光(按键类)</para>
|
/// <para>300:Curtain,窗帘(按键类)</para>
|
/// <para>0:EnergySavingMode,节能模式(灯类)</para>
|
/// <para>1:SleepMode,睡眠模式(灯类)</para>
|
/// <para>100:WhiteBalance,白平衡(灯类)</para>
|
/// <para>101:RGBColor,RGB指示灯颜色(灯类)</para>
|
/// <para>102:RGBLevel,RGB指示灯亮度(灯类)</para>
|
/// </summary>
|
public int privateFuncTypeTwo;
|
}
|
|
/// <summary>
|
/// 私有功能类(第三级别)信息
|
/// </summary>
|
public class PrivateFunTypeThird
|
{
|
/// <summary>
|
/// 第三级信息
|
/// <para>0:EnergySavingModeOpenLevel,节能模式开亮度(灯类 )</para>
|
/// <para>1:EnergySavingModeCloseLevel,节能模式关亮度(灯类)</para>
|
/// <para>1:场景触发;(特殊功能)</para>
|
/// <para>65535:禁止发送功能(特殊功能)</para>
|
/// <para>100:SwitchOpen,开关开(按键类)</para>
|
/// <para>101:SwitchClose,开关关(按键类)</para>
|
/// <para>102:SwitchChange,开关切换(按键类)</para>
|
/// <para>200:DimmerStepUp,增大调光(按键类)</para>
|
/// <para>201:DimmerStepDown,降低调光(按键类)</para>
|
/// <para>202:DimmerStepChange,调光切换(按键类)</para>
|
/// <para>300:CurtainOpen,窗帘开(按键类)</para>
|
/// <para>301:CurtainClose,窗帘关(按键类)</para>
|
/// <para>302:CurtainStop,窗帘停</para>
|
/// <para>303:CurtainUpStop,窗帘上升停</para>
|
/// <para>304:CurtainDownstop,窗帘下降停</para>
|
/// </summary>
|
public int privateFuncTypeThird;
|
}
|
|
/// <summary>
|
/// 获取按键面板的第一级别功能功能系(1024:灯类,256:按键类,768:PIR类)
|
/// </summary>
|
/// <param name="panel">按键面板的某一个回路</param>
|
/// <returns></returns>
|
public async Task<List<int>> GetPanelDeviceFunctionLevel1()
|
{
|
var result = await GetPanelPrivateFunctionsAsync();
|
if (result == null || result.panelPrivateFunctionsResponseInfo == null)
|
{
|
return null;
|
}
|
|
return result.panelPrivateFunctionsResponseInfo.privateFuncTypeLevelFirstList;
|
}
|
|
/// <summary>
|
/// <para>获取按键面板的第二级别功能功能系(以下为返回值)</para>
|
/// <para>100:Switch,开关(按键类)</para>
|
/// <para>200:Dimmer,调光(按键类)</para>
|
/// <para>300:Curtain,窗帘(按键类)</para>
|
/// <para>0:EnergySavingMode,节能模式(灯类)</para>
|
/// <para>1:SleepMode,睡眠模式(灯类)</para>
|
/// <para>100:WhiteBalance,白平衡(灯类)</para>
|
/// <para>101:RGBColor,RGB指示灯颜色(灯类)</para>
|
/// <para>102:RGBLevel,RGB指示灯亮度(灯类)</para>
|
/// </summary>
|
/// <param name="panel">按键面板的某一个回路</param>
|
/// <param name="level1">第一级别的ID(1024:灯类,256:按键类,768:PIR类)</param>
|
/// <returns></returns>
|
public async Task<List<int>> GetPanelDeviceFunctionLevel2(int level1)
|
{
|
var result = await GetPanelPrivateFunctionsAsync(new int[] { level1 });
|
if (result == null || result.panelPrivateFunctionsResponseInfo == null)
|
{
|
return null;
|
}
|
return result.panelPrivateFunctionsResponseInfo.privateFuncTypeLevelSecondList;
|
}
|
|
/// <summary>
|
/// 按键类第三级别如下:
|
/// <para>1:场景触发;(特殊功能)</para>
|
/// <para>65535:禁止发送功能(特殊功能)</para>
|
/// <para>100:SwitchOpen,开关开(按键类)</para>
|
/// <para>101:SwitchClose,开关关(按键类)</para>
|
/// <para>102:SwitchChange,开关切换(按键类)</para>
|
/// <para>200:DimmerStepUp,增大调光(按键类)</para>
|
/// <para>201:DimmerStepDown,降低调光(按键类)</para>
|
/// <para>202:DimmerStepChange,调光切换(按键类)</para>
|
/// <para>300:CurtainOpen,窗帘开(按键类)</para>
|
/// <para>301:CurtainClose,窗帘关(按键类)</para>
|
/// <para>302:CurtainStop,窗帘停</para>
|
/// <para>303:CurtainUpStop,窗帘上升停</para>
|
/// <para>304:CurtainDownstop,窗帘下降停</para>
|
/// </summary>
|
/// <param name="panel">按键面板的某一个回路</param>
|
/// <param name="level1">第一级别的ID(1024:灯类,256:按键类,768:PIR类)</param>
|
/// <param name="level2">第二级别的ID(当第一级别是按键类,1:特殊功能,100:按键开关,200:按键调光;300:按键窗帘)</param>
|
/// <returns></returns>
|
public async Task<List<int>> GetPanelDeviceFunctionLevel3(int level1, int level2)
|
{
|
var result = await GetPanelPrivateFunctionsAsync(new int[] { level1, level2 });
|
if (result == null || result.panelPrivateFunctionsResponseInfo == null)
|
{
|
return null;
|
}
|
return result.panelPrivateFunctionsResponseInfo.privateFuncTypeLevelThirdList;
|
}
|
#endregion
|
|
#region 控制按键指示灯.
|
///<summary >
|
///控制按键指示灯
|
/// </summary>
|
public async System.Threading.Tasks.Task<ResponseAllData> ControlKeyAsync(KeyNumStatus keyNum, KeyStatus keyStatus)
|
{
|
ResponseAllData result = null;
|
if (Gateway == null)
|
{
|
result = new ResponseAllData { errorMessageBase = "当前没有网关" };
|
return result;
|
}
|
return await System.Threading.Tasks.Task.Run(async () =>
|
{
|
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 = Gateway.getGatewayBaseInfo.gwID };
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
|
|
if (temp == null)
|
{
|
result = new ResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
|
}
|
|
else
|
{
|
result = new ResponseAllData { errorResponData = temp, errorMessageBase = 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());
|
|
if (gatewayTemp.clientDataPassthroughResponseData == null)
|
{
|
result = new ResponseAllData { errorMessageBase = "网关返回的数据为空" };
|
}
|
else
|
{
|
if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null)
|
{
|
var data = gatewayTemp.clientDataPassthroughResponseData.PassData;
|
if (data.Length == 16)
|
{
|
var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
|
if (command == "0002")
|
{
|
var tempD = new ResponseData();
|
tempD.command = Convert.ToInt32(data[10].ToString() + data[11].ToString() + data[12].ToString() + data[13].ToString(), 16);
|
tempD.status = Convert.ToInt32(data[14].ToString() + data[15].ToString(), 16);
|
result = new ResponseAllData { responseData = tempD };
|
System.Console.WriteLine($"UI收到通知后的主题_command:0400_{ topic}");
|
}
|
}
|
}
|
}
|
}
|
};
|
|
Gateway.Actions += action;
|
System.Console.WriteLine("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString());
|
|
try
|
{
|
var passData = ControlKeyData(keyNum, keyStatus);
|
var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
|
var data = new JObject { { "PassData", passData } };
|
jObject.Add("Data", data);
|
Gateway.Send(("ClientDataPassthrough"), jObject.ToString());
|
}
|
catch { }
|
|
var dateTime = DateTime.Now;
|
while ((DateTime.Now - dateTime).TotalMilliseconds < 9000)//WaitReceiveDataTime)
|
{
|
await System.Threading.Tasks.Task.Delay(10);
|
if (result != null)
|
{
|
break;
|
}
|
}
|
if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
|
{
|
result = new ResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
|
}
|
Gateway.Actions -= action;
|
System.Console.WriteLine("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString());
|
|
return result;
|
});
|
}
|
|
/// <summary>
|
/// 按键指示灯状态
|
/// </summary>
|
public enum KeyStatus
|
{
|
/// <summary>
|
/// 关
|
/// </summary>
|
close = 0x00,
|
/// <summary>
|
/// 开
|
/// </summary>
|
open = 0x64,
|
/// <summary>
|
/// 无效
|
/// </summary>
|
inValid = 0xff,
|
}
|
|
/// <summary>
|
/// 控制按键指示灯
|
/// </summary>
|
string ControlKeyData(KeyNumStatus keyNumStatus, KeyStatus keyStatus)
|
{
|
string data = "";
|
string dataLength = "07";
|
string dataComand1 = "00";
|
string dataComand2 = "04";
|
string dataSerialNum = "01";
|
string addDataLength = "03";
|
string kStatus = "";
|
string kNum = "";
|
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());
|
|
switch (keyStatus)
|
{
|
case KeyStatus.close:
|
kStatus = "00";
|
break;
|
case KeyStatus.open:
|
kStatus = "64";
|
break;
|
case KeyStatus.inValid:
|
kStatus = "ff";
|
break;
|
}
|
|
|
data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
|
tempAttributeData + kStatus;
|
}
|
catch { };
|
|
return data;
|
}
|
#endregion
|
|
#region 配置按键指示灯颜色.
|
///<summary >
|
///配置按键指示灯颜色
|
/// </summary>
|
public async System.Threading.Tasks.Task<ResponseAllData> SetPanelColorInfoAsync(KeyColorData keyColorData, KeyNumStatus keyNumStatus)
|
{
|
ResponseAllData result = null;
|
if (Gateway == null)
|
{
|
result = new ResponseAllData { errorMessageBase = "当前没有网关" };
|
return result;
|
}
|
return await System.Threading.Tasks.Task.Run(async () =>
|
{
|
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 = Gateway.getGatewayBaseInfo.gwID };
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
|
|
if (temp == null)
|
{
|
result = new ResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
|
}
|
|
else
|
{
|
result = new ResponseAllData { errorResponData = temp, errorMessageBase = 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());
|
|
if (gatewayTemp.clientDataPassthroughResponseData == null)
|
{
|
result = new ResponseAllData { errorMessageBase = "网关返回的数据为空" };
|
}
|
else
|
{
|
if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null)
|
{
|
var data = gatewayTemp.clientDataPassthroughResponseData.PassData;
|
if (data.Length == 16)
|
{
|
var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
|
if (command == "0002")
|
{
|
var tempD = new ResponseData();
|
tempD.command = Convert.ToInt32(data[10].ToString() + data[11].ToString() + data[12].ToString() + data[13].ToString(), 16);
|
tempD.status = Convert.ToInt32(data[14].ToString() + data[15].ToString(), 16);
|
result = new ResponseAllData { responseData = tempD };
|
System.Console.WriteLine($"UI收到通知后的主题_command:0401_{ topic}");
|
}
|
}
|
}
|
}
|
}
|
};
|
|
Gateway.Actions += action;
|
System.Console.WriteLine("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString());
|
|
try
|
{
|
var passData = SetPanelColorData(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);
|
Gateway.Send(("ClientDataPassthrough"), jObject.ToString());
|
}
|
catch { }
|
|
var dateTime = DateTime.Now;
|
while ((DateTime.Now - dateTime).TotalMilliseconds < 9000)// WaitReceiveDataTime)
|
{
|
await System.Threading.Tasks.Task.Delay(10);
|
if (result != null)
|
{
|
break;
|
}
|
}
|
if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
|
{
|
result = new ResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
|
}
|
Gateway.Actions -= action;
|
System.Console.WriteLine("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString());
|
|
return result;
|
});
|
}
|
|
/// <summary>
|
/// 绑定设备信息,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class KeyColorDataResponseAllData
|
{
|
/// <summary>
|
/// 错误信息
|
/// </summary>
|
public string errorMessageBase;
|
/// <summary>
|
/// 网关信息错误反馈
|
/// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
|
/// </summary>
|
public ErrorResponData errorResponData;
|
/// <summary>
|
/// 按键指示灯颜色信息
|
/// </summary>
|
public KeyColorData keyColorData;
|
}
|
|
/// <summary>
|
/// 配置按键指示灯颜色数据
|
/// <para>发配置按键指示灯颜色命令时,此时为发送到网关的透传数据</para>
|
/// </summary>
|
/// <returns>The passthorugh data.</returns>
|
/// <param name="keyColorData">Key color data.</param>
|
/// <param name="keyNum">Key number.</param>
|
string SetPanelColorData(KeyColorData keyColorData, 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;
|
}
|
|
/// <summary>
|
/// 按键指示灯颜色信息
|
/// </summary>
|
public KeyColorData keyColorData;
|
// <summary>
|
/// 按键指示灯颜色信息
|
/// </summary>
|
[System.Serializable]
|
public class KeyColorData
|
{
|
/// <summary>
|
/// 指示灯对应顺序号
|
/// </summary>
|
public KeyNum keyNum;
|
/// <summary>
|
/// 开状态颜色R(0-ff)
|
/// </summary>
|
public string OpenColorR;
|
/// <summary>
|
/// 开状态颜色G(0-ff)
|
/// </summary>
|
public string OpenColorG;
|
/// <summary>
|
/// 开状态颜色B(0-ff)
|
/// </summary>
|
public string OpenColorB;
|
/// <summary>
|
/// 关状态颜色R(0-ff)
|
/// </summary>
|
public string CloseColorR;
|
/// <summary>
|
/// 关状态颜色G(0-ff)
|
/// </summary>
|
public string CloseColorG;
|
/// <summary>
|
/// 关状态颜色B(0-ff)
|
/// </summary>
|
public string CloseColorB;
|
}
|
|
/// <summary>
|
/// 按键指示灯颜色信息对应顺序号
|
/// </summary>
|
public class KeyNumStatus
|
{
|
/// <summary>
|
/// false:关
|
/// true:开
|
/// </summary>
|
public bool Key1;
|
/// <summary>
|
/// false:关
|
/// true:开
|
/// </summary>
|
public bool Key2;
|
/// <summary>
|
/// false:关
|
/// true:开
|
/// </summary>
|
public bool Key3;
|
/// <summary>
|
/// false:关
|
/// true:开
|
/// </summary>
|
public bool Key4;
|
/// <summary>
|
/// false:关
|
/// true:开
|
/// </summary>
|
public bool Key5;
|
/// <summary>
|
/// false:关
|
/// true:开
|
/// </summary>
|
public bool Key6;
|
/// <summary>
|
/// false:关
|
/// true:开
|
/// </summary>
|
public bool Key7;
|
/// <summary>
|
/// false:关
|
/// true:开
|
/// </summary>
|
public bool Key8;
|
/// <summary>
|
/// false:关
|
/// true:开
|
/// </summary>
|
public bool Key9;
|
/// <summary>
|
/// false:关
|
/// true:开
|
/// </summary>
|
public bool Key10;
|
/// <summary>
|
/// false:关
|
/// true:开
|
/// </summary>
|
public bool Key11;
|
/// <summary>
|
/// false:关
|
/// true:开
|
/// </summary>
|
public bool Key12;
|
/// <summary>
|
/// false:关
|
/// true:开
|
/// </summary>
|
public bool Key13;
|
/// <summary>
|
/// false:关
|
/// true:开
|
/// </summary>
|
public bool Key14;
|
/// <summary>
|
/// false:关
|
/// true:开
|
/// </summary>
|
public bool Key15;
|
/// <summary>
|
/// false:关
|
/// true:开
|
/// </summary>
|
public bool Key16;
|
}
|
#endregion
|
|
#region 配置按键指示灯面板亮度属性.
|
///<summary >
|
///配置按键指示灯面板亮度属性
|
/// <para>directionsLevel:指示灯亮度 0-100(这个是点击后的值)</para>
|
/// <para>backlightLevel:背光灯亮度 0-100(这个是点击前的值)</para>
|
/// </summary>
|
public async System.Threading.Tasks.Task<ResponseAllData> SetKeyLevelAsync(int directionsLevel, int backlightLevel)
|
{
|
ResponseAllData result = null;
|
if (Gateway == null)
|
{
|
result = new ResponseAllData { errorMessageBase = "当前没有网关" };
|
return result;
|
}
|
return await System.Threading.Tasks.Task.Run(async () =>
|
{
|
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 = Gateway.getGatewayBaseInfo.gwID };
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
|
|
if (temp == null)
|
{
|
result = new ResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
|
}
|
|
else
|
{
|
result = new ResponseAllData { errorResponData = temp, errorMessageBase = 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());
|
|
if (gatewayTemp.clientDataPassthroughResponseData == null)
|
{
|
result = new ResponseAllData { errorMessageBase = "网关返回的数据为空" };
|
}
|
else
|
{
|
if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null)
|
{
|
var data = gatewayTemp.clientDataPassthroughResponseData.PassData;
|
if (data.Length == 16)
|
{
|
var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
|
if (command == "0002")
|
{
|
var tempD = new ResponseData();
|
tempD.command = Convert.ToInt32(data[10].ToString() + data[11].ToString() + data[12].ToString() + data[13].ToString(), 16);
|
tempD.status = Convert.ToInt32(data[14].ToString() + data[15].ToString(), 16);
|
result = new ResponseAllData { responseData = tempD };
|
System.Console.WriteLine($"UI收到通知后的主题_command:0402_{ topic}");
|
}
|
}
|
}
|
}
|
}
|
};
|
|
Gateway.Actions += action;
|
System.Console.WriteLine("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString());
|
|
try
|
{
|
var passData = SetPanelLevelData(directionsLevel, backlightLevel);
|
var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
|
var data = new JObject { { "PassData", passData } };
|
jObject.Add("Data", data);
|
Gateway.Send(("ClientDataPassthrough"), jObject.ToString());
|
}
|
catch { }
|
|
var dateTime = DateTime.Now;
|
while ((DateTime.Now - dateTime).TotalMilliseconds < 9000)// WaitReceiveDataTime)
|
{
|
await System.Threading.Tasks.Task.Delay(10);
|
if (result != null)
|
{
|
break;
|
}
|
}
|
if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
|
{
|
result = new ResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
|
}
|
Gateway.Actions -= action;
|
System.Console.WriteLine("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString());
|
|
return result;
|
});
|
}
|
|
/// <summary>
|
/// 控制按键指示灯
|
/// </summary>
|
string SetPanelLevelData(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 配置按键指示灯面板节能模式.
|
///<summary >
|
/// 配置按键指示灯面板节能模式
|
/// <para>modeEnable:节能模式使能</para>
|
/// <para>modeTime:无操作进入节能模式时间 0-ff</para>
|
/// <para>节能模式亮度:0-100</para>
|
/// </summary>
|
public async System.Threading.Tasks.Task<ResponseAllData> SetKeyModeAsync(bool modeEnable, int modeTime, int level)
|
{
|
ResponseAllData result = null;
|
if (Gateway == null)
|
{
|
result = new ResponseAllData { errorMessageBase = "当前没有网关" };
|
return result;
|
}
|
return await System.Threading.Tasks.Task.Run(async () =>
|
{
|
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 = Gateway.getGatewayBaseInfo.gwID };
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
|
|
if (temp == null)
|
{
|
result = new ResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
|
}
|
|
else
|
{
|
result = new ResponseAllData { errorResponData = temp, errorMessageBase = 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());
|
|
if (gatewayTemp.clientDataPassthroughResponseData == null)
|
{
|
result = new ResponseAllData { errorMessageBase = "网关返回的数据为空" };
|
}
|
else
|
{
|
if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null)
|
{
|
var data = gatewayTemp.clientDataPassthroughResponseData.PassData;
|
if (data.Length == 16)
|
{
|
var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
|
if (command == "0002")
|
{
|
var tempD = new ResponseData();
|
tempD.command = Convert.ToInt32(data[10].ToString() + data[11].ToString() + data[12].ToString() + data[13].ToString(), 16);
|
tempD.status = Convert.ToInt32(data[14].ToString() + data[15].ToString(), 16);
|
result = new ResponseAllData { responseData = tempD };
|
System.Console.WriteLine($"UI收到通知后的主题_command:0403_{ topic}");
|
}
|
}
|
}
|
}
|
}
|
};
|
|
Gateway.Actions += action;
|
System.Console.WriteLine("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString());
|
|
try
|
{
|
var passData = SetPanelModeModeData(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);
|
Gateway.Send(("ClientDataPassthrough"), jObject.ToString());
|
}
|
catch { }
|
|
var dateTime = DateTime.Now;
|
while ((DateTime.Now - dateTime).TotalMilliseconds < 9000)// WaitReceiveDataTime)
|
{
|
await System.Threading.Tasks.Task.Delay(10);
|
if (result != null)
|
{
|
break;
|
}
|
}
|
if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
|
{
|
result = new ResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
|
}
|
Gateway.Actions -= action;
|
System.Console.WriteLine("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString());
|
|
return result;
|
});
|
}
|
|
/// <summary>
|
/// 配置按键指示灯面板节能模式
|
/// </summary>
|
string SetPanelModeModeData(bool modeEnable, int modeTime, int modelevel)
|
{
|
string data = "";
|
string dataLength = "07";
|
string dataComand1 = "03";
|
string dataComand2 = "04";
|
string dataSerialNum = "01";
|
string addDataLength = "03";
|
string mode = "";
|
string time = "";
|
string level = "";
|
try
|
{
|
if (modeEnable)
|
{
|
mode = "01";
|
}
|
else
|
{
|
mode = "00";
|
}
|
var sbString1 = new System.Text.StringBuilder();
|
string temp = Convert.ToString(modeTime, 16);
|
switch (temp.Length)
|
{
|
case 1:
|
time = "0" + temp;
|
break;
|
case 2:
|
time = temp;
|
break;
|
}
|
|
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;
|
}
|
|
sbString1.Append(time.ToUpper());
|
sbString2.Append(level.ToUpper());
|
data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
|
mode + sbString1 + sbString2;
|
}
|
catch { };
|
|
return data;
|
}
|
#endregion
|
|
#region 获取按键指示灯开关颜色.
|
///<summary >
|
///获取按键指示灯开关颜色.
|
/// </summary>
|
public async System.Threading.Tasks.Task<KeyColorDataResponseAllData> GetPanelColorInfoAsync(KeyNum keyNum)
|
{
|
KeyColorDataResponseAllData result = null;
|
if (Gateway == null)
|
{
|
result = new KeyColorDataResponseAllData { errorMessageBase = "当前没有网关" };
|
return result;
|
}
|
return await System.Threading.Tasks.Task.Run(async () =>
|
{
|
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 = Gateway.getGatewayBaseInfo.gwID };
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
|
|
if (temp == null)
|
{
|
result = new KeyColorDataResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
|
}
|
|
else
|
{
|
result = new KeyColorDataResponseAllData { errorResponData = temp, errorMessageBase = 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());
|
|
if (gatewayTemp.clientDataPassthroughResponseData == null)
|
{
|
result = new KeyColorDataResponseAllData { errorMessageBase = "网关返回的数据为空" };
|
}
|
else
|
{
|
if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null)
|
{
|
var data = gatewayTemp.clientDataPassthroughResponseData.PassData;
|
if (data.Length == 24)
|
{
|
var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
|
if (command == "0405")
|
{
|
var key1 = data[10] + data[11];
|
var key = data[10].ToString() + data[11].ToString();
|
var tempR = new 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(); ;
|
|
switch (key)
|
{
|
case "01":
|
tempR.keyNum = KeyNum.Key1;
|
break;
|
case "02":
|
tempR.keyNum = KeyNum.Key2;
|
break;
|
case "03":
|
tempR.keyNum = KeyNum.Key3;
|
break;
|
case "04":
|
tempR.keyNum = KeyNum.Key4;
|
break;
|
case "05":
|
tempR.keyNum = KeyNum.Key5;
|
break;
|
case "06":
|
tempR.keyNum = KeyNum.Key6;
|
break;
|
case "07":
|
tempR.keyNum = KeyNum.Key7;
|
break;
|
case "08":
|
tempR.keyNum = KeyNum.Key8;
|
break;
|
case "09":
|
tempR.keyNum = KeyNum.Key9;
|
break;
|
case "0a":
|
tempR.keyNum = KeyNum.Key10;
|
break;
|
case "0b":
|
tempR.keyNum = KeyNum.Key11;
|
break;
|
case "0c":
|
tempR.keyNum = KeyNum.Key12;
|
break;
|
case "0d":
|
tempR.keyNum = KeyNum.Key13;
|
break;
|
case "0e":
|
tempR.keyNum = KeyNum.Key14;
|
break;
|
case "0f":
|
tempR.keyNum = KeyNum.Key15;
|
break;
|
}
|
keyColorData = tempR;
|
result = new KeyColorDataResponseAllData { keyColorData = tempR };
|
System.Console.WriteLine($"UI收到通知后的主题_command:0404_{ topic}");
|
}
|
}
|
}
|
}
|
}
|
};
|
|
Gateway.Actions += action;
|
System.Console.WriteLine("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString());
|
|
try
|
{
|
var passData = GetkeyColorData(keyNum);
|
var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
|
var data = new JObject { { "PassData", passData } };
|
jObject.Add("Data", data);
|
Gateway.Send(("ClientDataPassthrough"), jObject.ToString());
|
}
|
catch { }
|
|
var dateTime = DateTime.Now;
|
while ((DateTime.Now - dateTime).TotalMilliseconds < 9000)// WaitReceiveDataTime)
|
{
|
await System.Threading.Tasks.Task.Delay(10);
|
if (result != null)
|
{
|
break;
|
}
|
}
|
if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
|
{
|
result = new KeyColorDataResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
|
}
|
Gateway.Actions -= action;
|
System.Console.WriteLine("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString());
|
|
return result;
|
});
|
}
|
|
/// <summary>
|
/// 获取按键指示灯开关颜色
|
/// </summary>
|
string GetkeyColorData(KeyNum keyNum)
|
{
|
string data = "";
|
string dataLength = "05";
|
string dataComand1 = "04";
|
string dataComand2 = "04";
|
string dataSerialNum = "01";
|
string addDataLength = "01";
|
string kNum = "";
|
|
try
|
{
|
switch (keyNum)
|
{
|
case KeyNum.Key1:
|
kNum = "01";
|
break;
|
case KeyNum.Key2:
|
kNum = "02";
|
break;
|
case KeyNum.Key3:
|
kNum = "03";
|
break;
|
case KeyNum.Key4:
|
kNum = "04";
|
break;
|
case KeyNum.Key5:
|
kNum = "05";
|
break;
|
case KeyNum.Key6:
|
kNum = "06";
|
break;
|
case KeyNum.Key7:
|
kNum = "07";
|
break;
|
case KeyNum.Key8:
|
kNum = "08";
|
break;
|
case KeyNum.Key9:
|
kNum = "09";
|
break;
|
case KeyNum.Key10:
|
kNum = "0A";
|
break;
|
case KeyNum.Key11:
|
kNum = "0B";
|
break;
|
case KeyNum.Key12:
|
kNum = "0C";
|
break;
|
case KeyNum.Key13:
|
kNum = "0D";
|
break;
|
case KeyNum.Key14:
|
kNum = "0E";
|
break;
|
case KeyNum.Key15:
|
kNum = "0F";
|
break;
|
case KeyNum.Key16:
|
kNum = "10";
|
break;
|
}
|
|
data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength + kNum;
|
}
|
catch { };
|
|
return data;
|
}
|
|
/// <summary>
|
/// 按键指示灯颜色信息对应顺序号(睡眠组号)
|
/// </summary>
|
public enum KeyNum
|
{
|
Key1 = 1,
|
Key2 = 2,
|
Key3 = 3,
|
Key4 = 4,
|
Key5 = 5,
|
Key6 = 6,
|
Key7 = 7,
|
Key8 = 8,
|
Key9 = 9,
|
Key10 = 10,
|
Key11 = 11,
|
Key12 = 12,
|
Key13 = 13,
|
Key14 = 14,
|
Key15 = 15,
|
Key16 = 16,
|
}
|
#endregion
|
|
#region 获取按键指示灯面板开关亮度配置.
|
///<summary >
|
///获取按键指示灯面板开关亮度配置
|
/// </summary>
|
public async System.Threading.Tasks.Task<PanelSwitchLevelInfo> GetPanelSwitchLevelAsync(string reserve = "01")
|
{
|
PanelSwitchLevelInfo result = null;
|
if (Gateway == null)
|
{
|
result = new PanelSwitchLevelInfo { errorMessageBase = "当前没有网关" };
|
return result;
|
}
|
return await System.Threading.Tasks.Task.Run(async () =>
|
{
|
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 = Gateway.getGatewayBaseInfo.gwID };
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
|
|
if (temp == null)
|
{
|
result = new PanelSwitchLevelInfo { errorMessageBase = "网关错误回复,且数据是空" };
|
}
|
|
else
|
{
|
result = new PanelSwitchLevelInfo { errorResponData = temp, errorMessageBase = 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());
|
|
if (gatewayTemp.clientDataPassthroughResponseData == null)
|
{
|
result = new PanelSwitchLevelInfo { errorMessageBase = "网关返回的数据为空" };
|
}
|
else
|
{
|
if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null)
|
{
|
var data = gatewayTemp.clientDataPassthroughResponseData.PassData;
|
if (data.Length == 14)
|
{
|
var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
|
if (command == "0407")
|
{
|
var level1 = Convert.ToInt32(data[10].ToString() + data[11].ToString(), 16);
|
var level2 = Convert.ToInt32(data[12].ToString() + data[13].ToString(), 16);
|
panelDirectionsLevel = level1;
|
panelBacklightLevel = level2;
|
result = new PanelSwitchLevelInfo { panelDirectionsLevel = level1, panelBacklightLevel = level2 };
|
System.Console.WriteLine($"UI收到通知后的主题_command:0406_{ topic}");
|
}
|
}
|
}
|
}
|
}
|
};
|
|
Gateway.Actions += action;
|
System.Console.WriteLine("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString());
|
|
try
|
{
|
var passData = SendPanelSwitchLevelData(reserve);
|
var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
|
var data = new JObject { { "PassData", passData } };
|
jObject.Add("Data", data);
|
Gateway.Send(("ClientDataPassthrough"), jObject.ToString());
|
}
|
catch { }
|
|
var dateTime = DateTime.Now;
|
while ((DateTime.Now - dateTime).TotalMilliseconds < 9000)//WaitReceiveDataTime)
|
{
|
await System.Threading.Tasks.Task.Delay(10);
|
if (result != null)
|
{
|
break;
|
}
|
}
|
if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
|
{
|
result = new PanelSwitchLevelInfo { errorMessageBase = " 回复超时,请重新操作" };
|
}
|
Gateway.Actions -= action;
|
System.Console.WriteLine("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString());
|
|
return result;
|
});
|
}
|
|
/// <summary>
|
/// 获取按键指示灯面板开关亮度配置数据
|
/// <para>发配置按键指示灯颜色命令时,此时为发送到网关的透传数据</para>
|
/// </summary>
|
string SendPanelSwitchLevelData(string reserve)
|
{
|
string data = "";
|
string dataLength = "05";
|
string dataComand1 = "06";
|
string dataComand2 = "04";
|
string dataSerialNum = "01";
|
string addDataLength = "01";
|
string reserveData = reserve;
|
|
try
|
{
|
data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
|
reserveData;
|
}
|
catch { };
|
|
return data;
|
}
|
|
/// <summary>
|
/// 按键指示灯面板开关亮度配置回复
|
/// </summary>
|
[System.Serializable]
|
public class PanelSwitchLevelInfo
|
{
|
/// <summary>
|
/// 错误信息
|
/// </summary>
|
public string errorMessageBase;
|
/// <summary>
|
/// 网关信息错误反馈
|
/// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
|
/// </summary>
|
public ErrorResponData errorResponData;
|
/// <summary>
|
///按键开状态(指示)亮度(这个是点击后的值)
|
/// </summary>
|
public int panelDirectionsLevel = -1;
|
|
/// <summary>
|
/// 按键关状态(背光)亮度(这个是点击前的值)
|
/// </summary>
|
public int panelBacklightLevel = -1;
|
}
|
#endregion
|
|
#region 获取按键节能模式配置状态.
|
///<summary >
|
///获取按键节能模式配置状态
|
/// </summary>
|
public async System.Threading.Tasks.Task<PanelSwitchLevelResponInfo> GetPanelSaveEnergyModeAsync(string reserve = "01")
|
{
|
PanelSwitchLevelResponInfo result = null;
|
if (Gateway == null)
|
{
|
result = new PanelSwitchLevelResponInfo { errorMessageBase = "当前没有网关" };
|
return result;
|
}
|
return await System.Threading.Tasks.Task.Run(async () =>
|
{
|
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 = Gateway.getGatewayBaseInfo.gwID };
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
|
|
if (temp == null)
|
{
|
result = new PanelSwitchLevelResponInfo { errorMessageBase = "网关错误回复,且数据是空" };
|
}
|
|
else
|
{
|
result = new PanelSwitchLevelResponInfo { errorResponData = temp, errorMessageBase = 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());
|
|
if (gatewayTemp.clientDataPassthroughResponseData == null)
|
{
|
result = new PanelSwitchLevelResponInfo { errorMessageBase = "网关返回的数据为空" };
|
}
|
else
|
{
|
if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null)
|
{
|
var data = gatewayTemp.clientDataPassthroughResponseData.PassData;
|
if (data.Length == 16)
|
{
|
var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
|
if (command == "0409")
|
{
|
var tempR = new PanelSaveEnergyModeInfo();
|
if (data[10].ToString() + data[11].ToString() == "01")
|
{
|
tempR.enable = true;
|
}
|
else
|
{
|
tempR.enable = false;
|
}
|
tempR.time = Convert.ToInt32(data[12].ToString() + data[13].ToString(), 16);
|
tempR.level = Convert.ToInt32(data[14].ToString() + data[15].ToString(), 16);
|
panelSaveEnergyModeInfo = tempR;
|
result = new PanelSwitchLevelResponInfo { panelSaveEnergyModeInfo = tempR };
|
System.Console.WriteLine($"UI收到通知后的主题_command:0408_{ topic}");
|
}
|
}
|
}
|
}
|
}
|
};
|
|
Gateway.Actions += action;
|
System.Console.WriteLine("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString());
|
|
try
|
{
|
var passData = SendPanelSaveEnergyModeData(reserve);
|
var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
|
var data = new JObject { { "PassData", passData } };
|
jObject.Add("Data", data);
|
Gateway.Send(("ClientDataPassthrough"), jObject.ToString());
|
}
|
catch { }
|
|
var dateTime = DateTime.Now;
|
while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
|
{
|
await System.Threading.Tasks.Task.Delay(10);
|
if (result != null)
|
{
|
break;
|
}
|
}
|
if ((DateTime.Now - dateTime).TotalMilliseconds > 9000)// WaitReceiveDataTime)
|
{
|
result = new PanelSwitchLevelResponInfo { errorMessageBase = " 回复超时,请重新操作" };
|
}
|
Gateway.Actions -= action;
|
System.Console.WriteLine("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString());
|
|
return result;
|
});
|
}
|
|
/// <summary>
|
/// 获取按键节能模式配置状态数据
|
/// </summary>
|
string SendPanelSaveEnergyModeData(string reserve)
|
{
|
string data = "";
|
string dataLength = "05";
|
string dataComand1 = "08";
|
string dataComand2 = "04";
|
string dataSerialNum = "01";
|
string addDataLength = "01";
|
string reserveData = reserve;
|
|
try
|
{
|
data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
|
reserveData;
|
}
|
catch { };
|
|
return data;
|
}
|
|
/// <summary>
|
/// 获取按键节能模式配置状态数据回复
|
/// </summary>
|
[System.Serializable]
|
public class PanelSwitchLevelResponInfo
|
{
|
/// <summary>
|
/// 错误信息
|
/// </summary>
|
public string errorMessageBase;
|
/// <summary>
|
/// 网关信息错误反馈
|
/// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
|
/// </summary>
|
public ErrorResponData errorResponData;
|
/// <summary>
|
/// 网关信息错误反馈
|
/// <para>获取按键节能模式配置状态数据</para>
|
/// </summary>
|
public PanelSaveEnergyModeInfo panelSaveEnergyModeInfo;
|
}
|
|
/// <summary>
|
/// 按键节能模式信息
|
/// </summary>
|
public PanelSaveEnergyModeInfo panelSaveEnergyModeInfo;
|
/// <summary>
|
/// 获取按键节能模式配置状态数据
|
/// </summary>
|
[System.Serializable]
|
public class PanelSaveEnergyModeInfo
|
{
|
/// <summary>
|
///false-disable true-enable
|
/// </summary>
|
public bool enable;
|
/// <summary>
|
///无操作进入节能模式时间(0-255 单位秒)
|
/// </summary>
|
public int time = -1;
|
|
/// <summary>
|
/// 节能模式亮度(0-100)
|
/// </summary>
|
public int level = -1;
|
}
|
#endregion
|
|
#region 配置按键指示灯睡眠组分(暂时不做)
|
///<summary >
|
///获取按键指示灯睡眠组
|
///<para>sleepGroup:睡眠组号</para>
|
/// </summary>
|
//public async System.Threading.Tasks.Task<PanelSleepGroupResponseAllData> GetPanelSleepGroupAsync(SleepGroup sleepGroup)
|
//{
|
// PanelSleepGroupResponseAllData result = null;
|
// if (Gateway == null)
|
// {
|
// result = new PanelSleepGroupResponseAllData { errorMessageBase = "当前没有网关" };
|
// return result;
|
// }
|
// return await System.Threading.Tasks.Task.Run(async () =>
|
// {
|
// 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 = Gateway.getGatewayBaseInfo.gwID };
|
// var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
|
|
// if (temp == null)
|
// {
|
// result = new PanelSleepGroupResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
|
// }
|
|
// else
|
// {
|
// result = new PanelSleepGroupResponseAllData { errorResponData = temp, errorMessageBase = 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());
|
|
// if (gatewayTemp.clientDataPassthroughResponseData == null)
|
// {
|
// result = new PanelSleepGroupResponseAllData { errorMessageBase = "网关返回的数据为空" };
|
// }
|
// else
|
// {
|
// if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null)
|
// {
|
// var data = gatewayTemp.clientDataPassthroughResponseData.PassData;
|
// if (data.Length == 14)
|
// {
|
// var tempR = new PanelSleepGroupResponseData();
|
// tempR.status = int.Parse(data[12].ToString() + data[13].ToString());
|
// switch (data[10].ToString() + data[11].ToString())
|
// {
|
// case "01":
|
// tempR.sleepGroupNum = SleepGroupNum.Group1;
|
// break;
|
// case "02":
|
// tempR.sleepGroupNum = SleepGroupNum.Group2;
|
// break;
|
// case "03":
|
// tempR.sleepGroupNum = SleepGroupNum.Group3;
|
// break;
|
// case "04":
|
// tempR.sleepGroupNum = SleepGroupNum.Group4;
|
// break;
|
// case "05":
|
// tempR.sleepGroupNum = SleepGroupNum.Group5;
|
// break;
|
// case "06":
|
// tempR.sleepGroupNum = SleepGroupNum.Group6;
|
// break;
|
// case "07":
|
// tempR.sleepGroupNum = SleepGroupNum.Group7;
|
// break;
|
// case "08":
|
// tempR.sleepGroupNum = SleepGroupNum.Group8;
|
// break;
|
// case "09":
|
// tempR.sleepGroupNum = SleepGroupNum.Group9;
|
// break;
|
// case "0a":
|
// tempR.sleepGroupNum = SleepGroupNum.Group10;
|
// break;
|
// case "0b":
|
// tempR.sleepGroupNum = SleepGroupNum.Group11;
|
// break;
|
// case "0c":
|
// tempR.sleepGroupNum = SleepGroupNum.Group12;
|
// break;
|
// case "0d":
|
// tempR.sleepGroupNum = SleepGroupNum.Group13;
|
// break;
|
// case "0e":
|
// tempR.sleepGroupNum = SleepGroupNum.Group14;
|
// break;
|
// case "0f":
|
// tempR.sleepGroupNum = SleepGroupNum.Group15;
|
// break;
|
// }
|
// result = new PanelSleepGroupResponseAllData { panelSleepGroupResponseData = tempR };
|
// }
|
// }
|
// System.Console.WriteLine($"UI收到通知后的主题_{ topic}");
|
// }
|
// }
|
// };
|
|
// Gateway.Actions += action;
|
// System.Console.WriteLine("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString());
|
|
// try
|
// {
|
// OpenPassthroughControl(Gateway);
|
// var passData = SetPanelSleepGroupData(sleepGroup);
|
// var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
|
// var data = new JObject { { "PassData", passData } };
|
// jObject.Add("Data", data);
|
// CurrentGateWayId = Gateway.getGatewayBaseInfo?.gwID;
|
// Gateway.Send(("ClientDataPassthrough"), jObject.ToString());
|
// }
|
// catch { }
|
|
// var dateTime = DateTime.Now;
|
// while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
|
// {
|
// await System.Threading.Tasks.Task.Delay(10);
|
// if (result != null)
|
// {
|
// break;
|
// }
|
// }
|
// if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
|
// {
|
// result = new PanelSleepGroupResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
|
// }
|
// Gateway.Actions -= action;
|
// System.Console.WriteLine("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString());
|
|
// return result;
|
// });
|
//}
|
|
///// <summary>
|
///// 绑定设备信息,网关反馈信息
|
///// </summary>
|
//public PanelSleepGroupResponseAllData panelSleepGroupResponseAllData;
|
//[System.Serializable]
|
//public class PanelSleepGroupResponseAllData
|
//{
|
// /// <summary>
|
// /// 错误信息
|
// /// </summary>
|
// public string errorMessageBase;
|
// /// <summary>
|
// /// 网关信息错误反馈
|
// /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
|
// /// </summary>
|
// public ErrorResponData errorResponData;
|
// /// <summary>
|
// /// 绑定设备信息
|
// /// </summary>
|
// public PanelSleepGroupResponseData panelSleepGroupResponseData;
|
//}
|
|
///// <summary>
|
///// 绑定设备信息,网关反馈信息
|
///// </summary>
|
//public PanelSleepGroupResponseData panelSleepGroupResponseData;
|
//[System.Serializable]
|
//public class PanelSleepGroupResponseData
|
//{
|
// /// <summary>
|
// /// 睡眠组号
|
// /// </summary>
|
// public SleepGroupNum sleepGroupNum;
|
// /// <summary>
|
// /// 状态
|
// /// <para>0--执行 1—唤醒</para>
|
// /// </summary>
|
// public int status;
|
//}
|
|
///// <summary>
|
///// 配置按键指示灯睡眠组分区
|
///// </summary>
|
//string SetPanelSleepGroupData(SleepGroup sleepGroup)
|
//{
|
// string data = "";
|
// string dataLength = "06";
|
// string dataComand1 = "0a";
|
// string dataComand2 = "04";
|
// string dataSerialNum = "01";
|
// string addDataLength = "02";
|
// int attributeData = 0;
|
|
// try
|
// {
|
// int bit0 = 0, bit1 = 0, bit2 = 0, bit3 = 0, bit4 = 0, bit5 = 0, bit6 = 0, bit7 = 0, bit8 = 0, bit9 = 0, bit10 = 0, bit11 = 0, bit12 = 0, bit13 = 0, bit14 = 0, bit15 = 0;
|
// if (sleepGroup != null)
|
// {
|
// if (sleepGroup.bit0)
|
// {
|
// bit0 = 1;
|
// }
|
// if (sleepGroup.bit1)
|
// {
|
// bit1 = 1;
|
// }
|
// if (sleepGroup.bit2)
|
// {
|
// bit2 = 1;
|
// }
|
// if (sleepGroup.bit3)
|
// {
|
// bit3 = 1;
|
// }
|
// if (sleepGroup.bit4)
|
// {
|
// bit4 = 1;
|
// }
|
// if (sleepGroup.bit5)
|
// {
|
// bit5 = 1;
|
// }
|
// if (sleepGroup.bit6)
|
// {
|
// bit6 = 1;
|
// }
|
// if (sleepGroup.bit7)
|
// {
|
// bit7 = 1;
|
// }
|
// if (sleepGroup.bit8)
|
// {
|
// bit8 = 1;
|
// }
|
// if (sleepGroup.bit9)
|
// {
|
// bit9 = 1;
|
// }
|
// if (sleepGroup.bit10)
|
// {
|
// bit10 = 1;
|
// }
|
// if (sleepGroup.bit11)
|
// {
|
// bit11 = 1;
|
// }
|
// if (sleepGroup.bit12)
|
// {
|
// bit12 = 1;
|
// }
|
// if (sleepGroup.bit13)
|
// {
|
// bit13 = 1;
|
// }
|
// if (sleepGroup.bit14)
|
// {
|
// bit14 = 1;
|
// }
|
// if (sleepGroup.bit15)
|
// {
|
// bit15 = 1;
|
// }
|
// attributeData = bit0 * 1 + bit1 * 2 + bit2 * 4 + bit3 * 8 + bit4 * 16 + bit5 * 32 + bit6 * 64 + bit7 * 128 + bit8 * 256 + bit9 * 512 + bit10 * 1024 + bit11 * 2048 + bit12 * 4096 + bit13 * 8192 + bit14 * 16384 + bit15 * 32768;
|
// }
|
// string tempAttributeData = attributeData.ToString("X4");
|
|
// if (sleepGroup != null)
|
// {
|
// data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
|
// tempAttributeData;
|
// }
|
// }
|
// catch { };
|
|
// return data;
|
//}
|
|
///// <summary>
|
///// 睡眠组号(可位或)
|
///// </summary>
|
//public class SleepGroup
|
//{
|
// /// <summary>
|
// /// false:关
|
// /// true:开
|
// /// </summary>
|
// public bool bit0;
|
// /// <summary>
|
// /// false:关
|
// /// true:开
|
// /// </summary>
|
// public bool bit1;
|
// /// <summary>
|
// /// false:关
|
// /// true:开
|
// /// </summary>
|
// public bool bit2;
|
// /// <summary>
|
// /// false:关
|
// /// true:开
|
// /// </summary>
|
// public bool bit3;
|
// /// <summary>
|
// /// false:关
|
// /// true:开
|
// /// </summary>
|
// public bool bit4;
|
// /// <summary>
|
// /// false:关
|
// /// true:开
|
// /// </summary>
|
// public bool bit5;
|
// /// <summary>
|
// /// false:关
|
// /// true:开
|
// /// </summary>
|
// public bool bit6;
|
// /// <summary>
|
// /// false:关
|
// /// true:开
|
// /// </summary>
|
// public bool bit7;
|
// /// <summary>
|
// /// false:关
|
// /// true:开
|
// /// </summary>
|
// public bool bit8;
|
// /// <summary>
|
// /// false:关
|
// /// true:开
|
// /// </summary>
|
// public bool bit9;
|
// /// <summary>
|
// /// false:关
|
// /// true:开
|
// /// </summary>
|
// public bool bit10;
|
// /// <summary>
|
// /// false:关
|
// /// true:开
|
// /// </summary>
|
// public bool bit11;
|
// /// <summary>
|
// /// false:关
|
// /// true:开
|
// /// </summary>
|
// public bool bit12;
|
// /// <summary>
|
// /// false:关
|
// /// true:开
|
// /// </summary>
|
// public bool bit13;
|
// /// <summary>
|
// /// false:关
|
// /// true:开
|
// /// </summary>
|
// public bool bit14;
|
// /// <summary>
|
// /// false:关
|
// /// true:开
|
// /// </summary>
|
// public bool bit15;
|
//}
|
|
///// <summary>
|
///// 执行按键指示灯睡眠组
|
///// </summary>
|
//public enum SleepGroupNum
|
//{
|
// Group1 = 1,
|
// Group2 = 2,
|
// Group3 = 3,
|
// Group4 = 4,
|
// Group5 = 5,
|
// Group6 = 6,
|
// Group7 = 7,
|
// Group8 = 8,
|
// Group9 = 9,
|
// Group10 = 10,
|
// Group11 = 11,
|
// Group12 = 12,
|
// Group13 = 13,
|
// Group14 = 14,
|
// Group15 = 15,
|
// Group16 = 16,
|
//}
|
#endregion
|
|
#region 配置面板功能
|
///<summary >
|
///配置面板功能
|
///<para>value:给面板配置的模式</para>
|
/// </summary>
|
public async System.Threading.Tasks.Task<SetWritableValueResponAllData> ConfigureHdlKeyValueAsync(KeyMode value, int clusterID = 6)
|
{
|
if (Gateway == null)
|
{
|
return null;
|
}
|
return await System.Threading.Tasks.Task.Run(async () =>
|
{
|
SetWritableValueResponAllData 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 = Gateway.getGatewayBaseInfo.gwID };
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
|
|
if (temp == null)
|
{
|
d = new SetWritableValueResponAllData { errorMessageBase = "网关错误回复,且数据是空" };
|
}
|
else
|
{
|
d = new SetWritableValueResponAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
|
}
|
}
|
|
if (topic == gatewayID + "/" + "SetWritableValue_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 = Gateway.getGatewayBaseInfo.gwID };
|
var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<SetWritableValueResponData>(jobject["Data"].ToString());
|
|
if (tempData == null)
|
{
|
d = new SetWritableValueResponAllData { errorMessageBase = "网关返回的数据为空" };
|
}
|
else
|
{
|
d = new SetWritableValueResponAllData { setWritableValueResponData = tempData };
|
System.Console.WriteLine($"UI收到通知后的主题_{ topic}");
|
}
|
}
|
};
|
Gateway.Actions += action;
|
System.Console.WriteLine("SetWritableValue_Actions 启动" + "_" + System.DateTime.Now.ToString());
|
try
|
{
|
var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", clusterID }, { "Command", 120 } };
|
var data = new JObject { { "Undivided", 0 }, { "AttributeId", 6533 }, { "AttributeDataType", 33 }, { "AttributeData", (int)value } };
|
jObject.Add("Data", data);
|
Gateway.Send("SetWritableValue", 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 SetWritableValueResponAllData { errorMessageBase = " 回复超时,请重新操作" };
|
}
|
Gateway.Actions -= action;
|
System.Console.WriteLine("SetWritableValue_Actions 退出" + System.DateTime.Now.ToString());
|
return d;
|
});
|
}
|
|
/// <summary>
|
/// 配置面板的功能模式
|
/// </summary>
|
public enum KeyMode
|
{
|
/// <summary>
|
/// 开关类型——开.
|
/// </summary>
|
Scene_Trigger = 1,
|
/// <summary>
|
/// 开关类型——开.
|
/// </summary>
|
OnOff_On = 100,
|
/// <summary>
|
/// 开关类型——关.
|
/// </summary>
|
OnOff_oFF = 101,
|
/// <summary>
|
/// 开关类型——取反.
|
/// </summary>
|
OnOff_OnOff = 102,
|
/// <summary>
|
/// 亮度类型——按等级调大.
|
/// </summary>
|
Level_Step_Up = 200,
|
/// <summary>
|
/// 亮度类型——按等级调小.
|
/// </summary>
|
Level_Step_Down = 201,
|
/// <summary>
|
/// 亮度类型——按等级取反.
|
/// </summary>
|
Level_Step_Up_Down = 202,
|
/// <summary>
|
/// 亮度类型——取反.
|
/// </summary>
|
Level_Up = 203,
|
/// <summary>
|
/// 亮度类型——取反.
|
/// </summary>
|
Level_Down = 204,
|
/// <summary>
|
/// 亮度类型——取反.
|
/// </summary>
|
Level_Up_Down = 205,
|
/// <summary>
|
/// 窗帘类型——开.
|
/// </summary>
|
Wcd_Up = 300,
|
/// <summary>
|
/// 窗帘类型——关.
|
/// </summary>
|
Wcd_Down = 301,
|
/// <summary>
|
/// 窗帘类型——停.
|
/// </summary>
|
Wcd_Stop = 302,
|
/// <summary>
|
/// 窗帘类型——上升停止.
|
/// </summary>
|
Wcd_Up_Stop = 303,
|
/// <summary>
|
/// 窗帘类型——下降停止.
|
/// </summary>
|
Wcd_Down_Stop = 304,
|
/// <summary>
|
/// 窗帘类型——下降停止.
|
/// </summary>
|
Default = 65535,
|
}
|
#endregion
|
|
/// <summary>
|
///读取面板的配置信息
|
/// </summary>
|
public void ReadPanelSupportAttribute()
|
{
|
ReadAttri(Device.Cluster_ID.HdlKey, AttriButeId.HdlKey);
|
}
|
|
#region 读取面板的配置信息
|
/// <summary>
|
/// 读取面板的配置信息
|
/// </summary>
|
public async System.Threading.Tasks.Task<PanelConfigureInfoResponAllData> ReadPanelConfigureInfoAsync(params int[] args)
|
{
|
if (Gateway == null)
|
{
|
return null;
|
}
|
return await System.Threading.Tasks.Task.Run(async () =>
|
{
|
PanelConfigureInfoResponAllData d = null;
|
Action<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];//网关返回的网关ID
|
var reportStatus = topic.Split('/')[1];//主题为设备上报的主题
|
string addr = "";//上报的设备addr
|
string epoint = "";//上报的设备epoint
|
string cluID = "";//上报的设备cluID
|
string attrId = "";//上报的设备attrId
|
if (reportStatus == "DeviceStatusReport")
|
{
|
addr = topic.Split('/')[2];
|
epoint = topic.Split('/')[3];
|
cluID = topic.Split('/')[4];
|
attrId = topic.Split('/')[5];
|
}
|
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 = Gateway.getGatewayBaseInfo.gwID };
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
|
|
if (temp == null)
|
{
|
d = new PanelConfigureInfoResponAllData { errorMessageBase = "网关错误回复,且数据是空" };
|
}
|
else
|
{
|
d = new PanelConfigureInfoResponAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
|
}
|
}
|
else 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 lightSwitch = new Panel { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId };
|
lightSwitch.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.DeviceStatusReportData>(jobject["Data"].ToString());
|
if ((DeviceType)(deviceID) == DeviceType.OnOffSwitch)
|
{
|
var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel.DeviceStatusReportData>(jobject["Data"].ToString());
|
if (tempData == null)
|
{
|
d = new PanelConfigureInfoResponAllData { errorMessageBase = "网关错误回复,且数据是空" };
|
}
|
else
|
{
|
d = new PanelConfigureInfoResponAllData { deviceStatusReportData = tempData };
|
System.Console.WriteLine($"UI收到通知后的主题_{ topic}");
|
}
|
}
|
}
|
};
|
|
Gateway.Actions += action;
|
System.Console.WriteLine("GetDeviceStatus_Actions 启动" + System.DateTime.Now.ToString());
|
|
try
|
{
|
var JObject = new JObject {
|
{ "DeviceAddr",DeviceAddr },
|
{ "Epoint", DeviceEpoint },
|
{ "Cluster_ID", (int)Device.Cluster_ID.HdlKey },
|
{ "Command", 108 }
|
};
|
var attriBute = new JArray{
|
new JObject {
|
{ "AttriButeId", (int)AttriButeId.HdlKey}
|
}
|
};
|
var data = new JObject { { "AttriBute", attriBute } };
|
JObject.Add("Data", data);
|
Gateway?.Send(("GetDeviceStatus"), 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 PanelConfigureInfoResponAllData { errorMessageBase = " 回复超时,请重新操作" };
|
}
|
Gateway.Actions -= action;
|
System.Console.WriteLine("GetDeviceStatus_Actions 退出" + System.DateTime.Now.ToString());
|
|
return d;
|
});
|
}
|
|
/// <summary>
|
/// 网关恢复出厂设置返回数据
|
/// </summary>
|
[System.Serializable]
|
public class PanelConfigureInfoResponAllData
|
{
|
/// <summary>
|
/// 错误信息
|
/// </summary>
|
public string errorMessageBase;
|
/// <summary>
|
/// 网关信息错误反馈
|
/// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
|
/// </summary>
|
public ErrorResponData errorResponData;
|
///<summary >
|
///设备数据
|
/// </summary>
|
public DeviceStatusReportData deviceStatusReportData;
|
}
|
#endregion
|
|
//#region 设备绑定
|
///// <summary>
|
/////设备绑定
|
///// </summary>
|
//public async System.Threading.Tasks.Task<AddedDeviceBindResponseAllData> AddDeviceBindAsync(AddBindData addBindData)
|
//{
|
// return await System.Threading.Tasks.Task.Run(async () =>
|
// {
|
// var result = new AddedDeviceBindResponseAllData();
|
// var mainGateway = ZbGateway.MainGateWay;
|
// if (mainGateway == null)
|
// {
|
// result.errorMessageBase = "当前没有主网关";
|
// return result;
|
// }
|
// Action<string, string> action = (topic, message) =>
|
// {
|
// System.Console.WriteLine($"UI收到通知后的主题_{ topic}");
|
// 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 = mainGateway.getGatewayBaseInfo.gwID };
|
// var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
|
|
// if (temp == null)
|
// {
|
// result.errorMessageBase = "网关错误回复,且数据是空";
|
// }
|
// else
|
// {
|
// result.errorResponData = temp;
|
// result.errorMessageBase = ErrorMess(temp.Error);
|
// }
|
// }
|
// else if (topic == gatewayID + "/" + "Bind/SetBind_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 = mainGateway.getGatewayBaseInfo.gwID };
|
// //var tempBindName = Newtonsoft.Json.JsonConvert.DeserializeObject<string>(jobject["Data"]["BindName"].ToString());
|
// var tempBindList = Newtonsoft.Json.Linq.JArray.Parse(jobject["Data"]["BindList"].ToString());
|
// if (tempBindList == null)
|
// {
|
// result.errorMessageBase = "网关返回的数据为空";
|
// }
|
// else
|
// {
|
// var dataBindRes = new AddedDeviceBindResponseData();
|
// for (int m = 0; tempBindList != null && m < tempBindList.Count; m++)
|
// {
|
// var tempBind = tempBindList[m];
|
// dataBindRes.BindList.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<AddBindListResponseObj>(tempBind.ToString()));
|
// }
|
// if (dataBindRes != null)
|
// {
|
// result.addedDeviceBindResponseData = dataBindRes;
|
// System.Console.WriteLine($"UI收到通知后的主题_{topic}");
|
// }
|
// }
|
// }
|
// else if (topic == gatewayID + "/" + "Bind/BindResult")
|
// {
|
// 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 = mainGateway.getGatewayBaseInfo.gwID };
|
// var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<AddBindResultResponseData>(jobject["Data"].ToString());
|
|
// if (tempData != null)
|
// {
|
// result.addBindResultResponseData = tempData;
|
// }
|
// }
|
// };
|
// mainGateway.Actions += action;
|
// System.Console.WriteLine("Bind/SetBind_Actions 启动" + "_" + System.DateTime.Now.ToString());
|
// try
|
// {
|
// if (addBindData != null)
|
// {
|
// var jObject = new JObject { { "DeviceAddr", addBindData.DeviceAddr }, { "Epoint", addBindData.Epoint }, { "Cluster_ID", 0 }, { "Command", 5001 } };
|
// var bindList = new JArray { };
|
// foreach (var bindInfo in addBindData.BindList)
|
// {
|
// if (bindInfo.BindType == 0)
|
// {
|
// var dInfo = new JObject{
|
// { "BindMacAddr",bindInfo.BindMacAddr},
|
// { "BindEpoint", bindInfo.BindEpoint} ,
|
// { "BindCluster", bindInfo.BindCluster} ,
|
// { "BindType",bindInfo.BindType}
|
// };
|
// bindList.Add(dInfo);
|
// }
|
// else if (bindInfo.BindType == 1)
|
// {
|
// var dInfo = new JObject{
|
// { "BindCluster", bindInfo.BindCluster} ,
|
// { "BindType",bindInfo.BindType},
|
// { "BindScenesId", bindInfo.BindScenesId}
|
// };
|
// bindList.Add(dInfo);
|
// }
|
// }
|
// var data = new JObject{
|
// {"BindName",addBindData.BindName},
|
// { "BindList", bindList }
|
// };
|
// jObject.Add("Data", data);
|
// mainGateway.Send("Bind/SetBind", jObject.ToString());
|
// }
|
// }
|
// catch
|
// {
|
// }
|
|
// var dateTime = DateTime.Now;
|
// while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
|
// {
|
// await System.Threading.Tasks.Task.Delay(100);
|
// if (result == null || result.addedDeviceBindResponseData == null)
|
// {
|
// continue;
|
// }
|
// if (0 < result.addedDeviceBindResponseData.BindList.FindAll((obj) => obj.BindType == 0).Count)
|
// {
|
// if (result.addBindResultResponseData != null)
|
// {
|
// break;
|
// }
|
// }
|
// else
|
// {
|
// break;
|
// }
|
// }
|
// if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
|
// {
|
// result.errorMessageBase = " 回复超时,请重新操作";
|
// }
|
// mainGateway.Actions -= action;
|
// System.Console.WriteLine($"Bind/SetBind_Actions 退出 {System.DateTime.Now}");
|
// return result;
|
// });
|
//}
|
|
///// <summary>
|
///// 绑定设备信息,网关反馈信息
|
///// </summary>
|
//public AddedDeviceBindResponseAllData addedDeviceBindResponseAllData;
|
//[System.Serializable]
|
//public class AddedDeviceBindResponseAllData
|
//{
|
// /// <summary>
|
// /// 错误信息
|
// /// </summary>
|
// public string errorMessageBase;
|
// /// <summary>
|
// /// 网关信息错误反馈
|
// /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
|
// /// </summary>
|
// public ErrorResponData errorResponData;
|
// /// <summary>
|
// /// 网关直接反馈绑定设备信息
|
// /// </summary>
|
// public AddedDeviceBindResponseData addedDeviceBindResponseData;
|
// /// <summary>
|
// /// 按键设备的确认反馈绑定设备信息
|
// /// </summary>
|
// public AddBindResultResponseData addBindResultResponseData;
|
//}
|
|
///// <summary>
|
///// 绑定设备信息
|
///// </summary>
|
//public AddedDeviceBindResponseData addedDeviceBindResponseData;
|
//[System.Serializable]
|
//public class AddedDeviceBindResponseData
|
//{
|
// /// <summary>
|
// ///绑定名称
|
// /// </summary>
|
// public string BindName;
|
// /// <summary>
|
// ///绑定列表 ,当Status=0时存在
|
// /// </summary>
|
// public List<AddBindListResponseObj> BindList = new List<AddBindListResponseObj>();
|
//}
|
|
///// <summary>
|
///// 绑定列表的信息
|
///// </summary>
|
//[System.Serializable]
|
//public class AddBindListResponseObj : BindListResponseObj
|
//{
|
// /// <summary>
|
// /// 0:加入成功(该状态只适用用于跨网关绑定和绑定场景。同网关设备间的绑定需要节点设备的确认成功信息,不会直接反馈成功。)
|
// ///<para>1:失败,节点设备或场景不存在。</para>
|
// ///<para>2:未知,由节点设备反馈发送“Bind/BindResult”主题消息确定是否成功。</para>
|
// ///<para>3:绑定已经存在。</para>
|
// /// </summary>
|
// public int Result;
|
//}
|
|
///// <summary>
|
///// 按键设备的确认的信息
|
///// </summary>
|
//[System.Serializable]
|
//public class AddBindResultResponseData
|
//{
|
// /// <summary>
|
// ///绑定结果
|
// ///<para>0:成功</para>
|
// ///<para>140:失败,控制设备的绑定列表已满</para>
|
// ///<para>其他:失败</para>
|
// /// </summary>
|
// public int Result;
|
// /// <summary>
|
// /// 绑定的cluster
|
// /// </summary>
|
// public int BindCluster;
|
// /// <summary>
|
// /// 绑定设备Mac地址, 当BindType=0时存在
|
// /// </summary>
|
// public string BindMacAddr;
|
// /// <summary>
|
// /// 绑定设备的端口号,当BindType=0时存在
|
// /// </summary>
|
// public int BindEpoint;
|
// /// <summary>
|
// /// 绑定场景,当BindType=2时存在
|
// /// </summary>
|
// public int BindScenesId;
|
// /// <summary>
|
// /// 绑定设备的名称
|
// /// </summary>
|
// public string DeviceName;
|
//}
|
|
///// <summary>
|
///// 绑定设备的数据
|
///// </summary>
|
//public AddBindData addBindData;
|
//[System.Serializable]
|
//public class AddBindData
|
//{
|
// /// <summary>
|
// /// 控制设备节点的mac地址
|
// /// </summary>
|
// public string DeviceAddr;
|
// /// <summary>
|
// /// 错误信息
|
// /// </summary>
|
// public int Epoint;
|
// /// <summary>
|
// ///绑定名称,不修改名称时忽略该选项
|
// /// </summary>
|
// public string BindName;
|
// /// <summary>
|
// ///绑定列表,不修改绑定列表时忽略该选项。
|
// /// </summary>
|
// public List<AddBindListObj> BindList = new List<AddBindListObj>();
|
//}
|
|
///// <summary>
|
///// 控制设备绑定的信息
|
///// </summary>
|
//[System.Serializable]
|
//public class AddBindListObj
|
//{
|
// /// <summary>
|
// /// 绑定类型
|
// ///<para>0:绑定设备 </para>
|
// ///<para>1:绑定场景</para>
|
// /// </summary>
|
// public int BindType;
|
// /// <summary>
|
// /// 绑定的cluster,需要控制设备的OutCluster列表中存在该cluster。
|
// ///如绑定某个设备的on/off,为6。
|
// /// </summary>
|
// public int BindCluster;
|
// /// <summary>
|
// /// 绑定设备Mac地址, 当BindType=0时存在
|
// /// </summary>
|
// public string BindMacAddr;
|
// /// <summary>
|
// /// 绑定设备的端口号,当BindType=0时存在
|
// /// </summary>
|
// public int BindEpoint;
|
// /// <summary>
|
// /// 绑定场景,当BindType=1时存在
|
// /// </summary>
|
// public int BindScenesId;
|
//}
|
//#endregion
|
|
//#region 解除绑定
|
///// <summary>
|
///// 解除绑定
|
///// </summary>
|
//public async System.Threading.Tasks.Task<DelDeviceBindResponseAllData> DelDeviceBindAsync(DelDeviceBindData delDeviceBindData)
|
//{
|
// return await System.Threading.Tasks.Task.Run(async () =>
|
// {
|
// var responseData = new DelDeviceBindResponseAllData();
|
// var mainGateway = ZbGateway.MainGateWay;
|
// if (mainGateway == null)
|
// {
|
// responseData.errorMessageBase = "当前没有主网关";
|
// return responseData;
|
// }
|
|
// 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 = mainGateway.getGatewayBaseInfo.gwID };
|
// var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
|
|
// if (temp == null)
|
// {
|
// responseData.errorMessageBase = "网关错误回复,且数据是空";
|
// }
|
// else
|
// {
|
// responseData.errorResponData = temp;
|
// responseData.errorMessageBase = ErrorMess(temp.Error);
|
// }
|
// }
|
|
// if (topic == gatewayID + "/" + "Bind/RemoveBind_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 = Gateway.getGatewayBaseInfo.gwID };
|
// var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<DelDeviceBindResponseData>(jobject["Data"].ToString());
|
|
// if (tempData == null)
|
// {
|
// responseData.errorMessageBase = "网关返回的数据为空";
|
|
// }
|
// else
|
// {
|
// responseData.delDeviceBindResponseData = tempData;
|
// System.Console.WriteLine($"UI收到通知后的主题_{ topic}");
|
// }
|
// }
|
|
// if (topic == gatewayID + "/" + "Bind/RemoveBindResult")
|
// {
|
// 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 = mainGateway.getGatewayBaseInfo.gwID };
|
// var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<RemoveBindResultResponseData>(jobject["Data"].ToString());
|
|
// if (tempData != null)
|
// {
|
// responseData.removeBindResultResponseData = tempData;
|
// System.Console.WriteLine($"UI收到通知后的主题_{ topic}");
|
// }
|
// }
|
// };
|
// mainGateway.Actions += action;
|
// System.Console.WriteLine("DeviceBind/DelBind_Actions 启动" + "_" + System.DateTime.Now.ToString());
|
// try
|
// {
|
// if (delDeviceBindData != null)
|
// {
|
// var jObject = new JObject { { "DeviceAddr", delDeviceBindData.DeviceAddr }, { "Epoint", delDeviceBindData.Epoint }, { "Cluster_ID", 0 }, { "Command", 5003 } };
|
// var removeBindList = new JArray { };
|
// foreach (var removeBindInfo in delDeviceBindData.RemoveBindList)
|
// {
|
// if (removeBindInfo.BindType == 0)
|
// {
|
// var dInfo = new JObject{
|
// { "BindMacAddr",removeBindInfo.BindMacAddr},
|
// { "BindEpoint", removeBindInfo.BindEpoint} ,
|
// { "BindCluster", removeBindInfo.BindCluster} ,
|
// { "BindType",removeBindInfo.BindType}
|
// };
|
// removeBindList.Add(dInfo);
|
// }
|
// else if (removeBindInfo.BindType == 1)
|
// {
|
// var dInfo = new JObject{
|
// { "BindCluster", removeBindInfo.BindCluster} ,
|
// { "BindType",removeBindInfo.BindType},
|
// { "BindScenesId", removeBindInfo.BindScenesId}
|
// };
|
// removeBindList.Add(dInfo);
|
// }
|
// }
|
// var data = new JObject {
|
// {"RemoveBindList",removeBindList}
|
// };
|
// jObject.Add("Data", data);
|
// mainGateway.Send("Bind/RemoveBind", jObject.ToString());
|
// }
|
// }
|
// catch { }
|
|
|
// var dateTime = DateTime.Now;
|
// while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
|
// {
|
// await System.Threading.Tasks.Task.Delay(100);
|
// if (responseData == null || responseData.delDeviceBindResponseData == null)
|
// {
|
// continue;
|
// }
|
// if (0 < responseData.delDeviceBindResponseData.RemoveBindList.FindAll((obj) => obj.BindType == 0).Count)
|
// {
|
// if (responseData.removeBindResultResponseData != null)
|
// {
|
// break;
|
// }
|
// }
|
// else
|
// {
|
// break;
|
// }
|
// }
|
|
// if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
|
// {
|
// responseData.errorMessageBase = "回复超时,请重新操作";
|
// }
|
// mainGateway.Actions -= action;
|
// System.Console.WriteLine("DeviceBind/DelBind_Actions 退出" + System.DateTime.Now.ToString());
|
|
// return responseData;
|
// });
|
//}
|
|
///// <summary>
|
/////解除绑定数据,网关反馈信息
|
///// </summary>
|
//public DelDeviceBindResponseAllData delDeviceBindResponseAllData;
|
///// <summary>
|
/////解除绑定数据,网关反馈信息
|
///// </summary>
|
//[System.Serializable]
|
//public class DelDeviceBindResponseAllData
|
//{
|
// /// <summary>
|
// /// 错误信息
|
// /// </summary>
|
// public string errorMessageBase;
|
// /// <summary>
|
// /// 网关信息错误反馈
|
// /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
|
// /// </summary>
|
// public ErrorResponData errorResponData;
|
// /// <summary>
|
// /// 解除绑定数据信息
|
// /// </summary>
|
// public DelDeviceBindResponseData delDeviceBindResponseData;
|
|
// /// <summary>
|
// /// 解除绑定按键确认数据信息
|
// /// </summary>
|
// public RemoveBindResultResponseData removeBindResultResponseData;
|
//}
|
|
///// <summary>
|
///// 解除绑定数据
|
///// </summary>
|
//public DelDeviceBindResponseData delDeviceBindResponseData;
|
///// <summary>
|
///// 解除绑定数据
|
///// </summary>
|
//[System.Serializable]
|
//public class DelDeviceBindResponseData
|
//{
|
// /// <summary>
|
// ///绑定列表 ,当Status=0时存在
|
// /// </summary>
|
// public List<RemoveBindListResponseObj> RemoveBindList = new List<RemoveBindListResponseObj>();
|
//}
|
|
///// <summary>
|
///// 移除设备绑定的信息
|
///// </summary>
|
//[System.Serializable]
|
//public class RemoveBindListResponseObj : BindListResponseObj
|
//{
|
// /// <summary>
|
// /// 0:移除成功(该状态只适用用于跨网关绑定、绑定场景、失效设备(设备已经从网关的设备列表中删除)。同网关设备间的解除绑定需要节点设备的确认成功信息,不会直接反馈成功。)
|
// ///<para>1:失败,设备不在绑定列表中</para>
|
// ///<para>3:失败,在等待节点设备确认是否解除绑定成功(当网关还在等待某节点设备确认是否解除绑定成功的反馈信息时,客户端再次发送解除绑定该节点设备的指令,将反馈该状态。)</para>
|
// ///<para>4:未知,由节点设备反馈发送“Bind/RemoveBindResult”主题消息确定是否成功。</para>
|
// /// </summary>
|
// public int Result;
|
|
//}
|
|
///// <summary>
|
///// 移除设备绑定按键确认的信息
|
///// </summary>
|
//[System.Serializable]
|
//public class RemoveBindResultResponseData
|
//{
|
// /// <summary>
|
// ///绑定结果
|
// ///<para>0:成功</para>
|
// ///<para>136:控制设备本地绑定列表中无此绑定</para>
|
// ///<para>其他:失败</para>
|
// /// </summary>
|
// public int Result;
|
|
// /// <summary>
|
// /// 绑定设备Mac地址
|
// /// </summary>
|
// public string BindMacAddr;
|
// /// <summary>
|
// /// 绑定设备的端口号
|
// /// </summary>
|
// public int BindEpoint;
|
// /// <summary>
|
// /// 绑定的cluster
|
// /// </summary>
|
// public int BindCluster;
|
// /// <summary>
|
// /// 绑定设备名称
|
// /// </summary>
|
// public string DeviceName;
|
//}
|
|
///// <summary>
|
///// 解除绑定数据
|
///// </summary>
|
//public DelDeviceBindData delDeviceBindData;
|
///// <summary>
|
///// 解除绑定数据
|
///// </summary>
|
//[System.Serializable]
|
//public class DelDeviceBindData
|
//{
|
// /// <summary>
|
// /// 控制设备节点的mac地址
|
// /// </summary>
|
// public string DeviceAddr;
|
// /// <summary>
|
// /// 错误信息
|
// /// </summary>
|
// public int Epoint;
|
// /// <summary>
|
// ///绑定列表 ,当Status=0时存在
|
// /// </summary>
|
// public List<RemoveBindListObj> RemoveBindList = new List<RemoveBindListObj>();
|
//}
|
|
///// <summary>
|
///// 移除设备绑定的信息
|
///// </summary>
|
//[System.Serializable]
|
//public class RemoveBindListObj
|
//{
|
|
// /// <summary>
|
// /// 绑定类型
|
// ///<para>0:移除设备 </para>
|
// ///<para>1:移除场景</para>
|
// /// </summary>
|
// public int BindType;
|
// /// <summary>
|
// /// 绑定的cluster
|
// /// </summary>
|
// public int BindCluster;
|
// /// <summary>
|
// /// 绑定设备Mac地址, 当BindType=0时存在
|
// /// </summary>
|
// public string BindMacAddr;
|
// /// <summary>
|
// /// 绑定设备的端口号,当BindType=0时存在
|
// /// </summary>
|
// public int BindEpoint;
|
// /// <summary>
|
// /// 绑定场景,当BindType=1时存在
|
// /// </summary>
|
// public int BindScenesId;
|
//}
|
//#endregion
|
|
//#region 获取所有绑定
|
///// <summary>
|
/////获取所有绑定
|
///// </summary>
|
//public async System.Threading.Tasks.Task<GetDeviceBindResponseAllData> GetDeviceBindAsyncAsync()
|
//{
|
// return await System.Threading.Tasks.Task.Run(async () =>
|
// {
|
// GetDeviceBindResponseAllData d = null;
|
// var mainGateway = ZbGateway.MainGateWay;
|
// if (mainGateway == null)
|
// {
|
// d = new GetDeviceBindResponseAllData { errorMessageBase = "当前没有主网关" };
|
// return d;
|
// }
|
|
// 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 = mainGateway.getGatewayBaseInfo.gwID };
|
// var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
|
|
// if (temp == null)
|
// {
|
// d = new GetDeviceBindResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
|
// }
|
// else
|
// {
|
// d = new GetDeviceBindResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
|
// }
|
// }
|
|
// if (topic == gatewayID + "/" + "Bind/GetDeviceBind_Respon")
|
// {
|
// var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID };
|
// var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<GetDeviceBindResponseData>(jobject["Data"].ToString());
|
// //var tempBindList = Newtonsoft.Json.Linq.JArray.Parse(jobject["Data"]["BindList"].ToString());
|
// if (tempData == null)
|
// {
|
// d = new GetDeviceBindResponseAllData { errorMessageBase = "网关返回的数据为空" };
|
// }
|
// else
|
// {
|
// d = new GetDeviceBindResponseAllData { getAllBindResponseData = tempData };
|
// System.Console.WriteLine($"UI收到通知后的主题_{ topic}");
|
// }
|
// }
|
// };
|
// mainGateway.Actions += action;
|
|
// try
|
// {
|
// System.Console.WriteLine("Bind/GetDeviceBind_Actions 启动" + "_" + System.DateTime.Now.ToString());
|
// var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 0 }, { "Command", 5007 } };
|
// mainGateway.Send("Bind/GetDeviceBind", 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 GetDeviceBindResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
|
// }
|
// mainGateway.Actions -= action;
|
// System.Console.WriteLine("Bind/GetDeviceBind_Actions 退出" + System.DateTime.Now.ToString());
|
|
// return d;
|
// });
|
//}
|
|
///// <summary>
|
/////获取所有绑定数据,网关反馈信息
|
///// </summary>
|
//public GetDeviceBindResponseAllData getAllBindResponseAllData;
|
//[System.Serializable]
|
//public class GetDeviceBindResponseAllData
|
//{
|
// /// <summary>
|
// /// 错误信息
|
// /// </summary>
|
// public string errorMessageBase;
|
// /// <summary>
|
// /// 网关信息错误反馈
|
// /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
|
// /// </summary>
|
// public ErrorResponData errorResponData;
|
// /// <summary>
|
// /// 控制设备绑定的设备列表回复数据
|
// /// </summary>
|
// public GetDeviceBindResponseData getAllBindResponseData;
|
//}
|
|
///// <summary>
|
///// 获取所有绑定回复的数据
|
///// </summary>
|
//public GetDeviceBindResponseData getAllBindResponseData;
|
//[System.Serializable]
|
//public class GetDeviceBindResponseData
|
//{
|
// /// <summary>
|
// /// 0:成功
|
// ///<para>1:绑定不存在</para>
|
// /// </summary>
|
// public int Result;
|
// /// <summary>
|
// /// 绑定列表 ,当Status=0时存在。
|
// /// </summary>
|
// public List<BindListResponseObj> BindList = new List<BindListResponseObj>();
|
//}
|
|
///// <summary>
|
///// 获取所有绑定的信息
|
///// </summary>
|
//public class BindListResponseObj
|
//{
|
// /// <summary>
|
// /// 绑定类型
|
// ///<para>0:移除设备,同网关设备间的移除</para>
|
// ///<para>1:移除设备,跨网关设备间的移除</para>
|
// ///<para>2:移除绑定场景</para>
|
// /// </summary>
|
// public int BindType;
|
// /// <summary>
|
// /// 绑定的cluster
|
// /// </summary>
|
// public int BindCluster;
|
// /// <summary>
|
// /// 绑定设备Mac地址, 当BindType=0时存在
|
// /// </summary>
|
// public string BindMacAddr;
|
// /// <summary>
|
// /// 绑定设备的端口号,当BindType=0时存在
|
// /// </summary>
|
// public int BindEpoint;
|
// /// <summary>
|
// /// 绑定场景,当BindType=1时存在
|
// /// </summary>
|
// public int BindScenesId;
|
// /// <summary>
|
// /// 绑定的设备或场景名称
|
// /// </summary>
|
// public string ESName;
|
//}
|
//#endregion
|
|
//#region 删除一个控制设备所有绑定信息
|
///// <summary>
|
/////删除一个控制设备所有绑定信息
|
///// </summary>
|
//public async System.Threading.Tasks.Task<ClearBindInfoResponseAllData> ClearBindInfoAsync()
|
//{
|
// if (Gateway == null)
|
// {
|
// return null;
|
// }
|
// return await System.Threading.Tasks.Task.Run(async () =>
|
// {
|
// ClearBindInfoResponseAllData 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 = Gateway.getGatewayBaseInfo.gwID };
|
// var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
|
|
// if (temp == null)
|
// {
|
// d = new ClearBindInfoResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
|
// }
|
// else
|
// {
|
// d = new ClearBindInfoResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
|
// }
|
// }
|
|
// if (topic == gatewayID + "/" + "Bind/ClearBindInfo_Respon")
|
// {
|
// var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
|
// var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClearBindInfoResponseData>(jobject["Data"].ToString());
|
// if (tempData == null)
|
// {
|
// d = new ClearBindInfoResponseAllData { errorMessageBase = "网关返回的数据为空" };
|
// }
|
// else
|
// {
|
// d = new ClearBindInfoResponseAllData { clearBindInfoResponseData = tempData };
|
// System.Console.WriteLine($"UI收到通知后的主题_{ topic}");
|
// }
|
// }
|
// };
|
// Gateway.Actions += action;
|
// System.Console.WriteLine("Bind/ClearBindInfo_Actions 启动" + "_" + System.DateTime.Now.ToString());
|
|
// try
|
// {
|
// var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 0 }, { "Command", 5006 } };
|
// Gateway.Send("Bind/ClearBindInfo", 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 ClearBindInfoResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
|
// }
|
// Gateway.Actions -= action;
|
// System.Console.WriteLine("Bind/ClearBindInfo_Actions 退出" + System.DateTime.Now.ToString());
|
|
// return d;
|
// });
|
//}
|
|
///// <summary>
|
/////删除一个控制设备所有绑定数据,网关反馈信息
|
///// </summary>
|
//public ClearBindInfoResponseAllData clearBindInfoResponseAllData;
|
//[System.Serializable]
|
//public class ClearBindInfoResponseAllData
|
//{
|
// /// <summary>
|
// /// 错误信息
|
// /// </summary>
|
// public string errorMessageBase;
|
// /// <summary>
|
// /// 网关信息错误反馈
|
// /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
|
// /// </summary>
|
// public ErrorResponData errorResponData;
|
// /// <summary>
|
// /// 控制设备绑定的设备列表回复数据
|
// /// </summary>
|
// public ClearBindInfoResponseData clearBindInfoResponseData;
|
//}
|
|
///// <summary>
|
///// 删除一个控制设备所有绑定信息回复的数据
|
///// </summary>
|
//public ClearBindInfoResponseData clearBindInfoResponseData;
|
//[System.Serializable]
|
//public class ClearBindInfoResponseData
|
//{
|
// /// <summary>
|
// /// 0:成功
|
// ///<para>1:绑定信息不存在</para>
|
// /// </summary>
|
// public int Result;
|
//}
|
|
//#endregion
|
|
/// <summary>
|
/// 读取面板的配置信息(信息存到当前的对象具体值中)
|
/// </summary>
|
//public void ReadPanelConfigureInfo()
|
//{
|
// ReadAttri(Device.Cluster_ID.HdlKey, AttriButeId.HdlKey);
|
//}
|
|
//#region 获取所有做了绑定的控制设备
|
///// <summary>
|
/////获取所有做了绑定的控制设备
|
///// </summary>
|
//public async System.Threading.Tasks.Task<GetControlDeviceBindResponseAllData> GetControlDeviceAsync()
|
//{
|
// if (Gateway == null)
|
// {
|
// return null;
|
// }
|
// return await System.Threading.Tasks.Task.Run(async () =>
|
// {
|
// var d = new GetControlDeviceBindResponseAllData { };
|
// 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 = Gateway.getGatewayBaseInfo.gwID };
|
// var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
|
|
// if (temp == null)
|
// {
|
// d.errorMessageBase = "网关错误回复,且数据是空";
|
// }
|
// else
|
// {
|
// d.errorResponData = temp;
|
// d.errorMessageBase = ErrorMess(temp.Error);
|
// }
|
// }
|
|
// if (topic == gatewayID + "/" + "DeviceBind_AddBind_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 = Gateway.getGatewayBaseInfo.gwID };
|
// var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<GetControlDeviceBindResponseData>(jobject["Data"].ToString());
|
|
// if (tempData == null)
|
// {
|
// d.errorMessageBase = "网关返回的数据为空";
|
// }
|
// else
|
// {
|
// d.getControlDeviceBindResponseData = tempData;
|
// }
|
// }
|
// };
|
// Gateway.Actions += action;
|
// System.Console.WriteLine("GetControlDevice_Actions 启动" + "_" + Gateway.getGatewayBaseInfo.gwID + System.DateTime.Now.ToString());
|
|
// var jObject = new JObject {{ "Cluster_ID", 0 }, { "Command", 154 } };
|
// Gateway.Send("DeviceBind/GetControlDevice", jObject.ToString());
|
|
// var dateTime = DateTime.Now;
|
// while ((DateTime.Now - dateTime).TotalMilliseconds < 1000)
|
// {
|
// await System.Threading.Tasks.Task.Delay(10);
|
// if (d.getControlDeviceBindResponseData != null)
|
// {
|
// break;
|
// }
|
// }
|
// if ((DateTime.Now - dateTime).TotalMilliseconds > 10000)
|
// {
|
// d.errorMessageBase = " 回复超时,请重新操作";
|
// }
|
// Gateway.Actions -= action;
|
// System.Console.WriteLine("GetControlDevice_Actions 退出" + System.DateTime.Now.ToString());
|
|
// return d;
|
// });
|
//}
|
|
///// <summary>
|
///// 获取所有做了绑定的控制设备数据,网关反馈信息
|
///// </summary>
|
//public GetControlDeviceBindResponseAllData getControlDeviceBindResponseAllData;
|
//[System.Serializable]
|
//public class GetControlDeviceBindResponseAllData
|
//{
|
// /// <summary>
|
// /// 错误信息
|
// /// </summary>
|
// public string errorMessageBase;
|
// /// <summary>
|
// /// 网关信息错误反馈
|
// /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
|
// /// </summary>
|
// public ErrorResponData errorResponData;
|
// /// <summary>
|
// /// 获取所有做了绑定的控制设备数据
|
// /// </summary>
|
// public GetControlDeviceBindResponseData getControlDeviceBindResponseData;
|
//}
|
|
|
///// <summary>
|
///// 获取所有做了绑定的控制设备数据
|
///// </summary>
|
//public GetControlDeviceBindResponseData getControlDeviceBindResponseData;
|
//[System.Serializable]
|
//public class GetControlDeviceBindResponseData
|
//{
|
// /// <summary>
|
// /// 设备属性列表
|
// /// </summary>
|
// public List<DeviceObj> DeviceObj = new List<DeviceObj>();
|
//}
|
|
///// <summary>
|
///// Command数组
|
///// </summary>
|
//public class DeviceObj
|
//{
|
// /// <summary>
|
// /// 控制设备的mac地址
|
// /// </summary>
|
// public string DeviceAddr;
|
|
// /// <summary>
|
// /// 控制设备的端口号
|
// /// </summary>
|
// public int Epoint;
|
//}
|
//#endregion
|
}
|
}
|