Class XNetReply
- All Implemented Interfaces:
Message
- Direct Known Subclasses:
Z21XNetReply
public class XNetReply extends AbstractMRReply
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description boolean
checkParity()
Check whether the message has a valid parity.protected FeedbackItem
createFeedbackItem(int n, int d)
Integer
getElementBCD(int n)
Get an integer representation of a BCD value.int
getFeedbackEncoderMsgAddr()
If this is a feedback response message for a feedback encoder, return the address.int
getFeedbackEncoderMsgAddr(int startByte)
If this is a feedback broadcast message and the specified startByte is the address byte of an address byte/data byte pair for a feedback encoder, return the address.int
getFeedbackMessageItems()
Returns the number of feedback items in the messages.int
getFeedbackMessageType()
Extract the feedback message type from a feedback message this is the middle two bits of the upper byte of the second data byte.int
getFeedbackMessageType(int startByte)
Extract the feedback message type from the data byte of associated with the specified address byte specified by startByte.String
getOpCodeHex()
Get the opcode as a string in hex format.int
getServiceModeCVNumber()
int
getServiceModeCVValue()
int
getThrottleMsgAddr()
If this is a throttle-type message, return address.int
getTurnoutMsgAddr()
If this is a feedback response message for a turnout, return the address.int
getTurnoutMsgAddr(int startByte)
If this is a feedback broadcast message and the specified startbyte is the address byte of an addres byte data byte pair for a turnout, return the address.int
getTurnoutStatus(int turnout)
Parse the feedback message for a turnout, and return the status for the even or odd half of the nibble (upper or lower part).int
getTurnoutStatus(int startByte, int turnout)
Parse the specified address byte/data byte pair in a feedback broadcast message and see if it is for a turnout.boolean
isCommErrorMessage()
In the interest of code reuse, the following function checks to see if an XpressNet Message is a communications error message.boolean
isConsistMessage()
Is this a consist message?boolean
isCSBusyMessage()
In the interest of code reuse, the following function checks to see if an XpressNet Message is the Command Station Busy message (61 81 e3).boolean
isCSTransferError()
In the interest of code reuse, the following function checks to see if an XpressNet Message is the Command Station Transfer Error message (61 80 e1).boolean
isDirectModeResponse()
Is this message a direct CV mode programming response?boolean
isFeedbackBroadcastMessage()
Is this a feedback broadcast message?boolean
isFeedbackMessage()
Is this a feedback response message?boolean
isFeedbackMotionComplete(int startByte)
boolean
isOkMessage()
In the interest of code reuse, the following function checks to see if an XpressNet Message is the OK message (01 04 05).boolean
isPagedModeResponse()
Is this message a register or paged mode programming response?boolean
isRetransmittableErrorMsg()
boolean
isServiceModeResponse()
Is this message a service mode response?boolean
isThrottleMessage()
Is this a throttle message?boolean
isThrottleTakenOverMessage()
Does this message indicate the locomotive has been taken over by another device?boolean
isTimeSlotErrorMessage()
In the interest of code reuse, the following function checks to see if an XpressNet Message is a communications error message.boolean
isTimeSlotRestored()
In the interest of code reuse, the following function checks to see if an XpressNet Message is the timeslot restored message (01 07 06).boolean
isTimeSlotRevoked()
In the interest of code reuse, the following function checks to see if an XpressNet Message is the Command Station no longer providing a timeslot message (01 05 04).boolean
isUnsolicited()
Get flag for Unsolicited.boolean
isUnsupportedError()
In the interest of code reuse, the following function checks to see if an XpressNet Message is the not supported Error message (61 82 e3).boolean
onTurnoutFeedback(int accessoryNumber, Function<FeedbackItem,Boolean> proc)
Calls processor for turnout's feedback, returns the processor's outcome.protected String
parseFunctionHighMomentaryStatus(int element3, int element4)
Parse the Momentary sytatus of functions F13-F28.protected String
parseFunctionHighStatus(int element3, int element4)
Parse the status of functions F13-F28.protected String
parseFunctionMomentaryStatus(int element3, int element4)
Parse the Momentary status of functions.protected String
parseFunctionStatus(int element3, int element4)
Parse the status of functions F0-F12.protected String
parseSpeedAndDirection(int element1, int element2)
Parse the speed step and the direction information for a locomotive.void
resetUnsolicited()
Deprecated.since 4.21.1 without replacementBoolean
selectModuleFeedback(int sensorNumber)
Returns value of the given feedback module bit.Optional<FeedbackItem>
selectTurnoutFeedback(int accessoryNumber)
Selects a matching turnout feedback.void
setParity()
protected int
skipPrefix(int index)
skipPrefix is not used at this point in time, but is defined as abstract in AbstractMRReplyString
toMonitorString()
Methods inherited from class jmri.jmrix.AbstractMRReply
flush, getOpCode, isBinary, match, maxSize, pollValue, setBinary, setElement, setOpCode, setUnsolicited, skipWhiteSpace, toString, value
Methods inherited from class jmri.jmrix.AbstractMessage
equals, getElement, getNumDataElements, hashCode
-
Constructor Details
-
Method Details
-
getOpCodeHex
Get the opcode as a string in hex format.- Returns:
- 0x hex string of OpCode.
-
checkParity
Check whether the message has a valid parity.- Returns:
- true if parity valid, else false.
-
setParity
-
getElementBCD
Get an integer representation of a BCD value.- Parameters:
n
- byte in message to convert- Returns:
- Integer value of BCD byte.
-
skipPrefix
skipPrefix is not used at this point in time, but is defined as abstract in AbstractMRReply- Specified by:
skipPrefix
in classAbstractMRReply
-
getTurnoutMsgAddr
If this is a feedback response message for a turnout, return the address. Otherwise return -1.- Returns:
- the integer address or -1 if not a turnout message
-
getTurnoutMsgAddr
If this is a feedback broadcast message and the specified startbyte is the address byte of an addres byte data byte pair for a turnout, return the address. Otherwise return -1.- Parameters:
startByte
- address byte of the address byte/data byte pair.- Returns:
- the integer address or -1 if not a turnout message
-
getTurnoutStatus
Parse the feedback message for a turnout, and return the status for the even or odd half of the nibble (upper or lower part).- Parameters:
turnout
-- 0 for the even turnout associated with the pair. This is the upper half of the data nibble asociated with the pair
- 1 for the odd turnout associated with the pair. This is the lower half of the data nibble asociated with the pair
- Returns:
- THROWN/CLOSED as defined in
Turnout
-
getTurnoutStatus
Parse the specified address byte/data byte pair in a feedback broadcast message and see if it is for a turnout. If it is, return the status for the even or odd half of the nibble (upper or lower part)- Parameters:
startByte
- address byte of the address byte/data byte pair.turnout
-- 0 for the even turnout associated with the pair. This is the upper half of the data nibble asociated with the pair
- 1 for the odd turnout associated with the pair. This is the lower half of the data nibble asociated with the pair
- Returns:
- THROWN/CLOSED as defined in
Turnout
-
getFeedbackEncoderMsgAddr
If this is a feedback response message for a feedback encoder, return the address. Otherwise return -1.- Returns:
- the integer address or -1 if not a feedback message
-
getFeedbackMessageItems
Returns the number of feedback items in the messages. For accessory info replies, always returns 1. For broadcast, it returns the number of feedback pairs. Returns 0 for non-feedback messages.- Returns:
- number of feedback pair items.
-
getFeedbackEncoderMsgAddr
If this is a feedback broadcast message and the specified startByte is the address byte of an address byte/data byte pair for a feedback encoder, return the address. Otherwise return -1.- Parameters:
startByte
- address byte of the address byte data byte pair.- Returns:
- the integer address or -1 if not a feedback message
-
isFeedbackMessage
Is this a feedback response message?- Returns:
- true if a feedback response, else false.
-
isFeedbackBroadcastMessage
Is this a feedback broadcast message?- Returns:
- true if a feedback broadcast message, else false.
-
getFeedbackMessageType
Extract the feedback message type from a feedback message this is the middle two bits of the upper byte of the second data byte.- Returns:
- message type, values are:
- 0 for a turnout with no feedback
- 1 for a turnout with feedback
- 2 for a feedback encoder
- 3 is reserved by Lenz for future use.
-
getFeedbackMessageType
Extract the feedback message type from the data byte of associated with the specified address byte specified by startByte.The return value is the middle two bits of the upper byte of the data byte of an address byte/data byte pair.
- Parameters:
startByte
- The address byte for this addres byte data byte pair.- Returns:
- message type, values are:
- 0 for a turnout with no feedback
- 1 for a turnout with feedback
- 2 for a feedback encoder
- 3 is reserved by Lenz for future use.
-
isFeedbackMotionComplete
-
getThrottleMsgAddr
If this is a throttle-type message, return address. Otherwise return -1.Note we only identify the command now; the response to a request for status is not yet seen here.
- Returns:
- address if throttle-type message, else -1.
-
isThrottleMessage
Is this a throttle message?- Returns:
- true if throttle message. else false.
-
isThrottleTakenOverMessage
Does this message indicate the locomotive has been taken over by another device?- Returns:
- true if take over message, else false.
-
isConsistMessage
Is this a consist message?- Returns:
- true if consist message, else false.
-
isOkMessage
In the interest of code reuse, the following function checks to see if an XpressNet Message is the OK message (01 04 05).- Returns:
- true if an OK message, else false.
-
isTimeSlotRestored
In the interest of code reuse, the following function checks to see if an XpressNet Message is the timeslot restored message (01 07 06).- Returns:
- true if a time-slot restored message.
-
isTimeSlotRevoked
In the interest of code reuse, the following function checks to see if an XpressNet Message is the Command Station no longer providing a timeslot message (01 05 04).- Returns:
- true if a time-slot revoked message, else false.
-
isCSBusyMessage
In the interest of code reuse, the following function checks to see if an XpressNet Message is the Command Station Busy message (61 81 e3).- Returns:
- true if is a CS Busy message, else false.
-
isCSTransferError
In the interest of code reuse, the following function checks to see if an XpressNet Message is the Command Station Transfer Error message (61 80 e1).- Returns:
- if CS Transfer error, else false.
-
isUnsupportedError
In the interest of code reuse, the following function checks to see if an XpressNet Message is the not supported Error message (61 82 e3).- Returns:
- true if unsupported error, else false.
-
isCommErrorMessage
In the interest of code reuse, the following function checks to see if an XpressNet Message is a communications error message.The errors handled are: 01 01 00 -- Error between interface and the PC 01 02 03 -- Error between interface and the Command Station 01 03 02 -- Unknown Communications Error 01 06 07 -- LI10x Buffer Overflow 01 0A 0B -- LIUSB only. Request resend of data.
- Returns:
- true if comm error message, else false.
-
isTimeSlotErrorMessage
In the interest of code reuse, the following function checks to see if an XpressNet Message is a communications error message.The errors handled are: 01 05 04 -- Timeslot Error 01 07 06 -- Timeslot Restored 01 08 09 -- Data sent while there is no Timeslot
- Returns:
- true if time slot error, else false.
-
isServiceModeResponse
Is this message a service mode response?- Returns:
- true if a service mode response, else false.
-
isPagedModeResponse
Is this message a register or paged mode programming response?- Returns:
- true if register or paged mode programming response, else false.
-
isDirectModeResponse
Is this message a direct CV mode programming response?- Returns:
- true if direct CV mode programming response, else false.
-
getServiceModeCVNumber
- Returns:
- the CV value associated with a service mode reply return -1 if not a service mode message.
-
getServiceModeCVValue
- Returns:
- the value returned by the DCC system associated with a service mode reply. return -1 if not a service mode message.
-
isRetransmittableErrorMsg
- Overrides:
isRetransmittableErrorMsg
in classAbstractMRReply
- Returns:
- true if the message is an error message indicating we should retransmit.
-
isUnsolicited
Description copied from class:AbstractMRReply
Get flag for Unsolicited.- Overrides:
isUnsolicited
in classAbstractMRReply
- Returns:
- true if the message is an unsolicited message
-
resetUnsolicited
Deprecated.since 4.21.1 without replacementResets the unsolicited feedback flag. If the reply was not a feedback, or was received as a broadcast - unsolicited from the command station, this method will not cause theisUnsolicited()
to returnfalse
.Messages sent as unsolicited by the command station can not be turned to solicited.
-
selectModuleFeedback
Returns value of the given feedback module bit. ReturnsOptional
that is non-empty, if the feedback was present. The Optional's value indicates the feedback state.- Parameters:
sensorNumber
- the sensor bit ID- Returns:
- optional sensor state.
-
onTurnoutFeedback
Calls processor for turnout's feedback, returns the processor's outcome. Searches for the turnout feedback for the given accessory. If found, runs a processor on the feedback item, and returns its Boolean result.Returns
false
, if matching feedback is not found.- Parameters:
accessoryNumber
- the turnout numberproc
- the processor- Returns:
false
if feedback was not found, or a result ofproc()
.
-
selectTurnoutFeedback
Selects a matching turnout feedback. Finds turnout feedback for the givenaccessoryNumber
. Returns an encapsulated feedback, that can be inspected. If no matching feedback is present, returns emptyOptional
.- Parameters:
accessoryNumber
- the turnout number- Returns:
- optional feedback item.
-
createFeedbackItem
-
toMonitorString
- Returns:
- a string representation of the reply suitable for display in the XpressNet monitor.
-
parseSpeedAndDirection
Parse the speed step and the direction information for a locomotive.- Parameters:
element1
- contains the speed step mode designation and availability informationelement2
- contains the data byte including the step mode and availability information- Returns:
- readable version of message
-
parseFunctionStatus
Parse the status of functions F0-F12.- Parameters:
element3
- contains the data byte including F0,F1,F2,F3,F4element4
- contains F12,F11,F10,F9,F8,F7,F6,F5- Returns:
- readable version of message
-
parseFunctionHighStatus
Parse the status of functions F13-F28.- Parameters:
element3
- contains F20,F19,F18,F17,F16,F15,F14,F13element4
- contains F28,F27,F26,F25,F24,F23,F22,F21- Returns:
- readable version of message
-
parseFunctionMomentaryStatus
Parse the Momentary status of functions.- Parameters:
element3
- contains the data byte including F0,F1,F2,F3,F4element4
- contains F12,F11,F10,F9,F8,F7,F6,F5- Returns:
- readable version of message
-
parseFunctionHighMomentaryStatus
Parse the Momentary sytatus of functions F13-F28.- Parameters:
element3
- contains F20,F19,F18,F17,F16,F15,F14,F13element4
- contains F28,F27,F26,F25,F24,F23,F22,F21- Returns:
- readable version of message
-