From 002a3f2e9d2f9579c01f88af12bd8a320003569f Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期二, 31 三月 2020 08:57:19 +0800
Subject: [PATCH] 20200331
---
HDL_ON/DriverLayer/Control.cs | 162 +++++++++++++++++++++++++++++++++++++----------------
1 files changed, 112 insertions(+), 50 deletions(-)
diff --git a/HDL_ON/DriverLayer/Control.cs b/HDL_ON/DriverLayer/Control.cs
index f1eb051..cb7006d 100644
--- a/HDL_ON/DriverLayer/Control.cs
+++ b/HDL_ON/DriverLayer/Control.cs
@@ -8,6 +8,10 @@
{
public partial class Control
{
+ public static void Send(Function function)
+ {
+ ControlBusScenes(function as Scene);
+ }
/// <summary>
/// 鍙戦�佸懡浠�
@@ -17,15 +21,13 @@
/// <param name="commandString"></param>
/// <param name="function"></param>
/// <returns></returns>
- public static void Send(string commandType, Function function)
+ public static void Send(CommandType_A commandType, Function function)
{
if (function.bus_Data!=null)
{
try
{
- //var ssd = function.GetSendJObject(commandString);
ControlBusData(function, commandType);
- //return revBytes;
}
catch (Exception ex)
{
@@ -51,13 +53,44 @@
}
}
+ /// <summary>
+ /// 鎺у埗bus鍦烘櫙
+ /// </summary>
+ static void ControlBusScenes(Scene scene)
+ {
+ foreach(var busSceneData in scene.bus_SceneData)
+ {
+ foreach(var function in DB_ResidenceData.residenceData.functionList.GetAllDeviceFunctionList())
+ {
+ if(busSceneData.Key == function.sid)
+ {
+ switch(function.functionType)
+ {
+ case FunctionType.Curtain:
+ ControlBytesSend(Command.SetCurtainModelStutas, function.bus_Data.SubnetID, function.bus_Data.DeviceID, busSceneData.Value);
+ break;
+ case FunctionType.AC:
+ ControlBytesSend(Command.SetACMode, function.bus_Data.SubnetID, function.bus_Data.DeviceID, busSceneData.Value);
+ break;
+ case FunctionType.Relay:
+ case FunctionType.Dimmer:
+ ControlBytesSend(Command.SetSingleLight, function.bus_Data.SubnetID, function.bus_Data.DeviceID, busSceneData.Value);
+ break;
+ case FunctionType.RGB:
+ ControlBytesSend(Command.SetLogicLoopColor, function.bus_Data.SubnetID, function.bus_Data.DeviceID, busSceneData.Value);
+ break;
+ }
+ }
+ }
+ }
+ }
/// <summary>
/// 灏咥鍗忚鎺у埗鏁版嵁杞崲绋媌us鍗忚鐨勬帶鍒舵暟鎹�
/// </summary>
/// <param name="commandString"></param>
/// <returns></returns>
- static void ControlBusData(Function function,string command)//JObject commandString,BusData bus_Data,
+ static void ControlBusData(Function function, CommandType_A command)
{
//鍙嶉:
//{
@@ -75,16 +108,17 @@
//var functionType = jobj.GetValue("sid").ToString().Substring(22, 2);//鎴彇24锛�25瀛楃鑾峰彇鎺у埗鐨勮澶囩殑绫诲瀷
switch (command)
{
- case "write":
+ case CommandType_A.write:
switch (function.functionCategory)
{
- case FunctionType.Light:
+ case FunctionCategory.Light:
var light = function as Light;
switch (light.functionType)
{
- case "RGB":
+ case FunctionType.RGB:
+ MainPage.Log($"rgb level : {light.brightness}");
byte b = 100;//寮�鍏虫搷浣滀緷鎹畂n_off瀛楁锛屽疄闄呭紑鍏冲�间緷鎹産rightness锛屽綋on_off涓烘墦寮�锛宐rightness涓嶈兘涓�0
- if (light.on_off == 0)
+ if (light.on_off == "off")
{
b = 0;
}
@@ -98,11 +132,13 @@
light.redColor,light.greenColor,
light.blueColor,
0,0};
- ControlBytesSend(Command.SetLogicLoopColor, subnetId, deviceId, bytes);
+ MainPage.Log($"rgb level1 : {light.brightness}");
+ ControlBytesSend(Command.SetLogicLoopColor, subnetId, deviceId, bytes,1);
+ MainPage.Log($"rgb level2 : {light.brightness}");
break;
- case "Dimmer":
+ case FunctionType.Dimmer:
byte b1 = 100;
- if (light.on_off == 0)
+ if (light.on_off == "off")
{
b1 = 0;
}
@@ -115,54 +151,80 @@
b1,
0, 0 });
break;
- case "Relay":
- ControlBytesSend(Command.SetSingleLight, subnetId, deviceId, new byte[] { function.bus_Data.LoopID, light.on_off == 1 ? (byte)100 : (byte)0, 0, 0 });
+ case FunctionType.Relay:
+ ControlBytesSend(Command.SetSingleLight, subnetId, deviceId, new byte[] { function.bus_Data.LoopID, light.on_off == "on" ? (byte)100 : (byte)0, 0, 0 });
break;
}
break;
- case FunctionType.Curtain:
- //if (jobj.ContainsKey("Curtain"))//on/off/stop
- //{
- // byte state = 0;
- // switch (jobj.GetValue("switch").ToString())
- // {
- // case "stop":
- // state = 0;
- // break;
- // case "on":
- // state = 1;
- // break;
- // case "off":
- // state = 2;
- // break;
- // }
- // return ControlBytesSendHasReturn(Command.SetCurtainModelStutas, subnetId, deviceId, new byte[] { function.bus_Data.LoopID, state });
- //}
- //else if (jobj.ContainsKey("MotorCurtain") || jobj.ContainsKey("RollingShutter"))
- //{
- // var state = Convert.ToByte(jobj.GetValue("openLevel").ToString());
- // return ControlBytesSendHasReturn(Command.SetCurtainModelStutas, subnetId, deviceId, new byte[] { 17, state });
- //}
+ case FunctionCategory.Curtain:
+ var curtain = function as Curtain;
+ switch (curtain.functionType)
+ {
+ case FunctionType.Curtain:
+ byte b1 = 0;
+ if (curtain.on_off == "stop")
+ {
+ b1 = 0;
+ }else if(curtain.on_off == "on")
+ {
+ b1 = 1;
+ }
+ else
+ {
+ b1 = 2;
+ }
+ ControlBytesSend(Command.SetCurtainModelStutas, subnetId, deviceId, new byte[] { curtain.bus_Data.LoopID, b1 });
+ break;
+ case FunctionType.MotorCurtain:
+ case FunctionType.RollingShutter:
+ if (curtain.on_off == "stop")
+ {
+ ControlBytesSend(Command.SetCurtainModelStutas, subnetId, deviceId, new byte[] { curtain.bus_Data.LoopID, 0 });
+ }
+ ControlBytesSend(Command.SetCurtainModelStutas, subnetId, deviceId, new byte[] { 17, (byte)curtain.openLevel });
+ break;
+ }
+ break;
+ case FunctionCategory.AC:
+ var aC = function as AC;
+ ControlBytesSend(Command.SetACMode, subnetId, deviceId, new byte[] { aC.bus_Data.LoopID, (byte)aC.curTempType, 32, 32, 32, 32, 32, 0, aC.on_off == "on" ? (byte)1 : (byte)0, aC.curModeIndex, aC.curFanIndex, (byte)aC.curTemp, 0 });
break;
}
break;
- case "read":
- //switch ((FunctionType)Enum.ToObject(typeof(FunctionType), Convert.ToInt32(functionType)))
- //{
- // case FunctionType.Light:
- // if (jobj.ContainsKey("switch"))//缁х數鍣�
- // {
- // var state = jobj.GetValue("switch").ToString() == "0" ? (byte)0 : (byte)100;
- // var bytes = new byte[] { Convert.ToByte(loopId), state, 0, 0 };
- // return ControlBytesSendHasReturn(Command.ReadLightSingleLoopBrightness, subnetId, deviceId, bytes);
- // }
- // break;
- //}
+ case CommandType_A.read:
+ switch (function.functionCategory)
+ {
+ case FunctionCategory.Light:
+ switch (function.functionType)
+ {
+ case FunctionType.Relay:
+ case FunctionType.Dimmer:
+ ControlBytesSend(Command.ReadLightSingleLoopBrightness, subnetId, deviceId, new byte[] { function.bus_Data.LoopID });
+ break;
+ case FunctionType.RGB:
+ ControlBytesSend(Command.ReadLogicLoopColor, subnetId, deviceId, new byte[] { function.bus_Data.LoopID });
+ break;
+ }
+ break;
+ case FunctionCategory.Curtain:
+ switch (function.functionType)
+ {
+ case FunctionType.Curtain:
+ case FunctionType.MotorCurtain:
+ case FunctionType.RollingShutter:
+ ControlBytesSend(Command.ReadCurtainStatus, subnetId, deviceId, new byte[] { function.bus_Data.LoopID });
+ break;
+ }
+ break;
+ case FunctionCategory.AC:
+ ControlBytesSend(Command.ReadACMode, subnetId, deviceId, new byte[] {function.bus_Data.LoopID });
+ break;
+ }
break;
}
-
}
- catch (Exception ex) {
+ catch (Exception ex)
+ {
MainPage.Log($"DataConversion_Bus Erorr : {ex.Message}");
}
}
--
Gitblit v1.8.0