Package jmri.jmrix.openlcb
Class OlcbAddress
java.lang.Object
jmri.jmrix.openlcb.OlcbAddress
Utilities for handling OpenLCB event messages as addresses.
OpenLCB event messages have header information, plus an EventID in the data part. JMRI maps these into address strings.
String forms:
- Special case for DCC Turnout addressing: Tnnn where nnn is a decimal number
- Full hex string preceeded by "x"
- Needs to be pairs of digits: 0123, not 123
- Full 8 byte ID as pairs separated by "."
Note: the check() routine does a full, expensive
validity check of the name. All other operations
assume correctness, diagnose some invalid-format strings, but
may appear to successfully handle other invalid forms.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionOlcbAddress(String input, CanSystemConnectionMemo memo) Construct from string without leading system or type lettersConstruct from OlcbEvent. -
Method Summary
Modifier and TypeMethodDescriptionbooleancheck()Confirm that the address string (provided earlier) is fully valid.booleanintcompare(OlcbAddress opp) static intcompareSystemNameSuffix(String suffix1, String suffix2, CanSystemConnectionMemo memo) (package private) int[]elements()booleanTwo addresses are equal if they result in the same numeric contentsinthashCode()booleanWas this parsed from a name (e.g. not explicit ID, not pair)(package private) booleanmatch(CanMessage r) (package private) booleansplit(CanSystemConnectionMemo memo) Split a string containing one or more addresses into individual ones.Provide as dotted pairs.toString()static StringvalidateSystemNameFormat(String name, Locale locale, String prefix, CanSystemConnectionMemo memo) Validates Strings for OpenLCB format.static StringvalidateSystemNameFormat2Part(String name, Locale locale, String prefix, CanSystemConnectionMemo memo) Validates 2 part Hardware Address Strings for OpenLCB format.
-
Field Details
-
singleAddressPattern
- See Also:
-
-
Constructor Details
-
OlcbAddress
Construct from OlcbEvent.- Parameters:
e- the event ID.
-
OlcbAddress
Construct from string without leading system or type letters- Parameters:
input- hex coded string of address
-
-
Method Details
-
equals
Two addresses are equal if they result in the same numeric contents -
hashCode
-
compare
-
makeMessage
-
check
Confirm that the address string (provided earlier) is fully valid.This is an expensive call. It's complete-compliance done using a regular expression. It can reject some forms that the code will normally handle OK.
- Returns:
- true if valid, else false.
-
match
-
match
-
split
Split a string containing one or more addresses into individual ones.- Returns:
- null if entire string can't be parsed.
-
checkSplit
-
elements
int[] elements() -
toString
-
toCanonicalString
- Returns:
- The canonical form of 0x1122334455667788
-
toDottedString
Provide as dotted pairs.- Returns:
- dotted pair form off string.
-
toEventID
- Returns:
- null if no valid address was parsed earlier, e.g. there was a ; in the data
-
isFromName
Was this parsed from a name (e.g. not explicit ID, not pair)- Returns:
- true if constructed from an event name
-
validateSystemNameFormat
@Nonnull public static String validateSystemNameFormat(@Nonnull String name, @Nonnull Locale locale, @Nonnull String prefix, CanSystemConnectionMemo memo) throws NamedBean.BadSystemNameException Validates Strings for OpenLCB format.- Parameters:
name- the system name to validate.locale- the locale for a localized exception.prefix- system prefix, eg. MT for OpenLcb turnout.- Returns:
- the unchanged value of the name parameter.
- Throws:
NamedBean.BadSystemNameException- if provided name is an invalid format.
-
validateSystemNameFormat2Part
@Nonnull public static String validateSystemNameFormat2Part(@Nonnull String name, @Nonnull Locale locale, @Nonnull String prefix, CanSystemConnectionMemo memo) throws NamedBean.BadSystemNameException Validates 2 part Hardware Address Strings for OpenLCB format.- Parameters:
name- the system name to validate.locale- the locale for a localized exception.prefix- system prefix, eg. MT for OpenLcb turnout.- Returns:
- the unchanged value of the name parameter.
- Throws:
NamedBean.BadSystemNameException- if provided name is an invalid format.
-
compareSystemNameSuffix
@CheckReturnValue public static int compareSystemNameSuffix(@Nonnull String suffix1, @Nonnull String suffix2, CanSystemConnectionMemo memo) SeeNamedBean.compareSystemNameSuffix(java.lang.String, java.lang.String, jmri.NamedBean)for background. This is a common implementation for OpenLCB Sensors and Turnouts of the comparison method.- Parameters:
suffix1- 1st suffix to compare.suffix2- 2nd suffix to compare.- Returns:
- true if suffixes match, else false.
-