Package jmri.jmrix.loconet.lnsvf2
Class LnSv2MessageContents
- java.lang.Object
-
- jmri.jmrix.loconet.lnsvf2.LnSv2MessageContents
-
public class LnSv2MessageContents extends java.lang.Object
Supporting class for LocoNet SV Programming Format 2 messaging. 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LnSv2MessageContents.Sv2Command
-
Field Summary
-
Constructor Summary
Constructors Constructor Description LnSv2MessageContents(LocoNetMessage m)
Create a new LnSV2MessageContents object from a LocoNet message.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static LocoNetMessage
createSv2ChangeAddressReply(int ida, int destAddr)
Create a LocoNet message for the reply for an SV2 "Change Address" message where the device requires a reconfigure.static LocoNetMessage
createSv2ChangeAddressReply(int ida, int newDestAddr, int mfg, int developer, int productId, int serialNum)
Create a LocoNet message for the reply for an SV2 "Change Address" message where the device requires a reconfigure.static LocoNetMessage
createSv2DeviceDiscoveryReply(int ida, int currentDest, int mfg, int devel, int prodID, int serial)
static LocoNetMessage
createSv2Message(int source, int command, int destination, int svNum, int d1, int d2, int d3, int d4)
Create a LocoNet message containing an SV Programming Format 2 message.static LocoNetMessage
createSv2ReconfigureReply(int ida, int newDestAddr, int mfg, int developer, int productId, int serialNum)
Create a LocoNet message for the reply for an SV2 "Reconfigure Reply"static LocoNetMessage
createSvDiscoverQueryMessage()
static LocoNetMessage
createSvReadReply(LocoNetMessage m, int svValue)
static LocoNetMessage
createSvReadReply(LocoNetMessage m, int[] svValues)
static LocoNetMessage
createSvReadRequest()
static LocoNetMessage
createSvReadRequest(int deviceAddress, int svNum)
Create LocoNet message for another query of an SV of this object.static LnSv2MessageContents.Sv2Command
extractMessageType(LocoNetMessage m)
Interpret a LocoNet message to determine its SV Programming Format 2 <SV_CMD>.int
getDestAddr()
int
getSingleReadReportData()
Get the data from a SVs Single Read Reply message.int
getSv2D1()
Get the d1 valueint
getSv2D2()
Get the d2 valueint
getSv2D3()
Get the d3 valueint
getSv2D4()
Get the d4 valueint
getSv2DeveloperID()
int
getSv2ManufacturerID()
int
getSv2ProductID()
int
getSv2SerialNum()
int
getSVNum()
static boolean
isLnMessageASpecificSv2Command(LocoNetMessage m, LnSv2MessageContents.Sv2Command svCmd)
Compare reply message against a specific SV Programming Format 2 message type.boolean
isSupportedSv2Command()
Confirm a message specifies a valid (known) SV Programming Format 2 command.static boolean
isSupportedSv2Command(int possibleCmd)
static boolean
isSupportedSv2Message(LocoNetMessage m)
Check a LocoNet message to determine if it is a valid SV Programming Format 2 message.boolean
isSupportedSv2ReadFourReply()
boolean
isSupportedSv2ReadOneReply()
boolean
isSupportedSv2ReadOneReplyOrSv2ReadFourReply()
boolean
isSvChangeAddressReply()
boolean
isSvReconfigureReply()
java.lang.String
toString()
Interpret the SV Programming Format 2 message into a human-readable string.java.lang.String
toString(java.util.Locale locale)
Interpret the SV Programming Format 2 message into a human-readable string.
-
-
-
Field Detail
-
SV2_LENGTH_ELEMENT_VALUE
public static final int SV2_LENGTH_ELEMENT_VALUE
- See Also:
- Constant Field Values
-
SV2_LENGTH_ELEMENT_INDEX
public static final int SV2_LENGTH_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
SV2_SRC_ELEMENT_INDEX
public static final int SV2_SRC_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
SV2_SV_CMD_ELEMENT_INDEX
public static final int SV2_SV_CMD_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
SV2_SV_TYPE_ELEMENT_INDEX
public static final int SV2_SV_TYPE_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
SV2_SVX1_ELEMENT_INDEX
public static final int SV2_SVX1_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
SV2_SV_DST_L_ELEMENT_INDEX
public static final int SV2_SV_DST_L_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
SV2_SV_DST_H_ELEMENT_INDEX
public static final int SV2_SV_DST_H_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
SV2_SV_ADRL_ELEMENT_INDEX
public static final int SV2_SV_ADRL_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
SV2_SV_ADRH_ELEMENT_INDEX
public static final int SV2_SV_ADRH_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
SV2_SVX2_ELEMENT_INDEX
public static final int SV2_SVX2_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
SV2_SVD1_ELEMENT_INDEX
public static final int SV2_SVD1_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
SV2_SVD2_ELEMENT_INDEX
public static final int SV2_SVD2_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
SV2_SVD3_ELEMENT_INDEX
public static final int SV2_SVD3_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
SV2_SVD4_ELEMENT_INDEX
public static final int SV2_SVD4_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
SV2_SRC_ELEMENT_MASK
public static final int SV2_SRC_ELEMENT_MASK
- See Also:
- Constant Field Values
-
SV2_SVX1_ELEMENT_VALIDITY_CHECK_MASK
public static final int SV2_SVX1_ELEMENT_VALIDITY_CHECK_MASK
- See Also:
- Constant Field Values
-
SV2_SVX1_ELEMENT_VALIDITY_CHECK_VALUE
public static final int SV2_SVX1_ELEMENT_VALIDITY_CHECK_VALUE
- See Also:
- Constant Field Values
-
SV2_SV_DST_L_DSTLX7_CHECK_MASK
public static final int SV2_SV_DST_L_DSTLX7_CHECK_MASK
- See Also:
- Constant Field Values
-
SV2_SV_DST_H_DSTHX7_CHECK_MASK
public static final int SV2_SV_DST_H_DSTHX7_CHECK_MASK
- See Also:
- Constant Field Values
-
SV2_SV_ADRL_SVADRL7_CHECK_MASK
public static final int SV2_SV_ADRL_SVADRL7_CHECK_MASK
- See Also:
- Constant Field Values
-
SV2_SV_ADRH_SVADRH7_CHECK_MASK
public static final int SV2_SV_ADRH_SVADRH7_CHECK_MASK
- See Also:
- Constant Field Values
-
SV2_SVX2_ELEMENT_VALIDITY_CHECK_MASK
public static final int SV2_SVX2_ELEMENT_VALIDITY_CHECK_MASK
- See Also:
- Constant Field Values
-
SV2_SVX2_ELEMENT_VALIDITY_CHECK_VALUE
public static final int SV2_SVX2_ELEMENT_VALIDITY_CHECK_VALUE
- See Also:
- Constant Field Values
-
SV2_SV_D1_D1X7_CHECK_MASK
public static final int SV2_SV_D1_D1X7_CHECK_MASK
- See Also:
- Constant Field Values
-
SV2_SV_D2_D2X7_CHECK_MASK
public static final int SV2_SV_D2_D2X7_CHECK_MASK
- See Also:
- Constant Field Values
-
SV2_SV_D3_D3X7_CHECK_MASK
public static final int SV2_SV_D3_D3X7_CHECK_MASK
- See Also:
- Constant Field Values
-
SV2_SV_D4_D4X7_CHECK_MASK
public static final int SV2_SV_D4_D4X7_CHECK_MASK
- See Also:
- Constant Field Values
-
SV2_SV_TYPE_ELEMENT_VALIDITY_CHECK_MASK
public static final int SV2_SV_TYPE_ELEMENT_VALIDITY_CHECK_MASK
- See Also:
- Constant Field Values
-
SV2_SV_TYPE_ELEMENT_VALIDITY_CHECK_VALUE
public static final int SV2_SV_TYPE_ELEMENT_VALIDITY_CHECK_VALUE
- See Also:
- Constant Field Values
-
SV_CMD_WRITE_ONE
public static final int SV_CMD_WRITE_ONE
- See Also:
- Constant Field Values
-
SV_CMD_WRITE_ONE_REPLY
public static final int SV_CMD_WRITE_ONE_REPLY
- See Also:
- Constant Field Values
-
SV_CMD_QUERY_ONE
public static final int SV_CMD_QUERY_ONE
- See Also:
- Constant Field Values
-
SV_CMD_REPORT_ONE
public static final int SV_CMD_REPORT_ONE
- See Also:
- Constant Field Values
-
SV_CMD_WRITE_ONE_MASKED
public static final int SV_CMD_WRITE_ONE_MASKED
- See Also:
- Constant Field Values
-
SV_CMD_WRITE_ONE_MASKED_REPLY
public static final int SV_CMD_WRITE_ONE_MASKED_REPLY
- See Also:
- Constant Field Values
-
SV_CMD_WRITE_FOUR
public static final int SV_CMD_WRITE_FOUR
- See Also:
- Constant Field Values
-
SV_CMD_WRITE_FOUR_REPLY
public static final int SV_CMD_WRITE_FOUR_REPLY
- See Also:
- Constant Field Values
-
SV_CMD_QUERY_FOUR
public static final int SV_CMD_QUERY_FOUR
- See Also:
- Constant Field Values
-
SV_CMD_REPORT_FOUR
public static final int SV_CMD_REPORT_FOUR
- See Also:
- Constant Field Values
-
SV_CMD_DISCOVER_DEVICES_QUERY
public static final int SV_CMD_DISCOVER_DEVICES_QUERY
- See Also:
- Constant Field Values
-
SV_CMD_DISCOVER_DEVICE_REPORT
public static final int SV_CMD_DISCOVER_DEVICE_REPORT
- See Also:
- Constant Field Values
-
SV_CMD_IDENTIFY_DEVICE_BY_DEVICE_ADDRESS
public static final int SV_CMD_IDENTIFY_DEVICE_BY_DEVICE_ADDRESS
- See Also:
- Constant Field Values
-
SV_CMD_IDENTIFY_DEVICE_BY_DEVICE_ADDRESS_REPLY
public static final int SV_CMD_IDENTIFY_DEVICE_BY_DEVICE_ADDRESS_REPLY
- See Also:
- Constant Field Values
-
SV_CMD_CHANGE_ADDRESS_REQUEST
public static final int SV_CMD_CHANGE_ADDRESS_REQUEST
- See Also:
- Constant Field Values
-
SV_CMD_CHANGE_ADDRESS_REPLY
public static final int SV_CMD_CHANGE_ADDRESS_REPLY
- See Also:
- Constant Field Values
-
SV_CMD_RECONFIGURE_REQUEST
public static final int SV_CMD_RECONFIGURE_REQUEST
- See Also:
- Constant Field Values
-
SV_CMD_RECONFIGURE_REPLY
public static final int SV_CMD_RECONFIGURE_REPLY
- See Also:
- Constant Field Values
-
SV2_SV_CMD_REPLY_BIT_NUMBER
public static final int SV2_SV_CMD_REPLY_BIT_NUMBER
- See Also:
- Constant Field Values
-
SV2_SV_CMD_REPLY_BIT_MASK
public static final int SV2_SV_CMD_REPLY_BIT_MASK
- See Also:
- Constant Field Values
-
SV2_SV_DATA_INDEX_EEPROM_SIZE
public static final int SV2_SV_DATA_INDEX_EEPROM_SIZE
- See Also:
- Constant Field Values
-
SV2_SV_DATA_INDEX_SOFTWARE_VERSION
public static final int SV2_SV_DATA_INDEX_SOFTWARE_VERSION
- See Also:
- Constant Field Values
-
SV2_SV_DATA_INDEX_SERIAL_NUMBER_LOW
public static final int SV2_SV_DATA_INDEX_SERIAL_NUMBER_LOW
- See Also:
- Constant Field Values
-
SV2_SV_DATA_INDEX_SERIAL_NUMBER_HIGH
public static final int SV2_SV_DATA_INDEX_SERIAL_NUMBER_HIGH
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
LnSv2MessageContents
public LnSv2MessageContents(LocoNetMessage m) throws java.lang.IllegalArgumentException
Create a new LnSV2MessageContents object from a LocoNet message.- Parameters:
m
- LocoNet message containing an SV Programming Format 2 message- Throws:
java.lang.IllegalArgumentException
- if the LocoNet message is not a valid, supported SV Programming Format 2 message
-
-
Method Detail
-
isSupportedSv2Message
public static boolean isSupportedSv2Message(LocoNetMessage m)
Check a LocoNet message to determine if it is a valid SV Programming Format 2 message.- Parameters:
m
- LocoNet message to check- Returns:
- true if LocoNet message m is a supported SV Programming Format 2 message, else false.
-
isLnMessageASpecificSv2Command
public static boolean isLnMessageASpecificSv2Command(LocoNetMessage m, LnSv2MessageContents.Sv2Command svCmd)
Compare reply message against a specific SV Programming Format 2 message type.- Parameters:
m
- LocoNet message to be verified as an SV Programming Format 2 message with the specified <SV_CMD> valuesvCmd
- SV Programming Format 2 command to expect- Returns:
- true if message is an SV Programming Format 2 message of the specified <SV_CMD>, else false.
-
extractMessageType
public static LnSv2MessageContents.Sv2Command extractMessageType(LocoNetMessage m)
Interpret a LocoNet message to determine its SV Programming Format 2 <SV_CMD>. If the message is not an SV Programming Format 2 message, returns null.- Parameters:
m
- LocoNet message containing SV Programming Format 2 message- Returns:
- Sv2Command found in the SV Programming Format 2 message or null if not found
-
toString
public java.lang.String toString()
Interpret the SV Programming Format 2 message into a human-readable string.- Overrides:
toString
in classjava.lang.Object
- Returns:
- String containing a human-readable version of the SV Programming Format 2 message
-
toString
public java.lang.String toString(java.util.Locale locale)
Interpret the SV Programming Format 2 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 SV Programming Format 2 message, in the language specified by the Locale, if the properties have been translated to that Locale, else in the default English language.
-
isSupportedSv2Command
public static boolean isSupportedSv2Command(int possibleCmd)
- Parameters:
possibleCmd
- integer to be compared to the command list- Returns:
- true if the possibleCmd value is one of the supported SV Programming Format 2 commands
-
isSupportedSv2Command
public boolean isSupportedSv2Command()
Confirm a message specifies a valid (known) SV Programming Format 2 command.- Returns:
- true if the SV2 message specifies a valid (known) SV Programming Format 2 command.
-
isSupportedSv2ReadOneReply
public boolean isSupportedSv2ReadOneReply()
- Returns:
- true if the SV2 message is a SV2 Read One Reply message
-
isSupportedSv2ReadFourReply
public boolean isSupportedSv2ReadFourReply()
- Returns:
- true if the SV2 message is a SV2 Read Four Reply message
-
isSupportedSv2ReadOneReplyOrSv2ReadFourReply
public boolean isSupportedSv2ReadOneReplyOrSv2ReadFourReply()
- Returns:
- true if the SV2 message is a SV2 Read One Reply message or a SV2 Read Four Reply message
-
getSingleReadReportData
public int getSingleReadReportData()
Get the data from a SVs Single Read Reply message. May also be used to return the effective SV value reported in a SV2 Single Write Reply message.- Returns:
- the
<D1>
value from the SV2 message
-
createSv2Message
public static LocoNetMessage createSv2Message(int source, int command, int destination, int svNum, int d1, int d2, int d3, int d4) throws java.lang.IllegalArgumentException
Create a LocoNet message containing an SV Programming Format 2 message. See Programmer message code inLnOpsModeProgrammer
loadSV2MessageFormat- Parameters:
source
- source device address (7 bit, for <SRC>)command
- SV Programming Format 2 command number (for <SV_CMD>)destination
- = SV format 2 destination address (for <DST_L> and <DST_H>)svNum
- SV Programming Format 2 16-bit SV number (for <SVN_L> and <SVN_H>)d1
- SV Programming Format 2 first data value (for <D1>)d2
- SV Programming Format 2 second data value (for <D2>)d3
- SV Programming Format 2 third data value (for <D3>)d4
- SV Programming Format 2 fourth data value (for <D4>)- Returns:
- LocoNet message for the requested message
- Throws:
java.lang.IllegalArgumentException
- if command is not a valid SV Programming Format 2 <SV_CMD> value
-
getDestAddr
public int getDestAddr()
-
getSVNum
public int getSVNum()
-
getSv2ManufacturerID
public int getSv2ManufacturerID()
-
isSvReconfigureReply
public boolean isSvReconfigureReply()
-
getSv2DeveloperID
public int getSv2DeveloperID()
-
getSv2ProductID
public int getSv2ProductID()
-
getSv2SerialNum
public int getSv2SerialNum()
-
createSv2DeviceDiscoveryReply
public static LocoNetMessage createSv2DeviceDiscoveryReply(int ida, int currentDest, int mfg, int devel, int prodID, int serial)
- Parameters:
ida
- IDA number for "SRC" field of OPC_PEER_XFERcurrentDest
- the destination address of the devicemfg
- the Manufacturer IDdevel
- the developer IDprodID
- the product IDserial
- the serial number- Returns:
- a LocoNet message containing the formatted reply
-
createSv2ChangeAddressReply
public static LocoNetMessage createSv2ChangeAddressReply(int ida, int destAddr)
Create a LocoNet message for the reply for an SV2 "Change Address" message where the device requires a reconfigure.- Parameters:
ida
- IDA value, for the SRC field of the OPC_PEER_XFERdestAddr
- the "old" SV2 destination address- Returns:
- a LocoNet message
-
createSv2ChangeAddressReply
public static LocoNetMessage createSv2ChangeAddressReply(int ida, int newDestAddr, int mfg, int developer, int productId, int serialNum)
Create a LocoNet message for the reply for an SV2 "Change Address" message where the device requires a reconfigure.- Parameters:
ida
- IDA value, for the SRC field of the OPC_PEER_XFERnewDestAddr
- the "new" SV2 destination addressmfg
- manufacturer IDdeveloper
- device IDproductId
- product IDserialNum
- serial Number- Returns:
- a LocoNet message
-
createSv2ReconfigureReply
public static LocoNetMessage createSv2ReconfigureReply(int ida, int newDestAddr, int mfg, int developer, int productId, int serialNum)
Create a LocoNet message for the reply for an SV2 "Reconfigure Reply"- Parameters:
ida
- IDA value, for the SRC field of the OPC_PEER_XFERnewDestAddr
- the "new" SV2 destination addressmfg
- manufacturer IDdeveloper
- device IDproductId
- product IDserialNum
- serial Number- Returns:
- a LocoNet message
-
createSvReadReply
public static LocoNetMessage createSvReadReply(LocoNetMessage m, int[] svValues)
- Parameters:
m
- the preceding LocoNet messagesvValues
- array containing the SV values; only one value is used when m contains an SV_QUERY_ONE, else contains 4 values.- Returns:
- LocoNet message containing the reply, or null if preceding message isn't a query
-
createSvReadReply
public static LocoNetMessage createSvReadReply(LocoNetMessage m, int svValue)
- Parameters:
m
- the preceding LocoNet messagesvValue
- value of one SV register- Returns:
- LocoNet message containing the reply, or null if preceding message isn't a query
-
getSv2D1
public int getSv2D1()
Get the d1 value- Returns:
- d1 element contents
-
getSv2D2
public int getSv2D2()
Get the d2 value- Returns:
- d2 element contents
-
getSv2D3
public int getSv2D3()
Get the d3 value- Returns:
- d3 element contents
-
getSv2D4
public int getSv2D4()
Get the d4 value- Returns:
- d4 element contents
-
isSvChangeAddressReply
public boolean isSvChangeAddressReply()
-
createSvDiscoverQueryMessage
public static LocoNetMessage createSvDiscoverQueryMessage()
-
createSvReadRequest
public static LocoNetMessage createSvReadRequest()
-
createSvReadRequest
public static LocoNetMessage createSvReadRequest(int deviceAddress, int svNum)
Create LocoNet message for another query of an SV of this object.- Parameters:
deviceAddress
- address of the devicesvNum
- SV number- Returns:
- LocoNet message
-
-