Ejemplo n.º 1
0
 public override LaserBaseResponse Decode(OriginalBytes obytes)
 {
     base.Decode(obytes);
     //cc*128 + dd = T 红光激光器电流上限数字量 (data) T = (data / 4096) * 2500 (MA)
     this.Current = (obytes.Data[3] * 128 + obytes.Data[4]) * 100 / Program.SysConfig.LaserConfig.COF;
     return(this);
 }
Ejemplo n.º 2
0
        public override MotorBaseResponse Decode(OriginalBytes obytes)
        {
            byte             commandCode    = obytes.Data[6];
            byte             additionalCode = obytes.Data[7];
            MotorC64Response m64r           = new MotorC64Response(commandCode, additionalCode);

            if (m64r.AdditionCode == 0xAA)
            {
                m64r.CommandCode  = obytes.Data[6];
                m64r.AdditionCode = obytes.Data[7];
                Array.Copy(obytes.Data, 8, m64r.CodeArea.DataLength, 0, 2);
                m64r.CodeArea.Data = new byte[m64r.CodeArea.Length];
                Array.Copy(obytes.Data, 10, m64r.CodeArea.Data, 0, m64r.CodeArea.Length);
                Array.Copy(obytes.Data, 10 + m64r.CodeArea.Length, m64r.CodeArea.CRC16Code, 0, 2);
                m64r.Motor1Config = m64r.CodeArea.Data[0];
                m64r.Motor2Config = m64r.CodeArea.Data[1];
            }
            else if (m64r.AdditionCode == 0x99)
            {
                //写回应
                m64r.ResponseCode = m64r.CodeArea.Data[0];
            }
            m64r.BasePackage = new CIIBasePackage(m64r.CodeArea, false);
            return(m64r);
        }
Ejemplo n.º 3
0
 public override List<BaseResponse> Decode(BasePackage bp, OriginalBytes obytes)
 {
     Cabinet cabinet = SpringHelper.GetObject<Cabinet>("cabinet");
     if (bp.AppData.Length == 48)//应用数据(48)
     {
         List<BaseResponse> list = new List<BaseResponse>();
         for (byte rackNo = 2; rackNo <= 5; rackNo++)//除系统机笼
         {
             for (byte slotNo = 3; slotNo <= 14; slotNo++)
             {
                 BoardStatusResponse boardStatusResponse = new BoardStatusResponse();
                 boardStatusResponse.CommunicatinBoard = cabinet.GetCommunicationBoard(bp.RemoteIpEndPoint);
                 boardStatusResponse.DtTime = DateTime.Now;
                 boardStatusResponse.OriginalBytes = obytes;
                 byte[] eqid = new byte[] { 0x05, rackNo, slotNo, 0xFF, 0xFF };
                 Board b = cabinet.FindEq(eqid) as Board;
                 if (b != null)
                 {
                     boardStatusResponse.Board = b;
                     boardStatusResponse.ErrorCode = bp.AppData[(rackNo - 2) * 12 + (slotNo - 3)];
                     list.Add(boardStatusResponse);
                 }
             }
         }
         return list;
     }
     return null;
 }
Ejemplo n.º 4
0
        public override LaserBaseResponse Decode(OriginalBytes obytes)
        {
            base.Decode(obytes);

            //cc*128 + dd = T 电流数字量 (data) T = (data / 4096) * 2500 (MA)
            this.Current = ((obytes.Data[3] * 128 + obytes.Data[4]) / 4096d) * 2500;
            return(this);
        }
Ejemplo n.º 5
0
 public override LaserBaseResponse Decode(OriginalBytes obytes)
 {
     base.Decode(obytes);
     //cc*128 + dd = T 红光激光器电流设定值系数
     this.COF = obytes.Data[3] * 128 + obytes.Data[4];
     Program.SysConfig.LaserConfig.COF = this.COF;
     return(this);
 }
Ejemplo n.º 6
0
 public void AddFieldBytes(FieldBytes fieldBytes)
 {
     if (OriginalBytes == null)
     {
         OriginalBytes = new List <FieldBytes>();
     }
     OriginalBytes.Add(fieldBytes);
 }
Ejemplo n.º 7
0
 public override LaserBaseResponse Decode(OriginalBytes obytes)
 {
     base.Decode(obytes);
     //aa*128 + bb 脉冲宽度 T = data * 10 (单位ns)
     this.PulseWidth = (obytes.Data[1] * 128 + obytes.Data[2]) * 10;
     //cc*128 + dd 重复频率 T = data * 0.1 (单位KHZ)
     //c05Response.RepeatFrequency = (obytes.Data[3] * 128 + obytes.Data[4]) * 0.1;
     return(this);
 }
