File was renamed from HDL_ON/DriverLayer/Packet.cs |
| | |
| | | using HDL_ON.UI; |
| | | using Shared; |
| | | |
| | | namespace HDL_ON |
| | | namespace HDL_ON.DriverLayer |
| | | { |
| | | /// <summary> |
| | | /// bus控制数据包 |
| | | /// bus数据包 |
| | | /// </summary> |
| | | public class Packet |
| | | { |
| | |
| | | public virtual void Manager() |
| | | { |
| | | try |
| | | { |
| | | //如果当前通讯方式不是本地bus udp则退出 |
| | | if(DriverLayer.Control.ins.communicationMode == DriverLayer.CommunicationMode.local_BusUdp) |
| | | { |
| | | return; |
| | | } |
| | | { |
| | | //对于操作数据库的时间比较长的,可以创建另一个线程处理 |
| | | if (!"HDLMIRACLE".Equals(Encoding.ASCII.GetString(Bytes, 4, 10))) |
| | | { |
| | |
| | | { |
| | | if (updataObj.trait_on_off.value.ToString() == "on") |
| | | { |
| | | if (updataObj.functionType == FunctionType.Fan) |
| | | switch (updataObj.functionType) |
| | | { |
| | | (updataObj as Fan).openLevel = receiveBytes[2]; |
| | | updataObj.lastState = Language.StringByID(StringId.Level) + " : " + receiveBytes[2]; |
| | | } |
| | | else |
| | | { |
| | | (updataObj as Light).brightness = receiveBytes[2]; |
| | | updataObj.lastState = Language.StringByID(StringId.Brightness) + " : " + receiveBytes[2] + "%"; |
| | | case FunctionType.Fan: |
| | | (updataObj as Fan).openLevel = receiveBytes[2]; |
| | | updataObj.lastState = Language.StringByID(StringId.Level) + " : " + receiveBytes[2]; |
| | | break; |
| | | case FunctionType.Relay: |
| | | (updataObj as Light).brightness = receiveBytes[2]; |
| | | updataObj.lastState = Language.StringByID(StringId.Brightness) + " : " + receiveBytes[2] + "%"; |
| | | break; |
| | | //case FunctionType.Socket: |
| | | // (updataObj as SwitchSocket). |
| | | } |
| | | } |
| | | HomePage.UpdataFunctionStates(updataObj); |
| | |
| | | } |
| | | } |
| | | break; |
| | | case Command.ReadGatewayACK: |
| | | 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 DEBUG |
| | | DB_ResidenceData.residenceData.residenceGatewayMAC = "4E47323347591243"; |
| | | #endif |
| | | if (DB_ResidenceData.residenceData.residenceGatewayMAC == mac) |
| | | { |
| | | DriverLayer.Control.Ins.GatewayOnline = true; |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | |
| | | MainPage.Log($"Bus Rev Erorr : {ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// byte转16进制字符串 |
| | | /// </summary> |
| | | /// <param name="b"></param> |
| | | /// <returns></returns> |
| | | string ByteToHex16(byte b) |
| | | { |
| | | string s = Convert.ToString(b, 16).ToUpper(); |
| | | if (s.Length <= 1) |
| | | { |
| | | return "0" + s; |
| | | } |
| | | return s; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 处理接收回来的数据 |
| | |
| | | receiveFlag += string.Format("{0},{1}", usefulBytes[0], usefulBytes[1]); |
| | | break; |
| | | case Command.ReadRemark: |
| | | DriverLayer.Control.ins.myUdp.ReceiveReadRemark(usefulBytes); |
| | | DriverLayer.Control.Ins.myUdp.ReceiveReadRemark(usefulBytes); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | DriverLayer.Control.ins.myUdp.ReceiveRepeatManager(receiveFlag); |
| | | DriverLayer.Control.Ins.myUdp.ReceiveRepeatManager(receiveFlag); |
| | | } |
| | | catch (Exception ex) |
| | | { |