From 3069c032027eeea7a14fa9f462440bb2d802d9a9 Mon Sep 17 00:00:00 2001
From: wei <kaede@kaededeMacBook-Air.local>
Date: 星期一, 11 一月 2021 14:25:09 +0800
Subject: [PATCH] 20210111-合并代码
---
HDL_ON/DAL/DriverLayer/Packet.cs | 179 +++++++++++++++++++++++++++++++++++++----------------------
1 files changed, 113 insertions(+), 66 deletions(-)
diff --git a/HDL_ON/DAL/DriverLayer/Packet.cs b/HDL_ON/DAL/DriverLayer/Packet.cs
index 1caa9ff..1723234 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);
}
@@ -116,24 +124,24 @@
{
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)
+ 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;
}
@@ -163,12 +171,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)
+ if (light.spk != SPK.LightRGB)
{
- 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];
@@ -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;
}
@@ -191,7 +199,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;
@@ -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;
}
@@ -220,11 +228,11 @@
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])
{
- if (rgb.functionType == FunctionType.RGB)
+ if (rgb.spk == SPK.LightRGB)
{
rgb.trait_on_off.curValue = receiveBytes[1] > 0 ? "on" : "off";
if (receiveBytes[1] > 0)
@@ -232,9 +240,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);
@@ -247,9 +253,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)
{
@@ -266,7 +272,7 @@
}
else
{
- if (curtain.bus_Data.loopId != receiveBytes[0])
+ if (curtain.bus.LoopId != receiveBytes[0])
continue;
switch (receiveBytes[1])
{
@@ -287,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;
}
@@ -304,16 +310,16 @@
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].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.trait_temp.curValue = receiveBytes[11].ToString();
ac.lastState = "";
switch (ac.trait_mode.curValue.ToString())
{
@@ -359,7 +365,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])
{
@@ -403,31 +409,31 @@
{
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;
}
@@ -441,31 +447,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 DB_ResidenceData.functionList.sensorsEnvironmentalScience)
+ foreach (var sensor in FunctionList.List.sensorsEnvironmentalScience)
{
- if (sensor.bus_Data != null)
+ byte sensorType = 0;
+ switch (sensor.spk)
{
- if ((int)sensor.functionType % 256 == receiveBytes[1] && sensor.bus_Data.SubnetID == subnetID &&
- sensor.bus_Data.DeviceID == deviceID && sensor.bus_Data.loopId == receiveBytes[2])
+ 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 (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,12 +501,31 @@
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)
+ byte sensorType = 0;
+ switch (sensor.spk)
{
- if ((int)sensor.functionType % 256 == receiveBytes[1] && sensor.bus_Data.SubnetID == subnetID &&
- sensor.bus_Data.DeviceID == deviceID && sensor.bus_Data.loopId == receiveBytes[2])
+ 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 (sensorType == receiveBytes[1] && sensor.bus.SubnetID == subnetID &&
+ sensor.bus.DeviceID == deviceID && sensor.bus.LoopId == receiveBytes[2])
{
//0淇濈暀 1鏃犵鍙�4Byte鏁村舰 2鏈夌鍙�4Byte鏁村舰 3Float褰紙浠B憋級
switch (receiveBytes[3])
@@ -524,7 +568,7 @@
{
break;
}
- foreach (var ac in DB_ResidenceData.functionList.aCs)
+ foreach (var ac in FunctionList.List.aCs)
{
if (ac.GetBusId() == subnetID + "_" + deviceID + "_" + reACPanel)
{
@@ -537,7 +581,7 @@
case 7:
case 8:
case 19:
- ac.trait_temp.curValue = receiveBytes[1];
+ ac.trait_temp.curValue = receiveBytes[1].ToString();
break;
case 5:
ac.curFanIndex = receiveBytes[1];
@@ -559,11 +603,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].ToString();
FunctionPage.UpdataStates(ac);
}
}
@@ -572,10 +616,13 @@
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;
- DriverLayer.Control.Ins.IsRemote = false;
+ //鏈湴鎼滅储缃戝叧鎴愬姛
+ Control.Ins.IsSearchLocalGatewaySuccessful = true;
+ Control.Ins.GatewayOnline = true;
+ Control.Ins.IsRemote = false;
+ DAL.Mqtt.MqttClient.DisConnectRemote();//鏂紑mqtt
}
break;
}
@@ -643,12 +690,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