From 2ae36ddb40d28c62b64a2fdd4c3033e7d65d5cfb Mon Sep 17 00:00:00 2001
From: wei <kaede@kaededeMacBook-Air.local>
Date: 星期四, 04 三月 2021 15:20:29 +0800
Subject: [PATCH] 2021-0304-1

---
 HDL_ON/DAL/DriverLayer/Packet.cs |  152 +++++++++++++++++++++++++++++++++-----------------
 1 files changed, 101 insertions(+), 51 deletions(-)

diff --git a/HDL_ON/DAL/DriverLayer/Packet.cs b/HDL_ON/DAL/DriverLayer/Packet.cs
index 3e18471..323b918 100644
--- a/HDL_ON/DAL/DriverLayer/Packet.cs
+++ b/HDL_ON/DAL/DriverLayer/Packet.cs
@@ -91,6 +91,14 @@
                 }
                 //澶勭悊鎺ユ敹鍒扮殑鏁版嵁
                 UdpPacket_DataProcessing(subnetID, deviceID, command, usefulBytes);
+#if DEBUG
+                string ddd = "";
+                foreach(var bb in usefulBytes)
+                {
+                    ddd += bb + ",";
+                }
+                MainPage.Log(ddd);
+#endif
                 //澶勭悊鏄惁瑕侀噸鍙戞暟鎹�
                 ManagerReceive(subnetID, deviceID, command, usefulBytes);
             }
