Class CbusAddress

java.lang.Object
jmri.jmrix.can.cbus.CbusAddress

public class CbusAddress extends Object
Utilities for handling CBUS addresses.

CBUS frames have a one byte command and length, optionally followed by data bytes. JMRI maps these into address strings.

Forms:

Full hex string preceeded by "X"
Needs to be pairs of digits: 0123, not 123
+/-ddd
ddd is node*100,000 (a.k.a NODEFACTOR) + event
+/-nNNNeEEE
where NNN is a node number and EEE is an event number
If ddd < 65536 then the CBUS address is taken to represent a short event.
  • Field Details

  • Constructor Details

    • CbusAddress

      public CbusAddress(String s)
      Construct from string without leading system or type letters.
      Parameters:
      s - CBUS Hardware Address format
  • Method Details

    • equals

      public boolean equals(Object r)
      Two addresses are equal if they result in the same numeric contents.
      Overrides:
      equals in class Object
      Parameters:
      r - The other CbusAddress to compare
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • makeMessage

      public CanMessage makeMessage(int header)
    • check

      public boolean check()
    • match

      public boolean match(AbstractMessage r)
      Does the CbusAddress match.
      Parameters:
      r - CanReply or CanMessage being tested
      Returns:
      true if matches
    • matchRequest

      public boolean matchRequest(CanReply r)
      Does the CbusAddress match a CanReply event request.
      Parameters:
      r - CanReply being tested
      Returns:
      true if matches
    • split

      Split a string containing one or more addresses into individual ones.
      Returns:
      0 length if entire string can't be parsed.
    • getIncrement

      @Nonnull public static String getIncrement(@Nonnull String testAddr) throws JmriException
      Increments a CBUS address by 1 eg +123 to +124 eg -N123E456 to -N123E457
      Parameters:
      testAddr - initial CbusAddress String, eg -N123E456
      Returns:
      incremented address.
      Throws:
      JmriException - if unable to make the address
    • validateSysName

      public static String validateSysName(String address) throws IllegalArgumentException
      Validate a CBUS hardware address validation.
      Parameters:
      address - the hardware address to check, excluding both system prefix and type letter.
      Returns:
      same address if all OK.
      Throws:
      IllegalArgumentException - when address is not validated. or contains too many parts
    • checkSplit

      public boolean checkSplit()
      Used in Testing.
      Returns:
      true if split length is 1 or 2, else false.
    • elements

      int[] elements()
    • toString

      public String toString()
      eg. X9801D203A4 or +N123E456
      Overrides:
      toString in class Object
    • toCanonicalString

      eg.x9801D203A4 or x90007B01C8
      Returns:
      x followed by Can Frame Data