using Shared.Phone.UserCenter;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using ZigBee.Device;
namespace Shared.Common
{
///
/// 本地设备
///
public class LocalDevice
{
#region ■ 变量声明___________________________
///
/// 本地设备
///
private static LocalDevice m_Current = null;
///
/// 本地设备
///
public static LocalDevice Current
{
get
{
if (m_Current == null)
{
m_Current = new LocalDevice();
}
return m_Current;
}
set
{
m_Current = value;
}
}
///
/// 本地所有设备的缓存
///
public List listAllDevice
{
get
{
lock (dicAllDevice)
{
//先获取全部的Mac
var listMac = new List();
foreach (var strMac in this.dicDeviceEpoint.Keys)
{
listMac.Add(strMac);
}
//根据MAC地址,获取全部回路的设备对象(强制排序)
return this.GetDevicesByMac(listMac);
}
}
}
///
/// R文件里面设备模块ID的翻译名字的前缀
///
public const string deviceModelIdName = "uDeviceModelId";
///
/// R文件里面所有设备名字的ID
///
public Dictionary dicDeviceAllNameID = null;
///
/// 设备的模块ID的枚举(keys:模块ID value:设备具体类型值-设备所属类型值(自定义的值,嘛,只要不重复就可以)
///
private Dictionary dicDeviceModelIdEnum = null;
///
/// 需要转换的设备的模块ID(keys:旧模块ID,value:新模块ID)
///
private Dictionary dicDeviceModelIdChanged = null;
///
/// 图片共有(keys:指定设备的具体类型 value:指定共有对象的具体类型)
///
private Dictionary dicPictrueShard = null;
///
/// 本地所有设备的缓存(非公开)
///
private Dictionary dicAllDevice = new Dictionary();
///
/// 本地所有的顶点升级设备(非公开,主键是MAC+200端口)
///
private Dictionary dicOTADevice = new Dictionary();
///
/// 设备的总回路(keys:Mac地址 value:全部端口号)
///
private Dictionary> dicDeviceEpoint = new Dictionary>();
///
/// 物理设备属于哪个房间的记录
///
private Dictionary dicDeviceRoomId = null;
#endregion
#region ■ 刷新设备___________________________
///
/// 刷新本地设备信息
///
public void ReFreshByLocal()
{
this.dicAllDevice.Clear();
this.dicDeviceEpoint.Clear();
//初始化R文件里面设备默认名字的ID
this.InitDeviceDefultNameIDList();
//获取本地全部的设备文件
List listFile = this.GetAllDeviceFile();
foreach (string file in listFile)
{
CommonDevice device = null;
//反序列化为指定的类,不然数据会丢失而导致无法强转
try
{
device = CommonDevice.CommonDeviceByFilePath(file);
}
catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); }
if (device == null || device.CurrentGateWayId == null)
{
//失效的文件,没有网关id的都删除掉
Global.DeleteFilebyHomeId(file);
continue;
}
//如果这个设备的网关ID不存在的话
if (HdlGatewayLogic.Current.IsGatewayExist(device.CurrentGateWayId) == false)
{
if (UserCenterResourse.UserInfo.AuthorityNo == 3)
{
//如果他是成员的话,帮他新建一个网关
HdlGatewayLogic.Current.AddVirtualGateway(device.CurrentGateWayId);
}
else
{
//如果是主人,或者管理员,那么这个文件是非法的,直接删除
Global.DeleteFilebyHomeId(file);
continue;
}
}
string mainKey = this.GetDeviceMainKeys(device);
if (device is OTADevice)
{
//200端口不需要处理
this.dicOTADevice[mainKey] = (OTADevice)device;
continue;
}
//添加缓存
this.dicAllDevice[mainKey] = device;
//回路收集
if (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == false)
{
this.dicDeviceEpoint[device.DeviceAddr] = new HashSet();
}
this.dicDeviceEpoint[device.DeviceAddr].Add(device.DeviceEpoint);
//检测Ui图片是否正确,这个图片本地是否存在?
if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(device.IconPath)) == true)
{
//不存在的话,重新生成
device.IconPath = string.Empty;
device.ReSave();
HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
}
}
//成员身份的时候,删除掉非法的网关文件
this.DeleteGatewayFileByMemberModel();
//初始化物理设备所属房间的记录
this.InitRealDeviceRoomId();
}
///
/// 成员身份的时候,删除掉非法的网关文件
///
private void DeleteGatewayFileByMemberModel()
{
if (UserCenterResourse.UserInfo.AuthorityNo != 3)
{
return;
}
var listId = new HashSet();
lock (dicAllDevice)
{
foreach (var device in this.dicAllDevice.Values)
{
if (listId.Contains(device.CurrentGateWayId) == false)
{
listId.Add(device.CurrentGateWayId);
}
}
}
var listGateway = HdlGatewayLogic.Current.GetAllLocalGateway();
foreach (var gateway in listGateway)
{
string gwId = gateway.GwId;
if (listId.Contains(gwId) == false)
{
//这个网关对于当前这个成员来说是非法的
HdlGatewayLogic.Current.DeleteGatewayFile(gwId);
}
}
}
#endregion
#region ■ 添加设备___________________________
///
/// 将指定网关的设备存入缓存中(从新获取镜像)
/// -1:异常 1:正常 2:设备信息缺损
///
/// 网关对象
public int SetDeviceToMemmoryByGateway(ZbGateway zbGateway)
{
//从网关获取全部的设备
int statu = 0;
List listDevice = new List();
List list = this.GetDeviceListFromGateway(zbGateway, ref statu, true);
if (list == null)
{
return -1;
}
listDevice.AddRange(list);
//获取这个网关的本地所有设备
string gwID = zbGateway.GwId;
List listLocalDevices = this.GetDeviceByGatewayID(gwID);
//获取ota设备
foreach (var ota in this.dicOTADevice.Values)
{
if (ota.CurrentGateWayId == gwID)
{
listLocalDevices.Add(ota);
}
}
Dictionary dicExist = new Dictionary();
foreach (var device in listLocalDevices)
{
string maikey = this.GetDeviceMainKeys(device);
dicExist[maikey] = device;
}
//添加设备的缓存
var listDriveDevice = new List();
for (int i = 0; i < listDevice.Count; i++)
{
var device = listDevice[i];
if (device == null || device.DeviceAddr == null)
{
continue;
}
//添加缓存
this.AddDeviceToMemory(ref device);
//移除存在的设备内存
string maikey = this.GetDeviceMainKeys(device);
if (dicExist.ContainsKey(maikey) == true)
{
dicExist.Remove(maikey);
}
//获取设备的固定属性
HdlDeviceFixedAttributeLogic.Current.SetAllFixedAttributeToDevice(device);
//对未命名的虚拟设备重新命名
if (device.DriveCode > 0 && this.GetSimpleEpointName(device) == string.Empty)
{
listDriveDevice.Add(device);
}
}
if (listDriveDevice.Count > 0)
{
//如果虚拟设备还没有名字的话
HdlThreadLogic.Current.RunThread(() =>
{
//如果不这样放在一个线程里,有可能对Dictionary产生影响
foreach (var myDevice in listDriveDevice)
{
//根据设备类型获取名称
var dName = this.GetDeviceObjectText(new List() { myDevice }, false);
//在端点名字的后面附加【回路】字样
dName += "(" + myDevice.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")";
this.ReName(myDevice, dName, ShowErrorMode.NO);
}
});
}
//只有完全获取的时候,才会去处理删除的问题
if (statu != 1)
{
return statu;
}
//如果本地和网关的设备不一致的时候,删除本地的设备
var listDeleteMac = new List();
foreach (var device in dicExist.Values)
{
if (device is OTADevice)
{
this.DeleteMemmoryOtaDevice(device.DeviceAddr);
}
else
{
this.DeleteMemmoryDevice(device, true);
}
if (listDeleteMac.Contains(device.DeviceAddr) == false)
{
//收集被删除的Mac
listDeleteMac.Add(device.DeviceAddr);
}
}
if (listDeleteMac.Count > 0)
{
//将真实物理设备从房间中移除
this.DeleteRealDeviceFromRoom(listDeleteMac);
}
return statu;
}
///
/// 添加设备到缓存,存在时覆盖
///
/// 设备对象(这个东西有可能会被更改)
public void AddDeviceToMemory(ref CommonDevice device)
{
string mainKeys = this.GetDeviceMainKeys(device);
//如果它是升级的顶端端点,则不能让它加入到缓存,但是可以让他生成文件
if (device is OTADevice)
{
if (this.dicOTADevice.ContainsKey(mainKeys) == false)
{
this.dicOTADevice[mainKeys] = (OTADevice)device;
}
else
{
//交换属性
var tempDevice = this.dicOTADevice[mainKeys];
//将DeviceInfo的属性设置到主属性中
this.SetDeviceInfoToMain(tempDevice, device);
device = tempDevice;
}
bool exists = Global.IsExistsByHomeId(device.FilePath);
device.ReSave();
if (exists == false)
{
//添加自动备份
HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
}
return;
}
lock (dicAllDevice)
{
if (this.dicAllDevice.ContainsKey(mainKeys) == true)
{
//交换属性
var tempDevice = this.dicAllDevice[mainKeys];
//将DeviceInfo的属性设置到主属性中
this.SetDeviceInfoToMain(tempDevice, device);
device = tempDevice;
}
else
{
this.dicAllDevice[mainKeys] = device;
}
}
//设备回路收集
if (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == false)
{
this.dicDeviceEpoint[device.DeviceAddr] = new HashSet();
}
if (this.dicDeviceEpoint[device.DeviceAddr].Contains(device.DeviceEpoint) == false)
{
this.dicDeviceEpoint[device.DeviceAddr].Add(device.DeviceEpoint);
}
bool exists2 = Global.IsExistsByHomeId(device.FilePath);
device.ReSave();
if (exists2 == false)
{
//添加自动备份
HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
}
}
///
/// 添加虚拟设备到缓存
///
/// 设备对象
public void AddVirtualDeviceToMemory(CommonDevice device)
{
string mainKeys = this.GetDeviceMainKeys(device);
this.dicAllDevice[mainKeys] = device;
//设备回路收集
if (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == false)
{
this.dicDeviceEpoint[device.DeviceAddr] = new HashSet();
}
if (this.dicDeviceEpoint[device.DeviceAddr].Contains(device.DeviceEpoint) == false)
{
this.dicDeviceEpoint[device.DeviceAddr].Add(device.DeviceEpoint);
}
device.ReSave();
}
#endregion
#region ■ 修改设备___________________________
///
/// 更改端点名字并且刷新缓存(修改失败时,会显示信息)
///
/// 设备对象
/// 新名字
/// 是否显示错误
public bool ReName(CommonDevice device, string newName, ShowErrorMode mode = ShowErrorMode.YES)
{
//先别管那么多,更改名字后,刷新设备缓存
this.SetEpointName(device, newName);
this.BackupDeviceAfterReName(device);
//如果住宅为虚拟住宅
if (Common.Config.Instance.Home.IsVirtually == true)
{
//修改设备名字的话,主页需要重新刷新
Phone.UserView.UserPage.Instance.RefreshForm = true;
return true;
}
//不再检测名字是否一样
//成员只能修改自己本地的名字
if (UserCenterResourse.UserInfo.AuthorityNo != 3)
{
var result = this.RenameDeviceNameAsync(device, newName);
if (result == null || result.deviceRenameData == null || result.deviceRenameData.Result == 1)
{
//设备名称修改失败
string msg = Language.StringByID(R.MyInternationalizationString.uDeviceReNameFail);
//拼接上【网关回复超时】的Msg
msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
if (mode == ShowErrorMode.YES)
{
this.ShowErrorMsg(msg);
}
return false;
}
}
//修改设备名字的话,主页需要重新刷新
Phone.UserView.UserPage.Instance.RefreshForm = true;
return true;
}
///
/// 更改Mac名字并且刷新缓存(修改失败时,会显示信息)
///
/// 设备对象
/// 新名字
/// 是否显示错误
public bool ReMacName(List listDevice, string newMacName, ShowErrorMode mode = ShowErrorMode.YES)
{
if (listDevice.Count == 0)
{
return true;
}
//先别管那么多,先修改缓存
for (int i = 0; i < listDevice.Count; i++)
{
var device2 = listDevice[i];
//这两个东西很特殊
this.SetMacName(device2, newMacName);
//更改名字后,刷新设备缓存
this.BackupDeviceAfterReName(device2);
}
//如果住宅为虚拟住宅
if (Common.Config.Instance.Home.IsVirtually == true)
{
return true;
}
CommonDevice device = listDevice[0];
//不再检测名字是否一样
//成员只能修改自己本地的名字
if (UserCenterResourse.UserInfo.AuthorityNo != 3)
{
//修改物理名字
var result = this.RenameDeviceMacNameAsync(device, newMacName);
if (result == null || result.renameDeviceMacNameData == null || result.renameDeviceMacNameData.Result != 0)
{
//设备名称修改失败
string msg = Language.StringByID(R.MyInternationalizationString.uDeviceReNameFail);
//拼接上【网关回复超时】的Msg
msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
if (mode == ShowErrorMode.YES)
{
this.ShowErrorMsg(msg);
}
return false;
}
//如果它只有一个回路,则更改端点名字
if (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == true)
{
//只有一个端点
if (this.dicDeviceEpoint[device.DeviceAddr].Count == 1)
{
return this.ReName(device, newMacName);
}
//如果它有两个端点时,pir传感器特殊处理
else if (this.dicDeviceEpoint[device.DeviceAddr].Count == 2)
{
var myType = this.GetMyDeviceEnumInfo(listDevice);
if (myType.ConcreteType == DeviceConcreteType.Sensor_Pir)
{
foreach (var myDevice in listDevice)
{
if (myDevice.Type == DeviceType.IASZone)
{
return this.ReName(myDevice, newMacName);
}
}
}
}
}
}
return true;
}
///
/// 修改设备mac名称
/// macName:设备名称
///
private CommonDevice.RenameDeviceMacNameAllData RenameDeviceMacNameAsync(CommonDevice device, string macName)
{
//如果当前是虚拟住宅
if (Common.Config.Instance.Home.IsVirtually == true)
{
return Phone.ModelData.DeviceModelDataLogic.Current.ReDeviceMacName(device, macName, "MacRename");
}
//获取编辑设备Mac名字的命令字符
var sendData = this.GetReDeviceMacNameCommandText(device.DeviceAddr, device.DeviceEpoint, macName);
var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "MacRename", sendData, "MacRename_Respon", 8);
if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
{
return null;
}
//加缓存
Phone.ModelData.DeviceModelDataLogic.Current.ReDeviceMacName(device, macName, "MacRename");
var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject(result.ReceiptData);
return new CommonDevice.RenameDeviceMacNameAllData { renameDeviceMacNameData = tempData };
}
///
/// 修改设备端口(按键)名称
///
/// 设备对象
/// 设备端点名字
///
private CommonDevice.DeviceRenameAllData RenameDeviceNameAsync(CommonDevice device, string deviceName)
{
//如果当前是虚拟住宅
if (Common.Config.Instance.Home.IsVirtually == true)
{
return Phone.ModelData.DeviceModelDataLogic.Current.ReDeviceEpointName(device, deviceName, "DeviceRename");
}
//获取编辑设备端点名字的命令字符
var sendData = this.GetReDeviceEpointNameCommandText(device.DeviceAddr, device.DeviceEpoint, deviceName);
var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "DeviceRename", sendData, "DeviceRenameRespon", 8);
if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
{
return null;
}
//加缓存
Phone.ModelData.DeviceModelDataLogic.Current.ReDeviceEpointName(device, deviceName, "DeviceRename");
var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject(result.ReceiptData);
return new CommonDevice.DeviceRenameAllData { deviceRenameData = tempData };
}
///
/// 获取编辑设备Mac名字的命令字符
///
///
///
///
///
public string GetReDeviceMacNameCommandText(string deviceAddr, int deviceEpoint, string deviceName)
{
var bytes = new byte[64];
var reamarkGwBytes = Encoding.UTF8.GetBytes(deviceName);
System.Array.Copy(reamarkGwBytes, 0, bytes, 0, 64 < reamarkGwBytes.Length ? 64 : reamarkGwBytes.Length);
deviceName = Encoding.UTF8.GetString(bytes);
var jObject = new Newtonsoft.Json.Linq.JObject { { "DeviceAddr", deviceAddr }, { "Epoint", deviceEpoint }, { "Cluster_ID", 0 }, { "Command", 100 } };
var data = new Newtonsoft.Json.Linq.JObject { { "MacName", deviceName } };
jObject.Add("Data", data);
return jObject.ToString();
}
///
/// 获取编辑设备端点名字的命令字符
///
///
///
///
///
public string GetReDeviceEpointNameCommandText(string deviceAddr, int deviceEpoint, string deviceName)
{
var bytes = new byte[64];
var reamarkGwBytes = Encoding.UTF8.GetBytes(deviceName);
System.Array.Copy(reamarkGwBytes, 0, bytes, 0, 64 < reamarkGwBytes.Length ? 64 : reamarkGwBytes.Length);
deviceName = Encoding.UTF8.GetString(bytes);
var jObject = new Newtonsoft.Json.Linq.JObject { { "DeviceAddr", deviceAddr }, { "Epoint", deviceEpoint }, { "Cluster_ID", 0 }, { "Command", 96 } };
var data = new Newtonsoft.Json.Linq.JObject { { "DeviceName", deviceName } };
jObject.Add("Data", data);
return jObject.ToString();
}
///
/// 更改名字后,刷新设备缓存
///
///
private void BackupDeviceAfterReName(CommonDevice device)
{
lock (dicAllDevice)
{
string mainKeys = this.GetDeviceMainKeys(device);
if (this.dicAllDevice.ContainsKey(mainKeys) == true)
{
//一般设备
this.dicAllDevice[mainKeys] = device;
device.ReSave();
//添加自动备份
HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
}
else if (this.dicOTADevice.ContainsKey(mainKeys) == true)
{
//Ota设备
this.dicOTADevice[mainKeys] = (OTADevice)device;
device.ReSave();
//添加自动备份
HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
}
}
}
#endregion
#region ■ 删除设备___________________________
///
/// 删除设备并且刷新缓存(删除失败时,会显示信息)
///
/// 设备对象(MAC地址必须要相同)
public async Task DeleteDevice(List listdevice)
{
//虚拟住宅的话,不需要删除网关的设备
if (Config.Instance.Home.IsVirtually == false)
{
var data = new CommonDevice.RemoveDeviceData();
var info = new CommonDevice.RemoveDeviceListInfo();
info.DeviceAddr = listdevice[0].DeviceAddr;
data.DeviceAddrList.Add(info);
//删一次的时候,它会把MAC地址下面全部的设备都删除
var result = await listdevice[0].DeleteDeviceAsync(data);
if (result == null || result.removeDeviceResponseData == null || result.removeDeviceResponseData.Result != 0)
{
//设备删除失败
string msg = Language.StringByID(R.MyInternationalizationString.uDeviceDeleteFail);
//拼接上【网关回复超时】的Msg
msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
this.ShowErrorMsg(msg);
return false;
}
}
//删除缓存的Ota设备
this.DeleteMemmoryOtaDevice(listdevice[0].DeviceAddr);
//删除一般设备文件
foreach (CommonDevice device in listdevice)
{
this.DeleteMemmoryDevice(device);
}
if (this.dicDeviceRoomId.ContainsKey(listdevice[0].DeviceAddr) == true)
{
//移除真实设备的房间索引
this.dicDeviceRoomId.Remove(listdevice[0].DeviceAddr);
this.SaveRealDeviceRoomId(null, null);
}
return true;
}
///
/// 删除缓存的一般设备
///
/// 设备对象
/// 是否从房间删除
public void DeleteMemmoryDevice(CommonDevice device, bool deleteRoom = true)
{
//删除缓存设备的话,主页需要重新刷新
Phone.UserView.UserPage.Instance.RefreshForm = true;
if (deleteRoom == true)
{
//从房间中删除
HdlRoomLogic.Current.DeleteDevice(device);
//删除我的喜爱的设备
HdlRoomLogic.Current.DeleteLoveDevice(device);
}
//删除缓存
string mainKeys = this.GetDeviceMainKeys(device);
lock (dicAllDevice)
{
if (this.dicAllDevice.ContainsKey(mainKeys) == true)
{
this.dicAllDevice.Remove(mainKeys);
}
if (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == true)
{
//变更端点数
this.dicDeviceEpoint[device.DeviceAddr].Remove(device.DeviceEpoint);
}
}
//删除设备文件
string filePath = device.FilePath;
if (Global.IsExistsByHomeId(filePath) == true)
{
if (UserCenterResourse.UserInfo.AuthorityNo == 3)
{
//成员的话,直接删除,没有商量的余地
Global.DeleteFilebyHomeId(filePath);
}
else
{
//变更:搞掉它,不留了
Global.DeleteFilebyHomeId(filePath);
//删除自动备份
HdlAutoBackupLogic.DeleteFile(device.FilePath);
}
}
}
///
/// 删除缓存的Ota设备
///
///
///
public void DeleteMemmoryOtaDevice(string macAdrr, int ePoint = 200)
{
//删除200端口文件
string otaKeys = this.GetDeviceMainKeys(macAdrr, ePoint);
if (this.dicOTADevice.ContainsKey(otaKeys) == true)
{
string otaFile = this.dicOTADevice[otaKeys].FilePath;
if (Global.IsExistsByHomeId(otaFile) == true)
{
if (UserCenterResourse.UserInfo.AuthorityNo == 3)
{
//成员的话,直接删除,没有商量的余地
Global.DeleteFilebyHomeId(otaFile);
}
else
{
//变更:搞掉它,不留了
Global.DeleteFilebyHomeId(otaFile);
//删除自动备份
HdlAutoBackupLogic.DeleteFile(otaFile);
}
}
this.dicOTADevice.Remove(otaKeys);
}
}
#endregion
#region ■ 测试设备___________________________
///
/// 发送定位指令到设备
///
///
public void SetFixedPositionCommand(CommonDevice device)
{
//如果当前住宅不是虚拟住宅
if (Common.Config.Instance.Home.IsVirtually == false)
{
device.IdentifyControl(device.DeviceAddr, device.DeviceEpoint, 5);
}
}
///
/// 检测设备是否拥有定位的功能
///
///
///
public bool DeviceIsCanFixedPosition(CommonDevice device)
{
if (device.Type == DeviceType.DoorLock || device.Type == DeviceType.PMSensor)
{
//门锁没有定位功能
return false;
}
if (device.Type == DeviceType.IASZone)
{
var myTypeInfo = this.GetMyDeviceEnumInfo(new List() { device });
if (myTypeInfo.ConcreteType == DeviceConcreteType.Sensor_Pir)
{
//传感器除了Pir都没有定位功能
return true;
}
return false;
}
foreach (var data in device.InClusterList)
{
//拥有on/off功能的,才支持测试
if (data.InCluster == 3)
{
return true;
}
}
return false;
}
///
/// 检测设备是否拥有开关的功能(输出簇)
///
///
///
public bool OutDeviceIsCanOnOff(CommonDevice device)
{
foreach (var data in device.OutClusterList)
{
//拥有on/off功能的,才支持测试
if (data.OutCluster == 6)
{
return true;
}
}
return false;
}
///
/// 检测设备是否拥有开关的功能(输入簇)
///
///
///
public bool InDeviceIsCanOnOff(CommonDevice device)
{
foreach (var data in device.InClusterList)
{
//拥有on/off功能的,才支持测试
if (data.InCluster == 6)
{
return true;
}
}
return false;
}
#endregion
#region ■ 获取设备___________________________
///
/// 根据网关ID获取所有的设备
///
/// 网关ID>
///
public List GetDeviceByGatewayID(string gwId)
{
lock (dicAllDevice)
{
var listMac = new List();
//各网关的所有设备的Mac
foreach (CommonDevice device in this.dicAllDevice.Values)
{
if (gwId == device.CurrentGateWayId)
{
listMac.Add(device.DeviceAddr);
}
}
return this.GetDevicesByMac(listMac);
}
}
///
/// 获取指定设备(主键是:Mac地址+端口号),不存在时,返回null
///
/// Mac地址+端口号
///
public CommonDevice GetDevice(string mainKeys)
{
lock (dicAllDevice)
{
if (this.dicAllDevice.ContainsKey(mainKeys) == true)
{
return this.dicAllDevice[mainKeys];
}
}
return null;
}
///
/// 获取指定设备,不存在时,返回null
///
/// Mac地址
/// 端口号
///
public CommonDevice GetDevice(string DeviceAddr, int DeviceEpoint)
{
string mainkeys = this.GetDeviceMainKeys(DeviceAddr, DeviceEpoint);
return this.GetDevice(mainkeys);
}
///
/// 根据MAC地址,获取全部回路的设备对象
///
/// Mac地址
/// 是否排序
///
public List GetDevicesByMac(string DeviceAddr, bool sort = true)
{
var list = new List();
if (dicDeviceEpoint.ContainsKey(DeviceAddr) == false)
{
return list;
}
foreach (var point in dicDeviceEpoint[DeviceAddr])
{
var device = this.GetDevice(DeviceAddr, point);
if (device != null)
{
list.Add(device);
}
}
if (sort == false)
{
return list;
}
//排序
list.Sort((obj1, obj2) =>
{
if (obj1.DeviceEpoint > obj2.DeviceEpoint)
{
return 1;
}
return -1;
});
return list;
}
///
/// 根据MAC地址,获取简约面板全部回路的设备对象
///
///
///
public List GetMutilfunctionPanelByMac(List listDevice, bool sort = true)
{
//和彪哥、设备和产品部同事确认:
//简约多功能面板[不显示多余的回路,只显示携带的2个继电器,1个温度传感器,1个湿度传感器
var list = new List();
foreach (var dev in listDevice)
{
if (dev.Type == DeviceType.TemperatureSensor)
{
if (dev.DeviceEpoint == 64)
{
list.Add(dev);
}
}
else if (dev.Type == DeviceType.FreshAirHumiditySensor)
{
if (dev.DeviceEpoint == 65)
{
list.Add(dev);
}
}
else if (dev.Type == DeviceType.OnOffOutput)
{
list.Add(dev);
}
}
if (sort == false)
{
return list;
}
list.Sort((obj1, obj2) =>
{
if (obj1.DeviceEpoint > obj2.DeviceEpoint)
{
return 1;
}
return -1;
});
return list;
}
///
/// 根据MAC地址,获取新风、简约环境面板全部回路的设备对象
///
///
///
public List GetPanelMatchEpointByMac(List listDevice, bool sort = true)
{
var list = new List();
foreach (var dev in listDevice)
{
if (dev.Type == DeviceType.TemperatureSensor)
{
list.Add(dev);
}
else if (dev.Type == DeviceType.FreshAirHumiditySensor)
{
list.Add(dev);
}
}
if (sort == false)
{
return list;
}
list.Sort((obj1, obj2) => {
if (obj1.DeviceEpoint > obj2.DeviceEpoint)
{
return 1;
}
return -1;
});
return list;
}
///
/// 根据MAC地址,获取全部回路的设备对象(强制排序)
///
/// Mac地址
///
public List GetDevicesByMac(List listMacAddr)
{
//先排序
listMacAddr.Sort();
var list = new List();
foreach (string strMac in listMacAddr)
{
var listEpoint = new List();
//获取全部的端点
foreach (int epoint in this.dicDeviceEpoint[strMac])
{
listEpoint.Add(epoint);
}
//然后排序
listEpoint.Sort();
foreach (int epoint in listEpoint)
{
var device = this.GetDevice(strMac, epoint);
if (device != null)
{
list.Add(device);
}
}
}
return list;
}
///
/// 根据MAC地址,获取全部回路的数量
///
/// Mac地址
///
public int GetDevicesCountByMac(string DeviceAddr)
{
if (dicDeviceEpoint.ContainsKey(DeviceAddr) == false)
{
return 0;
}
return dicDeviceEpoint[DeviceAddr].Count;
}
///
/// 获取本地全部的设备文件
///
///
public List GetAllDeviceFile()
{
List listDeviceFile = new List();
List listAllFile = Global.FileListByHomeId();
foreach (string file in listAllFile)
{
if (file.StartsWith("Device_") == false)
{
//如果不是设备文件
continue;
}
listDeviceFile.Add(file);
}
return listDeviceFile;
}
///
/// 获取OTA设备(200端口的)
///
///
///
///
public OTADevice GetOTADevice(string macAdrr, int ePoint = 200)
{
string mainkeys = this.GetDeviceMainKeys(macAdrr, ePoint);
if (this.dicOTADevice.ContainsKey(mainkeys) == false)
{
return null;
}
return this.dicOTADevice[mainkeys];
}
///
/// 获取特殊的,没有其他回路,单纯只有200端点的OTA设备
///
/// 网关ID
///
public List GetSpecialOtaDevice(string gwId)
{
var list = new List();
foreach (var ota in this.dicOTADevice.Values)
{
if (ota.CurrentGateWayId != gwId)
{
//不是同一个网关
continue;
}
//没有其他回路
if (dicDeviceEpoint.ContainsKey(ota.DeviceAddr) == false
|| dicDeviceEpoint[ota.DeviceAddr].Count == 0)
{
//目前只针对中央空调
if (ota.ModelIdentifier == "MAC/GW-ZB.10")
{
list.Add(ota);
}
}
}
return list;
}
#endregion
#region ■ 获取设备信息_______________________
///
/// 读取单个端点回路设备信息
///
/// 设备对象
///
public CommonDevice.DeviceInfoData ReadDeviceEpointDeviceInfo(CommonDevice device)
{
var jObject = new Newtonsoft.Json.Linq.JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", device.DeviceEpoint }, { "Cluster_ID", 0 }, { "Command", 80 } };
var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "GetStatusRecord", jObject.ToString(), "GetStatusRecord_Respon");
if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
{
return null;
}
var info = Newtonsoft.Json.JsonConvert.DeserializeObject(result.ReceiptData);
return info;
}
#endregion
#region ■ 设置设备功能类型___________________
///
/// 设置设备功能类型到网关
///
/// 设备回路
/// 功能类型
///
public bool SendDeviceFunctionTypeToGateway(CommonDevice device, DeviceFunctionType functionType)
{
var jObject = new Newtonsoft.Json.Linq.JObject { { "DeviceAddr", device.DeviceAddr }, { "Epoint", device.DeviceEpoint }, { "Cluster_ID", 0 }, { "Command", 110 } };
var data = new Newtonsoft.Json.Linq.JObject { { "FunctionType", (int)functionType } };
jObject.Add("Data", data);
var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "Device/SetEPDeviceFunctionType", jObject.ToString(), "Device/SetEPDeviceFunctionTypeRespon");
if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
{
return false;
}
var resultData = Newtonsoft.Json.Linq.JObject.Parse(result.ReceiptData);
if (resultData.Property("Result") != null)
{
//0:修改成功 1:修改失败
return resultData["Result"].ToString() == "0";
}
return false;
}
#endregion
#region ■ 获取设备名称_______________________
///
/// 获取设备端点的名称(有特效)
///
/// 设备对象
///
public string GetDeviceEpointName(CommonDevice device)
{
string dName = this.GetSimpleEpointName(device);
if (string.IsNullOrEmpty(dName) == false)
{
return dName;
}
if (this.IsMiniLight(device) == true)
{
//Mini夜灯
return Language.StringByID(R.MyInternationalizationString.uMiniNightLight);
}
//如果这个设备只有一个回路的话,返回Mac名字给它
if (this.GetDevicesCountByMac(device.DeviceAddr) <= 1)
{
return this.GetDeviceMacName(device);
}
//同一设备里面,不同类型的回路,它的命名都从1开始
int epointNo = 0;
var listSort = this.GetDevicesByMac(device.DeviceAddr);
foreach (var myDevice in listSort)
{
if (myDevice.Type == device.Type)
{
//同一类型编号+1
epointNo++;
if (myDevice.DeviceEpoint == device.DeviceEpoint)
{
//已经到达它自己
break;
}
}
}
if (device.Type == DeviceType.OnOffOutput
|| device.Type == DeviceType.DimmableLight
|| device.Type == DeviceType.ColorDimmableLight
|| device.Type == DeviceType.ColorTemperatureLight)
{
//继电器,掉光器都叫回路
return Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + epointNo;
}
if (device.Type == DeviceType.Thermostat)
{
//空调都叫室内机
return Language.StringByID(R.MyInternationalizationString.uIndoorUnit) + epointNo;
}
//获取设备类型
var deviceInfoType = this.GetMyDeviceEnumInfo(new List() { device });
if (device.Type == DeviceType.OnOffSwitch)
{
//面板的干接点叫按键
if (deviceInfoType.BeloneType == DeviceBeloneType.A按键面板)
{
return Language.StringByID(R.MyInternationalizationString.uPanelButton) + epointNo;
}
//其他的干接点叫干接点
else
{
return Language.StringByID(R.MyInternationalizationString.uDeviceBelongId16) + epointNo;
}
}
else if (device.Type == DeviceType.FreshAirHumiditySensor)
{
//新风面板/简约多功能/简约环境面板湿度传感器
return Language.StringByID(deviceInfoType.DefultNameId) + Language.StringByID(R.MyInternationalizationString.HumiditySensor);
}
else if (device.Type == DeviceType.TemperatureSensor)
{
if (deviceInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueFreshAir
|| deviceInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleEnvironment
|| deviceInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleMultifunction)
{
//新风面板/简约多功能/简约环境面板 温度传感器
return Language.StringByID(deviceInfoType.DefultNameId) + Language.StringByID(R.MyInternationalizationString.TemperatureSensor);
}
else if (deviceInfoType.BeloneType == DeviceBeloneType.A按键面板)
{
//面板的温度探头叫 面板名字+温度
return Language.StringByID(deviceInfoType.DefultNameId) + Language.StringByID(R.MyInternationalizationString.uTemperature);
}
}
//其他情况,使用它的默认名称
return Language.StringByID(deviceInfoType.DefultNameId) + epointNo;
}
///
/// 获取设备MAC名称
///
/// 设备对象
///
public string GetDeviceMacName(CommonDevice device)
{
string dName = this.GetSimpleMacName(device);
if (string.IsNullOrEmpty(dName) == false)
{
return dName;
}
if (this.IsMiniLight(device) == true)
{
//Mini夜灯
return Language.StringByID(R.MyInternationalizationString.uMiniNightLight);
}
//获取设备类型
var deviceInfoType = this.GetMyDeviceEnumInfo(new List() { device });
return Language.StringByID(deviceInfoType.DefultNameId);
}
///
/// 非公开,设置设备的Mac名字(此方法只是单存的变更缓存)
///
/// 设备对象
/// Mac名字
///
private void SetMacName(CommonDevice device, string macName)
{
device.DeviceName = macName;
}
///
/// 非公开,设置设备的端点名字(此方法只是单存的变更缓存)
///
/// 设备对象
/// 端点名字
///
private void SetEpointName(CommonDevice device, string epointName)
{
device.DeviceEpointName = epointName;
}
///
/// 单纯获取设备的Mac名字
///
/// 设备对象
///
public string GetSimpleMacName(CommonDevice device)
{
return device.DeviceName;
}
///
/// 单纯获取设备的端点名字
///
/// 设备对象
///
public string GetSimpleEpointName(CommonDevice device)
{
return device.DeviceEpointName;
}
///
/// 初始化R文件里面设备默认名字的ID
///
private void InitDeviceDefultNameIDList()
{
if (this.dicDeviceAllNameID != null)
{
return;
}
this.dicDeviceAllNameID = new Dictionary();
Type type = typeof(R.MyInternationalizationString);
var PropertyList = type.GetFields();
foreach (var item in PropertyList)
{
if (item.Name.StartsWith(deviceModelIdName) == true
|| item.Name.StartsWith("uDeviceBelongId") == true)
{
this.dicDeviceAllNameID[item.Name] = Convert.ToInt32(item.GetValue(null));
}
}
//初始化设备枚举
this.InitDeviceModelIdEnum();
}
#endregion
#region ■ 设置图标___________________________
///
/// 变更设备的图标
///
/// 设备对象
/// 图片地址(非选择)
public void ChangedDeviceIcon(CommonDevice device, string unSelPath)
{
if (unSelPath == string.Empty)
{
return;
}
device.IconPath = unSelPath;
device.IsCustomizeImage = true;
device.ReSave();
HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
}
///
/// 设置设备【图标】到指定的控件
///
/// 控件对象
/// 设备对象
///
public void SetDeviceIconToControl(Button btnIcon, CommonDevice device)
{
if (device == null)
{
btnIcon.UnSelectedImagePath = "Device/ThirdPartyDevice.png";
return;
}
string unSelectFilePath = string.Empty;
string selectFilePath = string.Empty;
//获取设备【图标】
this.GetDeviceIcon(device, ref unSelectFilePath, ref selectFilePath);
if (btnIcon.UnSelectedImagePath != unSelectFilePath)
{
btnIcon.UnSelectedImagePath = unSelectFilePath;
}
if (btnIcon.SelectedImagePath != selectFilePath)
{
btnIcon.SelectedImagePath = selectFilePath;
}
}
///
/// 设置设备【图标】到指定的控件(注意,此函数设置的选择状态的图片是白色的)
///
/// 控件对象
/// 设备对象
///
public void SetDeviceIconToControl2(Button btnIcon, CommonDevice device)
{
if (device == null)
{
btnIcon.UnSelectedImagePath = "Device/ThirdPartyDevice.png";
return;
}
string unSelectFilePath = device.IconPath;
string selectFilePath = unSelectFilePath.Replace(".png", "Selected2.png");
//获取设备【图标】
if (btnIcon.UnSelectedImagePath != unSelectFilePath)
{
btnIcon.UnSelectedImagePath = unSelectFilePath;
}
if (btnIcon.SelectedImagePath != selectFilePath)
{
btnIcon.SelectedImagePath = selectFilePath;
}
}
///
/// 获取设备【图标】
///
/// 设备对象
/// 图片地址
/// 图片地址
///
public void GetDeviceIcon(CommonDevice device, ref string unSelectPath, ref string selectPath)
{
if (string.IsNullOrEmpty(device.IconPath) == true)
{
return;
}
unSelectPath = device.IconPath;
string selPath = device.OnlineIconPath;
if (string.IsNullOrEmpty(selPath) == false)
{
selectPath = selPath;
}
}
///
/// 设置设备的真实图片到指定的控件
///
/// 控件对象
/// 设备对象
public void SetRealDeviceIconToControl(Button btnIcon, List listdevice)
{
//获取设备的真实图片
string imagePath = this.GetRealDeviceIcon(listdevice);
btnIcon.UnSelectedImagePath = imagePath;
}
///
/// 获取设备的真实图片
///
/// 设备对象
public string GetRealDeviceIcon(List listdevice)
{
//获取它属于什么类型的设备
var myDeviceType = this.GetMyDeviceEnumInfo(listdevice);
string strConcrete = Enum.GetName(typeof(DeviceConcreteType), myDeviceType.ConcreteType);
//图片共有
if (this.dicPictrueShard.ContainsKey(strConcrete) == true)
{
strConcrete = this.dicPictrueShard[strConcrete];
}
string strType = strConcrete.Replace("_", string.Empty);
//将类型转为图片地址
string imageFilePath = "RealDevice/" + strType + ".png";
//这个图片本地是否存在?
if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(imageFilePath)) == true)
{
//不存在则使用共通图片
string[] arry = strConcrete.Split(new string[] { "_" }, StringSplitOptions.None);
if (arry.Length == 1)
{
//如果它自己就是共通图片的话,不再处理
return "RealDevice/CommonDevice.png";
}
imageFilePath = "RealDevice/" + arry[0] + ".png";
//如果它自己的共通图片还是不存在的话,则直接使用所有设备的共通图片
if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(imageFilePath)) == true)
{
imageFilePath = "RealDevice/CommonDevice.png";
}
}
return imageFilePath;
}
///
/// 设置【设备类型】的图标到指定的控件(此方法不能用在设备功能类型菜单的图标)
///
/// 控件对象
/// 设备对象
///
public void SetDeviceObjectIconToControl(Button btnIcon, List listdevice)
{
//获取自定义设备类型
var myDeviceType = this.GetMyDeviceEnumInfo(listdevice);
string imageUnSelectFilePath = string.Empty;
string imageSelectFilePath = string.Empty;
//获取【设备类型】的图标
this.GetDeviceObjectIcon(myDeviceType.ConcreteType, ref imageUnSelectFilePath, ref imageSelectFilePath);
//设置图片
btnIcon.UnSelectedImagePath = imageUnSelectFilePath;
btnIcon.SelectedImagePath = imageSelectFilePath;
}
///
/// 获取【设备类型】的图标(此方法不能用在设备功能类型菜单的图标)
///
/// 设备对象
/// 图片地址
/// 图片地址
///
public void GetDeviceObjectIcon(List listdevice, ref string unSelectPath, ref string selectPath)
{
//获取自定义设备类型
var myDeviceType = this.GetMyDeviceEnumInfo(listdevice);
//获取【设备类型】的图标
this.GetDeviceObjectIcon(myDeviceType.ConcreteType, ref unSelectPath, ref selectPath);
}
///
/// 获取【设备功能类型】的菜单图标
///
/// 自定义设备类型
/// 图片地址
/// 图片地址
///
public void GetDeviceFunctionTypeMenuIcon(DeviceConcreteType specificType, ref string unSelectPath, ref string selectPath)
{
//新风小模块
if (specificType == DeviceConcreteType.Relay_FangyueFreshAirModul)
{
unSelectPath = "Device/FreshAirEpoint.png";
selectPath = "Device/FreshAirEpointSelected.png";
return;
}
//PM2.5空气质量传感器
else if (specificType == DeviceConcreteType.Sensor_PMTwoPointFive)
{
unSelectPath = "Device/AirQualitySensorEpoint.png";
selectPath = "Device/AirQualitySensorEpointSelected.png";
return;
}
//上面需要特殊处理
//获取【设备类型】的图标
this.GetDeviceObjectIcon(specificType, ref unSelectPath, ref selectPath);
}
///
/// 获取【设备类型】的图标 2020.05.13:次函数不再公开
///
/// 自定义设备类型
/// 图片地址
/// 图片地址
///
private void GetDeviceObjectIcon(DeviceConcreteType specificType, ref string unSelectPath, ref string selectPath)
{
//将具体类型转字符串
string strSpecific = Enum.GetName(typeof(DeviceConcreteType), specificType);
//图片共有
if (this.dicPictrueShard.ContainsKey(strSpecific) == true)
{
strSpecific = this.dicPictrueShard[strSpecific];
}
string strType = strSpecific.Replace("_", string.Empty);
//将类型转为图片地址
string imageFilePath = "Device/" + strType + ".png";
string imageSelectFilePath = "Device/" + strType + "Selected.png";
//这个图片本地是否存在?
if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(imageFilePath)) == true)
{
//不存在则使用共通图片
string[] arry = strSpecific.Split(new string[] { "_" }, StringSplitOptions.None);
//如果它自己就是共通图片的话,不再处理
if (arry.Length > 1)
{
imageFilePath = "Device/" + arry[0] + ".png";
imageSelectFilePath = "Device/" + arry[0] + "Selected.png";
}
}
//如果那款设备连共通图片都没有的话
if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(imageFilePath)) == true)
{
imageFilePath = "Device/ThirdPartyDevice.png";
imageSelectFilePath = "Device/ThirdPartyDeviceSelected.png";
}
//设置图片
unSelectPath = imageFilePath;
selectPath = imageSelectFilePath;
}
#endregion
#region ■ 获取自定义的设备类型_______________
///
/// 获取【自定义的设备类型】,两种类型都设置了
///
/// 设备对象
///
public DeviceEnumInfo GetMyDeviceEnumInfo(List listdevice)
{
CommonDevice checkDevice = listdevice[0];
foreach (var temp in listdevice)
{
//拿拥有模块ID的那个回路来判断
if (temp.ModelIdentifier != string.Empty)
{
checkDevice = temp;
}
}
//获取河东设备的设备类型
DeviceEnumInfo info = this.GetHdlMyDeviceEnumInfo(checkDevice);
if (info != null)
{
return info;
}
//获取第三方设备的【设备类型】
info = this.GetNotHdlMyDeviceEnumInfo(listdevice);
//这里再次判断是否是河东设备,有可能它的模块ID写错了
info.IsHdlDevice = this.IsHdlDevice(checkDevice);
return info;
}
///
/// 获取设备的【设备类型】的翻译文本(优先镜像)
///
///
/// 第三方或者虚拟设备的时候,是否添加标识
///
public string GetDeviceObjectText(List listDevice, bool ApendFalge = true)
{
CommonDevice checkDevice = listDevice[0];
foreach (var temp in listDevice)
{
//拿拥有模块ID的那个回路来判断
if (temp.ModelIdentifier != string.Empty)
{
checkDevice = temp;
}
}
//获取自定义设备类型
var myInfoType = this.GetMyDeviceEnumInfo(listDevice);
//获取设备类型的翻译名字
string strName = Language.StringByID(myInfoType.ObjectTypeNameId);
if (strName == string.Empty)
{
//加一层保险,未知设备
strName = Language.StringByID(R.MyInternationalizationString.UnknowDevice);
}
if (ApendFalge == true)
{
if (listDevice[0].DriveCode > 0)
{
//虚拟设备加个标识
strName += "✩";
}
else
{
foreach (var temp in listDevice)
{
//拿拥有模块ID的那个回路来判断
if (temp.ModelIdentifier != string.Empty)
{
if (this.IsHdlDevice(checkDevice) == false)
{
//第三方设备加个标识
strName += "★";
break;
}
}
}
}
}
return strName;
}
#endregion
#region ■ 获取河东设备的设备类型_____________
///
/// 获取Hdl设备的【自定义的设备类型】
///
/// 随便某一回路
///
private DeviceEnumInfo GetHdlMyDeviceEnumInfo(CommonDevice device)
{
//设备具体类型
var info = new DeviceEnumInfo();
info.IsHdlDevice = this.IsHdlDevice(device);
if (device.ModelIdentifier == string.Empty)
{
return null;
}
string modelKeys = device.ModelIdentifier;
//交换一下模块ID(麦乐克那边的传感器)
this.ChangedDeviceModeId(ref modelKeys);
if (this.dicDeviceModelIdEnum.ContainsKey(modelKeys) == false)
{
//没有匹配到模块ID,则直接走第三方设备的判断
return null;
}
string[] strValue = this.dicDeviceModelIdEnum[modelKeys].Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
int ConcreteValue = Convert.ToInt32(strValue[0]);
int BeloneValue = Convert.ToInt32(strValue[1]);
//设置设备的【设备所属类型】
info.BeloneType = (DeviceBeloneType)BeloneValue;
if (dicDeviceAllNameID.ContainsKey("uDeviceBelongId" + BeloneValue) == true)
{
//设备所属类型的翻译名字
info.BeloneTextId = dicDeviceAllNameID["uDeviceBelongId" + BeloneValue];
}
//设备具体类型
info.ConcreteType = (DeviceConcreteType)ConcreteValue;
if (info.ConcreteType.ToString() == ConcreteValue.ToString())
{
info.ConcreteType = DeviceConcreteType.UnKownDevice;
}
string keyName = deviceModelIdName + ConcreteValue;
if (this.dicDeviceAllNameID.ContainsKey(keyName) == true)
{
//设备的官方名称
info.ConcreteTextId = this.dicDeviceAllNameID[keyName];
}
//设备的类型翻译名称
info.ObjectTypeNameId = Convert.ToInt32(strValue[2]);
return info;
}
#endregion
#region ■ 获取第三方设备的设备类型___________
///
/// 获取设备的【所属类型信息】,此方法会把所有的传感器都归为【传感器】(包括温湿度传感器)
///
/// 设备回路
///
public DeviceEnumInfo GetDeviceBelongEnumInfo(CommonDevice device)
{
var info = this.GetNotHdlMyDeviceEnumInfo(new List() { device });
if (info.BeloneType == DeviceBeloneType.A调光器
|| info.BeloneType == DeviceBeloneType.A彩灯)
{
//归为灯光
info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId15;
info.BeloneType = DeviceBeloneType.A灯光;
info.ConcreteType = DeviceConcreteType.Light;
info.ObjectTypeNameId = 60007;//调光模块
int value = (int)info.BeloneType;
if (dicDeviceAllNameID.ContainsKey("uDeviceBelongId" + value) == true)
{
//设备所属类型的翻译名字
info.BeloneTextId = dicDeviceAllNameID["uDeviceBelongId" + value];
}
}
else if (info.BeloneType == DeviceBeloneType.A传感器
|| device.Type == DeviceType.TemperatureSensor)
{
//传感器合并
info.BeloneType = DeviceBeloneType.A传感器;
info.ConcreteType = DeviceConcreteType.Sensor;
info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId1200;
info.ObjectTypeNameId = 60000;//传感器
int value = (int)info.BeloneType;
if (dicDeviceAllNameID.ContainsKey("uDeviceBelongId" + value) == true)
{
//设备所属类型的翻译名字
info.BeloneTextId = dicDeviceAllNameID["uDeviceBelongId" + value];
}
}
return info;
}
///
/// 获取第三方设备的【设备类型】(不建议使用)
///
/// Mac都一样的设备列表
///
public DeviceEnumInfo GetNotHdlMyDeviceEnumInfo(List listdevice)
{
var dicType = new Dictionary();
foreach (CommonDevice device in listdevice)
{
if (dicType.ContainsKey(device.Type) == false)
{
dicType[device.Type] = device;
}
}
var info = new DeviceEnumInfo();
info.IsHdlDevice = false;
//1包含面板的话,当面板处理
if (dicType.ContainsKey(DeviceType.OnOffSwitch) == true)
{
if (listdevice.Count > 1)
{
info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId200;
info.BeloneType = DeviceBeloneType.A按键面板;
info.ConcreteType = DeviceConcreteType.ButtonPanel;
}
else
{
info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId16;
info.BeloneType = DeviceBeloneType.A干接点;
info.ConcreteType = DeviceConcreteType.DryContact;
}
info.ObjectTypeNameId = 60003;//智能面板
}
//3包含窗帘的话,当窗帘处理
else if (dicType.ContainsKey(DeviceType.WindowCoveringDevice) == true)
{
info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId100;
info.BeloneType = DeviceBeloneType.A窗帘;
info.ConcreteType = DeviceConcreteType.Curtain;
info.ObjectTypeNameId = 60002;//遮阳模块
}
//4空气开关
else if (dicType.ContainsKey(DeviceType.AirSwitch) == true)
{
//默认值
info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId4100;
info.BeloneType = DeviceBeloneType.A开关;
info.ConcreteType = DeviceConcreteType.AirSwitch;
info.ObjectTypeNameId = 60001;//开关模块
if (dicType[DeviceType.AirSwitch].DfunctionType == DeviceFunctionType.A开关)
{
info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId13;
info.BeloneType = DeviceBeloneType.A开关;
info.ConcreteType = DeviceConcreteType.Switch;
}
else if (dicType[DeviceType.AirSwitch].DfunctionType == DeviceFunctionType.A插座)
{
info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId14;
info.BeloneType = DeviceBeloneType.A插座;
info.ConcreteType = DeviceConcreteType.Socket1;
}
else if (dicType[DeviceType.AirSwitch].DfunctionType == DeviceFunctionType.A灯光)
{
info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId15;
info.BeloneType = DeviceBeloneType.A灯光;
info.ConcreteType = DeviceConcreteType.Light;
}
}
//5继电器
else if (dicType.ContainsKey(DeviceType.OnOffOutput) == true)
{
//默认值
info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId2300;
info.BeloneType = DeviceBeloneType.A继电器;
info.ConcreteType = DeviceConcreteType.Relay;
info.ObjectTypeNameId = 60001;//开关模块
if (dicType[DeviceType.OnOffOutput].DfunctionType == DeviceFunctionType.A开关)
{
info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId13;
info.BeloneType = DeviceBeloneType.A开关;
info.ConcreteType = DeviceConcreteType.Switch;
}
else if (dicType[DeviceType.OnOffOutput].DfunctionType == DeviceFunctionType.A插座)
{
info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId14;
info.BeloneType = DeviceBeloneType.A插座;
info.ConcreteType = DeviceConcreteType.Socket1;
}
else if (dicType[DeviceType.OnOffOutput].DfunctionType == DeviceFunctionType.A灯光)
{
info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId15;
info.BeloneType = DeviceBeloneType.A灯光;
info.ConcreteType = DeviceConcreteType.Light;
}
}
//6调光器
else if (dicType.ContainsKey(DeviceType.DimmableLight) == true)
{
info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId2500;
info.BeloneType = DeviceBeloneType.A调光器;
info.ConcreteType = DeviceConcreteType.DimmableLight;
info.ObjectTypeNameId = 60007;//调光模块
}
//7彩灯
else if (dicType.ContainsKey(DeviceType.ColorDimmableLight) == true)
{
info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId9;
info.BeloneType = DeviceBeloneType.A彩灯;
info.ConcreteType = DeviceConcreteType.ColorLight;
info.ObjectTypeNameId = 60007;//调光模块
}
//8空调
else if (dicType.ContainsKey(DeviceType.Thermostat) == true)
{
info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId3600;
info.BeloneType = DeviceBeloneType.A空调;
info.ConcreteType = DeviceConcreteType.AirConditioner;
info.ObjectTypeNameId = 60009;//空调模块
}
//9中继器
else if (dicType.ContainsKey(DeviceType.Repeater) == true)
{
info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId3900;
info.BeloneType = DeviceBeloneType.A中继器;
info.ConcreteType = DeviceConcreteType.Repeater;
info.ObjectTypeNameId = 60006;//系统设备
}
//10转换器
else if (dicType.ContainsKey(DeviceType.Transverter) == true)
{
info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId4200;
info.BeloneType = DeviceBeloneType.A转换器;
info.ConcreteType = DeviceConcreteType.Converter;
info.ObjectTypeNameId = 60008;//转换器
}
//11智能门锁
else if (dicType.ContainsKey(DeviceType.DoorLock) == true)
{
info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId2800;
info.BeloneType = DeviceBeloneType.A智能门锁;
info.ConcreteType = DeviceConcreteType.IntelligentLocks;
info.ObjectTypeNameId = 60010;//智能门锁
}
//12包含传感器的话,当传感器处理
else if (dicType.ContainsKey(DeviceType.IASZone) == true)
{
info.BeloneType = DeviceBeloneType.A传感器;
info.ConcreteType = DeviceConcreteType.Sensor;
info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId1200;
info.ObjectTypeNameId = 60000;//传感器
//设置传感器具体的类型
this.SetSensorDeviceSpecificType(ref info, listdevice);
}
//13包含温度传感器的话
else if (dicType.ContainsKey(DeviceType.TemperatureSensor) == true)
{
bool temperatrue = false;
bool humidity = false;
//获取全部的回路
var listTemp = this.GetDevicesByMac(listdevice[0].DeviceAddr, false);
foreach (var device in listTemp)
{
if (device is TemperatureSensor)
{
//温度传感器
if (((TemperatureSensor)device).SensorDiv == 1)
{
temperatrue = true;
}
//湿度传感器
else if (((TemperatureSensor)device).SensorDiv == 2)
{
humidity = true;
}
}
}
if (temperatrue == true && humidity == true)
{
//设置传感器具体的类型
info.BeloneType = DeviceBeloneType.A温湿度传感器;
info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId10;
info.ConcreteType = DeviceConcreteType.Sensor_TemperatureHumidity;
}
else if (temperatrue == true && humidity == false)
{
//设置传感器具体的类型
info.BeloneType = DeviceBeloneType.A温度传感器;
info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId11;
info.ConcreteType = DeviceConcreteType.Sensor_Temperature;
}
else if (temperatrue == false && humidity == true)
{
//设置传感器具体的类型
info.BeloneType = DeviceBeloneType.A湿度传感器;
info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId12;
info.ConcreteType = DeviceConcreteType.Sensor_Humidity;
}
info.ObjectTypeNameId = 60000;//传感器
}
//14新风设备
else if (dicType.ContainsKey(DeviceType.FreshAir) == true)
{
info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId2310;
info.BeloneType = DeviceBeloneType.A新风;
info.ConcreteType = DeviceConcreteType.Relay_FangyueFreshAirModul;
info.ObjectTypeNameId = 60011;//新风
}
//15 PM2.5传感器设备
else if (dicType.ContainsKey(DeviceType.PMSensor) == true)
{
info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1307;
info.BeloneType = DeviceBeloneType.APM2点5空气质量传感器;
info.ConcreteType = DeviceConcreteType.Sensor_PMTwoPointFive;
info.ObjectTypeNameId = 60000;//传感器
}
//16色温灯
else if (dicType.ContainsKey(DeviceType.ColorTemperatureLight) == true)
{
info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId20000;
info.BeloneType = DeviceBeloneType.A彩灯;
info.ConcreteType = DeviceConcreteType.ColorLight_Temperature;
info.ObjectTypeNameId = 60007;//调光模块
}
int value = (int)info.BeloneType;
if (dicDeviceAllNameID.ContainsKey("uDeviceBelongId" + value) == true)
{
//设备所属类型的翻译名字
info.BeloneTextId = dicDeviceAllNameID["uDeviceBelongId" + value];
}
return info;
}
#endregion
#region ■ 传感器具体的类型___________________
///
/// 设置传感器具体的类型
///
/// 自定义设备枚举信息
/// 设备对象
private void SetSensorDeviceSpecificType(ref DeviceEnumInfo info, List listdevice)
{
//如果这个设备拥有多个回路的话,我也不知道怎么命名,只能给个默认名字
if (listdevice.Count > 1)
{
return;
}
var iasZone = (IASZone)listdevice[0];
if (iasZone.IasDeviceType == 13)
{
//运动传感器
info.ConcreteType = DeviceConcreteType.Sensor_Motion;
info.ConcreteTextId = R.MyInternationalizationString.uMotionSensor;
}
else if (iasZone.IasDeviceType == 40)
{
//烟雾传感器
info.ConcreteType = DeviceConcreteType.Sensor_Fire;
info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1302;
}
else if (iasZone.IasDeviceType == 42)
{
//水侵传感器
info.ConcreteType = DeviceConcreteType.Sensor_Water;
info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1304;
}
else if (iasZone.IasDeviceType == 43)
{
//燃气传感器
info.ConcreteType = DeviceConcreteType.Sensor_CarbonMonoxide;
info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1300;
}
else if (iasZone.IasDeviceType == 44)
{
//紧急按钮
info.ConcreteType = DeviceConcreteType.Sensor_EmergencyButton;
info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1305;
}
else if (iasZone.IasDeviceType == 277)
{
//钥匙扣
info.ConcreteType = DeviceConcreteType.Sensor_Keyfob;
info.ConcreteTextId = R.MyInternationalizationString.uKeyfob;
}
else if (iasZone.IasDeviceType == 21 || iasZone.IasDeviceType == 22)
{
//门窗传感器
info.ConcreteType = DeviceConcreteType.Sensor_DoorWindow;
info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1301;
}
else if (iasZone.IasDeviceType == 541)
{
//球型移动传感器
info.ConcreteType = DeviceConcreteType.Sensor_SphericalMotion;
info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1205;
}
}
#endregion
#region ■ 物理设备所属房间___________________
///
/// 初始化物理设备所属房间的记录
///
private void InitRealDeviceRoomId()
{
this.dicDeviceRoomId = new Dictionary();
string fullName = UserCenterLogic.CombinePath(DirNameResourse.DeviceRoomIdFile);
var strData = UserCenterLogic.LoadFileContent(fullName);
if (strData != null)
{
this.dicDeviceRoomId = Newtonsoft.Json.JsonConvert.DeserializeObject>(strData);
}
}
///
/// 保存物理设备所属房间的记录
///
/// 需要保存的设备对象
/// 需要保存的哪个设备的房间ID
/// 如果只有一个回路,是否把回路的房间一起修改
public void SaveRealDeviceRoomId(List listDevice, string roomId, bool saveRoadDevice = true)
{
if (listDevice == null)
{
return;
}
//如果设备只有一个回路,如果改变了真实设备区域,则它的回路的区域也一起改了
if (saveRoadDevice == true && listDevice != null && listDevice.Count == 1)
{
if (listDevice[0] is OTADevice)
{
//单纯只是Ota设备则不处理
return;
}
HdlRoomLogic.Current.ChangedRoom(listDevice[0], roomId, false);
}
bool save = false;
if (roomId == string.Empty)
{
//选择的是未分配
this.dicDeviceRoomId.Remove(listDevice[0].DeviceAddr);
save = true;
}
else
{
if (this.dicDeviceRoomId.ContainsKey(listDevice[0].DeviceAddr) == false)
{
this.dicDeviceRoomId[listDevice[0].DeviceAddr] = roomId;
save = true;
}
else
{
//2020.05.18追加:如果记录的房间ID是不存在的话,则重新覆盖
var room = HdlRoomLogic.Current.GetRoomById(this.dicDeviceRoomId[listDevice[0].DeviceAddr]);
if (room == null || this.dicDeviceRoomId[listDevice[0].DeviceAddr] != roomId)
{
this.dicDeviceRoomId[listDevice[0].DeviceAddr] = roomId;
save = true;
}
}
}
if (save == true)
{
//保存记录
string fullName = UserCenterLogic.CombinePath(DirNameResourse.DeviceRoomIdFile);
UserCenterLogic.SaveFileContent(fullName, this.dicDeviceRoomId);
//添加自动备份
HdlAutoBackupLogic.AddOrEditorFile(DirNameResourse.DeviceRoomIdFile);
}
}
///
/// 获取真实物理设备的房间名字
///
/// 设备的某一个回路
///
public string GeteRealDeviceRoomName(CommonDevice device)
{
if (this.dicDeviceRoomId.ContainsKey(device.DeviceAddr) == false)
{
//未分配区域
return Language.StringByID(R.MyInternationalizationString.uDeviceNotAssignedRoom);
}
var room = HdlRoomLogic.Current.GetRoomById(this.dicDeviceRoomId[device.DeviceAddr]);
return HdlRoomLogic.Current.GetFloorRoomName(room);
}
///
/// 获取真实物理设备属于哪个房间
///
/// 设备的某一个回路
///
public Room GeteRealDeviceRoom(CommonDevice device)
{
if (this.dicDeviceRoomId.ContainsKey(device.DeviceAddr) == false)
{
return null;
}
return HdlRoomLogic.Current.GetRoomById(this.dicDeviceRoomId[device.DeviceAddr]);
}
///
/// 将真实物理设备从房间中移除
///
/// 随便一个回路
public void DeleteRealDeviceFromRoom(CommonDevice device)
{
//将真实物理设备从房间中移除
this.DeleteRealDeviceFromRoom(new List() { device.DeviceAddr });
}
///
/// 将真实物理设备从房间中移除
///
/// 设备Mac地址
public void DeleteRealDeviceFromRoom(List listMac)
{
bool save = false;
foreach (var deviceMacAddr in listMac)
{
if (this.dicDeviceRoomId.ContainsKey(deviceMacAddr) == true)
{
this.dicDeviceRoomId.Remove(deviceMacAddr);
save = true;
}
}
if (save == false)
{
//没有改变,不需要保存
return;
}
//保存记录
string fullName = UserCenterLogic.CombinePath(DirNameResourse.DeviceRoomIdFile);
UserCenterLogic.SaveFileContent(fullName, this.dicDeviceRoomId);
//添加自动备份
HdlAutoBackupLogic.AddOrEditorFile(DirNameResourse.DeviceRoomIdFile);
}
///
/// 根据房间ID,移除指定的真实物理设备的所属房间记录
///
///
public void DeleteRealDeviceByRoomId(string i_RoomId)
{
var listDeleteKey = new List();
foreach (var deviceAddr in this.dicDeviceRoomId.Keys)
{
if (this.dicDeviceRoomId[deviceAddr] == i_RoomId
&& listDeleteKey.Contains(deviceAddr) == false)
{
listDeleteKey.Add(deviceAddr);
}
}
//将真实物理设备从房间中移除
this.DeleteRealDeviceFromRoom(listDeleteKey);
}
#endregion
#region ■ 设备排序___________________________
///
/// 设备排序
///
/// 请确保这个东西已经按mac和端点排序了
///
public List SortDeviceByBelongType(List i_listDevice)
{
//获取排序规则
var listRule = this.GetBelongTypeSortRule();
var dicDevice = new Dictionary>();
dicDevice[DeviceBeloneType.A未知设备] = new List();
foreach (var device in i_listDevice)
{
//获取所属类型
var typeInfo = this.GetDeviceBelongEnumInfo(device);
if (listRule.Contains(typeInfo.BeloneType) == false)
{
//不在排序范围内,都丢在最后面
dicDevice[DeviceBeloneType.A未知设备].Add(device);
continue;
}
if (dicDevice.ContainsKey(typeInfo.BeloneType) == false)
{
dicDevice[typeInfo.BeloneType] = new List();
}
dicDevice[typeInfo.BeloneType].Add(device);
}
var listSort = new List();
foreach (var myType in listRule)
{
//根据规则顺序,添加设备
if (dicDevice.ContainsKey(myType) == false || dicDevice[myType].Count == 0)
{
continue;
}
listSort.AddRange(dicDevice[myType]);
}
return listSort;
}
///
/// 获取设备所属类型的的排序规则
///
///
public HashSet GetBelongTypeSortRule()
{
//谁在前面,谁就优先显示
var list = new HashSet();
list.Add(DeviceBeloneType.A灯光);
list.Add(DeviceBeloneType.A彩灯);
list.Add(DeviceBeloneType.A开关);
list.Add(DeviceBeloneType.A插座);
list.Add(DeviceBeloneType.A调光器);
list.Add(DeviceBeloneType.A窗帘);
list.Add(DeviceBeloneType.A新风);
list.Add(DeviceBeloneType.A空调);
list.Add(DeviceBeloneType.A继电器);
list.Add(DeviceBeloneType.A干接点);
list.Add(DeviceBeloneType.A智能门锁);
list.Add(DeviceBeloneType.A智能空开);
list.Add(DeviceBeloneType.A传感器);
//其他的看着办呗,都是排在后面的,都归为这个属性
list.Add(DeviceBeloneType.A未知设备);
return list;
}
#endregion
#region ■ 一般方法___________________________
///
/// 从缓存变量检测设备是否在线
///
///
///
public bool CheckDeviceIsOnline(CommonDevice i_device)
{
var listDevice = this.GetDevicesByMac(i_device.DeviceAddr, false);
foreach (var device in listDevice)
{
//0:离线 1:在线 2:正在刷新状态
bool statu = i_device.IsOnline == 1 || i_device.IsOnline == 2;
if (statu == true)
{
//有一个回路在线,即在线
return true;
}
}
return false;
}
///
/// 判断该设备是否可以显示在主页
///
///
///
public bool CanShowInHomeHomeMainPage(CommonDevice i_device)
{
if (i_device == null || i_device.Type == DeviceType.OnOffSwitch)//干接点
{
//这个设备不见了
return false;
}
if (i_device.Type == DeviceType.OnOffOutput || i_device.Type == DeviceType.AirSwitch)
{
//2020.03.23追加式样:未指定类型的继电器,不显示
if (i_device.DfunctionType == DeviceFunctionType.A未定义
|| i_device.DfunctionType == DeviceFunctionType.A不指定)
{
return false;
}
}
//如果是新风面板的新风设备,则不显示
else if (i_device.Type == DeviceType.FreshAir)
{
var myInfoType = LocalDevice.Current.GetMyDeviceEnumInfo(new List() { i_device });
if (myInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueFreshAir)
{
return false;
}
}
//2020.03.30追加式样:如果是面板的温度探头,不显示
else if (i_device.Type == DeviceType.TemperatureSensor && ((TemperatureSensor)i_device).SensorDiv == 1)
{
var myInfoType = LocalDevice.Current.GetMyDeviceEnumInfo(new List() { i_device });
if (myInfoType.BeloneType == DeviceBeloneType.A按键面板)
{
return false;
}
}
else if (i_device.Type == DeviceType.FreshAirHumiditySensor)
{
//新风的湿度传感器不显示
return false;
}
return true;
}
///
/// 判断是不是河东的设备
///
///
///
public bool IsHdlDevice(CommonDevice device)
{
return device.ManufacturerName == "HDL";
}
///
/// 是否是Mini夜灯
///
///
///
public bool IsMiniLight(CommonDevice device)
{
return device.DriveCode != 0 && device.Type == DeviceType.ColorTemperatureLight;
}
///
/// 获取设备的唯一主键
///
///
///
public string GetDeviceMainKeys(CommonDevice device)
{
return this.GetDeviceMainKeys(device.DeviceAddr, device.DeviceEpoint);
}
///
/// 获取设备的唯一主键
///
/// MAC地址
/// 端口号
///
public string GetDeviceMainKeys(string DeviceAddr, int DeviceEpoint)
{
return DeviceAddr + "_" + DeviceEpoint;
}
///
/// 交换设备的模块ID
///
/// 模块ID
///
public bool ChangedDeviceModeId(ref string modeId)
{
if (this.dicDeviceModelIdChanged.ContainsKey(modeId) == false)
{
return false;
}
modeId = this.dicDeviceModelIdChanged[modeId];
return true;
}
///
/// 附加设备的版本代号(返回Ver.XXX)
///
/// 版本号
///
public string AppendVersion(int versionValue)
{
//10101 3个byte 显示为:ver.1.01.01
//中间那个byte为奇数时,代表是测试版本,在显示最新版本时,不需要显示,但是在历史版本那里可以显示
//中间那个byte为偶数时, 代表是正式版本
//直接是10进制
string txt10 = Convert.ToString(versionValue).PadLeft(6, '0');
//这个是第一位
int value1 = Convert.ToInt32(txt10.Substring(0, 2));
//这个是第二位
string value2 = txt10.Substring(2, 2);
//这个是第三位
string value3 = txt10.Substring(4, 2);
//Ver.
string ver = Language.StringByID(R.MyInternationalizationString.uVersionAbbreviation);
return ver + value1 + "." + value2 + "." + value3;
}
///
/// 显示错误信息窗口
///
///
private void ShowErrorMsg(string msg)
{
Application.RunOnMainThread(() =>
{
var contr = new ShowMsgControl(ShowMsgType.Error, msg);
contr.Show();
});
}
///
/// 显示Tip信息窗口
///
///
private void ShowTipMsg(string msg)
{
Application.RunOnMainThread(() =>
{
var contr = new ShowMsgControl(ShowMsgType.Tip, msg);
contr.Show();
});
}
#endregion
//----------------------------------分割线(自定义接口)---------------------------------------------
#region ■ 获取设备列表的接口_________________
///
/// 从网关重新获取设备列表(返回的设备为虚拟出来的)
/// statu状态 -1:异常,会返回null, 1:没有异常, 2:数据接收不全
///
/// 网关对象
/// 状态-> -1:异常,会返回null, 1:没有异常, 2:数据接收不全
/// 是否无视时间(此变量是给获取在线状态用的),true:每次调用都去网关获取,false:3分钟内返回的是本地的设备
/// 是否显示错误
///
public List GetDeviceListFromGateway(ZbGateway zbGateway, ref int statu, bool ignoreTime, ShowErrorMode mode = ShowErrorMode.YES)
{
if (ignoreTime == false)
{
if ((DateTime.Now - zbGateway.LastDateTime).TotalMilliseconds < 3 * 60 * 1000)
{
//不无视时间,返回本地设备列表
statu = 1;
return this.GetDeviceByGatewayID(zbGateway.GwId);
}
}
zbGateway.LastDateTime = DateTime.Now;
//如果切换到了别的界面,则不显示错误信息
string nowFormId = UserCenterResourse.NowActionFormID;
ZbGateway realWay = null;
if (HdlGatewayLogic.Current.GetRealGateway(ref realWay, zbGateway) == false)
{
if (nowFormId == UserCenterResourse.NowActionFormID && mode == ShowErrorMode.YES)
{
//错误:网关对象丢失
string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg);
this.ShowTipMsg(msg);
}
statu = -1;
return null;
}
//是否达成中断的时机
bool canBreak = false;
//网关ID
string gatewayID = zbGateway.GwId;
//超时时间
int TimeOut = 0;
//设备总数
int deviceCount = -1;
//接收数
int receiveCount = 0;
//设备列表
var listDevice = new List();
//网关里面有可能会有重复的回路
var listCheck = new HashSet();
Action getDeviceAction = (topic, message) =>
{
if (topic == gatewayID + "/DeviceInfoRespon")
{
try
{
lock (listDevice)
{
//设备接收数
receiveCount++;
TimeOut = 0;
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
var totalNum = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"]["TotalNum"].ToString());
if (totalNum == 0)
{
//这个网关没有设备
canBreak = true;
return;
}
if (deviceCount == -1)
{
//设置需要接收多少个设备
deviceCount = totalNum;
}
var deviceID = (DeviceType)jobject.Value("Device_ID");
//根据设备类型创建设备对象的实例
var device = this.NewDeviceObjectByDeviceId(deviceID, jobject, zbGateway);
if (device != null)
{
string mainkeys = this.GetDeviceMainKeys(device);
//网关里面有可能会有重复的回路
if (listCheck.Contains(mainkeys) == false)
{
listDevice.Add(device);
listCheck.Add(mainkeys);
//刷新一下本地缓存
var localDevice = this.GetDevice(mainkeys);
if (localDevice != null)
{
//刷新属性
this.SetDeviceInfoToMain(localDevice, device);
}
}
}
}
}
//Log出力
catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); }
if (receiveCount == deviceCount && deviceCount != -1)
{
//设备全部接收完成
canBreak = true;
}
}
else if (topic == gatewayID + "/DeviceInfoResponEnd")
{
}
};
realWay.Actions += getDeviceAction;
try
{
var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 93 } };
realWay.Send("GetDeviceInfo", jObject.ToString());
}
catch { canBreak = true; }
while (canBreak == false && TimeOut < 60)
{
System.Threading.Thread.Sleep(100);
TimeOut++;
}
realWay.Actions -= getDeviceAction;
getDeviceAction = null;
if (TimeOut >= 60)
{
if (listDevice.Count == 0)
{
if (nowFormId == UserCenterResourse.NowActionFormID && mode == ShowErrorMode.YES)
{
//获取设备列表失败
//[XXXX]网关回复超时,请稍后再试
string msg = Language.StringByID(R.MyInternationalizationString.uGetDeviceListFail);
msg += "\r\n[" + HdlGatewayLogic.Current.GetGatewayName(zbGateway).ToString() + "]";
msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时", false);
this.ShowTipMsg(msg);
}
statu = -1;
return null;
}
else
{
if (nowFormId == UserCenterResourse.NowActionFormID && mode == ShowErrorMode.YES)
{
//网络不稳定,设备列表信息缺损
string msg = Language.StringByID(R.MyInternationalizationString.uNetworkUnStableAndDeviceInfoIsNotFull);
this.ShowTipMsg(msg);
}
statu = 2;
}
}
else
{
statu = 1;
}
return listDevice;
}
#endregion
#region ■ 创建新设备对象相关_________________
///
/// 根据设备类型创建设备对象的实例
///
/// 设备类型
/// 主题Data
/// 网关对象
///
private CommonDevice NewDeviceObjectByDeviceId(DeviceType deviceType, Newtonsoft.Json.Linq.JObject jobject, ZbGateway zbGateway)
{
string gwId = zbGateway.GwId;
//根据设备类型创建设备对象的实例
CommonDevice device = this.NewDeviceObjectByDeviceId(deviceType);
if (device == null)
{
return null;
}
//设置设备属性类
device.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (device.DeviceInfo == null)
{
return null;
}
this.SetMacName(device, string.Empty);
this.SetEpointName(device, string.Empty);
//设置设备主键类
this.SetNewDeviceMainKeys(device, jobject);
device.CurrentGateWayId = gwId;
//将DeviceInfo的属性设置到主属性中
this.SetDeviceInfoToMain(device, device);
return device;
}
///
/// 将DeviceInfo的属性设置到主属性中
///
/// 主设备对象
/// 设置源设备对象
public void SetDeviceInfoToMain(CommonDevice mainDevice, CommonDevice device)
{
if (string.IsNullOrEmpty(device.DeviceInfo.MacName) == false)
{
mainDevice.DeviceName = device.DeviceInfo.MacName;
}
if (string.IsNullOrEmpty(device.DeviceInfo.DeviceName) == false)
{
mainDevice.DeviceEpointName = device.DeviceInfo.DeviceName;
}
mainDevice.CurrentGateWayId = device.CurrentGateWayId;
mainDevice.ZigbeeType = device.DeviceInfo.ZigbeeType;
mainDevice.IsOnline = device.DeviceInfo.IsOnline;
mainDevice.DriveCode = device.DeviceInfo.DriveCode;
mainDevice.IasDeviceType = device.DeviceInfo.DeviceType;
mainDevice.Profile = device.DeviceInfo.Profile;
mainDevice.Type = device.Type;
//固件版本
mainDevice.ImgVersion = device.DeviceInfo.ImgVersion;
//硬件版本
mainDevice.HwVersion = device.DeviceInfo.HwVersion;
//镜像ID
mainDevice.ImgTypeId = device.DeviceInfo.ImgTypeId;
//厂商名称
mainDevice.ManufacturerName = device.DeviceInfo.ManufacturerName;
//模块ID
mainDevice.ModelIdentifier = device.DeviceInfo.ModelIdentifier;
//序列号
mainDevice.SerialNumber = device.DeviceInfo.ProductCode;
//设备功能类型
mainDevice.DfunctionType = (DeviceFunctionType)device.DeviceInfo.FunctionType;
mainDevice.InClusterList.Clear();
mainDevice.InClusterList.AddRange(device.DeviceInfo.InClusterList);
mainDevice.OutClusterList.Clear();
mainDevice.OutClusterList.AddRange(device.DeviceInfo.OutClusterList);
//如果是温度传感器
if (mainDevice.Type == DeviceType.TemperatureSensor)
{
//输出族 1026:温度传感器 1029:湿度传感器
foreach (var data in mainDevice.OutClusterList)
{
if (data.OutCluster == 1029)
{
((TemperatureSensor)mainDevice).SensorDiv = 2;
}
else if (data.OutCluster == 1026)
{
((TemperatureSensor)mainDevice).SensorDiv = 1;
}
}
}
//如果是调光器
else if (mainDevice.Type == DeviceType.DimmableLight)
{
mainDevice.DfunctionType = DeviceFunctionType.A灯光;
if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A灯光)
{
//调光器固定灯光
this.SendDeviceFunctionTypeToGateway(mainDevice, DeviceFunctionType.A灯光);
}
if (mainDevice.IsCustomizeImage == false)
{
mainDevice.IconPath = "Device/Light.png";
}
}
//如果是色温灯
else if (mainDevice.Type == DeviceType.ColorTemperatureLight)
{
mainDevice.DfunctionType = DeviceFunctionType.A灯光;
if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A灯光)
{
//色温灯固定灯光
this.SendDeviceFunctionTypeToGateway(mainDevice, DeviceFunctionType.A灯光);
}
if (mainDevice.IsCustomizeImage == false)
{
mainDevice.IconPath = "Device/ColorLightTemperature.png";
}
}
//如果是三路继电器的回路的话,默认为灯光
else if (mainDevice.Type == DeviceType.OnOffOutput)
{
//2020.05.13变更:继电器都默认为灯光
//var myType = this.GetHdlMyDeviceEnumInfo(mainDevice);
//if (myType != null && myType.ConcreteType == DeviceConcreteType.Relay_ThreeLoad)
{
if (mainDevice.DfunctionType == DeviceFunctionType.A未定义)
{
mainDevice.DfunctionType = DeviceFunctionType.A灯光;
if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A灯光)
{
//继电器默认为灯光
this.SendDeviceFunctionTypeToGateway(mainDevice, DeviceFunctionType.A灯光);
}
}
if (mainDevice.IsCustomizeImage == false)
{
mainDevice.IconPath = "Device/Light.png";
}
}
}
//如果是空气开关的话
else if (mainDevice.Type == DeviceType.AirSwitch)
{
//空气开关默认为开关
if (mainDevice.DfunctionType == DeviceFunctionType.A未定义)
{
mainDevice.DfunctionType = DeviceFunctionType.A开关;
if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A开关)
{
//空气开关默认为开关
this.SendDeviceFunctionTypeToGateway(mainDevice, DeviceFunctionType.A开关);
}
}
if (mainDevice.IsCustomizeImage == false)
{
mainDevice.IconPath = "Device/Switch.png";
}
}
//如果是彩灯的话
else if (mainDevice.Type == DeviceType.ColorDimmableLight)
{
mainDevice.DfunctionType = DeviceFunctionType.A灯光;
if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A灯光)
{
//彩灯默认为开关
this.SendDeviceFunctionTypeToGateway(mainDevice, DeviceFunctionType.A灯光);
}
if (mainDevice.IsCustomizeImage == false)
{
mainDevice.IconPath = "Device/ColorLight.png";
}
}
}
///
/// 根据设备Type创建对应的设备对象
///
/// 设备Type
///
public CommonDevice NewDeviceObjectByDeviceId(DeviceType deviceType)
{
CommonDevice device = null;
//根据设备类型创建设备对象的实例
if (deviceType == DeviceType.ColorDimmableLight) { device = new ColorDimmableLight(); }
else if (deviceType == DeviceType.DimmableLight) { device = new DimmableLight(); }
else if (deviceType == DeviceType.ColorDimmerSwitch) { device = new ColorDimmerSwitch(); }
else if (deviceType == DeviceType.LevelControlSwitch) { device = new LevelControlSwitch(); }
else if (deviceType == DeviceType.OnOffSwitch) { device = new Panel(); }
else if (deviceType == DeviceType.OnOffOutput) { device = new ToggleLight(); }
else if (deviceType == DeviceType.AirSwitch) { device = new AirSwitch(); }
else if (deviceType == DeviceType.WindowCoveringDevice) { device = new Rollershade(); }
else if (deviceType == DeviceType.WindowCoveringController) { device = new WindowCoveringController(); }
else if (deviceType == DeviceType.IASZone) { device = new IASZone(); }
else if (deviceType == DeviceType.Repeater) { device = new Repeater(); }
else if (deviceType == DeviceType.Thermostat) { device = new AC(); }
else if (deviceType == DeviceType.FreshAir) { device = new FreshAir(); }
else if (deviceType == DeviceType.DoorLock) { device = new DoorLock(); }
else if (deviceType == DeviceType.TemperatureSensor) { device = new TemperatureSensor(); }
else if (deviceType == DeviceType.PMSensor) { device = new PMSensor(); }
else if (deviceType == DeviceType.FreshAirHumiditySensor) { device = new HumiditySensor(); }
else if (deviceType == DeviceType.ColorTemperatureLight) { device = new ColorTemperatureLight(); }
else if (deviceType == DeviceType.Buzzer) { device = new Buzzer(); }
else if (deviceType == DeviceType.OtaDevice || deviceType == DeviceType.OtaPanelDevice) { device = new OTADevice(); }
else { return null; }
device.DeviceEpointName = string.Empty;
device.DeviceName = string.Empty;
return device;
}
///
/// 给新设备设置主键属性
///
/// 设备对象
/// 主题Data
public void SetNewDeviceMainKeys(CommonDevice device, Newtonsoft.Json.Linq.JObject jobject)
{
//设置设备主键类
device.DeviceID = jobject.Value("Device_ID");
device.DeviceAddr = jobject.Value("DeviceAddr");
device.DeviceEpoint = jobject.Value("Epoint");
}
#endregion
//----------------------------------分割线(设备模块ID)---------------------------------------------
#region ■ 自定义设备模块ID___________________
///
/// 初始化设备的模块ID的枚举
///
private void InitDeviceModelIdEnum()
{
if (this.dicDeviceModelIdEnum != null)
{
return;
}
this.dicDeviceModelIdEnum = new Dictionary();
//*********************************************************************
//新设备添加方法:
//1、在这里填写上模块ID,然后是 DeviceConcreteType ,然后是 DeviceBeloneType , 然后是 设备类型的翻译ID
//2、然后在最下面的【自定义设备类型】折叠栏里添加【设备的具体类型】,【设备的所属类型】
//3、以设备的具体类型为名字(去掉【-】)添加设备的【所属图片】,【真实物理图片】。回路图片需要特殊处理
//4、添加R文件(uDeviceModelId),添加Language文件
//5、如果需要共有图片,则在这个函数的最底下添加
//*********************************************************************
//前言:因为zigbeehome的设备拥有四种名字:
//1、设备官方名称 ----它由DeviceConcreteType的数值所决定(个人中心专用)
//2、设备入网后的默认名称 ----它不需要在代码里面定义,它直接在Language文件里面定义
// 范围:50000开始,它的规则是DeviceConcreteType对应的R文件里面的ID的数值+20000,
//3、设备所属名称 ----它有DeviceBeloneType的数值所决定
//4、设备类型名称 ----它由【设备类型的翻译ID】所决定,这个值是个人中心专用,
// 它是Language文件里面的 60000之后的那些值
//定义规则:模块ID(已翻译) = 设备具体类型值 - 设备所属类型值 - 设备类型的翻译ID
//设备具体类型值:DeviceConcreteType(在这个文件最下面进行定义)
//设备所属类型值: DeviceBeloneType(自定义的值,嘛,只要不重复就可以,在这个文件最下面进行定义)
//设备类型的翻译ID:这个值是个人中心专用,它是Language文件里面的 60000之后的那些值
//=========★★开合帘类(100-199)★★=========
this.dicDeviceModelIdEnum["MWM65B-ZB.20"] = "100-100-60002";//智能开合帘电机
this.dicDeviceModelIdEnum["MVSM35B-ZB.20"] = "101-100-60002";//智能管状电机
//=========★★按键面板类(200-1199)★★=========
this.dicDeviceModelIdEnum["MPT4/R4-ZB.18"] = "200-200-60003";//4按键触摸面板(带4路继电器底座)
this.dicDeviceModelIdEnum["MPT3/R3-ZB.18"] = "201-200-60003";//3按键触摸面板
this.dicDeviceModelIdEnum["MPT2/R2-ZB.18"] = "202-200-60003";//2按键触摸面板
this.dicDeviceModelIdEnum["MPT1/R1-ZB.18"] = "203-200-60003";//12按键触摸面板
this.dicDeviceModelIdEnum["MPT4-ZB.18"] = "210-200-60003";//4按键触摸面板(只带电源底座)
this.dicDeviceModelIdEnum["MPT4R4L/S-ZB.18"] = "220-200-60003";//简约4按键面板
this.dicDeviceModelIdEnum["MPT3R3L/S-ZB.18"] = "221-200-60003";//简约3按键面板
this.dicDeviceModelIdEnum["MPT2R2L/S-ZB.18"] = "222-200-60003";//简约2按键面板
this.dicDeviceModelIdEnum["MPT4SC/S-ZB.18"] = "224-200-60003";//简约4按键场景面板
this.dicDeviceModelIdEnum["MPT2W/S-ZB.18"] = "226-200-60003";//简约2路窗帘面板
this.dicDeviceModelIdEnum["MP2B/TILE-ZB.18"] = "240-200-60003";//方悦单开双控面板
this.dicDeviceModelIdEnum["MP4B/TILE-ZB.18"] = "241-200-60003";//方悦双开四控面板
this.dicDeviceModelIdEnum["MP8B/TILE-ZB.18"] = "242-200-60003";//方悦四开八控面板
this.dicDeviceModelIdEnum["MPFA/TILE-ZB.18"] = "250-200-60003";//方悦新风面板
this.dicDeviceModelIdEnum["MPTE3/TILE-ZB.18"] = "253-200-60003";//方悦环境面板
this.dicDeviceModelIdEnum["MP2W/TILE-ZB.18"] = "256-200-60003";//窗帘面板
this.dicDeviceModelIdEnum["MPTL4C/S-ZB.18"] = "212-200-60003";//简约多功能面板
this.dicDeviceModelIdEnum["MPTE3/S-ZB.18"] = "230-200-60003";//简约环境面板
//=========★★PIR传感器类(1200-1299)★★=========
this.dicDeviceModelIdEnum["MSPIR01-ZB.10"] = "1200-1200-60000";//pir传感器220
this.dicDeviceModelIdEnum["MSPIRB-ZB.10"] = "1205-1200-60000";//球型移动传感器
//=========★★安防类传感器类(1300-2299)★★=========
//这里是麦乐克的
this.dicDeviceModelIdEnum["MULTI-GASE--EA07"] = "1300-1200-60000";//燃气传感器
this.dicDeviceModelIdEnum["MULTI-MECI--EA01"] = "1301-1200-60000";//门窗磁传感器
this.dicDeviceModelIdEnum["MULTI-FIRE--EA05"] = "1302-1200-60000";//烟雾传感器
this.dicDeviceModelIdEnum["MULTI-MOTI--EA04"] = "1303-1200-60000";//红外传感器
this.dicDeviceModelIdEnum["MULTI-WATE--EA02"] = "1304-1200-60000";//水浸传感器
this.dicDeviceModelIdEnum["MULTI-BURO--EA06"] = "1305-1200-60000";//紧急按键
//这里是河东的
this.dicDeviceModelIdEnum["MSG01/M-ZB.10"] = "1300-1200-60000";//燃气传感器
this.dicDeviceModelIdEnum["MSDC01/M-ZB.10"] = "1301-1200-60000";//门窗磁传感器
this.dicDeviceModelIdEnum["MSS01/M-ZB.10"] = "1302-1200-60000";//烟雾传感器
this.dicDeviceModelIdEnum["MSPIR01/M-ZB.10"] = "1303-1200-60000";//红外传感器
this.dicDeviceModelIdEnum["MSW01/M-ZB.10"] = "1304-1200-60000";//水浸传感器
this.dicDeviceModelIdEnum["MBU01/M-ZB.10"] = "1305-1200-60000";//紧急按键
this.dicDeviceModelIdEnum["MGCD01/M-ZB.10"] = "1306-1200-60000";//吸顶燃气传感器
//PM2.5空气质量传感器 【该设备属于第三方设备,没有镜像ID】
this.dicDeviceModelIdEnum["MSPM25/M-ZB.10"] = "1307-1200-60000";//PM2.5空气质量传感器
//=========★★继电器类(2300-2499)★★=========
this.dicDeviceModelIdEnum["MPR0310-ZB.10"] = "2300-2300-60001";//3路继电器小模块
this.dicDeviceModelIdEnum["MFA01-ZB.10"] = "2310-2300-60011";//方悦新风小模块
//=========★★调光器类(2500-2799)★★=========
this.dicDeviceModelIdEnum["MPD0101-ZB.10"] = "2500-2500-60007";//1路调光器小模块
//=========★★智能门锁类(2800-????)★★=========
this.dicDeviceModelIdEnum["H06C"] = "2800-2800-60010";//智能门锁(H06C)
this.dicDeviceModelIdEnum["S-one"] = "2802-2800-60010";//智能门锁(S-one)
//=========★★空调类(3600-3899)★★=========
this.dicDeviceModelIdEnum["MAC/GW-ZB.10"] = "3600-3600-60009";//zigbee空调网关模块
//=========★★中继器类(3900-3999)★★=========
this.dicDeviceModelIdEnum["MSR-ZB.10"] = "3900-3900-60006"; //zigbee中继器
//=========★★空气开关类(4100-4199)★★=========
this.dicDeviceModelIdEnum["MBCI01-ZB.10"] = "4100-4100-60001";//zigbee微断云控制器
//=========★★转换器类(4200-4699)★★=========
this.dicDeviceModelIdEnum["MBUS/GW-ZB.10"] = "4200-4200-60008";//zigbee转buspro协议转换器
this.dicDeviceModelIdEnum["M485/GW-ZB.10"] = "4201-4200-60008";//zigbee转485协议转换器
//✩✩✩✩✩需要交换的模块ID✩✩✩✩✩
this.dicDeviceModelIdChanged = new Dictionary();
//=========★★安防类传感器类★★=========
this.dicDeviceModelIdChanged["MULTI-GASE--EA07"] = "MSG01/M-ZB.10";//燃气传感器
this.dicDeviceModelIdChanged["MULTI-MECI--EA01"] = "MSDC01/M-ZB.10";//门窗磁传感器
this.dicDeviceModelIdChanged["MULTI-FIRE--EA05"] = "MSS01/M-ZB.10";//烟雾传感器
this.dicDeviceModelIdChanged["MULTI-MOTI--EA04"] = "MSPIR01/M-ZB.10";//红外传感器
this.dicDeviceModelIdChanged["MULTI-WATE--EA02"] = "MSW01/M-ZB.10";//水浸传感器
this.dicDeviceModelIdChanged["MULTI-BURO--EA06"] = "MBU01/M-ZB.10";//紧急按键
//✩✩✩✩✩需要共有的图片对象✩✩✩✩✩
//两者都是DeviceConcreteType
//Keys:指定的设备 value:沿用的图片是哪款设备的
this.dicPictrueShard = new Dictionary();
this.dicPictrueShard["ButtonPanel_SimpleFour"] = "ButtonPanel_Four";//简约4按键面板 沿用 4按键的图标
this.dicPictrueShard["ButtonPanel_SimpleThree"] = "ButtonPanel_Three";//简约3按键面板 沿用 3按键的图标
this.dicPictrueShard["ButtonPanel_SimpleTwo"] = "ButtonPanel_Two";//简约2按键面板 沿用 2按键的图标
this.dicPictrueShard["IntelligentLocks_Sone"] = "IntelligentLocks_H06C";//S-one的门锁图片 沿用 H06C的图标
this.dicPictrueShard["Relay_FangyueFreshAirModul"] = "Relay_ThreeLoad";//方悦新风小模块图片 沿用 3路继电器的图标
}
#endregion
}
#region ■ 自定义设备类型_________________________
///
/// 仅限底层使用:设备的具体【设备类型】,自定义与模块id关联的枚举(值为LocalDevice里面dicDeviceModelIdEnum所指定的DeviceConcreteType值)
/// 变量名可以作为【设备类型】图片,这个值是瞎写的,没什么特殊意义
///
public enum DeviceConcreteType
{
//定义规则:【设备类型】图片名字=LocalDevice里面dicDeviceModelIdEnum所指定的DeviceConcreteType值
///
/// 未知设备
///
UnKownDevice = -1,
//=========★★窗帘类(100-199)★★=========
///
/// 窗帘
///
Curtain = -100,
///
/// 智能开合帘电机 镜像id:100
///
Curtain_AutoOpen = 100,
///
/// 智能管状电机 镜像id:101
///
Curtain_Siphonate = 101,
//=========★★按键面板类(200-1199)★★=========
///
/// 按键面板
///
ButtonPanel = -200,
///
/// 4按键多功能触摸面板(带4路继电器底座) 镜像id:200
///
ButtonPanel_Four = 200,
///
/// 3按键多功能触摸面板(带3路继电器底座) 镜像id:201
///
ButtonPanel_Three = 201,
///
/// 2按键多功能触摸面板(带2路继电器底座) 镜像id:202
///
ButtonPanel_Two = 202,
///
/// 12按键多功能触摸面板(带1路继电器底座) 镜像id:203
///
ButtonPanel_Twelve = 203,
///
/// 4按键多功能触摸面板(只带电源底座) 镜像id:210
///
ButtonPanel_FourNotPower = 210,
///
/// 简约4按键面板 镜像id:220
///
ButtonPanel_SimpleFour = 220,
///
/// 简约3按键面板 镜像id:221
///
ButtonPanel_SimpleThree = 221,
///
/// 简约2按键面板 镜像id:222
///
ButtonPanel_SimpleTwo = 222,
///
/// 简约4按键场景面板 镜像id:224
///
ButtonPanel_FourButtonScene = 224,
///
/// 简约2路窗帘面板 镜像id:226
///
ButtonPanel_TwoButtonCurtain = 226,
///
/// 方悦2按键轻触式面板 镜像id:240
///
ButtonPanel_FangyueTwo = 240,
///
/// 方悦4按键轻触式面板 镜像id:241
///
ButtonPanel_FangyueFour = 241,
///
/// 方悦8按键轻触式面板 镜像id:242
///
ButtonPanel_FangyueEight = 242,
///
/// 方悦新风面板 镜像id:250
///
ButtonPanel_FangyueFreshAir = 250,
///
/// 方悦环境面板 镜像id:253
///
ButtonPanel_FangyueEnvironment = 253,
///
/// 窗帘面板 镜像id:256
///
ButtonPanel_Curtain = 256,
///
/// 简约多功能面板 镜像ID:212
///
ButtonPanel_SimpleMultifunction = 212,
///
/// 简约环境面板
///
ButtonPanel_SimpleEnvironment = 230,
//=========★★PIR传感器类(1200-1299)★★=========
///
/// 传感器
///
Sensor = -1200,
///
/// pir传感器220 镜像id:1200
///
Sensor_Pir = 1200,
///
/// 球形移动传感器 镜像id:1205
///
Sensor_SphericalMotion = 1205,
//=========★★安防类传感器类(1300-2299)★★=========
///
/// 燃气传感器
///
Sensor_CarbonMonoxide = 1300,
///
/// 门窗传感器
///
Sensor_DoorWindow = 1301,
///
/// 烟雾传感器
///
Sensor_Fire = 1302,
///
/// 红外传感器
///
Sensor_Infrared = 1303,
///
/// 水侵传感器
///
Sensor_Water = 1304,
///
/// 紧急按钮
///
Sensor_EmergencyButton = 1305,
///
/// 吸顶燃气传感器
///
Sensor_CeilingGas = 1306,
///
/// PM2.5空气质量传感器
///
Sensor_PMTwoPointFive = 1307,
///
/// 运动传感器
///
Sensor_Motion = -1306,
///
/// 钥匙扣
///
Sensor_Keyfob = -1307,
///
/// 温湿度传感器
///
Sensor_TemperatureHumidity = -1308,
///
/// 温度传感器
///
Sensor_Temperature = -1309,
///
/// 湿度传感器
///
Sensor_Humidity = -1310,
//=========★★继电器类(2300-2499)★★=========
///
/// 继电器
///
Relay = -2300,
///
/// 三路继电器 镜像id:2300
///
Relay_ThreeLoad = 2300,
///
/// 方悦新风小模块 镜像id:2310
///
Relay_FangyueFreshAirModul = 2310,
//=========★★调光器类(2500-2799)★★=========
///
/// 调光器
///
DimmableLight = -2500,
///
/// 1路调光器小模块
///
DimmableLight_OneLoad = 2500,
//=========★★智能门锁类(2800-????)★★=========
///
/// 智能门锁
///
IntelligentLocks = -2800,
///
/// H06C
///
IntelligentLocks_H06C = 2800,
///
/// S-one
///
IntelligentLocks_Sone = 2802,
//=========★★彩灯类(????-????)★★=========
///
/// 彩灯
///
ColorLight = -10,
///
/// 色温灯(它的镜像ID未定,暂定20000)
///
ColorLight_Temperature = 20000,
//=========★★空调(3600-3899)★★=========
///
/// 空调
///
AirConditioner = -3600,
///
/// zigbee空调网关模块
///
AirConditioner_ZbGateway = 3600,
//=========★★中继器(3900-3999)★★=========
///
/// 中继器
///
Repeater = -3900,
///
/// zigbee中继器 镜像id:3900
///
Repeater_Zigbee = 3900,
//=========★★空气开关类(4100-????)★★=========
///
/// 智能空开
///
AirSwitch = -4100,
///
/// 智能空开 镜像id:4100
///
AirSwitch_CloudContr = 4100,
//=========★★转换器类(4200-4699)★★=========
///
/// 转换器
///
Converter = -4200,
///
/// zigbee转485协议转换器
///
Converter_Zb485 = 4200,
///
/// zigbee转buspro协议转换器
///
Converter_ZbBuspro = 4201,
//=========★★其他类(????-????)★★=========
///
/// 干接点(注意,它属于其他类,不是设备类型)
///
DryContact = -10000,
///
/// 灯光(注意,它属于其他类,不是设备类型)
///
Light = -10001,
///
/// 插座(注意,它属于其他类,不是设备类型)
///
Socket1 = -10002,
///
/// 开关(注意,它属于其他类,不是设备类型)
///
Switch = -10003,
}
///
/// 仅限底层使用:设备所属的【设备种类】,自定义与模块id关联的枚举(值为LocalDevice里面dicDeviceModelIdEnum所指定的DeviceBeloneType值)
/// 这个值是瞎写的,没什么特殊意义
///
public enum DeviceBeloneType
{
///
/// 未知设备
///
A未知设备 = 0,
///
/// 窗帘(100-199)
///
A窗帘 = 100,
///
/// 按键面板(200-1199)
///
A按键面板 = 200,
///
/// 传感器(1200-2299)
///
A传感器 = 1200,
///
/// PM2.5空气质量传感器
///
APM2点5空气质量传感器 = 1307,
///
/// 继电器(2300-2499)
///
A继电器 = 2300,
///
/// 新风
///
A新风 = 2310,
///
/// 调光器(2500-2799)
///
A调光器 = 2500,
///
/// 智能门锁(2800-????)
///
A智能门锁 = 2800,
///
/// 空调(3600-3899)
///
A空调 = 3600,
///
/// 中继器(3900-3999)
///
A中继器 = 3900,
///
/// 智能空开(4100-4199)
///
A智能空开 = 4100,
///
/// 转换器(4200-4699)
///
A转换器 = 4200,
///
/// 彩灯
///
A彩灯 = 9,
///
/// 温湿度传感器
///
A温湿度传感器 = 10,
///
/// 温度传感器
///
A温度传感器 = 11,
///
/// 湿度传感器
///
A湿度传感器 = 12,
///
/// 开关
///
A开关 = 13,
///
/// 插座
///
A插座 = 14,
///
/// 灯光
///
A灯光 = 15,
///
/// 干接点
///
A干接点 = 16,
}
#endregion
}