Class TrafficController

  • All Implemented Interfaces:
    CommandStation

    public class TrafficController
    extends java.lang.Object
    implements CommandStation
    Converts Stream-based I/O to/from NMRA packets and controls sending to the direct interface.

    This is much simpler than many other "TrafficHandler" classes, because

    • It's not handling mode information, or even any information back from the device; it's just sending.
    • It can work with the direct packets.
    This actually bears more similarity to a pure implementation of the CommandStation interface, which is where the real guts of it is. In particular, note that transmission is not a threaded operation.
    • Field Detail

      • istream

        protected java.io.DataInputStream istream
      • ostream

        protected java.io.OutputStream ostream
    • Method Detail

      • sendPacket

        public boolean sendPacket​(byte[] packet,
                                  int repeats)
        Send a specific packet to the rails.
        Specified by:
        sendPacket in interface CommandStation
        Parameters:
        packet - Byte array representing the packet, including the error-correction byte. Must not be null.
        repeats - Number of times to repeat the transmission, but is ignored in the current implementation
        Returns:
        true if the operation succeeds, false otherwise.
      • status

        public boolean status()
      • disconnectPort

        public void disconnectPort​(AbstractSerialPortController p)
        Break connection to existing PortController object. Once broken, attempts to send via "message" member will fail.
        Parameters:
        p - the controller to disconnect from