Package jmri.jmrix.bachrus.speedmatcher
Class SpeedMatcher
- java.lang.Object
-
- jmri.jmrix.bachrus.speedmatcher.SpeedMatcher
-
- All Implemented Interfaces:
java.util.EventListener,ProgListener,ThrottleListener
- Direct Known Subclasses:
BasicSpeedMatcher,SpeedStepScaleSpeedMatcher
public abstract class SpeedMatcher extends java.lang.Object implements ThrottleListener, ProgListener
Abstract class defining the basic operations of a speed matcher. All speed matcher implementations must extend this class.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classSpeedMatcher.ProgrammerStateprotected static classSpeedMatcher.SpeedMatcherCVstatic classSpeedMatcher.SpeedTableStep-
Nested classes/interfaces inherited from interface jmri.ThrottleListener
ThrottleListener.DecisionType
-
-
Field Summary
Fields Modifier and Type Field Description protected floatALLOWED_SPEED_MATCH_ERRORprotected intattemptprotected floatcurrentSpeedKPHprotected DccLocoAddressdccLocoAddressprotected intINITIAL_MOMENTUMprotected AddressedProgrammeropsModeProgrammerprotected PowerManagerpowerManagerprotected SpeedMatcher.ProgrammerStateprogrammerStateprotected intREVERSE_TRIM_MAXprotected intREVERSE_TRIM_MINprotected floatspeedMatchErrorprotected intspeedMatcherValueDeltaprotected javax.swing.JButtonstartStopButtonprotected javax.swing.JLabelstatusLabelprotected intstepDurationprotected booleantrimReverseSpeedprotected intwarmUpForwardSecondsprotected intwarmUpReverseSeconds-
Fields inherited from interface jmri.ProgListener
CommError, ConfirmFailed, FailedTimeout, NoAck, NoLocoDetected, NotImplemented, OK, ProgrammerBusy, ProgrammingShort, SequenceError, UnknownError, UserAborted
-
-
Constructor Summary
Constructors Constructor Description SpeedMatcher(SpeedMatcherConfig config)Constructor for the abstract SpeedMatcher at the core of any Speed Matcher
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidcleanUpSpeedMatcher()Cleans up the speed matcher when speed matching is stopped or is finishedprotected intgetNextSpeedMatchValue(int lastValue, int max, int min)Gets the next value to try for speed matchingprotected booleaninitializeAndStartSpeedMatcher(java.awt.event.ActionListener timerActionListener)Shared code to initialize the speed matcher's programmer and throttle and start the speed matching timer.abstract booleanisSpeedMatcherIdle()Indicates if the speed matcher is idle (not currently speed matching)voidnotifyDecisionRequired(LocoAddress address, ThrottleListener.DecisionType question)Called when we must decide whether to steal the throttle for the requested address.voidnotifyFailedThrottleRequest(LocoAddress address, java.lang.String reason)Called when a throttle could not be obtainedvoidnotifyThrottleFound(DccThrottle t)Called when a throttle is found Implementers must override, call super, and start speed matcher in implementationvoidprogrammingOpReply(int value, int status)Called when the programmer has completed its operationprotected voidresetSpeedMatcher(int initialValueDelta)Resets the speed matcher with the given value deltaprotected voidsetSpeedMatchError(float speedTarget)Sets the current speed match errorprotected voidsetSpeedMatchStateTimerDuration(int timerDuration)Sets the duration for the speed match timerprotected voidsetThrottle(boolean isForward, int speedStep)Sets the speed matcher's throttle direction and speed safely within timers to protect against executing a throttle change to close to setting a CVabstract booleanstartSpeedMatcher()Starts the speed matching processprotected voidstartSpeedMatchStateTimer()Starts the speed match state timerabstract voidstopSpeedMatcher()Stops the speed matching processprotected voidstopSpeedMatchStateTimer()Stops the speed match state timervoidupdateCurrentSpeed(float currentSpeedKPH)Updates the locomotive's current speed in the speed matcherprotected abstract booleanvalidate()Validates the speed matcher's configurationprotected voidwriteForwardTrim(int value)Starts writing forward trim (CV 66) using the ops mode programmerprotected voidwriteMomentumAccel(int value)Starts writing acceleration momentum (CV 3) using the ops mode programmerprotected voidwriteMomentumDecel(int value)Starts writing deceleration momentum (CV 4) using the ops mode programmerprotected voidwriteReverseTrim(int value)Starts writing reverse trim (CV 95) using the ops mode programmerprotected voidwriteSpeedTableStep(SpeedMatcher.SpeedTableStep step, int value)Starts writing a Speed Table Step CV (CV 67-94) using the ops mode programmerprotected voidwriteVHigh(int value)Starts writing vHigh (CV 5) using the ops mode programmerprotected voidwriteVMid(int value)Starts writing vMid (CV 6) using the ops mode programmerprotected voidwriteVStart(int value)Starts writing vStart (CV 2) using the ops mode programmer
-
-
-
Field Detail
-
INITIAL_MOMENTUM
protected final int INITIAL_MOMENTUM
- See Also:
- Constant Field Values
-
REVERSE_TRIM_MAX
protected final int REVERSE_TRIM_MAX
- See Also:
- Constant Field Values
-
REVERSE_TRIM_MIN
protected final int REVERSE_TRIM_MIN
- See Also:
- Constant Field Values
-
ALLOWED_SPEED_MATCH_ERROR
protected final float ALLOWED_SPEED_MATCH_ERROR
- See Also:
- Constant Field Values
-
attempt
protected int attempt
-
speedMatchError
protected float speedMatchError
-
speedMatcherValueDelta
protected int speedMatcherValueDelta
-
trimReverseSpeed
protected boolean trimReverseSpeed
-
warmUpForwardSeconds
protected int warmUpForwardSeconds
-
warmUpReverseSeconds
protected int warmUpReverseSeconds
-
stepDuration
protected int stepDuration
-
currentSpeedKPH
protected float currentSpeedKPH
-
dccLocoAddress
protected DccLocoAddress dccLocoAddress
-
opsModeProgrammer
protected AddressedProgrammer opsModeProgrammer
-
powerManager
protected PowerManager powerManager
-
statusLabel
protected javax.swing.JLabel statusLabel
-
startStopButton
protected javax.swing.JButton startStopButton
-
programmerState
protected SpeedMatcher.ProgrammerState programmerState
-
-
Constructor Detail
-
SpeedMatcher
public SpeedMatcher(SpeedMatcherConfig config)
Constructor for the abstract SpeedMatcher at the core of any Speed Matcher- Parameters:
config- SpeedMatcherConfig for initializing the SpeedMatcher
-
-
Method Detail
-
startSpeedMatcher
public abstract boolean startSpeedMatcher()
Starts the speed matching process- Returns:
- true if speed matching started successfully, false otherwise
-
stopSpeedMatcher
public abstract void stopSpeedMatcher()
Stops the speed matching process
-
isSpeedMatcherIdle
public abstract boolean isSpeedMatcherIdle()
Indicates if the speed matcher is idle (not currently speed matching)- Returns:
- true if idle, false otherwise
-
updateCurrentSpeed
public void updateCurrentSpeed(float currentSpeedKPH)
Updates the locomotive's current speed in the speed matcher- Parameters:
currentSpeedKPH- the locomotive's current speed in KPH
-
validate
protected abstract boolean validate()
Validates the speed matcher's configuration- Returns:
- true if the configuration is valid, false otherwise
-
cleanUpSpeedMatcher
protected void cleanUpSpeedMatcher()
Cleans up the speed matcher when speed matching is stopped or is finished
-
initializeAndStartSpeedMatcher
protected boolean initializeAndStartSpeedMatcher(java.awt.event.ActionListener timerActionListener)
Shared code to initialize the speed matcher's programmer and throttle and start the speed matching timer. Expected to be called in an implementing speed matcher's Start function.- Parameters:
timerActionListener- callback to fire when the timer times out- Returns:
- true if initialization and start is successful, false otherwise
-
startSpeedMatchStateTimer
protected void startSpeedMatchStateTimer()
Starts the speed match state timer
-
stopSpeedMatchStateTimer
protected void stopSpeedMatchStateTimer()
Stops the speed match state timer
-
setSpeedMatchStateTimerDuration
protected void setSpeedMatchStateTimerDuration(int timerDuration)
Sets the duration for the speed match timer- Parameters:
timerDuration- timer duration in milliseconds
-
setThrottle
protected void setThrottle(boolean isForward, int speedStep)
Sets the speed matcher's throttle direction and speed safely within timers to protect against executing a throttle change to close to setting a CV- Parameters:
isForward- true for forward, false for reversspeedStep- 0-28 or 0-128 depending on mode
-
setSpeedMatchError
protected void setSpeedMatchError(float speedTarget)
Sets the current speed match error- Parameters:
speedTarget- - target speed in KPH
-
getNextSpeedMatchValue
protected int getNextSpeedMatchValue(int lastValue, int max, int min)
Gets the next value to try for speed matching- Parameters:
lastValue- the last speed match CV value triedmax- the maximum valuemin- the minimum value- Returns:
- the next value to try for speed matching [min:max]
-
resetSpeedMatcher
protected void resetSpeedMatcher(int initialValueDelta)
Resets the speed matcher with the given value delta- Parameters:
initialValueDelta- the value delta to use for the next use of the speed matcher
-
writeVStart
protected void writeVStart(int value)
Starts writing vStart (CV 2) using the ops mode programmer- Parameters:
value- vStart value (0-255 inclusive)
-
writeVMid
protected void writeVMid(int value)
Starts writing vMid (CV 6) using the ops mode programmer- Parameters:
value- vMid value (0-255 inclusive)
-
writeVHigh
protected void writeVHigh(int value)
Starts writing vHigh (CV 5) using the ops mode programmer- Parameters:
value- vHigh value (0-255 inclusive)
-
writeMomentumAccel
protected void writeMomentumAccel(int value)
Starts writing acceleration momentum (CV 3) using the ops mode programmer- Parameters:
value- acceleration value (0-255 inclusive)
-
writeMomentumDecel
protected void writeMomentumDecel(int value)
Starts writing deceleration momentum (CV 4) using the ops mode programmer- Parameters:
value- deceleration value (0-255 inclusive)
-
writeForwardTrim
protected void writeForwardTrim(int value)
Starts writing forward trim (CV 66) using the ops mode programmer- Parameters:
value- forward trim value (0-255 inclusive)
-
writeReverseTrim
protected void writeReverseTrim(int value)
Starts writing reverse trim (CV 95) using the ops mode programmer- Parameters:
value- reverse trim value (0-255 inclusive)
-
writeSpeedTableStep
protected void writeSpeedTableStep(SpeedMatcher.SpeedTableStep step, int value)
Starts writing a Speed Table Step CV (CV 67-94) using the ops mode programmer- Parameters:
step- the SpeedTableStep to setvalue- speed table step value (0-255 inclusive)
-
programmingOpReply
public void programmingOpReply(int value, int status)
Called when the programmer has completed its operation- Specified by:
programmingOpReplyin interfaceProgListener- Parameters:
value- value from a read operation, or value written on a writestatus- denotes the completion code. Note that this is a bitwise combination of the various states codes defined in this interface. (see ProgListener.java for possible values)
-
notifyThrottleFound
public void notifyThrottleFound(DccThrottle t)
Called when a throttle is found Implementers must override, call super, and start speed matcher in implementation- Specified by:
notifyThrottleFoundin interfaceThrottleListener- Parameters:
t- the requested DccThrottle
-
notifyDecisionRequired
public void notifyDecisionRequired(LocoAddress address, ThrottleListener.DecisionType question)
Called when we must decide whether to steal the throttle for the requested address. This is an automatically stealing implementation, so the throttle will be automatically stolen- Specified by:
notifyDecisionRequiredin interfaceThrottleListener- Parameters:
address- the requested addressquestion- the question being asked, steal / cancel, share / cancel, steal / share / cancel
-
notifyFailedThrottleRequest
public void notifyFailedThrottleRequest(LocoAddress address, java.lang.String reason)
Called when a throttle could not be obtained- Specified by:
notifyFailedThrottleRequestin interfaceThrottleListener- Parameters:
address- the requested addressreason- the reason the throttle could not be obtained
-
-