Package jmri.jmrix.can.cbus
Class CbusAddress
- java.lang.Object
-
- jmri.jmrix.can.cbus.CbusAddress
-
public class CbusAddress extends java.lang.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
-
-
Field Summary
Fields Modifier and Type Field Description protected int[]
aFrame
(package private) static int
NODEFACTOR
(package private) static java.lang.String
SINGLE_ADDRESS_PATTERN
-
Constructor Summary
Constructors Constructor Description CbusAddress(java.lang.String s)
Construct from string without leading system or type letters.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
check()
boolean
checkSplit()
Used in Testing.(package private) int[]
elements()
boolean
equals(java.lang.Object r)
Two addresses are equal if they result in the same numeric contents.static java.lang.String
getIncrement(java.lang.String testAddr)
Increments a CBUS address by 1 eg +123 to +124 eg -N123E456 to -N123E457int
hashCode()
CanMessage
makeMessage(int header)
boolean
match(AbstractMessage r)
Does the CbusAddress match.boolean
matchRequest(CanReply r)
Does the CbusAddress match a CanReply event request.CbusAddress[]
split()
Split a string containing one or more addresses into individual ones.java.lang.String
toCanonicalString()
eg.x9801D203A4 or x90007B01C8java.lang.String
toString()
eg.static java.lang.String
validateSysName(java.lang.String address)
Validate a CBUS hardware address validation.
-
-
-
Field Detail
-
SINGLE_ADDRESS_PATTERN
static final java.lang.String SINGLE_ADDRESS_PATTERN
- See Also:
- Constant Field Values
-
aFrame
protected int[] aFrame
-
NODEFACTOR
static final int NODEFACTOR
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CbusAddress
public CbusAddress(java.lang.String s)
Construct from string without leading system or type letters.- Parameters:
s
- CBUS Hardware Address format
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object r)
Two addresses are equal if they result in the same numeric contents.- Overrides:
equals
in classjava.lang.Object
- Parameters:
r
- The other CbusAddress to compare
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.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
@Nonnull public CbusAddress[] 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 java.lang.String getIncrement(@Nonnull java.lang.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 java.lang.String validateSysName(java.lang.String address) throws java.lang.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:
java.lang.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 java.lang.String toString()
eg. X9801D203A4 or +N123E456- Overrides:
toString
in classjava.lang.Object
-
toCanonicalString
public java.lang.String toCanonicalString()
eg.x9801D203A4 or x90007B01C8- Returns:
- x followed by Can Frame Data
-
-