| | |
| | | namespace ZigBee.Device |
| | | { |
| | | [System.Serializable] |
| | | public class AC : ThirdPartyModuleUpgrade |
| | | public class AC : CommonDevice |
| | | { |
| | | public AC() |
| | | { |
| | |
| | | /// <summary> |
| | | ///当前室内温度 |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public int currentLocalTemperature = 0; |
| | | |
| | | /// <summary> |
| | | /// 当前加热度数 |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public int currentHeatingSetpoint = 0; |
| | | |
| | | /// <summary> |
| | | /// 当前制冷度数 |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public int currentCoolingSetpoint = 0; |
| | | |
| | | /// <summary> |
| | | ///恒温设备类型 |
| | | /// <para>恒温设备具备功能,Attribute Values如下</para> |
| | | /// <para>0:(Cooling Only) 无Heat和Emergency功能</para> |
| | | /// <para>1:(Cooling With Reheat)无Heat和Emergency功能</para> |
| | | /// <para>2:(Heating Only)无Cool和Precooling功能</para> |
| | | /// <para>3:(Heating With Reheat)无Cool和Precooling功能</para> |
| | | /// <para>4:(Cooling and Heating 4-pipes)可能有所有功能</para> |
| | | /// <para>5:(Cooling and Heating 4-pipes with Reheat)可能有所有功能</para> |
| | | /// 当前自动温度 |
| | | /// </summary> |
| | | public int currentAcType = 0; |
| | | |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public int currentAutoSetpoint; |
| | | /// <summary> |
| | | /// 恒温设备当前模式 |
| | | /// <para>恒温设备具备功能,SystemMode Attribute Values如下</para> |
| | |
| | | /// <para>8:Dry </para> |
| | | /// <para>9:Sleep</para> |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public int currentSystemMode = 0; |
| | | |
| | | /// <summary> |
| | | /// 风扇当前模式 |
| | | /// <para>0:Off </para> |
| | |
| | | /// <para>5:Auto </para> |
| | | /// <para>6:Smart</para> |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public int currentFanMode = 0; |
| | | |
| | | /// <summary> |
| | | /// 支持的控制模式 |
| | | /// 风扇zz扫风当前模式 |
| | | /// <para>0:1挡 </para> |
| | | /// <para>1:2</para> |
| | | /// <para>2:3</para> |
| | | /// <para>3:4 </para> |
| | | /// <para>4:5 </para> |
| | | /// <para>7:Auto </para> |
| | | /// </summary> |
| | | public List<AcMode> acModes = new List<AcMode> { }; |
| | | |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public int currentFanSwingMode = 0; |
| | | /// <summary> |
| | | /// 支持的风速模式 |
| | | /// <para>自定义空调支持的模式(默认全开)</para>
|
| | | /// <para>数组索引 -> 0:制冷 1:制热 2:送风 3:除湿 4:自动</para>
|
| | | /// <para>值 -> 1:代表使用 0:代表不使用</para>
|
| | | /// </summary> |
| | | public List<FanMode> fanModes = new List<FanMode> { }; |
| | | |
| | | public int[] listSupportMode = new int[5] { 1, 1, 1, 1, 1 }; |
| | | /// <summary>
|
| | | /// 是否启用摆风功能 false:不使用摆风功能 true:使用摆风功能
|
| | | /// </summary> |
| | | public bool UseSwingFunction = true; |
| | | /// <summary> |
| | | /// 过滤网清洗状态 |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public bool CleanStatu = false; |
| | | |
| | | /// <summary> |
| | | /// 获取当前室内温度. |
| | |
| | | public void ReadHeatingSetpoint() |
| | | { |
| | | ReadAttri(Device.Cluster_ID.Thermostat, AttriButeId.HeatingSetpoint); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 获取当前自动度数. |
| | | /// <para>AttriButeId=18 (先调用发现属性接口,查看设备是否支持该接口的属性)</para> |
| | | /// </summary> |
| | | public void ReadAutoSetpoint() |
| | | { |
| | | ReadAttri(Device.Cluster_ID.Thermostat, AttriButeId.AutoSetpoint); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | ReadAttri(Device.Cluster_ID.FanControl, AttriButeId.FanModeSequence); |
| | | } |
| | | |
| | | /// <summary>
|
| | | /// 获取空调自定义设置的支持模式
|
| | | /// </summary> |
| | | public void ReadModeSupport()
|
| | | {
|
| | | ReadAttri(Device.Cluster_ID.Thermostat, AttriButeId.AcModeSupport);
|
| | | } |
| | | |
| | | /// <summary> |
| | | /// 过滤网清洗状态 |
| | | /// </summary> |
| | | public void ReadCleanStatu() |
| | | { |
| | | ReadAttri(Device.Cluster_ID.Thermostat, AttriButeId.CleanStatu); |
| | | }
|
| | |
|
| | | /// <summary> |
| | | /// 获取是否启用空调摆风模式的状态(打开 或者 关闭) |
| | | /// </summary> |
| | | public void ReadUseSwingFunctionStatu() |
| | | { |
| | | ReadAttri(Device.Cluster_ID.FanControl, AttriButeId.UseAcSwingFunctionStatu); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 扫风模式 |
| | | /// </summary> |
| | | public enum FanSwingMode |
| | | { |
| | | /// <summary> |
| | | /// 一档 |
| | | /// </summary> |
| | | First = 0, |
| | | /// <summary> |
| | | /// 二挡 |
| | | /// </summary> |
| | | Second = 1, |
| | | /// <summary> |
| | | /// 三挡 |
| | | /// </summary> |
| | | Thrid = 2, |
| | | /// <summary> |
| | | /// 四挡 |
| | | /// </summary> |
| | | Fourth = 3, |
| | | /// <summary> |
| | | /// 五档 |
| | | /// </summary> |
| | | Fifth = 4, |
| | | /// <summary> |
| | | /// 自动 |
| | | /// </summary> |
| | | Auto = 7 |
| | | } |
| | | /// <summary> |
| | | /// 获取扫风模式 |
| | | /// </summary> |
| | | public void ReadSystemFansSwingMode() |
| | | { |
| | | ReadAttri(Device.Cluster_ID.FanSwing, AttriButeId.FanSwing); |
| | | } |
| | | /// <summary> |
| | | /// 设置扫风模式 |
| | | /// </summary> |
| | | /// <param name="fanSwing"></param> |
| | | /// <returns></returns> |
| | | public async System.Threading.Tasks.Task<SetWritableValueResponAllData> SetFanSwingAsyncMode(FanSwingMode fanSwing) |
| | | { |
| | | 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 temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.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 tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<SetWritableValueResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (tempData == null) |
| | | { |
| | | d = new SetWritableValueResponAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new SetWritableValueResponAllData { setWritableValueResponData = tempData }; |
| | | DebugPrintLog($"UI收到通知后的主题_{ topic}"); |
| | | } |
| | | } |
| | | }; |
| | | Gateway.Actions += action; |
| | | DebugPrintLog("SetWritableValue_Actions 启动" + "_" + System.DateTime.Now.ToString()); |
| | | try |
| | | { |
| | | var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 514 }, { "Command", 120 } }; |
| | | var data = new JObject { { "Undivided", 0 }, { "AttributeId", 4096 }, { "AttributeDataType", 48 }, { "AttributeData", (int)fanSwing } }; |
| | | 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; |
| | | DebugPrintLog("SetWritableValue_Actions 退出" + System.DateTime.Now.ToString()); |
| | | return d; |
| | | }); |
| | | } |
| | | |
| | | |
| | | ///<summary > |
| | | ///设置制冷度数. |
| | | /// </summary> |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | |
| | | 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) |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | |
| | | 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) |
| | |
| | | } |
| | | |
| | | ///<summary > |
| | | ///设置自动度数. |
| | | /// </summary> |
| | | public async System.Threading.Tasks.Task<SetWritableValueResponAllData> SetAutoTemperatureAsync(int temperature) |
| | | { |
| | | 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 temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.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 tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<SetWritableValueResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (tempData == null) |
| | | { |
| | | d = new SetWritableValueResponAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new SetWritableValueResponAllData { setWritableValueResponData = tempData }; |
| | | DebugPrintLog($"UI收到通知后的主题_{ topic}"); |
| | | } |
| | | } |
| | | }; |
| | | Gateway.Actions += action; |
| | | DebugPrintLog("SetWritableValue_Actions 启动" + "_" + System.DateTime.Now.ToString()); |
| | | try |
| | | { |
| | | var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 513 }, { "Command", 120 } }; |
| | | var data = new JObject { { "Undivided", 0 }, { "AttributeId", 4096 }, { "AttributeDataType", 41 }, { "AttributeData", (int)temperature } }; |
| | | 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; |
| | | DebugPrintLog("SetWritableValue_Actions 退出" + System.DateTime.Now.ToString()); |
| | | return d; |
| | | }); |
| | | } |
| | | |
| | | ///<summary > |
| | | ///设置恒温器设备当前工作模式. |
| | | /// </summary> |
| | | public async System.Threading.Tasks.Task<SetWritableValueResponAllData> SetSystemModeAsync(AcMode acMode) |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | |
| | | 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) |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | |
| | | 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) |
| | |
| | | {
|
| | | return await SetSystemModeAsync(acMode);
|
| | | } |
| | | |
| | | #region 升级空调第三方模块的接口 |
| | | |
| | | #region 读取IRACC模块固件版本(APP -> Zigbee MCU) |
| | | ///<summary > |
| | | ///读取IRACC模块固件版本 |
| | | /// <para>reserve:0-ff</para> |
| | | /// </summary> |
| | | public async System.Threading.Tasks.Task<ReadACFirewareVersionResponAllData> ReadACFirewareVersionAsync(string reserve = "01") |
| | | { |
| | | ReadACFirewareVersionResponAllData result = null; |
| | | if (Gateway == null) |
| | | { |
| | | result = new ReadACFirewareVersionResponAllData { 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 ReadACFirewareVersionResponAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | |
| | | else |
| | | { |
| | | result = new ReadACFirewareVersionResponAllData { 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 ReadACFirewareVersionResponAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null) |
| | | { |
| | | var data = gatewayTemp.clientDataPassthroughResponseData.PassData; |
| | | var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString(); |
| | | if (command == "0259") |
| | | { |
| | | var tempD = new ReadACFirewareVersionResponData(); |
| | | tempD.Status = Convert.ToInt32(data[10].ToString() + data[11].ToString(), 16); |
| | | if (data.Length == 82) |
| | | { |
| | | var firewareString = data.Substring(12); |
| | | var aa = firewareString.Length; |
| | | firewareVersion = firewareString; |
| | | var bytes = new byte[firewareString.Length / 2]; |
| | | for (int i = 0; i < bytes.Length; i++) |
| | | { |
| | | bytes[i] = Convert.ToByte(firewareString.Substring(i * 2, 2), 16); |
| | | } |
| | | |
| | | var firewareVersionTemp = System.Text.Encoding.ASCII.GetString(bytes); |
| | | tempD.FirewareVersion = firewareVersionTemp.Replace('\0', ' ').Trim(); |
| | | } |
| | | result = new ReadACFirewareVersionResponAllData { readACFirewareVersionResponData = tempD }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_command:0258_{topic}"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | |
| | | Gateway.Actions += action; |
| | | System.Console.WriteLine("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString()); |
| | | |
| | | try |
| | | { |
| | | var passData = ReadACFirewareVersionData(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 > WaitReceiveDataTime) |
| | | { |
| | | result = new ReadACFirewareVersionResponAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | Gateway.Actions -= action; |
| | | System.Console.WriteLine("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | return result; |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 读取IRACC模块固件版本 |
| | | /// </summary> |
| | | string ReadACFirewareVersionData(string reserve) |
| | | { |
| | | string data = ""; |
| | | string dataLength = "05"; |
| | | string dataComand1 = "58"; |
| | | string dataComand2 = "02"; |
| | | string dataSerialNum = "01"; |
| | | string addDataLength = "01"; |
| | | string reserveData = reserve; |
| | | |
| | | try |
| | | { |
| | | data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength + |
| | | reserveData; |
| | | } |
| | | catch { }; |
| | | |
| | | return data; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// IRACC模块固件版本,网关反馈信息 |
| | | /// </summary> |
| | | public ReadACFirewareVersionResponAllData readACFirewareVersionResponAllData; |
| | | /// <summary> |
| | | /// IRACC模块固件版本,网关反馈信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class ReadACFirewareVersionResponAllData |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// IRACC模块固件版本信息 |
| | | /// </summary> |
| | | public ReadACFirewareVersionResponData readACFirewareVersionResponData; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// IRACC模块固件版本的数据 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class ReadACFirewareVersionResponData |
| | | { |
| | | /// <summary> |
| | | /// 状态 |
| | | ///<para>0--成功</para> |
| | | ///<para>1--失败</para> |
| | | ///<para>ff--无效</para> |
| | | /// </summary> |
| | | public int Status; |
| | | /// <summary> |
| | | /// 固件版本 |
| | | /// </summary> |
| | | public string FirewareVersion; |
| | | } |
| | | #endregion |
| | | |
| | | #region 升级IRACC模块通知(APP -> Zigbee MCU) |
| | | ///<summary > |
| | | ///升级IRACC模块通知 |
| | | /// <para>firewareVer:固件版本</para> |
| | | /// <para>firewareSize:固件大小</para> |
| | | /// </summary> |
| | | public async System.Threading.Tasks.Task<ResponseAllData> UpggradeACNotificationAsync(string firewareVer, long firewareSize) |
| | | { |
| | | 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; |
| | | var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString(); |
| | | if (command == "025b") |
| | | { |
| | | var tempD = new ResponseData(); |
| | | if (data.Length == 12) |
| | | { |
| | | tempD.status = Convert.ToInt32(data[10].ToString() + data[11].ToString(), 16); |
| | | } |
| | | result = new ResponseAllData { responseData = tempD }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | |
| | | Gateway.Actions += action; |
| | | System.Console.WriteLine("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString()); |
| | | |
| | | try |
| | | { |
| | | var passData = UpggradeACNotificationData(firewareVer, firewareSize); |
| | | 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 > WaitReceiveDataTime) |
| | | { |
| | | result = new ResponseAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | Gateway.Actions -= action; |
| | | System.Console.WriteLine("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | return result; |
| | | }); |
| | | } |
| | | |
| | | private string firewareVersion = string.Empty; |
| | | /// <summary> |
| | | /// 升级IRACC模块通知返回 |
| | | /// </summary> |
| | | string UpggradeACNotificationData(string firewareVer, long firewareSize) |
| | | { |
| | | string data = ""; |
| | | string dataLength = "2C"; |
| | | string dataComand1 = "5A"; |
| | | string dataComand2 = "02"; |
| | | string dataSerialNum = "01"; |
| | | string addDataLength = "28"; |
| | | string deviceUpgradeMethod = "01"; |
| | | string firewareVersionData = ""; |
| | | string firewareSizeData = ""; |
| | | |
| | | try |
| | | { |
| | | //固件版本 |
| | | var firewareVerBytes = System.Text.Encoding.ASCII.GetBytes(firewareVer); |
| | | for (int i = 0; i < firewareVerBytes.Length; i++) |
| | | { |
| | | var fw = Convert.ToString(firewareVerBytes[i], 16); |
| | | if (fw.Length == 1) |
| | | { |
| | | fw = "0" + fw; |
| | | } |
| | | firewareVersionData += fw; |
| | | } |
| | | |
| | | var aa = firewareVersionData.Length; |
| | | firewareVersionData = firewareVersionData.PadRight(70, '0'); |
| | | |
| | | //固件尺寸 |
| | | var tempFwSize = Convert.ToString(firewareSize, 16); |
| | | tempFwSize = tempFwSize.PadLeft(8, '0'); |
| | | for (int i = 6; i >= 0; i = i - 2) |
| | | { |
| | | firewareSizeData += tempFwSize.Substring(i, 2); |
| | | } |
| | | |
| | | data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength + |
| | | deviceUpgradeMethod + firewareVersionData + firewareSizeData; |
| | | |
| | | } |
| | | catch { }; |
| | | |
| | | return data; |
| | | } |
| | | |
| | | /// <summary> |
| | | ///升级IRACC模块通知回复 |
| | | /// </summary> |
| | | public ResponseAllData keyColorDataResponseAllData; |
| | | [System.Serializable] |
| | | public class ResponseAllData |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 升级IRACC模块通知信息 |
| | | /// </summary> |
| | | public ResponseData responseData; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 升级IRACC模块通知回复(Zigbee MCU -> APP) |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class ResponseData |
| | | { |
| | | /// <summary> |
| | | /// 状态值 |
| | | /// <para>0--版本号不一致(可以升级</para> |
| | | /// <para>1--版本号一致(不用升级</para> |
| | | /// <para>2--预留(暂时不用到</para> |
| | | /// <para>ff--无效(暂时不用到)</para> |
| | | /// </summary> |
| | | public int status = -1; |
| | | } |
| | | #endregion |
| | | |
| | | #region 设备请求APP获取升级数据 (Zigbee MCU -> APP,主动上报) |
| | | /// <summary> |
| | | ///设备请求APP获取升级数据(Zigbee MCU -> APP,主动上报) |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class DeviceRequestUpgradeResponseData |
| | | { |
| | | /// <summary> |
| | | /// 数据偏移量,每个分包偏移量+(1-43) |
| | | /// </summary> |
| | | public string offset = string.Empty; |
| | | /// <summary> |
| | | /// 数据长度len |
| | | /// </summary> |
| | | public int dataLength = -1; |
| | | } |
| | | #endregion |
| | | |
| | | #region 发升级数据到设备(APP -> Zigbee MCU) |
| | | ///<summary > |
| | | ///读取IRACC模块固件版本 |
| | | /// <para>reserve:0-ff</para> |
| | | /// </summary> |
| | | public async void UpgradeAsync(SendUpgradeData upgradeData) |
| | | { |
| | | if (Gateway == null) |
| | | { |
| | | return; |
| | | } |
| | | Action<string, string> action = (topic, message) => { }; |
| | | Gateway.Actions += action; |
| | | System.Console.WriteLine("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString()); |
| | | |
| | | try |
| | | { |
| | | string passData = ""; |
| | | if (upgradeData != null) |
| | | { |
| | | passData = SendUpgrade(upgradeData); |
| | | } |
| | | |
| | | 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 { } |
| | | |
| | | Gateway.Actions -= action; |
| | | System.Console.WriteLine("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString()); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 发升级数据到设备 |
| | | /// </summary> |
| | | string SendUpgrade(SendUpgradeData upgradeData) |
| | | { |
| | | string data = ""; |
| | | string dataLength = ""; |
| | | string dataComand1 = "5D"; |
| | | string dataComand2 = "02"; |
| | | string dataSerialNum = "01"; |
| | | string addDataLength = ""; |
| | | |
| | | string status = ""; |
| | | string offset = ""; |
| | | string upgradeDataLength = ""; |
| | | string dataString = ""; |
| | | |
| | | try |
| | | { |
| | | var len = 4 + 1 + 4 + 1 + upgradeData.dataLength; |
| | | dataLength = Convert.ToString(len, 16); |
| | | if (dataLength.Length == 1) |
| | | { |
| | | dataLength = "0" + dataLength; |
| | | } |
| | | |
| | | addDataLength = Convert.ToString(6 + upgradeData.dataLength, 16); |
| | | if (addDataLength.Length == 1) |
| | | { |
| | | addDataLength = "0" + addDataLength; |
| | | } |
| | | |
| | | if (upgradeData.status == 0) |
| | | { |
| | | status = "00"; |
| | | } |
| | | else if (upgradeData.status == 1) |
| | | { |
| | | status = "01"; |
| | | } |
| | | else |
| | | { |
| | | status = "ff"; |
| | | } |
| | | |
| | | |
| | | offset = upgradeData.offset; |
| | | |
| | | var dl = Convert.ToString(upgradeData.dataLength, 16); |
| | | if (dl.Length == 1) |
| | | { |
| | | upgradeDataLength = "0" + dl; |
| | | } |
| | | else |
| | | { |
| | | upgradeDataLength = dl; |
| | | } |
| | | |
| | | for (int i = 0; i < upgradeData.databytes.Length; i++) |
| | | { |
| | | var dataB = Convert.ToString(upgradeData.databytes[i], 16);
if (dataB.Length == 1)
{
dataB = "0" + dataB;
}
dataString += dataB; |
| | | } |
| | | |
| | | data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength + |
| | | status + offset + upgradeDataLength + dataString; |
| | | } |
| | | catch { }; |
| | | |
| | | return data; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 发送升级数据到设备(APP -> Zigbee MCU) |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class SendUpgradeData |
| | | { |
| | | /// <summary> |
| | | /// 0--成功 |
| | | ///<para>1--失败</para> |
| | | ///<para>ff--无效</para> |
| | | /// </summary> |
| | | public int status = 0; |
| | | /// <summary> |
| | | /// 数据偏移量,每个分包偏移量+(1-43) |
| | | /// </summary> |
| | | public string offset; |
| | | /// <summary> |
| | | /// 数据长度len |
| | | /// </summary> |
| | | public int dataLength = -1; |
| | | |
| | | /// <summary> |
| | | /// 分包数据 |
| | | /// </summary> |
| | | public byte[] databytes; |
| | | } |
| | | #endregion |
| | | |
| | | #region 分包结束(Zigbee MCU -> APP,主动上报) |
| | | /// <summary> |
| | | /// 设备请求APP获取分包结束命令(Zigbee MCU -> APP) |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class DeviceRequestFinishResponseData |
| | | { |
| | | /// <summary> |
| | | /// 0-ff |
| | | /// </summary> |
| | | public int reserve = -1; |
| | | } |
| | | #endregion |
| | | |
| | | #region 分包结束(APP -> Zigbee MCU) |
| | | ///<summary > |
| | | ///读取IRACC模块固件版本 |
| | | /// <para>status:0--成功;1--失败;ff--无效 .</para> |
| | | /// </summary> |
| | | public async void SendFinishAsync(int status) |
| | | { |
| | | if (Gateway == null) |
| | | { |
| | | return; |
| | | } |
| | | Action<string, string> action = (topic, message) => { }; |
| | | Gateway.Actions += action; |
| | | System.Console.WriteLine("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString()); |
| | | |
| | | try |
| | | { |
| | | var passData = SendFinishDataString(status); |
| | | 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 { } |
| | | |
| | | Gateway.Actions -= action; |
| | | System.Console.WriteLine("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString()); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 发升级数据到设备 |
| | | /// </summary> |
| | | string SendFinishDataString(int status) |
| | | { |
| | | string data = ""; |
| | | string dataLength = "05"; |
| | | string dataComand1 = "5F"; |
| | | string dataComand2 = "02"; |
| | | string dataSerialNum = "01"; |
| | | string addDataLength = "01"; |
| | | string statusString = ""; |
| | | try |
| | | { |
| | | if (status == 0) |
| | | { |
| | | statusString = "00"; |
| | | } |
| | | else if (status == 1) |
| | | { |
| | | statusString = "01"; |
| | | } |
| | | else |
| | | { |
| | | statusString = "ff"; |
| | | } |
| | | data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength + |
| | | statusString; |
| | | } |
| | | catch { }; |
| | | |
| | | return data; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 分包结束返回(APP -> Zigbee MCU |
| | | /// </summary> |
| | | //[System.Serializable] |
| | | public class SendFinishData |
| | | { |
| | | /// <summary> |
| | | /// 状态:成功/失败 |
| | | ///<para>0--成功<<para> |
| | | ///<para>1--失败<<para> |
| | | ///<para>ff--无效<<para> |
| | | /// </summary> |
| | | public int status = -1; |
| | | } |
| | | |
| | | #endregion |
| | | #endregion |
| | | } |
| | | } |