From 611786df5108dca0bdcff03834cc285cba4b8e61 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期二, 13 十月 2020 16:48:43 +0800
Subject: [PATCH] 2020-10-13-1

---
 HDL_ON/DriverLayer/Control.cs |  125 +++++++++++++++++++++++++++++++++--------
 1 files changed, 99 insertions(+), 26 deletions(-)

diff --git a/HDL_ON/DriverLayer/Control.cs b/HDL_ON/DriverLayer/Control.cs
index 960aaa7..5f6ad52 100644
--- a/HDL_ON/DriverLayer/Control.cs
+++ b/HDL_ON/DriverLayer/Control.cs
@@ -1,5 +1,7 @@
 using System;
 using System.Collections.Generic;
+using HDL_ON.DAL;
+using HDL_ON.DAL.Net;
 using HDL_ON.Entity;
 using Newtonsoft.Json.Linq;
 using Shared;
@@ -38,20 +40,10 @@
             }
             else
             {
-
-                //var jObject = new JObject {
-                //{ "DeviceAddr", 11},
-                //{ "Epoint", 22},
-                //    { "Cluster_ID", 8 },
-                //    { "Command", 33},
-                //    { "SendMode", 2 }
-                //};
-                //var data = new JObject {
-                //    { "Level", 1 },
-                //    { "TransitionTime", 0 }
-                //};
-                //jObject.Add("Data", data);
-                //return revBytes;
+                var commandObj = function.GetSendJObject(commandType);
+                var commandString = Newtonsoft.Json.JsonConvert.SerializeObject(commandObj);
+                var commandBytes = CommonPage.MyEncodingUTF8.GetBytes(commandString);
+                MqttCommon.MqttRemoteSend(commandBytes);
             }
         }
 
@@ -66,7 +58,7 @@
                 {
                     if(busSceneData.Key == function.sid)
                     {
-                        switch(function.functionType)
+                        switch (function.functionType)
                         {
                             case FunctionType.Curtain:
                                 ControlBytesSend(Command.SetCurtainModelStutas, function.bus_Data.SubnetID, function.bus_Data.DeviceID, busSceneData.Value);
@@ -81,6 +73,22 @@
                             case FunctionType.RGB:
                                 ControlBytesSend(Command.SetLogicLoopColor, function.bus_Data.SubnetID, function.bus_Data.DeviceID, busSceneData.Value);
                                 break;
+                            case FunctionType.FloorHeating:
+                                var fh = function as FloorHeating;
+                                if (fh.modeTemp.Count == 4)
+                                {
+                                    byte b1 = fh.on_off == "on" ? (byte)1 : (byte)0;
+                                    if (fh.workMode > 0)
+                                    {
+                                        b1 += (byte)(16 + fh.workMode);
+                                    }
+                                    ControlBytesSend(Command.SetFloorHeat, function.bus_Data.SubnetID, function.bus_Data.DeviceID, new byte[] { fh.bus_Data.LoopID, b1, (byte)fh.curTempType, fh.curModeIndex, fh.modeTemp["ordinary"], fh.modeTemp["day"], fh.modeTemp["night"], fh.modeTemp["away"], 0, 0 });
+                                }
+                                break;
+                            case FunctionType.Socket:
+                                var s = function as SwitchSocket;
+                                ControlBytesSend(Command.SetSingleLight, function.bus_Data.SubnetID, function.bus_Data.DeviceID, new byte[] { s.bus_Data.LoopID, s.on_off == "on" ? (byte)100 : (byte)0 });
+                                break;
                         }
                     }
                 }
