Class TransmitDeferrer

java.lang.Object
com.reduxrobotics.canand.TransmitDeferrer

public class TransmitDeferrer extends Object
Class that allows for batching messages to be transmitted. Batching allows for multiple messages to go over the JNI barrier in a single call. This does not work with calls that wait on a response!
  • Constructor Details

    • TransmitDeferrer

      public TransmitDeferrer()
  • Method Details

    • isActive

      public static boolean isActive()
      Returns whether or not the current thread is collecting all message transmits into the local MessageBatcher.
      Returns:
      true if active, false if not
    • queueCANMessage

      public static void queueCANMessage(CANBus bus, int messageID, byte[] data)
      Queues a CAN message to be sent in the batch. Does nothing if the active flag is not set.
      Parameters:
      bus - the bus to send to
      messageID - the message id
      data - the data to transmit
    • queueCANMessage

      public static void queueCANMessage(CANBus bus, int messageID, long data, int length)
      Queues a CAN message to be sent in the batch. Does nothing if the active flag is not set.
      Parameters:
      bus - the bus to send to
      messageID - the message id
      data - the data to transmit
      length - the length of data to send.
    • clearMessageBuffer

      public static void clearMessageBuffer()
      Clears the internal message buffer. The internal List holding the buffer of messasges to send is not shrinked automatically to avoid garbage collection as presumably deferTransmit(Runnable) is used in a loop, with a similar number of CAN message sends each time.

      This method frees that memory, in the case that this somehow becomes an issue. If called inside the Runnable, no messages will be sent when it returns.

    • deferTransmit

      public static int deferTransmit(Runnable func)
      Batches Redux device messages writes in the passed Runnable into a single JNI-passing call. Settings sets must have timeouts set to 0 to function correctly! This is because since message sending is deferred, no setting confirmation or fetch will return.
      Parameters:
      func - Function to batch calls for
      Returns:
      non-negative on success, negative for error