@@ -122,18 +130,18 @@
                         {
                             if (updataObj.GetBusId() == subnetID + "_" + deviceID + "_" + receiveBytes[0])
                             {
-                                if (updataObj.functionType != FunctionType.RGB)
+                                if (updataObj.spk != SPK.LightRGB)
                                 {
                                     updataObj.trait_on_off.curValue = receiveBytes[2] > 0 ? "on" : "off";
                                     if (updataObj.trait_on_off.curValue.ToString() == "on")
                                     {
-                                        switch (updataObj.functionType)
+                                        switch (updataObj.spk)
                                         {
-                                            case FunctionType.Fan:
+                                            case SPK.ElectricFan:
                                                 (updataObj as Fan).openLevel = receiveBytes[2];
                                                 updataObj.lastState = Language.StringByID(StringId.Level) + " : " + receiveBytes[2];
                                                 break;
-                                            case FunctionType.Dimmer:
+                                            case SPK.LightDimming:
                                                 (updataObj as Light).brightness = receiveBytes[2];
                                                 updataObj.lastState = Language.StringByID(StringId.Brightness) + " : " + receiveBytes[2] + "%";
                                                 break;
@@ -143,15 +151,15 @@
                                     RoomPage.UpdataStates(updataObj);
                                     FunctionPage.UpdataStates(updataObj);
                                     ClassificationPage.UpdataInfo(updataObj);
-                                    switch (updataObj.functionType)
+                                    switch (updataObj.spk)
                                     {
-                                        case FunctionType.Relay:
+                                        case SPK.LightSwitch:
                                             RelayPage.UpdataState(updataObj as Light);
                                             break;
-                                        case FunctionType.Dimmer:
+                                        case SPK.LightDimming:
                                             DimmerPage.UpdataStates(updataObj as Light);
                                             break;
-                                        case FunctionType.Fan:
+                                        case SPK.ElectricFan:
                                             FanPage.UpdataState(updataObj as Fan);
                                             break;
                                     }
@@ -166,7 +174,7 @@
                             var light = FunctionList.List.lights.Find((obj) => obj.bus.SubnetID == subnetID && obj.bus.DeviceID == deviceID && obj.bus.LoopId == (i + 1));
                             if (light != null)
                             {
-                                if (light.functionType != FunctionType.RGB)
+                                if (light.spk != SPK.LightRGB)
                                 {
                                     light.trait_on_off.curValue = receiveBytes[light.bus.LoopId] == 0 ? "off" : "on";
                                     if (light.trait_on_off.curValue.ToString() == "on")
@@ -178,12 +186,12 @@
                                     RoomPage.UpdataStates(light);
                                     FunctionPage.UpdataStates(light);
                                     ClassificationPage.UpdataInfo(light);
-                                    switch (light.functionType)
+                                    switch (light.spk)
                                     {
-                                        case FunctionType.Relay:
+                                        case SPK.LightSwitch:
                                             RelayPage.UpdataState(light);
                                             break;
-                                        case FunctionType.Dimmer:
+                                        case SPK.LightDimming:
                                             DimmerPage.UpdataStates(light);
                                             break;
                                     }
@@ -205,12 +213,12 @@
                                     RoomPage.UpdataStates(fan);
                                     FunctionPage.UpdataStates(fan);
                                     ClassificationPage.UpdataInfo(fan);
-                                    switch (fan.functionType)
+                                    switch (fan.spk)
                                     {
-                                        case FunctionType.Fan:
+                                        case SPK.ElectricFan:
                                             FanPage.UpdataState(fan);
                                             break;
-                                        case FunctionType.Socket:
+                                        case SPK.ElectricSocket:
 
                                             break;
                                     }
@@ -224,7 +232,7 @@
                         {
                             if (rgb.GetBusId() == subnetID + "_" + deviceID + "_" + receiveBytes[0])
                             {
-                                if (rgb.functionType == FunctionType.RGB)
+                                if (rgb.spk == SPK.LightRGB)
                                 {
                                     rgb.trait_on_off.curValue = receiveBytes[1] > 0 ? "on" : "off";
                                     if (receiveBytes[1] > 0)
@@ -285,15 +293,15 @@
                                 FunctionPage.UpdataStates(curtain);
                                 HomePage.UpdataFunctionStates(curtain);
                                 ClassificationPage.UpdataInfo(curtain);
-                                switch (curtain.functionType)
+                                switch (curtain.spk)
                                 {
-                                    case FunctionType.Curtain:
+                                    case SPK.CurtainSwitch:
                                         CurtainModulePage.UpdataState(curtain);
                                         break;
-                                    case FunctionType.MotorCurtain:
+                                    case SPK.CurtainTrietex:
                                         MotorCurtainPage.UpdataState(curtain);
                                         break;
-                                    case FunctionType.RollingShutter:
+                                    case SPK.CurtainRoller:
                                         RollingShutterPage.UpdataState(curtain);
                                         break;
                                 }
@@ -307,13 +315,13 @@
                             if (ac.GetBusId() == subnetID + "_" + deviceID + "_" + receiveBytes[0])
                             {
                                 ac.curTempType = receiveBytes[1];
-                                ac.trait_IndoorTemp.curValue = receiveBytes[2];
+                                ac.SetAttrState(FunctionAttributeKey.IndoorTemp, receiveBytes[2].ToString());
                                 ac.trait_on_off.curValue = receiveBytes[8] == 1 ? "on" : "off";
-                                ac.curModeIndex = receiveBytes[9];
-                                ac.curFanIndex = receiveBytes[10];
-                                ac.trait_temp.curValue = receiveBytes[11];
+                                ac.SetModeIndex(receiveBytes[9]);
+                                ac.SetFanIndex(receiveBytes[10]);
+                                ac.SetAttrState(FunctionAttributeKey.SetTemp, receiveBytes[11].ToString());
                                 ac.lastState = "";
-                                switch (ac.trait_mode.curValue.ToString())
+                                switch (ac.GetAttrState(FunctionAttributeKey.Mode))
                                 {
                                     case "cool":
                                         ac.lastState = Language.StringByID(StringId.Cool);
@@ -331,7 +339,7 @@
                                         ac.lastState = Language.StringByID(StringId.AirSupply);
                                         break;
                                 }
-                                switch (ac.trait_fan.curValue.ToString())
+                                switch (ac.GetAttrState(FunctionAttributeKey.FanSpeed))
                                 {
                                     case "high":
                                         ac.lastState += " " + Language.StringByID(StringId.HighWindSpeed);
@@ -346,7 +354,7 @@
                                         ac.lastState += " " + Language.StringByID(StringId.Auto);
                                         break;
                                 }
-                                ac.lastState += " " + ac.trait_temp.curValue + ac.tempUnitString;
+                                ac.lastState += " " + ac.GetAttrState(FunctionAttributeKey.SetTemp) + ac.tempUnitString;
                                 RoomPage.UpdataStates(ac);
                                 FunctionPage.UpdataStates(ac);
                                 HomePage.UpdataFunctionStates(ac);
@@ -401,34 +409,37 @@
                                 {
                                     case "normal":
                                         fh.lastState = Language.StringByID(StringId.Normal);
-                                        fh.trait_temp.curValue = receiveBytes[4];
+                                        fh.trait_temp.curValue = receiveBytes[4].ToString();
                                         break;
                                     case "day":
                                         fh.lastState = Language.StringByID(StringId.Day);
-                                        fh.trait_temp.curValue = receiveBytes[5];
+                                        fh.trait_temp.curValue = receiveBytes[5].ToString();
                                         break;
                                     case "night":
                                         fh.lastState = Language.StringByID(StringId.Night);
-                                        fh.trait_temp.curValue = receiveBytes[6];
+                                        fh.trait_temp.curValue = receiveBytes[6].ToString();
                                         break;
                                     case "timer":
                                         fh.lastState = Language.StringByID(StringId.Auto);
                                         if (receiveBytes[8] == 0)
                                         {
                                             fh.timeFlag = 0;
-                                            fh.trait_temp.curValue = receiveBytes[5];
+                                            fh.trait_temp.curValue = receiveBytes[5].ToString();
                                         }
                                         else
                                         {
                                             fh.timeFlag = 1;
-                                            fh.trait_temp.curValue = receiveBytes[6];
+                                            fh.trait_temp.curValue = receiveBytes[6].ToString();
                                         }
                                         break;
                                     case "away":
-                                        fh.trait_temp.curValue = receiveBytes[7];
+                                        fh.trait_temp.curValue = receiveBytes[7].ToString();
                                         fh.lastState = Language.StringByID(StringId.Away);
                                         break;
                                 }
+
+                                fh.trait_IndoorTemp.curValue = receiveBytes[9] > 128 ? (1 - (receiveBytes[9] - 128)) : receiveBytes[9];
+
                                 fh.lastState += " " + fh.trait_temp.curValue + fh.tempUnitString;
                                 RoomPage.UpdataStates(fh);
                                 FunctionPage.UpdataStates(fh);
@@ -439,31 +450,50 @@
                         }
                         break;
                     case Command.ReadDeviceLoopInfoACK:
-                        FunctionType dt = (FunctionType)(11 * 256 + receiveBytes[1]);
+                        //FunctionType dt = (FunctionType)(11 * 256 + receiveBytes[1]);
                         string tag = receiveBytes[1] + "_" + subnetID + "_" + deviceID + "_" + receiveBytes[2];
                         foreach (var sensor in FunctionList.List.sensorsEnvironmentalScience)
                         {
+                            byte sensorType = 0;
+                            switch (sensor.spk)
+                            {
+                                case SPK.SensorTemperature:
+                                    sensorType = 2;
+                                    break;
+                                case SPK.SensorHumidity:
+                                    sensorType = 3;
+                                    break;
+                                case SPK.SensorTVOC:
+                                    sensorType = 5;
+                                    break;
+                                case SPK.SensorPm25:
+                                    sensorType = 6;
+                                    break;
+                                case SPK.SensorCO2:
+                                    sensorType = 7;
+                                    break;
+                            }
                             if (sensor.bus != null)
                             {
-                                if ((int)sensor.functionType % 256 == receiveBytes[1] && sensor.bus.SubnetID == subnetID &&
+                                if (sensorType == receiveBytes[1] && sensor.bus.SubnetID == subnetID &&
                                     sensor.bus.DeviceID == deviceID && sensor.bus.LoopId == receiveBytes[2])
                                 {
-                                    switch (dt)
+                                    switch (sensor.spk)
                                     {
-                                        case FunctionType.Temp:
+                                        case SPK.SensorTemperature:
                                             byte[] tempBytes = new byte[] { receiveBytes[24], receiveBytes[25], receiveBytes[26], receiveBytes[27] };
                                             sensor.values = Math.Round(BitConverter.ToSingle(tempBytes, 0), 1);
                                             break;
-                                        case FunctionType.Humidity:
+                                        case SPK.SensorHumidity:
                                             sensor.values = Convert.ToDouble(receiveBytes[24] * 256 + receiveBytes[25]) / 10;
                                             break;
-                                        case FunctionType.TVOC:
+                                        case SPK.SensorTVOC:
                                             sensor.values = Convert.ToDouble(receiveBytes[24] * 256 + receiveBytes[25]) / 100;
                                             break;
-                                        case FunctionType.PM25:
+                                        case SPK.SensorPm25:
                                             sensor.values = Convert.ToInt32(receiveBytes[24] * 256 + receiveBytes[25]);
                                             break;
-                                        case FunctionType.CO2:
+                                        case SPK.SensorCO2:
                                             sensor.values = Convert.ToInt32(receiveBytes[24] * 256 + receiveBytes[25]);
                                             break;
                                     }
@@ -476,9 +506,28 @@
                         string tag1 = receiveBytes[1] + "_" + subnetID + "_" + deviceID + "_" + receiveBytes[2];
                         foreach (var sensor in FunctionList.List.sensorsEnvironmentalScience)
                         {
+                            byte sensorType = 0;
+                            switch (sensor.spk)
+                            {
+                                case SPK.SensorTemperature:
+                                    sensorType = 2;
+                                    break;
+                                case SPK.SensorHumidity:
+                                    sensorType = 3;
+                                    break;
+                                case SPK.SensorTVOC:
+                                    sensorType = 5;
+                                    break;
+                                case SPK.SensorPm25:
+                                    sensorType = 6;
+                                    break;
+                                case SPK.SensorCO2:
+                                    sensorType = 7;
+                                    break;
+                            }
                             if (sensor.bus != null)
                             {
-                                if ((int)sensor.functionType % 256 == receiveBytes[1] && sensor.bus.SubnetID == subnetID &&
+                                if (sensorType == receiveBytes[1] && sensor.bus.SubnetID == subnetID &&
                                     sensor.bus.DeviceID == deviceID && sensor.bus.LoopId == receiveBytes[2])
                                 {
                                     //0淇濈暀 1鏃犵鍙�4Byte鏁村舰  2鏈夌鍙�4Byte鏁村舰  3Float褰紙浠B憋級
@@ -535,18 +584,18 @@
                                     case 7:
                                     case 8:
                                     case 19:
-                                        ac.trait_temp.curValue = receiveBytes[1];
+                                        ac.SetAttrState(FunctionAttributeKey.SetTemp, receiveBytes[1].ToString());
                                         break;
                                     case 5:
-                                        ac.curFanIndex = receiveBytes[1];
+                                        ac.SetFanIndex ( receiveBytes[1]);
                                         break;
                                     case 6:
-                                        ac.curModeIndex = receiveBytes[1];
+                                        ac.SetModeIndex ( receiveBytes[1]);
                                         break;
 
                                 }
                                 ac.lastState = "";
-                                ac.lastState += " " + ac.trait_temp.curValue + ac.tempUnitString;
+                                ac.lastState += " " + ac.GetAttrState(FunctionAttributeKey.SetTemp) + ac.tempUnitString;
                                 RoomPage.UpdataStates(ac);
                                 FunctionPage.UpdataStates(ac);
                                 HomePage.UpdataFunctionStates(ac);
@@ -561,7 +610,7 @@
                         {
                             if (ac.GetBusId() == subnetID + "_" + deviceID + "_" + receiveBytes[0])
                             {
-                                ac.trait_IndoorTemp.curValue = receiveBytes[1];
+                                ac.SetAttrState(FunctionAttributeKey.IndoorTemp, receiveBytes[1].ToString());
                                 FunctionPage.UpdataStates(ac);
                             }
                         }
@@ -572,8 +621,9 @@
                         MainPage.Log($"name : {Name} ; mac : {mac}");
                         if (DB_ResidenceData.Instance.residenceGatewayMAC == mac)
                         {
-                            Control.Ins.GatewayOnline = true;
-                            Control.Ins.IsRemote = false;
+                            //鏈湴鎼滅储缃戝叧鎴愬姛
+                            Control.Ins.IsSearchLocalGatewaySuccessful = true;
+                            Control.Ins.GatewayOnline_Local = true;
                             DAL.Mqtt.MqttClient.DisConnectRemote();//鏂紑mqtt
                         }
                         break;
@@ -642,12 +692,12 @@
                         receiveFlag += string.Format("{0},{1}", usefulBytes[0], usefulBytes[1]);
                         break;
                     case Command.ReadRemark:
-                        DriverLayer.Control.Ins.myUdp.ReceiveReadRemark(usefulBytes);
+                        new Control_Udp().ReceiveReadRemark(usefulBytes);
                         break;
                     default:
                         break;
                 }
-                DriverLayer.Control.Ins.myUdp.ReceiveRepeatManager(receiveFlag);
+                Control_Udp.ReceiveRepeatManager(receiveFlag,usefulBytes);
             }
             catch (Exception ex)
             {

--
Gitblit v1.8.0