java.lang.Object
org.openremote.agent.protocol.bluetooth.mesh.utils.MeshParserUtils

public class MeshParserUtils extends Object
  • Field Details

  • Constructor Details

    • MeshParserUtils

      public MeshParserUtils()
  • Method Details

    • bytesToHex

      public static String bytesToHex(byte[] bytes, boolean add0x)
    • bytesToHex

      public static String bytesToHex(byte[] bytes, int start, int length, boolean add0x)
    • toByteArray

      public static byte[] toByteArray(String hexString)
    • parseUpdateFlags

      public static byte parseUpdateFlags(int keyRefreshFlag, int ivUpdateFlag)
    • getBitValue

      public static int getBitValue(int value, int position)
    • addKeyIndexPadding

      public static byte[] addKeyIndexPadding(Integer keyIndex)
    • removeKeyIndexPadding

      public static int removeKeyIndexPadding(byte[] keyIndex)
    • validateNetworkKeyInput

      public static boolean validateNetworkKeyInput(@NotNull @NotNull String networkKey) throws IllegalArgumentException
      Validates the network key input
      Parameters:
      networkKey - Network Key input
      Returns:
      true if the Network Key is a valid value
      Throws:
      IllegalArgumentException - in case of an invalid was entered as an input and the message containing the error
    • validateKeyIndexInput

      public static boolean validateKeyIndexInput(String input) throws IllegalArgumentException
      Validates the Key Index input
      Parameters:
      input - Key Index input
      Returns:
      true if the Key Index is a valid value
      Throws:
      IllegalArgumentException - in case of an invalid was entered as an input and the message containing the error
    • validateIvIndexInput

      public static boolean validateIvIndexInput(String input) throws IllegalArgumentException
      Validates the IV Index input
      Parameters:
      input - IV Index input
      Returns:
      true if the the value is valid
      Throws:
      IllegalArgumentException - in case of an invalid was entered as an input and the message containing the error
    • validateIvIndexInput

      public static boolean validateIvIndexInput(Integer ivIndex) throws IllegalArgumentException
      Validates the IV Index input
      Parameters:
      ivIndex - IV Index input
      Returns:
      true if the the value is valid
      Throws:
      IllegalArgumentException - in case of an invalid was entered as an input and the message containing the error
    • validateKeyInput

      public static boolean validateKeyInput(@NotNull @NotNull String key) throws IllegalArgumentException
      Validates the key input
      Parameters:
      key - key
      Returns:
      true if the Key is a valid value
      Throws:
      IllegalArgumentException - in case of an invalid was entered as an input and the message containing the error
    • isValidSequenceNumber

      public static boolean isValidSequenceNumber(int sequenceNumber)
    • getSequenceNumberBytes

      public static byte[] getSequenceNumberBytes(int sequenceNumber)
    • convert24BitsToInt

      public static int convert24BitsToInt(@NotNull @jakarta.validation.constraints.NotNull byte[] byteArray)
    • getSequenceNumberFromPDU

      public static int getSequenceNumberFromPDU(byte[] pdu)
    • calculateSeqZero

      public static int calculateSeqZero(byte[] sequenceNumber)
    • getSrcAddress

      public static byte[] getSrcAddress(byte[] pdu)
    • getDstAddress

      public static byte[] getDstAddress(byte[] pdu)
    • concatenateSegmentedMessages

      public static byte[] concatenateSegmentedMessages(Map<Integer,byte[]> segmentedMessages)
    • getOpCode

      public static int getOpCode(byte[] accessPayload, int opCodeCount)
      Returns the opcode within the access payload
      Parameters:
      accessPayload - payload
      Returns:
      array of opcodes
    • getOpCode

      public static byte[] getOpCode(int opCode)
      Returns an array of opcodes. If the MSB = 0 then the length is 1 If the MSB = 1 then the length is 2 If the MSB = 2 then the length is 3
      Parameters:
      opCode - operation code
    • getOpCodeLength

      public static int getOpCodeLength(int mostSignificantOpcodeByte)
      Returns the length of the opcode. If the MSB = 0 then the length is 1 If the MSB = 1 then the length is 2 If the MSB = 2 then the length is 3
      Parameters:
      mostSignificantOpcodeByte - operation code
      Returns:
      length of opcodes
    • createVendorOpCode

      public static byte[] createVendorOpCode(int opCode, int companyIdentifier)
      Returns the vendor opcode packed with company identifier If the MSB = 0 then the length is 1 If the MSB = 1 then the length is 2 If the MSB = 2 then the length is 3
      Parameters:
      opCode - operation code
      Returns:
      length of opcodes
    • isValidOpcode

      public static boolean isValidOpcode(int opCode) throws IllegalArgumentException
      Checks if the opcode is valid
      Parameters:
      opCode - opCode of mesh message
      Returns:
      if the opcode is valid
      Throws:
      IllegalArgumentException
    • isValidParameters

      public static boolean isValidParameters(byte[] parameters) throws IllegalArgumentException
      Checks if the parameters are within the valid range
      Parameters:
      parameters - opCode of mesh message
      Returns:
      if the opcode is valid
      Throws:
      IllegalArgumentException
    • isValidTtl

      public static boolean isValidTtl(int ttl)
      Checks if the Publication ttl value is within the allowed range where the range is 0x00 - 0x7F.
      Parameters:
      ttl - ttl
      Returns:
      true if valid and false otherwise
    • isValidDefaultTtl

      public static boolean isValidDefaultTtl(int ttl)
      Checks if the ttl value is within the allowed range.

      0x00, 0x02 - 0x7F are the Default TTL states. 0x01, 0x80 and 0xFF are Prohibited.

      Parameters:
      ttl - ttl
      Returns:
      true if valid and false otherwise
    • isDefaultPublishTtl

      public static boolean isDefaultPublishTtl(int publishTtl)
      Checks if the default publish ttl is used for publication
      Parameters:
      publishTtl - publish ttl
      Returns:
      true if valid and false otherwise
    • validateRetransmitCount

      public static boolean validateRetransmitCount(int retransmitCount)
      Checks if the retransmit count is within the allowed range
      Parameters:
      retransmitCount - publish ttl
      Returns:
      true if valid and false otherwise
    • validatePublishRetransmitIntervalSteps

      public static boolean validatePublishRetransmitIntervalSteps(int intervalSteps)
      Checks if the publish retransmit interval steps is within the allowed range
      Parameters:
      intervalSteps - publish ttl
      Returns:
      true if valid and false otherwise
    • getRemainingTime

      public static String getRemainingTime(int remainingTime)
      Returns the remaining time as a string
      Parameters:
      remainingTime - remaining time that for the transition to finish
      Returns:
      remaining time as string.
    • getRemainingTransitionTime

      public static String getRemainingTransitionTime(int stepResolution, int numberOfSteps)
      Returns the remaining time as a string
      Returns:
      remaining time as string.
    • getRemainingTime

      public static int getRemainingTime(int resolution, int steps)
      Returns the remaining time in milliseconds
      Parameters:
      resolution - time resolution
      steps - number of steps
      Returns:
      time in milliseconds
    • getValue

      public static int getValue(byte[] bytes)
    • unsignedByteToInt

      public static int unsignedByteToInt(byte b)
      Convert a signed byte to an unsigned int.
    • unsignedBytesToInt

      public static int unsignedBytesToInt(byte b0, byte b1)
      Convert signed bytes to a 16-bit unsigned int.
    • bytesToInt

      public static int bytesToInt(@NotNull @jakarta.validation.constraints.NotNull byte[] b)
    • hexToInt

      public static int hexToInt(String hex)
    • intToBytes

      public static byte[] intToBytes(int i)
    • isVendorModel

      public static boolean isVendorModel(int modelId)
      Returns if the model id is a vendor model
      Parameters:
      modelId - model identifier
    • getCompanyIdentifier

      public static int getCompanyIdentifier(int modelId)
    • uuidToHex

      public static String uuidToHex(@NotNull @NotNull UUID uuid)
      Returns UUID as a hex
      Parameters:
      uuid - UUID
    • uuidToHex

      public static String uuidToHex(@NotNull @NotNull String uuid)
      Returns UUID as a hex
      Parameters:
      uuid - UUID
    • uuidToBytes

      public static byte[] uuidToBytes(@NotNull @NotNull UUID uuid)
      Returns UUID in bytes
      Parameters:
      uuid - UUID
    • formatUuid

      public static String formatUuid(@NotNull @NotNull String uuidHex)
      Formats a hex string without dashes to a uuid string
      Parameters:
      uuidHex - Hex string
    • isUuidPattern

      public static boolean isUuidPattern(@NotNull @NotNull String uuidHex)
    • getUuid

      public static UUID getUuid(@NotNull @NotNull String uuidHex)
      Returns a type4 UUID from a uuid string without dashes
      Parameters:
      uuidHex - Hex string
    • formatTimeStamp

      public static String formatTimeStamp(long timestamp)
      Formats the timestamp
      Parameters:
      timestamp - timestamp
    • isNodeKeyExists

      public static boolean isNodeKeyExists(@NotNull @NotNull List<NodeKey> keys, int index)
    • getNodeKey

      public static NodeKey getNodeKey(@NotNull @NotNull List<NodeKey> keys, int index)
    • isValidHeartbeatCountLog

      public static boolean isValidHeartbeatCountLog(int countLog)
      Validates heart beat count log.
      Parameters:
      countLog - Heartbeat publication count.
      Returns:
      true if valid.
      Throws:
      IllegalArgumentException - if the countLog value is not a value from 0 to 17 or 255
    • isValidHeartbeatPublicationTtl

      public static boolean isValidHeartbeatPublicationTtl(int ttl)
      Validates heart beat publication ttl.
      Parameters:
      ttl - Heartbeat publication ttl.
      Returns:
      true if valid or false otherwise.