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;
}
}