Ejemplo n.º 8
0
 public override LaserBaseResponse Decode(OriginalBytes obytes)
 {
     base.Decode(obytes);
     this.DtTime        = DateTime.Now;
     this.OriginalBytes = obytes;
     //aa*128 + bb = T 温度数字量 (data) T = data / 81.72 (℃)
     this.Temperature = (obytes.Data[1] * 128 + obytes.Data[2]) / 81.72;
     return(this);
 }
Ejemplo n.º 9
0
 public override LaserBaseResponse Decode(OriginalBytes obytes)
 {
     base.Decode(obytes);
     //aa*128 + bb 最小脉冲宽度 T = data(单位ns)
     this.MinimumPulseWidth = obytes.Data[1] * 128 + obytes.Data[2];
     //cc*128 + dd 最大脉冲宽度 T = data(单位ns)
     this.MaxmumPulseWidth = obytes.Data[3] * 128 + obytes.Data[4];
     return(this);
 }
Ejemplo n.º 10
0
 public override LaserBaseResponse Decode(OriginalBytes obytes)
 {
     base.Decode(obytes);
     //aa*128 + bb 最小脉冲宽度 T = data * 0.1 (单位 KHZ)
     this.MinimumRepeatFrequency = (obytes.Data[1] * 128 + obytes.Data[2]) * 0.1;
     //cc*128 + dd 最大脉冲宽度 T = data * 0.1 (单位 KHZ)
     this.MaxmumRepeatFrequency = (obytes.Data[3] * 128 + obytes.Data[4]) * 0.1;
     return(this);
 }
Ejemplo n.º 11
0
        public override LaserBaseResponse Decode(OriginalBytes obytes)
        {
            base.Decode(obytes);

            this.SN0    = obytes.Data[1];
            this.SN1    = obytes.Data[2];
            this.SN2    = obytes.Data[3];
            this.SN3    = obytes.Data[4];
            this.Serial = string.Format("{0}{1}{2}{3}", GetSN0String(this.SN0), this.SN1, this.SN2, this.SN3);
            return(this);
        }
Ejemplo n.º 12
0
        public override List <LaserBaseResponse> Decode(LaserBasePackage bp, OriginalBytes obytes)
        {
            base.Decode(bp, obytes);

            LaserC08Response c08Response = new LaserC08Response();

            c08Response.DtTime        = DateTime.Now;
            c08Response.OriginalBytes = obytes;
            //cc*128 + dd = T 红光激光器电流上限数字量 (data) T = (data / 4096) * 2500 (MA)
            c08Response.Current = (obytes.Data[3] * 128 + obytes.Data[4]) * 100 / LD_COF;
            return(CreateOneList(c08Response));
        }
Ejemplo n.º 13
0
        public override List <LaserBaseResponse> Decode(LaserBasePackage bp, OriginalBytes obytes)
        {
            base.Decode(bp, obytes);

            LaserC03Response c03Response = new LaserC03Response();

            c03Response.DtTime        = DateTime.Now;
            c03Response.OriginalBytes = obytes;
            //aa*128 + bb = T 温度数字量 (data) T = data / 81.72 (℃)
            c03Response.Temperature = (obytes.Data[1] * 128 + obytes.Data[2]) / 81.72;
            return(CreateOneList(c03Response));
        }
Ejemplo n.º 14
0
        public override List <LaserBaseResponse> Decode(LaserBasePackage bp, OriginalBytes obytes)
        {
            base.Decode(bp, obytes);

            LaserC0BResponse c0BResponse = new LaserC0BResponse();

            c0BResponse.DtTime        = DateTime.Now;
            c0BResponse.OriginalBytes = obytes;
            //cc*128 + dd = T 红光激光器电流设定值系数
            c0BResponse.COF = obytes.Data[3] * 128 + obytes.Data[4];
            return(CreateOneList(c0BResponse));
        }
Ejemplo n.º 15
0
        public override LaserBaseResponse Decode(OriginalBytes obytes)
        {
            base.Decode(obytes);

            this.DtTime        = DateTime.Now;
            this.OriginalBytes = obytes;
            //aa*128 + bb
            this.Flag = obytes.Data[1] * 128 + obytes.Data[2];
            //cc*128 + dd = T 设备温度 = (T / 4096 *2500) / 10 (℃)
            this.Temperature = (((obytes.Data[3] * 128 + obytes.Data[4]) / 4096d) * 2500) / 10;
            return(this);
        }
Ejemplo n.º 16
0
        public override LaserBaseResponse Decode(OriginalBytes obytes)
        {
            base.Decode(obytes);

            this.DtTime        = DateTime.Now;
            this.OriginalBytes = obytes;
            this.VersionNumber = obytes.Data[1];
            this.Hour          = obytes.Data[2];
            this.Month         = obytes.Data[3];
            this.Second        = obytes.Data[4];

            return(this);
        }
Ejemplo n.º 17
0
        public override List <LaserBaseResponse> Decode(LaserBasePackage bp, OriginalBytes obytes)
        {
            base.Decode(bp, obytes);

            LaserC07Response c07Response = new LaserC07Response();

            c07Response.DtTime        = DateTime.Now;
            c07Response.OriginalBytes = obytes;
            //aa*128 + bb 最小脉冲宽度 T = data * 0.1 (单位 KHZ)
            c07Response.MinimumRepeatFrequency = (obytes.Data[1] * 128 + obytes.Data[2]) * 0.1;
            //cc*128 + dd 最大脉冲宽度 T = data * 0.1 (单位 KHZ)
            c07Response.MaxmumRepeatFrequency = (obytes.Data[3] * 128 + obytes.Data[4]) * 0.1;
            return(CreateOneList(c07Response));
        }
Ejemplo n.º 18
0
        public override List <LaserBaseResponse> Decode(LaserBasePackage bp, OriginalBytes obytes)
        {
            base.Decode(bp, obytes);

            LaserC06Response c06Response = new LaserC06Response();

            c06Response.DtTime        = DateTime.Now;
            c06Response.OriginalBytes = obytes;
            //aa*128 + bb 最小脉冲宽度 T = data * 10 (单位ns)
            c06Response.MinimumPulseWidth = (obytes.Data[1] * 128 + obytes.Data[2]) * 10;
            //cc*128 + dd 最大脉冲宽度 T = data * 10 (单位ns)
            c06Response.MaxmumPulseWidth = (obytes.Data[3] * 128 + obytes.Data[4]) * 10;
            return(CreateOneList(c06Response));
        }
Ejemplo n.º 19
0
        public override List <LaserBaseResponse> Decode(LaserBasePackage bp, OriginalBytes obytes)
        {
            base.Decode(bp, obytes);

            LaserC01Response c01Response = new LaserC01Response();

            c01Response.DtTime        = DateTime.Now;
            c01Response.OriginalBytes = obytes;
            //aa*128 + bb
            c01Response.Flag = obytes.Data[1] * 128 + obytes.Data[2];
            //cc*128 + dd = T 设备温度 = (T / 4096 *2500) / 10 (℃)
            c01Response.Temperature = ((obytes.Data[3] * 128 + obytes.Data[4]) / 4096 * 2500) / 10;
            return(CreateOneList(c01Response));
        }
Ejemplo n.º 20
0
        public override List <LaserBaseResponse> Decode(LaserBasePackage bp, OriginalBytes obytes)
        {
            base.Decode(bp, obytes);

            LaserC05Response c05Response = new LaserC05Response();

            c05Response.DtTime        = DateTime.Now;
            c05Response.OriginalBytes = obytes;
            //aa*128 + bb 脉冲宽度 T = data * 10 (单位ns)
            c05Response.PulseWidth = (obytes.Data[1] * 128 + obytes.Data[2]) * 10;
            //cc*128 + dd 重复频率 T = data * 0.1 (单位KHZ)
            c05Response.RepeatFrequency = (obytes.Data[3] * 128 + obytes.Data[4]) * 0.1;
            return(CreateOneList(c05Response));
        }
Ejemplo n.º 21
0
        public override List <LaserBaseResponse> Decode(LaserBasePackage bp, OriginalBytes obytes)
        {
            base.Decode(bp, obytes);

            LaserC00Response c00Response = new LaserC00Response();

            c00Response.DtTime        = DateTime.Now;
            c00Response.OriginalBytes = obytes;
            c00Response.VersionNumber = obytes.Data[1];
            c00Response.Hour          = obytes.Data[2];
            c00Response.Month         = obytes.Data[3];
            c00Response.Second        = obytes.Data[4];

            return(CreateOneList(c00Response));
        }
Ejemplo n.º 22
0
 public override List <LaserBaseResponse> Decode(LaserBasePackage bp, OriginalBytes obytes)
 {
     base.Decode(bp, obytes);
     if (CheckResponse(obytes.Data))
     {
         LaserC74Response c74Response = new LaserC74Response();
         c74Response.DtTime        = DateTime.Now;
         c74Response.OriginalBytes = obytes;
         return(CreateOneList(c74Response));
     }
     else
     {
         return(null);
     }
 }
Ejemplo n.º 23
0
        public override List <LaserBaseResponse> Decode(LaserBasePackage bp, OriginalBytes obytes)
        {
            base.Decode(bp, obytes);

            LaserC0CResponse c0CResponse = new LaserC0CResponse();

            c0CResponse.DtTime        = DateTime.Now;
            c0CResponse.OriginalBytes = obytes;

            c0CResponse.SN0    = obytes.Data[1];
            c0CResponse.SN1    = obytes.Data[2];
            c0CResponse.SN2    = obytes.Data[3];
            c0CResponse.SN3    = obytes.Data[4];
            c0CResponse.Serial = string.Format("{0}{1}{2}{3}", GetSN0String(c0CResponse.SN0), c0CResponse.SN1, c0CResponse.SN2, c0CResponse.SN3);
            return(CreateOneList(c0CResponse));
        }
        public override string ToString()
        {
            var offset        = string.Format("{0:X4}", Offset);
            var originalBytes = BitConverter.ToString(OriginalBytes.ToArray()).PadRight(12);
            var instruction   = OpCode.Name.ToLowerInvariant();
            var operands      = string.Join(", ", Operands);

            if (operands != string.Empty)
            {
                operands = $" {operands}";
            }
            var instructionWithOperands = $"{instruction}{operands}".PadRight(22);
            var comment = $"; {OpCode.Comment}";

            return($"{offset}:\t{originalBytes}\t{instructionWithOperands}{comment}");
        }
Ejemplo n.º 25
0
        public override MotorBaseResponse Decode(OriginalBytes obytes)
        {
            if (obytes.Data.Length != 164)
            {
                return(null);
            }
            byte             commandCode    = obytes.Data[6];
            byte             additionalCode = obytes.Data[7];
            MotorC40Response m40r           = new MotorC40Response(commandCode, additionalCode);

            if (m40r.AdditionCode == 0xAA)
            {
                //读回应
                m40r.CommandCode  = obytes.Data[6];
                m40r.AdditionCode = obytes.Data[7];
                Array.Copy(obytes.Data, 8, m40r.CodeArea.DataLength, 0, 2);
                m40r.CodeArea.Data = new byte[m40r.CodeArea.Length];
                Array.Copy(obytes.Data, 10, m40r.CodeArea.Data, 0, m40r.CodeArea.Length);
                Array.Copy(obytes.Data, 10 + m40r.CodeArea.Length, m40r.CodeArea.CRC16Code, 0, 2);

                m40r.SystemFlowStatus    = m40r.CodeArea.Data[0];
                m40r.Motor1Switch        = m40r.CodeArea.Data[1];
                m40r.Motor1Status        = m40r.CodeArea.Data[2];
                m40r.Motor1completeSteps = ByteHelper.BytesToInt2(m40r.CodeArea.Data, 3);
                m40r.Motor1Steps         = ByteHelper.BytesToInt2(m40r.CodeArea.Data, 7);

                m40r.Motor2Switch        = m40r.CodeArea.Data[11];
                m40r.Motor2Status        = m40r.CodeArea.Data[12];
                m40r.Motor2completeSteps = ByteHelper.BytesToInt2(m40r.CodeArea.Data, 13);
                m40r.Motor2Steps         = ByteHelper.BytesToInt2(m40r.CodeArea.Data, 17);

                m40r.Voltage1    = ByteHelper.BytesToInt2(m40r.CodeArea.Data, 21);
                m40r.Voltage2    = ByteHelper.BytesToInt2(m40r.CodeArea.Data, 25);
                m40r.Temperature = ByteHelper.BytesToInt2(m40r.CodeArea.Data, 29);
                m40r.M1V1        = ByteHelper.BytesToInt2(m40r.CodeArea.Data, 33);
                m40r.M1V2        = ByteHelper.BytesToInt2(m40r.CodeArea.Data, 37);
                m40r.M2V1        = ByteHelper.BytesToInt2(m40r.CodeArea.Data, 41);
                m40r.M2V2        = ByteHelper.BytesToInt2(m40r.CodeArea.Data, 45);

                Array.Copy(m40r.CodeArea.Data, 100, m40r.ErrorAlarmCodes, 0, 50);
            }

            m40r.BasePackage = new CIIBasePackage(m40r.CodeArea, false);
            return(m40r);
        }
Ejemplo n.º 26
0
        public override MotorBaseResponse Decode(OriginalBytes obytes)
        {
            byte             commandCode    = obytes.Data[6];
            byte             additionalCode = obytes.Data[7];
            MotorC50Response m50r           = new MotorC50Response(commandCode, additionalCode);

            if (m50r.AdditionCode == 0xAA)
            {
                //读回应
                m50r.CommandCode  = obytes.Data[6];
                m50r.AdditionCode = obytes.Data[7];
                Array.Copy(obytes.Data, 8, m50r.CodeArea.DataLength, 0, 2);
                m50r.CodeArea.Data = new byte[m50r.CodeArea.Length];
                Array.Copy(obytes.Data, 10, m50r.CodeArea.Data, 0, m50r.CodeArea.Length);
                Array.Copy(obytes.Data, 10 + m50r.CodeArea.Length, m50r.CodeArea.CRC16Code, 0, 2);
                m50r.Selection = m50r.CodeArea.Data[0];
                switch (Selection)
                {
                case 0xA0:
                    m50r.Frequency = ByteHelper.BytesToInt2(m50r.CodeArea.Data, 1);
                    m50r.MaxPulses = ByteHelper.BytesToInt2(m50r.CodeArea.Data, 5);
                    break;

                case 0xA1:
                    m50r.Frequency = ByteHelper.BytesToInt2(m50r.CodeArea.Data, 1);
                    break;

                case 0xA2:
                    m50r.MaxPulses = ByteHelper.BytesToInt2(m50r.CodeArea.Data, 1);
                    break;
                }
            }
            else if (m50r.AdditionCode == 0x99)
            {
                //写回应
                m50r.ResponseCode = m50r.CodeArea.Data[0];
            }
            m50r.BasePackage = new CIIBasePackage(m50r.CodeArea, false);
            return(m50r);
        }
Ejemplo n.º 27
0
 public override LaserBaseResponse Decode(OriginalBytes obytes)
 {
     base.Decode(obytes);
     return(this);
 }
Ejemplo n.º 28
0
        public override MotorBaseResponse Decode(OriginalBytes obytes)
        {
            byte             commandCode    = obytes.Data[6];
            byte             additionalCode = obytes.Data[7];
            MotorC60Response m60r           = new MotorC60Response(commandCode, additionalCode);

            if (m60r.AdditionCode == 0xAA)
            {
                //读回应
                m60r.ControlSelection = obytes.Data[6];
                m60r.AdditionCode     = obytes.Data[7];
                Array.Copy(obytes.Data, 8, m60r.CodeArea.DataLength, 0, 2);
                m60r.CodeArea.Data = new byte[m60r.CodeArea.Length];
                Array.Copy(obytes.Data, 10, m60r.CodeArea.Data, 0, m60r.CodeArea.Length);
                Array.Copy(obytes.Data, 10 + m60r.CodeArea.Length, m60r.CodeArea.CRC16Code, 0, 2);
                switch (controlSelection)
                {
                case 0x00:
                    m60r.ControlMode61 = m60r.CodeArea.Data[0];
                    m60r.Direction61   = m60r.CodeArea.Data[1];
                    m60r.TotalSteps61  = ByteHelper.BytesToInt2(m60r.CodeArea.Data, 2);

                    m60r.ControlMode62 = m60r.CodeArea.Data[6];
                    m60r.Direction62   = m60r.CodeArea.Data[7];
                    m60r.TotalSteps62  = ByteHelper.BytesToInt2(m60r.CodeArea.Data, 8);

                    m60r.ControlModeA1 = m60r.CodeArea.Data[12];
                    m60r.DirectionA1   = m60r.CodeArea.Data[13];
                    m60r.TotalStepsA1  = ByteHelper.BytesToInt2(m60r.CodeArea.Data, 14);

                    m60r.ControlModeA2 = m60r.CodeArea.Data[18];
                    m60r.DirectionA2   = m60r.CodeArea.Data[19];
                    m60r.TotalStepsA2  = ByteHelper.BytesToInt2(m60r.CodeArea.Data, 20);
                    break;

                case 0x60:
                    m60r.ControlMode61 = m60r.CodeArea.Data[0];
                    m60r.Direction61   = m60r.CodeArea.Data[1];
                    m60r.TotalSteps61  = ByteHelper.BytesToInt2(m60r.CodeArea.Data, 2);

                    m60r.ControlMode62 = m60r.CodeArea.Data[6];
                    m60r.Direction62   = m60r.CodeArea.Data[7];
                    m60r.TotalSteps62  = ByteHelper.BytesToInt2(m60r.CodeArea.Data, 8);
                    break;

                case 0x61:
                    m60r.ControlMode61 = m60r.CodeArea.Data[0];
                    m60r.Direction61   = m60r.CodeArea.Data[1];
                    m60r.TotalSteps61  = ByteHelper.BytesToInt2(m60r.CodeArea.Data, 2);
                    break;

                case 0x62:
                    m60r.ControlMode62 = m60r.CodeArea.Data[6];
                    m60r.Direction62   = m60r.CodeArea.Data[7];
                    m60r.TotalSteps62  = ByteHelper.BytesToInt2(m60r.CodeArea.Data, 8);
                    break;

                case 0xA0:
                    m60r.ControlModeA1 = m60r.CodeArea.Data[12];
                    m60r.DirectionA1   = m60r.CodeArea.Data[13];
                    m60r.TotalStepsA1  = ByteHelper.BytesToInt2(m60r.CodeArea.Data, 14);

                    m60r.ControlModeA2 = m60r.CodeArea.Data[18];
                    m60r.DirectionA2   = m60r.CodeArea.Data[19];
                    m60r.TotalStepsA2  = ByteHelper.BytesToInt2(m60r.CodeArea.Data, 20);
                    break;

                case 0xA1:
                    m60r.ControlModeA1 = m60r.CodeArea.Data[12];
                    m60r.DirectionA1   = m60r.CodeArea.Data[13];
                    m60r.TotalStepsA1  = ByteHelper.BytesToInt2(m60r.CodeArea.Data, 14);
                    break;

                case 0xA2:
                    m60r.ControlModeA2 = m60r.CodeArea.Data[18];
                    m60r.DirectionA2   = m60r.CodeArea.Data[19];
                    m60r.TotalStepsA2  = ByteHelper.BytesToInt2(m60r.CodeArea.Data, 20);
                    break;
                }
            }
            else if (m60r.AdditionCode == 0x99)
            {
                //写回应
                m60r.ResponseCode = m60r.CodeArea.Data[0];
            }
            m60r.BasePackage = new CIIBasePackage(m60r.CodeArea, false);
            return(m60r);
        }
