示例#1
0
        public static byte[] ConvertToTIDIALERRule(byte[] _input, EMessageLengthType _LengthType)
        {
            byte[] numArray;
            if (_LengthType == EMessageLengthType.None)
            {
                numArray = new byte[_input.Length + 3];
                _input.CopyTo((Array)numArray, 1);
            }
            else
            {
                numArray = new byte[_input.Length + 5];
                IsoUltil.IntToMessageLength(_input.Length, _LengthType).CopyTo((Array)numArray, 1);
                _input.CopyTo((Array)numArray, 3);
            }
            byte num = 0;

            numArray[0] = (byte)2;
            numArray[numArray.Length - 2] = (byte)3;
            for (int index = 1; index < numArray.Length - 1; ++index)
            {
                num ^= numArray[index];
            }
            numArray[numArray.Length - 1] = num;
            return(numArray);
        }
示例#2
0
        public static byte[] IntToMessageLength(int _input, EMessageLengthType _type)
        {
            byte[] numArray = new byte[2];
            switch (_type)
            {
            case EMessageLengthType.BCD:
                return(IsoUltil.BinToBcd(_input, 2));

            case EMessageLengthType.HL:
                numArray[0] = (byte)(_input / 256);
                numArray[1] = (byte)(_input % 256);
                break;

            case EMessageLengthType.LH:
                numArray[1] = (byte)(_input / 256);
                numArray[0] = (byte)(_input % 256);
                break;
            }
            return(numArray);
        }
示例#3
0
        public static int MessageLengthToInt(byte[] _input, EMessageLengthType _type)
        {
            int num1 = 0;

            switch (_type)
            {
            case EMessageLengthType.BCD:
                byte num2 = _input[0];
                byte num3 = _input[1];
                num1 = (int)num2 / 16 * 1000 + (int)num2 % 16 * 100 + (int)num3 / 16 * 10 + (int)num3 % 16;
                break;

            case EMessageLengthType.HL:
                num1 = (int)_input[0] * 256 + (int)_input[1];
                break;

            case EMessageLengthType.LH:
                num1 = (int)_input[1] * 256 + (int)_input[0];
                break;
            }
            return(num1);
        }
示例#4
0
        public byte[] Pack(EMessageLengthType lengthtype)
        {
            this.m_PackageSize = lengthtype != EMessageLengthType.None ? (lengthtype != EMessageLengthType.String4 ? 2 : 4) : 0;
            if (this.HasHeader)
            {
                this.m_TPDU.Pack().CopyTo((Array)this.Buffer, this.m_PackageSize);
                this.m_PackageSize += 5;
            }
            if (this.m_LengthInAsc)
            {
                Encoding.Default.GetBytes(this.MessageType.ToString("0000")).CopyTo((Array)this.Buffer, this.m_PackageSize);
                this.m_PackageSize += 4;
            }
            else
            {
                IsoUltil.BinToBcd(this.MessageType, 2).CopyTo((Array)this.Buffer, this.m_PackageSize);
                this.m_PackageSize += 2;
            }
            this.CreateBitmap().CopyTo((Array)this.Buffer, this.m_PackageSize);
            this.m_PackageSize += 8;
            int num1 = 128;

            if (!this.m_BitAttributes[0].IsSet)
            {
                num1 = 64;
            }
            int num2;

            for (int index = 0; index < num1; ++index)
            {
                if (this.m_BitAttributes[index].IsSet)
                {
                    switch (this.m_BitAttributes[index].LengthAttribute)
                    {
                    case BitLength.FIXED:
                        this.m_BitAttributes[index].Data.CopyTo((Array)this.Buffer, this.m_PackageSize);
                        break;

                    case BitLength.LLVAR:
                        if (this.m_LengthInAsc)
                        {
                            Encoding encoding = Encoding.Default;
                            num2 = this.m_BitAttributes[index].Length;
                            string s = num2.ToString("00");
                            encoding.GetBytes(s).CopyTo((Array)this.Buffer, this.m_PackageSize);
                            this.m_PackageSize += 2;
                            this.m_BitAttributes[index].Data.CopyTo((Array)this.Buffer, this.m_PackageSize);
                            break;
                        }
                        IsoUltil.BinToBcd(this.m_BitAttributes[index].Length, 1).CopyTo((Array)this.Buffer, this.m_PackageSize);
                        ++this.m_PackageSize;
                        this.m_BitAttributes[index].Data.CopyTo((Array)this.Buffer, this.m_PackageSize);
                        break;

                    case BitLength.LLLVAR:
                        if (this.m_LengthInAsc)
                        {
                            Encoding encoding = Encoding.Default;
                            num2 = this.m_BitAttributes[index].Length;
                            string s = num2.ToString("000");
                            encoding.GetBytes(s).CopyTo((Array)this.Buffer, this.m_PackageSize);
                            this.m_PackageSize += 3;
                            this.m_BitAttributes[index].Data.CopyTo((Array)this.Buffer, this.m_PackageSize);
                            break;
                        }
                        IsoUltil.BinToBcd(this.m_BitAttributes[index].Length, 2).CopyTo((Array)this.Buffer, this.m_PackageSize);
                        this.m_PackageSize += 2;
                        this.m_BitAttributes[index].Data.CopyTo((Array)this.Buffer, this.m_PackageSize);
                        break;
                    }
                    switch (this.m_BitAttributes[index].TypeAtribute)
                    {
                    case BitType.AN:
                    case BitType.ANS:
                        this.m_PackageSize += this.m_BitAttributes[index].Length;
                        break;

                    case BitType.BCD:
                        this.m_PackageSize += (this.m_BitAttributes[index].Length + 1) / 2;
                        break;

                    case BitType.BINARY:
                        this.m_PackageSize += this.m_BitAttributes[index].Length;
                        break;
                    }
                }
            }
            if (lengthtype == EMessageLengthType.String4)
            {
                Encoding encoding = Encoding.Default;
                num2 = this.m_PackageSize - 4;
                string s = num2.ToString("0000");
                encoding.GetBytes(s).CopyTo((Array)this.Buffer, 0);
            }
            else if (lengthtype != EMessageLengthType.None)
            {
                IsoUltil.IntToMessageLength(this.m_PackageSize - 2, lengthtype).CopyTo((Array)this.Buffer, 0);
            }
            byte[] numArray = new byte[this.m_PackageSize];
            Array.Copy((Array)this.Buffer, (Array)numArray, this.m_PackageSize);
            return(numArray);
        }
示例#5
0
 public TransmittedData(EMessageLengthType _LengthType)
 {
     this.m_LengthType = _LengthType;
 }