@@ -94,20 +102,12 @@
         /// <returns></returns>
         static void ControlBusData(Function function, CommandType_A command)
         {
-            //鍙嶉:
-            //{
-            //"Namespace": "HDL", "Command": "writeRespone",
-            //鈥淭ype鈥�:鈥漝evice鈥�, "objects": [{
-            //"sid": "0001002019101209000025670100010001鈥�, "statue": "success鈥�
-            //}] }
             try
             {
                 var subnetId = function.bus_Data.SubnetID;
                 var deviceId = function.bus_Data.DeviceID;
                 var loopId = function.bus_Data.LoopID;
 
-                //var jobj = JObject.FromObject(commandString.GetValue("objects"));
-                //var functionType = jobj.GetValue("sid").ToString().Substring(22, 2);//鎴彇24锛�25瀛楃鑾峰彇鎺у埗鐨勮澶囩殑绫诲瀷
                 switch (command)
                 {
                     case CommandType_A.write:
@@ -131,8 +131,8 @@
                                         var bytes = new byte[] { function.bus_Data.LoopID,
                                             b,
                                             254, 0,0,3,
-                                            light.redColor,light.greenColor,
-                                            light.blueColor,
+                                            (byte)light.redColor,(byte)light.greenColor,
+                                            (byte)light.blueColor,
                                             0,0};
                                         MainPage.Log($"rgb level1 : {light.brightness}");
                                         ControlBytesSend(Command.SetLogicLoopColor, subnetId, deviceId, bytes,1);
@@ -183,7 +183,14 @@
                                         {
                                             ControlBytesSend(Command.SetCurtainModelStutas, subnetId, deviceId, new byte[] { curtain.bus_Data.LoopID, 0 });
                                         }
-                                        ControlBytesSend(Command.SetCurtainModelStutas, subnetId, deviceId, new byte[] { 17, (byte)curtain.openLevel });
+                                        else if (curtain.on_off == "on")
+                                        {
+                                            ControlBytesSend(Command.SetCurtainModelStutas, subnetId, deviceId, new byte[] { 17, 100 });
+                                        }
+                                        else if (curtain.on_off == "off")
+                                        {
+                                            ControlBytesSend(Command.SetCurtainModelStutas, subnetId, deviceId, new byte[] { 17, 0 });
+                                        }
                                         break;
                                 }
                                 break;
@@ -193,6 +200,46 @@
                                     case FunctionType.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;
+                                    case FunctionType.FloorHeating:
+                                        var fh = function as FloorHeating;
+                                        if (fh.modeTemp.Count == 4)
+                                        {
+                                            byte b1 = fh.on_off == "on" ? (byte)1 : (byte)0;
+                                            if (fh.workMode > 0)
+                                            {
+                                                b1 += (byte)(16 + fh.workMode);
+                                            }
+                                            ControlBytesSend(Command.SetFloorHeat, subnetId, deviceId, new byte[] { fh.bus_Data.LoopID, b1,(byte)fh.curTempType,fh.curModeIndex, fh.modeTemp["ordinary"], fh.modeTemp["day"], fh.modeTemp["night"], fh.modeTemp["away"], 0, 0 });
+                                        }
+                                        //else
+                                        //{
+                                        //    ControlBytesSend(Command.ReadFloorHeat, subnetId,deviceId,new byte[] { fh.bus_Data.LoopID});
+                                        //}
+                                        break;
+                                }
+                                break;
+                            case FunctionCategory.Electrical:
+                                switch (function.functionType)
+                                {
+                                    case FunctionType.Fan:
+                                        var fan = function as Fan;
+                                        if(fan.on_off == "on")
+                                        {
+                                            ControlBytesSend(Command.SetSingleLight, subnetId, deviceId, new byte[] { fan.bus_Data.LoopID, (byte)fan.openLevel });
+                                        }
+                                        {
+                                            ControlBytesSend(Command.SetSingleLight, subnetId, deviceId, new byte[] { fan.bus_Data.LoopID, 0 });
+                                        }
+                                        break;
+                                }
+                                break;
+                            case FunctionCategory.SwitchDevice:
+                                switch(function.functionType)
+                                {
+                                    case FunctionType.Socket:
+                                        var s = function as SwitchSocket;
+                                        ControlBytesSend(Command.SetSingleLight, subnetId, deviceId, new byte[] { s.bus_Data.LoopID, s.on_off == "on" ? (byte)100 : (byte)0 });
                                         break;
                                 }
                                 break;
@@ -229,8 +276,34 @@
                                     case FunctionType.AC:
                                         ControlBytesSend(Command.ReadACMode, subnetId, deviceId, new byte[] { function.bus_Data.LoopID });
                                         break;
+                                    case FunctionType.FloorHeating:
+                                        ControlBytesSend(Command.ReadFloorHeat, subnetId, deviceId, new byte[] { function.bus_Data.LoopID });
+                                        break;
                                 }
                                 break;
+                            case FunctionCategory.Electrical:
+                                switch (function.functionType)
+                                {
+                                    case FunctionType.Fan:
+                                        var fan = function as Fan;
+                                        ControlBytesSend(Command.SetSingleLightACK, subnetId, deviceId, new byte[] { fan.bus_Data.LoopID });
+                                        break;
+                                }
+                                break;
+                            case FunctionCategory.SwitchDevice:
+                                switch (function.functionType)
+                                {
+                                    case FunctionType.Socket:
+                                        var s = function as SwitchSocket;
+                                        ControlBytesSend(Command.SetSingleLightACK, subnetId, deviceId, new byte[] { s.bus_Data.LoopID });
+                                        break;
+                                }
+                                break;
+                            case FunctionCategory.Sensor:
+                                var sensor = function as Sensor;
+                                ControlBytesSend(Command.ReadDeviceLoopInfo, subnetId, deviceId, new byte[] { (byte)5,
+                                            (byte)((int)sensor.functionType % 256), sensor.bus_Data.LoopID });
+                                break;
                         }
                         break;
                 }

--
Gitblit v1.8.0