| | |
| | | //加密检测 |
| | | EncryptionDetection (); |
| | | |
| | | |
| | | //var mes2 = System.Text.Encoding.ASCII.GetString (Bytes, 0, Bytes.Length); |
| | | //Utlis.WriteLine ($"============>GetBytes :{mes2}"); |
| | | |
| | | //对于操作数据库的时间比较长的,可以创建另一个线程处理 |
| | | if (!"HDLMIRACLE".Equals (System.Text.Encoding.ASCII.GetString (Bytes, 4, 10))) { |
| | |
| | | |
| | | byte subnetID = this.Bytes [17]; //源子网号 |
| | | byte deviceID = this.Bytes [18]; //源设备号 |
| | | |
| | | |
| | | //源设备类型 |
| | | int deviceType = this.Bytes [19] * 256 + this.Bytes [20]; |
| | |
| | | |
| | | //不是要接收的指令就返回 |
| | | if (!((targetSubnetID == Global.LocalSubnetID && targetDeviceID == Global.LocalDeviceID) || (targetSubnetID == 0xff && targetDeviceID == 0xff))) { |
| | | return; |
| | | //Utlis.WriteLine ($"============>targetSubnetID return"); |
| | | return; |
| | | } |
| | | byte [] usefulBytes = null; |
| | | if (this.Bytes [16] == 0xFF) { |
| | |
| | | try { |
| | | ReceiveEvent (subnetID, deviceID, command, usefulBytes); |
| | | } catch (Exception ex) { |
| | | Console.WriteLine (ex.Message); |
| | | Utlis.WriteLine (ex.Message); |
| | | } |
| | | } |
| | | |
| | |
| | | if (IsLocal) {//本地通讯 |
| | | |
| | | if (UserConfig.Instance.IsLocalEncrypt) { |
| | | if ("Passord error" == (System.Text.Encoding.ASCII.GetString (Bytes, 14, 13))) { |
| | | //网关返回,加密密码key不对 |
| | | |
| | | return; |
| | | if (Bytes.Length == 28) { |
| | | var mes = System.Text.Encoding.ASCII.GetString (Bytes, 14, 14); |
| | | if ("Password error" == mes) { |
| | | //网关返回,加密密码key不对 |
| | | UserConfig.Instance.EncryptedPasswordCorrect = false; |
| | | return; |
| | | } |
| | | } |
| | | var messageGet = Shared.Securitys.EncryptionService.AesEncryptPayload (Bytes, UserConfig.Instance.LocalEncryptKey); |
| | | var messageGet = Shared.Securitys.EncryptionService.AesDecryptPayload (Bytes, UserConfig.Instance.LocalEncryptKey); |
| | | Bytes = messageGet; |
| | | |
| | | |
| | | } else { |
| | | if ("Locked" == (System.Text.Encoding.ASCII.GetString (Bytes, 14, 6))) { |
| | | //网关已加密,自动切换为加密 |
| | | UserConfig.Instance.IsLocalEncrypt = true; |
| | | if (Bytes.Length == 20) { |
| | | var mes = System.Text.Encoding.ASCII.GetString (Bytes, 14, 6); |
| | | if ("Locked" == mes) { |
| | | //网关已加密,自动切换为加密 |
| | | UserConfig.Instance.IsLocalEncrypt = true; |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |