| | |
| | | [System.Serializable] |
| | | public class ZbGateway : ZbGatewayData |
| | | { |
| | | public ZbGateway() |
| | | { |
| | | this.Type = DeviceType.ZbGateway; |
| | | } |
| | | |
| | | |
| | | |
| | | #region 网关特殊信息处理 |
| | | #region 一堆变量 |
| | | /// <summary> |
| | | /// 主网关 |
| | | /// </summary> |
| | |
| | | /// </summary> |
| | | /// <value>The file path.</value> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public override string FilePath |
| | | public string FilePath |
| | | { |
| | | get |
| | | { |
| | | var deviceType = Type.ToString(); |
| | | var fileName = "Gateway_" + deviceType + "_" + this.getGatewayBaseInfo?.gwID; |
| | | var fileName = "Gateway_" + DeviceType.ZbGateway.ToString() + "_" + this.getGatewayBaseInfo?.gwID; |
| | | return fileName; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 等待从网关接收数据的时间 |
| | | /// </summary> |
| | | /// <value>The wait receive data time.</value> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public int WaitReceiveDataTime |
| | | { |
| | | get |
| | | { |
| | | if (Device.ZbGateway.RemoteMqttClient != null && Device.ZbGateway.RemoteMqttClient.IsConnected) |
| | | { |
| | | return 10000; |
| | | } |
| | | else |
| | | { |
| | | return 3000; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 局域网加密密码 |
| | | /// </summary> |
| | | string password; |
| | | private string password; |
| | | /// <summary> |
| | | /// 局域网加密密钥 |
| | | /// </summary> |
| | |
| | | } |
| | | } |
| | | |
| | | #region variable |
| | | /// <summary> |
| | | /// 远程连接成功时的时间 |
| | | /// </summary> |
| | | public static DateTime LoginRemoteDateTime = DateTime.Now; |
| | | |
| | | /// <summary> |
| | | /// 同步到远程的当前时间戳 |
| | | /// </summary>Re |
| | | public static ulong CurrentTimeStamp |
| | | { |
| | | get |
| | | { |
| | | return RemoteTimeStamp + (ulong)(DateTime.Now - LoginRemoteDateTime).TotalSeconds; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 远程连接成功时的时间戳 |
| | | /// </summary> |
| | | public static ulong RemoteTimeStamp; |
| | | /// <summary> |
| | | /// 网关是否加密 |
| | | /// </summary> |
| | |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public static List<ZbGateway> GateWayList = new List<ZbGateway>(); |
| | | |
| | | //当前网关中的设备列表 |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public List<CommonDevice> DeviceList = new List<CommonDevice>(); |
| | | |
| | | /// <summary> |
| | | /// 网关中场景列表 |
| | | /// 一个场景中包含所有信息,包括场景设备信息 |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public static List<Scene.GetSceneAllInfo> AllSceneList = new List<Scene.GetSceneAllInfo>(); |
| | | |
| | | /// <summary> |
| | | /// 网关中场景的设备列表 |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public List<Scene.GetSceneDeviceListInfo> SceneDeviceList = new List<Scene.GetSceneDeviceListInfo>(); |
| | | |
| | | #region action variable |
| | | /// <summary> |
| | | /// 接收数据后回调 |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | Action<object> action; |
| | | /// <summary> |
| | | /// 设置数据回调 |
| | | /// </summary> |
| | | public void SetAction(Action<object> action, int timeOut = 1000) |
| | | { |
| | | this.action = action; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 网关推送数据 |
| | | /// <para>第一个参数:如果为 DeviceInComingRespon:设备新上报</para> |
| | |
| | | /// <para>第一个参数:如果为 ZoneTriggerReport:防区被触发时报告</para> |
| | | /// <para>第一个参数:如果为 LogicExecuteReport:逻辑被调用反馈</para> |
| | | /// <para>第一个参数:如果为 TimingWillArrive:时间点条件推迟执行</para> |
| | | /// para>第一个参数: 如果为 ModeTriggerReport:模式安防动作被最终激活时发送报警信息</para> |
| | | /// <para>第一个参数: 如果为 ModeTriggerReport:模式安防动作被最终激活时发送报警信息</para> |
| | | /// <para>第一个参数:如果为 EnOrWithdrawSucceedReport:通过外部方式布防撤防成功时报告息</para> |
| | | /// <para>第一个参数:如果为 PushTargetInfoReport:胁迫密码撤防时短信推送</para> |
| | | /// <para>第一个参数:如果为 DeviceDefaultAck:节点设备默认反馈</para> |
| | | /// <para>第一个参数:如果为 DDevice/IsGetEpointInfo:有新设备加入zigbee网络反馈</para>设备请求APP获取升级数据 |
| | | /// <para>第一个参数:如果为 Device/DeviceJoinZbNet:获取新设备所有端点信息是否成功反馈</para> |
| | | /// <para>第一个参数:如果为 DeviceRequestAcUpdateData: 设备请求空调发升级数据</para> |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public Action<string, object> ReportAction; |
| | | /// <summary> |
| | | /// 云端通讯错误数据上报 |
| | | ///<para>"ForwardGatewayNoOnLine", "当前操作的网关不在线"</para> |
| | | ///<para>"AppTimeOut", "从云端获取数据超时,请重新获取"</para> |
| | | ///<para>"AppNoLogin", "登录过期,请重新登录"</para> |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public Action<string, string> CloudErrorAction; |
| | | |
| | | /// <summary> |
| | | /// 网关文件流内容通知 |
| | |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public Action<string, string> Actions; |
| | | #endregion |
| | | #endregion |
| | | |
| | | #endregion |
| | | |
| | | #region 网关API |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | d = new GetGwVersionAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | d = new GetGwVersionAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "GetZbGwVersionRespon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; |
| | | gatewayTemp.getGwVersion = Newtonsoft.Json.JsonConvert.DeserializeObject<GetGwVersionData>(jobject["Data"].ToString()); |
| | | var getGwVersion = Newtonsoft.Json.JsonConvert.DeserializeObject<GetGwVersionData>(jobject["Data"].ToString()); |
| | | |
| | | if (gatewayTemp.getGwVersion == null) |
| | | if (getGwVersion == null) |
| | | { |
| | | d = new GetGwVersionAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new GetGwVersionAllData { getGwVersion = gatewayTemp.getGwVersion }; |
| | | AppVersion = gatewayTemp.getGwVersion.AppVersion; |
| | | ZigbeeVersion = gatewayTemp.getGwVersion.ZigbeeVersion; |
| | | d = new GetGwVersionAllData { getGwVersion = getGwVersion }; |
| | | //Save(); |
| | | DebugPrintLog($"UI收到通知后的主题_{topic}"); |
| | | } |
| | |
| | | if (topic == gatewayID + "/" + "GetZbGwInfo_Respon") |
| | | { |
| | | var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID }; |
| | | gatewayTemp.getGwInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<GetGwData>(jobject["Data"].ToString()); |
| | | var getGwInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<GetGwData>(jobject["Data"].ToString()); |
| | | |
| | | if (gatewayTemp.getGwInfo == null) |
| | | if (getGwInfo == null) |
| | | { |
| | | data = new GetGwAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | data = new GetGwAllData { getGwData = gatewayTemp.getGwInfo }; |
| | | data = new GetGwAllData { getGwData = getGwInfo }; |
| | | DebugPrintLog($"UI收到通知后的主题_{topic}"); |
| | | } |
| | | } |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | d = new GetMacResponData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | d = new GetMacResponData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "ZbGw/GetMac_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; |
| | | var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<MacAddrData>(jobject["Data"].ToString()); |
| | | |
| | | if (tempData == null) |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | d = new GwReNameAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | d = new GwReNameAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "GwReName_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; |
| | | gatewayTemp.gwRename = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.GwReNameData>(jobject["Data"].ToString()); |
| | | var gwRename = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.GwReNameData>(jobject["Data"].ToString()); |
| | | |
| | | if (gatewayTemp.gwRename == null) |
| | | if (gwRename == null) |
| | | { |
| | | d = new GwReNameAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new GwReNameAllData { gwReNameData = gatewayTemp.gwRename }; |
| | | d = new GwReNameAllData { gwReNameData = gwRename }; |
| | | DebugPrintLog($"UI收到通知后的主题_{ topic}"); |
| | | } |
| | | } |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | d = new GwSetHomeIdAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | d = new GwSetHomeIdAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "GwSetHomeId_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; |
| | | gatewayTemp.gwSetHomeId = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.GwSetHomeIdData>(jobject["Data"].ToString()); |
| | | if (gatewayTemp.gwSetHomeId == null) |
| | | var gwSetHomeId = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.GwSetHomeIdData>(jobject["Data"].ToString()); |
| | | if (gwSetHomeId == null) |
| | | { |
| | | d = new GwSetHomeIdAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new GwSetHomeIdAllData { gwSetHomeIdData = gatewayTemp.gwSetHomeId }; |
| | | d = new GwSetHomeIdAllData { gwSetHomeIdData = gwSetHomeId }; |
| | | DebugPrintLog($"UI收到通知后的主题_{ topic}"); |
| | | } |
| | | } |
| | |
| | | |
| | | Actions -= action; |
| | | DebugPrintLog("GwReName_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | return d; |
| | | }); |
| | | } |
| | | #endregion |
| | | |
| | | #region 获取网关记录的设备属性状态 |
| | | /// <summary> |
| | | ///获取网关记录的设备属性状态 |
| | | /// </summary> |
| | | public async System.Threading.Tasks.Task<GetStatusRecordAllInfo> GetStatusRecordAsync(string deviceAddr, int deviceEpoint) |
| | | { |
| | | return await System.Threading.Tasks.Task.Run(async () => |
| | | { |
| | | GetStatusRecordAllInfo d = null; |
| | | Action<string, string> action = (topic, message) => |
| | | { |
| | | var gatewayID = topic.Split('/')[0]; |
| | | var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | | d = new GetStatusRecordAllInfo { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new GetStatusRecordAllInfo { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "GetStatusRecord_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; |
| | | gatewayTemp.getStatusRecordInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.GetStatusRecordInfo>(jobject["Data"].ToString()); |
| | | |
| | | if (gatewayTemp.getStatusRecordInfo == null) |
| | | { |
| | | d = new GetStatusRecordAllInfo { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new GetStatusRecordAllInfo { getStatusRecordInfo = gatewayTemp.getStatusRecordInfo }; |
| | | DebugPrintLog($"UI收到通知后的主题_{ topic}"); |
| | | } |
| | | } |
| | | }; |
| | | Actions += action; |
| | | DebugPrintLog("GetStatusRecord_Actions 启动" + System.DateTime.Now.ToString()); |
| | | try |
| | | { |
| | | var jObject = new JObject { { "DeviceAddr", deviceAddr }, { "Epoint", deviceEpoint }, { "Cluster_ID", 0 }, { "Command", 80 } }; |
| | | Send("GetStatusRecord", jObject.ToString()); |
| | | |
| | | } |
| | | catch { } |
| | | |
| | | var dateTime = DateTime.Now; |
| | | while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime) |
| | | { |
| | | await System.Threading.Tasks.Task.Delay(10); |
| | | if (d != null) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime) |
| | | { |
| | | d = new GetStatusRecordAllInfo { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | Actions -= action; |
| | | DebugPrintLog("GetStatusRecord_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | return d; |
| | | }); |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | d = new GwLinuxResetResponData { errorMessageBase = ErrorMess(temp.Error) }; |
| | | d = new GwLinuxResetResponData { errorMessageBase = CommonDevice.ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "GwLinuxReset_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; |
| | | var result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"].ToString()); |
| | | |
| | | if (result == null) |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | d = new GwRebootResponAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | d = new GwRebootResponAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "GwReboot_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; |
| | | var result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"].ToString()); |
| | | |
| | | if (result == null) |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | d = new SaveNVFileResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | d = new SaveNVFileResponseAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "ZbGwOperation/SaveNVFile_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; |
| | | gatewayTemp.zbGwOperationSaveNVFileData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.SaveNVFileResponseData>(jobject["Data"].ToString()); |
| | | var zbGwOperationSaveNVFileData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.SaveNVFileResponseData>(jobject["Data"].ToString()); |
| | | |
| | | if (gatewayTemp.zbGwOperationSaveNVFileData == null) |
| | | if (zbGwOperationSaveNVFileData == null) |
| | | { |
| | | d = new SaveNVFileResponseAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new SaveNVFileResponseAllData { saveNVFileResponseData = gatewayTemp.zbGwOperationSaveNVFileData }; |
| | | d = new SaveNVFileResponseAllData { saveNVFileResponseData = zbGwOperationSaveNVFileData }; |
| | | DebugPrintLog($"UI收到通知后的主题_{ topic}"); |
| | | } |
| | | } |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | d = new RestoreNVAllDtta { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | d = new RestoreNVAllDtta { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | |
| | | if (topic == gatewayID + "/" + "ZbGwOperation/RestoreNV_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; |
| | | var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.RestoreNVDtta>(jobject["Data"].ToString()); |
| | | |
| | | if (tempData == null) |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | if (temp == null) |
| | | { |
| | | d = new GwGetChannelResponData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new GwGetChannelResponData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | d = new GwGetChannelResponData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "ZbGw/GetChannel_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; |
| | | var channel = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Channel"].ToString()); |
| | | d = new GwGetChannelResponData { channel = channel }; |
| | | DebugPrintLog($"UI收到通知后的主题_{ topic}"); |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | d = new ChangeChannelResponAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | d = new ChangeChannelResponAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "ZbGw/ChangeChannel_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; |
| | | var tempInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<ChangeChannelResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (tempInfo == null) |
| | |
| | | /// </summary> |
| | | public async System.Threading.Tasks.Task<Panel.PanelSwitchLevelInfo> ClientDataPassthroughBytesAsync(string deviceAddr, int devicePoint, long dataLength, byte[] passData) |
| | | { |
| | | var myDevice = Shared.Common.LocalDevice.Current.GetDevice(deviceAddr, devicePoint); |
| | | |
| | | Panel.PanelSwitchLevelInfo result = null; |
| | | if (Gateway == null) |
| | | |
| | | if (myDevice.Gateway == null) |
| | | { |
| | | result = new Panel.PanelSwitchLevelInfo { errorMessageBase = "当前没有网关" }; |
| | | return result; |
| | |
| | | |
| | | 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) |
| | | { |
| | |
| | | |
| | | else |
| | | { |
| | | result = new Panel.PanelSwitchLevelInfo { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | result = new Panel.PanelSwitchLevelInfo { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "ZbDataPassthrough") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; |
| | | gatewayTemp.clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString()); |
| | | var clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ClientDataPassthroughResponseData>(jobject["Data"].ToString()); |
| | | |
| | | if (gatewayTemp.clientDataPassthroughResponseData == null) |
| | | if (clientDataPassthroughResponseData == null) |
| | | { |
| | | result = new Panel.PanelSwitchLevelInfo { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null) |
| | | if (clientDataPassthroughResponseData?.PassData != null) |
| | | { |
| | | var data = gatewayTemp.clientDataPassthroughResponseData.PassData; |
| | | var data = clientDataPassthroughResponseData.PassData; |
| | | if (data.Length == 14) |
| | | { |
| | | var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString(); |
| | |
| | | } |
| | | }; |
| | | |
| | | Gateway.Actions += action; |
| | | myDevice.Gateway.Actions += action; |
| | | System.Console.WriteLine("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString()); |
| | | |
| | | try |
| | |
| | | { |
| | | result = new Panel.PanelSwitchLevelInfo { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | Gateway.Actions -= action; |
| | | myDevice.Gateway.Actions -= action; |
| | | System.Console.WriteLine("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | return result; |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | d = new PassthroughAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | d = new PassthroughAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "ZbDataPassthrough") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<string>(jobject["Data"].ToString()); |
| | | |
| | | if (gatewayTemp.getGwVersion == null) |
| | | { |
| | | d = new PassthroughAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new PassthroughAllData { passData = temp }; |
| | | DebugPrintLog($"UI收到通知后的主题_{ topic}"); |
| | | } |
| | | d = new PassthroughAllData { passData = temp }; |
| | | DebugPrintLog($"UI收到通知后的主题_{ topic}"); |
| | | } |
| | | }; |
| | | Actions += action; |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = this.getGatewayBaseInfo?.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | |
| | | else |
| | | { |
| | | d = new LinuxUpgradeAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | d = new LinuxUpgradeAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "ZbGwOperation/LinuxUpgrade_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; |
| | | var result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString()); |
| | | d = new LinuxUpgradeAllData { Result = result }; |
| | | DebugPrintLog($"UI收到通知后的主题_{ topic}"); |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | |
| | | else |
| | | { |
| | | d = new ZbGwOperationUpgradeAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | d = new ZbGwOperationUpgradeAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "ZbGwOperation/Upgrade_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; |
| | | gatewayTemp.zbGwOperationUpgradeData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ZbGwOperationUpgradeData>(jobject["Data"].ToString()); |
| | | zbGwOperationUpgradeData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ZbGwOperationUpgradeData>(jobject["Data"].ToString()); |
| | | |
| | | if (gatewayTemp.zbGwOperationUpgradeData == null) |
| | | if (zbGwOperationUpgradeData == null) |
| | | { |
| | | d = new ZbGwOperationUpgradeAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new ZbGwOperationUpgradeAllData { bGwOperationUpgradeData = gatewayTemp.zbGwOperationUpgradeData }; |
| | | d = new ZbGwOperationUpgradeAllData { bGwOperationUpgradeData = zbGwOperationUpgradeData }; |
| | | DebugPrintLog($"UI收到通知后的主题_{ topic}"); |
| | | } |
| | | } |
| | |
| | | /// <returns>The file async.</returns> |
| | | /// <param name="distributedMark">Distributed mark:固件唯一标识</param> |
| | | /// <param name="imageName">Image name:固件版本</param> |
| | | public async System.Threading.Tasks.Task<DownloadFileResponAllData> DownloadFileAsync(string distributedMark, string imageName) |
| | | public async System.Threading.Tasks.Task<CommonDevice.DownloadFileResponAllData> DownloadFileAsync(string distributedMark, string imageName) |
| | | { |
| | | return await System.Threading.Tasks.Task.Run(async () => |
| | | { |
| | | DownloadFileResponAllData d = null; ; |
| | | CommonDevice.DownloadFileResponAllData d = null; ; |
| | | Action<string, string> action = (topic, message) => |
| | | { |
| | | var gatewayID = topic.Split('/')[0]; |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | | d = new DownloadFileResponAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | d = new CommonDevice.DownloadFileResponAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | |
| | | else |
| | | { |
| | | d = new DownloadFileResponAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | d = new CommonDevice.DownloadFileResponAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "DownloadFile_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; |
| | | gatewayTemp.downloadFileResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<DownloadFileResponData>(jobject["Data"].ToString()); |
| | | var downloadFileResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DownloadFileResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (gatewayTemp.downloadFileResponData == null) |
| | | if (downloadFileResponData == null) |
| | | { |
| | | d = new DownloadFileResponAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | d = new CommonDevice.DownloadFileResponAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new DownloadFileResponAllData { downloadFileResponData = gatewayTemp.downloadFileResponData }; |
| | | d = new CommonDevice.DownloadFileResponAllData { downloadFileResponData = downloadFileResponData }; |
| | | DebugPrintLog($"UI收到通知后的主题_{ topic}"); |
| | | } |
| | | } |
| | |
| | | } |
| | | if ((DateTime.Now - dateTime).TotalMilliseconds > 30 * 1000) |
| | | { |
| | | d = new DownloadFileResponAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | d = new CommonDevice.DownloadFileResponAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | |
| | | } |
| | | Actions -= action; |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | |
| | | else |
| | | { |
| | | d = new CheckVDDriveCodeResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | d = new CheckVDDriveCodeResponseAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "VirtualDrive/CatDriveCode_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; |
| | | gatewayTemp.vDriveDriveCodeResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<VDriveDriveCodeResponData>(jobject["Data"].ToString()); |
| | | var vDriveDriveCodeResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<VDriveDriveCodeResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (gatewayTemp.vDriveDriveCodeResponData == null) |
| | | if (vDriveDriveCodeResponData == null) |
| | | { |
| | | d = new CheckVDDriveCodeResponseAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new CheckVDDriveCodeResponseAllData { vDriveDriveCodeResponData = gatewayTemp.vDriveDriveCodeResponData }; |
| | | d = new CheckVDDriveCodeResponseAllData { vDriveDriveCodeResponData = vDriveDriveCodeResponData }; |
| | | DebugPrintLog($"UI收到通知后的主题_{ topic}"); |
| | | } |
| | | } |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | |
| | | else |
| | | { |
| | | d = new VirtualDriveUpgradeResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | d = new VirtualDriveUpgradeResponseAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "VirtualDrive/Upgrade_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; |
| | | gatewayTemp.virtualDriveUpgradeResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<VirtualDriveUpgradeResponData>(jobject["Data"].ToString()); |
| | | virtualDriveUpgradeResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<VirtualDriveUpgradeResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (gatewayTemp.virtualDriveUpgradeResponData == null) |
| | | if (virtualDriveUpgradeResponData == null) |
| | | { |
| | | d = new VirtualDriveUpgradeResponseAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new VirtualDriveUpgradeResponseAllData { virtualDriveUpgradeResponData = gatewayTemp.virtualDriveUpgradeResponData }; |
| | | d = new VirtualDriveUpgradeResponseAllData { virtualDriveUpgradeResponData = virtualDriveUpgradeResponData }; |
| | | DebugPrintLog($"UI收到通知后的主题_{topic}"); |
| | | } |
| | | } |
| | |
| | | |
| | | #endregion |
| | | |
| | | //#region 上传私有数据 |
| | | //private bool backupSuccess = false; |
| | | /// <summary> |
| | | /// 上传私有数据 |
| | | /// </summary> |
| | | /// <returns>The data to gateway.</returns> |
| | | /// <param name="fileName">File name.</param> |
| | | /// <param name="dev">Dev.</param> |
| | | //public async System.Threading.Tasks.Task<SendFileResponseAllData> BackupDataToGateway(string fileName, CommonDevice dev) |
| | | //{ |
| | | // return await System.Threading.Tasks.Task.Run(async () => |
| | | // { |
| | | // SendFileResponseAllData backUpStatus = null; |
| | | // var file = await System.Threading.Tasks.Task.Factory.StartNew(() => Newtonsoft.Json.JsonConvert.SerializeObject(dev)); |
| | | // var data = System.Text.Encoding.UTF8.GetBytes(file); |
| | | // //网关中创建存储数据的文件 |
| | | // var saveFileName = await dev.Gateway.CreateFileAsync(fileName); |
| | | // if (saveFileName != null && saveFileName.Result == 0) |
| | | // { |
| | | // backupSuccess = false; |
| | | // //上传数据到网关 |
| | | // var saveData = await dev.Gateway.SendFileAsync(data); |
| | | // if (saveData != null) |
| | | // { |
| | | // backUpStatus = new SendFileResponseAllData { Result = saveData.Result }; |
| | | // } |
| | | // } |
| | | // var dateTime = DateTime.Now; |
| | | // while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime) |
| | | // { |
| | | // await System.Threading.Tasks.Task.Delay(10); |
| | | // if (backUpStatus != null) |
| | | // { |
| | | // break; |
| | | // } |
| | | // } |
| | | // if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime) |
| | | // { |
| | | // backUpStatus = new SendFileResponseAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | // }; |
| | | // return backUpStatus; |
| | | // }); |
| | | //} |
| | | |
| | | /// <summary> |
| | | /// 下载私有数据 |
| | | /// </summary> |
| | | /// <returns>The data from gateway.</returns> |
| | | /// <param name="fileName">File name.</param> |
| | | /// <param name="dev">Dev.</param> |
| | | //public async System.Threading.Tasks.Task<System.Collections.Generic.List<byte>> DownloadDataFromGateway(string fileName, CommonDevice dev) |
| | | //{ |
| | | // return await System.Threading.Tasks.Task.Run(async () => |
| | | // { |
| | | // byteSource.Clear(); |
| | | // System.Collections.Generic.List<byte> backUpData = null; |
| | | // var dateTime = DateTime.Now; |
| | | // //获取当前文件的具体信息 |
| | | // //var getFileSize = await currentKey.Gateway.GetCurrentFileInfoAsync(fileName); |
| | | // //下载文件 |
| | | // var saveFileName = await dev.Gateway.SetDownloadFileAsync(fileName); |
| | | // Action<string, byte[]> action = (topic, dataContent) => |
| | | // { |
| | | // if (topic.Split('/')[0] + "/" + topic.Split('/')[1] + "/" + topic.Split('/')[2] == topic.Split('/')[0] + "/" + "FileTransfer/DownloadFile") |
| | | // { |
| | | // dateTime = DateTime.Now; |
| | | // byte[] fileBytes = dataContent; |
| | | // if (fileBytes[5] != 1) |
| | | // { |
| | | // if (fileBytes.Length == 2056) |
| | | // { |
| | | // var tempBytes = new byte[2048]; |
| | | // System.Array.Copy(fileBytes, 8, tempBytes, 0, 2048); |
| | | // byteSource.AddRange(tempBytes); |
| | | // } |
| | | // else |
| | | // { |
| | | // var tempBytes = new byte[fileBytes.Length - 8]; |
| | | // System.Array.Copy(fileBytes, 8, tempBytes, 0, tempBytes.Length); |
| | | // byteSource.AddRange(tempBytes); |
| | | // } |
| | | // } |
| | | // else |
| | | // { |
| | | // var tempBytes = new byte[fileBytes.Length - 8]; |
| | | // System.Array.Copy(fileBytes, 8, tempBytes, 0, tempBytes.Length); |
| | | // byteSource.AddRange(tempBytes); |
| | | |
| | | // if (byteSource != null ) |
| | | // { |
| | | // backUpData = byteSource; |
| | | // } |
| | | // } |
| | | |
| | | // } |
| | | // }; |
| | | // dev.Gateway.FileContentAction += action; |
| | | |
| | | // while ((DateTime.Now - dateTime).TotalMilliseconds < 2000) |
| | | // { |
| | | // await System.Threading.Tasks.Task.Delay(10); |
| | | // } |
| | | // dev.Gateway.FileContentAction -= action; |
| | | // return byteSource; |
| | | // }); |
| | | //} |
| | | |
| | | //#endregion |
| | | |
| | | #region 客户端上传文件到网关. |
| | | /// <summary> |
| | | /// 客户端上传文件到网关 |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | dataRes = new CreateFileResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | dataRes = new CreateFileResponseAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "FileTransfer/CreateFile_Respon") |
| | | { |
| | | var security = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID }; |
| | | var result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString()); |
| | | dataRes = new CreateFileResponseAllData { Result = result }; |
| | | DebugPrintLog($"UI收到通知后的主题_{ topic}"); |
| | |
| | | |
| | | if (topic == gatewayID + "/FileTransfer/SendFile_Respon") |
| | | { |
| | | var gateway = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; |
| | | var result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString()); |
| | | dataRes = new SendFileResponseAllData { Result = result }; |
| | | if (result == 0) |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | dataRes = new FileTransferLsDiResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | dataRes = new FileTransferLsDiResponseAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "FileTransfer/lsDir_Respon") |
| | | { |
| | | var lsDir = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID }; |
| | | var resultlsDir = Newtonsoft.Json.JsonConvert.DeserializeObject<FileTransferLsDiResponseData>(jobject["Data"].ToString()); |
| | | if (resultlsDir != null) |
| | | { |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | dataRes = new FileTransferGetFileInfoResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | dataRes = new FileTransferGetFileInfoResponseAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "FileTransfer/GetFileInfo_Respon") |
| | | { |
| | | var lsDir = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID }; |
| | | var resultlsDir = Newtonsoft.Json.JsonConvert.DeserializeObject<FileTransferGetFileInfoResponseData>(jobject["Data"].ToString()); |
| | | if (resultlsDir != null) |
| | | { |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | dataRes = new SetDownloadFileResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | dataRes = new SetDownloadFileResponseAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "FileTransfer/SetDownloadFile_Respon") |
| | | { |
| | | var lsDir = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = CurrentGateWayId }; |
| | | var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<SetDownloadFileResponseData>(jobject["Data"].ToString()); |
| | | if (tempData != null) |
| | | { |
| | |
| | | var tempDa = new SetDownloadFileResponseData(); |
| | | if (tempData.Result == 0) |
| | | { |
| | | ZbGateway.byteSource.Clear(); |
| | | this.byteSource.Clear(); |
| | | } |
| | | tempDa.Result = tempData.Result; |
| | | dataRes.setDownloadFileResponseData = tempDa; |
| | |
| | | #endregion |
| | | |
| | | #region 网关发送文件流到客户端 |
| | | static System.Collections.Generic.List<byte> byteSource = new System.Collections.Generic.List<byte>(); |
| | | private List<byte> byteSource = new List<byte>(); |
| | | ///<summary > |
| | | /// 下载文件中的数据 |
| | | /// </summary> |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | dataRes = new DelFileOrDirResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | dataRes = new DelFileOrDirResponseAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "FileTransfer/DelFileOrDir_Respon") |
| | | { |
| | | var lsDir = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = CurrentGateWayId }; |
| | | var resultDelFileOrDir = Newtonsoft.Json.JsonConvert.DeserializeObject<DelFileOrDirResponseData>(jobject["Data"].ToString()); |
| | | if (resultDelFileOrDir != null) |
| | | { |
| | |
| | | |
| | | if (topic == gatewayID + "/" + "Error_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorResponData>(jobject["Data"].ToString()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | dataRes = new CreateDirResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | dataRes = new CreateDirResponseAllData { errorResponData = temp, errorMessageBase = CommonDevice.ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "FileTransfer/CreateDir_Respon") |
| | | { |
| | | var lsDir = new ZbGateway() { DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = CurrentGateWayId }; |
| | | var resultCreateDir = Newtonsoft.Json.JsonConvert.DeserializeObject<CreateDirResponseData>(jobject["Data"].ToString()); |
| | | if (resultCreateDir != null) |
| | | { |
| | |
| | | if (topic == gatewayID + "/" + "SendAESKey_Respon") |
| | | { |
| | | var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; |
| | | var result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString()); |
| | | sendKeyResponData = new SendKeyResponData { Result = result }; |
| | | DebugPrintLog($"UI收到通知后的主题_{ topic}"); |
| | |
| | | /// <para>进入当前界面时要添加</para> |
| | | /// <para>退出当前界面时要关闭</para> |
| | | /// </summary> |
| | | public static readonly System.Collections.Generic.List<IStatus> StatusList = new System.Collections.Generic.List<IStatus>(); |
| | | public static readonly List<IStatus> StatusList = new List<IStatus>(); |
| | | |
| | | /// <summary> |
| | | /// 设备信息变化 |
| | |
| | | /// </summary> |
| | | IMqttClient localMqttClient = new MqttFactory().CreateMqttClient(); |
| | | bool localMqttIsConnecting; |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public bool localIsConnected; |
| | | /// <summary> |
| | | /// 手机标识 |
| | |
| | | /// 外网的MQTT是否正在连接 |
| | | /// </summary> |
| | | static bool remoteMqttIsConnecting; |
| | | static bool IsLoginAgain; |
| | | |
| | | /// <summary> |
| | | /// 远程MqttClient |
| | | /// </summary> |
| | | public static IMqttClient RemoteMqttClient= new MqttFactory().CreateMqttClient(); |
| | | static bool remoteIsConnected; |
| | | private int IsLogin = 0; |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | static Action actionTemp; |
| | | public static IMqttClient RemoteMqttClient = new MqttFactory().CreateMqttClient(); |
| | | static bool remoteIsConnected; |
| | | |
| | | /// <summary> |
| | | /// 启动远程Mqtt |
| | |
| | | localIsConnected = false;
|
| | | DebugPrintLog($"Local主动断开_{s}");
|
| | | //await localMqttClient.DisconnectAsync(new MQTTnet.Client.Disconnecting.MqttClientDisconnectOptions { }, CancellationToken.None);
|
| | | await localMqttClient.DisconnectAsync(); |
| | | await localMqttClient.DisconnectAsync();
|
| | | }
|
| | | } |
| | | catch (Exception ex) |
| | |
| | | /// <summary>
|
| | | /// 断开远程Mqtt的链接
|
| | | /// </summary> |
| | | public static async System.Threading.Tasks.Task DisConnectRemoteMqttClient(string s="")
|
| | | public static async System.Threading.Tasks.Task DisConnectRemoteMqttClient(string s = "")
|
| | | {
|
| | | try
|
| | | {
|
| | |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 数据发送 |
| | | |
| | | /// <summary> |
| | | /// 发送消息到服务器 |
| | |
| | | if (IsRemote) |
| | | { |
| | | await SendRemoteMsg(topic, message, retain); |
| | | DebugPrintLog($"远程——发送到网关的主题:{topic}_发送到网关的数据:{System.Text.Encoding.UTF8.GetString(message)}_当前网关{CurrentGateWayId}");//{System.DateTime.Now.ToString()}");// DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff") |
| | | DebugPrintLog($"远程——发送到网关的主题:{topic}_发送到网关的数据:{System.Text.Encoding.UTF8.GetString(message)}");//{System.DateTime.Now.ToString()}");// DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff") |
| | | } |
| | | else |
| | | { |
| | | DebugPrintLog($"局域网——发送到网关的主题:{topic}_发送到网关的数据:{System.Text.Encoding.UTF8.GetString(message)}_当前网关{CurrentGateWayId} 是否加密:{IsEncry}");
|
| | | DebugPrintLog($"局域网——发送到网关的主题:{topic}_发送到网关的数据:{System.Text.Encoding.UTF8.GetString(message)}_是否加密:{IsEncry}");
|
| | |
|
| | | if (IsEncry) |
| | | { |
| | |
| | | {
|
| | | await localMqttClient.PublishAsync(new MqttApplicationMessage { Topic = topic, Payload = message, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce, Retain = retain });
|
| | | }
|
| | | catch(Exception e)
|
| | | catch (Exception e)
|
| | | { |
| | | DebugPrintLog($"Local主动断开_{e.Message}");
|
| | | await DisConnectLocalMqttClient(e.Message); |
| | | await StartLocalMqtt("ReConnect");
|
| | | if (localIsConnected)
|
| | | {
|
| | | DebugPrintLog($"局域网——二次发送到网关的主题:{topic}_发送到网关的数据:{System.Text.Encoding.UTF8.GetString(message)}_当前网关{CurrentGateWayId} 是否加密:{IsEncry}");
|
| | | DebugPrintLog($"局域网——二次发送到网关的主题:{topic}_发送到网关的数据:{System.Text.Encoding.UTF8.GetString(message)}_是否加密:{IsEncry}");
|
| | | await localMqttClient.PublishAsync(new MqttApplicationMessage { Topic = topic, Payload = message, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce, Retain = retain });
|
| | | } |
| | | }
|
| | |
| | | return; |
| | | }
|
| | |
|
| | | DebugPrintLog($"局域网——发送到网关的主题:{topic}_发送到网关的数据:{System.Text.Encoding.UTF8.GetString(message)}_当前网关{CurrentGateWayId} 是否加密:{IsEncry}");
|
| | | DebugPrintLog($"局域网——发送到网关的主题:{topic}_发送到网关的数据:{System.Text.Encoding.UTF8.GetString(message)}_是否加密:{IsEncry}");
|
| | |
|
| | | if (IsEncry)
|
| | | {
|
| | |
| | | await StartLocalMqtt("ReConnect");
|
| | | if (localIsConnected)
|
| | | {
|
| | | DebugPrintLog($"局域网——二次发送到网关的主题:{topic}_发送到网关的数据:{System.Text.Encoding.UTF8.GetString(message)}_当前网关{CurrentGateWayId} 是否加密:{IsEncry}");
|
| | | DebugPrintLog($"局域网——二次发送到网关的主题:{topic}_发送到网关的数据:{System.Text.Encoding.UTF8.GetString(message)}_是否加密:{IsEncry}");
|
| | | await localMqttClient.PublishAsync(new MqttApplicationMessage { Topic = topic, Payload = message, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce, Retain = retain });
|
| | | }
|
| | | }
|
| | |
| | | } |
| | | } |
| | | |
| | | [Serializable] |
| | | public class CloudTimeResponse |
| | | { |
| | | public string StateCode; |
| | | public string Info; |
| | | public string CloudTimestamp; |
| | | } |
| | | #endregion |
| | | |
| | | #region 数据接收处理 |
| | | |
| | | /// <summary> |
| | | /// 接收远程数据处理 |
| | |
| | | /// <param name="topic">Topic.</param> |
| | | /// <param name="message">Message.</param> |
| | | /// <param name="e">E.</param> |
| | | static void ReceiveMessage(string topic, string message, byte []payload) |
| | | static void ReceiveMessage(string topic, string message, byte[] payload) |
| | | { |
| | | try |
| | | { |
| | |
| | | } |
| | | |
| | | gwa.GwResDataAction?.Invoke(topic, message); |
| | | gwa.CurrentGateWayId = gatewayID; |
| | | |
| | | var jobject = new Newtonsoft.Json.Linq.JObject(); |
| | | if (topic.Split('/')[0] + "/" + topic.Split('/')[1] == topic.Split('/')[0] + "/" + "FileTransfer") |
| | |
| | | } |
| | | |
| | | #endregion |
| | | #region 设备新上报 |
| | | //步骤1)网关告知客户端有新设备加入zigbee网络。 |
| | | if (topic == gatewayID + "/" + "Device/DeviceJoinZbNet_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | gatewayTemp.deviceDeviceJoinZbNetResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceDeviceJoinZbNetResponData>(jobject["Data"].ToString()); |
| | | if (gatewayTemp.deviceDeviceJoinZbNetResponData == null) |
| | | { |
| | | return; |
| | | } |
| | | //上报类型通知 |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("Device/DeviceJoinZbNet已经通知"); |
| | | gatewayTemp.CurrentGateWayId = gatewayID;//这里的CurrentGateWayId是当前新new ZbGateway的值 |
| | | gwa.ReportAction("Device/DeviceJoinZbNet", gatewayTemp); |
| | | } |
| | | } |
| | | //步骤2)网关告知客户端获取新设备所有端点信息是否成功 |
| | | if (topic == gatewayID + "/" + "Device/IsGetEpointInfo_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | gatewayTemp.deviceIsGetEpointInfoResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceIsGetEpointInfoResponData>(jobject["Data"].ToString()); |
| | | if (gatewayTemp.deviceIsGetEpointInfoResponData == null) |
| | | { |
| | | return; |
| | | } |
| | | //上报类型通知 |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("Device/IsGetEpointInfo已经通知"); |
| | | gatewayTemp.CurrentGateWayId = gatewayID;//这里的CurrentGateWayId是当前新new ZbGateway的值 |
| | | gwa.ReportAction("Device/IsGetEpointInfo", gatewayTemp); |
| | | } |
| | | } |
| | | //步骤3)网关上报节点设备所有端点信息 |
| | | if (topic == gatewayID + "/" + "DeviceInComingRespon") |
| | | { |
| | | //新设备上报,重新发获取所有的设备 |
| | | var tempDevice = new CommonDevice() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | tempDevice.getNewDeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.NewDeviceInfoData>(jobject["Data"].ToString()); |
| | | if (gwa.ReportAction != null)
|
| | | {
|
| | | DebugPrintLog("DeviceInComingRespon已经通知");
|
| | | gwa.ReportAction("DeviceInComingRespon", tempDevice.getNewDeviceInfo);
|
| | | }
|
| | | UpdateDeviceInfo(tempDevice, "DeviceInComingRespon"); |
| | | } |
| | | #endregion |
| | | #region 设备在线状态更新反馈 |
| | | else if (topic == gatewayID + "/" + "OnlineStatusChange_Respon") |
| | | { |
| | | var tempDevice = new CommonDevice() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
|
| | | tempDevice.IsOnline = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["IsOnline"].ToString());
|
| | |
|
| | | if (gwa.ReportAction != null)
|
| | | {
|
| | | DebugPrintLog("OnlineStatusChange已经通知");
|
| | | gwa.ReportAction("OnlineStatusChange", tempDevice);
|
| | | }
|
| | | var infoTempDevice = gwa.DeviceList.Find(obj => obj.DeviceID == tempDevice.DeviceID && obj.DeviceAddr == tempDevice.DeviceAddr);
|
| | | if (infoTempDevice == null)
|
| | | {
|
| | | gwa.DeviceList.Add(tempDevice);
|
| | | UpdateDeviceInfo(tempDevice, "OnlineStatusChange");
|
| | | }
|
| | | else
|
| | | {
|
| | | if (infoTempDevice.DeviceInfo != null)
|
| | | {
|
| | | infoTempDevice.DeviceInfo.IsOnline = infoTempDevice.IsOnline;
|
| | | }
|
| | | UpdateDeviceInfo(infoTempDevice, "OnlineStatusChange");
|
| | | } |
| | | } |
| | | #endregion |
| | | #region 设备被删除上报 |
| | | else if (topic == gatewayID + "/" + "RemoveDeviceRespon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | gatewayTemp.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.RemoveDeviceResponseData>(jobject["Data"].ToString()); |
| | | |
| | | if (gatewayTemp.removeDeviceResponseData != null) |
| | | { |
| | | try |
| | | { |
| | | if (gatewayTemp.removeDeviceResponseData.Result == 0) |
| | | { |
| | | foreach (var delD in gatewayTemp.removeDeviceResponseData.DeviceList) |
| | | { |
| | | var tempDevice = new CommonDevice() { DeviceAddr = jobject.Value<string>("DeviceAddr"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
|
| | | tempDevice.removeDeviceResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.RemoveDeviceResponseData>(jobject["Data"].ToString());
|
| | | if (tempDevice.removeDeviceResponseData == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | else
|
| | | {
|
| | | UpdateDeviceInfo(tempDevice, "RemoveDeviceRespon");
|
| | | if (tempDevice.removeDeviceResponseData.Result == 0)
|
| | | {
|
| | | var infoTempDevice = gwa.DeviceList.Find((CommonDevice obj) => obj.DeviceID == tempDevice.DeviceID && obj.DeviceAddr == tempDevice.DeviceAddr && obj.DeviceEpoint == tempDevice.DeviceEpoint);
|
| | | if (infoTempDevice != null)
|
| | | {
|
| | | gwa.DeviceList.Remove(infoTempDevice);
|
| | | }
|
| | | }
|
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch { } |
| | | } |
| | | } |
| | | #region 设备在线状态更新反馈 |
| | | |
| | | //2020.05.11 删除 |
| | | |
| | | #endregion |
| | | |
| | | #region 设备状态上报 |
| | | else if (topic == gatewayID + "/" + "DeviceStatusReport" + "/" + addr + "/" + epoint + "/" + cluID + "/" + attrId) |
| | | { |
| | |
| | | var tempEpoint = jobject.Value<int>("Epoint"); |
| | | var dataId = jobject.Value<int>("Data_ID"); |
| | | |
| | | var tempDevice = new CommonDevice { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId };
|
| | | var tempDevice = new CommonDevice { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint };
|
| | | tempDevice.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DeviceStatusReportData>(jobject["Data"].ToString());
|
| | | UpdateDeviceInfo(tempDevice, "DeviceStatusReport"); |
| | | } |
| | |
| | | switch ((DeviceType)(deviceID)) |
| | | { |
| | | case DeviceType.DoorLock: |
| | | var doorLock = new DoorLock() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | var doorLock = new DoorLock() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | var OperatingEventNotificationDatad = Newtonsoft.Json.JsonConvert.DeserializeObject<ZigBee.Device.DoorLock.DoorLockOperatingEventNotificationCommand>(jobject["Data"].ToString()); |
| | | if (OperatingEventNotificationDatad != null) |
| | | { |
| | |
| | | switch ((DeviceType)(deviceID)) |
| | | { |
| | | case DeviceType.DoorLock: |
| | | var doorLock = new DoorLock() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | var doorLock = new DoorLock() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | var ProgrammingEventNotificationData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZigBee.Device.DoorLock.DoorLockProgrammingEventNotificationCommand>(jobject["Data"].ToString()); |
| | | if (ProgrammingEventNotificationData != null) |
| | | { |
| | |
| | | UpdateDeviceInfo(doorLock, "DoorLockProgrammingEventNotificationCommand"); |
| | | break; |
| | | } |
| | | } |
| | | }
|
| | | #endregion |
| | | #region IAS安防信息上报 |
| | | else if (topic == gatewayID + "/" + "IASInfoReport") |
| | | { |
| | | var deviceID = jobject.Value<int>("Device_ID"); |
| | | switch ((DeviceType)(deviceID)) |
| | | { |
| | | case DeviceType.IASZone: |
| | | var ias = new IASZone() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | ias.iASInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone.IASInfoData>(jobject["Data"].ToString()); |
| | | //上报类型通知,必需先调用,然后才有通知,否则是空不会通知的 |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("IASInfoReport已经通知"); |
| | | //ias.Save(); |
| | | gwa.ReportAction("IASInfoReport", ias.iASInfo); |
| | | } |
| | | UpdateDeviceInfo(ias, "IASInfoReport"); |
| | | break; |
| | | } |
| | | } |
| | |
|
| | | //2020.05.11 删除
|
| | |
|
| | | #endregion |
| | | #region 下载进度上报 |
| | | else if (topic == gatewayID + "/" + "DownloadFile_Progress") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; |
| | | gatewayTemp.downloadFileProgressResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<DownloadFileProgressResponData>(jobject["Data"].ToString()); |
| | | if (gatewayTemp.downloadFileProgressResponData == null) |
| | | gwa.downloadFileProgressResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DownloadFileProgressResponData>(jobject["Data"].ToString()); |
| | | if (gwa.downloadFileProgressResponData == null) |
| | | { |
| | | return; |
| | | } |
| | |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("DownloadFileProgress"); |
| | | gatewayTemp.CurrentGateWayId = gatewayID;//这里的CurrentGateWayId是当前新new ZbGateway的值 |
| | | gwa.ReportAction("DownloadFileProgress", gatewayTemp); |
| | | gwa.ReportAction("DownloadFileProgress", gwa); |
| | | } |
| | | } |
| | | else if (topic == gatewayID + "/" + "ZbGwOperation/Upgrade_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; |
| | | gatewayTemp.zbGwOperationUpgradeData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGwOperationUpgradeData>(jobject["Data"].ToString()); |
| | | if (gatewayTemp.zbGwOperationUpgradeData == null) |
| | | gwa.zbGwOperationUpgradeData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGwOperationUpgradeData>(jobject["Data"].ToString()); |
| | | if (gwa.zbGwOperationUpgradeData == null) |
| | | { |
| | | return; |
| | | } |
| | |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("协调器升级百分比"); |
| | | gatewayTemp.CurrentGateWayId = gatewayID;//这里的CurrentGateWayId是当前新new ZbGateway的值 |
| | | gwa.ReportAction("CordinatorUpgradePercent", gatewayTemp); |
| | | gwa.ReportAction("CordinatorUpgradePercent", gwa); |
| | | } |
| | | } |
| | | else if (topic == gatewayID + "/" + "OTA/Schedule_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; |
| | | gatewayTemp.oTAScheduleResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<OTAScheduleResponData>(jobject["Data"].ToString()); |
| | | gwa.oTAScheduleResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.OTAScheduleResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (gatewayTemp.oTAScheduleResponData == null) |
| | | if (gwa.oTAScheduleResponData == null) |
| | | { |
| | | return; |
| | | } |
| | |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("节点设备升级百分比"); |
| | | gatewayTemp.CurrentGateWayId = gatewayID;//这里的CurrentGateWayId是当前新new ZbGateway的值 |
| | | gwa.ReportAction("DeviceUpgradePercent", gatewayTemp); |
| | | gwa.ReportAction("DeviceUpgradePercent", gwa); |
| | | } |
| | | } |
| | | else if (topic == gatewayID + "/" + "VirtualDrive/Upgrade_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; |
| | | gatewayTemp.virtualDriveUpgradeResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<VirtualDriveUpgradeResponData>(jobject["Data"].ToString()); |
| | | gwa.virtualDriveUpgradeResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<VirtualDriveUpgradeResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (gatewayTemp.virtualDriveUpgradeResponData == null) |
| | | if (gwa.virtualDriveUpgradeResponData == null) |
| | | { |
| | | return; |
| | | } |
| | |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("虚拟驱动升级百分比"); |
| | | gatewayTemp.CurrentGateWayId = gatewayID;//这里的CurrentGateWayId是当前新new ZbGateway的值 |
| | | gwa.ReportAction("VirtualDriveUpgrade", gatewayTemp); |
| | | gwa.ReportAction("VirtualDriveUpgrade", gwa); |
| | | } |
| | | } |
| | | #endregion |
| | | #region 重启网关系统 |
| | | else if (topic == gatewayID + "/" + "GwReboot_Respon") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID") }; |
| | | gatewayTemp.gwRebootResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<GwRebootResponData>(jobject["Data"].ToString()); |
| | | var gwRebootResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<GwRebootResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (gatewayTemp.gwRebootResponData == null) |
| | | if (gwRebootResponData == null) |
| | | { |
| | | return; |
| | | } |
| | |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("GwReboot_Respon已经通知"); |
| | | gatewayTemp.CurrentGateWayId = gatewayID;//这里的CurrentGateWayId是当前新new ZbGateway的值 |
| | | gwa.ReportAction("GwReboot_Respon", gatewayTemp); |
| | | gwa.ReportAction("GwReboot_Respon", gwRebootResponData); |
| | | } |
| | | } |
| | | #endregion |
| | |
| | | } |
| | | } |
| | | #endregion |
| | | #region 节点设备默认反馈 |
| | | else if (topic == gatewayID + "/" + "DeviceDefaultAck") |
| | | { |
| | | var deviceDefaultAck = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID }; |
| | | if (deviceDefaultAck == null) |
| | | { |
| | | return; |
| | | } |
| | | //上报类型通知 |
| | | if (gwa.ReportAction != null) |
| | | { |
| | | DebugPrintLog("DeviceDefaultAck"); |
| | | gwa.ReportAction("DeviceDefaultAck", deviceDefaultAck); |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | #region 设备请求APP获取升级数据 |
| | | else if (topic == gatewayID + "/" + "ZbDataPassthrough") |
| | |
| | | //上报类型通知 |
| | | if (gwa.ReportAction != null) |
| | | {
|
| | | var clientDataPassthrough = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString());
|
| | | var clientDataPassthrough = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ClientDataPassthroughResponseData>(jobject["Data"].ToString());
|
| | | if (clientDataPassthrough != null)
|
| | | {
|
| | | DebugPrintLog("DeviceRequestAcUpdateData");
|
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 保存缓存 |
| | | |
| | | /// <summary> |
| | | /// 重新保存设备 |
| | | /// </summary> |
| | | public void ReSave() |
| | | { |
| | | Global.WriteFileByBytesByHomeId(FilePath, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this))); |
| | | } |
| | | #endregion |
| | | |
| | | #region 调试打印 |
| | | |
| | | /// <summary> |
| | | /// 调试时打开打印信息,true:打印,false:不打印 |
| | | /// </summary> |
| | | /// <param name="msg">Message.</param> |
| | | /// <param name="flage">If set to <c>true</c> flage.</param> |
| | | public static void DebugPrintLog(string msg, bool flage = true) |
| | | { |
| | | #if DEBUG |
| | | if (flage == true) |
| | | { |
| | | if (msg.Contains("DeviceStatusReport") == false) |
| | | { |
| | | System.Console.WriteLine(msg + " " + System.DateTime.Now.ToLongTimeString() + " " + System.DateTime.Now.Millisecond); |
| | | } |
| | | } |
| | | #endif |
| | | } |
| | | |
| | | #endregion |
| | | } |
| | | } |