Exemplo n.º 1
0
        protected static void DecodeUserData(string pdu, ref int index, out byte userDataLength, out byte[] userData)
        {
            byte @byte = BcdWorker.GetByte(pdu, index++);

            if (@byte <= 0)
            {
                userDataLength = 0;
                userData       = null;
            }
            else
            {
                int    length = BcdWorker.CountBytes(pdu) - index;
                string s      = BcdWorker.GetBytesString(pdu, index, length);
                index += length;
                string str2 = string.Empty;
                for (int i = 0; i < (s.Length / 2); i++)
                {
                    string byteString = BcdWorker.GetByteString(s, i);
                    if (!Calc.IsHexString(byteString))
                    {
                        break;
                    }
                    str2 = str2 + byteString;
                }
                userDataLength = @byte;
                userData       = Calc.HexToInt(str2);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the user data out of the string.
        /// </summary>
        /// <param name="pdu">The PDU string to use.</param>
        /// <param name="index">The index where to start in the string.</param>
        /// <param name="dcs">The coding that was used to encode the data. Required to determine the proper data length.</param>
        /// <param name="userDataLength">Receives the user data length in bytes.</param>
        /// <param name="userData">Received the user data.</param>
        /// <remarks>
        /// <para>If there's no data, userDataLength will be set to 0 and userData to null.</para>
        /// <para>The decoded data might require further processing, for example 7-bit data (septets) packed
        /// into octets, that must be converted back to septets before the data can be used.</para>
        /// <para>Processing will stop at the first character that is not hex encountered or if the
        /// string ends too early. It will not change the <b>userDataLength</b> read from the string.</para>
        /// </remarks>
        public static void DecodeUserData(string pdu, ref int index, byte dcs, out byte userDataLength, out byte[] userData)
        {
            int num  = index;
            int num1 = num;

            index = num + 1;
            byte num2 = BcdWorker.GetByte(pdu, num1);

            if (num2 <= 0)
            {
                userDataLength = 0;
                userData       = new byte[0];
                return;
            }
            else
            {
                int remainingUserDataBytes = PduParts.GetRemainingUserDataBytes(num2, dcs);
                int num3 = BcdWorker.CountBytes(pdu) - index;
                if (num3 < remainingUserDataBytes)
                {
                    remainingUserDataBytes = num3;
                }
                string bytesString = BcdWorker.GetBytesString(pdu, index, remainingUserDataBytes);
                index = index + remainingUserDataBytes;
                string empty = string.Empty;
                for (int i = 0; i < bytesString.Length / 2; i++)
                {
                    string byteString = BcdWorker.GetByteString(bytesString, i);
                    if (!Calc.IsHexString(byteString))
                    {
                        break;
                    }
                    empty = string.Concat(empty, byteString);
                }
                userDataLength = num2;
                userData       = Calc.HexToInt(empty);
                return;
            }
        }