public class EventLoopManager
extends java.lang.Object
Takes RobocolDatagram messages, converts them into the appropriate data type, and then passes it to the current EventLoop.
Modifier and Type | Class and Description |
---|---|
static interface |
EventLoopManager.EventLoopMonitor
Callback to monitor when event loop changes state
|
Modifier and Type | Field and Description |
---|---|
protected boolean |
isPeerConnected |
static java.lang.String |
RC_BATTERY_LEVEL_KEY |
static java.lang.String |
ROBOT_BATTERY_LEVEL_KEY |
RobotState |
state |
static java.lang.String |
SYSTEM_ERROR_KEY |
static java.lang.String |
SYSTEM_NONE_KEY |
static java.lang.String |
SYSTEM_WARNING_KEY |
static java.lang.String |
TAG |
Constructor and Description |
---|
EventLoopManager(Context context)
Constructor
|
Modifier and Type | Method and Description |
---|---|
void |
buildAndSendTelemetry(java.lang.String tag,
java.lang.String msg) |
void |
close() |
CallbackResult |
commandEvent(Command command) |
CallbackResult |
emptyEvent(RobocolDatagram packet) |
CallbackResult |
gamepadEvent(RobocolDatagram packet) |
EventLoop |
getEventLoop()
Get the current event loop
|
Gamepad |
getGamepad()
Get the current gamepad state
|
Gamepad |
getGamepad(int port)
Get the gamepad connected to a particular user
|
Gamepad[] |
getGamepads()
Get the gamepads
|
Heartbeat |
getHeartbeat()
Get the current heartbeat state
|
EventLoopManager.EventLoopMonitor |
getMonitor()
return any event loop monitor previously set
|
CallbackResult |
heartbeatEvent(RobocolDatagram packet,
long tReceived) |
CallbackResult |
onNetworkConnectionEvent(NetworkConnection.Event event) |
CallbackResult |
packetReceived(RobocolDatagram packet) |
void |
peerConnected(boolean peerLikelyChanged) |
void |
peerDisconnected() |
CallbackResult |
peerDiscoveryEvent(RobocolDatagram packet) |
void |
refreshSystemTelemetry()
Do our best to maintain synchrony of the system error / warning state between applications
without incurring undo overhead.
|
void |
refreshSystemTelemetryNow()
Forces an immediate refresh of the system telemetry
|
void |
registerSyncdDevice(SyncdDevice device)
Register a sync'd device
|
CallbackResult |
reportGlobalError(java.lang.String error,
boolean recoverable) |
void |
sendTelemetryData(TelemetryMessage telemetry)
Send telemetry data
|
void |
setEventLoop(EventLoop eventLoop)
Replace the current event loop with a new event loop
|
void |
setIdleEventLoop(EventLoop idleEventLoop) |
void |
setMonitor(EventLoopManager.EventLoopMonitor monitor)
Set a monitor for this event loop
|
void |
shutdown()
Performs the logical inverse of
start(EventLoop) . |
void |
start(EventLoop eventLoop)
Starts up the
EventLoopManager . |
CallbackResult |
telemetryEvent(RobocolDatagram packet) |
void |
unregisterSyncdDevice(SyncdDevice device)
Unregisters a device from this event loop.
|
public static final java.lang.String TAG
public static final java.lang.String SYSTEM_NONE_KEY
public static final java.lang.String SYSTEM_ERROR_KEY
public static final java.lang.String SYSTEM_WARNING_KEY
public static final java.lang.String ROBOT_BATTERY_LEVEL_KEY
public static final java.lang.String RC_BATTERY_LEVEL_KEY
public RobotState state
protected boolean isPeerConnected
public void setIdleEventLoop(EventLoop idleEventLoop)
public void setMonitor(EventLoopManager.EventLoopMonitor monitor)
monitor
- event loop monitorpublic EventLoopManager.EventLoopMonitor getMonitor()
public EventLoop getEventLoop()
public Gamepad getGamepad()
Port 0 is assumed
getGamepad(int)
public Gamepad getGamepad(int port)
port
- user 0 and 1 are validpublic Gamepad[] getGamepads()
Array index will match the user number
public Heartbeat getHeartbeat()
public CallbackResult telemetryEvent(RobocolDatagram packet)
public CallbackResult reportGlobalError(java.lang.String error, boolean recoverable)
public CallbackResult packetReceived(RobocolDatagram packet)
public void refreshSystemTelemetryNow()
public void refreshSystemTelemetry()
public CallbackResult onNetworkConnectionEvent(NetworkConnection.Event event)
public void start(EventLoop eventLoop) throws RobotCoreException
EventLoopManager
. This mostly involves setting up the network
connections and listeners and senders, then getting the event loop thread going.
Note that shutting down the EventLoopManager
does not do a full
complete inverse. Rather, it leaves the underlying network connection alive and
running, as this, among other things, helps remote toasts to continue to function
correctly. Thus, we must be aware of that possibility here as we start.RobotCoreException
shutdown()
public void shutdown()
start(EventLoop)
.start(EventLoop)
public void close()
public void registerSyncdDevice(SyncdDevice device)
device
- sync'd deviceunregisterSyncdDevice(SyncdDevice)
public void unregisterSyncdDevice(SyncdDevice device)
device
- the device to be unregistered. May not be null.registerSyncdDevice(SyncdDevice)
public void setEventLoop(EventLoop eventLoop) throws RobotCoreException
eventLoop
- new event loopRobotCoreException
- if event loop fails to initpublic void sendTelemetryData(TelemetryMessage telemetry)
Send the telemetry data, and then clear the sent data
telemetry
- telemetry datapublic CallbackResult gamepadEvent(RobocolDatagram packet) throws RobotCoreException
RobotCoreException
public CallbackResult heartbeatEvent(RobocolDatagram packet, long tReceived) throws RobotCoreException
RobotCoreException
public void peerConnected(boolean peerLikelyChanged)
public void peerDisconnected()
public CallbackResult peerDiscoveryEvent(RobocolDatagram packet) throws RobotCoreException
RobotCoreException
public CallbackResult commandEvent(Command command) throws RobotCoreException
RobotCoreException
public CallbackResult emptyEvent(RobocolDatagram packet)
public void buildAndSendTelemetry(java.lang.String tag, java.lang.String msg)