Ejemplo n.º 29
0
 public virtual List<BaseResponse> Decode(BasePackage bp, OriginalBytes obytes)
 {
     CycleNo = bp.CycleNo;
     return null;
 }
Ejemplo n.º 30
0
        public override bool TryApplyPatch(out string failureReason)
        {
            string fileName;

            if (GameFile == GameFile.PakFile)
            {
                fileName = Chunk + ".pak";
            }
            else
            {
                fileName = GameFile.GetFileName();
            }

            string path = Directory.GetFiles(GameDirectory, fileName, SearchOption.AllDirectories).FirstOrDefault();

            if (path == null)
            {
                failureReason = $"Can't find '{fileName}'";
                return(false);
            }

            string originalBytesString = OriginalBytes.Replace("0x", "").Replace(" ", "").Replace("-", "");
            string newBytesString      = NewBytes.Replace("0x", "").Replace(" ", "").Replace("-", "");

            if (originalBytesString.Length % 2 != 0 || newBytesString.Length % 2 != 0)
            {
                failureReason = "String of bytes does not have the correct length";
                return(false);
            }

            byte[] originalBytes = originalBytesString.ConvertHexStringToBytes();
            byte[] newBytes      = newBytesString.ConvertHexStringToBytes();

            using (var fs = File.Open(path, FileMode.Open))
            {
                if (fs.Length < Offset)
                {
                    failureReason = "Invalid offset";
                    return(false);
                }
                else
                {
                    fs.Seek(Offset, SeekOrigin);

                    // Verify original bytes to make sure we're in the right place.
                    for (int i = 0; i < originalBytes.Length; i++)
                    {
                        if (originalBytes[i] != fs.ReadByte())
                        {
                            failureReason = $"Byte at offset {Offset} in '{fileName}' is different than expected";
                            return(false);
                        }
                    }

                    fs.Seek(Offset, SeekOrigin);
                    fs.Write(newBytes);
                }
            }

            failureReason = "";
            return(true);
        }
Ejemplo n.º 31
0
 public override List<BaseResponse> Decode(BasePackage bp, OriginalBytes obytes)
 {
     base.Decode(bp, obytes);
     Cabinet cabinet = SpringHelper.GetObject<Cabinet>("cabinet");
     List<BaseResponse> list = new List<BaseResponse>();
     //应用区数据格式:[EquipId(COMPONENT)(5)+testtimes(4)+误码次数(4)+丢包次数(4)+通信终端次数(4)]*
     if (bp.AppData.Length % 21 == 0)
     {
         for (int i = 0; i < bp.AppData.Length / 21; i++)
         {
             byte[] eqid = new byte[] { bp.AppData[i * 21 + 0], bp.AppData[i * 21 + 1], bp.AppData[i * 21 + 2], bp.AppData[i * 21 + 3], bp.AppData[i * 21 + 4] };
             int allTimes = (int)Util.B2LInt32(new byte[] { bp.AppData[i * 21 + 5], bp.AppData[i * 21 + 6], bp.AppData[i * 21 + 7], bp.AppData[i * 21 + 8] });
             int errorPackageTimes = (int)Util.B2LInt32(new byte[] { bp.AppData[i * 21 + 9], bp.AppData[i * 21 + 10], bp.AppData[i * 21 + 11], bp.AppData[i * 21 + 12] });
             int lostPackageTimes = (int)Util.B2LInt32(new byte[] { bp.AppData[i * 21 + 13], bp.AppData[i * 21 + 14], bp.AppData[i * 21 + 15], bp.AppData[i * 21 + 16] });
             int interruptTimes = (int)Util.B2LInt32(new byte[] { bp.AppData[i * 21 + 17], bp.AppData[i * 21 + 18], bp.AppData[i * 21 + 19], bp.AppData[i * 21 + 20] });
             AbstractEq eq = cabinet.FindEq(eqid);
             if (eq != null && eq is Component)
             {
                 ComponentTestResponse cr = new ComponentTestResponse();
                 cr.CommunicatinBoard = cabinet.GetCommunicationBoard(bp.RemoteIpEndPoint);
                 cr.DtTime = DateTime.Now;
                 cr.OriginalBytes = obytes;
                 cr.Component = eq as Component;
                 cr.Component.AllTestTimes = allTimes;
                 cr.Component.ErrorPackageTimes = errorPackageTimes;
                 cr.Component.LostPackageTimes = lostPackageTimes;
                 cr.Component.InterruptTimes = interruptTimes;
                 list.Add(cr);
             }
         }
     }
     return list;
 }
