New file |
| | |
| | | using System;
|
| | | using System.Collections.Generic; |
| | | using Newtonsoft.Json.Linq; |
| | | |
| | | namespace ZigBee.Device |
| | | { |
| | | public class PIRSensor: BindObj |
| | | { |
| | | public PIRSensor() |
| | | { |
| | | this.Type = DeviceType.IASZone; |
| | | } |
| | | |
| | | //#region PIR传感器参数配置 |
| | | /////<summary > |
| | | /////PIR传感器参数配置 |
| | | ///// </summary> |
| | | //public async System.Threading.Tasks.Task<ResponseAllData> SetPIRSensorParamateAsync(ConfigureParamates configureParamates) |
| | | //{ |
| | | // 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 |
| | | // { |
| | | // result = new ResponseAllData { }; |
| | | // if (clientDataPassthroughResponseData?.PassData != null) |
| | | // { |
| | | // var data = clientDataPassthroughResponseData.PassData; |
| | | // if (data.Length == 14) |
| | | // { |
| | | // result.responseData.command = int.Parse(data[10].ToString() + data[11].ToString()+ data[12].ToString() + data[13].ToString()); |
| | | // result.responseData.status = int.Parse(data[14].ToString() + data[15].ToString()); |
| | | // } |
| | | // } |
| | | // System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | // } |
| | | // } |
| | | // }; |
| | | |
| | | // try |
| | | // { |
| | | // var passData = SetPIRSensorData(configureParamates); |
| | | // 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"), Common.SecuritySet.Encryption((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 ResponseAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | // } |
| | | // Gateway.Actions -= action; |
| | | // System.Console.WriteLine("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | // return result; |
| | | // }); |
| | | //} |
| | | |
| | | ///// <summary>
|
| | | ///// PIR配置参数回复
|
| | | ///// </summary>
|
| | | //public ParamatesInfo paramatesInfo;
|
| | | //[System.Serializable]
|
| | | //public class ParamatesInfo
|
| | | //{
|
| | | // /// <summary>
|
| | | // /// 错误信息
|
| | | // /// </summary>
|
| | | // public string errorMessageBase;
|
| | | // /// <summary>
|
| | | // /// 网关信息错误反馈
|
| | | // /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
|
| | | // /// </summary>
|
| | | // public ErrorResponData errorResponData;
|
| | | // /// <summary>
|
| | | // /// PIR配置参数
|
| | | // /// </summary>
|
| | | // public ConfigureParamates configureParamates ;
|
| | | //}
|
| | |
|
| | | ///// <summary>
|
| | | ///// PIR配置参数
|
| | | ///// </summary>
|
| | | //[System.Serializable]
|
| | | //public class ConfigureParamates
|
| | | //{ |
| | | // /// <summary>
|
| | | // ///亮度(光照度)使能
|
| | | // ///<para> false:不使能</para>
|
| | | // /// <para>true:使能</para>
|
| | | // /// </summary>
|
| | | // public bool levelEnable;
|
| | | // /// <summary>
|
| | | // /// 光照度等级
|
| | | // /// </summary>
|
| | | // public LevelSize levelSize = new LevelSize{};
|
| | | // /// <summary>
|
| | | // ///亮度(光照度)使能
|
| | | // ///<para> false:不使能</para>
|
| | | // /// <para>true:使能</para>
|
| | | // /// </summary>
|
| | | // public bool controlDevEnable;
|
| | | // /// <summary>
|
| | | // /// 触发开灯到触发关灯的时间间隔,(注意:该参数为16进制)
|
| | | // /// <para>0-ffff 单位秒</para>
|
| | | // /// </summary>
|
| | | // public int transitionTime;
|
| | |
|
| | | // } |
| | | |
| | | ///// <summary>
|
| | | ///// 按键指示灯颜色信息对应顺序号
|
| | | ///// </summary>
|
| | | //public enum LevelSize
|
| | | //{
|
| | | // /// <summary>
|
| | | // /// 白天
|
| | | // /// </summary>
|
| | | // Daytime = 1,
|
| | | // /// <summary>
|
| | | // /// 昏暗
|
| | | // /// </summary>
|
| | | // Dusky = 2,
|
| | | // /// <summary>
|
| | | // /// 黑夜
|
| | | // /// </summary>
|
| | | // Night = 3,
|
| | | //}
|
| | | |
| | | ///// <summary> |
| | | ///// 配置PIR配置参数 |
| | | ///// <para>发配置按键指示灯颜色命令时,此时为发送到网关的透传数据</para> |
| | | ///// </summary> |
| | | //string SetPIRSensorData(ConfigureParamates configureParamates) |
| | | //{ |
| | | // string data = ""; |
| | | // string dataLength = "09"; |
| | | // string dataComand1 = "00"; |
| | | // string dataComand2 = "03"; |
| | | // string dataSerialNum = "01"; |
| | | // string addDataLength = "05";
|
| | | // string levelEnable = "";
|
| | | // string levelSize = "";
|
| | | // string controlDevEnable = "";
|
| | | // string transitionTime = ""; |
| | | // try
|
| | | // { |
| | | // if (configureParamates != null) |
| | | // { |
| | | // if (configureParamates.levelEnable) |
| | | // { |
| | | // levelEnable = "00"; |
| | | // } |
| | | // else |
| | | // { |
| | | // levelEnable = "01"; |
| | | // } |
| | | // switch (configureParamates.levelSize) |
| | | // { |
| | | // case LevelSize.Daytime: |
| | | // levelSize = "01"; |
| | | // break; |
| | | // case LevelSize.Dusky: |
| | | // levelSize = "02"; |
| | | // break; |
| | | // case LevelSize.Night: |
| | | // levelSize = "03"; |
| | | // break; |
| | | // } |
| | | // if (configureParamates.controlDevEnable) |
| | | // { |
| | | // controlDevEnable = "00"; |
| | | // } |
| | | // else |
| | | // { |
| | | // controlDevEnable = "01"; |
| | | // } |
| | | |
| | | // var time = configureParamates.transitionTime.ToString(); |
| | | // var sbString = new System.Text.StringBuilder(); |
| | | // switch (time.Length) |
| | | // {
|
| | | // case 1: |
| | | // transitionTime = "000"+ time;
|
| | | // break; |
| | | // case 2:
|
| | | // transitionTime = "00" + time;
|
| | | // break; |
| | | // case 3:
|
| | | // transitionTime = "0" + time;
|
| | | // break; |
| | | // case 4:
|
| | | // transitionTime = time;
|
| | | // break; |
| | | // } |
| | | // sbString.Append(transitionTime.ToUpper());
|
| | | // } |
| | | |
| | | // data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength + |
| | | // levelEnable + levelSize + controlDevEnable + transitionTime; |
| | | // } |
| | | // catch { }; |
| | | |
| | | // return data; |
| | | //} |
| | | //#endregion
|
| | |
|
| | | //#region 获取PIR配置数据
|
| | | /////<summary >
|
| | | /////PIR传感器参数配置
|
| | | ///// <para>reserve:0-ff</para>
|
| | | ///// </summary>
|
| | | //public async System.Threading.Tasks.Task<ParamatesInfo> GetPIRSensorParamateAsync(string reserve="01")
|
| | | //{
|
| | | // ParamatesInfo result = null;
|
| | | // if (Gateway == null)
|
| | | // {
|
| | | // result = new ParamatesInfo { 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 ParamatesInfo { errorMessageBase = "网关错误回复,且数据是空" };
|
| | | // }
|
| | |
|
| | | // else
|
| | | // {
|
| | | // result = new ParamatesInfo { 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 ParamatesInfo { errorMessageBase = "网关返回的数据为空" };
|
| | | // }
|
| | | // else
|
| | | // {
|
| | | // result = new ParamatesInfo { };
|
| | | // if (clientDataPassthroughResponseData?.PassData != null)
|
| | | // {
|
| | | // var data = clientDataPassthroughResponseData.PassData;
|
| | | // if (data.Length == 18)
|
| | | // {
|
| | | // var le = data[8].ToString() + data[9].ToString();
|
| | | // if (le == "01")
|
| | | // {
|
| | | // result.configureParamates.levelEnable = true;
|
| | | // }
|
| | | // else
|
| | | // {
|
| | | // result.configureParamates.levelEnable = false;
|
| | | // } |
| | | |
| | | // var size = data[10].ToString() + data[11].ToString();
|
| | | // switch (size)
|
| | | // {
|
| | | // case "01":
|
| | | // result.configureParamates.levelSize = LevelSize.Daytime;
|
| | | // break;
|
| | | // case "02":
|
| | | // result.configureParamates.levelSize = LevelSize.Dusky;
|
| | | // break;
|
| | | // case "03":
|
| | | // result.configureParamates.levelSize = LevelSize.Night;
|
| | | // break;
|
| | | // }
|
| | |
|
| | | // var cdl = data[12].ToString() + data[13].ToString();
|
| | | // if (cdl == "01")
|
| | | // {
|
| | | // result.configureParamates.controlDevEnable = true;
|
| | | // }
|
| | | // else
|
| | | // {
|
| | | // result.configureParamates.controlDevEnable = false;
|
| | | // }
|
| | | |
| | | // result.configureParamates.transitionTime = int.Parse(data[14].ToString() + data[15].ToString() + data[16].ToString() + data[17].ToString());
|
| | | // }
|
| | | // }
|
| | | // System.Console.WriteLine($"UI收到通知后的主题_{ topic}");
|
| | | // }
|
| | | // }
|
| | | // };
|
| | |
|
| | | // try
|
| | | // {
|
| | | // var passData = GetPIRSensorData(reserve);
|
| | | // 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"), Common.SecuritySet.Encryption((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 ParamatesInfo { errorMessageBase = " 回复超时,请重新操作" };
|
| | | // }
|
| | | // Gateway.Actions -= action;
|
| | | // System.Console.WriteLine("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString());
|
| | |
|
| | | // return result;
|
| | | // });
|
| | | //} |
| | | |
| | | ///// <summary>
|
| | | ///// 配置PIR配置参数
|
| | | ///// <para>发配置按键指示灯颜色命令时,此时为发送到网关的透传数据</para>
|
| | | ///// </summary> |
| | | //string GetPIRSensorData(string reserve)
|
| | | //{
|
| | | // string data = "";
|
| | | // string dataLength = "05";
|
| | | // string dataComand1 = "01";
|
| | | // string dataComand2 = "03";
|
| | | // string dataSerialNum = "01";
|
| | | // string addDataLength = "01";
|
| | | // string reserveData = reserve;
|
| | | |
| | | // try
|
| | | // {
|
| | | // data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
|
| | | // reserveData;
|
| | | // }
|
| | | // catch { };
|
| | |
|
| | | // return data;
|
| | | //}
|
| | | //#endregion |
| | | } |
| | | } |