Class LnClockControl
- java.lang.Object
-
- jmri.implementation.DefaultClockControl
-
- jmri.jmrix.loconet.LnClockControl
-
- All Implemented Interfaces:
java.util.EventListener
,ClockControl
,SlotListener
public class LnClockControl extends DefaultClockControl implements SlotListener
Implementation of the Hardware Fast Clock for LocoNet.This module is based on a GUI module developed by Bob Jacobsen and Alex Shepherd to correct the LocoNet fast clock rate and synchronize it with the internal JMRI fast clock Timebase. The methods that actually send, correct, or receive information from the LocoNet hardware are repackaged versions of their code.
The LocoNet Fast Clock is controlled by the user via the Fast Clock Setup GUI that is accessed from the JMRI Tools menu.
For this implementation, "synchronize" implies "correct", since the two clocks run at a different rate.
Some of the message formats used in this class are Copyright Digitrax, Inc. and used with permission as part of the JMRI project. That permission does not extend to uses in other software products. If you wish to use this code, algorithm or these message formats outside of JMRI, please contact Digitrax Inc for separate permission.
This file is part of JMRI.JMRI is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. See the "COPYING" file for a copy of this license.
JMRI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) Timebase
clock
(package private) static double
CORRECTION
(package private) java.beans.PropertyChangeListener
minuteChangeListener
(package private) static long
MSECPERHOUR
(package private) static long
MSECPERMINUTE
(package private) LnPowerManager
pm
(package private) SlotManager
sm
(package private) LnTrafficController
tc
-
Constructor Summary
Constructors Constructor Description LnClockControl(LocoNetSystemConnectionMemo scm)
Create a ClockControl object for a LocoNet clock.LnClockControl(SlotManager sm, LnTrafficController tc, LnPowerManager pm)
Create a ClockControl object for a LocoNet clock.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canCorrectHardwareClock()
Returns true if hardware clock accuracy can be corrected using the computer clock.void
dispose()
java.lang.String
getHardwareClockName()
Accessor routinesdouble
getRate()
Default implementation returns the rate of the internal clock.java.util.Date
getTime()
Default implementation returns InstanceM default jmri.Timebase getTime().void
initializeHardwareClock(double rate, java.util.Date now, boolean getTime)
Default implementation is to ignore this request.void
initiateRead()
Requests read of the LocoNet fast clockvoid
newMinute()
Corrects the LocoNet Fast Clockvoid
notifyChangedSlot(LocoNetSlot s)
Handle changed slot contents, due to clock changes.boolean
requiresIntegerRate()
Default implementation returns false.void
setRate(double newRate)
For the default implementation, setRate is ignored.void
setTime(java.util.Date now)
For the default implementation, set time is ignored.void
startHardwareClock(java.util.Date now)
Default implementation is to call SetTime to now.void
stopHardwareClock()
Default implementation is to ignore.-
Methods inherited from class jmri.implementation.DefaultClockControl
canSet12Or24HourClock, getStatus
-
-
-
-
Field Detail
-
sm
final SlotManager sm
-
tc
final LnTrafficController tc
-
pm
final LnPowerManager pm
-
minuteChangeListener
java.beans.PropertyChangeListener minuteChangeListener
-
MSECPERHOUR
static final long MSECPERHOUR
- See Also:
- Constant Field Values
-
MSECPERMINUTE
static final long MSECPERMINUTE
- See Also:
- Constant Field Values
-
CORRECTION
static final double CORRECTION
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
LnClockControl
public LnClockControl(LocoNetSystemConnectionMemo scm)
Create a ClockControl object for a LocoNet clock.- Parameters:
scm
- the LocoNet System Connection Memo to associate with this Clock Control object
-
LnClockControl
public LnClockControl(SlotManager sm, LnTrafficController tc, LnPowerManager pm)
Create a ClockControl object for a LocoNet clock.- Parameters:
sm
- the Slot Manager associated with this objecttc
- the Traffic Controller associated with this objectpm
- the PowerManager associated with this object
-
-
Method Detail
-
getHardwareClockName
public java.lang.String getHardwareClockName()
Accessor routines- Specified by:
getHardwareClockName
in interfaceClockControl
- Overrides:
getHardwareClockName
in classDefaultClockControl
- Returns:
- the associated name
-
canCorrectHardwareClock
public boolean canCorrectHardwareClock()
Description copied from class:DefaultClockControl
Returns true if hardware clock accuracy can be corrected using the computer clock.Hardware implementations should override this and return true if they can correct their hardware clock. Returns true if hardware clock accuracy can be corrected using the computer clock.
- Specified by:
canCorrectHardwareClock
in interfaceClockControl
- Overrides:
canCorrectHardwareClock
in classDefaultClockControl
- Returns:
- true if correctable; false otherwise
-
setRate
public void setRate(double newRate)
Description copied from class:DefaultClockControl
For the default implementation, setRate is ignored. Set the rate of the Fast Clock.The rate is a number that multiplies the wall clock time For example, a rate of 4 specifies that the fast clock runs 4 times faster than the wall clock.
- Specified by:
setRate
in interfaceClockControl
- Overrides:
setRate
in classDefaultClockControl
- Parameters:
newRate
- the new rate
-
requiresIntegerRate
public boolean requiresIntegerRate()
Description copied from class:DefaultClockControl
Default implementation returns false.If an integer rate is required by the hardware, this method should be overridden. Returns true if hardware clock requires an integer rate.
- Specified by:
requiresIntegerRate
in interfaceClockControl
- Overrides:
requiresIntegerRate
in classDefaultClockControl
- Returns:
- true if integer rates only; false otherwise
-
getRate
public double getRate()
Description copied from class:DefaultClockControl
Default implementation returns the rate of the internal clock. Get the rate of the Fast Clock.The rate is a number that multiplies the wall clock. For example, a rate of 4 specifies that the fast clock runs 4 times faster than the wall clock.
- Specified by:
getRate
in interfaceClockControl
- Overrides:
getRate
in classDefaultClockControl
- Returns:
- Fast Clock rate.
-
setTime
public void setTime(java.util.Date now)
Description copied from class:DefaultClockControl
For the default implementation, set time is ignored. Set the fast clock time.- Specified by:
setTime
in interfaceClockControl
- Overrides:
setTime
in classDefaultClockControl
- Parameters:
now
- the new time
-
getTime
public java.util.Date getTime()
Description copied from class:DefaultClockControl
Default implementation returns InstanceM default jmri.Timebase getTime(). ie. the time of the internal clock. Get the fast clock time.- Specified by:
getTime
in interfaceClockControl
- Overrides:
getTime
in classDefaultClockControl
- Returns:
- current time.
-
startHardwareClock
public void startHardwareClock(java.util.Date now)
Description copied from class:DefaultClockControl
Default implementation is to call SetTime to now. Start hardware fast clock Some hardware fast clocks continue to run indefinitely. This is provided for the case where the hardware clock can be stopped and started.- Specified by:
startHardwareClock
in interfaceClockControl
- Overrides:
startHardwareClock
in classDefaultClockControl
- Parameters:
now
- the starting time
-
stopHardwareClock
public void stopHardwareClock()
Description copied from class:DefaultClockControl
Default implementation is to ignore. Stop hardware fast clock. This is provided for the case where the hardware clock can be stopped and started.- Specified by:
stopHardwareClock
in interfaceClockControl
- Overrides:
stopHardwareClock
in classDefaultClockControl
-
initializeHardwareClock
public void initializeHardwareClock(double rate, java.util.Date now, boolean getTime)
Description copied from class:DefaultClockControl
Default implementation is to ignore this request. Initialize the hardware fast clock Note: When the hardware clock control receives this, it should initialize those clock settings that are available on the hardware clock. This method is used when the fast clock is started, and when time source, synchronize, or correct options are changed. If rate is 0.0, the hardware clock should be initialized "stopped", and the current rate saved for when the clock is restarted. If getTime is "true" the time from the hardware clock should be used in place of the supplied time if possible.- Specified by:
initializeHardwareClock
in interfaceClockControl
- Overrides:
initializeHardwareClock
in classDefaultClockControl
- Parameters:
rate
- the ratenow
- the timegetTime
- true if hardware clock should be used; false otherwise
-
initiateRead
public void initiateRead()
Requests read of the LocoNet fast clock
-
newMinute
public void newMinute()
Corrects the LocoNet Fast Clock
-
notifyChangedSlot
public void notifyChangedSlot(LocoNetSlot s)
Handle changed slot contents, due to clock changes. Can get here three ways: 1) clock slot as a result of action by a throttle and 2) clock slot responding to a read from this module 3) a slot not involving the clock changing.- Specified by:
notifyChangedSlot
in interfaceSlotListener
- Parameters:
s
- the LocoNetSlot object which has been changed
-
dispose
public void dispose()
-
-