| | |
| | | } |
| | | else |
| | | { |
| | | //对于操作数据库的时间比较长的,可以创建另一个线程处理 |
| | | if (!"HDLMIRACLE".Equals(System.Text.Encoding.ASCII.GetString(Bytes, 4, 10))) |
| | | try |
| | | { |
| | | return; |
| | | } |
| | | |
| | | byte subnetID = this.Bytes[17]; //源子网号 |
| | | byte deviceID = this.Bytes[18]; //源设备号 |
| | | |
| | | //源设备类型 |
| | | int deviceType = this.Bytes[19] * 256 + this.Bytes[20]; |
| | | |
| | | Command command = (Command)(Bytes[21] * 256 + Bytes[22]); //操作码控制命令 |
| | | |
| | | byte targetSubnetID = this.Bytes[23]; |
| | | byte targetDeviceID = this.Bytes[24]; |
| | | |
| | | //不是要接收的指令就返回 |
| | | if (!((targetSubnetID == 252 && targetDeviceID == 252) || (targetSubnetID == 0xff && targetDeviceID == 0xff))) |
| | | { |
| | | return; |
| | | } |
| | | byte[] usefulBytes = null; |
| | | if (this.Bytes[16] == 0xFF) |
| | | { |
| | | usefulBytes = new byte[Bytes.Length - 16 - 11]; |
| | | System.Array.Copy(Bytes, 27, usefulBytes, 0, usefulBytes.Length); |
| | | } |
| | | else |
| | | { |
| | | //有用的附加数据 |
| | | usefulBytes = new byte[this.Bytes[16] - 11]; |
| | | Array.Copy(Bytes, 25, usefulBytes, 0, usefulBytes.Length); |
| | | } |
| | | |
| | | if (ReceiveEvent != null) |
| | | { |
| | | string revIp = $"{Bytes[0]}.{Bytes[1]}.{Bytes[2]}.{Bytes[3]}"; |
| | | if (revIp == "172.16.2.237") |
| | | //对于操作数据库的时间比较长的,可以创建另一个线程处理 |
| | | if (!"HDLMIRACLE".Equals(System.Text.Encoding.ASCII.GetString(Bytes, 4, 10))) |
| | | { |
| | | |
| | | return; |
| | | } |
| | | ReceiveEvent(subnetID, deviceID, command, usefulBytes, revIp); |
| | | } |
| | | Control.controlLostCount = 0; |
| | | |
| | | //if (command == Command.SuperGatewayAgentACK) { |
| | | // SuperGateWay.SendAndReceiveDatas.Recevice (subnetID, deviceID, usefulBytes); |
| | | //} |
| | | if (ReceviceAllDadaAction != null) |
| | | byte subnetID = this.Bytes[17]; //源子网号 |
| | | byte deviceID = this.Bytes[18]; //源设备号 |
| | | |
| | | //源设备类型 |
| | | int deviceType = this.Bytes[19] * 256 + this.Bytes[20]; |
| | | |
| | | Command command = (Command)(Bytes[21] * 256 + Bytes[22]); //操作码控制命令 |
| | | |
| | | byte targetSubnetID = this.Bytes[23]; |
| | | byte targetDeviceID = this.Bytes[24]; |
| | | |
| | | //不是要接收的指令就返回 |
| | | if (!((targetSubnetID == 252 && targetDeviceID == 252) || (targetSubnetID == 0xff && targetDeviceID == 0xff))) |
| | | { |
| | | return; |
| | | } |
| | | byte[] usefulBytes = null; |
| | | if (this.Bytes[16] == 0xFF) |
| | | { |
| | | usefulBytes = new byte[Bytes.Length - 16 - 11]; |
| | | System.Array.Copy(Bytes, 27, usefulBytes, 0, usefulBytes.Length); |
| | | } |
| | | else |
| | | { |
| | | //有用的附加数据 |
| | | usefulBytes = new byte[this.Bytes[16] - 11]; |
| | | Array.Copy(Bytes, 25, usefulBytes, 0, usefulBytes.Length); |
| | | } |
| | | |
| | | if (ReceiveEvent != null) |
| | | { |
| | | string revIp = $"{Bytes[0]}.{Bytes[1]}.{Bytes[2]}.{Bytes[3]}"; |
| | | if (revIp == "172.16.2.237") |
| | | { |
| | | |
| | | } |
| | | ReceiveEvent(subnetID, deviceID, command, usefulBytes, revIp); |
| | | } |
| | | |
| | | //if (command == Command.SuperGatewayAgentACK) { |
| | | // SuperGateWay.SendAndReceiveDatas.Recevice (subnetID, deviceID, usefulBytes); |
| | | //} |
| | | if (ReceviceAllDadaAction != null) |
| | | { |
| | | ReceviceAllDadaAction(subnetID, deviceID, deviceType, command, targetSubnetID, targetDeviceID, usefulBytes, (System.Net.IPEndPoint)RemoteEndPoint); |
| | | } |
| | | //处理是否要重发数据 |
| | | Control.ManagerReceive(subnetID, deviceID, command, targetSubnetID, targetDeviceID, usefulBytes, RemoteEndPoint); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | ReceviceAllDadaAction(subnetID, deviceID, deviceType, command, targetSubnetID, targetDeviceID, usefulBytes, (System.Net.IPEndPoint)RemoteEndPoint); |
| | | MainPage.Log($"packet {ex.Message} "); |
| | | } |
| | | //处理是否要重发数据 |
| | | Control.ManagerReceive(subnetID, deviceID, command, targetSubnetID, targetDeviceID, usefulBytes, RemoteEndPoint); |
| | | |
| | | } |
| | | } |
| | | } |