Search in sources :

Example 1 with RobocolDatagram

use of com.qualcomm.robotcore.robocol.RobocolDatagram in project robotcode by OutoftheBoxFTC.

the class EventLoopManager method peerDiscoveryEvent.

public CallbackResult peerDiscoveryEvent(RobocolDatagram packet) throws RobotCoreException {
    networkConnectionHandler.updateConnection(packet, null, this);
    // Send a second PeerDiscovery() packet in response. That will inform the fellow
    // who sent the incoming PeerDiscovery() who *we* are.
    // 
    // We should still send a peer discovery packet even if *we* already know the client,
    // because it could be that the connection dropped (e.g., while changing other settings)
    // and the other guy (ie: DS) needs to reconnect. If we don't send this, the connection will
    // never complete. These only get sent about once per second so it's not a huge load on the network.
    PeerDiscovery outgoing = new PeerDiscovery(PeerDiscovery.PeerType.PEER);
    RobocolDatagram outgoingDatagram = new RobocolDatagram(outgoing);
    networkConnectionHandler.sendDatagram(outgoingDatagram);
    return CallbackResult.HANDLED;
}
Also used : PeerDiscovery(com.qualcomm.robotcore.robocol.PeerDiscovery) RobocolDatagram(com.qualcomm.robotcore.robocol.RobocolDatagram)

Example 2 with RobocolDatagram

use of com.qualcomm.robotcore.robocol.RobocolDatagram in project robotcode by OutoftheBoxFTC.

the class EventLoopManager method sendTelemetryData.

/**
 * Send telemetry data
 * <p>
 * Send the telemetry data, and then clear the sent data
 *
 * @param telemetry telemetry data
 */
public void sendTelemetryData(TelemetryMessage telemetry) {
    try {
        // conveying state here helps global errors always be portrayed as in EMERGENCY_STOP state rather than waiting until next heartbeat
        telemetry.setRobotState(this.state);
        networkConnectionHandler.sendDatagram(new RobocolDatagram(telemetry.toByteArrayForTransmission()));
    } catch (RobotCoreException e) {
        RobotLog.ww(TAG, e, "Failed to send telemetry data");
    }
    // clear the stale telemetry data
    telemetry.clearData();
}
Also used : RobocolDatagram(com.qualcomm.robotcore.robocol.RobocolDatagram) RobotCoreException(com.qualcomm.robotcore.exception.RobotCoreException)

Aggregations

RobocolDatagram (com.qualcomm.robotcore.robocol.RobocolDatagram)2 RobotCoreException (com.qualcomm.robotcore.exception.RobotCoreException)1 PeerDiscovery (com.qualcomm.robotcore.robocol.PeerDiscovery)1