From 9137222ece9b978eb97b5598f2eee6e070bcf9d6 Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期五, 28 二月 2020 15:22:16 +0800
Subject: [PATCH] 2020-02-28 更新

---
 Crabtree/SmartHome/UI/SimpleControl/Phone/Scene/SceneMethod.cs |  279 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 278 insertions(+), 1 deletions(-)

diff --git a/Crabtree/SmartHome/UI/SimpleControl/Phone/Scene/SceneMethod.cs b/Crabtree/SmartHome/UI/SimpleControl/Phone/Scene/SceneMethod.cs
index 1ce1687..690786c 100644
--- a/Crabtree/SmartHome/UI/SimpleControl/Phone/Scene/SceneMethod.cs
+++ b/Crabtree/SmartHome/UI/SimpleControl/Phone/Scene/SceneMethod.cs
@@ -333,7 +333,8 @@
             dialog.Show ();
         }
 
-        public void ControlScene (string sceneFilePath)
+
+        public void ControlSceneOld(string sceneFilePath)
         {
             if (CommonPage.IsRemote) {
                 if (!SmartHome.MqttCommon.IsGatewayOnline) {
@@ -535,6 +536,282 @@
             });
         }
 
+        public void ControlScene (string sceneFilePath)
+        {
+            if (CommonPage.IsRemote) {
+                if (!SmartHome.MqttCommon.IsGatewayOnline) {
+                    new Alert ("", "Gateway offline" + ErrorCode.ControlFailure, "Close").Show ();
+                    return;
+                }
+            }
+            var tempScene = Scene.GetSceneByFilePath (sceneFilePath);
+            if (tempScene == null)
+                return;
+            showTip = true;
+            MainPage.Loading.Start ("Sending...");
+
+            System.Threading.Tasks.Task.Run (() => {
+                int sceneDeviceCount = tempScene.DeviceFilePathList.Count;
+                int controlDeviceIndex = 0;
+                int mSendCount = 0;
+                byte [] replyBytes = null;
+                if (!tempScene.busScene) {
+                    foreach (var deviceFilePath in tempScene.DeviceFilePathList) {
+                        controlDeviceIndex++;
+                        new System.Threading.Thread (() => {
+                            mSendCount++;
+                            var common = Newtonsoft.Json.JsonConvert.DeserializeObject<Common> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
+                            if (common.Type == DeviceType.LightDimming) {
+                                var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightDimming> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
+                                if (device == null) {
+                                    replyBytes = new byte [] { 0x00 };
+                                } else {
+                                    replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, device.DelayTimeHeight, device.DelayTimeLow });
+                                }
+                            } else if (common.Type == DeviceType.LightEnergySocket) {
+                                var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightEnergySocket> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
+                                //if (device == null) {
+                                //    mSendCount--;
+                                //    continue;
+                                //}
+                                if (device == null) {
+                                    replyBytes = new byte [] { 0x00 };
+                                } else {
+                                    replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, device.DelayTimeHeight, device.DelayTimeLow });
+                                }
+                            } else if (common.Type == DeviceType.LightEnergySwitch) {
+                                var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightEnergySwitch> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
+                                //if (device == null) {
+                                //    mSendCount--;
+                                //    continue;
+                                //}
+                                if (device == null) {
+                                    replyBytes = new byte [] { 0x00 };
+                                } else {
+                                    replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, device.DelayTimeHeight, device.DelayTimeLow });
+                                }
+                            } else if (common.Type == DeviceType.LightRGB) {
+                                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 {
+
+                                    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 device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightSwitch> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
+                                //if (device == null) {
+                                //    mSendCount--;
+                                //    continue;
+                                //}
+                                if (device == null) {
+                                    replyBytes = new byte [] { 0x00 };
+                                } else {
+                                    replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, device.DelayTimeHeight, device.DelayTimeLow });
+                                }
+                            } else if (common.Type == DeviceType.CurtainModel) {
+                                var device = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainModel> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
+                                //if (device == null) {
+                                //    mSendCount--;
+                                //    continue;
+                                //}
+                                if (device == null) {
+                                    replyBytes = new byte [] { 0x00 };
+                                } else {
+                                    replyBytes = Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, (byte)device.Status });
+                                }
+                            } else if (common.Type == DeviceType.CurtainRoller) {
+                                var device = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainRoller> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
+                                //if (device == null) {
+                                //    mSendCount--;
+                                //    continue;
+                                //}
+                                if (device == null) {
+                                    replyBytes = new byte [] { 0x00 };
+                                } else {
+                                    replyBytes = Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { 1, (byte)device.Status });
+                                }
+                            } else if (common.Type == DeviceType.CurtainTrietex) {
+                                var device = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainTrietex> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
+                                //if (device == null) {
+                                //    mSendCount--;
+                                //    continue;
+                                //}
+                                if (device == null) {
+                                    replyBytes = new byte [] { 0x00 };
+                                } else {
+                                    replyBytes = Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { 1, (byte)device.Status });
+                                }
+                            } else if (common.Type == DeviceType.HVAC || common.Type == DeviceType.ACInfrared) {
+                                var device = Newtonsoft.Json.JsonConvert.DeserializeObject<HVAC> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
+                                //if (device == null) {
+                                //    mSendCount--;
+                                //    continue;
+                                //}
+                                if (device == null) {
+                                    replyBytes = new byte [] { 0x00 };
+                                } else {
+                                    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 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 {
+                                    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 device = Newtonsoft.Json.JsonConvert.DeserializeObject<FanModule> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
+                                //if (device == null) {
+                                //    mSendCount--;
+                                //    continue;
+                                //}
+                                if (device == null) {
+                                    replyBytes = new byte [] { 0x00 };
+                                } else {
+                                    replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, (byte)device.WindSpeed });
+                                }
+                            } else if (common.Type == DeviceType.LogicModule) {
+                                var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LogicModule> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
+                                //if (device == null) {
+                                //    mSendCount--;
+                                //    continue;
+                                //}
+                                if (device == null) {
+                                    replyBytes = new byte [] { 0x00 };
+                                } else {
+                                    replyBytes = Control.ControlBytesSendHasReturn (Command.SetScene, device.SubnetID, device.DeviceID, new byte [] {
+                            device.AreaID,device.AreaSceneID});
+                                }
+                            }
+
+                            try {
+                                if (showTip) {
+                                    if (replyBytes == null) {
+                                        Application.RunOnMainThread (() => {
+                                            string tipString = Language.StringByID (R.MyInternationalizationString.ControlFailure);
+                                            var btnTip = new Button () {
+                                                Height = Application.GetRealHeight (140),
+                                                Text = common.Name + tipString + "..." + controlDeviceIndex.ToString () + @"/" + sceneDeviceCount.ToString (),
+                                                BackgroundColor = SkinStyle.Current.TitileView,
+                                            };
+                                            MainPage.MainFrameLayout.AddChidren (btnTip);
+                                            btnTip.MouseUpEventHandler += (sender, e) => {
+                                                btnTip.RemoveFromParent ();
+                                                showTip = false;
+                                                //MainPage.MainFrameLayout.Remove (btnTip);
+                                            };
+                                            System.Threading.Tasks.Task.Run (() => {
+                                                System.Threading.Thread.Sleep (3000);
+                                                Application.RunOnMainThread (() => {
+                                                    btnTip.RemoveFromParent ();
+                                                    //MainPage.MainFrameLayout.Remove (btnTip);
+                                                    //showTip = false;
+                                                });
+                                            });
+                                        });
+                                    }
+                                }
+                            } catch {
+                            }
+
+                            mSendCount--;
+                        }){ IsBackground = true}.Start();
+
+                        //绛夊緟100ms鍐嶅彂閫佺浜屼釜璁惧鏁版嵁
+                        System.Threading.Thread.Sleep (100);
+
+                    }
+
+                    //
+                    while (mSendCount > 0) {
+                        System.Threading.Thread.Sleep (100);
+                    }
+                } else {
+                    foreach (var common in tempScene.GlobalSceneDeviceList) {
+                        switch (common.obj1) {
+                        case 0://0   鏃犳晥 Invalid
+                            break;
+                        case 85://0x55  鍦烘櫙 Scene ||0x0002
+                            replyBytes = Control.ControlBytesSendHasReturn (Command.SetScene, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
+                            break;
+                        case 86://0x56  搴忓垪 Sequence ||0x001A
+                            replyBytes = Control.ControlBytesSendHasReturn (Command.SetSeries, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
+                            break;
+                        case 88://0x58  閫氱敤寮�鍏� Universal Switch ||0xe01c
+                            replyBytes = Control.ControlBytesSendHasReturn (Command.SetCommonSwitch, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
+                            break;
+                        case 89: //0x59  鍗曡矾璋冭妭 Single Channel Lighting Control  0031
+                            replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
+                            break;
+                        case 92://0x5c  绐楀笜寮�鍏� Curtain Switch e3e0
+                            replyBytes = Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelStutas, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
+                            break;
+                        case 94://0x5e  GPRS鎺у埗 GPRS Control E3D4
+                            replyBytes = Control.ControlBytesSendHasReturn (Command.GPRSControl, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
+                            break;
+                        case 95://0x5f  闈㈡澘鎺у埗 Panel Control e3d8
+                            replyBytes = Control.ControlBytesSendHasReturn (Command.InstructionPanelKey, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
+                            break;
+                        case 100://0x64 骞挎挱鍦烘櫙 Broadcast Scene ||0x0002  
+                            replyBytes = Control.ControlBytesSendHasReturn (Command.SetScene, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
+                            break;
+                        case 101://0x65 骞挎挱鍥炶矾 Broadcast Channel 0031
+                            replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
+                            break;
+                        case 102://0x66 娑堥槻妯″潡 Security Module 011E
+                            replyBytes = Control.ControlBytesSendHasReturn (Command.SecurityModule, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
+                            break;
+                        case 103://0x67 闊充箰鎾斁 Music Control 0218
+                            replyBytes = Control.ControlBytesSendHasReturn (Command.MusicControl, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
+                            break;
+                            //104 閫氱敤鎺у埗 Universal Control
+                            //105 杩炴帴椤� Link Page
+                            //107 RGB璋冭妭 RGB Control
+                            //108 绾㈠鎺у埗 Infrared Control
+                            //case 109://109 閫昏緫鐏皟鑺� Logic Light Adjust ||  0xE45E
+                            //    replyBytes = Control.ControlBytesSendHasReturn (Command.LogicLightAdjust, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
+                            //    break;
+                            //}
+                            //110 閫昏緫鍦烘櫙 Logic Scene
+                            //112 LCD & LED浼戠湢 LCD & LED Sleep
+                            //113 鏈嶅姟鍣ㄦ帶鍒�   Server control
+                        }
+                    }
+                }
+
+                Application.RunOnMainThread (() => {
+                    MainPage.Loading.Hide ();
+                });
+            });
+
+
+        }
+
         public void ControlBusSceneDevice (Common common)
         {
             byte [] replyBytes = null;

--
Gitblit v1.8.0