Class Dcc4PcSensorManager
- java.lang.Object
-
- jmri.beans.PropertyChangeSupport
-
- jmri.beans.VetoableChangeSupport
-
- jmri.managers.AbstractManager<Sensor>
-
- jmri.managers.AbstractSensorManager
-
- jmri.jmrix.dcc4pc.Dcc4PcSensorManager
-
- All Implemented Interfaces:
java.beans.PropertyChangeListener
,java.beans.VetoableChangeListener
,java.util.EventListener
,PropertyChangeFirer
,PropertyChangeProvider
,SilenceablePropertyChangeProvider
,VetoableChangeFirer
,VetoableChangeProvider
,AbstractMRListener
,Dcc4PcListener
,Manager<Sensor>
,NameIncrementingManager
,ProvidingManager<Sensor>
,SensorManager
public class Dcc4PcSensorManager extends AbstractSensorManager implements Dcc4PcListener
Implement SensorManager for Dcc4Pc systems. The Manager handles all the state changes.System names are "DSnn:yy", where D is the user configurable system prefix, nn is the board id and yy is the port on that board.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
Dcc4PcSensorManager.ActiveBoard
-
Nested classes/interfaces inherited from interface jmri.Manager
Manager.ManagerDataEvent<E extends NamedBean>, Manager.ManagerDataListener<E extends NamedBean>, Manager.NameValidity
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.concurrent.ConcurrentHashMap<java.lang.Integer,Dcc4PcSensorManager.ActiveBoard>
activeBoards
(package private) Dcc4PcBoardManager
boardManager
static int
CONSIST_ADDRESS
static int
LONG_ADDRESS
static int
NO_ADDRESS
(package private) java.lang.Runnable
pollShutDownTask
(package private) java.lang.Thread
pollThread
(package private) Dcc4PcReporterManager
reportManager
static int
SHORT_ADDRESS
(package private) boolean
stopPolling
(package private) Dcc4PcTrafficController
tc
-
Fields inherited from class jmri.managers.AbstractSensorManager
sensorDebounceGoingActive, sensorDebounceGoingInActive
-
Fields inherited from class jmri.managers.AbstractManager
_beans, _tsys, _tuser, memo, silenceableProperties, silencedProperties
-
Fields inherited from class jmri.beans.VetoableChangeSupport
vetoableChangeSupport
-
Fields inherited from class jmri.beans.PropertyChangeSupport
propertyChangeSupport
-
Fields inherited from interface jmri.Manager
ANALOGIOS, AUDIO, BLOCKBOSS, BLOCKS, CONDITIONALS, CTCDATA, ENTRYEXIT, IDTAGS, LAYOUTBLOCKS, LIGHTS, LOGIXNG_ANALOG_ACTIONS, LOGIXNG_ANALOG_EXPRESSIONS, LOGIXNG_CONDITIONALNGS, LOGIXNG_DIGITAL_ACTIONS, LOGIXNG_DIGITAL_BOOLEAN_ACTIONS, LOGIXNG_DIGITAL_EXPRESSIONS, LOGIXNG_GLOBAL_VARIABLES, LOGIXNG_MODULES, LOGIXNG_STRING_ACTIONS, LOGIXNG_STRING_EXPRESSIONS, LOGIXNG_TABLES, LOGIXNGS, LOGIXS, MEMORIES, METERFRAMES, METERS, OBLOCKS, PANELFILES, REPORTERS, ROUTES, SECTIONS, SENSORGROUPS, SENSORS, SIGNALGROUPS, SIGNALHEADS, SIGNALMASTLOGICS, SIGNALMASTS, STRINGIOS, TIMEBASE, TRANSITS, TURNOUTS, WARRANTS
-
-
Constructor Summary
Constructors Constructor Description Dcc4PcSensorManager(Dcc4PcTrafficController tc, Dcc4PcSystemConnectionMemo memo)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addActiveBoard(int address, java.lang.String version, int inputs, int encoding)
(package private) void
addBoard(int newBoard)
boolean
allowMultipleAdditions(java.lang.String systemName)
Determines if it is possible to add a range of NamedBeans in numerical order for a particular system implementation.void
changeBoardAddress(int oldAddress, int newAddress)
protected Sensor
createNewSensor(java.lang.String systemName, java.lang.String userName)
Internal method to invoke the factory and create a new Sensor.protected void
createSensorsForBoard(Dcc4PcReply r)
protected void
createSensorsFromReply(Dcc4PcReply r)
Generate all the sensor and reporter details based upon the reply message from the board.java.lang.String
createSystemName(java.lang.String curAddress, java.lang.String prefix)
Default Sensor ensures a numeric only system name.(package private) int
decodeDuplicatePacket(int value, int seq, Dcc4PcReporter rc)
Determine if the Railcom data is duplicated.static java.lang.String
decodeInputState(int state)
void
dispose()
Free resources when no longer used.(package private) void
extractBoardID(java.lang.String systemName)
This extracts the board id out from the system name.java.lang.String
getBoardDescription(int board)
java.lang.String
getBoardEncodingAsString(int board)
int
getBoardInputs(int board)
java.util.List<java.lang.Integer>
getBoards()
java.lang.String
getBoardVersion(int board)
(package private) void
getInputState(int[] longArray, int board)
(package private) int
getInputState(int value, int input)
Dcc4PcSystemConnectionMemo
getMemo()
Get the system connection for this manager.Dcc4PcSensor
getSensor(java.lang.String name)
Get an existing Sensor or return null if it doesn't exist.void
handleTimeout(Dcc4PcMessage m)
protected boolean
isBoardCreated(int address)
void
message(Dcc4PcMessage m)
void
notifyMessage(Dcc4PcMessage m)
void
notifyReply(Dcc4PcReply m)
(package private) void
pollManager()
void
reply(Dcc4PcReply r)
protected void
setBoardDescription(int address, java.lang.String description)
protected void
startPolling()
protected void
stopPolling()
java.lang.String
validateSystemNameFormat(java.lang.String name, java.util.Locale locale)
Validates to contain at least 1 number . . .-
Methods inherited from class jmri.managers.AbstractSensorManager
getBeanTypeHandled, getBySystemName, getDefaultSensorDebounceGoingActive, getDefaultSensorDebounceGoingInActive, getEntryToolTip, getNamedBeanClass, getXMLOrder, isPullResistanceConfigurable, newSensor, provideSensor, setDefaultSensorDebounceGoingActive, setDefaultSensorDebounceGoingInActive, typeLetter, updateAll
-
Methods inherited from class jmri.managers.AbstractManager
addDataListener, checkNumeric, deleteBean, deregister, fireDataListenersAdded, fireDataListenersRemoved, fireVetoableChange, getAutoSystemName, getBySystemName, getByUserName, getKnownBeanProperties, getNamedBean, getNamedBeanSet, getObjectCount, getOuterBean, getSystemPrefix, handleUserNameUniqueness, makeSystemName, propertyChange, register, registerSelf, registerUserName, removeDataListener, setDataListenerMute, setPropertyChangesSilenced, updateAutoNumber, validSystemNameFormat, vetoableChange
-
Methods inherited from class jmri.beans.VetoableChangeSupport
addVetoableChangeListener, addVetoableChangeListener, fireVetoableChange, fireVetoableChange, fireVetoableChange, getVetoableChangeListeners, getVetoableChangeListeners, removeVetoableChangeListener, removeVetoableChangeListener
-
Methods inherited from class jmri.beans.PropertyChangeSupport
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jmri.Manager
addDataListener, deleteBean, deregister, getBeanTypeHandled, getKnownBeanProperties, getNamedBean, getNamedBeanSet, getObjectCount, getSubSystemNamePrefix, getSystemNamePrefix, getSystemPrefix, isValidSystemNameFormat, makeSystemName, makeSystemName, makeSystemName, register, removeDataListener, setDataListenerMute, validateBadCharsInSystemNameFormat, validateIntegerSystemNameFormat, validateNmraAccessorySystemNameFormat, validateSystemNameFormat, validateSystemNameFormatOnlyNumeric, validateSystemNamePrefix, validateTrimmedMin1NumberSystemNameFormat, validateTrimmedSystemNameFormat, validateUppercaseTrimmedSystemNameFormat, validSystemNameFormat
-
Methods inherited from interface jmri.NameIncrementingManager
getNextValidSystemName
-
Methods inherited from interface jmri.beans.PropertyChangeProvider
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
Methods inherited from interface jmri.SensorManager
getByUserName, provide
-
Methods inherited from interface jmri.beans.SilenceablePropertyChangeProvider
setPropertyChangesSilenced
-
Methods inherited from interface jmri.beans.VetoableChangeProvider
addVetoableChangeListener, addVetoableChangeListener, getVetoableChangeListeners, getVetoableChangeListeners, removeVetoableChangeListener, removeVetoableChangeListener
-
-
-
-
Field Detail
-
reportManager
Dcc4PcReporterManager reportManager
-
pollShutDownTask
java.lang.Runnable pollShutDownTask
-
boardManager
Dcc4PcBoardManager boardManager
-
pollThread
java.lang.Thread pollThread
-
stopPolling
boolean stopPolling
-
NO_ADDRESS
public static final int NO_ADDRESS
- See Also:
- Constant Field Values
-
SHORT_ADDRESS
public static final int SHORT_ADDRESS
- See Also:
- Constant Field Values
-
LONG_ADDRESS
public static final int LONG_ADDRESS
- See Also:
- Constant Field Values
-
CONSIST_ADDRESS
public static final int CONSIST_ADDRESS
- See Also:
- Constant Field Values
-
activeBoards
java.util.concurrent.ConcurrentHashMap<java.lang.Integer,Dcc4PcSensorManager.ActiveBoard> activeBoards
-
-
Constructor Detail
-
Dcc4PcSensorManager
public Dcc4PcSensorManager(Dcc4PcTrafficController tc, Dcc4PcSystemConnectionMemo memo)
-
-
Method Detail
-
getSensor
public Dcc4PcSensor getSensor(@Nonnull java.lang.String name)
Description copied from class:AbstractSensorManager
Get an existing Sensor or return null if it doesn't exist. Locates via user name, then system name if needed.- Specified by:
getSensor
in interfaceSensorManager
- Overrides:
getSensor
in classAbstractSensorManager
- Parameters:
name
- User name or system name to match- Returns:
- null if no match found
-
getMemo
@Nonnull public Dcc4PcSystemConnectionMemo getMemo()
Get the system connection for this manager.
-
createNewSensor
@Nonnull protected Sensor createNewSensor(@Nonnull java.lang.String systemName, java.lang.String userName) throws java.lang.IllegalArgumentException
Internal method to invoke the factory and create a new Sensor. Called after all the logic for returning an existing Sensor has been invoked. An existing SystemName is not found, existing UserName not found. Implementing classes should base Sensor on the system name, then add user name.- Specified by:
createNewSensor
in classAbstractSensorManager
- Parameters:
systemName
- the system name to use for the new SensoruserName
- the optional user name to use for the new Sensor- Returns:
- the new Sensor
- Throws:
java.lang.IllegalArgumentException
- if unsuccessful with reason for fail.
-
extractBoardID
void extractBoardID(java.lang.String systemName)
This extracts the board id out from the system name.- Parameters:
systemName
- including system prefix and type letter.
-
allowMultipleAdditions
public boolean allowMultipleAdditions(@Nonnull java.lang.String systemName)
Description copied from interface:NameIncrementingManager
Determines if it is possible to add a range of NamedBeans in numerical order for a particular system implementation.Default is not providing this service. Systems should override this method if they do provide the service.
- Specified by:
allowMultipleAdditions
in interfaceNameIncrementingManager
- Parameters:
systemName
- the system name to check against; appears to be ignored in all implementations- Returns:
- true if possible; false otherwise
-
createSystemName
@Nonnull public java.lang.String createSystemName(@Nonnull java.lang.String curAddress, @Nonnull java.lang.String prefix) throws JmriException
Description copied from class:AbstractSensorManager
Default Sensor ensures a numeric only system name. Create a System Name from hardware address and system letter prefix. AbstractManager performs no validation.- Specified by:
createSystemName
in interfaceSensorManager
- Overrides:
createSystemName
in classAbstractSensorManager
- Parameters:
curAddress
- hardware address, no system prefix or type letter.prefix
- - just system prefix, not including Type Letter.- Returns:
- full system name with system prefix, type letter and hardware address.
- Throws:
JmriException
- if unable to create a system name.
-
notifyReply
public void notifyReply(Dcc4PcReply m)
-
notifyMessage
public void notifyMessage(Dcc4PcMessage m)
-
stopPolling
protected void stopPolling()
-
startPolling
protected final void startPolling()
-
addBoard
void addBoard(int newBoard)
-
reply
public void reply(Dcc4PcReply r)
- Specified by:
reply
in interfaceDcc4PcListener
-
getInputState
void getInputState(int[] longArray, int board)
-
getInputState
int getInputState(int value, int input)
-
decodeInputState
public static java.lang.String decodeInputState(int state)
-
decodeDuplicatePacket
int decodeDuplicatePacket(int value, int seq, Dcc4PcReporter rc)
Determine if the Railcom data is duplicated. If it is then this instructs the Reporter to move things about.- Parameters:
value
- Railcom dataseq
- message sequence numberrc
- Reporter to request action(s) from- Returns:
- value calculated locally
-
pollManager
void pollManager()
-
createSensorsFromReply
protected void createSensorsFromReply(Dcc4PcReply r)
Generate all the sensor and reporter details based upon the reply message from the board.- Parameters:
r
- Reply that we build the information from
-
handleTimeout
public void handleTimeout(Dcc4PcMessage m)
- Specified by:
handleTimeout
in interfaceDcc4PcListener
-
message
public void message(Dcc4PcMessage m)
- Specified by:
message
in interfaceDcc4PcListener
-
changeBoardAddress
public void changeBoardAddress(int oldAddress, int newAddress)
-
getBoards
public java.util.List<java.lang.Integer> getBoards()
-
getBoardInputs
public int getBoardInputs(int board)
-
getBoardEncodingAsString
public java.lang.String getBoardEncodingAsString(int board)
-
getBoardVersion
public java.lang.String getBoardVersion(int board)
-
getBoardDescription
public java.lang.String getBoardDescription(int board)
-
isBoardCreated
protected boolean isBoardCreated(int address)
-
addActiveBoard
protected void addActiveBoard(int address, java.lang.String version, int inputs, int encoding)
-
setBoardDescription
protected void setBoardDescription(int address, java.lang.String description)
-
createSensorsForBoard
protected void createSensorsForBoard(Dcc4PcReply r)
-
validateSystemNameFormat
@Nonnull public java.lang.String validateSystemNameFormat(@Nonnull java.lang.String name, @Nonnull java.util.Locale locale) throws NamedBean.BadSystemNameException
Validates to contain at least 1 number . . .TODO: Custom validation for Dcc4PcSensorManager could be improved. Validate the format of name, returning it unchanged if valid.
Although further restrictions may be added by system-specific implementations, at a minimum, the implementation must consider a name that does not start with the System Name prefix for this manager to be invalid, and must consider a name that is the same as the System Name prefix to be invalid.
Overriding implementations may rely on
Manager.validSystemNameFormat(java.lang.String)
, however they must provide an actionable message in the thrown exception if that method does not returnManager.NameValidity.VALID
. When overriding implementations of this method rely on validSystemNameFormat(), implementations of that method must not throw an exception, log an error, or otherwise disrupt the user.- Specified by:
validateSystemNameFormat
in interfaceManager<Sensor>
- Parameters:
name
- the system name to validatelocale
- the locale for a localized exception; this is needed for the JMRI web server, which supports multiple locales- Returns:
- the unchanged value of the name parameter
- Throws:
NamedBean.BadSystemNameException
- if provided name is an invalid format
-
dispose
public void dispose()
Description copied from class:AbstractManager
Free resources when no longer used. Specifically, remove all references to and from this object, so it can be garbage-collected.- Specified by:
dispose
in interfaceManager<Sensor>
- Specified by:
dispose
in interfaceSensorManager
- Overrides:
dispose
in classAbstractManager<Sensor>
-
-