//using System;
//using System.Collections.Generic;
//using Shared;
//namespace SmartHome
//{
// ///
// /// HDLLink协议 工具类
// ///
// public class HDLLinkUtlis
// {
// #region ■ Current___________________________
// ///
// /// 通用方法
// ///
// private static HDLLinkUtlis m_Current = null;
// ///
// /// 通用方法
// ///
// public static HDLLinkUtlis Current {
// get {
// if (m_Current == null) {
// m_Current = new HDLLinkUtlis ();
// }
// return m_Current;
// }
// }
// #endregion
// ///
// /// 将在线设备转换成sid + 属性列表
// ///
// ///
// ///
// public List ConvertToSidListToIotCloud (string sOid, Common onlineDevice)
// {
// List tmpResult = new List ();
// try {
// if (onlineDevice.bytSimpleParam == null || onlineDevice.bytSimpleParam.Length == 0) {
// string sSimpleList = DeviceTypeList.GetSimpleFunctionListFromPublicModeGroup (onlineDevice.DeviceType);
// #region
// string [] ArayStr = sSimpleList.Trim ().Split (new char [] { ' ' });
// List ArayTmp = new List ();
// for (int i = 0; i < ArayStr.Length; i++) {
// if (ArayStr [i] != null && ArayStr [i] != "" && ArayStr [i].Trim () != "") {
// ArayTmp.Add (Convert.ToByte (ArayStr [i], 16));
// }
// }
// onlineDevice.bytSimpleParam = ArayTmp.ToArray ();
// #endregion
// }
// if (onlineDevice.bytSimpleParam != null && onlineDevice.bytSimpleParam.Length > 0) {
// for (int intI = 0; intI < onlineDevice.bytSimpleParam.Length / 3; intI++) {
// Byte BigType = onlineDevice.bytSimpleParam [0 + intI * 3];
// Byte SmallType = onlineDevice.bytSimpleParam [1 + intI * 3];
// int Count = onlineDevice.bytSimpleParam [2 + intI * 3];
// if (Count > 0) {
// for (int j = 1; j <= Count; j++) {
// Sid tmpSid = new Sid ();
// tmpSid.sid = HDLSysPF.FormingNewSid (onlineDevice.DeviceType, sOid, j, false, BigType, SmallType);
// tmpSid.oid = sOid;
// try {
// tmpSid.name = onlineDevice.myEasyDesignChannelRemark [intI] [j - 1];
// } catch (Exception ex) {
// tmpSid.name = "";
// }
// if (tmpSid.name == null || tmpSid.name == "" || tmpSid.name == "Unread") {
// tmpSid.name = onlineDevice.Remark + CsConst.mstrINIDefault.IniReadValue ("public", "00000", "") + " " + j.Tostring ();
// if (onlineDevice.Remark == "") {
// tmpSid.name = onlineDevice.strDescription + CsConst.mstrINIDefault.IniReadValue ("public", "00000", "") + " " + j.Tostring ();
// }
// }
// GateWay.sidObject tmp = HDLSysPF.UpdateSidAttributesToDeviceList (onlineDevice, tmpSid.name, sOid, j, BigType, SmallType, true);
// tmpSid.attributes = tmp.attributes;//UpdateSidAttributesToDeviceList(onlineDevice.DeviceType, sOid, j, BigType, SmallType, ref spk);
// tmpSid.spk = tmp.spk;
// tmpResult.Add (tmpSid);
// }
// }
// }
// }
// return tmpResult;
// } catch (Exception) {
// return tmpResult;
// //throw;
// }
// }
// ///
// ///
// ///
// ///
// ///
// ///
// ///
// public void ConvertOidListToIotStruct (string homeId, List onlineDevices, string gatewayId, ref IotCloud currentProject)
// {
// try {
// //step 1 ;抓换类型
// Sids functionList = currentProject.functions;
// List tmpFunction = new List ();
// //step 2 转换类型
// Oids tmp = ConvertToOidListToIotCloud (onlineDevices, ref tmpFunction);
// if (currentProject.modules == null || currentProject.modules.devices == null || currentProject.modules.devices.Count == 0) currentProject.modules = tmp;
// else {
// foreach (Oid tmpModule in tmp.devices) {
// Oid tmpFind = currentProject.modules.devices.Find (P => P.mac.Equals (tmpModule.mac));
// if (tmpFind == null) currentProject.modules.devices.Add (tmpModule);
// }
// }
// tmp.homeId = homeId;
// //上传功能列表
// #region
// //if (functionList == null)
// //{
// functionList = new Sids ();
// functionList.devices = new List ();
// functionList.devices = tmpFunction;
// //}
// functionList.homeId = homeId;
// functionList.gatewayId = gatewayId;
// currentProject.modules = tmp;
// currentProject.functions = functionList;
// #endregion
// } catch (Exception ex) {
// //MessageBox.Show (ex.Tostring ());
// //throw;
// }
// }
// ///
// ///
// ///
// ///
// ///
// ///
// ///
// public void ConvertOidListToIotStruct (string homeId, List onlineDevices, string gatewayId, ref IotCloud currentProject)
// {
// try {
// //step 1 转换类型
// Sids functionList = currentProject.functions;
// List tmpFunction = new List ();
// //step 2 转换类型
// Oids tmp = ConvertToOidListToIotCloud (onlineDevices, ref tmpFunction);
// if (currentProject.modules == null || currentProject.modules.devices == null || currentProject.modules.devices.Count == 0) currentProject.modules = tmp;
// else {
// foreach (Oid tmpModule in tmp.devices) {
// Oid tmpFind = currentProject.modules.devices.Find (P => P.mac.Equals (tmpModule.mac));
// if (tmpFind == null) currentProject.modules.devices.Add (tmpModule);
// }
// }
// tmp.homeId = homeId;
// //上传功能列表
// #region
// //if (functionList == null)
// //{
// functionList = new Sids ();
// functionList.devices = new List ();
// functionList.devices = tmpFunction;
// //}
// functionList.homeId = homeId;
// functionList.gatewayId = gatewayId;
// currentProject.modules = tmp;
// currentProject.functions = functionList;
// #endregion
// } catch (Exception ex) {
// //MessageBox.Show (ex.Tostring ());
// //throw;
// }
// }
// ///
// /// 生成设备Oid
// ///
// ///
// ///
// public string FormingNewOid (int iDeviceType)
// {
// string sOid = "";
// try {
// string sOidBeginsWith = "000101";//厂商 + 通讯方式
// long sTimeSp = HDLSysPF.ConvertDateTimeLong ();
// string sTimeSpan = "";
// GateWay.ConvertIntToByteArray (sTimeSp, ref sTimeSpan);
// if (sTimeSpan.Length != 8) return sOid;
// HDLUDP.TimeBetwnNext (10);
// sOid = sOidBeginsWith + sTimeSpan;
// if (iDeviceType == 00
// || DimmerDeviceTypeList.HDLDimmerDeviceTypeList.Contains (iDeviceType)
// || DMXDeviceTypeList.HDLDMXDeviceTypeList.Contains (iDeviceType))//调光器 20200730类
// {
// sOid += "01";
// } else if (RelayDeviceTypeList.HDLRelayDeviceTypeList.Contains (iDeviceType))//继电器类
// {
// sOid += "02";
// } else if (CurtainDeviceType.HDLCurtainModuleDeviceType.Contains (iDeviceType))//遮阳类(窗帘)
// {
// sOid += "03";
// } else if (HVACModuleDeviceTypeList.HDLHVACModuleDeviceTypeLists.Contains (iDeviceType) || FloorheatingDeviceTypeList.HDLFloorHeatingDeviceType.Contains (iDeviceType))//恒温器(空调)
// {
// sOid += "12";
// } else if (AudioDeviceTypeList.AudioBoxDeviceTypeList.Contains (iDeviceType)) {
// sOid += "10";
// } else if (Eightin1DeviceTypeList.HDL8in1DeviceType.Contains (iDeviceType)
// || Sevenin1DeviceTypeList.HDL7in1DeviceType.Contains (iDeviceType)
// || Twelvein1DeviceTypeList.HDL12in1DeviceType.Contains (iDeviceType))//传感器类
// {
// sOid += "04";
// } else {
// sOid += "07"; //网关产品
// }
// return sOid;
// } catch {
// return sOid;
// }
// }
// ///
// /// 生成功能设备Sid
// ///
// ///
// ///
// ///
// ///
// ///
// ///
// ///
// public string FormingNewSid (int iDeviceType, string sOid, int iChnId, bool isUseE548ReturnBigSmallType, byte BigType, byte SmallType)
// {
// if (sOid == null || sOid == "") return "";
// try {
// string sSid = "";
// if (DimmerDeviceTypeList.HDLDimmerDeviceTypeList.Contains (iDeviceType)) {
// if (DimmerDeviceTypeList.DALIDimmerDeviceTypeLists.Contains (iDeviceType)) {
// BigType = 1;
// SmallType = 7;
// sSid += "0203";
// } else {
// sSid += "0202";
// }
// } else if (RelayDeviceTypeList.HDLRelayDeviceTypeList.Contains (iDeviceType)) {
// sSid += "0201";
// } else if (CurtainDeviceType.HDLCurtainModuleDeviceType.Contains (iDeviceType)) {
// if (CurtainDeviceType.NormalMotorCurtainDeviceType.Contains (iDeviceType) || (iDeviceType == 9700)) //所有开合帘 //0 2020 05 24创明开合帘
// {
// sSid += "0303";
// } else if (CurtainDeviceType.RollerCurtainDeviceType.Contains (iDeviceType)
// || (iDeviceType == 9701))//所有 卷帘控制器
// {
// sSid += "0304";
// } else {
// sSid += "0301";
// }
// } else if (HVACModuleDeviceTypeList.HDLHVACModuleDeviceTypeLists.Contains (iDeviceType)) {
// sSid += "0401";
// } else if (Eightin1DeviceTypeList.HDL8in1DeviceType.Contains (iDeviceType)
// || Sevenin1DeviceTypeList.HDL7in1DeviceType.Contains (iDeviceType)
// || HaikeSensorDeviceTypeList.HaikeSensorDeviceType.Contains (iDeviceType)
// || Twelvein1DeviceTypeList.HDL12in1DeviceType.Contains (iDeviceType)
// || Rs232DeviceTypeList.HDLRs232DeviceType.Contains (iDeviceType)) {
// if (BigType == 19 && SmallType == 0) {
// sSid += "1301";
// } else if (BigType == 5 && SmallType == 0) {
// sSid += "0519";
// } else {
// sSid += BigType.Tostring ("X2") + SmallType.Tostring ("X2");
// }
// } else if (FloorheatingDeviceTypeList.HDLFloorHeatingDeviceType.Contains (iDeviceType)) {
// sSid += "0402";
// } else if (DMXDeviceTypeList.HDLDMXDeviceTypeList.Contains (iDeviceType)) {
// sSid += "0204";
// } else if (DimmerDeviceTypeList.DALIDimmerDeviceTypeLists.Contains (iDeviceType)) {
// sSid += "0203";
// } else if (AudioDeviceTypeList.AudioBoxDeviceTypeList.Contains (iDeviceType)) {
// sSid += "0901";
// }
// string sTmpWithE548 = sSid;
// sSid = sOid + sSid + iChnId.Tostring ("X4");
// if (isUseE548ReturnBigSmallType) {
// sSid += BigType.Tostring ("X2") + SmallType.Tostring ("X2");
// } else {
// sSid += sTmpWithE548;
// }
// return sSid;
// } catch {
// return "";
// }
// }
// }
// [Serializable]
// public class Sids : BaseCloudFeedback
// {
// public string homeId { get; set; }
// public string gatewayId { get; set; }
// public List devices { get; set; }
// }
// [Serializable]
// public class BaseCloudFeedback
// {
// public int code { get; set; }
// public string timestamp { get; set; }
// public bool isSuccess { get; set; }
// public string message { get; set; }
// }
// [Serializable]
// public class Oids : BaseCloudFeedback
// {
// public string homeId { get; set; }
// public string gatewayId { get; set; }
// public List devices { get; set; }
// }
// [Serializable]
// public class Oid
// {
// public string protocolType { get; set; }
// public string device_name { get; set; }
// public string oid { get; set; }
// public string addresses { get; set; }
// public string device_model { get; set; }
// public string fw_version { get; set; }
// public string hw_info { get; set; }
// public string mac { get; set; }
// public string deviceType { get; set; }
// }
// [Serializable]
// public class Sid
// {
// public string sid { get; set; }
// public string name { get; set; }
// public string[] uids { get; set; }
// public string spk { get; set; }
// public string oid { get; set; } //设备模块地址
// public string omodel { get; set; } //型号
// public List attributes { get; set; } //属性列表
// }
// [Serializable]
// public class Function
// {
// //public string name { get; set; }
// public string key { get; set; }
// public List value { get; set; }
// public int max { get; set; }
// public int min { get; set; }
// public string data_type { get; set; }
// }
//}