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) ComponentFactorycf-
Fields inherited from class jmri.jmrix.DefaultSystemConnectionMemo
classObjectMap
-
Fields inherited from class jmri.beans.Bean
propertyChangeSupport
-
Fields inherited from interface jmri.SystemConnectionMemo
DEREGISTER, DISABLED, INTERVAL, STORE, SYSTEM_PREFIX, USER_NAME
-
-
Constructor Summary
Constructors Constructor Description CMRISystemConnectionMemo()CMRISystemConnectionMemo(java.lang.String prefix, java.lang.String userName)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcheckSystemPrefix(java.lang.String systemName)Check and skip the System Prefix string on a system name.static intcompareSystemNameSuffix(java.lang.String suffix1, java.lang.String suffix2)voidconfigureManagers()Configure the common managers for CMRI connections.java.lang.StringconvertSystemNameToAlternate(java.lang.String systemName)Convert one format C/MRI system name to the alternate format.voiddispose()Dispose of System Connection.protected java.util.ResourceBundlegetActionModelResourceBundle()intgetBitFromSystemName(java.lang.String systemName)Get the bit number from a C/MRI system name.SerialLightManagergetLightManager()<B extends NamedBean>
java.util.Comparator<B>getNamedBeanComparator(java.lang.Class<B> type)Get the Comparator to be used for two NamedBeans.intgetNodeAddressFromSystemName(java.lang.String systemName)Get the serial node address from a C/MRI system name.AbstractNodegetNodeFromSystemName(java.lang.String systemName, SerialTrafficController tc)Get the serial node from a C/MRI system name.SerialSensorManagergetSensorManager()SerialTrafficControllergetTrafficController()Get the traffic controller instance associated with this connection memo.SerialTurnoutManagergetTurnoutManager()java.lang.StringgetUserNameFromSystemName(java.lang.String systemName)Get the user name for a valid system name.java.lang.StringisInputBitFree(int nAddress, int bitNum)Test if a C/MRI input bit is free for assignment.java.lang.StringisOutputBitFree(int nAddress, int bitNum)Test if a C/MRI output bit is free for assignment.java.lang.StringmakeSystemName(java.lang.String type, int nAddress, int bitNum)Construct a C/MRI system name from type character, node address, and bit number.java.lang.StringnormalizeSystemName(java.lang.String systemName)Normalize a C/MRI system name.voidsetTrafficController(SerialTrafficController s)Set the traffic controller instance associated with this connection memo.java.lang.StringvalidateSystemNameFormat(java.lang.String systemName, char type, java.util.Locale locale)Validate system name format.booleanvalidSystemNameConfig(java.lang.String systemName, char type, SerialTrafficController tc)Validate C/MRI system name for configuration.Manager.NameValidityvalidSystemNameFormat(java.lang.String systemName, char type)Validate system name format.-
Methods inherited from class jmri.jmrix.DefaultSystemConnectionMemo
deregister, get, getActionFactory, getConsistManager, getDefaultOutputInterval, getDisabled, getOutputInterval, getSystemPrefix, getUserName, isDirty, isRestartRequired, provides, register, 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
-
-
-
-
Constructor Detail
-
CMRISystemConnectionMemo
public CMRISystemConnectionMemo()
-
CMRISystemConnectionMemo
public CMRISystemConnectionMemo(@Nonnull java.lang.String prefix, @Nonnull java.lang.String userName)
-
-
Method Detail
-
setTrafficController
public void setTrafficController(SerialTrafficController s)
Set the traffic controller instance associated with this connection memo.- Parameters:
s- jmri.jmrix.cmri.serial.SerialTrafficController object to use.
-
getTrafficController
public SerialTrafficController getTrafficController()
Get the traffic controller instance associated with this connection memo.- Returns:
- the traffic controller, created if needed
-
getUserNameFromSystemName
public java.lang.String getUserNameFromSystemName(java.lang.String systemName)
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
public int getBitFromSystemName(java.lang.String systemName)
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
public int checkSystemPrefix(java.lang.String systemName)
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
public java.lang.String isOutputBitFree(int nAddress, int bitNum)
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
public java.lang.String normalizeSystemName(java.lang.String systemName)
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
public java.lang.String convertSystemNameToAlternate(java.lang.String systemName)
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
public Manager.NameValidity validSystemNameFormat(@Nonnull java.lang.String systemName, char type)
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 java.lang.String validateSystemNameFormat(java.lang.String systemName, char type, java.util.Locale locale) throws java.lang.IllegalArgumentException
Validate 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:
java.lang.IllegalArgumentException- if unable to validate systemName
-
isInputBitFree
public java.lang.String isInputBitFree(int nAddress, int bitNum)
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
public java.lang.String makeSystemName(java.lang.String type, int nAddress, int bitNum)
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
public AbstractNode getNodeFromSystemName(java.lang.String systemName, SerialTrafficController tc)
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
public boolean validSystemNameConfig(java.lang.String systemName, char type, SerialTrafficController tc)
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
public int getNodeAddressFromSystemName(java.lang.String systemName)
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 java.lang.String suffix1, @Nonnull java.lang.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
public void configureManagers()
Configure the common managers for CMRI connections. This puts the common manager config in one place.- Specified by:
configureManagersin interfaceConfiguringSystemConnectionMemo
-
getTurnoutManager
public SerialTurnoutManager getTurnoutManager()
-
getSensorManager
public SerialSensorManager getSensorManager()
-
getLightManager
public SerialLightManager getLightManager()
-
getActionModelResourceBundle
protected java.util.ResourceBundle getActionModelResourceBundle()
- Specified by:
getActionModelResourceBundlein classDefaultSystemConnectionMemo
-
getNamedBeanComparator
public <B extends NamedBean> java.util.Comparator<B> getNamedBeanComparator(java.lang.Class<B> type)
Description copied from class:DefaultSystemConnectionMemoGet 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:
getNamedBeanComparatorin interfaceSystemConnectionMemo- Specified by:
getNamedBeanComparatorin classDefaultSystemConnectionMemo- Type Parameters:
B- the type of NamedBean- Parameters:
type- the class of NamedBean- Returns:
- the Comparator
-
dispose
public void dispose()
Description copied from class:DefaultSystemConnectionMemoDispose of System Connection.Removes objects from classObjectMap after calling dispose if Disposable. Removes these objects from InstanceManager.
- Specified by:
disposein interfaceDisposable- Specified by:
disposein interfaceSystemConnectionMemo- Overrides:
disposein classDefaultSystemConnectionMemo
-
-