Class XNetReply

    • Constructor Detail

      • XNetReply

        public XNetReply​(XNetMessage message)
        Create a reply from an XNetMessage.
        Parameters:
        message - existing message.
      • XNetReply

        public XNetReply​(java.lang.String message)
        Create a reply from a string of hex characters.
        Parameters:
        message - hex string of message.
    • Method Detail

      • getOpCodeHex

        public java.lang.String getOpCodeHex()
        Get the opcode as a string in hex format.
        Returns:
        0x hex string of OpCode.
      • checkParity

        public boolean checkParity()
        Check whether the message has a valid parity.
        Returns:
        true if parity valid, else false.
      • getElementBCD

        public java.lang.Integer getElementBCD​(int n)
        Get an integer representation of a BCD value.
        Parameters:
        n - byte in message to convert
        Returns:
        Integer value of BCD byte.
      • skipPrefix

        protected int skipPrefix​(int index)
        skipPrefix is not used at this point in time, but is defined as abstract in AbstractMRReply
        Specified by:
        skipPrefix in class AbstractMRReply
      • getTurnoutMsgAddr

        public int 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

        public 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. 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

        public 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).
        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

        public 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. 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

        public int 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

        public final int 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

        public 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. 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

        public boolean isFeedbackMessage()
        Is this a feedback response message?
        Returns:
        true if a feedback response, else false.
      • isFeedbackBroadcastMessage

        public boolean isFeedbackBroadcastMessage()
        Is this a feedback broadcast message?
        Returns:
        true if a feedback broadcast message, else false.
      • getFeedbackMessageType

        public 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.
        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

        public int getFeedbackMessageType​(int startByte)
        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.
      • getThrottleMsgAddr

        public int 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

        public boolean isThrottleMessage()
        Is this a throttle message?
        Returns:
        true if throttle message. else false.
      • isThrottleTakenOverMessage

        public boolean isThrottleTakenOverMessage()
        Does this message indicate the locomotive has been taken over by another device?
        Returns:
        true if take over message, else false.
      • isConsistMessage

        public boolean isConsistMessage()
        Is this a consist message?
        Returns:
        true if consist message, else false.
      • isOkMessage

        public 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).
        Returns:
        true if an OK message, else false.
      • isTimeSlotRestored

        public 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).
        Returns:
        true if a time-slot restored message.
      • isTimeSlotRevoked

        public 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).
        Returns:
        true if a time-slot revoked message, else false.
      • isCSBusyMessage

        public 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).
        Returns:
        true if is a CS Busy message, else false.
      • isCSTransferError

        public 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).
        Returns:
        if CS Transfer error, else false.
      • isUnsupportedError

        public 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).
        Returns:
        true if unsupported error, else false.
      • isCommErrorMessage

        public boolean 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

        public boolean 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

        public boolean isServiceModeResponse()
        Is this message a service mode response?
        Returns:
        true if a service mode response, else false.
      • isPagedModeResponse

        public boolean isPagedModeResponse()
        Is this message a register or paged mode programming response?
        Returns:
        true if register or paged mode programming response, else false.
      • isDirectModeResponse

        public boolean isDirectModeResponse()
        Is this message a direct CV mode programming response?
        Returns:
        true if direct CV mode programming response, else false.
      • getServiceModeCVNumber

        public int getServiceModeCVNumber()
        Returns:
        the CV value associated with a service mode reply return -1 if not a service mode message.
      • getServiceModeCVValue

        public int getServiceModeCVValue()
        Returns:
        the value returned by the DCC system associated with a service mode reply. return -1 if not a service mode message.
      • selectModuleFeedback

        @CheckForNull
        public java.lang.Boolean selectModuleFeedback​(int sensorNumber)
        Returns value of the given feedback module bit. Returns Optional 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

        public boolean onTurnoutFeedback​(int accessoryNumber,
                                         java.util.function.Function<FeedbackItem,​java.lang.Boolean> proc)
        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 number
        proc - the processor
        Returns:
        false if feedback was not found, or a result of proc().
      • selectTurnoutFeedback

        @Nonnull
        public java.util.Optional<FeedbackItemselectTurnoutFeedback​(int accessoryNumber)
        Selects a matching turnout feedback. Finds turnout feedback for the given accessoryNumber. Returns an encapsulated feedback, that can be inspected. If no matching feedback is present, returns empty Optional.
        Parameters:
        accessoryNumber - the turnout number
        Returns:
        optional feedback item.
      • toMonitorString

        public java.lang.String toMonitorString()
        Returns:
        a string representation of the reply suitable for display in the XpressNet monitor.
      • parseSpeedAndDirection

        protected java.lang.String parseSpeedAndDirection​(int element1,
                                                          int element2)
        Parse the speed step and the direction information for a locomotive.
        Parameters:
        element1 - contains the speed step mode designation and availability information
        element2 - contains the data byte including the step mode and availability information
        Returns:
        readable version of message
      • parseFunctionStatus

        protected java.lang.String parseFunctionStatus​(int element3,
                                                       int element4)
        Parse the status of functions F0-F12.
        Parameters:
        element3 - contains the data byte including F0,F1,F2,F3,F4
        element4 - contains F12,F11,F10,F9,F8,F7,F6,F5
        Returns:
        readable version of message
      • parseFunctionHighStatus

        protected java.lang.String parseFunctionHighStatus​(int element3,
                                                           int element4)
        Parse the status of functions F13-F28.
        Parameters:
        element3 - contains F20,F19,F18,F17,F16,F15,F14,F13
        element4 - contains F28,F27,F26,F25,F24,F23,F22,F21
        Returns:
        readable version of message
      • parseFunctionMomentaryStatus

        protected java.lang.String parseFunctionMomentaryStatus​(int element3,
                                                                int element4)
        Parse the Momentary status of functions.
        Parameters:
        element3 - contains the data byte including F0,F1,F2,F3,F4
        element4 - contains F12,F11,F10,F9,F8,F7,F6,F5
        Returns:
        readable version of message
      • parseFunctionHighMomentaryStatus

        protected java.lang.String parseFunctionHighMomentaryStatus​(int element3,
                                                                    int element4)
        Parse the Momentary sytatus of functions F13-F28.
        Parameters:
        element3 - contains F20,F19,F18,F17,F16,F15,F14,F13
        element4 - contains F28,F27,F26,F25,F24,F23,F22,F21
        Returns:
        readable version of message