Testing full duplex BT communications.

This commit is contained in:
2014-03-31 11:47:46 -04:30
parent 35b6c333c7
commit aff56cc8bd
3 changed files with 131 additions and 3 deletions

View File

@@ -0,0 +1,42 @@
/*
* Copyright (C) 2014 Miguel Angel Astor Romero
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ve.ucv.ciens.ccg.nxtarbot.threads;
import java.io.DataInputStream;
import java.io.IOException;
public class CommRecv extends Thread {
private boolean done;
private byte msg;
private DataInputStream iStream;
public CommRecv(DataInputStream iStream){
done = false;
this.iStream = iStream;
}
@Override
public void run(){
while(!done){
try{
msg = iStream.readByte();
System.out.println("Byte: " + Byte.toString(msg));
}catch(IOException io){
done = true;
}
}
}
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright (C) 2014 Miguel Angel Astor Romero
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ve.ucv.ciens.ccg.nxtarbot.threads;
import java.io.DataOutputStream;
import java.io.IOException;
import lejos.nxt.LightSensor;
import lejos.nxt.SensorPort;
public class CommSend extends Thread {
private boolean done;
private byte msg;
private LightSensor light;
private DataOutputStream oStream;
public CommSend(DataOutputStream oStream){
light = new LightSensor(SensorPort.S1);
done = false;
msg = 0;
this.oStream = oStream;
}
@Override
public void run(){
while(!done){
try{
if((msg = (byte)light.getLightValue()) < 40){
oStream.writeByte(msg);
oStream.flush();
}
}catch(IOException io){
done = true;
}
}
}
}