From 2b380862ab304f049ae7181a058b0791671d1bb4 Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期二, 23 二月 2021 09:39:54 +0800
Subject: [PATCH] 2021-02-23 1.增加场景数据转换和上传测试方法。2.增加风扇和通用开关设备spk
---
Crabtree/SmartHome/HDL/Common/HDLLinkUtlis.cs | 894 ++++++++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 670 insertions(+), 224 deletions(-)
diff --git a/Crabtree/SmartHome/HDL/Common/HDLLinkUtlis.cs b/Crabtree/SmartHome/HDL/Common/HDLLinkUtlis.cs
index 7b0d2f2..996ecc4 100644
--- a/Crabtree/SmartHome/HDL/Common/HDLLinkUtlis.cs
+++ b/Crabtree/SmartHome/HDL/Common/HDLLinkUtlis.cs
@@ -10,6 +10,60 @@
/// </summary>
public class HDLLinkUtlis
{
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="curtainStatus"></param>
+ /// <returns></returns>
+ public static string GetCurtainStatusKey (CurtainStatus curtainStatus) {
+ if(curtainStatus == CurtainStatus.Open) {
+ return "on";
+ } else if (curtainStatus == CurtainStatus.Close) {
+ return "off";
+ } else if (curtainStatus == CurtainStatus.Stop) {
+ return "stop";
+ } else {
+ return "off";
+ }
+
+ }
+
+ #region 鐢熸垚4浣峛yte 鏃堕棿鎴�
+ private static long LastTime = 0;
+ /// <summary>
+ /// DateTime鏃堕棿鏍煎紡杞崲涓�13浣嶅甫姣鐨刄nix鏃堕棿鎴�
+ /// </summary>
+ /// <param name="time"> DateTime鏃堕棿鏍煎紡</param>
+ /// <returns>Unix鏃堕棿鎴虫牸寮�</returns>
+ public static long ConvertDateTimeLong ()
+ {
+ System.DateTime startTime = TimeZoneInfo.ConvertTimeToUtc (new System.DateTime (2020, 1, 1));
+ long l = (long)(Math.Round ((DateTime.Now - startTime).TotalSeconds, 1) * 10);
+ if (l <= LastTime) l = LastTime + 1;
+ LastTime = l;
+ return l;
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="m"></param>
+ /// <param name="strTmp"></param>
+ /// <returns></returns>
+ public static bool ConvertIntToByteArray (long m, ref string strTmp)
+ {
+ strTmp = "00000000";
+ byte [] arry = new byte [4];
+ arry [0] = (byte)(m & 0xFF);
+ arry [1] = (byte)((m & 0xFF00) >> 8);
+ arry [2] = (byte)((m & 0xFF0000) >> 16);
+ arry [3] = (byte)((m & 0xFF000000) >> 24);
+ strTmp = arry [0].ToString ("X2") + arry [1].ToString ("X2") + arry [2].ToString ("X2") + arry [3].ToString ("X2");
+ return true;
+ }
+ #endregion
+
+
+
#region 鈻� Current___________________________
/// <summary>
/// 閫氱敤鏂规硶
@@ -28,11 +82,425 @@
}
#endregion
+ #region 鈻� 涓婁紶鍦烘櫙鍒楄〃___________________________
+ /// <summary>
+ /// 涓婁紶鍦烘櫙鍒楄〃
+ /// </summary>
+ public bool UploadSecneList ()
+ {
+ var res = false;
+ try {
+ //1.鍔犺浇鎵�鏈夊満鏅苟杞崲
+ var allSecneList = GetAllSecneList ();
+ var hdlLinkSceneList = new List<HDLLinkScene> ();
+ foreach (var sence in allSecneList) {
+ var mHDLLinkScene = GetHDLLinkScene (sence);
+ //1.1鎴愬姛杞崲鐨勫満鏅墠娣诲姞鍒板噯澶囦笂浼犲垪琛�
+ if(mHDLLinkScene != null && mHDLLinkScene.functions != null && mHDLLinkScene.functions.Count > 0) {
+ hdlLinkSceneList.Add (mHDLLinkScene);
+ }
+ }
+ //2.涓婁紶鍦烘櫙
+ res = UploadSceneList (hdlLinkSceneList);
-
+ } catch (Exception ex){
+ Utlis.WriteLine ("catch :" + ex.ToString ());
+ }
+ return res;
+ }
+
+
+ /// <summary>
+ /// 鑾峰彇鎵�鏈夊満鏅垪琛�
+ /// </summary>
+ /// <returns></returns>
+ public List<Scene> GetAllSecneList ()
+ {
+ List<Scene> targetSceneList = new List<Scene> ();
+ //// 鎵惧嚭闇�瑕佹樉绀虹殑鍦烘櫙
+ // 1.鍏ㄥ眬鍦烘櫙
+ var globalSceneFileList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (Scene.GlobalSceneFilePath)));
+ if (globalSceneFileList == null) {
+ globalSceneFileList = new List<string> ();
+ }
+ // 2.鎴块棿鍦烘櫙
+ List<string> RoomsSceneFileList = new List<string> ();
+ foreach (var r in Room.Lists) {
+ if (string.IsNullOrEmpty (r.Name)) {
+ continue;
+ }
+ if (r != null) {
+ RoomsSceneFileList.AddRange (r.SceneFilePathList);
+ }
+ }
+
+ foreach (var list in globalSceneFileList) {
+ var tempScene = Scene.GetSceneByFilePath (list);
+ if (tempScene != null) {
+ targetSceneList.Add (tempScene);
+ }
+ }
+
+ foreach (var list in RoomsSceneFileList) {
+ var tempScene = Scene.GetSceneByFilePath (list);
+ if (tempScene != null) {
+ targetSceneList.Add (tempScene);
+ }
+ }
+ // 鎵�鏈夊満鏅�
+ return targetSceneList;
+ }
/// <summary>
///
+ /// </summary>
+ /// <param name="mScene"></param>
+ bool UploadSceneList (List<HDLLinkScene> hdlLinkSceneList)
+ {
+ var res = false;
+ try {
+ var revertObj = HttpServerRequest.Current.AddScene (hdlLinkSceneList);
+ if (revertObj.Code == StateCode.SUCCESS) {
+ res = true;
+ } else {
+ IMessageCommon.Current.ShowErrorInfoAlter (revertObj.Code);
+ }
+ } catch {
+
+ }
+ return res;
+ }
+
+ /// <summary>
+ /// 鍘熺敓鍗忚Scene 杞崲鎴� HDLLinkScene鏁版嵁鏍煎紡
+ /// </summary>
+ /// <param name="mScene"></param>
+ /// <returns></returns>
+ HDLLinkScene GetHDLLinkScene (Scene mScene)
+ {
+ var mHDLLinkScene = new HDLLinkScene ();
+ //mHDLLinkScene.sid = mHDLLinkScene.NewSid();
+ mHDLLinkScene.sid = mScene.SceneID;
+ mHDLLinkScene.name = mScene.Name;
+ if (UserConfig.Instance.CheckWhetherGatewayIdNotNull ()) {
+ mHDLLinkScene.gatewayId = UserConfig.Instance.HomeGateway.gatewayId;
+ }
+ var functions = new List<SceneFunction> ();
+ if (!mScene.busScene) {
+ foreach (var deviceFilePath in mScene.DeviceFilePathList) {
+ var jsonInfo = System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath));
+ var common = Newtonsoft.Json.JsonConvert.DeserializeObject<Common> (jsonInfo);
+ if (common == null) continue;
+
+ var function = CommonUtlis.Current.CommonToFunction (common, CommonConfig.Current.FunctionList);
+ if (function == null) continue;
+
+ if (common.Type == DeviceType.LightDimming) {
+ var commonNew = Newtonsoft.Json.JsonConvert.DeserializeObject<LightDimming> (jsonInfo);
+ var mSceneFunction = new SceneFunction ();
+ mSceneFunction.sid = function.sid;
+ //1.Brightness
+ var status = new List<SceneFunctionStatus> ();
+ status.Add (new SceneFunctionStatus () {
+ key = FunctionAttributeKey.Brightness,
+ value = commonNew.CurrentBrightness.ToString(),
+ });
+ //2.Delay
+ status.Add (new SceneFunctionStatus () {
+ key = FunctionAttributeKey.Delay,
+ value = (commonNew.DelayTimeHeight * 256 + commonNew.DelayTimeLow).ToString (),
+ });
+
+ mSceneFunction.status = status;
+ functions.Add (mSceneFunction);
+
+ } else if (common.Type == DeviceType.LightEnergySocket) {
+ var commonNew = Newtonsoft.Json.JsonConvert.DeserializeObject<LightEnergySocket> (jsonInfo);
+ var mSceneFunction = new SceneFunction ();
+ mSceneFunction.sid = function.sid;
+ //1.on_off
+ var status = new List<SceneFunctionStatus> ();
+ status.Add (new SceneFunctionStatus () {
+ key = FunctionAttributeKey.OnOff,
+ value = commonNew.CurrentBrightness > 0 ? "on" : "off",
+ });
+ //2.Delay
+ status.Add (new SceneFunctionStatus () {
+ key = FunctionAttributeKey.Delay,
+ value = (commonNew.DelayTimeHeight * 256 + commonNew.DelayTimeLow).ToString (),
+ });
+
+ mSceneFunction.status = status;
+ functions.Add (mSceneFunction);
+
+
+ } else if (common.Type == DeviceType.LightEnergySwitch) {
+ var commonNew = Newtonsoft.Json.JsonConvert.DeserializeObject<LightEnergySwitch> (jsonInfo);
+ var mSceneFunction = new SceneFunction ();
+ mSceneFunction.sid = function.sid;
+ //1.on_off
+ var status = new List<SceneFunctionStatus> ();
+ status.Add (new SceneFunctionStatus () {
+ key = FunctionAttributeKey.OnOff,
+ value = commonNew.CurrentBrightness > 0 ? "on" : "off",
+ });
+ //2.Delay
+ status.Add (new SceneFunctionStatus () {
+ key = FunctionAttributeKey.Delay,
+ value = (commonNew.DelayTimeHeight * 256 + commonNew.DelayTimeLow).ToString(),
+ });
+
+ mSceneFunction.status = status;
+ functions.Add (mSceneFunction);
+
+
+ } else if (common.Type == DeviceType.LightRGB) {
+ var commonNew = Newtonsoft.Json.JsonConvert.DeserializeObject<LightLogic> (jsonInfo);
+ var mSceneFunction = new SceneFunction ();
+ mSceneFunction.sid = function.sid;
+ //1.Brightness
+ var status = new List<SceneFunctionStatus> ();
+ status.Add (new SceneFunctionStatus () {
+ key = FunctionAttributeKey.Brightness,
+ value = commonNew.CurrentBrightness.ToString (),
+ });
+ //2.Delay
+ status.Add (new SceneFunctionStatus () {
+ key = FunctionAttributeKey.Delay,
+ value = (commonNew.DelayTimeHeigh * 256 + commonNew.DelayTimeLow).ToString (),
+ });
+
+ //3.rgb
+ status.Add (new SceneFunctionStatus () {
+ key = FunctionAttributeKey.RGB,
+ value = commonNew.RStatus + "," + commonNew.GStatus + "," + commonNew.BStatus,
+ });
+
+ mSceneFunction.status = status;
+ functions.Add (mSceneFunction);
+
+ //var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightLogic> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
+ ////if (device == null) {
+ //// mSendCount--;
+ //// continue;
+ ////}
+ //if (device == null) {
+ // //replyBytes = new byte [] { 0x00 };
+ //} else {
+ // var mSceneFunction = new SceneFunction ();
+ // functions.Add (mSceneFunction);
+ // replyBytes = Control.ControlBytesSendHasReturn (Command.SetLogicLoopColor, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, 254, device.DelayTimeHeigh,device.DelayTimeLow,
+ // 3,device.RStatus,device.GStatus,device.BStatus,0,0});
+ //}
+
+ } else if (common.Type == DeviceType.LightSwitch) {
+ var commonNew = Newtonsoft.Json.JsonConvert.DeserializeObject<LightSwitch> (jsonInfo);
+ var mSceneFunction = new SceneFunction ();
+ mSceneFunction.sid = function.sid;
+ //1.Brightness
+ var status = new List<SceneFunctionStatus> ();
+ status.Add (new SceneFunctionStatus () {
+ key = FunctionAttributeKey.OnOff,
+ value = commonNew.CurrentBrightness > 0 ? "on" : "off",
+ });
+ //2.Delay
+ status.Add (new SceneFunctionStatus () {
+ key = FunctionAttributeKey.Delay,
+ value = (commonNew.DelayTimeHeight * 256 + commonNew.DelayTimeLow).ToString (),
+ });
+
+ mSceneFunction.status = status;
+ functions.Add (mSceneFunction);
+
+
+ } else if (common.Type == DeviceType.CurtainModel) {
+ var commonNew = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainModel> (jsonInfo);
+ var mSceneFunction = new SceneFunction ();
+ mSceneFunction.sid = function.sid;
+ //1.on_off stop
+ var status = new List<SceneFunctionStatus> ();
+ status.Add (new SceneFunctionStatus () {
+ key = FunctionAttributeKey.OnOff,
+ value = GetCurtainStatusKey(commonNew.Status),
+ });
+
+ mSceneFunction.status = status;
+ functions.Add (mSceneFunction);
+
+
+ } else if (common.Type == DeviceType.CurtainRoller) {
+ var commonNew = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainRoller> (jsonInfo);
+ var mSceneFunction = new SceneFunction ();
+ mSceneFunction.sid = function.sid;
+ //1.percent
+ var status = new List<SceneFunctionStatus> ();
+ status.Add (new SceneFunctionStatus () {
+ key = FunctionAttributeKey.Percent,
+ value = commonNew.CurtainProress.ToString(),
+ });
+
+ mSceneFunction.status = status;
+ functions.Add (mSceneFunction);
+
+
+ } else if (common.Type == DeviceType.CurtainTrietex) {
+ var commonNew = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainTrietex> (jsonInfo);
+ var mSceneFunction = new SceneFunction ();
+ mSceneFunction.sid = function.sid;
+ //1.percent
+ var status = new List<SceneFunctionStatus> ();
+ status.Add (new SceneFunctionStatus () {
+ key = FunctionAttributeKey.Percent,
+ value = commonNew.CurtainProress.ToString (),
+ });
+
+ mSceneFunction.status = status;
+ functions.Add (mSceneFunction);
+ } else if (common.Type == DeviceType.HVAC || common.Type == DeviceType.ACInfrared) {
+ var commonNew = Newtonsoft.Json.JsonConvert.DeserializeObject<HVAC> (jsonInfo);
+ var mSceneFunction = new SceneFunction ();
+ mSceneFunction.sid = function.sid;
+ //1.on_off
+ var status = new List<SceneFunctionStatus> ();
+ status.Add (new SceneFunctionStatus () {
+ key = FunctionAttributeKey.OnOff,
+ value = commonNew.Power > 0 ? "on" : "off",
+ });
+
+ //2.mode
+ status.Add (new SceneFunctionStatus () {
+ key = FunctionAttributeKey.Mode,
+ value = commonNew.SetModeAttribute,
+ });
+
+ //3.fan
+ status.Add (new SceneFunctionStatus () {
+ key = FunctionAttributeKey.FanSpeed,
+ value = commonNew.SetFanSpeedAttribute,
+ });
+
+ //4.SetTemp
+ status.Add (new SceneFunctionStatus () {
+ key = FunctionAttributeKey.SetTemp,
+ value = commonNew.SetTemperature.ToString(),
+ });
+
+ mSceneFunction.status = status;
+ functions.Add (mSceneFunction);
+
+ //replyBytes = Control.ControlBytesSendHasReturn (Command.SetACMode, device.SubnetID, device.DeviceID, new byte [] {
+ // device.LoopID,
+ // device.TemperatureMode,
+ // device.IndoorTemperature,
+ // device.CoolTemperature,
+ // device.HeatTemperature,
+ // device.AutoTemperature,
+ // device.ChuShiTemperature,
+ // device.RealModeAndFanSpeed,
+ // device.Power,
+ // device.SetMode,
+ // device.SetFanSpeed,
+ // device.SetTemperature,
+ // device.ShaoFanMode});
+
+
+
+ } else if (common.Type == DeviceType.FoolHeat) {
+ var commonNew = Newtonsoft.Json.JsonConvert.DeserializeObject<FoolHeat> (jsonInfo);
+ var mSceneFunction = new SceneFunction ();
+ mSceneFunction.sid = function.sid;
+ //1.on_off
+ var status = new List<SceneFunctionStatus> ();
+ status.Add (new SceneFunctionStatus () {
+ key = FunctionAttributeKey.OnOff,
+ value = commonNew.Status > 0 ? "on" : "off",
+ });
+
+ //2.mode
+ status.Add (new SceneFunctionStatus () {
+ key = FunctionAttributeKey.Mode,
+ value = commonNew.SetModeAttribute,
+ });
+
+ //3.SetTemp
+ status.Add (new SceneFunctionStatus () {
+ key = FunctionAttributeKey.SetTemp,
+ value = commonNew.WorkingTemperature.ToString (),
+ });
+
+ mSceneFunction.status = status;
+ functions.Add (mSceneFunction);
+
+ //var device = Newtonsoft.Json.JsonConvert.DeserializeObject<FoolHeat> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
+ ////if (device == null) {
+ //// mSendCount--;
+ //// continue;
+ ////}
+ //if (device == null) {
+ // //replyBytes = new byte [] { 0x00 };
+ //} else {
+ // var mSceneFunction = new SceneFunction ();
+ // functions.Add (mSceneFunction);
+ //replyBytes = Control.ControlBytesSendHasReturn (Command.SetFoolHeat, device.SubnetID, device.DeviceID,
+ // new byte [] { device.LoopID, (byte)(device.Status + device.WorkingMode * 16), 0,device.WorkingMode,device.NormalTemperature, device.DayTemperature,
+ // device.NightTemperature, device.AwayTemperature , 0, 0 });
+ //}
+ } else if (common.Type == DeviceType.FanModule) {
+ var commonNew = Newtonsoft.Json.JsonConvert.DeserializeObject<FanModule> (jsonInfo);
+ var mSceneFunction = new SceneFunction ();
+ mSceneFunction.sid = function.sid;
+ //1.on_off
+ var status = new List<SceneFunctionStatus> ();
+ status.Add (new SceneFunctionStatus () {
+ key = FunctionAttributeKey.OnOff,
+ value = commonNew.WindSpeed > 0 ? "on" : "off",
+ });
+
+ //2.FanSpeedPercent
+ status.Add (new SceneFunctionStatus () {
+ key = FunctionAttributeKey.FanSpeedPercent,
+ value = commonNew.WindSpeed.ToString(),
+ });
+
+ mSceneFunction.status = status;
+ functions.Add (mSceneFunction);
+
+ //replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, (byte)device.WindSpeed });
+
+ } else if (common.Type == DeviceType.LogicModule) {
+ //replyBytes = Control.ControlBytesSendHasReturn (Command.SetScene, device.SubnetID, device.DeviceID, new byte [] {
+ //device.AreaID,device.AreaSceneID});
+ } else if (common.Type == DeviceType.UniversalDevice) {//2020-09-02 澧炲姞閫氱敤寮�鍏�
+ var commonNew = Newtonsoft.Json.JsonConvert.DeserializeObject<UniversalDevice> (jsonInfo);
+ var mSceneFunction = new SceneFunction ();
+ mSceneFunction.sid = function.sid;
+ //1.on_off
+ var status = new List<SceneFunctionStatus> ();
+ status.Add (new SceneFunctionStatus () {
+ key = FunctionAttributeKey.OnOff,
+ value = commonNew.SendBytes [1] > 0 ? "on" : "off",
+ });
+
+ mSceneFunction.status = status;
+ functions.Add (mSceneFunction);
+ //replyBytes = Control.ControlBytesSendHasReturn (Command.SetCommonSwitch, device.SubnetID, device.DeviceID, new byte [] { device.SendBytes [0], device.SendBytes [1] });
+ }
+ }
+ } else {
+
+ }
+
+
+ mHDLLinkScene.functions = functions;
+ return mHDLLinkScene;
+ }
+
+
+ #endregion
+
+ #region 鈻� 涓婁紶璁惧鍒楄〃___________________________
+ /// <summary>
+ /// 涓婁紶璁惧鍒楄〃
/// </summary>
/// <returns></returns>
public bool UploadOidAndSidList ()
@@ -70,87 +538,7 @@
List<Common> TargetList = new List<Common> ();
//鎵惧嚭闇�瑕佹樉绀虹殑璁惧
- var filesList = FileUtils.ReadFiles ().FindAll ((obj) => {
- string [] str = obj.Split ('_');
- return obj.StartsWith ("Equipment_") && str.Length == 5;
- });
- var localEquipments = filesList.FindAll ((obj) => {
- string typeString = obj.Split ('_') [1];
- return (
- #region light
- typeString.ToString () == DeviceType.LightCCT.ToString () ||
- typeString.ToString () == DeviceType.LightRGB.ToString () ||
- typeString.ToString () == DeviceType.LightDALI.ToString () ||
- typeString.ToString () == DeviceType.LightRGBW.ToString () ||
- typeString.ToString () == DeviceType.LightLogic.ToString () ||
- typeString.ToString () == DeviceType.LightSwitch.ToString () ||
- typeString.ToString () == DeviceType.LightDimming.ToString () ||
- typeString.ToString () == DeviceType.LightMixSwitch.ToString () ||
- typeString.ToString () == DeviceType.LightRGBandCCT.ToString () ||
- typeString.ToString () == DeviceType.LightMixDimming.ToString () ||
- typeString.ToString () == DeviceType.LightEnergySwitch.ToString () ||
- typeString.ToString () == DeviceType.LightEnergySocket.ToString () ||
- typeString.ToString () == DeviceType.LightSwitchSocket.ToString ()
- || typeString.ToString () == DeviceType.DMX48.ToString ()
- #endregion
- #region light
- || typeString.ToString () == DeviceType.SensorCH4.ToString () ||
- typeString.ToString () == DeviceType.SensorCO2.ToString () ||
- typeString.ToString () == DeviceType.SensorLPG.ToString () ||
- typeString.ToString () == DeviceType.SensorCOH2.ToString () ||
- typeString.ToString () == DeviceType.SensorPM25.ToString () ||
- typeString.ToString () == DeviceType.SensorTVOC.ToString () ||
- typeString.ToString () == DeviceType.SensorPower.ToString () ||
- typeString.ToString () == DeviceType.SensorSmoke.ToString () ||
- typeString.ToString () == DeviceType.SensorWater.ToString () ||
- typeString.ToString () == DeviceType.SensorWeight.ToString () ||
- typeString.ToString () == DeviceType.SensorCurrent.ToString () ||
- typeString.ToString () == DeviceType.SensorVoltage.ToString ()
- || typeString.ToString () == DeviceType.SensorRainfall.ToString ()
- || typeString.ToString () == DeviceType.SensorVelocity.ToString ()
- || typeString.ToString () == DeviceType.SensorMenciAndwindowMagnetic.ToString ()
- || typeString.ToString () == DeviceType.SensorMobileDetection.ToString ()
- || typeString.ToString () == DeviceType.SensorLiquidPressure.ToString ()
- || typeString.ToString () == DeviceType.SensorVibration.ToString ()
- || typeString.ToString () == DeviceType.SensorLiquidFlow.ToString ()
- || typeString.ToString () == DeviceType.SensorLiquidDepth.ToString ()
- || typeString.ToString () == DeviceType.SensorTemperature.ToString ()
- || typeString.ToString () == DeviceType.SensorHeightLength.ToString ()
- || typeString.ToString () == DeviceType.SensorIllumination.ToString ()
- || typeString.ToString () == DeviceType.SensorWindPressure.ToString ()
- || typeString.ToString () == DeviceType.SensorHumidity.ToString ()
- #endregion
- #region curtain
- || typeString.ToString () == DeviceType.CurtainModel.ToString ()
- || typeString.ToString () == DeviceType.CurtainRoller.ToString ()
- || typeString.ToString () == DeviceType.CurtainTrietex.ToString ()
- #endregion
- #region ac
- || typeString.ToString () == DeviceType.ACPanel.ToString ()
- || typeString.ToString () == DeviceType.ACDevice.ToString ()
- || typeString.ToString () == DeviceType.ACInfrared.ToString ()
- || typeString.ToString () == DeviceType.ACCoolmaster.ToString ()
- || typeString.ToString () == DeviceType.CustomAC.ToString ()
- || typeString.ToString () == DeviceType.HVAC.ToString ()
- #endregion
- #region foolheat
- || typeString.ToString () == DeviceType.FoolHeat.ToString ()
- || typeString.ToString () == DeviceType.FoolHeatPanel.ToString ()
- #endregion
- #region
- || typeString.ToString () == DeviceType.InfraredMode.ToString ()
- || typeString.ToString () == DeviceType.DoorLock.ToString ()
- || typeString.ToString () == DeviceType.FanModule.ToString ()
- || typeString.ToString () == DeviceType.FreshAir.ToString ()
- || typeString.ToString () == DeviceType.InfraredTV.ToString ()
- || typeString.ToString () == DeviceType.UniversalDevice.ToString ()
- || typeString.ToString () == DeviceType.MusicModel.ToString ()
- || typeString.ToString () == DeviceType.SecurityModule.ToString ()
- || typeString.ToString () == DeviceType.LogicModule.ToString ()
- || typeString.ToString () == DeviceType.SecurityPanel.ToString ()
- #endregion
- );
- });
+ var localEquipments = CommonUtlis.Current.GetAllLocalEquipments ();
foreach (string deviceFilePath in localEquipments) {
try {
@@ -581,13 +969,66 @@
tmp.name = loopCommon.Name;
tmp.attributes = new List<Attribute> ();
tmp.omodel = loopCommon.Type.ToString ();
- //缁х數鍣ㄥ紑鍏崇被
- if (loopCommon.Type == DeviceType.LightSwitch
+ if (loopCommon.Type == DeviceType.UniversalDevice) {
+ //閫氱敤寮�鍏�
+ tmp.spk = SPK.UniversalDevice;
+ #region on_off
+ Attribute tempAttribute = new Attribute ();
+ tempAttribute.key = "on_off";
+ tempAttribute.data_type = "string";
+ tempAttribute.value = new List<string> ();
+ tempAttribute.value.Add ("on");
+ tempAttribute.value.Add ("off");
+ tempAttribute.max = 1;
+ tempAttribute.min = 0;
+ tmp.attributes.Add (tempAttribute);
+ #endregion
+
+ }else if (loopCommon.Type == DeviceType.FanModule ) {
+ //椋庢墖
+ tmp.spk = SPK.ElectricFan;
+ #region on_off
+ Attribute tempAttribute = new Attribute ();
+ tempAttribute.key = "on_off";
+ tempAttribute.data_type = "string";
+ tempAttribute.value = new List<string> ();
+ tempAttribute.value.Add ("on");
+ tempAttribute.value.Add ("off");
+ tempAttribute.max = 1;
+ tempAttribute.min = 0;
+ tmp.attributes.Add (tempAttribute);
+ #endregion
+
+ #region volume_level
+ Attribute tempSpeedAttribute = new Attribute ();
+ tempSpeedAttribute.key = FunctionAttributeKey.FanSpeedPercent;
+ tempSpeedAttribute.data_type = "integer";
+ tempSpeedAttribute.value = new List<string> ();
+ tempSpeedAttribute.max = 8;
+ tempSpeedAttribute.min = 0;
+ tmp.attributes.Add (tempSpeedAttribute);
+ #endregion
+
+ } else if (loopCommon.Type == DeviceType.LightSwitch
|| loopCommon.Type == DeviceType.LightEnergySwitch
- || loopCommon.Type == DeviceType.LightEnergySocket
- || loopCommon.Type == DeviceType.LightSwitchSocket
|| loopCommon.Type == DeviceType.LightMixSwitch) {
- tmp.spk = "light.switch";
+ //缁х數鍣ㄥ紑鍏崇被
+ tmp.spk = SPK.LightSwitch;
+ #region on_off
+ Attribute tempAttribute = new Attribute ();
+ tempAttribute.key = "on_off";
+ tempAttribute.data_type = "string";
+ tempAttribute.value = new List<string> ();
+ tempAttribute.value.Add ("on");
+ tempAttribute.value.Add ("off");
+ tempAttribute.max = 1;
+ tempAttribute.min = 0;
+ tmp.attributes.Add (tempAttribute);
+ #endregion
+ }else if (loopCommon.Type == DeviceType.LightEnergySocket
+ || loopCommon.Type == DeviceType.LightSwitchSocket) {
+ //鐢靛櫒 鎻掑骇
+ tmp.spk = SPK.ElectricSocket;
#region on_off
Attribute tempAttribute = new Attribute ();
tempAttribute.key = "on_off";
@@ -603,7 +1044,8 @@
|| loopCommon.Type == DeviceType.LightCCT
|| loopCommon.Type == DeviceType.LightDALI) {
//璋冨厜绫�
- tmp.spk = "light.dimming";
+ //tmp.spk = "light.dimming";
+ tmp.spk = SPK.LightDimming;
#region on_off
Attribute tempAttribute = new Attribute ();
tempAttribute.key = "on_off";
@@ -644,7 +1086,8 @@
if (loopCommon.Type == DeviceType.LightCCT || loopCommon.Type == DeviceType.LightDALI)//鑹叉俯绫诲埆
{
- tmp.spk = "light.cct";
+ //tmp.spk = "light.cct";
+ tmp.spk = SPK.LightCCT;
#region cct
Attribute tempAttribute2 = new Attribute ();
tempAttribute2.key = "cct";
@@ -663,7 +1106,8 @@
|| loopCommon.Type == DeviceType.LightRGBandCCT
|| loopCommon.Type == DeviceType.DMX48) {
- tmp.spk = "light.rgb";
+ tmp.spk = SPK.LightRGB;
+ //tmp.spk = "light.rgb";
#region on_off
Attribute tempAttribute = new Attribute ();
tempAttribute.key = "on_off";
@@ -689,7 +1133,8 @@
if (loopCommon.Type == DeviceType.LightRGBW) {
- tmp.spk = "light.rgbw";
+ //tmp.spk = "light.rgbw";
+ tmp.spk = SPK.LightRGBW;
#region color
Attribute tempAttribute3 = new Attribute ();
tempAttribute3.key = "rgb";
@@ -730,7 +1175,8 @@
}
} else if (loopCommon.Type == DeviceType.CurtainModel || loopCommon.Type == DeviceType.CurtainRoller || loopCommon.Type == DeviceType.CurtainTrietex) {
- tmp.spk = "curtain.switch";
+ //tmp.spk = "curtain.switch";
+ tmp.spk = SPK.CurtainSwitch;
#region on_off
Attribute tempAttribute = new Attribute ();
tempAttribute.key = "on_off";
@@ -745,7 +1191,8 @@
#endregion
if (loopCommon.Type == DeviceType.CurtainRoller || loopCommon.Type == DeviceType.CurtainTrietex)//鎵�鏈夊嵎甯樻帶鍒跺櫒
{
- tmp.spk = "curtain.trietex";
+ tmp.spk = SPK.CurtainTrietex;
+ //tmp.spk = "curtain.trietex";
#region openlevel
Attribute tempAttribute1 = new Attribute ();
tempAttribute1.key = "percent";
@@ -765,7 +1212,8 @@
|| loopCommon.Type == DeviceType.HVAC) {
//绌鸿皟绫�
- tmp.spk = "ac.standard";
+ tmp.spk = SPK.AcStandard;
+ //tmp.spk = "ac.standard";
#region on_off
Attribute tempAttribute = new Attribute ();
tempAttribute.key = "on_off";
@@ -870,7 +1318,8 @@
#endregion
} else if (loopCommon.Type == DeviceType.FoolHeat
|| loopCommon.Type == DeviceType.FoolHeatPanel) {
- tmp.spk = "floorHeat.standard";
+ tmp.spk = SPK.FloorHeatStandard;
+ //tmp.spk = "floorHeat.standard";
#region on_off
Attribute tempAttribute = new Attribute ();
tempAttribute.key = "on_off";
@@ -940,7 +1389,8 @@
} else if (loopCommon.Type == DeviceType.MusicA31
|| loopCommon.Type == DeviceType.MusicModel
|| loopCommon.Type == DeviceType.MusicPanel) {
- tmp.spk = "music.standard";
+ tmp.spk = SPK.MusicStandard;
+ //tmp.spk = "music.standard";
// on_off volume song_step audio list_channel mode song_num special_song volume_level
#region on_off
Attribute tempAttribute = new Attribute ();
@@ -1125,7 +1575,8 @@
} else if (loopCommon.BigClass == 5) {
//浼犳劅鍣�
if (loopCommon.Type == DeviceType.SensorMobileDetection) {
- tmp.spk = "sensor.pir";
+ tmp.spk = SPK.SensorPir;
+ //tmp.spk = "sensor.pir";
#region on_off
Attribute tempAttribute = new Attribute ();
tempAttribute.key = "enable";
@@ -1159,7 +1610,8 @@
tmp.attributes.Add (tempAttribute2);
#endregion
}else if (loopCommon.Type == DeviceType.SensorTemperature) {
- tmp.spk = "sensor.temperature";
+ tmp.spk = SPK.SensorTemperature;
+ //tmp.spk = "sensor.temperature";
#region on_off
Attribute tempAttribute = new Attribute ();
tempAttribute.key = "enable";
@@ -1206,7 +1658,8 @@
//tmp.attributes.Add(tempAttribute3);
//#endregion
}else if (loopCommon.Type == DeviceType.SensorIllumination) {
- tmp.spk = "sensor.light";
+ //tmp.spk = "sensor.light";
+ tmp.spk = SPK.SensorLight;
#region on_off
Attribute tempAttribute = new Attribute ();
tempAttribute.key = "enable";
@@ -1246,7 +1699,8 @@
tmp.attributes.Add (tempAttribute3);
#endregion
} else if (loopCommon.Type == DeviceType.SensorPM25) {
- tmp.spk = "sensor.pm25";
+ //tmp.spk = "sensor.pm25";
+ tmp.spk = SPK.SensorPm25;
#region on_off
Attribute tempAttribute = new Attribute ();
tempAttribute.key = "enable";
@@ -1286,7 +1740,8 @@
tmp.attributes.Add (tempAttribute3);
#endregion
}else if (loopCommon.Type == DeviceType.SensorHumidity) {
- tmp.spk = "sensor.humidity";
+ //tmp.spk = "sensor.humidity";
+ tmp.spk = SPK.SensorHumidity;
#region on_off
Attribute tempAttribute = new Attribute ();
tempAttribute.key = "enable";
@@ -1307,7 +1762,8 @@
tmp.attributes.Add (tempAttribute1);
#endregion
}else if (loopCommon.Type == DeviceType.SensorTVOC) {
- tmp.spk = "sensor.tvoc";
+ //tmp.spk = "sensor.tvoc";
+ tmp.spk = SPK.SensorTVOC;
#region on_off
Attribute tempAttribute = new Attribute ();
tempAttribute.key = "enable";
@@ -1328,7 +1784,8 @@
tmp.attributes.Add (tempAttribute1);
#endregion
}else if (loopCommon.Type == DeviceType.SensorCO2) {
- tmp.spk = "sensor.co2";
+ //tmp.spk = "sensor.co2";
+ tmp.spk = SPK.SensorCO2;
#region on_off
Attribute tempAttribute = new Attribute ();
tempAttribute.key = "enable";
@@ -1349,7 +1806,8 @@
tmp.attributes.Add (tempAttribute1);
#endregion
}else if (loopCommon.Type == DeviceType.Sensor) {
- tmp.spk = "dryContact.standard";
+ //tmp.spk = "dryContact.standard";
+ tmp.spk = SPK.DryContact;
#region on_off
Attribute tempAttribute = new Attribute ();
tempAttribute.key = "enable";
@@ -1414,6 +1872,9 @@
} catch { }
return tmp;
}
+
+ #endregion
+
#region 鑾峰彇灞炴��
@@ -1487,42 +1948,11 @@
//#endregion
- #region 鐢熸垚4浣峛yte 鏃堕棿鎴�
- private long LastTime = 0;
- /// <summary>
- /// DateTime鏃堕棿鏍煎紡杞崲涓�13浣嶅甫姣鐨刄nix鏃堕棿鎴�
- /// </summary>
- /// <param name="time"> DateTime鏃堕棿鏍煎紡</param>
- /// <returns>Unix鏃堕棿鎴虫牸寮�</returns>
- public long ConvertDateTimeLong ()
- {
- System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime (new System.DateTime (2020, 1, 1));
- long l = (long)(Math.Round ((DateTime.Now - startTime).TotalSeconds, 1) * 10);
- if (l <= LastTime) l = LastTime + 1;
- LastTime = l;
- return l;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="m"></param>
- /// <param name="strTmp"></param>
- /// <returns></returns>
- public bool ConvertIntToByteArray (long m, ref string strTmp)
- {
- strTmp = "00000000";
- byte [] arry = new byte [4];
- arry [0] = (byte)(m & 0xFF);
- arry [1] = (byte)((m & 0xFF00) >> 8);
- arry [2] = (byte)((m & 0xFF0000) >> 16);
- arry [3] = (byte)((m & 0xFF000000) >> 24);
- strTmp = arry [0].ToString ("X2") + arry [1].ToString ("X2") + arry [2].ToString ("X2") + arry [3].ToString ("X2");
- return true;
- }
- #endregion
+
}
+ #region 鈻� 璁惧鍒楄〃鐩稿叧___________________________
[Serializable]
public class BaseCloudFeedback
{
@@ -1877,6 +2307,11 @@
/// value
/// </summary>
public const string Value = "value";
+
+ /// <summary>
+ /// 椋庢墖妗d綅
+ /// </summary>
+ public const string FanSpeedPercent = "fan_speed_percent";
}
/// <summary>
@@ -2008,6 +2443,11 @@
/// 瀹剁數銆侀鎵�
/// </summary>
public const string ElectricFan = "electrical.fan";
+ /// <summary>
+ /// 鍏跺畠銆侀�氱敤寮�鍏�
+ /// </summary>
+ public const string UniversalDevice = "other.common";
+
}
@@ -2079,98 +2519,104 @@
// public Sids devices { get; set; } //璁惧鍒楄〃
//}
-}
-//sid缁勬垚閮ㄥ垎锛�
-//sid
-//鏉ユ簮 鍘傚晢浠g爜 閫氳鏂瑰紡 浜у搧鏃堕棿鎴� 浜у搧绫诲埆 鐗╂ā鍨嬬被 閫氶亾鍙� 澶у皬绫诲埆
-//1byte 1byte 1byte 4byte 1byte 2byte 2byte 2byte
-//oid缁勬垚閮ㄥ垎锛�
-//鏉ユ簮 鍘傚晢浠g爜 閫氳鏂瑰紡 浜у搧鏃堕棿鎴� 浜у搧绫诲埆
-//1byte 1 byte 1 byte 4 byte 1byte
-//鍏朵腑鍚勯儴鍒嗕唬鐮佸垪琛細
-//鏉ユ簮 1byte 缂栧彿 鎻忚堪
-// 00 榛樿鍘熺敓鎬佺郴缁熸暟鎹�
-// 01 缃戝叧鎴栬�呭叾浠朅璁惧
-// 02 璋冭瘯杞欢
-// 03 APP搴旂敤绋嬪簭
-// 04 绗笁鏂圭綉鍏虫垨鑰呭钩鍙�
-//鍘傚晢浠g爜 1byte 缂栧彿 鎻忚堪
-// 01 HDL
-// 02
+ //sid缁勬垚閮ㄥ垎锛�
+ //sid
+ //鏉ユ簮 鍘傚晢浠g爜 閫氳鏂瑰紡 浜у搧鏃堕棿鎴� 浜у搧绫诲埆 鐗╂ā鍨嬬被 閫氶亾鍙� 澶у皬绫诲埆
+ //1byte 1byte 1byte 4byte 1byte 2byte 2byte 2byte
+ //oid缁勬垚閮ㄥ垎锛�
+ //鏉ユ簮 鍘傚晢浠g爜 閫氳鏂瑰紡 浜у搧鏃堕棿鎴� 浜у搧绫诲埆
+ //1byte 1 byte 1 byte 4 byte 1byte
+ //鍏朵腑鍚勯儴鍒嗕唬鐮佸垪琛細
+ //鏉ユ簮 1byte 缂栧彿 鎻忚堪
+ // 00 榛樿鍘熺敓鎬佺郴缁熸暟鎹�
+ // 01 缃戝叧鎴栬�呭叾浠朅璁惧
+ // 02 璋冭瘯杞欢
+ // 03 APP搴旂敤绋嬪簭
+ // 04 绗笁鏂圭綉鍏虫垨鑰呭钩鍙�
-//閫氳鏂瑰紡 1byte 缂栧彿 鎻忚堪
-// 01 HDL Bus
-// 02 Zigbee
-// 03 KNX
-// 04 Z-Wave
+ //鍘傚晢浠g爜 1byte 缂栧彿 鎻忚堪
+ // 01 HDL
+ // 02
-//浜у搧鏃堕棿鎴� 4bytes 浠�2020骞�1鏈�1鏃ョ畻鍑虹殑鏃堕棿鎴�0.1s涓哄崟浣�
+ //閫氳鏂瑰紡 1byte 缂栧彿 鎻忚堪
+ // 01 HDL Bus
+ // 02 Zigbee
+ // 03 KNX
+ // 04 Z-Wave
-//浜у搧绫诲埆 1byte 缂栧彿 鎻忚堪
-// 01 璋冨厜鍣�
-// 02 缁х數鍣�
-// 03 骞叉帴鐐规ā鍧�
-// 04 浼犳劅鍣�
-// 05 闈㈡澘
-// 06 RCU
-// 07 缃戝叧
-// 08 绾㈠鍙戝皠
-// 09 Android灞�
-// 10 鍦烘櫙
-// 11 闊充箰鎾斁鍣�
-// 12 232/485杞崲鍣�
-// 21 鑷姩鍖�
-// 22 瀹夐槻闃插尯
-// 14 绐楀笜妯″潡
-// 15 HVAC
-// 16 鍦扮儹妯″潡
+ //浜у搧鏃堕棿鎴� 4bytes 浠�2020骞�1鏈�1鏃ョ畻鍑虹殑鏃堕棿鎴�0.1s涓哄崟浣�
-//鐗╂ā鍨嬬被鍨� 2bytes 缂栧彿 鎻忚堪
-// 01 寮�鍏崇被 01 寮�鍏�
-// 02 鎻掑骇
-// 03
-// 02 鐓ф槑 01 寮�鍏�
-// 02 璋冨厜
-// 03 鑹叉俯(CCT)
-// 04 RGB
-// 03 閬槼 01 绐楀笜鎺у埗鍣�
-// 02 鐧惧彾绐�
-// 03 寮�鍚堝笜
-// 04 鍗峰笜
-// 05 聽鎺ㄧ獥鍣�
-// 06 聽鎶曞奖骞�
-// 04 闈㈡澘 01 鎸夐敭闈㈡澘
-// 05 浼犳劅鍣� 01 绉诲姩鎺㈡祴
-// 02 娓╁害浼犳劅鍣�
-// 03 婀垮害浼犳劅鍣�
-// 04 鐓у害浼犳劅鍣�
-// 05 TVOC
-// 06 PM2.5
-// 07 CO2
-// 08 姣背娉紶鎰熷櫒
-// 09
-// 10
-// 11 鐑熼浘浼犳劅鍣�
-// 25 骞叉帴鐐�
-// 07 鎭掓俯鍣� 01 绌鸿皟
-// 02 椋庢墖
-// 03 姣涚粏绌鸿皟
-// 08 鍦扮儹 01 鍦扮儹妯″潡
-// 09 鑳屾櫙闊充箰 01 闊充箰鎾斁鍣�
-// 02 Sonos
-// 10 鍦烘櫙 01 鍦烘櫙
-// 02 鐢靛奖鍦烘櫙
-// 19 鏂伴 01 鏂伴
+ //浜у搧绫诲埆 1byte 缂栧彿 鎻忚堪
+ // 01 璋冨厜鍣�
+ // 02 缁х數鍣�
+ // 03 骞叉帴鐐规ā鍧�
+ // 04 浼犳劅鍣�
+ // 05 闈㈡澘
+ // 06 RCU
+ // 07 缃戝叧
+ // 08 绾㈠鍙戝皠
+ // 09 Android灞�
+ // 10 鍦烘櫙
+ // 11 闊充箰鎾斁鍣�
+ // 12 232/485杞崲鍣�
+ // 21 鑷姩鍖�
+ // 22 瀹夐槻闃插尯
+ // 14 绐楀笜妯″潡
+ // 15 HVAC
+ // 16 鍦扮儹妯″潡
-//13 鑳芥簮 01 鐢佃〃
-// 02 姘磋〃
-// 03 鐕冩皵
-// 16 鐢靛櫒 01 椋庢墖
-// 02 TV
-// 20 瀹夐槻 01 瀹夐槻
-// 21 鑷姩鍖� 01 鑷姩鍖�
-//澶х被鍒� 1bytes 锛堥鐣欙級
-//灏忕被鍒� 1byte 锛堥鐣欙級
\ No newline at end of file
+ //鐗╂ā鍨嬬被鍨� 2bytes 缂栧彿 鎻忚堪
+ // 01 寮�鍏崇被 01 寮�鍏�
+ // 02 鎻掑骇
+ // 03
+ // 02 鐓ф槑 01 寮�鍏�
+ // 02 璋冨厜
+ // 03 鑹叉俯(CCT)
+ // 04 RGB
+ // 03 閬槼 01 绐楀笜鎺у埗鍣�
+ // 02 鐧惧彾绐�
+ // 03 寮�鍚堝笜
+ // 04 鍗峰笜
+ // 05 聽鎺ㄧ獥鍣�
+ // 06 聽鎶曞奖骞�
+ // 04 闈㈡澘 01 鎸夐敭闈㈡澘
+ // 05 浼犳劅鍣� 01 绉诲姩鎺㈡祴
+ // 02 娓╁害浼犳劅鍣�
+ // 03 婀垮害浼犳劅鍣�
+ // 04 鐓у害浼犳劅鍣�
+ // 05 TVOC
+ // 06 PM2.5
+ // 07 CO2
+ // 08 姣背娉紶鎰熷櫒
+ // 09
+ // 10
+ // 11 鐑熼浘浼犳劅鍣�
+ // 25 骞叉帴鐐�
+ // 07 鎭掓俯鍣� 01 绌鸿皟
+ // 02 椋庢墖
+ // 03 姣涚粏绌鸿皟
+ // 08 鍦扮儹 01 鍦扮儹妯″潡
+ // 09 鑳屾櫙闊充箰 01 闊充箰鎾斁鍣�
+ // 02 Sonos
+ // 10 鍦烘櫙 01 鍦烘櫙
+ // 02 鐢靛奖鍦烘櫙
+ // 19 鏂伴 01 鏂伴
+
+ //13 鑳芥簮 01 鐢佃〃
+ // 02 姘磋〃
+ // 03 鐕冩皵
+ // 16 鐢靛櫒 01 椋庢墖
+ // 02 TV
+ // 20 瀹夐槻 01 瀹夐槻
+ // 21 鑷姩鍖� 01 鑷姩鍖�
+ //澶х被鍒� 1bytes 锛堥鐣欙級
+ //灏忕被鍒� 1byte 锛堥鐣欙級
+
+ #endregion
+
+
+
+}
\ No newline at end of file
--
Gitblit v1.8.0