Package jmri.jmrix.cmri
Class CMRISystemConnectionMemo
java.lang.Object
jmri.beans.UnboundBean
jmri.beans.Bean
jmri.jmrix.DefaultSystemConnectionMemo
jmri.jmrix.cmri.CMRISystemConnectionMemo
- All Implemented Interfaces:
BeanInterface
,PropertyChangeFirer
,PropertyChangeProvider
,Disposable
,ConfiguringSystemConnectionMemo
,SystemConnectionMemo
public class CMRISystemConnectionMemo extends DefaultSystemConnectionMemo implements ConfiguringSystemConnectionMemo
Minimal SystemConnectionMemo for C/MRI systems.
-
Field Summary
Fields Modifier and Type Field Description (package private) ComponentFactory
cf
Fields inherited from interface jmri.SystemConnectionMemo
DISABLED, INTERVAL, SYSTEM_PREFIX, USER_NAME
-
Constructor Summary
Constructors Constructor Description CMRISystemConnectionMemo()
CMRISystemConnectionMemo(String prefix, String userName)
-
Method Summary
Modifier and Type Method Description int
checkSystemPrefix(String systemName)
Check and skip the System Prefix string on a system name.static int
compareSystemNameSuffix(String suffix1, String suffix2)
void
configureManagers()
Configure the common managers for CMRI connections.String
convertSystemNameToAlternate(String systemName)
Convert one format C/MRI system name to the alternate format.void
dispose()
Called when disposing of a disposable.protected ResourceBundle
getActionModelResourceBundle()
int
getBitFromSystemName(String systemName)
Get the bit number from a C/MRI system name.SerialLightManager
getLightManager()
<B extends NamedBean>
Comparator<B>getNamedBeanComparator(Class<B> type)
Get the Comparator to be used for two NamedBeans.int
getNodeAddressFromSystemName(String systemName)
Get the serial node address from a C/MRI system name.AbstractNode
getNodeFromSystemName(String systemName, SerialTrafficController tc)
Get the serial node from a C/MRI system name.SerialSensorManager
getSensorManager()
SerialTrafficController
getTrafficController()
Get the traffic controller instance associated with this connection memo.SerialTurnoutManager
getTurnoutManager()
String
getUserNameFromSystemName(String systemName)
Get the user name for a valid system name.String
isInputBitFree(int nAddress, int bitNum)
Test if a C/MRI input bit is free for assignment.String
isOutputBitFree(int nAddress, int bitNum)
Test if a C/MRI output bit is free for assignment.String
makeSystemName(String type, int nAddress, int bitNum)
Construct a C/MRI system name from type character, node address, and bit number.String
normalizeSystemName(String systemName)
Normalize a C/MRI system name.void
setTrafficController(SerialTrafficController s)
Set the traffic controller instance associated with this connection memo.String
validateSystemNameFormat(String systemName, char type, Locale locale)
Validate system name format.boolean
validSystemNameConfig(String systemName, char type, SerialTrafficController tc)
Validate C/MRI system name for configuration.Manager.NameValidity
validSystemNameFormat(String systemName, char type)
Validate system name format.Methods inherited from class jmri.jmrix.DefaultSystemConnectionMemo
addToActionList, deregister, get, getActionFactory, getConsistManager, getDefaultOutputInterval, getDisabled, getOutputInterval, getSystemPrefix, getUserName, isDirty, isRestartRequired, provides, register, removeFromActionList, setConsistManager, setDisabled, setOutputInterval, setSystemPrefix, setUserName, store
Methods inherited from class jmri.beans.Bean
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, getPropertyChangeListeners, isNotifyOnEDT, removePropertyChangeListener, removePropertyChangeListener
Methods inherited from class jmri.beans.UnboundBean
getIndexedProperty, getProperty, getPropertyNames, hasIndexedProperty, hasProperty, setIndexedProperty, setProperty
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface jmri.beans.PropertyChangeProvider
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
Methods inherited from interface jmri.SystemConnectionMemo
get, getActionFactory, getDefaultOutputInterval, getDisabled, getOutputInterval, getSystemPrefix, getUserName, isDirty, isRestartRequired, provides, register, setDisabled, setOutputInterval, setSystemPrefix, setUserName
-
Field Details
-
Constructor Details
-
Method Details
-
setTrafficController
Set the traffic controller instance associated with this connection memo.- Parameters:
s
- jmri.jmrix.cmri.serial.SerialTrafficController object to use.
-
getTrafficController
Get the traffic controller instance associated with this connection memo.- Returns:
- the traffic controller, created if needed
-
getUserNameFromSystemName
Get the user name for a valid system name.- Parameters:
systemName
- the system name- Returns:
- "" (null string) if the system name is not valid or does not exist
-
getBitFromSystemName
Get the bit number from a C/MRI system name. Bits are numbered from 1. Does not check whether that node is defined on current system.- Parameters:
systemName
- the system name- Returns:
- 0 if an error is found
-
checkSystemPrefix
Check and skip the System Prefix string on a system name.- Parameters:
systemName
- the system name- Returns:
- offset of the 1st character past the prefix, or -1 if not valid for this connection
-
isOutputBitFree
Test if a C/MRI output bit is free for assignment. Test is not performed if the node address or bit number is invalid.- Parameters:
nAddress
- the node addressbitNum
- the output bit number- Returns:
- "" (empty string) if the specified output bit is free for assignment, else returns the system name of the conflicting assignment.
-
normalizeSystemName
Normalize a C/MRI system name.This routine is used to ensure that each system name is uniquely linked to one C/MRI bit, by removing extra zeros inserted by the user.
- Parameters:
systemName
- the system name- Returns:
- "" (empty string) if the supplied system name does not have a valid format. Otherwise a normalized name is returned in the same format as the input name.
-
convertSystemNameToAlternate
Convert one format C/MRI system name to the alternate format.- Parameters:
systemName
- the system name- Returns:
- "" (empty string) if the supplied system name does not have a valid format, or if there is no representation in the alternate naming scheme
-
validSystemNameFormat
Validate system name format. Does not check whether that node is defined on current system.- Parameters:
systemName
- the system nametype
- the device type- Returns:
- enum indicating current validity, which might be just as a prefix
-
validateSystemNameFormat
public String validateSystemNameFormat(String systemName, char type, Locale locale) throws IllegalArgumentExceptionValidate system name format. Does not check whether that node is defined on current system.- Parameters:
systemName
- the system nametype
- the device typelocale
- the Locale for user messages- Returns:
- systemName unmodified
- Throws:
IllegalArgumentException
- if unable to validate systemName
-
isInputBitFree
Test if a C/MRI input bit is free for assignment. Test is not performed if the node address is invalid or bit number is greater than 2048.- Parameters:
nAddress
- the address to testbitNum
- the bit number to tests- Returns:
- "" (empty string) if the specified input bit is free for assignment, else returns the system name of the conflicting assignment.
-
makeSystemName
Construct a C/MRI system name from type character, node address, and bit number.If the supplied character is not valid, or the node address is out of the 0 - 127 range, or the bit number is out of the 1 - 2048 range, an error message is logged and the null string "" is returned.
- Parameters:
type
- the device typenAddress
- the address to usebitNum
- the bit number to assign- Returns:
- a system name in the CLnnnxxx, CTnnnxxx, or CSnnnxxx format if the bit number is 1 - 999. If the bit number is 1000 - 2048, the system name is returned in the CLnnnBxxxx, CTnnnBxxxx, or CSnnnBxxxx format. The returned name is normalized.
-
getNodeFromSystemName
Get the serial node from a C/MRI system name.- Parameters:
systemName
- the system nametc
- the controller for the node- Returns:
- the node or null if invalid systemName format or if the node is not found
-
validSystemNameConfig
Validate C/MRI system name for configuration. Validates node number and system prefix.- Parameters:
systemName
- the system name to checktype
- the device typetc
- the controller for the device- Returns:
- true if system name has a valid meaning in current configuration; otherwise false
-
getNodeAddressFromSystemName
Get the serial node address from a C/MRI system name.Nodes are numbered from 0 - 127. Does not check whether that node is defined on current system.
- Parameters:
systemName
- the name containing the node- Returns:
- '-1' if invalid systemName format or if the node is not found.
-
compareSystemNameSuffix
@CheckReturnValue public static int compareSystemNameSuffix(@Nonnull String suffix1, @Nonnull String suffix2)SeeNamedBean.compareSystemNameSuffix(java.lang.String, java.lang.String, jmri.NamedBean)
for background. This is a common implementation for C/MRI Lights, Sensors and Turnouts of the comparison method.- Parameters:
suffix1
- suffix to compare.suffix2
- suffix to compare.- Returns:
- CMRI comparison of suffixes.
-
configureManagers
Configure the common managers for CMRI connections. This puts the common manager config in one place.- Specified by:
configureManagers
in interfaceConfiguringSystemConnectionMemo
-
getTurnoutManager
-
getSensorManager
-
getLightManager
-
getActionModelResourceBundle
- Specified by:
getActionModelResourceBundle
in classDefaultSystemConnectionMemo
-
getNamedBeanComparator
Description copied from class:DefaultSystemConnectionMemo
Get the Comparator to be used for two NamedBeans. This is typically anNamedBeanComparator
, but may be any Comparator that works for this connection type.- Specified by:
getNamedBeanComparator
in interfaceSystemConnectionMemo
- Specified by:
getNamedBeanComparator
in classDefaultSystemConnectionMemo
- Type Parameters:
B
- the type of NamedBean- Parameters:
type
- the class of NamedBean- Returns:
- the Comparator
-
dispose
Description copied from interface:Disposable
Called when disposing of a disposable.Note there are no assurances this method will not be called multiple times against a single instance of this Disposable. It is the responsibility of this Disposable to protect itself and the application from ensuring that calling this method multiple times has no unwanted side effects.
- Specified by:
dispose
in interfaceDisposable
- Specified by:
dispose
in interfaceSystemConnectionMemo
- Overrides:
dispose
in classDefaultSystemConnectionMemo
-