Ejemplo n.º 32
0
 /// <summary>
 /// 自己生成的,下位机不会送达,所以没有解码方法
 /// </summary>
 /// <param name="bp"></param>
 /// <returns></returns>
 public override List<BaseResponse> Decode(BasePackage bp, OriginalBytes obytes)
 {
     return null;
 }
Ejemplo n.º 33
0
 /// <summary>
 /// [EquipId(BOARD)(5)+errorCode(1)]
 /// </summary>
 /// <param name="bp"></param>
 /// <param name="obytes"></param>
 /// <returns></returns>
 public override List<BaseResponse> Decode(BasePackage bp, OriginalBytes obytes)
 {
     Cabinet cabinet = SpringHelper.GetObject<Cabinet>("cabinet");
     if (bp.AppData.Length >= 6)
     {
         VPSErrorInfoResponse tr = new VPSErrorInfoResponse();
         tr.CommunicatinBoard = cabinet.GetCommunicationBoard(bp.RemoteIpEndPoint);
         tr.DtTime = DateTime.Now;
         tr.OriginalBytes = obytes;
         byte[] eqid = new byte[] { bp.AppData[0], bp.AppData[1], bp.AppData[2], bp.AppData[3], bp.AppData[4] };
         tr.ErrorBoard = cabinet.FindEq(eqid) as Board;
         tr.ErrorCode = bp.AppData[5];
         return CreateOneList(tr);
     }
     return null;
 }
Ejemplo n.º 34
0
        public int smallCycleBoard; //小周期号

        #endregion Fields

        #region Methods

        public override List<BaseResponse> Decode(BasePackage bp, OriginalBytes obytes)
        {
            base.Decode(bp, obytes);
            Cabinet cabinet = SpringHelper.GetObject<Cabinet>("cabinet");
            List<BaseResponse> list = new List<BaseResponse>();
            Board communicatinBoard = cabinet.GetCommunicationBoard(bp.RemoteIpEndPoint);
            //应用区数据格式:rack(1)+slot(1)+boardtype(1)+smallcycle(1)+lightport(2) +[采集到的码字(4)*16] +[错误次数(4)*16]
            if (bp.AppData.Length == 6 + 4 * 16 + 4 * 16)
            {
                byte rackNo = bp.AppData[0];
                byte slotNo = bp.AppData[1];
                byte boardType = bp.AppData[2];
                byte smallCycle = bp.AppData[3];
                UInt32[] realCodes = new UInt32[16];
                Int32[] errorTimes = new Int32[16];
                for (int i = 0; i < 16; i++)
                {
                    realCodes[i] = System.BitConverter.ToUInt32(bp.AppData, 6 + i * 4);
                    errorTimes[i] = System.BitConverter.ToInt32(bp.AppData, 6 + 64 + i * 4);
                }

                int a = (int)(((bp.AppData[4] << 8) & 0xFF00) | (bp.AppData[5] & 0x00FF));
                byte[] eqId = new byte[] { 0x05, rackNo, slotNo, 0xFF, 0xFF };
                //byte[] eqId = GetEqId(rackNo, slotNo);
                for (int i = 0; i < 16; ++i)
                {
                    if (((a >> i) & 0x01) == 0x01)//error
                    {
                        //例如 02 04 02 05 01 00
                        //表示 1 机笼 4槽道 VOB16板卡 01 00 ->0000 0001 0000 0000 : 第9个灯位有问题
                        int posk = (rackNo - 2) * 12 * 16 + (slotNo - 2) * 16 + i;
                        if (boardType == 0x01)//VIB
                        {
                            VIBTestResponse vibR = new VIBTestResponse();
                            vibR.CommunicatinBoard = communicatinBoard;
                            vibR.DtTime = DateTime.Now;
                            vibR.OriginalBytes = obytes;
                            vibR.Board = cabinet.FindEq(eqId) as Board;
                            vibR.Board.BoardType = "VIB";
                            vibR.LightPos = i + 1;
                            vibR.ExpectedCode = Util.vib_true[posk];
                            vibR.RealCode = realCodes[i];
                            vibR.ErrorTimes = errorTimes[i];
                            int readableSmallCycle = (int)smallCycle + 1;
                            vibR.smallCycleBoard = readableSmallCycle;
                            list.Add(vibR);
                        }
                        else if (boardType == 0x02)//VOB
                        {
                            VOBTestResponse vobR = new VOBTestResponse();
                            vobR.CommunicatinBoard = communicatinBoard;
                            vobR.DtTime = DateTime.Now;
                            vobR.OriginalBytes = obytes;
                            vobR.Board = cabinet.FindEq(eqId) as Board;
                            vobR.Board.BoardType = "VOB";
                            vobR.LightPos = i + 1;
                            vobR.RealCode = realCodes[i];
                            vobR.ErrorTimes = errorTimes[i];

                            byte[] cycleNo = new byte[2];
                            Array.Copy(obytes.Data, 3, cycleNo, 0, 2);//帧协议中周期号四个字节中的低两位作为是否有输出
                            uint value = (uint)(((cycleNo[0] << 8) & 0xFF00) | (cycleNo[1] & 0x00FF));
                            int readableSmallCycle = (int)smallCycle;
                            vobR.smallCycleBoard = readableSmallCycle;
                            if (((value >> i) & 0x01) == 0x01)//有输出
                            {
                                //VOB板卡第i个灯位错误,且当前灯位亮的状态(有输出)
                                vobR.OutPut = true;
                                vobR.ErrorCode = false;
                                if (readableSmallCycle == 2)
                                {
                                    vobR.ExpectedCode = Util.vob_ock_even[posk];
                                    vobR.OCK = true;
                                }
                                else if (readableSmallCycle == 0 || readableSmallCycle == 4 ||
                                    readableSmallCycle == 6 || readableSmallCycle == 8)
                                {
                                    vobR.ExpectedCode = Util.vob_true_even;
                                    vobR.OCK = false;
                                }
                                else if (readableSmallCycle == 1)
                                {
                                    vobR.ExpectedCode = Util.vob_ock_odd[posk];
                                    vobR.OCK = true;
                                }
                                else if (readableSmallCycle == 3 || readableSmallCycle == 5 ||
                                    readableSmallCycle == 7 || readableSmallCycle == 9)
                                {
                                    vobR.ExpectedCode = Util.vob_true_odd;
                                    vobR.OCK = false;
                                }
                            }
                            else
                            {
                                //当前的灯位灭的状态(无输出)
                                vobR.OutPut = false;
                                vobR.ErrorCode = true;
                                if (readableSmallCycle == 0 || readableSmallCycle == 2 ||
                                    readableSmallCycle == 4 || readableSmallCycle == 6 ||
                                    readableSmallCycle == 8)
                                {
                                    vobR.ExpectedCode = Util.vob_ckWord_even[posk];
                                }
                                else if (readableSmallCycle == 1 || readableSmallCycle == 3 ||
                                    readableSmallCycle == 5 || readableSmallCycle == 7 ||
                                    readableSmallCycle == 9)
                                {
                                    vobR.ExpectedCode = Util.vob_ckWord_odd[posk];
                                }
                            }
                            list.Add(vobR);
                        }
                    }
                }
            }
            return list;
        }
