Class MultiIndexProgrammerFacade
- java.lang.Object
-
- jmri.jmrix.AbstractProgrammerFacade
-
- jmri.implementation.MultiIndexProgrammerFacade
-
- All Implemented Interfaces:
java.util.EventListener
,Disposable
,ProgListener
,Programmer
public class MultiIndexProgrammerFacade extends AbstractProgrammerFacade implements ProgListener
Programmer facade for accessing CVs that require one or more "index CVs" to have specific values before doing the final read or write operation.Currently supports direct access to CVs (the usual style), operations where one index CV (called PI, for primary index) must have a specific value first, and operations where two index CVs (called PI and SI, for secondary index) must have a specific value first.
Accepts two different address formats so that the CV addresses can be written in the same style as the decoder manufacturer's documentation:
- If cvFirst is true:
- 123 Do read or write directly to CV 123; this allows unindexed CVs to go through
- 123.11 Writes 11 to PI, the index CV, then does the final read or write to CV 123
- 123.11.12 Writes 11 to the first index CV, then 12 to the second index CV, then does the final read or write to CV 123
- If cvFirst is false:
- 123 Do read or write directly to CV 123; this allows unindexed CVs to go through
- 11.123 Writes 11 to the first index CV, then does the final read or write to CV 123
- 11.12.123 Writes 11 to the first index CV, then 12 to the second index CV, then does the final read or write to CV 123
The specific CV numbers for PI and SI are provided when constructing the object. They can be read from a decoder definition file by e.g.
ProgrammerFacadeSelector
.Alternately the PI and/or SI CV numbers can be set by using a "nn=nn" syntax when specifying PI and/or SI. For example, using a cvFirst false syntax, "101=12.80" sets CV101 to 12 before accessing CV 80, regardless of the PI value configured into the facade.
If skipDupIndexWrite is true, sequential operations with the same PI and SI values (and only immediately sequential operations with both PI and SI unchanged) will skip writing of the PI and SI CVs. This might not work for some decoders, hence is configurable. See the logic in
ProgrammerFacadeSelector
for how the decoder file contents and default (preferences) interact.State Diagram for read and write operations (click to magnify):
- See Also:
ProgrammerFacadeSelector
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
MultiIndexProgrammerFacade.ProgState
-
Nested classes/interfaces inherited from interface jmri.Programmer
Programmer.WriteConfirmMode
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.lang.String
_cv
(package private) int
_startVal
(package private) int
_val
(package private) boolean
cvFirst
(package private) java.lang.String
defaultIndexPI
(package private) java.lang.String
defaultIndexSI
(package private) java.lang.String
indexPI
(package private) java.lang.String
indexSI
(package private) long
lastOpTime
(package private) int
lastValuePI
(package private) int
lastValueSI
(package private) long
maxDelay
(package private) boolean
skipDupIndexWrite
(package private) MultiIndexProgrammerFacade.ProgState
state
(package private) int
valuePI
(package private) int
valueSI
-
Fields inherited from class jmri.jmrix.AbstractProgrammerFacade
prog
-
Fields inherited from interface jmri.ProgListener
CommError, ConfirmFailed, FailedTimeout, NoAck, NoLocoDetected, NotImplemented, OK, ProgrammerBusy, ProgrammingShort, SequenceError, UnknownError, UserAborted
-
-
Constructor Summary
Constructors Constructor Description MultiIndexProgrammerFacade(Programmer prog, java.lang.String indexPI, java.lang.String indexSI, boolean cvFirst, boolean skipDupIndexWrite)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
confirmCV(java.lang.String CV, int val, ProgListener p)
Confirm the value of a CV using the specified programming mode.(package private) java.lang.String
getAlternateAddress(java.lang.String cv)
(package private) int
getAlternateValue(java.lang.String cv)
(package private) boolean
hasAlternateAddress(java.lang.String cv)
(package private) void
parseCV(java.lang.String cv)
void
programmingOpReply(int value, int status)
Receive a callback at the end of a programming operation.void
readCV(java.lang.String CV, ProgListener p)
Perform a CV read in the system-specific manner, and using the specified programming mode.void
readCV(java.lang.String CV, ProgListener p, int startVal)
Perform a CV read in the system-specific manner, and using the specified programming mode, possibly using a hint of the current value to speed up programming.(package private) boolean
useCachePiSi()
Check if the last-written PI and SI values can still be counted on.protected void
useProgrammer(ProgListener p)
void
writeCV(java.lang.String CV, int val, ProgListener p)
Perform a CV write in the system-specific manner, and using the specified programming mode.-
Methods inherited from class jmri.jmrix.AbstractProgrammerFacade
addPropertyChangeListener, decodeErrorCode, getCanRead, getCanRead, getCanWrite, getCanWrite, getMode, getSupportedModes, getWriteConfirmMode, removePropertyChangeListener, setMode
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jmri.Programmer
dispose, notifyProgListenerEnd
-
-
-
-
Field Detail
-
defaultIndexPI
java.lang.String defaultIndexPI
-
defaultIndexSI
java.lang.String defaultIndexSI
-
indexPI
java.lang.String indexPI
-
indexSI
java.lang.String indexSI
-
cvFirst
boolean cvFirst
-
skipDupIndexWrite
boolean skipDupIndexWrite
-
maxDelay
long maxDelay
-
_val
int _val
-
_cv
java.lang.String _cv
-
valuePI
int valuePI
-
valueSI
int valueSI
-
_startVal
int _startVal
-
lastValuePI
int lastValuePI
-
lastValueSI
int lastValueSI
-
lastOpTime
long lastOpTime
-
-
Constructor Detail
-
MultiIndexProgrammerFacade
public MultiIndexProgrammerFacade(Programmer prog, java.lang.String indexPI, java.lang.String indexSI, boolean cvFirst, boolean skipDupIndexWrite)
- Parameters:
prog
- the programmer to which this facade is attachedindexPI
- CV to which the first value is to be written for NN.NN and NN.NN.NN formsindexSI
- CV to which the second value is to be written for NN.NN.NN formscvFirst
- true if first value in parsed CV is to be written; false if second value is to be writtenskipDupIndexWrite
- true if heuristics can be used to skip PI and SI writes; false requires them to be written each time.
-
-
Method Detail
-
parseCV
void parseCV(java.lang.String cv)
-
hasAlternateAddress
boolean hasAlternateAddress(java.lang.String cv)
-
getAlternateAddress
java.lang.String getAlternateAddress(java.lang.String cv)
-
getAlternateValue
int getAlternateValue(java.lang.String cv)
-
useCachePiSi
boolean useCachePiSi()
Check if the last-written PI and SI values can still be counted on.- Returns:
- true if last-written values are reliable; false otherwise
-
writeCV
public void writeCV(java.lang.String CV, int val, ProgListener p) throws ProgrammerException
Description copied from class:AbstractProgrammerFacade
Perform a CV write in the system-specific manner, and using the specified programming mode.Handles a general address space through a String address. Each programmer defines the acceptable formats.
Note that this returns before the write is complete; you have to provide a ProgListener to hear about completion. For simplicity, expect the return to be on the GUI thread.
Exceptions will only be thrown at the start, not during the actual programming sequence. A typical exception would be due to an invalid mode (though that should be prevented earlier)
- Specified by:
writeCV
in interfaceProgrammer
- Overrides:
writeCV
in classAbstractProgrammerFacade
- Parameters:
CV
- the CV to writeval
- the value to writep
- the listener that will be notified of the write- Throws:
ProgrammerException
- if unable to communicate
-
readCV
public void readCV(java.lang.String CV, ProgListener p) throws ProgrammerException
Description copied from class:AbstractProgrammerFacade
Perform a CV read in the system-specific manner, and using the specified programming mode.Handles a general address space through a String address. Each programmer defines the acceptable formats.
Note that this returns before the write is complete; you have to provide a ProgListener to hear about completion. For simplicity, expect the return to be on the GUI thread.
Exceptions will only be thrown at the start, not during the actual programming sequence. A typical exception would be due to an invalid mode (though that should be prevented earlier)
- Specified by:
readCV
in interfaceProgrammer
- Overrides:
readCV
in classAbstractProgrammerFacade
- Parameters:
CV
- the CV to readp
- the listener that will be notified of the read- Throws:
ProgrammerException
- if unable to communicate
-
readCV
public void readCV(java.lang.String CV, ProgListener p, int startVal) throws ProgrammerException
Description copied from interface:Programmer
Perform a CV read in the system-specific manner, and using the specified programming mode, possibly using a hint of the current value to speed up programming.Handles a general address space through a String address. Each programmer defines the acceptable formats.
On systems that support it, the startVal is a hint as to what the current value of the CV might be (e.g. the value from the roster). This could be verified immediately in direct byte mode to speed up the read process.
Note that this returns before the write is complete; you have to provide a ProgListener to hear about completion. For simplicity, expect the return to be on the GUI thread.
Defaults to the normal read method if not overridden in a specific implementation.
Exceptions will only be thrown at the start, not during the actual programming sequence. A typical exception would be due to an invalid mode (though that should be prevented earlier)
- Specified by:
readCV
in interfaceProgrammer
- Parameters:
CV
- the CV to readp
- the listener that will be notified of the readstartVal
- a hint of what the current value might be, or 0- Throws:
ProgrammerException
- if unable to communicate
-
confirmCV
public void confirmCV(java.lang.String CV, int val, ProgListener p) throws ProgrammerException
Description copied from class:AbstractProgrammerFacade
Confirm the value of a CV using the specified programming mode. On some systems, this is faster than a read.Handles a general address space through a String address. Each programmer defines the acceptable formats.
Note that this returns before the write is complete; you have to provide a ProgListener to hear about completion. For simplicity, expect the return to be on the GUI thread.
Exceptions will only be thrown at the start, not during the actual programming sequence. A typical exception would be due to an invalid mode (though that should be prevented earlier)
- Specified by:
confirmCV
in interfaceProgrammer
- Overrides:
confirmCV
in classAbstractProgrammerFacade
- Parameters:
CV
- the CV to confirmval
- the value to confirmp
- the listener that will be notified of the confirmation- Throws:
ProgrammerException
- if unable to communicate
-
useProgrammer
protected void useProgrammer(ProgListener p) throws ProgrammerException
- Throws:
ProgrammerException
-
programmingOpReply
public void programmingOpReply(int value, int status)
Description copied from interface:ProgListener
Receive a callback at the end of a programming operation.- Specified by:
programmingOpReply
in 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 status coded defined in this interface.
-
-