Package jmri.jmrix.loconet.lnsvf1
Class Lnsv1MessageContents
- java.lang.Object
-
- jmri.jmrix.loconet.lnsvf1.Lnsv1MessageContents
-
public class Lnsv1MessageContents extends java.lang.Object
Supporting class for LocoNet SV Programming Format 1 (LocoIO) 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.
Uses the LOCONETSV1MODE programming mode.
Uses LnProgrammer LOCOIO_PEER_CODE_SV_VER1 message format, comparable to DecoderPro LOCONETSV1MODE The DecoderPro decoder definition is recommended for all LocoIO versions. Requires JMRI 4.12 or later.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLnsv1MessageContents.Sv1Command
-
Field Summary
Fields Modifier and Type Field Description static intLNSV1_BROADCAST_ADDRESSstatic intLNSV1_LOCOBUFFER_ADDRESSstatic intLNSV1_PEER_CODE_SV_VER0static intLNSV1_PEER_CODE_SV_VER1static intSV_CMD_READ_ONEstatic intSV_CMD_WRITE_ONEstatic intSV0_SVX2_ELEMENT_VALIDITY_CHECK_VALUEstatic intSV1_SV_CMD_ELEMENT_INDEXstatic intSV1_SV_DST_H_ELEMENT_INDEXstatic intSV1_SV_DST_L_ELEMENT_INDEXstatic intSV1_SV_SRC_L_ELEMENT_INDEXstatic intSV1_SVX1_ELEMENT_INDEXstatic intSV1_SVX1_ELEMENT_VALIDITY_CHECK_MASKstatic intSV1_SVX1_ELEMENT_VALIDITY_CHECK_VALUEstatic intSV1_SVX2_ELEMENT_INDEXstatic intSV1_SVX2_ELEMENT_VALIDITY_CHECK_MASKstatic intSV1_SVX2_ELEMENT_VALIDITY_CHECK_VALUE
-
Constructor Summary
Constructors Constructor Description Lnsv1MessageContents(LocoNetMessage m)Create a new Lnsv1MessageContents object from a LocoNet message.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static LocoNetMessagecreateBroadcastProbeAll()Create a message to probe all connected LocoIO (LNSV1) units on a given LocoNet connection.static LocoNetMessage[]createBroadcastSetAddress(int address, int subAddress)Compose a message that changes the hardware board address of ALL connected LNSV1 (LocoIO) boards.static LocoNetMessagecreateSv0Message(int source, int destination, int subAddress, int command, int svNum, int version, int newVal, int d6, int d7, int d8)Create a LocoNet message containing an SV Programming Format 0 message.static LocoNetMessagecreateSv1Message(int source, int destination, int subAddress, int command, int svNum, int version, int newVal, int d6, int d7, int d8)Create a LocoNet message containing an SV Programming Format 1 message.static LocoNetMessagecreateSv1ReadReply(int src, int dst, int subAddress, int version, int svNum, int returnValue)Simulate a read/probe reply for testing/developing.static LocoNetMessagecreateSv1ReadRequest(int dst, int subAddress, int svNum)Create LocoNet message for a query of an SV of this object.static LocoNetMessagecreateSv1WriteReply(int src, int dst, int subAddress, int version, int svNum, int returnValue)Simulate a read/probe reply for testing/developing.static LocoNetMessagecreateSv1WriteRequest(int dst, int subAddress, int svNum, int newValue)static Lnsv1MessageContents.Sv1CommandextractMessageType(LocoNetMessage m)Interpret a LocoNet message to extract its SV Programming Format 1 <SV_CMD>.static intextractMessageVersion(LocoNetMessage m)Interpret a LocoNet message to extract its SV Programming Format 1 <SV_CMD>.intgetCmd()intgetDestAddr()Not returning a valid address because LNSV1 messages do not use the DST_H field for high address.intgetDstH()Used to check message.intgetDstL()intgetSingleReadReportData()Get the data from a SVs READ_ONE Reply message.intgetSrcL()intgetSubAddress()intgetSv1D4()Get the d4 valueintgetSv1D6()Get the d6 valueintgetSv1D7()Get the d7 valueintgetSv1D8()Get the d8 valueintgetSvNum()intgetSvValue()intgetVersionNum()static booleanisLnMessageASpecificSv1Command(LocoNetMessage m, Lnsv1MessageContents.Sv1Command svCmd)Compare reply message against a specific SV Programming Format 1 message type.booleanisSupportedSv1Command()Confirm a message specifies a valid (known) SV Programming Format 1 command.static booleanisSupportedSv1Command(int possibleCmd)static booleanisSupportedSv1Message(LocoNetMessage m)Check a LocoNet message to determine if it is a valid SV Programming Format 1 message.booleanisSupportedSv1ReadOneReply()static java.lang.StringtoHexComposite(int low, int high)Format byte for hex displaystatic java.lang.StringtoHexStr(int value)Format byte for decimal + (optional) hex displayjava.lang.StringtoString()Interpret the SV Programming Format 1 message into a human-readable string.java.lang.StringtoString(java.util.Locale locale)Interpret the SV Programming Format 1 message into a human-readable string.
-
-
-
Field Detail
-
LNSV1_BROADCAST_ADDRESS
public static final int LNSV1_BROADCAST_ADDRESS
- See Also:
- Constant Field Values
-
LNSV1_LOCOBUFFER_ADDRESS
public static final int LNSV1_LOCOBUFFER_ADDRESS
- See Also:
- Constant Field Values
-
LNSV1_PEER_CODE_SV_VER0
public static final int LNSV1_PEER_CODE_SV_VER0
- See Also:
- Constant Field Values
-
LNSV1_PEER_CODE_SV_VER1
public static final int LNSV1_PEER_CODE_SV_VER1
- See Also:
- Constant Field Values
-
SV1_SV_SRC_L_ELEMENT_INDEX
public static final int SV1_SV_SRC_L_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
SV1_SV_DST_L_ELEMENT_INDEX
public static final int SV1_SV_DST_L_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
SV1_SV_DST_H_ELEMENT_INDEX
public static final int SV1_SV_DST_H_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
SV1_SVX1_ELEMENT_INDEX
public static final int SV1_SVX1_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
SV1_SV_CMD_ELEMENT_INDEX
public static final int SV1_SV_CMD_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
SV1_SVX2_ELEMENT_INDEX
public static final int SV1_SVX2_ELEMENT_INDEX
- See Also:
- Constant Field Values
-
SV1_SVX1_ELEMENT_VALIDITY_CHECK_MASK
public static final int SV1_SVX1_ELEMENT_VALIDITY_CHECK_MASK
- See Also:
- Constant Field Values
-
SV1_SVX1_ELEMENT_VALIDITY_CHECK_VALUE
public static final int SV1_SVX1_ELEMENT_VALIDITY_CHECK_VALUE
- See Also:
- Constant Field Values
-
SV1_SVX2_ELEMENT_VALIDITY_CHECK_MASK
public static final int SV1_SVX2_ELEMENT_VALIDITY_CHECK_MASK
- See Also:
- Constant Field Values
-
SV0_SVX2_ELEMENT_VALIDITY_CHECK_VALUE
public static final int SV0_SVX2_ELEMENT_VALIDITY_CHECK_VALUE
- See Also:
- Constant Field Values
-
SV1_SVX2_ELEMENT_VALIDITY_CHECK_VALUE
public static final int SV1_SVX2_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_READ_ONE
public static final int SV_CMD_READ_ONE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Lnsv1MessageContents
public Lnsv1MessageContents(LocoNetMessage m) throws java.lang.IllegalArgumentException
Create a new Lnsv1MessageContents object from a LocoNet message.- Parameters:
m- LocoNet message containing an SV Programming Format 1 message- Throws:
java.lang.IllegalArgumentException- if the LocoNet message is not a valid, supported SV Programming Format 1 message
-
-
Method Detail
-
isSupportedSv1Message
public static boolean isSupportedSv1Message(LocoNetMessage m)
Check a LocoNet message to determine if it is a valid SV Programming Format 1 message.- Parameters:
m- LocoNet message to check- Returns:
- true if LocoNet message m is a supported SV Programming Format 1 message, else false.
-
isLnMessageASpecificSv1Command
public static boolean isLnMessageASpecificSv1Command(LocoNetMessage m, Lnsv1MessageContents.Sv1Command svCmd)
Compare reply message against a specific SV Programming Format 1 message type.- Parameters:
m- LocoNet message to be verified as an SV Programming Format 1 message with the specified <SV_CMD> valuesvCmd- SV Programming Format 1 command to expect- Returns:
- true if message is an SV Programming Format 1 message of the specified <SV_CMD>, else false.
-
extractMessageType
public static Lnsv1MessageContents.Sv1Command extractMessageType(LocoNetMessage m)
Interpret a LocoNet message to extract its SV Programming Format 1 <SV_CMD>. If the message is not an SV Programming Format 1 message, returns null.- Parameters:
m- LocoNet message containing SV Programming Format 1 message- Returns:
- Sv1Command found in the SV Programming Format 1 message or null if not found
-
extractMessageVersion
public static int extractMessageVersion(LocoNetMessage m)
Interpret a LocoNet message to extract its SV Programming Format 1 <SV_CMD>. If the message is not an SV Programming Format 1 message, return null.- Parameters:
m- LocoNet message containing SV Programming Format 1 version field- Returns:
- Version found in the SV Programming Format 1 message or -1 if not found
-
toString
public java.lang.String toString()
Interpret the SV Programming Format 1 message into a human-readable string.- Overrides:
toStringin classjava.lang.Object- Returns:
- String containing a human-readable version of the SV Programming Format 1 message
-
toString
public java.lang.String toString(java.util.Locale locale)
Interpret the SV Programming Format 1 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 1 message, in the language specified by the Locale if the properties have been translated to that Locale, else in the default English language.
-
toHexStr
public static java.lang.String toHexStr(int value)
Format byte for decimal + (optional) hex display
-
toHexComposite
public static java.lang.String toHexComposite(int low, int high)
Format byte for hex display
-
isSupportedSv1Command
public static boolean isSupportedSv1Command(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 1 commands
-
isSupportedSv1Command
public boolean isSupportedSv1Command()
Confirm a message specifies a valid (known) SV Programming Format 1 command.- Returns:
- true if the SV1 message specifies a valid (known) SV Programming Format 1 command.
-
isSupportedSv1ReadOneReply
public boolean isSupportedSv1ReadOneReply()
- Returns:
- true if the SV1 message is a SV1 Read One Reply message
-
getSingleReadReportData
public int getSingleReadReportData()
Get the data from a SVs READ_ONE Reply message. May also be used to return the effective SV value reported in an SV1 WRITE_ONE Reply message (or is that returned in d8?).- Returns:
- the
<D6>value from the SV1 message
-
getSrcL
public int getSrcL()
-
getDstL
public int getDstL()
-
getDstH
public int getDstH()
Used to check message. LNSV1 messages do not use the DST_H field for high address
-
getDestAddr
public int getDestAddr()
Not returning a valid address because LNSV1 messages do not use the DST_H field for high address. and a composite address is not used. - LocoBuffer subaddress is always 1. - LocoIO subaddress is stored and fetched from PEER_XFER element SV1_SV_SUBADR_ELEMENT_INDEX (11). - JMRI LocoIO decoder address as stored in the Roster is calculated as a 14-bit number in jmri.jmrix.loconet.swing.lnsv1prog.Lnsv1ProgPane
-
getSubAddress
public int getSubAddress()
-
getCmd
public int getCmd()
-
getSvNum
public int getSvNum()
-
getSvValue
public int getSvValue()
-
getVersionNum
public int getVersionNum()
-
getSv1D4
public int getSv1D4()
Get the d4 value- Returns:
- d4 element contents
-
getSv1D6
public int getSv1D6()
Get the d6 value- Returns:
- d6 element contents
-
getSv1D7
public int getSv1D7()
Get the d7 value- Returns:
- d7 element contents
-
getSv1D8
public int getSv1D8()
Get the d8 value- Returns:
- d8 element contents
-
createSv0Message
public static LocoNetMessage createSv0Message(int source, int destination, int subAddress, int command, int svNum, int version, int newVal, int d6, int d7, int d8) throws java.lang.IllegalArgumentException
Create a LocoNet message containing an SV Programming Format 0 message. Used only to simulate replies from LocoIO. Uses LNSV1_PEER_CODE_SV_VER0.See Programmer message code in
LnOpsModeProgrammerloadSV1MessageFormat- Parameters:
source- source device address (for <SRC_L>)destination- = SV format 1 7-bit destination address (for <DST_L>)subAddress- = SV format 1 7-bit destination subaddress (for <DST_H>)command- SV Programming Format 1 command number (for <SV_CMD>)svNum- SV Programming Format 1 8-bit SV numbernewVal- (d4) SV first 8-bit data value to write (for <D4>)version- Programming Format 1 8-bit firmware version number; 0 in request,>0 in repliesd6- second 8-bit data value (for <D6>)d7- third 8-bit data value (for <D7>)d8- fourth 8-bit data value (for <D8>)- Returns:
- LocoNet message for the requested message
- Throws:
java.lang.IllegalArgumentException- if command is not a valid SV Programming Format 1 <SV_CMD> value
-
createSv1Message
public static LocoNetMessage createSv1Message(int source, int destination, int subAddress, int command, int svNum, int version, int newVal, int d6, int d7, int d8) throws java.lang.IllegalArgumentException
Create a LocoNet message containing an SV Programming Format 1 message.See Programmer message code in
LnOpsModeProgrammerloadSV1MessageFormat- Parameters:
source- source device address (for <SRC_L>)destination- = SV format 1 7-bit destination address (for <DST_L>)subAddress- = SV format 1 7-bit destination subaddress (for <DST_H>)command- SV Programming Format 1 command number (for <SV_CMD>)svNum- SV Programming Format 1 8-bit SV numbernewVal- (d4) SV first 8-bit data value to write (for <D4>)version- Programming Format 1 8-bit firmware version number; 0 in request,>0 in repliesd6- second 8-bit data value (for <D6>)d7- third 8-bit data value (for <D7>)d8- fourth 8-bit data value (for <D8>)- Returns:
- LocoNet message for the requested message
- Throws:
java.lang.IllegalArgumentException- if command is not a valid SV Programming Format 1 <SV_CMD> value
-
createSv1ReadRequest
public static LocoNetMessage createSv1ReadRequest(int dst, int subAddress, int svNum)
Create LocoNet message for a query of an SV of this object.- Parameters:
dst- address of the device to read fromsubAddress- subaddress of the device to read fromsvNum- SV number to read- Returns:
- LocoNet message
-
createSv1ReadReply
public static LocoNetMessage createSv1ReadReply(int src, int dst, int subAddress, int version, int svNum, int returnValue)
Simulate a read/probe reply for testing/developing.- Parameters:
src- board low addressdst- dest high address, usually 0x50 for LocoBuffer/PCsubAddress- board high addressversion- fictional firmware version number to addsvNum- SV read- Returns:
- LocoNet message containing the reply
-
createSv1WriteRequest
public static LocoNetMessage createSv1WriteRequest(int dst, int subAddress, int svNum, int newValue)
-
createSv1WriteReply
public static LocoNetMessage createSv1WriteReply(int src, int dst, int subAddress, int version, int svNum, int returnValue)
Simulate a read/probe reply for testing/developing.- Parameters:
src- board low addresssubAddress- board high addressdst- dest high address, usually 0x1050 for LocoBuffer/PCversion- fictional firmware version number to addsvNum- SV read- Returns:
- LocoNet message containing the reply
-
createBroadcastSetAddress
public static LocoNetMessage[] createBroadcastSetAddress(int address, int subAddress)
Compose a message that changes the hardware board address of ALL connected LNSV1 (LocoIO) boards.- Parameters:
address- the new base address of the LocoIO board to changesubAddress- the new subAddress of the board- Returns:
- an array containing one or two LocoNet messages
-
createBroadcastProbeAll
public static LocoNetMessage createBroadcastProbeAll()
Create a message to probe all connected LocoIO (LNSV1) units on a given LocoNet connection.- Returns:
- the complete LocoNet message
-
-