| | |
| | | /// </summary> |
| | | public int DeviceEpoint; |
| | | /// <summary> |
| | | /// 设备id |
| | | /// 实际的设备id |
| | | /// <para>258:color dimmable light,调关灯 </para> |
| | | /// <para>10:Door lock,门锁</para> |
| | | /// <para>514:Window covering device,窗帘</para> |
| | |
| | | /// <para>262:Light sensor,光照传感器</para> |
| | | /// <para>1026:sensor,传感器,具体类型的传感器DeviceType来区分</para> |
| | | /// </summary> |
| | | public int DeviceID; |
| | | public int DeviceID;
|
| | | /// <summary>
|
| | | /// <para>2020.09.21追加:为了对应第三方设备,以及之后的多设备ID问题,追加的变量</para>
|
| | | /// <para>这是个特殊的,并且不保存在文件当中的ID, DeviceType由此值映射出来</para>
|
| | | /// <para>当设备是河东设备时,它与DeviceID相等</para>
|
| | | /// <para>当是真正的第三方设备时,它有可能与DeviceID不相等</para>
|
| | | /// <para>比如:2和256都是继电器,那么【DeviceID为2 或者 DeviceID为256】 而 【ExDeviceID固定为2】,【DeviceType为OnOffOutput】</para>
|
| | | /// <para>通俗来说:DeviceID是实际正确的ID,而【ExDeviceID是一种所属概念的ID】</para>
|
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public int ExDeviceID; |
| | | /// <summary> |
| | | /// 该字段主要针对IAS安防设备设立。所有IAS安防设备共用一个DeviceID为1026。所以要区分子设备类型,需要该字段。 |
| | | /// 瞬间数据上报的传感器 (MomentStatus=1 TriggerZoneStatus>=1<报警>) |
| | |
| | | { |
| | | get |
| | | { |
| | | var deviceType = Type.ToString(); |
| | | var fileName = "Device_" + deviceType + "_" + DeviceAddr; |
| | | fileName += "_" + (DeviceEpoint.ToString().Length < 2 ? "0" + DeviceEpoint.ToString() : DeviceEpoint.ToString()); |
| | | return fileName; |
| | | //2020.09.21 对应第三方设备可以入网,设备文件名字,去掉 deviceType |
| | | return "Device_" + DeviceAddr + "_" + DeviceEpoint.ToString().PadLeft(2, '0'); |
| | | } |
| | | } |
| | | |
| | |
| | | /// <summary>
|
| | | /// 由设备字符串比特恢复设备对象
|
| | | /// </summary>
|
| | | /// <param name="strDeviceType">设备DeviceType的字符串类型</param>
|
| | | /// <param name="intDeviceType">设备DeviceType的整型值</param>
|
| | | /// <param name="strDeviceByte">设备Json文件转为比特后再转为的字符串</param>
|
| | | /// <returns></returns> |
| | | public static CommonDevice CommonDeviceByByteString(string strDeviceType, string strDeviceByte) |
| | | { |
| | | public static CommonDevice CommonDeviceByByteString(int intDeviceType, string strDeviceByte) |
| | | {
|
| | | //这是河东的特殊端点,不需要处理
|
| | | if (intDeviceType == 49408)
|
| | | {
|
| | | return null;
|
| | | } |
| | | |
| | | CommonDevice device = null; |
| | | if (strDeviceType == ZigBee.Device.DeviceType.DimmableLight.ToString()) |
| | | if (intDeviceType == (int)DeviceType.DimmableLight || intDeviceType == 3) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<DimmableLight>(strDeviceByte); |
| | | device.ExDeviceID = (int)DeviceType.DimmableLight; |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.OnOffOutput.ToString()) |
| | | else if (intDeviceType == (int)DeviceType.OnOffOutput || intDeviceType == 256) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<ToggleLight>(strDeviceByte); |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<ToggleLight>(strDeviceByte);
|
| | | device.ExDeviceID = (int)DeviceType.OnOffOutput; |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.ColorDimmerSwitch.ToString()) |
| | | else if (intDeviceType == (int)DeviceType.ColorDimmerSwitch) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<ColorDimmerSwitch>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.LevelControlSwitch.ToString()) |
| | | else if (intDeviceType == (int)DeviceType.LevelControlSwitch) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<LevelControlSwitch>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.WindowCoveringDevice.ToString()) |
| | | else if (intDeviceType == (int)DeviceType.WindowCoveringDevice) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<Rollershade>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.WindowCoveringController.ToString()) |
| | | else if (intDeviceType == (int)DeviceType.WindowCoveringController) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<WindowCoveringController>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.OnOffSwitch.ToString()) |
| | | else if (intDeviceType == (int)DeviceType.OnOffSwitch) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<Panel>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.IASZone.ToString()) |
| | | else if (intDeviceType == (int)DeviceType.IASZone) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.OtaDevice.ToString() || strDeviceType == ZigBee.Device.DeviceType.OtaPanelDevice.ToString()) |
| | | else if (intDeviceType == (int)DeviceType.OtaDevice || intDeviceType == (int)DeviceType.OtaPanelDevice) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<OTADevice>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.AirSwitch.ToString()) |
| | | else if (intDeviceType == (int)DeviceType.AirSwitch) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<AirSwitch>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.Repeater.ToString()) |
| | | else if (intDeviceType == (int)DeviceType.Repeater) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<Repeater>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.Thermostat.ToString()) |
| | | else if (intDeviceType == (int)DeviceType.Thermostat) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<AC>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.Transverter.ToString()) |
| | | else if (intDeviceType == (int)DeviceType.Transverter) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<Transverter>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.DoorLock.ToString()) |
| | | else if (intDeviceType == (int)DeviceType.DoorLock) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<DoorLock>(strDeviceByte); |
| | | }
|
| | | else if (strDeviceType == ZigBee.Device.DeviceType.TemperatureSensor.ToString()) |
| | | else if (intDeviceType == (int)DeviceType.TemperatureSensor) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<TemperatureSensor>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.FreshAirHumiditySensor.ToString()) |
| | | else if (intDeviceType == (int)DeviceType.FreshAirHumiditySensor) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<HumiditySensor>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.FreshAir.ToString()) |
| | | else if (intDeviceType == (int)DeviceType.FreshAir) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<FreshAir>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.PMSensor.ToString()) |
| | | else if (intDeviceType == (int)DeviceType.PMSensor) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<PMSensor>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.ColorTemperatureLight.ToString()) |
| | | else if (intDeviceType == (int)DeviceType.ColorTemperatureLight) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<ColorTemperatureLight>(strDeviceByte); |
| | | }
|
| | | else if (strDeviceType == ZigBee.Device.DeviceType.Buzzer.ToString()) |
| | | else if (intDeviceType == (int)DeviceType.Buzzer) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<Buzzer>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.ColorDimmableLight.ToString()) |
| | | else if (intDeviceType == (int)DeviceType.ColorDimmableLight) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<ColorDimmableLight>(strDeviceByte); |
| | | } |
| | | else if (strDeviceType == ZigBee.Device.DeviceType.DimmerSwitch.ToString()) |
| | | else if (intDeviceType == (int)DeviceType.DimmerSwitch) |
| | | { |
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<DimmerSwitch>(strDeviceByte); |
| | | } |
| | | else |
| | | { |
| | | return null; |
| | | {
|
| | | device = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice>(strDeviceByte); |
| | | } |
| | | |
| | | //这是河东的特殊端点,不需要处理 |
| | | if (device.DeviceEpoint == 242 && intDeviceType == 97)
|
| | | {
|
| | | return null;
|
| | | } |
| | | |
| | | if (device.ExDeviceID == 0)
|
| | | {
|
| | | //赋初始值
|
| | | device.ExDeviceID = device.DeviceID;
|
| | | } |
| | | |
| | | //能少存一个变量就少存一个 |
| | | device.Type = (DeviceType)device.DeviceID; |
| | | device.Type = (DeviceType)device.ExDeviceID; |
| | | |
| | | return device; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 由设备路径恢复设备对象 |
| | | /// </summary> |
| | | /// <returns>The device by file path.</returns> |
| | | /// <param name="deviceFilePath">Device file path.</param> |
| | | public static CommonDevice CommonDeviceByFilePath(string deviceFilePath) |
| | | { |
| | | var v = deviceFilePath.Split('_'); |
| | | if (v.Length < 3) |
| | | { |
| | | return null; |
| | | } |
| | | return CommonDeviceByByteString(v[1], System.Text.Encoding.UTF8.GetString(Shared.Common.Global.ReadFileByHomeId(deviceFilePath))); |
| | | } |
| | | |
| | | /// <summary> |