Package communication

Source Code of communication.SlaveConnection

package communication;

import BasicDataType.BlockingQueue;
import lejos.nxt.comm.Bluetooth;
import lejos.nxt.comm.BTConnection;
import lejos.nxt.comm.NXTConnection;

/**
* Connects as a slave to the master.
* @author Assar Lindstrom & Erik Lagercrantz
*/

public class SlaveConnection extends Connection {

  /**
   * Constructor
   * @param rq The receive queue
   */
  public SlaveConnection(BlockingQueue<Packet> rq){
    this.receiveQueue = rq;
    sendQueue = new BlockingQueue<Packet>();
  }

  /**
   * Sets node in waiting for connection mode.
   */
  public BTConnection connect() {
    BTConnection btc = null;
    System.out.println("Wait for connection...");
    while (true) {
      btc = Bluetooth.waitForConnection();
      if (btc == null) {
        System.out.println("No connection!");
        continue;
      }
      System.out.println("Connected.");
      btc.setIOMode(NXTConnection.RAW);
      break;
    }
    return btc;
  }

}
TOP

Related Classes of communication.SlaveConnection

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.