Package com.reduxrobotics.canand
Class TransmitDeferrer
java.lang.Object
com.reduxrobotics.canand.TransmitDeferrer
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Clears the internal message buffer.static int
deferTransmit
(Runnable func) Batches Redux device messages writes in the passed Runnable into a single JNI-passing call.static boolean
isActive()
Returns whether or not the current thread is collecting all message transmits into the local MessageBatcher.static void
queueCANMessage
(CANBus bus, int messageID, byte[] data) Queues a CAN message to be sent in the batch.static void
queueCANMessage
(CANBus bus, int messageID, long data, int length) Queues a CAN message to be sent in the batch.
-
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
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 tomessageID
- the message iddata
- the data to transmit
-
queueCANMessage
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 tomessageID
- the message iddata
- the data to transmitlength
- 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 presumablydeferTransmit(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
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
-