Ejemplo n.º 35
0
 //编码工厂
 public void EncodeInternal()
 {
     List<BaseRequest> list = txMsgQueue.PopAll();
     foreach (var br in list)
     {
         BasePackage bp = br.Encode();
         byte[] data = br.GetBigBytes(bp);
         OriginalBytes ob = new OriginalBytes();
         ob.RemoteIpEndPoint = bp.RemoteIpEndPoint;
         ob.Data = frameProtocol.EnPackage(data, bp.CycleNo);
         txQueue.Push(ob);
     }
 }
Ejemplo n.º 36
0
 public override List<BaseResponse> Decode(BasePackage bp, OriginalBytes obytes)
 {
     Cabinet cabinet = SpringHelper.GetObject<Cabinet>("cabinet");
     Board b = cabinet.GetCommunicationBoard(bp.RemoteIpEndPoint);
     if (b != null)
     {
         ShakeResponse sr = new ShakeResponse();
         sr.CommunicatinBoard = b;
         sr.DtTime = DateTime.Now;
         sr.OriginalBytes = obytes;
         return CreateOneList(sr);
     }
     return null;
 }
Ejemplo n.º 37
0
 public override List<BaseResponse> Decode(BasePackage bp, OriginalBytes obytes)
 {
     Cabinet cabinet = SpringHelper.GetObject<Cabinet>("cabinet");
     //应用区数据格式:[EquipId(COMPONENT)(5)]*
     StopFctTestResponse sr = new StopFctTestResponse();
     sr.Components = new List<Component>();
     if (bp.AppData.Length % 5 == 0)
     {
         for (int i = 0; i < bp.AppData.Length / 5; i++)
         {
             byte[] eqid = new byte[] { bp.AppData[i * 5 + 0], bp.AppData[i * 5 + 1], bp.AppData[i * 5 + 2], bp.AppData[i * 5 + 3], bp.AppData[i * 5 + 4] };
             AbstractEq eq = cabinet.FindEq(eqid);
             if (eq is Component)
             {
                 sr.CommunicatinBoard = cabinet.GetCommunicationBoard(bp.RemoteIpEndPoint);
                 sr.DtTime = DateTime.Now;
                 sr.OriginalBytes = obytes;
                 sr.Components.Add(eq as Component);
             }
         }
     }
     return CreateOneList(sr);
 }