Class Dcc4PcSensorManager
- All Implemented Interfaces:
PropertyChangeListener
,VetoableChangeListener
,EventListener
,PropertyChangeFirer
,PropertyChangeProvider
,SilenceablePropertyChangeProvider
,VetoableChangeFirer
,VetoableChangeProvider
,AbstractMRListener
,Dcc4PcListener
,Manager<Sensor>
,ProvidingManager<Sensor>
,SensorManager
public class Dcc4PcSensorManager extends AbstractSensorManager implements Dcc4PcListener
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) ConcurrentHashMap<Integer,Dcc4PcSensorManager.ActiveBoard>
activeBoards
(package private) Dcc4PcBoardManager
boardManager
static int
CONSIST_ADDRESS
static int
LONG_ADDRESS
static int
NO_ADDRESS
(package private) Runnable
pollShutDownTask
(package private) 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 interface jmri.Manager
ANALOGIOS, AUDIO, BLOCKBOSS, BLOCKS, CONDITIONALS, CTCDATA, deprecatedManagerLogger, ENTRYEXIT, IDTAGS, LAYOUTBLOCKS, LIGHTS, LOGIXNG_ANALOG_ACTIONS, LOGIXNG_ANALOG_EXPRESSIONS, LOGIXNG_CONDITIONALNGS, LOGIXNG_DIGITAL_ACTIONS, LOGIXNG_DIGITAL_BOOLEAN_ACTIONS, LOGIXNG_DIGITAL_EXPRESSIONS, 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
Modifier and Type Method Description protected void
addActiveBoard(int address, String version, int inputs, int encoding)
(package private) void
addBoard(int newBoard)
boolean
allowMultipleAdditions(String systemName)
Determines if it is possible to add a range of sensors in numerical order.void
changeBoardAddress(int oldAddress, int newAddress)
Sensor
createNewSensor(String systemName, String userName)
Internal method to invoke the factory and create a new Sensor based on the system name and optional user name, after all the logic for returning an existing Sensor has been invoked.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.String
createSystemName(String curAddress, String prefix)
Default Sensor ensures a numeric only system name.(package private) int
decodeDuplicatePacket(int value, int seq, Dcc4PcReporter rc)
Determining if the railcommdata is duplicated.static String
decodeInputState(int state)
void
dispose()
Free resources when no longer used.(package private) void
extractBoardID(String systemName)
This extracts the board id out from the system name.String
getBoardDescription(int board)
String
getBoardEncodingAsString(int board)
int
getBoardInputs(int board)
List<Integer>
getBoards()
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.String
getNextValidAddress(String curAddress, String prefix, boolean ignoreInitialExisting)
Get the Next valid hardware address.Dcc4PcSensor
getSensor(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, String description)
protected void
startPolling()
protected void
stopPolling()
String
validateSystemNameFormat(String name, 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, getIncrement, getIncrementFromExistingNumber, getInstanceBySystemName, getInstanceByUserName, getKnownBeanProperties, getNamedBean, getNamedBeanList, getNamedBeanSet, getNextValidAddress, getObjectCount, getSystemNameList, 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, getBeanBySystemName, getBeanByUserName, getBeanTypeHandled, getKnownBeanProperties, getNamedBean, getNamedBeanList, getNamedBeanSet, getObjectCount, getSubSystemNamePrefix, getSystemNameList, getSystemNamePrefix, getSystemPrefix, isValidSystemNameFormat, makeSystemName, makeSystemName, makeSystemName, register, removeDataListener, setDataListenerMute, setPropertyChangesMuted, validateBadCharsInSystemNameFormat, validateIntegerSystemNameFormat, validateNmraAccessorySystemNameFormat, validateSystemNameFormat, validateSystemNameFormatOnlyNumeric, validateSystemNamePrefix, validateTrimmedMin1NumberSystemNameFormat, validateTrimmedSystemNameFormat, validateUppercaseTrimmedSystemNameFormat, validSystemNameFormat
Methods inherited from interface jmri.beans.PropertyChangeProvider
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
Methods inherited from interface jmri.beans.SilenceablePropertyChangeProvider
setPropertyChangesSilenced
Methods inherited from interface jmri.beans.VetoableChangeProvider
addVetoableChangeListener, addVetoableChangeListener, getVetoableChangeListeners, getVetoableChangeListeners, removeVetoableChangeListener, removeVetoableChangeListener
-
Field Details
-
reportManager
-
pollShutDownTask
-
boardManager
-
tc
-
pollThread
-
stopPolling
boolean stopPolling -
NO_ADDRESS
- See Also:
- Constant Field Values
-
SHORT_ADDRESS
- See Also:
- Constant Field Values
-
LONG_ADDRESS
- See Also:
- Constant Field Values
-
CONSIST_ADDRESS
- See Also:
- Constant Field Values
-
activeBoards
-
-
Constructor Details
-
Method Details
-
getSensor
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
Get the system connection for this manager. -
createNewSensor
Internal method to invoke the factory and create a new Sensor based on the system name and optional user name, after all the logic for returning an existing Sensor has been invoked.- 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 or null if unsuccessful
-
extractBoardID
This extracts the board id out from the system name.- Parameters:
systemName
- including system prefix and type letter.
-
allowMultipleAdditions
Description copied from class:AbstractSensorManager
Determines if it is possible to add a range of sensors in numerical order.- Specified by:
allowMultipleAdditions
in interfaceSensorManager
- Overrides:
allowMultipleAdditions
in classAbstractSensorManager
- Parameters:
systemName
- the system name to check against; appears to be ignored in all implementations- Returns:
- true if possible; false otherwise
-
createSystemName
@Nonnull public String createSystemName(@Nonnull String curAddress, @Nonnull String prefix) throws JmriExceptionDescription 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.
-
getNextValidAddress
public String getNextValidAddress(@Nonnull String curAddress, @Nonnull String prefix, boolean ignoreInitialExisting) throws JmriExceptionDescription copied from class:AbstractManager
Get the Next valid hardware address. Used by the Turnout / Sensor / Reporter / Light Manager classes.System-specific methods may want to override getIncrement() rather than this one.
- Specified by:
getNextValidAddress
in interfaceSensorManager
- Overrides:
getNextValidAddress
in classAbstractManager<Sensor>
- Parameters:
curAddress
- the starting hardware address to get the next valid from.prefix
- system prefix, just system name, not type letter.ignoreInitialExisting
- false to return the starting address if it does not exist, else true to force an increment.- Returns:
- the next valid system name, excluding both system name prefix and type letter.
- Throws:
JmriException
- if unable to get the current / next address, or more than 10 next addresses in use.
-
notifyReply
-
notifyMessage
-
stopPolling
-
startPolling
-
addBoard
-
reply
- Specified by:
reply
in interfaceDcc4PcListener
-
getInputState
-
getInputState
-
decodeInputState
-
decodeDuplicatePacket
Determining if the railcommdata is duplicated. If it is then this instructs the rc input to move things about.- Parameters:
value
- Railcommand dataseq
- message sequence numberrc
- RailCommand to request action(s) from- Returns:
- value calculated locally
-
pollManager
void pollManager() -
createSensorsFromReply
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
- Specified by:
handleTimeout
in interfaceDcc4PcListener
-
message
- Specified by:
message
in interfaceDcc4PcListener
-
changeBoardAddress
-
getBoards
-
getBoardInputs
-
getBoardEncodingAsString
-
getBoardVersion
-
getBoardDescription
-
isBoardCreated
-
addActiveBoard
-
setBoardDescription
-
createSensorsForBoard
-
validateSystemNameFormat
@Nonnull public String validateSystemNameFormat(@Nonnull String name, @Nonnull Locale locale) throws NamedBean.BadSystemNameExceptionValidates 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
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>
-