| | |
| | | /// <summary> |
| | | /// 发送数据,不需要等待回复 |
| | | /// </summary> |
| | | public void ControlBytesSend(Command command, byte subnetID, byte deviceID, byte[] gatewayBytes, int sendCount = 3) |
| | | public void ControlBytesSend(Command command, byte subnetID, byte deviceID, byte[] gatewayBytes, int sendCount = 3,bool reSend = false) |
| | | { |
| | | #if DEBUG |
| | | string ddd = ""; |
| | | foreach (var bb in gatewayBytes) |
| | | { |
| | | ddd += bb + ","; |
| | | } |
| | | MainPage.Log($"发送bus命令:" + ((int)command).ToString("X").PadLeft(4,'0') + " : 数据:" + ddd); |
| | | #endif |
| | | |
| | | var control = new Control_Udp(); |
| | | control.Send(new Target() |
| | | { |
| | |
| | | SubnetID = subnetID, |
| | | DeviceID = deviceID, |
| | | AddData = gatewayBytes, |
| | | }, sendCount, false); |
| | | }, 3, true); |
| | | //}, sendCount, reSend); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | /// <param name="commandString"></param> |
| | | /// <returns></returns> |
| | | public void WriteBusData(Function function, Dictionary<string, string> commandDictionary) |
| | | public void WriteBusData(Function function, Dictionary<string, string> commandDictionary,bool reSend = false) |
| | | { |
| | | try |
| | | { |
| | |
| | | switch (function.spk) |
| | | { |
| | | case SPK.LightCCT: |
| | | byte b0 = 100;//开关操作依据on_off字段,实际开关值依据brightness,当on_off为打开,brightness不能为0 |
| | | if (function.trait_on_off.curValue.ToString() == "off") |
| | | byte b0 = 100; |
| | | if (commandDictionary.ContainsKey(FunctionAttributeKey.OnOff)) |
| | | { |
| | | b0 = 0; |
| | | if (function.trait_on_off.curValue.ToString() == "off") |
| | | { |
| | | b0 = 0; |
| | | } |
| | | else |
| | | { |
| | | b0 = function.lastBrightness == 0 ? (byte)100 : Convert.ToByte(function.lastBrightness); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | b0 = Convert.ToByte( function.GetAttrState(FunctionAttributeKey.Brightness)) == 0 ? (byte)100 : Convert.ToByte(function.GetAttrState(FunctionAttributeKey.Brightness)); |
| | | b0 = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.Brightness)); |
| | | } |
| | | var bytes0 = new byte[] { function.bus.LoopId, |
| | | b0, |
| | |
| | | ControlBytesSend(Command.SetLogicLoopColor, subnetId, deviceId, bytes0, 1); |
| | | break; |
| | | case SPK.LightRGB: |
| | | byte b = 100;//开关操作依据on_off字段,实际开关值依据brightness,当on_off为打开,brightness不能为0 |
| | | if (function.trait_on_off.curValue.ToString() == "off") |
| | | byte b = 100; |
| | | if (commandDictionary.ContainsKey(FunctionAttributeKey.OnOff)) |
| | | { |
| | | b = 0; |
| | | } |
| | | else |
| | | { |
| | | byte lightBri1 = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.Brightness)); |
| | | if (lightBri1 == 0) |
| | | if (function.trait_on_off.curValue.ToString() == "off") |
| | | { |
| | | b = 100; |
| | | b = 0; |
| | | } |
| | | else |
| | | { |
| | | b = lightBri1; |
| | | b = function.lastBrightness == 0 ? (byte)100 : Convert.ToByte(function.lastBrightness); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | b = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.Brightness)); |
| | | } |
| | | var tempLight = new Light(); |
| | | var bytes = new byte[] { function.bus.LoopId, |
| | |
| | | break; |
| | | case SPK.LightDimming: |
| | | byte b1 = 100; |
| | | if (function.trait_on_off.curValue.ToString() == "off") |
| | | if (commandDictionary.ContainsKey(FunctionAttributeKey.OnOff)) |
| | | { |
| | | b1 = 0; |
| | | } |
| | | else |
| | | { |
| | | byte lightBri = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.Brightness)); |
| | | if (lightBri == 0) |
| | | if (function.trait_on_off.curValue.ToString() == "off") |
| | | { |
| | | b1 = 100; |
| | | b1 = 0; |
| | | } |
| | | else |
| | | { |
| | | b1 = lightBri; |
| | | b1 = function.lastBrightness == 0 ? (byte)100 : Convert.ToByte(function.lastBrightness); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | b1 = Convert.ToByte(function.GetAttrState(FunctionAttributeKey.Brightness)); |
| | | } |
| | | ControlBytesSend(Command.SetSingleLight, subnetId, deviceId, new byte[] { |
| | | function.bus.LoopId, |
| | |
| | | { |
| | | b1 += (byte)(16 + wm); |
| | | } |
| | | if (commandDictionary.ContainsKey("temp")) |
| | | if (commandDictionary.ContainsKey("set_temp")) |
| | | { |
| | | var dicTempString = ""; |
| | | commandDictionary.TryGetValue("temp", out dicTempString); |
| | | commandDictionary.TryGetValue("set_temp", out dicTempString); |
| | | var dicTemp = Convert.ToByte(dicTempString); |
| | | var mode = function.GetAttrState(FunctionAttributeKey.Mode); |
| | | switch (mode) |
| | |
| | | } |
| | | break; |
| | | case FunctionCategory.AirFresh: |
| | | switch(function.spk) |
| | | { |
| | | case SPK.AirFreshJinmao: |
| | | //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档,2 - 2档,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 湿度设定 % |
| | | //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, |
| | | Convert.ToByte(function.GetAttrState(FunctionAttributeKey.Humidity)), |
| | | indoorTemp_airFrsh, |
| | | indoorHumidity_airFrsh, |
| | | //Convert.ToByte( function.GetAttrState(FunctionAttributeKey.FilterRemain)), |
| | | //function.GetAttrState(FunctionAttributeKey.FilterTimeout) =="true"?1:0, |
| | | 0,0 |
| | | }); |
| | | break; |
| | | } |
| | | break; |
| | | } |
| | | #region 发送命令立即更新UI |
| | |
| | | break; |
| | | } |
| | | ControlBytesSend(Command.ReadDeviceLoopInfo, subnetId, deviceId, new byte[] { 5, sensorType, function.bus.LoopId }); |
| | | break; |
| | | case FunctionCategory.AirFresh: |
| | | switch(function.spk) |
| | | { |
| | | case SPK.AirFreshJinmao: |
| | | ControlBytesSend(Command.FreshAirRead_JinMao, subnetId, deviceId, new byte[] { function.bus.LoopId }); |
| | | break; |
| | | } |
| | | break; |
| | | } |
| | | } |
| | |
| | | |
| | | try |
| | | { |
| | | //MainPage.Log("发送数据:" + SendFlag); |
| | | MainPage.Log("发送数据:" + SendFlag); |
| | | UdpSocket._BusSocket.AsyncBeginSend(packet); |
| | | packet.HaveSendCount--; |
| | | |
| | |
| | | var sendBytes = Control.Ins.ConvertSendBodyData(CommunicationTopic.SearchLoaclGateway, bodyString); |
| | | //组播发送 |
| | | packet = new Packet(sendBytes, new System.Net.IPEndPoint(System.Net.IPAddress.Parse("239.0.168.188"), 8585)); |
| | | packet.HaveSendCount = 4;//ps:没有重发,后期有时间可以增加重发判断 |
| | | packet.HaveSendCount = 4; |
| | | System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(managerSendCount)); |
| | | thread.IsBackground = true; |
| | | thread.Start(packet); |
| | | //wait();不需要等待 |
| | | |
| | | |
| | | |
| | | |
| | | //hjSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); |
| | | //hjSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true); |
| | | //EndPoint ipep = new IPEndPoint(IPAddress.Parse(CsConst.myLocalIP), HDLUDP.UDPPort); |
| | | //hjSocket.Bind(ipep); |
| | | |
| | | |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |