Class XNetSimulatorAdapter

  • All Implemented Interfaces:
    java.lang.Runnable, XNetPortController, PortAdapter, SerialPortAdapter

    public class XNetSimulatorAdapter
    extends XNetSimulatorPortController
    implements java.lang.Runnable
    Provide access to a simulated XpressNet system.

    Currently, the XNetSimulator reacts to commands sent from the user interface with messages an appropriate reply message.

    NOTE: Most XpressNet commands are still unsupported in this implementation.

    Normally controlled by the lenz.XNetSimulator.XNetSimulatorFrame class.

    NOTE: Some material in this file was modified from other portions of the support infrastructure.

    • Method Detail

      • openPort

        public java.lang.String openPort​(java.lang.String portName,
                                         java.lang.String appName)
        Description copied from interface: SerialPortAdapter
        Open a specified port.
        Specified by:
        openPort in interface SerialPortAdapter
        Parameters:
        portName - name tu use for this port
        appName - provided to the underlying OS during startup so that it can show on status displays, etc.
        Returns:
        null indicates OK return, else error message.
      • okToSend

        public boolean okToSend()
        Can the port accept additional characters? The state of CTS determines this, as there seems to be no way to check the number of queued bytes and buffer length. This might go false for short intervals, but it might also stick off if something goes wrong.
        Specified by:
        okToSend in interface XNetPortController
        Overrides:
        okToSend in class XNetSimulatorPortController
        Returns:
        true if OK to send, else false.
      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable
      • getTurnoutFeedbackType

        protected int getTurnoutFeedbackType()
        Return the turnout feedback type.
        • 0x00 - turnout without feedback, ie DR5000
        • 0x01 - turnout with feedback, ie NanoX
        • 0x10 - feedback module
        Returns:
        the turnout type reported by this station.
      • getAccessoryStateBits

        protected int getAccessoryStateBits​(int a)
        Returns accessory state, in the Operation Info Reply bit format. If the accessory has not been operated yet, returns 00 (not operated).
        Parameters:
        a - accessory number
        Returns:
        two bits representing the accessory state.
      • accInfoReply

        protected XNetReply accInfoReply​(int baseAddress,
                                         boolean nibble)
        Creates a reply packet for a turnout/accessory.
        Parameters:
        baseAddress - base address for the feedback, the 4-turnout block; numbered from 0
        nibble - lower or upper nibble (2 turnout block) delivered in the reply
        Returns:
        constructed reply.
      • generateAccRequestReply

        protected XNetReply generateAccRequestReply​(int address,
                                                    int output,
                                                    boolean state,
                                                    boolean previousAccessoryState)
        Generate reply to accessory request command. The returned XNetReply is the first to be returned by this simulated command station.
        Parameters:
        address - the accessory address
        output - the output to be manipulated
        state - true if output should be on, false for off
        previousAccessoryState - the previous accessory state
        Returns:
        the reply instance.
      • accInfoReply

        protected XNetReply accInfoReply​(int dccTurnoutAddress)
        Creates a reply for the specific turnout dcc address.
        Parameters:
        dccTurnoutAddress - the turnout address
        Returns:
        a reply packet
      • loadChars

        protected XNetMessage loadChars()
                                 throws java.io.IOException
        Get characters from the input source, and file a message.

        Returns only when the message is complete.

        Only used in the Receive thread.

        Returns:
        filled message
        Throws:
        java.io.IOException - when presented by the input source.
      • readByteProtected

        protected byte readByteProtected​(java.io.DataInputStream istream)
                                  throws java.io.IOException
        Read a single byte, protecting against various timeouts, etc.

        When a port is set to have a receive timeout (via the enableReceiveTimeout() method), some will return zero bytes or an EOFException at the end of the timeout. In that case, the read should be repeated to get the next real character.

        Parameters:
        istream - the input data source
        Returns:
        the next byte, waiting for it to become available
        Throws:
        java.io.IOException - from the underlying operations