Class SendableMessageWrapper

java.lang.Object
org.ka2ddo.yaac.io.SendableMessageWrapper
All Implemented Interfaces:
Serializable, SetBeaconRatesIfc, AX25FrameSource
Direct Known Subclasses:
ObjectReportSender

public class SendableMessageWrapper extends Object implements AX25FrameSource, Serializable, SetBeaconRatesIfc
This class wraps a SendableMessage in a AX25Frame suitable for transmission.
Author:
Andrew Pavlin KA2DDO
See Also:
  • Field Details

    • BULLETIN_SEQUENCE_CHARS

      public static final String BULLETIN_SEQUENCE_CHARS
      The characters (in order) for sequencing a multi-line bulletin. Maximum of 36 lines in a bulletin.
      See Also:
  • Constructor Details

    • SendableMessageWrapper

      public SendableMessageWrapper(SendableMessage msg)
      Wrap a SendableMessage for one transmission cycle with the default proportional pathing path set.
      Parameters:
      msg - SendableMessage to transmit
    • SendableMessageWrapper

      public SendableMessageWrapper(SendableMessage msg, String[] relays)
      Wrap a SendableMessage for one transmission cycle with the specified proportional pathing path set.
      Parameters:
      msg - SendableMessage to transmit
      relays - ordered array of digipeat paths for proportional pathing (1-element array to not use proportional pathing)
    • SendableMessageWrapper

      public SendableMessageWrapper(SendableMessage msg, int maxRetries)
      Wrap a SendableMessage for the specified number of transmission cycles with the default proportional pathing path set.
      Parameters:
      msg - SendableMessage to transmit
      maxRetries - number of times (times 2^N length of proportional path set) the message should be transmitted
    • SendableMessageWrapper

      public SendableMessageWrapper(SendableMessage msg, String[] relays, int maxRetries)
      Wrap a SendableMessage for the specified number of transmission cycles with the specified proportional pathing path set.
      Parameters:
      msg - SendableMessage to transmit
      relays - ordered array of digipeat paths for proportional pathing (1-element array to not use proportional pathing)
      maxRetries - number of times (times 2^N length of proportional path set) the message should be transmitted
  • Method Details

    • setSendableMessageListener

      public static void setSendableMessageListener(SendableMessageListener l)
      Set the global handler for changes in the list of SendableMessages.
      Parameters:
      l - SendableMessageListener to handle list change events
    • getMsg

      public SendableMessage getMsg()
      Get the SendableMessage wrapped in this object
      Returns:
      wrapped SendableMessage
    • getFrames

      public AX25Frame[] getFrames(boolean incrementXmtCount, ProtocolFamily protocolId, String senderCallsign)
      Get one or more AX25Frames of the data to transmit.
      Specified by:
      getFrames in interface AX25FrameSource
      Parameters:
      incrementXmtCount - indicate whether the transmit counter (used to cycle through proportional pathing) should be incremented
      protocolId - indicate the protocol to generate this frame for (not relevant for digipeated frames)
      senderCallsign - String of local callsign sending this message (may be ignored if digipeating a message from another station)
      Returns:
      array of AX25Frame objects to transmit, or null indicating nothing to transmit in the specified protocol
    • buildAX25FrameForMessage

      public static AX25Frame buildAX25FrameForMessage(String[] relays, SendableMessage msg, int numTransmissions, ProtocolFamily protocolId, String senderCallsign)
      Convert a SendableMessage object into a transmittable AX.25 frame, ready to send via KISS protocol to a TNC/radio.
      Parameters:
      relays - digipeater to specify in the AX.25 frame
      msg - the SendableMessage to encapsulate in an AX.25 frame
      numTransmissions - number of times the message has been transmitted.
      protocolId - AX.25 protocol ID to generate the message in; currently, only APRS and OPENTRAC are supported.
      senderCallsign - String of local callsign sending this message (may be ignored if digipeating a message from another station)
      Returns:
      an AX25Frame object ready to transmit, or null if the conversion and encapsulation could not be done.
    • getNumTransmitsBeforeDecay

      public int getNumTransmitsBeforeDecay()
      Get the number of times the message will be transmitted before the transmission rate is slowed. This is a function of the number of proportional paths defined, as the transmit interval will not be slowed until the entire proportional path cycle has been gone through.
      Specified by:
      getNumTransmitsBeforeDecay in interface AX25FrameSource
      Returns:
      number of transmits for one cycle of the proportional paths of this message
    • getLastTransmitTime

      public long getLastTransmitTime()
      Get the last time this message was transmitted.
      Returns:
      transmission time as Unix time in milliseconds since midnight Jan 1 1970 UTC, or zero if never transmitted
    • getNumTransmissions

      public int getNumTransmissions()
      Get the number of times this message has been transmitted.
      Returns:
      transmit count
    • resetTransmitCount

      public void resetTransmitCount(boolean isGuiDispatchThread)
      Reset the retransmission counters as if this was a brand-new message using the initial fast transmission rate.
      Parameters:
      isGuiDispatchThread - boolean true if caller is the GUI dispatch thread
    • getInitialSendRate

      public int getInitialSendRate()
      Get the fast retransmission rate for this message.
      Specified by:
      getInitialSendRate in interface SetBeaconRatesIfc
      Returns:
      fast retransmit rate in seconds
    • setInitialSendRate

      public void setInitialSendRate(int fastSendRate)
      Set the fast retransmission rate for this message.
      Specified by:
      setInitialSendRate in interface SetBeaconRatesIfc
      Parameters:
      fastSendRate - fast retransmit rate in seconds
    • setDecayRatio

      public void setDecayRatio(int decayRatio)
      Set the scaling factor by which the message repeat interval is enlarged (until the default slow send rate is reached).
      Specified by:
      setDecayRatio in interface SetBeaconRatesIfc
      Parameters:
      decayRatio - int decay ratio (should be 2 or 3)
    • getDecayRatio

      public int getDecayRatio()
      Get the scaling factor by which the message repeat interval is enlarged (until the default slow send rate is reached).
      Specified by:
      getDecayRatio in interface SetBeaconRatesIfc
      Returns:
      int decay ratio
    • getSlowSendRate

      public int getSlowSendRate()
      Get the slow retransmission rate for this message.
      Specified by:
      getSlowSendRate in interface SetBeaconRatesIfc
      Returns:
      slow retransmission rate in seconds
    • setSlowSendRate

      public void setSlowSendRate(int slowSendRate)
      Set the slow retransmission rate for this message.
      Specified by:
      setSlowSendRate in interface SetBeaconRatesIfc
      Parameters:
      slowSendRate - slow retransmission rate in seconds
    • isUseGpsForPosition

      public boolean isUseGpsForPosition()
      Indicate whether beacon data source can dynamically change its position (latitude/longitude), such as for a mobile station with a GPS.
      Specified by:
      isUseGpsForPosition in interface SetBeaconRatesIfc
      Returns:
      boolean true if latitude or longitude of beacon can change dynamically (not just through UI)
    • getNextMessage

      public SendableMessageWrapper getNextMessage()
      Get the next message in a chain of linked outgoing messages.
      Returns:
      SendableMessageWrapper of next message, or null if this message is alone or the end of a chain
    • setNextMessage

      public void setNextMessage(SendableMessageWrapper nextMessage)
      Set the message after this message in a chain of sequenced messages.
      Parameters:
      nextMessage - SendableMessageWrapper around the next message after this one, or null for no next message
    • getConnector

      public Connector getConnector()
      Get the port to which this message should be sent. By default, returns null (i.e., send to all available ports), but can be sent to a specific port if a non-null value is specified to setConnector(Connector).
      Specified by:
      getConnector in interface AX25FrameSource
      Returns:
      null for all PortConnectors
      See Also:
    • setConnector

      public void setConnector(Connector targetConnector)
      Set the port to which this message should be sent. Specifying null means send to all available ports, but can be sent to a specific port if parameter is non-null.
      Parameters:
      targetConnector - null for all PortConnectors
    • getOutstandingMessages

      public static Vector<SendableMessageWrapper> getOutstandingMessages()
      Get a reference to the vector of outstanding locally originated messages.
      Returns:
      Vector of SendableMessageWrappers that are still outstanding
    • findWrapperOf

      public static SendableMessageWrapper findWrapperOf(SendableMessage sm)
      Find any wrapper outstanding for the specified SendableMessage.
      Parameters:
      sm - SendableMessage to look for in queue
      Returns:
      SendableMessageWrapper containing the specified SendableMessage, or null if not found
    • findDuplicateWrapperOf

      public static SendableMessageWrapper findDuplicateWrapperOf(SendableMessage sm)
      Find any wrapper outstanding for an equivalent SendableMessage.
      Parameters:
      sm - SendableMessage to look for in queue
      Returns:
      SendableMessageWrapper containing the specified SendableMessage, or null if not found
    • getQruGroupCounts

      public static HashMap<String,int[]> getQruGroupCounts()
      Get a map of all the QRU groups known to have locally originated objects on this station, and return the count of objects per group.
      Returns:
      HashMap of group names to counts
    • getObjectsInGroup

      public static ArrayList<SendableMessageWrapper> getObjectsInGroup(String groupName)
      Search the list of outgoing messages for local Objects tagged with the specified QRU group.
      Parameters:
      groupName - QRU category name
      Returns:
      ArrayList of SendableMessageWrappers containing ObjectReports in the specified QRU group
    • isAcked

      public boolean isAcked()
      Report whether this message was acknowledged by its recipient.
      Returns:
      boolean true if this message received a "ack" response.
    • setAcked

      public void setAcked(boolean acknowledged)
      Indicate that this message has been acknowledged.
      Parameters:
      acknowledged - the new setting of the acknowledged boolean flag
    • isRejected

      public boolean isRejected()
      Report whether this message was rejected by its recipient.
      Returns:
      boolean true if this message received a "rej" response.
    • setRejected

      public void setRejected(boolean rejected)
      Indicate that this message has been rejected.
      Parameters:
      rejected - the new setting of the rejected boolean flag
    • queueForTransmission

      public void queueForTransmission()
      Put this SendableMessageWrapper on the list of messages to be transmitted and start transmitting it according to its transmit parameters.
    • cancelTransmission

      public void cancelTransmission(boolean isGuiDispatchThread)
      Stop trying to transmit this message, but still keep track of it in the model.
      Parameters:
      isGuiDispatchThread - boolean true if caller is the GUI dispatch thread
    • cleanup

      protected void cleanup()
      Do any cleanup work involved in removing this wrapped message from the transmission queue.
    • cancelPermanently

      public void cancelPermanently(boolean isGuiDispatchThread)
      Delete this SendableMessageWrapper from the transmission queue. Note this doesn't call cancelTransmission() because that would send an update event to any listeners, and this message might be deleted entirely before the event was processed.
      Parameters:
      isGuiDispatchThread - boolean true if caller is the GUI dispatch thread
    • removeObsoleteMessage

      public static void removeObsoleteMessage(Message msg, boolean isGuiDispatchThread)
      Find and cancel any queued messages matching the passed message.
      Parameters:
      msg - Message to compare against queued messages
      isGuiDispatchThread - boolean true if caller is the GUI dispatch thread
    • removeObsoleteMessage

      public static void removeObsoleteMessage(SendableMessageWrapper smw, boolean isGuiDispatchThread)
      Find and cancel any queued messages matching the passed message.
      Parameters:
      smw - SendableMessageWrapper to compare against queued messages
      isGuiDispatchThread - boolean true if caller is the GUI dispatch thread
    • requeue

      public void requeue()
      Reschedule the beacon based on its last transmission time and any changes in retransmit interval.
    • computeRandomizedTransmitTime

      public void computeRandomizedTransmitTime()
      Set the first time for this SendableMessage to transmit, so all the ones being started at YAAC startup time don't pile out at one time.
    • isActive

      public boolean isActive()
      Report whether this SendableMessageWrapper is still queued for upcoming transmissions.
      Returns:
      boolean true if message is still waiting for (re)transmission
    • getRemainingTransmits

      public int getRemainingTransmits()
      Get the number of transmissions remaining until the message has been sent.
      Returns:
      int number of remaining transmissions
    • getMaxTransmits

      public int getMaxTransmits()
      Get the maximum number of transmissions allowed for this message.
      Returns:
      int maximum number of transmissions
    • setMaxTransmits

      public void setMaxTransmits(int maxTransmits)
      Get the maximum number of transmissions allowed for this message.
      Parameters:
      maxTransmits - maximum number of transmissions
    • getDigipeatPaths

      public String[] getDigipeatPaths()
      Get the proportional pathing ordered set of digipeat paths.
      Returns:
      ordered String array of digipeat paths
    • setDigipeatPaths

      public void setDigipeatPaths(String[] relays)
      Set the proportional pathing ordered set of digipeat paths.
      Parameters:
      relays - ordered String array of digipeat paths
    • toString

      public String toString()
      Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object.
      Overrides:
      toString in class Object
      Returns:
      a string representation of the object.
    • getId

      public int getId()
      Get the internal sequence ID assigned to this wrapper
      Returns:
      ID number