001package jmri.jmrix.lenz; 002 003import javax.annotation.OverridingMethodsMustInvokeSuper; 004import org.slf4j.Logger; 005import org.slf4j.LoggerFactory; 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,2011 012 */ 013public abstract class XNetNetworkPortController extends jmri.jmrix.AbstractNetworkPortController implements XNetPortController { 014 015 private boolean timeSlot = true; 016 017 public XNetNetworkPortController() { 018 super(new XNetSystemConnectionMemo()); 019 allowConnectionRecovery = true; // all classes derived from this class 020 // can recover from a connection failure 021 } 022 023 /** 024 * Check that this object is ready to operate. This is a question of 025 * configuration, not transient hardware status. 026 */ 027 @Override 028 public abstract boolean status(); 029 030 /** 031 * Can the port accept additional characters? This might go false for short 032 * intervals, but it might also stick off if something goes wrong. 033 */ 034 @Override 035 @OverridingMethodsMustInvokeSuper 036 public boolean okToSend(){ 037 return hasTimeSlot(); 038 } 039 040 /** 041 * Indicate whether the command station is currently providing a timeslot to this 042 * port controller. 043 * 044 * @return true if the command station is currently providing a timeslot. 045 */ 046 @Override 047 public boolean hasTimeSlot(){ 048 return timeSlot; 049 } 050 051 /** 052 * Set a variable indicating whether or not the command station is 053 * providing a timeslot. 054 * <p> 055 * This method should be called with the paramter set to false if 056 * a "Command Station No Longer Providing a timeslot for communications" 057 * (01 05 04) is received. 058 * <p> 059 * This method should be called with the parameter set to true if 060 * a "Command Station is providing a timeslot for communications again." 061 * (01 07 06) is received. 062 * 063 * @param timeslot true if a timeslot is being sent, false otherwise. 064 */ 065 @Override 066 public void setTimeSlot(boolean timeslot){ 067 timeSlot = timeslot; 068 } 069 070 /** 071 * We need a way to say if the output buffer is empty or not. 072 */ 073 @Override 074 public void setOutputBufferEmpty(boolean s) { 075 } // Maintained for compatibility with XNetPortController. Simply ignore calls !!! 076 077 @Override 078 public XNetSystemConnectionMemo getSystemConnectionMemo() { 079 return (XNetSystemConnectionMemo) super.getSystemConnectionMemo(); 080 } 081 082 @Override 083 public void dispose() { 084 super.dispose(); 085 log.debug("Dispose called"); 086 } 087 088 /** 089 * Customizable method to deal with resetting a system connection after a 090 * successful recovery of a connection. 091 */ 092 @Override 093 protected void resetupConnection() { 094 this.getSystemConnectionMemo().getXNetTrafficController().connectPort(this); 095 } 096 097 private static final Logger log = LoggerFactory.getLogger(XNetNetworkPortController.class); 098 099}