From ea0b1e8e5f43c5fd0a7d479e25ede3b8cbea464a Mon Sep 17 00:00:00 2001
From: wxr <wxr@hdlchina.com.cn>
Date: 星期一, 02 十二月 2024 17:17:19 +0800
Subject: [PATCH] tcp;可视对讲;
---
HDL_ON/DAL/DriverLayer/Control_Udp.cs | 324 ++++++++++++++++++++++++++++++++++-------------------
1 files changed, 208 insertions(+), 116 deletions(-)
diff --git a/HDL_ON/DAL/DriverLayer/Control_Udp.cs b/HDL_ON/DAL/DriverLayer/Control_Udp.cs
index b715e44..9f22c22 100644
--- a/HDL_ON/DAL/DriverLayer/Control_Udp.cs
+++ b/HDL_ON/DAL/DriverLayer/Control_Udp.cs
@@ -11,10 +11,6 @@
{
public class Control_Udp
{
- //public Control_Udp()
- //{
- // MainPage.Log($"control bus udp 琚垱寤猴紝鏃堕棿锛歿DateTime.Now}");
- //}
/// <summary>
/// 閫氳绔彛
/// </summary>
@@ -29,7 +25,7 @@
/// 鎵�鏈夊涓�绔彛鐨勬帶鍒堕兘浼氭斁鍒拌繖涓泦鍚堥噷
/// </summary>
static List<Control_Udp> controlList = new List<Control_Udp>(50);
-
+
public System.Net.IPEndPoint EndPoint
{
@@ -37,7 +33,7 @@
{
try
{
- return new System.Net.IPEndPoint(System.Net.IPAddress.Parse(new NetWiFi().BroadcastIpAddress.ToString()),6000);
+ return new System.Net.IPEndPoint(System.Net.IPAddress.Parse(new NetWiFi().BroadcastIpAddress.ToString()), 6000);
}
catch
{
@@ -50,7 +46,7 @@
/// <summary>
/// 鍙戦�佹暟鎹紝涓嶉渶瑕佺瓑寰呭洖澶�
/// </summary>
- public void ControlBytesSend(Command command, byte subnetID, byte deviceID, byte[] gatewayBytes, int sendCount = 3,bool reSend = false)
+ public void ControlBytesSend(Command command, byte subnetID, byte deviceID, byte[] gatewayBytes, int sendCount = 3, bool reSend = false)
{
#if DEBUG
string ddd = "";
@@ -58,25 +54,24 @@
{
ddd += bb + ",";
}
- MainPage.Log($"鍙戦�乥us鍛戒护:" + ((int)command).ToString("X").PadLeft(4,'0') + " : 鏁版嵁:" + ddd);
+ MainPage.Log($"鍙戦�乥us鍛戒护:" + ((int)command).ToString("X").PadLeft(4, '0') + " : 鏁版嵁:" + ddd);
#endif
var control = new Control_Udp();
control.Send(new Target()
{
- IPEndPoint = EndPoint ,
+ IPEndPoint = EndPoint,
Command = command,
SubnetID = subnetID,
DeviceID = deviceID,
AddData = gatewayBytes,
- //}, 3, true);
}, sendCount, reSend);
}
/// <summary>
/// 閲嶅彂楠岃瘉
/// </summary>
- public static void ReceiveRepeatManager(string receiveFlag,byte []usefulBytes)
+ public static void ReceiveRepeatManager(string receiveFlag, byte[] usefulBytes)
{
for (int i = 0; i < controlList.Count; i++)
{
@@ -104,13 +99,13 @@
try
{
//璐﹀彿娌$櫥褰曚笉鍥炲
- if ( UserInfo.Current == null || ! UserInfo.Current.IsLogin)
+ if (UserInfo.Current == null)///|| ! UserInfo.Current.IsLogin)
{
return;
}
Control.Ins.OpenTcpServer();
- var sendStr = UserInfo.Current.AccountString;
+ var sendStr = UserInfo.Current.AccountString;
if (usefullBytes.Length == 0)
{
SendRemark(sendStr);
@@ -136,7 +131,8 @@
}
}
}
- catch (Exception ex) {
+ catch (Exception ex)
+ {
Console.WriteLine($"鍥炲bus鎼滅储寮傚父 : {ex.Message}");
}
}
@@ -165,7 +161,7 @@
/// </summary>
public void ControlBusScenes(Scene scene)
{
- if(Control.Ins.GatewayOnline_Local)
+ if (Control.Ins.GatewayOnline_Local)
{
foreach (var f in scene.functions)
{
@@ -191,13 +187,14 @@
break;
}
ControlBytesSend(Command.SetCurtainModelStutas, f.localFunction.bus.SubnetID, f.localFunction.bus.DeviceID,
- new byte[] { f.localFunction.bus.LoopId, curtainState },0);
+ new byte[] { f.localFunction.bus.LoopId, curtainState }, 0);
break;
}
}
break;
case SPK.AcStandard:
case SPK.HvacAC:
+ case SPK.HvacAcPanel:
AC acTemp = new AC();
byte onoff = 0;
byte mode = 0;
@@ -208,7 +205,7 @@
switch (attr.key)
{
case FunctionAttributeKey.OnOff:
- if(attr.value == "on")
+ if (attr.value == "on")
{
onoff = 1;
}
@@ -271,8 +268,8 @@
ControlBytesSend(Command.InstructionPanelKey, f.localFunction.bus.SubnetID, f.localFunction.bus.DeviceID, new byte[] { 6, mode, f.localFunction.bus.LoopId });
ControlBytesSend(Command.InstructionPanelKey, f.localFunction.bus.SubnetID, f.localFunction.bus.DeviceID, new byte[] { 5, fan, f.localFunction.bus.LoopId });
ControlBytesSend(Command.InstructionPanelKey, f.localFunction.bus.SubnetID, f.localFunction.bus.DeviceID, new byte[] { modeKey, modeKey, f.localFunction.bus.LoopId });
-
- }
+
+ }
break;
case SPK.LightSwitch:
case SPK.LightDimming:
@@ -302,8 +299,10 @@
break;
case SPK.LightRGB:
break;
- case SPK.HvacFloorHeat:case SPK.FloorHeatStandard:
- if (f.status.Find((obj)=>obj.key ==FunctionAttributeKey.Mode) == null)
+ case SPK.HvacFloorHeat:
+ case SPK.HvacFloorHeatPanel:
+ case SPK.FloorHeatStandard:
+ if (f.status.Find((obj) => obj.key == FunctionAttributeKey.Mode) == null)
{
foreach (var dic in f.status)
{
@@ -392,6 +391,27 @@
}
}
break;
+ case SPK.OtherCommon://2024-02-01 15:19:28
+ foreach (var attr in f.status)
+ {
+ if (attr.key == FunctionAttributeKey.OnOff)
+ {
+ byte onOffValue = 0;
+ switch (attr.value)
+ {
+ case "on":
+ onOffValue = 0;
+ break;
+ case "off":
+ onOffValue = 255;
+ break;
+ }
+ ControlBytesSend(Command.SetCommonSwitch, f.localFunction.bus.SubnetID, f.localFunction.bus.DeviceID,
+ new byte[] { f.localFunction.bus.LoopId, onOffValue });
+ break;
+ }
+ }
+ break;
}
}
}
@@ -442,21 +462,24 @@
{
case SPK.LightCCT:
#region cct light
- byte b0 = 100;
- if (commandDictionary.ContainsKey(FunctionAttributeKey.OnOff))
+ byte b0 = Convert.ToByte(function.lastBrightness);
+ if (commandDictionary.ContainsKey(FunctionAttributeKey.Brightness))
{
- if (function.trait_on_off.curValue.ToString() == "off")
- {
- b0 = 0;
- }
- else
- {
- b0 = function.lastBrightness == 0 ? (byte)100 : Convert.ToByte(function.lastBrightness);
- }
+ b0 = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.Brightness));
}
else
{
- b0 = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.Brightness));
+ if (commandDictionary.ContainsKey(FunctionAttributeKey.OnOff))
+ {
+ if (function.trait_on_off.curValue.ToString() == "off")
+ {
+ b0 = 0;
+ }
+ else
+ {
+ b0 = function.lastBrightness == 0 ? (byte)100 : Convert.ToByte(function.lastBrightness);
+ }
+ }
}
var bytes0 = new byte[] { function.bus.LoopId,
b0,
@@ -470,21 +493,24 @@
break;
case SPK.LightRGB:
#region rgb light
- byte b = 100;
- if (commandDictionary.ContainsKey(FunctionAttributeKey.OnOff))
+ byte b = Convert.ToByte(function.lastBrightness);
+ if (commandDictionary.ContainsKey(FunctionAttributeKey.Brightness))
{
- if (function.trait_on_off.curValue.ToString() == "off")
- {
- b = 0;
- }
- else
- {
- b = function.lastBrightness == 0 ? (byte)100 : Convert.ToByte(function.lastBrightness);
- }
+ b = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.Brightness));
}
else
{
- b = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.Brightness));
+ if (commandDictionary.ContainsKey(FunctionAttributeKey.OnOff))
+ {
+ if (function.trait_on_off.curValue.ToString() == "off")
+ {
+ b = 0;
+ }
+ else
+ {
+ b = function.lastBrightness == 0 ? (byte)100 : Convert.ToByte(function.lastBrightness);
+ }
+ }
}
var tempLight = new Light();
var bytes = new byte[] { function.bus.LoopId,
@@ -499,21 +525,24 @@
break;
case SPK.LightDimming:
#region dimming light
- byte b1 = 100;
- if (commandDictionary.ContainsKey(FunctionAttributeKey.OnOff))
+ byte b1 = Convert.ToByte(function.lastBrightness);
+ if (commandDictionary.ContainsKey(FunctionAttributeKey.Brightness))
{
- if (function.trait_on_off.curValue.ToString() == "off")
- {
- b1 = 0;
- }
- else
- {
- b1 = function.lastBrightness == 0 ? (byte)100 : Convert.ToByte(function.lastBrightness);
- }
+ b1 = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.Brightness));
}
else
{
- b1 = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.Brightness));
+ if (commandDictionary.ContainsKey(FunctionAttributeKey.OnOff))
+ {
+ if (function.trait_on_off.curValue.ToString() == "off")
+ {
+ b1 = 0;
+ }
+ else
+ {
+ b1 = function.lastBrightness == 0 ? (byte)100 : Convert.ToByte(function.lastBrightness);
+ }
+ }
}
ControlBytesSend(Command.SetSingleLight, subnetId, deviceId, new byte[] {
function.bus.LoopId,
@@ -579,8 +608,8 @@
break;
case SPK.AcStandard:
case SPK.HvacAC:
+ case SPK.HvacAcPanel:
var ac = new AC();
-
byte onoff = 0;
onoff = function.trait_on_off.curValue.ToString() == "on" ? (byte)1 : (byte)0;
byte mode = 0;
@@ -590,28 +619,34 @@
byte sanfan = 0;
byte temp = 16;
temp = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.SetTemp));
+ byte coolTemp = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.CoolTemperatrue));
+ byte heatTemp = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.HeatTemperatrue));
+ byte autoTemp = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.AutoTemperatrue));
+ byte dehumiTemp = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.DehumiTemperatrue));
foreach (var dic in commandDictionary)
{
switch (dic.Key)
{
case FunctionAttributeKey.OnOff:
onoff = dic.Value == "on" ? (byte)1 : (byte)0;
- //ControlBytesSend(Command.InstructionPanelKey, function.bus.SubnetID, function.bus.DeviceID,
- // new byte[] { 3, onoff, function.bus.LoopId });
break;
case "mode":
switch (dic.Value)
{
case "auto":
mode = 3;
+ temp = autoTemp;
break;
case "cool":
mode = 0;
+ temp = coolTemp;
break;
case "heat":
mode = 1;
+ temp = heatTemp;
break;
case "dry":
+ temp = dehumiTemp;
mode = 4;
break;
case "fan":
@@ -621,8 +656,6 @@
mode = 0;
break;
}
- //ControlBytesSend(Command.InstructionPanelKey, function.bus.SubnetID, function.bus.DeviceID,
- // new byte[] { 6, mode, function.bus.LoopId });
break;
case "fan":
switch (dic.Value)
@@ -643,8 +676,6 @@
fan = 0;
break;
}
- //ControlBytesSend(Command.InstructionPanelKey, function.bus.SubnetID, function.bus.DeviceID,
- // new byte[] { 5, fan, function.bus.LoopId });
break;
case FunctionAttributeKey.SetTemp:
try
@@ -655,28 +686,6 @@
{
temp = 16;
}
- //byte modeKey = 4;
- //switch (ac.GetModeIndex(function))
- //{
- // case 3:
- // modeKey = 8;
- // break;
- // case 0:
- // modeKey = 4;
- // break;
- // case 1:
- // modeKey = 7;
- // break;
- // case 4:
- // modeKey = 19;
- // break;
- // case 2:
- // modeKey = 2;
- // break;
- //}
-
- //ControlBytesSend(Command.InstructionPanelKey, function.bus.SubnetID, function.bus.DeviceID, new byte[] {
- // modeKey, temp, function.bus.LoopId });
break;
case FunctionAttributeKey.Swing:
//sanfan
@@ -686,25 +695,28 @@
break;
}
}
- /// 璁剧疆绌鸿皟妯″潡鍛戒护
- /// 1绌鸿皟鍙�(1-128)
- ///2娓╁害妯″紡(鎽勬皬Celsius:0锛屽崕姘廎ahrenheit:1)
- ///3鐜娓╁害 (鎽勬皬0-40锛屽崕姘�32-99)
- ///4鍒跺喎鎺у埗娓╁害(鎽勬皬0-30锛屽崕姘�32-86)
- ///5鍒剁儹鎺у埗娓╁害(鎽勬皬0-30锛屽崕姘�32-86)
- ///6鑷姩鎺у埗娓╁害(鎽勬皬0-30锛屽崕姘�32-86)
- ///7闄ゆ箍鎺у埗娓╁害(鎽勬皬0-30锛屽崕姘�32-86)
- ///8妞掔饥鍋堝浣裤伔楂? 楂�4bit妯″紡(0 鍒跺喎锛�1鍒剁儹锛�2閫氶) 浣�4bit椋庨��(0 鑷姩锛�1楂橀?椋庯紝3浣庨)
- ///9绌鸿皟寮�鍏� (1寮�0鍏�)
- ///10璁剧疆妯″紡 0 鍒跺喎1鍒剁儹锛�2閫氶锛�3鑷姩锛�4闄ゆ箍
- ///11璁剧疆椋庨�� 0 鑷姩锛�1楂橀2涓锛�3浣庨
- ///12宸ヤ綔妯℃帶鍒舵俯鑲氭幃鎽勬皬0-30锛屽崕姘�32-86)
- ///13鎵妯″紡锛氶珮4bit(瀹為檯鎵鐘舵�侊細0涓嶆壂椋庯紝1鎵)锛屼綆4bit(璁剧疆鎵妯″紡锛�0涓嶆壂椋庯紝1鎵)
+ switch (mode)
+ {
+ case 0:
+ coolTemp = temp;
+ break;
+ case 1:
+ heatTemp = temp;
+ break;
+ case 3:
+ autoTemp = temp;
+ break;
+ case 4:
+ dehumiTemp = temp;
+ break;
+ }
ControlBytesSend(Command.SetACMode, function.bus.SubnetID, function.bus.DeviceID, new byte[] { function.bus.LoopId,
- 0,0,0,0,0,0,0,onoff,mode,fan,temp,sanfan});
+ 0,0,coolTemp,heatTemp,autoTemp,dehumiTemp,0,onoff,mode,fan,temp,sanfan});
break;
- case SPK.HvacFloorHeat:case SPK.FloorHeatStandard:
+ case SPK.HvacFloorHeat:
+ case SPK.FloorHeatStandard:
+ case SPK.HvacFloorHeatPanel:
var fhTemp = new FloorHeating();
if (function.Fh_Mode_Temp.Count == 4)
{
@@ -803,6 +815,87 @@
case SPK.PanelSocket:
ControlBytesSend(Command.SetSingleLight, subnetId, deviceId, new byte[] { function.bus.LoopId, function.trait_on_off.curValue.ToString() == "on" ? (byte)100 : (byte)0 });
break;
+ case SPK.AirFreshJinmao:
+ case SPK.HvacAirFreshJinmao:
+ #region AirFresh
+ //1 鏂伴缂栧彿 1~200
+ //2 绫诲瀷 绗笁鏂圭被鍨� 0锛氶噾鑼傛柊椋�
+
+ //3 寮�鍏� 0 - 鍏虫満锛�1 - 寮�鏈�
+ byte switchValue = 0;
+ if (commandDictionary.ContainsKey(FunctionAttributeKey.OnOff) == true
+ && commandDictionary[FunctionAttributeKey.OnOff] == "on")
+ {
+ switchValue = 1;
+ }
+
+ //4 杩愯妯″紡 1 - 閫氶锛�2 - 鍔犳箍
+ byte airFreshMode = 1;
+ if (commandDictionary.ContainsKey(FunctionAttributeKey.Mode) == true
+ && commandDictionary[FunctionAttributeKey.Mode] == "humidification")
+ {
+ airFreshMode = 2;
+ }
+ //5 鑺傝兘鑸掗�傞�夋嫨 1 - 鑸掗�傦紝2 - 鑺傝兘
+ byte airFreshEnergy = 1;
+ if (commandDictionary.ContainsKey(FunctionAttributeKey.Energy) == true
+ && commandDictionary[FunctionAttributeKey.Energy] == "true")
+ {
+ airFreshEnergy = 2;
+ }
+ //6 椋庨�熸。浣� 0 - 鑷姩锛�1 - 1妗o紝2 - 2妗o紝3 - 3妗�
+ byte airFreshFan = 0;
+ if (commandDictionary.ContainsKey(FunctionAttributeKey.FanSpeed) == true)
+ {
+ switch (commandDictionary[FunctionAttributeKey.FanSpeed])
+ {
+ case "auto":
+ airFreshFan = 0;
+ break;
+ case "level_1":
+ airFreshFan = 1;
+ break;
+ case "level_2":
+ airFreshFan = 2;
+ break;
+ case "level_3":
+ airFreshFan = 3;
+ break;
+ }
+ }
+ //7 婀垮害璁惧畾 %
+ byte hum = 0;
+ if (commandDictionary.ContainsKey(FunctionAttributeKey.Humidity) == true)
+ {
+ hum = Convert.ToByte(commandDictionary[FunctionAttributeKey.Humidity]);
+ }
+ //8 瀹ゅ唴娓╁害鍊� 鈩�
+ byte indoorTemp_airFrsh = 0;
+ if (commandDictionary.ContainsKey(FunctionAttributeKey.IndoorTemp) == true)
+ {
+ indoorTemp_airFrsh = Convert.ToByte(commandDictionary[FunctionAttributeKey.IndoorTemp]);
+ }
+ byte indoorHumidity_airFrsh = 0;
+ if (commandDictionary.ContainsKey(FunctionAttributeKey.IndoorHumidity) == true)
+ {
+ indoorHumidity_airFrsh = Convert.ToByte(commandDictionary[FunctionAttributeKey.IndoorHumidity]);
+ }
+ //9 瀹ゅ唴婀垮害鍊� 鈩�
+ //10 杩囨护缃戝墿浣� %
+ //11 杩囨护缃戜娇鐢ㄨ秴鏃� 1 瓒呮椂 0 鏃�
+ ControlBytesSend(Command.FreshAirControl_JinMao, subnetId, deviceId, new byte[] {
+ function.bus.LoopId,0, switchValue ,
+ airFreshMode,airFreshEnergy,
+ airFreshFan,
+ hum,
+ indoorTemp_airFrsh,
+ indoorHumidity_airFrsh,
+ //Convert.ToByte( function.GetAttrState(FunctionAttributeKey.FilterRemain)),
+ //function.GetAttrState(FunctionAttributeKey.FilterTimeout) =="true"?1:0,
+ 0,0
+ });
+ #endregion
+ break;
}
#region 鍙戦�佸懡浠ょ珛鍗虫洿鏂癠I
//HomePage.UpdataFunctionStates(function);
@@ -847,9 +940,12 @@
break;
case SPK.AcStandard:
case SPK.HvacAC:
+ case SPK.HvacAcPanel:
ControlBytesSend(Command.ReadACMode, subnetId, deviceId, new byte[] { function.bus.LoopId });
break;
- case SPK.HvacFloorHeat:case SPK.FloorHeatStandard:
+ case SPK.HvacFloorHeat:
+ case SPK.FloorHeatStandard:
+ case SPK.HvacFloorHeatPanel:
ControlBytesSend(Command.ReadFloorHeat, subnetId, deviceId, new byte[] { function.bus.LoopId });
break;
case SPK.HvacFan:
@@ -875,6 +971,10 @@
case SPK.SensorCO2:
ControlBytesSend(Command.ReadDeviceLoopInfo, subnetId, deviceId, new byte[] { 5, 7, function.bus.LoopId });
break;
+ case SPK.AirFreshJinmao:
+ case SPK.HvacAirFreshJinmao:
+ ControlBytesSend(Command.FreshAirRead_JinMao, subnetId, deviceId, new byte[] { function.bus.LoopId });
+ break;
}
}
catch (Exception ex)
@@ -888,9 +988,6 @@
/// </summary>
void add()
{
- /// <summary>
- /// 杈惧埌50鏉℃暟鎹悗灏辨竻鐞嗕竴涓�
- /// </summary>
if (50 < controlList.Count)
{
lock (controlList)
@@ -988,11 +1085,10 @@
try
{
- MainPage.Log("鍙戦�佹暟鎹�:" + SendFlag);
UdpSocket._BusSocket.AsyncBeginSend(packet);
packet.HaveSendCount--;
- //杩欓噷鏄噸鍙戜袱娆�
+ //UDP閲嶅彂鏁版嵁
while (packet.HaveSendCount < 3)
{
if (packet.FlagDateTime.AddMilliseconds(1000).Ticks <= DateTime.Now.Ticks)
@@ -1092,7 +1188,7 @@
this.wait();
}
}
- catch(Exception ex)
+ catch (Exception ex)
{
MainPage.Log($"Send bus data error {ex.Message}");
}
@@ -1105,9 +1201,9 @@
{
try
{
- var sendJob = new JObject { { "id", Control.Ins.msg_id.ToString() }, { "time_stamp", Utlis.GetTimestamp ()} };
+ var sendJob = new JObject { { "id", Control.Ins.msg_id.ToString() }, { "time_stamp", Utlis.GetTimestamp() } };
var bodyString = JsonConvert.SerializeObject(sendJob);
-
+
var sendBytes = Control.Ins.ConvertSendBodyData(CommunicationTopic.SearchLoaclGateway, bodyString, false);
if (broadcast)
{
@@ -1135,7 +1231,7 @@
/// <summary>
/// 璇诲彇缃戝叧IP
/// </summary>
- public void SendLinkCommand(string topic,string bodyString)
+ public void SendLinkCommand(string topic, string bodyString)
{
try
{
@@ -1156,19 +1252,15 @@
/// <summary>
/// 鍙戦�乽dp A鍗忚鏁版嵁
/// </summary>
- public void SendLocalHdlLinkData(byte[] sendBytes,string id, int resend = 3)
+ public void SendLocalHdlLinkData(byte[] sendBytes, string id, int resend = 3)
{
packet = new Packet(sendBytes, new System.Net.IPEndPoint(System.Net.IPAddress.Parse(Control.Ins.reportIp), 8585));
- packet.HaveSendCount = 3 - resend;//閲嶅彂娆℃暟
+ packet.HaveSendCount = 3 - resend;
sendFlag = id;
System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(managerSendCount));
thread.IsBackground = true;
thread.Start(packet);
- //if (isWait)
- //{
- // wait();
- //}
- MainPage.Log($"鍙戦�丠dl-Link鏁版嵁锛孖P:{Control.Ins.reportIp}:8585");
+ //MainPage.Log($"鍙戦�佹暟鎹紝IP:{Control.Ins.reportIp}:8585");
}
}
--
Gitblit v1.8.0