|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjmri.jmrix.AbstractProgrammer
jmri.jmrix.loconet.SlotManager
public class SlotManager
Controls a collection of slots, acting as the counter-part of a LocoNet command station.
A SlotListener can register to hear changes. By registering here, the SlotListener is saying that it wants to be notified of a change in any slot. Alternately, the SlotListener can register with some specific slot, done via the LocoNetSlot object itself.
Strictly speaking, functions 9 through 28 are not in the
actual slot, but it's convenient to imagine there's an
"extended slot" and keep track of them here. This is a
partial implementation, though, because setting is still
done directly in LocoNetThrottle. In particular,
if this slot has not been read from the command station,
the first message directly setting F9 through F28 will
not have a place to store information. Instead, it will
trigger a slot read, so the following messages
will be properly handled.
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 Programmer implementation is single-user only. It's not clear whether the command stations can have multiple programming requests outstanding (e.g. service mode and ops mode, or two ops mode) at the same time, but this code definitely can't.
| Field Summary | |
|---|---|
protected int |
_mode
Records the current mode of the Programmer implementation. |
protected String |
commandStationType
|
protected int |
nextReadSlot
|
| Fields inherited from class jmri.jmrix.AbstractProgrammer |
|---|
LONG_TIMEOUT, propListeners, SHORT_TIMEOUT |
| Fields inherited from interface jmri.Programmer |
|---|
ADDRESSMODE, DIRECTBITMODE, DIRECTBYTEMODE, NONE, OPSACCBITMODE, OPSACCBYTEMODE, OPSACCEXTBITMODE, OPSACCEXTBYTEMODE, OPSBITMODE, OPSBYTEMODE, PAGEMODE, REGISTERMODE |
| Constructor Summary | |
|---|---|
SlotManager()
|
|
| Method Summary | |
|---|---|
void |
addSlotListener(SlotListener l)
|
void |
confirmCV(int CV,
int val,
ProgListener p)
Confirm the value of a CV using the specified programming mode. |
void |
confirmCVOpsMode(int CV,
int val,
ProgListener p,
int addr,
boolean longAddr)
|
void |
doConfirm(int CV,
int val,
ProgListener p,
int pcmd)
|
protected void |
doPowerOn()
Internal routine to handle a timeout & turn power off |
void |
doWrite(int CV,
int val,
ProgListener p,
int pcmd)
|
int |
findSlotFromMessage(LocoNetMessage m)
FInd the slot number that a message references |
void |
forwardMessageToSlot(LocoNetMessage m,
int i)
|
boolean |
getCanRead()
Determine whether this Programmer implementation is capable of reading decoder contents. |
String |
getCommandStationType()
Get the command station type |
int |
getInUseCount()
Provide a snapshot of the slots in use |
int |
getMode()
Get the current mode of the Programmer implementation. |
boolean |
getProgPowersOff()
Determine whether this Programmer implementation powers off the main track after a service track programming operation. |
boolean |
hasMode(int mode)
Determine is a mode is available for this Programmer implementation |
static SlotManager |
instance()
method to find the existing SlotManager object, if need be creating one |
void |
message(LocoNetMessage m)
Listen to the LocoNet. |
protected void |
notify(LocoNetSlot s)
Trigger the notification of all SlotListeners. |
protected void |
notifyProgListenerEnd(int value,
int status)
internal method to notify of the final result |
protected void |
notifyProgListenerLack(int status)
Internal method to notify of the LACK result. |
protected void |
notifyPropertyChange(String name,
int oldval,
int newval)
Trigger notification of PropertyChangeListeners. |
protected void |
programmerOpMessage(LocoNetMessage m,
int i)
|
protected LocoNetMessage |
progTaskStart(int pcmd,
int val,
int cvnum,
boolean write)
Internal method to create the LocoNetMessage for programmer task start |
void |
readCV(int CV,
ProgListener p)
Perform a CV read in the system-specific manner, and using the specified programming mode. |
void |
readCVOpsMode(int CV,
ProgListener p,
int addr,
boolean longAddr)
Invoked by LnOpsModeProgrammer to start an ops-mode read operation. |
protected void |
readNextSlot()
|
void |
removeSlotListener(SlotListener l)
|
protected void |
respondToAddrRequest(LocoNetMessage m,
int i)
|
protected void |
restartPowerTimer()
Internal routine to handle timer restart if needed to restore power. |
void |
sendPacket(byte[] packet,
int repeats)
Send a DCC packet to the rails. |
protected void |
sendProgrammingReply(ProgListener p,
int value,
int status)
Internal routine to forward a programing reply. |
void |
sendReadSlot(int slot)
Send a message requesting the data from a particular slot. |
void |
setCanRead(boolean pCanRead)
Configure whether this Programmer implementation is capable of reading decoder contents. |
void |
setCommandStationType(String value)
Set the command station type |
void |
setMode(int mode)
Set the mode of the Programmer implementation. |
void |
setProgPowersOff(boolean pProgPowersOff)
Configure whether this Programmer owers off the main track after a service track programming operation. |
LocoNetSlot |
slot(int i)
Access the information in a specific slot. |
void |
slotFromLocoAddress(int i,
SlotListener l)
Obtain a slot for a particular loco address. |
protected void |
stopPowerTimer()
Internal routine to stop power timer, as another programming operation has happened |
protected void |
timeout()
Internal routine to handle a timeout |
void |
update()
Start the process of checking each slot for contents. |
protected void |
useProgrammer(ProgListener p)
|
void |
writeCV(int CV,
int val,
ProgListener p)
Perform a CV write in the system-specific manner, and using the specified programming mode. |
void |
writeCVOpsMode(int CV,
int val,
ProgListener p,
int addr,
boolean longAddr)
|
| Methods inherited from class jmri.jmrix.AbstractProgrammer |
|---|
addPropertyChangeListener, decodeErrorCode, registerFromCV, removePropertyChangeListener, restartTimer, startLongTimer, startShortTimer, stopTimer |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected int _mode
protected String commandStationType
protected int nextReadSlot
| Constructor Detail |
|---|
public SlotManager()
| Method Detail |
|---|
public void sendPacket(byte[] packet,
int repeats)
sendPacket in interface CommandStationpacket - repeats - Number of times to repeat the transmission.public LocoNetSlot slot(int i)
i - Specific slot, counted starting from zero.
public void slotFromLocoAddress(int i,
SlotListener l)
This requires access to the command station, even if the locomotive address appears in the current contents of the slot array, to ensure that our local image is up-to-date.
This method sends an info request. When the echo of this is returned from the LocoNet, the next slot-read is recognized as the response.
The object that's looking for this information must provide a SlotListener to notify when the slot ID becomes available.
The SlotListener is not subscribed for slot notifications; it can do that later if it wants. We don't currently think that's a race condition.
i - Specific slot, counted starting from zero.l - The SlotListener to notify of the answer.public static final SlotManager instance()
public void addSlotListener(SlotListener l)
public void removeSlotListener(SlotListener l)
protected void notify(LocoNetSlot s)
s - The changed slot to notify.public void message(LocoNetMessage m)
message in interface LocoNetListenerm - incoming messagepublic int findSlotFromMessage(LocoNetMessage m)
public void forwardMessageToSlot(LocoNetMessage m,
int i)
protected void respondToAddrRequest(LocoNetMessage m,
int i)
protected void programmerOpMessage(LocoNetMessage m,
int i)
public void setMode(int mode)
setMode in interface Programmermode - A mode constant from the Programmer interfacepublic int getMode()
getMode in interface Programmer
protected void notifyPropertyChange(String name,
int oldval,
int newval)
name - Changed propertyoldval - newval - public boolean getProgPowersOff()
public void setProgPowersOff(boolean pProgPowersOff)
This is not part of the Programmer interface, but is used as part of the startup sequence for the LocoNet objects.
pProgPowersOff - True if power is off afterwardpublic boolean getCanRead()
getCanRead in interface Programmerpublic void setCanRead(boolean pCanRead)
This is not part of the Programmer interface, but is used as part of the startup sequence for the LocoNet objects.
pCanRead - True if reads are possiblepublic void setCommandStationType(String value)
public String getCommandStationType()
public boolean hasMode(int mode)
hasMode in interface Programmermode - A mode constant from the Programmer interface
protected void timeout()
timeout in class AbstractProgrammer
public void writeCVOpsMode(int CV,
int val,
ProgListener p,
int addr,
boolean longAddr)
throws ProgrammerException
ProgrammerException
public void writeCV(int CV,
int val,
ProgListener p)
throws ProgrammerException
Programmer
writeCV in interface ProgrammerProgrammerException
public void doWrite(int CV,
int val,
ProgListener p,
int pcmd)
throws ProgrammerException
ProgrammerException
public void confirmCVOpsMode(int CV,
int val,
ProgListener p,
int addr,
boolean longAddr)
throws ProgrammerException
ProgrammerException
public void confirmCV(int CV,
int val,
ProgListener p)
throws ProgrammerException
Programmer
confirmCV in interface ProgrammerProgrammerException
public void doConfirm(int CV,
int val,
ProgListener p,
int pcmd)
throws ProgrammerException
ProgrammerException
public void readCVOpsMode(int CV,
ProgListener p,
int addr,
boolean longAddr)
throws ProgrammerException
CV - Which CV to readp - Who to notify on completeaddr - Address of the locomotivelongAddr - true if a long address, false if short address
ProgrammerException
public void readCV(int CV,
ProgListener p)
throws ProgrammerException
Programmer
readCV in interface ProgrammerProgrammerException
protected void useProgrammer(ProgListener p)
throws ProgrammerException
ProgrammerException
protected LocoNetMessage progTaskStart(int pcmd,
int val,
int cvnum,
boolean write)
throws ProgrammerException
ProgrammerException
protected void notifyProgListenerEnd(int value,
int status)
value - The cv value to be returnedstatus - The error code, if anyprotected void notifyProgListenerLack(int status)
status - The error code, if any
protected void sendProgrammingReply(ProgListener p,
int value,
int status)
value - the value to returnstatus - The error code, if anyprotected void stopPowerTimer()
protected void restartPowerTimer()
protected void doPowerOn()
public void update()
This is not invoked by this class, but can be invoked from elsewhere to start the process of scanning all slots to update their contents.
public void sendReadSlot(int slot)
slot - Slot numberprotected void readNextSlot()
public int getInUseCount()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||