Exemplo n.º 1
0
        /// <summary>
        /// Calculates the number of bytes that must be present in the user data portion of the PDU.
        /// </summary>
        /// <param name="dataLength">The user data length specified in the PDU.</param>
        /// <param name="dataCodingScheme">The data coding scheme specified in the PDU.</param>
        /// <returns>The number of bytes (octets) that must be present, or, if decoding the user data, the number
        /// of remaining bytes that must be read.</returns>
        /// <remarks>The <b>dataLength</b> and <b>dataCodingScheme</b> parameters are used to
        /// calculate the number of bytes that must be present in the user data.</remarks>
        internal static int GetRemainingUserDataBytes(byte dataLength, byte dataCodingScheme)
        {
            int num;
            DataCodingScheme dataCodingScheme1 = DataCodingScheme.Decode(dataCodingScheme);
            byte             alphabet          = dataCodingScheme1.Alphabet;

            switch (alphabet)
            {
            case 0:
            {
                num = (int)Math.Ceiling((double)dataLength * 7 / 8);
                break;
            }

            case 1:
            case 2:
            {
                num = dataLength;
                break;
            }

            default:
            {
                num = (int)Math.Ceiling((double)dataLength * 7 / 8);
                break;
            }
            }
            return(num);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds a user data header to an existing user data.
        /// </summary>
        /// <param name="header">The user data header to add.</param>
        /// <exception cref="T:System.InvalidOperationException">There is already a user data header present in this message.</exception>
        /// <exception cref="T:System.ArgumentException">The resulting total of user data header and existing user data exceeds the allowed
        /// maximum data length.</exception>
        /// <remarks>
        /// <para>The user data must already be set before adding a user data header.</para>
        /// <para>Adding a user data header reduces the available space for the remaining user data. If the resulting total of
        /// user data header and existing user data exceeds allowed maximum data length, an exception is raised.</para>
        /// </remarks>
        public void AddUserDataHeader(byte[] header)
        {
            int num;

            if (this.UserDataHeaderPresent)
            {
                throw new InvalidOperationException("There is already a user data header present in this message.");
            }
            else
            {
                int              length           = (int)header.Length;
                byte             num1             = (byte)((double)length * 8 / 7);
                DataCodingScheme dataCodingScheme = GsmComm.PduConverter.DataCodingScheme.Decode(this.DCS);
                if (dataCodingScheme.Alphabet != 0)
                {
                    if (dataCodingScheme.Alphabet == 1 || dataCodingScheme.Alphabet == 2)
                    {
                        num = length + this.userDataLength;
                    }
                    else
                    {
                        num = num1 + this.userDataLength;
                    }
                }
                else
                {
                    num = num1 + this.userDataLength;
                }
                byte[] numArray = new byte[(int)header.Length + (int)this.userData.Length];
                header.CopyTo(numArray, 0);
                this.userData.CopyTo(numArray, (int)header.Length);
                this.SetUserData(numArray, (byte)num);
                this.UserDataHeaderPresent = true;
                return;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Decodes text from user data in the specified data coding scheme.
        /// </summary>
        /// <param name="userData">The user data to decode. Must contain text according to the specified data coding scheme.</param>
        /// <param name="dataCodingScheme">The data coding scheme specified in the PDU.</param>
        /// <returns>The decoded user data.</returns>
        public static string DecodeText(byte[] userData, byte dataCodingScheme)
        {
            string str;
            byte   alphabet = DataCodingScheme.Decode(dataCodingScheme).Alphabet;
            byte   num      = alphabet;

            switch (num)
            {
            case 0:
            {
                str = PduParts.Decode7BitText(userData);
                break;
            }

            case 1:
            {
                //Label0:
                str = PduParts.Decode7BitText(userData);
                break;
            }

            case 2:
            {
                str = PduParts.DecodeUcs2Text(userData);
                break;
            }

            default:
            {
                //goto Label0;
                str = PduParts.Decode7BitText(userData);
                break;
            }
            }
            return(str);
        }