001package jmri.jmrix.lenz;
002
003import java.io.DataInputStream;
004import java.io.DataOutputStream;
005import javax.annotation.OverridingMethodsMustInvokeSuper;
006
007/**
008 * Abstract base for classes representing an XNet communications port
009 *
010 * @author Bob Jacobsen Copyright (C) 2001, 2008
011 * @author Paul Bender Copyright (C) 2004,2010
012 */
013public abstract class XNetSimulatorPortController extends jmri.jmrix.AbstractSerialPortController implements XNetPortController {
014
015    private boolean timeSlot = true;
016
017    public XNetSimulatorPortController() {
018        super(new XNetSystemConnectionMemo());
019    }
020
021    // base class. Implementations will provide InputStream and OutputStream
022    // objects to XNetTrafficController classes, who in turn will deal in messages.    
023    // returns the InputStream from the port
024    @Override
025    public abstract DataInputStream getInputStream();
026
027    // returns the outputStream to the port
028    @Override
029    public abstract DataOutputStream getOutputStream();
030
031    /**
032     * Check that this object is ready to operate. This is a question of
033     * configuration, not transient hardware status.
034     */
035    @Override
036    public abstract boolean status();
037
038    /**
039     * Can the port accept additional characters? This might go false for short
040     * intervals, but it might also stick off if something goes wrong.
041     */
042    @Override
043    @OverridingMethodsMustInvokeSuper
044    public boolean okToSend(){
045       return hasTimeSlot();
046    }
047
048    /**
049     * Indicate whether the Command Station is currently providing a timeslot to this
050     * port controller.
051     *
052     * @return true if the Command Station is currently providing a timeslot.
053     */
054    @Override
055    public boolean hasTimeSlot(){
056        return timeSlot;
057    }
058
059    /**
060     * Set a variable indicating whether or not the command station is
061     * providing a timeslot.
062     * <p>
063     * This method should be called with the paramter set to false if
064     * a "Command Station No Longer Providing a timeslot for communications"
065     * (01 05 04) is received.
066     * <p>
067     * This method should be called with the parameter set to true if
068     * a "Command Station is providing a timeslot for communications again."
069     * (01 07 06) is received.
070     *
071     * @param timeslot true if a timeslot is being sent, false otherwise.
072     */
073    @Override
074    public void setTimeSlot(boolean timeslot){
075       timeSlot = timeslot;
076    }
077
078    /**
079     * We need a way to say if the output buffer is empty or not.
080     */
081    @Override
082    public abstract void setOutputBufferEmpty(boolean s);
083
084    @Override
085    public XNetSystemConnectionMemo getSystemConnectionMemo() {
086        return (XNetSystemConnectionMemo) super.getSystemConnectionMemo();
087    }
088
089    /**
090     * {@inheritDoc}
091     */
092    @Override
093    public String[] validBaudRates() {
094        return new String[]{};
095    }
096
097    /**
098     * {@inheritDoc}
099     */
100    @Override
101    public int[] validBaudNumbers() {
102        return new int[]{};
103    }
104
105}