Skip to content
Snippets Groups Projects
Commit 91654bd4 authored by Puissegur Alexis's avatar Puissegur Alexis
Browse files

bluetooth packets ok, connexion à revoir

parent 8634b9d0
No related branches found
No related tags found
No related merge requests found
......@@ -11,11 +11,11 @@ import java.util.logging.Logger;
import sun.misc.IOUtils;
public class BluetoothThread extends Thread implements Observable {
private static final int PACKET_SIZE = 18;
private static final int PACKET_SIZE = 16;
private BluetoothConnection connection;
private boolean keepGoing = true;
private String buffer;
private String buffer = "";
private Observer observer;
public BluetoothThread(BluetoothConnection connection, Observer observer) {
......@@ -39,11 +39,14 @@ public class BluetoothThread extends Thread implements Observable {
// Each packet must start with two SYNC bytes in a row
byte[] payload = new byte[PACKET_SIZE];
int nbRead = connection.getInputStream().read(payload);
System.out.println("payload : " + payload);
System.out.println("nbRead : " + nbRead);
this.buffer = new String(payload, StandardCharsets.UTF_8);
notifyObserver();
String received = new String(payload, StandardCharsets.UTF_8);
if(received.indexOf("F") > -1){ // fin
this.buffer += received.substring(0, received.indexOf("F"));
notifyObserver();
this.buffer = received.substring(received.indexOf("F")+1);
} else {
this.buffer +=received;
}
} catch (Exception e) {
System.out.println("Could not read stream + " + e);
}
......
......@@ -199,7 +199,11 @@ public class FXMLVueController implements Initializable, Observer {
public void update(Observable obs) {
if(obs instanceof BluetoothThread){
BluetoothThread t = (BluetoothThread) obs;
System.out.println(t.getBuffer());
/*System.out.println("H :" + t.getH());
System.out.println("L :" + t.getL());
System.out.println("T :" + t.getT());
System.out.println("P :" + t.getP());*/
System.out.println("payload : " + t.getBuffer());
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment