wei
2020-12-17 bb6ad792b598927a5459a5fb6f6c27fb1aa9e94e
HDL_ON/DAL/DriverLayer/Packet.cs
@@ -116,14 +116,15 @@
                {
                    case Command.SetSingleLightACK:
                        var queryList = new List<Function>();
                        queryList.AddRange(DB_ResidenceData.functionList.electricals);
                        queryList.AddRange(DB_ResidenceData.functionList.lights);
                        queryList.AddRange(FunctionList.List.electricals);
                        queryList.AddRange(FunctionList.List.lights);
                        foreach (var updataObj in queryList)
                        {
                            if (updataObj.GetBusId() == subnetID + "_" + deviceID + "_" + receiveBytes[0])
                            {
                                if (updataObj.functionType != FunctionType.RGB)
                                {
                                    updataObj.trait_on_off.curValue = receiveBytes[2] > 0 ? "on" : "off";
                                    if (updataObj.trait_on_off.curValue.ToString() == "on")
                                    {
                                        switch (updataObj.functionType)
@@ -132,12 +133,10 @@
                                                (updataObj as Fan).openLevel = receiveBytes[2];
                                                updataObj.lastState = Language.StringByID(StringId.Level) + " : " + receiveBytes[2];
                                                break;
                                            case FunctionType.Relay:
                                            case FunctionType.Dimmer:
                                                (updataObj as Light).brightness = receiveBytes[2];
                                                updataObj.lastState = Language.StringByID(StringId.Brightness) + " : " + receiveBytes[2] + "%";
                                                break;
                                            //case FunctionType.Socket:
                                            //    (updataObj as SwitchSocket).
                                        }
                                    }
                                    HomePage.UpdataFunctionStates(updataObj);
@@ -164,12 +163,12 @@
                    case Command.ReadLightAllLoopBrightnessACK:
                        for (int i = 0; i < receiveBytes[0]; i++)
                        {
                            var light = DB_ResidenceData.functionList.lights.Find((obj) => obj.bus_Data.SubnetID == subnetID && obj.bus_Data.DeviceID == deviceID && obj.bus_Data.LoopID == (i + 1));
                            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)
                                {
                                    light.trait_on_off.curValue = receiveBytes[light.bus_Data.LoopID] == 0 ? "off" : "on";
                                    light.trait_on_off.curValue = receiveBytes[light.bus.LoopId] == 0 ? "off" : "on";
                                    if (light.trait_on_off.curValue.ToString() == "on")
                                    {
                                        light.brightness = receiveBytes[2];
@@ -192,7 +191,7 @@
                            }
                            else
                            {
                                var e = DB_ResidenceData.functionList.electricals.Find((obj) => obj.bus_Data.SubnetID == subnetID && obj.bus_Data.DeviceID == deviceID && obj.bus_Data.LoopID == i);
                                var e = FunctionList.List.electricals.Find((obj) => obj.bus.SubnetID == subnetID && obj.bus.DeviceID == deviceID && obj.bus.LoopId == i);
                                if (e != null)
                                {
                                    var fan = e as Fan;
@@ -221,7 +220,7 @@
                        break;
                    case Command.SetLogicLoopColorACK:
                    case Command.ReadLogicLoopColorACK:
                        foreach (var rgb in DB_ResidenceData.functionList.lights)
                        foreach (var rgb in FunctionList.List.lights)
                        {
                            if (rgb.GetBusId() == subnetID + "_" + deviceID + "_" + receiveBytes[0])
                            {
@@ -233,9 +232,7 @@
                                        rgb.brightness = receiveBytes[1];
                                        rgb.lastState = Language.StringByID(StringId.Brightness) + " : " + receiveBytes[1] + "%";
                                    }
                                    rgb.redColor = receiveBytes[6];
                                    rgb.greenColor = receiveBytes[7];
                                    rgb.blueColor = receiveBytes[8];
                                    rgb.SetRGBcolor(new byte[] { receiveBytes[6], receiveBytes[7], receiveBytes[8] });
                                    HomePage.UpdataFunctionStates(rgb);
                                    RoomPage.UpdataStates(rgb);
@@ -248,9 +245,9 @@
                        break;
                    case Command.SetCurtainModelStutasACK:
                    case Command.ReadCurtainStutasACK:
                        foreach (var curtain in DB_ResidenceData.functionList.curtains)
                        foreach (var curtain in FunctionList.List.curtains)
                        {
                            if (curtain.bus_Data.SubnetID == subnetID && curtain.bus_Data.DeviceID == deviceID)
                            if (curtain.bus.SubnetID == subnetID && curtain.bus.DeviceID == deviceID)
                            {
                                if (receiveBytes[0] == 17)
                                {
@@ -267,7 +264,7 @@
                                }
                                else
                                {
                                    if (curtain.bus_Data.LoopID != receiveBytes[0])
                                    if (curtain.bus.LoopId != receiveBytes[0])
                                        continue;
                                    switch (receiveBytes[1])
                                    {
@@ -305,12 +302,12 @@
                        break;
                    case Command.SetACModeACK:
                    case Command.ReadACModeACK:
                        foreach (var ac in DB_ResidenceData.functionList.aCs)
                        foreach (var ac in FunctionList.List.aCs)
                        {
                            if (ac.GetBusId() == subnetID + "_" + deviceID + "_" + receiveBytes[0])
                            {
                                ac.curTempType = receiveBytes[1];
                                ac.indoorTemp = receiveBytes[2];
                                ac.trait_IndoorTemp.curValue = receiveBytes[2];
                                ac.trait_on_off.curValue = receiveBytes[8] == 1 ? "on" : "off";
                                ac.curModeIndex = receiveBytes[9];
                                ac.curFanIndex = receiveBytes[10];
@@ -360,7 +357,7 @@
                        break;
                    case Command.ReadFloorHeatACK:
                    case Command.SetFloorHeatACK:
                        foreach (var fh in DB_ResidenceData.functionList.floorHeatings)
                        foreach (var fh in FunctionList.List.floorHeatings)
                        {
                            if (fh.GetBusId() == subnetID + "_" + deviceID + "_" + receiveBytes[0])
                            {
@@ -444,12 +441,12 @@
                    case Command.ReadDeviceLoopInfoACK:
                        FunctionType dt = (FunctionType)(11 * 256 + receiveBytes[1]);
                        string tag = receiveBytes[1] + "_" + subnetID + "_" + deviceID + "_" + receiveBytes[2];
                        foreach (var sensor in DB_ResidenceData.functionList.sensorsEnvironmentalScience)
                        foreach (var sensor in FunctionList.List.sensorsEnvironmentalScience)
                        {
                            if (sensor.bus_Data != null)
                            if (sensor.bus != null)
                            {
                                if ((int)sensor.functionType % 256 == receiveBytes[1] && sensor.bus_Data.SubnetID == subnetID &&
                                    sensor.bus_Data.DeviceID == deviceID && sensor.bus_Data.LoopID == receiveBytes[2])
                                if ((int)sensor.functionType % 256 == receiveBytes[1] && sensor.bus.SubnetID == subnetID &&
                                    sensor.bus.DeviceID == deviceID && sensor.bus.LoopId == receiveBytes[2])
                                {
                                    switch (dt)
                                    {
@@ -477,12 +474,12 @@
                        break;
                    case Command.New_Analog_Quantity_BROADCAST:
                        string tag1 = receiveBytes[1] + "_" + subnetID + "_" + deviceID + "_" + receiveBytes[2];
                        foreach (var sensor in DB_ResidenceData.functionList.sensorsEnvironmentalScience)
                        foreach (var sensor in FunctionList.List.sensorsEnvironmentalScience)
                        {
                            if (sensor.bus_Data != null)
                            if (sensor.bus != null)
                            {
                                if ((int)sensor.functionType % 256 == receiveBytes[1] && sensor.bus_Data.SubnetID == subnetID &&
                                    sensor.bus_Data.DeviceID == deviceID && sensor.bus_Data.LoopID == receiveBytes[2])
                                if ((int)sensor.functionType % 256 == receiveBytes[1] && sensor.bus.SubnetID == subnetID &&
                                    sensor.bus.DeviceID == deviceID && sensor.bus.LoopId == receiveBytes[2])
                                {
                                    //0保留 1无符号4Byte整形  2有符号4Byte整形  3Float形(代±)
                                    switch (receiveBytes[3])
@@ -525,7 +522,7 @@
                        {
                            break;
                        }
                        foreach (var ac in DB_ResidenceData.functionList.aCs)
                        foreach (var ac in FunctionList.List.aCs)
                        {
                            if (ac.GetBusId() == subnetID + "_" + deviceID + "_" + reACPanel)
                            {
@@ -560,11 +557,11 @@
                        break;
                    case Command.ReadPanleTempACK://1944
                    case Command.PanleBroadcastTemp:
                        foreach (var ac in DB_ResidenceData.functionList.aCs)
                        foreach (var ac in FunctionList.List.aCs)
                        {
                            if (ac.GetBusId() == subnetID + "_" + deviceID + "_" + receiveBytes[0])
                            {
                                ac.indoorTemp = receiveBytes[1];
                                ac.trait_IndoorTemp.curValue = receiveBytes[1];
                                FunctionPage.UpdataStates(ac);
                            }
                        }
@@ -573,9 +570,11 @@
                        var mac = ByteToHex16(receiveBytes[5]) + ByteToHex16(receiveBytes[6]) + ByteToHex16(receiveBytes[7]) + ByteToHex16(receiveBytes[8]) + ByteToHex16(receiveBytes[9]) + ByteToHex16(receiveBytes[10]) + ByteToHex16(receiveBytes[11]) + ByteToHex16(receiveBytes[12]);
                        var Name = Encoding.GetEncoding("gb2312").GetString(receiveBytes, 13, 20).Trim('\0'); ;
                        MainPage.Log($"name : {Name} ; mac : {mac}");
                        if (DB_ResidenceData.residenceData.residenceGatewayMAC == mac)
                        if (DB_ResidenceData.Instance.residenceGatewayMAC == mac)
                        {
                            DriverLayer.Control.Ins.GatewayOnline = true;
                            Control.Ins.GatewayOnline = true;
                            Control.Ins.IsRemote = false;
                            DAL.Mqtt.MqttClient.DisConnectRemote();//断开mqtt
                        }
                        break;
                }