Package jmri.jmrix.loconet.uhlenbrock
Class LncvMessageContents
- java.lang.Object
-
- jmri.jmrix.loconet.uhlenbrock.LncvMessageContents
-
public class LncvMessageContents extends java.lang.Object
Supporting class for Uhlenbrock LocoNet LNCV Programming and Direct Format messaging. Structure adapted fromLnSv2MessageContents
Some of the message formats used in this class are Copyright Uhlenbrock.de 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 Uhlenbrock.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LncvMessageContents.LncvCommand
LNCV Commands mapped to unique sets of 3 parts in message.
-
Field Summary
-
Constructor Summary
Constructors Constructor Description LncvMessageContents(LocoNetMessage m)
Create a new LncvMessageContents object from a LocoNet message.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static LocoNetMessage
createAllProgEndRequest(int articleNum)
Create LocoNet broadcast message to end LNCV programming.static LocoNetMessage
createAllProgStartRequest(int articleNum)
Create LocoNet broadcast message to start LNCV programming.static LocoNetMessage
createCvReadRequest(int articleNum, int moduleAddress, int cvNum)
Create LocoNet message for a query of a CV of this object.static LocoNetMessage
createCvWriteRequest(int articleNum, int cvNum, int newValue)
Create LocoNet message for a write to a CV of this object.static LocoNetMessage
createDirectWriteRequest(int moduleAddress, int ledValue, boolean range2)
Create LocoNet message to set aseries of Track-Control module display LEDs.static LocoNetMessage
createLncvMessage(int opc, int source, int destination, int command, int articleNum, int cvNum, int moduleNum, int cmdData)
Create a LocoNet message containing an LNCV Programming Format message.static LocoNetMessage
createLncvMessage(int source, int destination, LncvMessageContents.LncvCommand command, int articleNum, int cvNum, int moduleNum)
Create LNCV message fromLncvMessageContents.LncvCommand
enum plus specific parameter values.static LocoNetMessage
createLncvProgStartReply(LocoNetMessage m)
In Hexfile simulation mode, mock a ProgStart reply message back to the CS.static LocoNetMessage
createLncvReadReply(LocoNetMessage m)
In Hexfile simulation mode, mock a ReadReply message back to the CS (when simulate replies is ON).static LocoNetMessage
createModProgEndRequest(int articleNum, int moduleAddress)
Create LocoNet message to leave programming of this module.static LocoNetMessage
createModProgStartRequest(int articleNum, int moduleAddress)
Create LocoNet message for first query of a CV of this module.static LncvMessageContents.LncvCommand
extractMessageType(LocoNetMessage m)
Interpret a LocoNet message to determine its LNCV compound Programming Format.int
getCmd()
int
getCvNum()
int
getCvValue()
int
getLncvArticleNum()
int
getLncvModuleNum()
static boolean
isLnMessageASpecificLncvCommand(LocoNetMessage m, LncvMessageContents.LncvCommand lncvCmd)
Compare reply message against a specific LNCV Programming Format message type.boolean
isSupportedLncvCommand()
Confirm a message corresponds with a valid (known) LNCV Programming Format command.static boolean
isSupportedLncvCommand(int command, int opc, int cmdData)
Check set of parameters against compoundLncvMessageContents.LncvCommand
enum set.static boolean
isSupportedLncvMessage(LocoNetMessage m)
Check a LocoNet message to determine if it is a valid LNCV Programming Format message.boolean
isSupportedLncvReadReply()
java.lang.String
toString()
Interpret the LNCV Programming Format message into a human-readable string.java.lang.String
toString(java.util.Locale locale)
Interpret the LNCV Programming Format message into a human-readable string.
-
-
-
Field Detail
-
LNCV_LENGTH_ELEMENT_VALUE
public static final int LNCV_LENGTH_ELEMENT_VALUE
- See Also:
- Constant Field Values
-
LNCV_LNMODULE_VALUE
public static final int LNCV_LNMODULE_VALUE
- See Also:
- Constant Field Values
-
LNCV_CS_SRC_VALUE
public static final int LNCV_CS_SRC_VALUE
- See Also:
- Constant Field Values
-
LNCV_PC_SRC_VALUE
public static final int LNCV_PC_SRC_VALUE
- See Also:
- Constant Field Values
-
LNCV_CSDEST_VALUE
public static final int LNCV_CSDEST_VALUE
- See Also:
- Constant Field Values
-
LNCV_ALL
public static final int LNCV_ALL
- See Also:
- Constant Field Values
-
LNCV_ALL_MASK
public static final int LNCV_ALL_MASK
- See Also:
- Constant Field Values
-
LNCV_MIN_MODULEADDR
public static final int LNCV_MIN_MODULEADDR
- See Also:
- Constant Field Values
-
LNCV_MAX_MODULEADDR
public static final int LNCV_MAX_MODULEADDR
- See Also:
- Constant Field Values
-
LNCV_LENGTH_ELEMENT_INDEX
public static final int LNCV_LENGTH_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
LNCV_SRC_ELEMENT_INDEX
public static final int LNCV_SRC_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
LNCV_DST_L_ELEMENT_INDEX
public static final int LNCV_DST_L_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
LNCV_DST_H_ELEMENT_INDEX
public static final int LNCV_DST_H_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
LNCV_CMD_ELEMENT_INDEX
public static final int LNCV_CMD_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
PXCT1_ELEMENT_INDEX
public static final int PXCT1_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
LNCV_ART_L_ELEMENT_INDEX
public static final int LNCV_ART_L_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
LNCV_ART_H_ELEMENT_INDEX
public static final int LNCV_ART_H_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
LNCV_CVN_L_ELEMENT_INDEX
public static final int LNCV_CVN_L_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
LNCV_CVN_H_ELEMENT_INDEX
public static final int LNCV_CVN_H_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
LNCV_MOD_L_ELEMENT_INDEX
public static final int LNCV_MOD_L_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
LNCV_MOD_H_ELEMENT_INDEX
public static final int LNCV_MOD_H_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
LNCV_CMDDATA_ELEMENT_INDEX
public static final int LNCV_CMDDATA_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
LNCV_SRC_ELEMENT_MASK
public static final int LNCV_SRC_ELEMENT_MASK
- See Also:
- Constant Field Values
-
PXCT1_ELEMENT_VALIDITY_CHECK_MASK
public static final int PXCT1_ELEMENT_VALIDITY_CHECK_MASK
- See Also:
- Constant Field Values
-
LNCV_ART_L_ARTL7_CHECK_MASK
public static final int LNCV_ART_L_ARTL7_CHECK_MASK
- See Also:
- Constant Field Values
-
LNCV_ART_H_ARTH7_CHECK_MASK
public static final int LNCV_ART_H_ARTH7_CHECK_MASK
- See Also:
- Constant Field Values
-
LNCV_CVN_L_CVNL7_CHECK_MASK
public static final int LNCV_CVN_L_CVNL7_CHECK_MASK
- See Also:
- Constant Field Values
-
LNCV_CVN_H_CVNH7_CHECK_MASK
public static final int LNCV_CVN_H_CVNH7_CHECK_MASK
- See Also:
- Constant Field Values
-
LNCV_MOD_L_MODL7_CHECK_MASK
public static final int LNCV_MOD_L_MODL7_CHECK_MASK
- See Also:
- Constant Field Values
-
LNCV_MOD_H_MODH7_CHECK_MASK
public static final int LNCV_MOD_H_MODH7_CHECK_MASK
- See Also:
- Constant Field Values
-
LNCV_CMDDATA_DAT7_CHECK_MASK
public static final int LNCV_CMDDATA_DAT7_CHECK_MASK
- See Also:
- Constant Field Values
-
LNCV_DATA_PROFF_MASK
public static final int LNCV_DATA_PROFF_MASK
- See Also:
- Constant Field Values
-
LNCV_DATA_PRON_MASK
public static final int LNCV_DATA_PRON_MASK
- See Also:
- Constant Field Values
-
LNCV_DATA_LED1_MASK
public static final int LNCV_DATA_LED1_MASK
- See Also:
- Constant Field Values
-
LNCV_DATA_LED2_MASK
public static final int LNCV_DATA_LED2_MASK
- See Also:
- Constant Field Values
-
LNCV_DATA_RO_MASK
public static final int LNCV_DATA_RO_MASK
- See Also:
- Constant Field Values
-
LNCV_CMD_WRITE
public static final int LNCV_CMD_WRITE
- See Also:
- Constant Field Values
-
LNCV_CMD_READ
public static final int LNCV_CMD_READ
- See Also:
- Constant Field Values
-
LNCV_CMD_READ_REPLY
public static final int LNCV_CMD_READ_REPLY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
LncvMessageContents
public LncvMessageContents(LocoNetMessage m) throws java.lang.IllegalArgumentException
Create a new LncvMessageContents object from a LocoNet message.- Parameters:
m
- LocoNet message containing an LNCV Programming Format message- Throws:
java.lang.IllegalArgumentException
- if the LocoNet message is not a valid, supported LNCV Programming Format message
-
-
Method Detail
-
isSupportedLncvMessage
public static boolean isSupportedLncvMessage(LocoNetMessage m)
Check a LocoNet message to determine if it is a valid LNCV Programming Format message.- Parameters:
m
- LocoNet message to check- Returns:
- true if LocoNet message m is a supported LNCV Programming Format message, else false.
-
isLnMessageASpecificLncvCommand
public static boolean isLnMessageASpecificLncvCommand(LocoNetMessage m, LncvMessageContents.LncvCommand lncvCmd)
Compare reply message against a specific LNCV Programming Format message type.- Parameters:
m
- LocoNet message to be verified as an LNCV Programming Format message with the specified <LNCV_CMD> valuelncvCmd
- LNCV Programming Format command to check against- Returns:
- true if message is an LNCV Programming Format message of the specified <LNCV_CMD>, else false.
-
extractMessageType
public static LncvMessageContents.LncvCommand extractMessageType(LocoNetMessage m)
Interpret a LocoNet message to determine its LNCV compound Programming Format. If the message is not an LNCV Programming/Direct Format message, returns null.- Parameters:
m
- LocoNet message containing LNCV Programming Format message- Returns:
- LncvCommand found in the LNCV Programming Format message or null if not found
-
toString
public java.lang.String toString()
Interpret the LNCV Programming Format message into a human-readable string.- Overrides:
toString
in classjava.lang.Object
- Returns:
- String containing a human-readable version of the LNCV Programming Format message
-
toString
public java.lang.String toString(java.util.Locale locale)
Interpret the LNCV Programming Format message into a human-readable string.- Parameters:
locale
- locale to use for the human-readable string- Returns:
- String containing a human-readable version of the LNCV Programming Format message, in the language specified by the Locale, if the properties have been translated to that Locale, else in the default English language.
-
isSupportedLncvCommand
public static boolean isSupportedLncvCommand(int command, int opc, int cmdData)
Check set of parameters against compoundLncvMessageContents.LncvCommand
enum set.- Parameters:
command
- LNCV CMD valueopc
- OPC valuecmdData
- LNCV cmdData value- Returns:
- true if the possibleCmd value is one of the supported (simple) LNCV Programming Format commands
-
isSupportedLncvCommand
public boolean isSupportedLncvCommand()
Confirm a message corresponds with a valid (known) LNCV Programming Format command.- Returns:
- true if the LNCV message specifies a valid (known) LNCV Programming Format command.
-
isSupportedLncvReadReply
public boolean isSupportedLncvReadReply()
- Returns:
- true if the LNCV message is an LNCV ReadReply message
-
createLncvMessage
public static LocoNetMessage createLncvMessage(int opc, int source, int destination, int command, int articleNum, int cvNum, int moduleNum, int cmdData) throws java.lang.IllegalArgumentException
Create a LocoNet message containing an LNCV Programming Format message.- Parameters:
opc
- Opcode (<OPC>), see LnConstantssource
- source device (<SRC>)destination
- destination address (for <DST_L> and <DST_H>)command
- LNCV Programming simple command (for <LNCV_CMD>), part of complex commandLncvMessageContents.LncvCommand
articleNum
- manufacturer's hardware class/article code as per specs (4 decimal digits)cvNum
- CV number (for <LNCV_CVN_L> and <LNCV_CVN_H>)moduleNum
- module address (for <LNCV_MOD_L> and <LNCV_MOD_H>), same field is used for CV Value in WRITE to and READ_REPLY from ModulecmdData
- signals programming start/stop: LNCV_DATA_PRON/LNCV_DATA_PROFF- Returns:
- LocoNet message for the requested instruction
- Throws:
java.lang.IllegalArgumentException
- of command is not a valid LNCV Programming Format <LNCV_CMD> value
-
createLncvMessage
public static LocoNetMessage createLncvMessage(int source, int destination, LncvMessageContents.LncvCommand command, int articleNum, int cvNum, int moduleNum)
Create LNCV message fromLncvMessageContents.LncvCommand
enum plus specific parameter values.- Parameters:
source
- source device (<SRC>)destination
- destination address (for <DST_L> and <DST_H>)command
- one of the composite LncvCommand'sarticleNum
- manufacturer's hardware class/article code as per specscvNum
- 16-bit CV number (for <LNCV_CVN_L> and <LNCV_CVN_H>)moduleNum
- module address (for <LNCV_MOD_L> and <LNCV_MOD_H>), same field is used for CV Value in WRITE to and READ_REPLY from Module- Returns:
- LocoNet message for the requested instruction
-
getCmd
public int getCmd()
-
getCvNum
public int getCvNum()
-
getCvValue
public int getCvValue()
-
getLncvArticleNum
public int getLncvArticleNum()
-
getLncvModuleNum
public int getLncvModuleNum()
-
createAllProgStartRequest
public static LocoNetMessage createAllProgStartRequest(int articleNum)
Create LocoNet broadcast message to start LNCV programming.- Parameters:
articleNum
- LNCV device type number used as filter to respond. Leave this out to 'broadcast' to all connected devices (which works for discovery purpose only)- Returns:
- LocoNet message
-
createAllProgEndRequest
public static LocoNetMessage createAllProgEndRequest(int articleNum)
Create LocoNet broadcast message to end LNCV programming. (expect no reply from module)- Parameters:
articleNum
- LNCV device type number used as filter to respond. Leave out to 'broadcast' to all connected devices (which works for discovery purpose only). Best to use same value as used while opening the session.- Returns:
- LocoNet message
-
createModProgStartRequest
public static LocoNetMessage createModProgStartRequest(int articleNum, int moduleAddress)
Create LocoNet message for first query of a CV of this module.- Parameters:
articleNum
- address of the modulemoduleAddress
- address of the module- Returns:
- LocoNet message
-
createModProgEndRequest
public static LocoNetMessage createModProgEndRequest(int articleNum, int moduleAddress)
Create LocoNet message to leave programming of this module. (expect no reply from module)- Parameters:
articleNum
- address of the modulemoduleAddress
- address of the module- Returns:
- LocoNet message
-
createCvWriteRequest
public static LocoNetMessage createCvWriteRequest(int articleNum, int cvNum, int newValue)
Create LocoNet message for a write to a CV of this object.- Parameters:
articleNum
- address of the modulecvNum
- CV number to querynewValue
- new value to store in CV- Returns:
- LocoNet message
-
createCvReadRequest
public static LocoNetMessage createCvReadRequest(int articleNum, int moduleAddress, int cvNum)
Create LocoNet message for a query of a CV of this object.- Parameters:
articleNum
- address of the modulecvNum
- CV number to querymoduleAddress
- address of the module- Returns:
- LocoNet message
-
createLncvReadReply
public static LocoNetMessage createLncvReadReply(LocoNetMessage m)
In Hexfile simulation mode, mock a ReadReply message back to the CS (when simulate replies is ON).- Parameters:
m
- the LocoNet message to respond to- Returns:
- LocoNet message containing the reply, or null if preceding message isn't a query
-
createLncvProgStartReply
public static LocoNetMessage createLncvProgStartReply(LocoNetMessage m)
In Hexfile simulation mode, mock a ProgStart reply message back to the CS.- Parameters:
m
- the LocoNet message to respond to- Returns:
- LocoNet message containing the reply, or null if preceding message isn't a query
-
createDirectWriteRequest
public static LocoNetMessage createDirectWriteRequest(int moduleAddress, int ledValue, boolean range2)
Create LocoNet message to set aseries of Track-Control module display LEDs.- Parameters:
moduleAddress
- address of the moduleledValue
- CV number to queryrange2
- true if intended for LED2 Command (leds 16-31), fasle for LED1 (0-15)- Returns:
- LocoNet message
-
-