/// <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; } }
/// <summary> /// Checks if the user data portion of the PDU is complete. /// </summary> /// <returns>true if all data is available, false otherwise.</returns> /// <remarks>This method can be used to verify that the user data has not been truncated or otherwise /// invalidated.</remarks> public bool IsUserDataComplete() { int remainingUserDataBytes = PduParts.GetRemainingUserDataBytes(this.userDataLength, this.DCS); return((int)this.userData.Length >= remainingUserDataBytes); }