| | |
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 设备获取硬件信息后的回调函数
|
| | | /// </summary>
|
| | | private Dictionary<string, Action<CommonDevice, CommonDevice.DeviceStatusReportData>> dicDeviceHardInfoBackAction = new Dictionary<string, Action<CommonDevice, CommonDevice.DeviceStatusReportData>>();
|
| | | /// 获取硬件信息的对象设备
|
| | | /// </summary>
|
| | | private HashSet<string> hsGetHardInfoDevice = new HashSet<string>();
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 主入口函数_________________________
|
| | |
| | | /// </summary>
|
| | | /// <param name="device">设备回路</param>
|
| | | /// <param name="backAction">回调函数</param>
|
| | | public void SetAllHardFirmwareInfoToDevice(CommonDevice device, Action<CommonDevice, CommonDevice.DeviceStatusReportData> backAction = null)
|
| | | public void SetAllHardFirmwareInfoToDevice(CommonDevice device)
|
| | | {
|
| | | if (device == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | lock (hsGetHardInfoDevice)
|
| | | {
|
| | | //先移除
|
| | | this.RemoveDeviceHardInfoThread(device);
|
| | |
|
| | | string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
|
| | | this.hsGetHardInfoDevice.Add(mainkeys);
|
| | |
|
| | | if (backAction != null)
|
| | | {
|
| | | //回调函数
|
| | | this.dicDeviceHardInfoBackAction[mainkeys] = backAction;
|
| | | }
|
| | | //设置设备的硬件信息(需要等待推送后才会更改)
|
| | | this.SetHardFirmwareInfoToDevice(device);
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 设置设备的硬件信息(需要等待推送后才会更改)
|
| | | /// </summary>
|
| | | /// <param name="device"></param>
|
| | | private void SetHardFirmwareInfoToDevice(CommonDevice device)
|
| | | {
|
| | | if (HdlGatewayReceiveLogic.Current.IsEsixt("DeviceGetHardFirmwareInfo") == false)
|
| | | {
|
| | | //添加事件
|
| | | HdlGatewayReceiveLogic.Current.AddAttributeEvent("DeviceGetHardFirmwareInfo", ReceiveComandDiv.A设备属性上报, this.SetHardFirmwareInfoByInterfaceResult);
|
| | | }
|
| | | //发送命令
|
| | | this.SetHardFirmwareInfoComand(device);
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 发送命令___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 发送获取硬件信息的命令
|
| | | /// </summary>
|
| | | /// <param name="device"></param>
|
| | | public void SetHardFirmwareInfoComand(CommonDevice device)
|
| | | {
|
| | | var jObject = new Newtonsoft.Json.Linq.JObject
|
| | | {
|
| | | { "DeviceAddr",device.DeviceAddr },
|
| | |
| | | {
|
| | | new Newtonsoft.Json.Linq.JObject
|
| | | {
|
| | | { "AttriButeId", 4}
|
| | | { "AttriButeId", 4}//生产商名字
|
| | | },
|
| | | new Newtonsoft.Json.Linq.JObject
|
| | | {
|
| | | { "AttriButeId", 5}
|
| | | { "AttriButeId", 5}//型号码(也叫模块ID)
|
| | | },
|
| | | new Newtonsoft.Json.Linq.JObject
|
| | | {
|
| | | { "AttriButeId", 6}
|
| | | { "AttriButeId", 6}//生产日期
|
| | | },
|
| | | new Newtonsoft.Json.Linq.JObject
|
| | | {
|
| | | { "AttriButeId", 7}
|
| | | { "AttriButeId", 7}//电源
|
| | | },
|
| | | new Newtonsoft.Json.Linq.JObject
|
| | | {
|
| | | { "AttriButeId", 13}
|
| | | { "AttriButeId", 13}//序列号
|
| | | }
|
| | | };
|
| | | var data = new Newtonsoft.Json.Linq.JObject { { "AttriBute", attriBute } };
|
| | | jObject.Add("Data", data);
|
| | | device.Gateway?.Send(("GetDeviceStatus"), jObject.ToString());
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 设置属性___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 设置设备的硬件信息 -1:异常 0:推送的这个东西并不是硬件信息 1:正常
|
| | | /// </summary>
|
| | | /// <param name="report">上报信息</param>
|
| | | /// <param name="device">设备对象</param>
|
| | | /// <returns></returns>
|
| | | public int SetHardFirmwareInfo(CommonDevice.DeviceStatusReportData report, CommonDevice device)
|
| | | {
|
| | | if (report == null)
|
| | | {
|
| | | return -1;
|
| | | }
|
| | | //属性是否改变
|
| | | bool AttriButeChanged = false;
|
| | | //是否是正确的推送数据
|
| | | bool isRightData = false;
|
| | | foreach (var data in report.AttriBute)
|
| | | {
|
| | | //生产商名字
|
| | | if (data.AttributeId == 4)
|
| | | {
|
| | | isRightData = true;
|
| | | if (data.AttriButeDataHex.Length > 2)
|
| | | {
|
| | | var value = UserCenterLogic.TranslateHexadecimalIntoText(data.AttriButeDataHex.Substring(2));
|
| | | if (device.ManufacturerName != value)
|
| | | {
|
| | | //属性变更了
|
| | | AttriButeChanged = true;
|
| | | }
|
| | | device.ManufacturerName = value;
|
| | | }
|
| | | }
|
| | | //型号码(也叫模块ID)
|
| | | if (data.AttributeId == 5)
|
| | | {
|
| | | isRightData = true;
|
| | | if (data.AttriButeDataHex.Length > 2)
|
| | | {
|
| | | var value = UserCenterLogic.TranslateHexadecimalIntoText(data.AttriButeDataHex.Substring(2));
|
| | | if (device.ModelIdentifier != value)
|
| | | {
|
| | | //属性变更了
|
| | | AttriButeChanged = true;
|
| | | }
|
| | | device.ModelIdentifier = value;
|
| | | }
|
| | | }
|
| | | //生产日期
|
| | | if (data.AttributeId == 6)
|
| | | {
|
| | | isRightData = true;
|
| | | if (data.AttriButeDataHex.Length > 2)
|
| | | {
|
| | | var value = UserCenterLogic.TranslateHexadecimalIntoText(data.AttriButeDataHex.Substring(2));
|
| | | if (device.ProductionDate != value)
|
| | | {
|
| | | //属性变更了
|
| | | AttriButeChanged = true;
|
| | | }
|
| | | device.ProductionDate = value;
|
| | | }
|
| | | }
|
| | | //电源
|
| | | if (data.AttributeId == 7)
|
| | | {
|
| | | isRightData = true;
|
| | | device.PowerSource = data.AttriButeData;
|
| | | }
|
| | | //序列号
|
| | | if (data.AttributeId == 13)
|
| | | {
|
| | | isRightData = true;
|
| | | if (data.AttriButeDataHex.Length > 2)
|
| | | {
|
| | | string value;
|
| | | if (Common.LocalDevice.Current.IsHdlDevice(device) == false)
|
| | | {
|
| | | //第三方设备
|
| | | value = data.AttriButeDataHex.Substring(2);
|
| | | }
|
| | | else
|
| | | {
|
| | | //河东设备
|
| | | value = UserCenterLogic.TranslateHexadecimalIntoText(data.AttriButeDataHex.Substring(2));
|
| | | }
|
| | | if (device.SerialNumber != value)
|
| | | {
|
| | | //属性变更了
|
| | | AttriButeChanged = true;
|
| | | }
|
| | | device.SerialNumber = value;
|
| | | }
|
| | | }
|
| | | }
|
| | | if (isRightData == false)
|
| | | {
|
| | | //这个不是硬件信息的推送
|
| | | return 0;
|
| | | }
|
| | |
|
| | | //如果属性变更了
|
| | | if (AttriButeChanged == true)
|
| | | {
|
| | | if (device.IsCustomizeImage == false)
|
| | | {
|
| | | //UI重新生成
|
| | | device.IconPath = string.Empty;
|
| | | device.ReSave();
|
| | | }
|
| | | }
|
| | | return 1;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 接口推送处理_______________________
|
| | |
|
| | | /// <summary>
|
| | | /// 根据接口推送的信息,设置设备硬件信息
|
| | | /// </summary>
|
| | | /// <param name="device"></param>
|
| | | private void SetHardFirmwareInfoByInterfaceResult(CommonDevice device)
|
| | | {
|
| | | string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
|
| | | if (this.hsGetHardInfoDevice.Contains(mainKeys) == false)
|
| | | {
|
| | | //推送的这个东西并不是指定的设备
|
| | | return;
|
| | | }
|
| | | //设置设备硬件信息
|
| | | var localDevice = Common.LocalDevice.Current.GetDevice(mainKeys);
|
| | | if (localDevice == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | lock (hsGetHardInfoDevice)
|
| | | {
|
| | | //-1:异常 0:推送的这个东西并不是硬件信息 1:正常
|
| | | if (this.SetHardFirmwareInfo(device.DeviceStatusReport, localDevice) != 1)
|
| | | {
|
| | | return;
|
| | | }
|
| | | localDevice.ReSave();
|
| | |
|
| | | this.hsGetHardInfoDevice.Remove(mainKeys);
|
| | | if (this.dicDeviceHardInfoBackAction.ContainsKey(mainKeys) == true)
|
| | | {
|
| | | var action = this.dicDeviceHardInfoBackAction[mainKeys];
|
| | | //调用回调函数
|
| | | action?.Invoke(device, device.DeviceStatusReport);
|
| | | //然后移除
|
| | | this.dicDeviceHardInfoBackAction.Remove(mainKeys);
|
| | | action = null;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 移除监听线程_______________________
|
| | |
|
| | | /// <summary>
|
| | | /// 移除获取设备硬件信息的监听线程
|
| | | /// </summary>
|
| | | /// <param name="device"></param>
|
| | | public void RemoveDeviceHardInfoThread(CommonDevice device)
|
| | | {
|
| | | lock (hsGetHardInfoDevice)
|
| | | {
|
| | | string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
|
| | | if (this.hsGetHardInfoDevice.Contains(mainKeys) == true)
|
| | | {
|
| | | this.hsGetHardInfoDevice.Remove(mainKeys);
|
| | | }
|
| | | if (this.dicDeviceHardInfoBackAction.ContainsKey(mainKeys) == true)
|
| | | {
|
| | | var action = this.dicDeviceHardInfoBackAction[mainKeys];
|
| | | //然后移除
|
| | | this.dicDeviceHardInfoBackAction.Remove(mainKeys);
|
| | | action = null;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|