All Downloads are FREE. Search and download functionalities are using the official Maven repository.

lejos.remote.rcx.LLCHandler Maven / Gradle / Ivy

Go to download

leJOS (pronounced like the Spanish word "lejos" for "far") is a tiny Java Virtual Machine. In 2013 it was ported to the LEGO EV3 brick.

The newest version!
package lejos.remote.rcx;

import lejos.hardware.port.I2CPort;
import lejos.utility.Delay;

/**
 * Packet handler than implement the LLC packet protocol.
 * Deals with packets and acks. 
 * Supports independent streams of data in both directions.
 * 
 **/
public class LLCHandler extends PacketHandler {

  private byte op;
  private boolean gotAck = false;
  private boolean gotPacket = false;
  private byte [] inPacket = new byte [3];
  private byte [] ackPacket = new byte [2];
  private int inPacketLength;

  public LLCHandler(I2CPort port) {
    LLC.init(port);
  }

  /** Send a packet.
   * @param packet the bytes to send
   * @param len the number of bytes to send
   * @return true if the send was successful, else false
   */
  public boolean sendPacket(byte [] packet, int len) {
    synchronized (this) {
      boolean res = LLC.sendBytes(packet, len);
      Delay.msDelay(100);
      return res;
    }
  }  

  /** Receive a packet.
   * @param buffer the buffer to receive the packet into
   * @return the number of bytes received
   */
  public int receivePacket(byte [] buffer) {
    gotPacket = false;
    for(int i=0;i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy