public class EventLoopManager extends java.lang.Object implements SyncdDevice.Manager
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 |
---|---|
static java.lang.String |
RC_BATTERY_STATUS_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(android.content.Context context,
EventLoopManagerClient eventLoopManagerClient,
EventLoop idleEventLoop)
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(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
|
WebServer |
getWebServer() |
CallbackResult |
heartbeatEvent(RobocolDatagram packet,
long tReceived) |
CallbackResult |
onNetworkConnectionEvent(NetworkConnection.NetworkEvent event) |
void |
onPeerConnected() |
void |
onPeerDisconnected() |
CallbackResult |
packetReceived(RobocolDatagram packet) |
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 |
setMonitor(EventLoopManager.EventLoopMonitor monitor)
Set a monitor for this event loop, which will immediately have the appropriate method called to
indicate the current peer status.
|
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_STATUS_KEY
public RobotState state
public EventLoopManager(android.content.Context context, EventLoopManagerClient eventLoopManagerClient, EventLoop idleEventLoop)
public WebServer getWebServer()
public void setMonitor(EventLoopManager.EventLoopMonitor monitor)
monitor
- event loop monitorpublic EventLoopManager.EventLoopMonitor getMonitor()
public EventLoop getEventLoop()
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.NetworkEvent 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)
registerSyncdDevice
in interface SyncdDevice.Manager
device
- sync'd deviceunregisterSyncdDevice(SyncdDevice)
public void unregisterSyncdDevice(SyncdDevice device)
unregisterSyncdDevice
in interface SyncdDevice.Manager
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 onPeerConnected()
public void onPeerDisconnected()
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)