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

loggers

parent ed6f364c
No related branches found
No related tags found
No related merge requests found
package BluetoothJavaServer.src.edu.kufpg.bluetooth.server;
package Bluetooth;
import java.io.DataInputStream;
import java.io.DataOutputStream;
......
......@@ -3,7 +3,7 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package BluetoothJavaServer.src.edu.kufpg.bluetooth.server;
package Bluetooth;
import Vue.FXMLVueController;
import app.App;
......@@ -13,6 +13,8 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.bluetooth.DeviceClass;
import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.DiscoveryListener;
......@@ -55,7 +57,7 @@ public class BluetoothManager implements DiscoveryListener {
}
devices.add(btDevice);
System.out.println("device found: " + name);
Logger.getLogger(FXMLVueController.class.getName()).log(Level.FINE,"deviceDiscovered","device found: " + name);
}
......@@ -77,7 +79,7 @@ public class BluetoothManager implements DiscoveryListener {
@Override
public void servicesDiscovered(int transID, ServiceRecord[] servRecord) {
for(ServiceRecord s : servRecord) {
System.out.println("-------"+ s + "-------");
Logger.getLogger(BluetoothManager.class.getName()).log(Level.FINE,s.toString(),servRecord);
}
serviceRecords.addAll(Arrays.asList(servRecord));
}
......@@ -92,17 +94,17 @@ public class BluetoothManager implements DiscoveryListener {
RemoteDevice[] devices = agent.retrieveDevices(DiscoveryAgent.PREKNOWN);
for(RemoteDevice d : devices) {
if(d.getBluetoothAddress().equals(THINGZ_ID)) {
System.out.println("Thingz trouve");
Logger.getLogger(BluetoothManager.class.getName()).log(Level.FINE,"launch","Thingz found");
synchronized(lock) {
int result = agent.searchServices(null, desiredServiceUuids, d, this);
if( DiscoveryListener.SERVICE_SEARCH_DEVICE_NOT_REACHABLE == result) {
System.out.println(" but it could not be reached");
Logger.getLogger(BluetoothManager.class.getName()).log(Level.FINE,"launch","But it could not be reached");
continue;
}
lock.wait();
if(null != serviceRecords && serviceRecords.size() > 0) {
System.out.println("service records found");
Logger.getLogger(BluetoothManager.class.getName()).log(Level.FINE,"launch","Thingz service records found");
for(ServiceRecord serviceRecord: serviceRecords) {
String connectionUrl = serviceRecord.getConnectionURL(ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false); // I have no idea what these args are
StreamConnection connection;
......@@ -111,11 +113,11 @@ public class BluetoothManager implements DiscoveryListener {
DataInputStream inputStream = new DataInputStream(connection.openDataInputStream());
BluetoothConnection bluetoothConnection = new BluetoothConnection(d.getBluetoothAddress(), inputStream);
bluetoothConnection.setOutputStream(new DataOutputStream(connection.openOutputStream()));
connections.add(bluetoothConnection);
System.out.println("Connected to " + d.getBluetoothAddress());
connections.add(bluetoothConnection);
Logger.getLogger(BluetoothManager.class.getName()).log(Level.FINE,"launch","Connected to " + d.getBluetoothAddress());
return true;
} catch (IOException e) {
System.out.println("Could not connect to " + d.getBluetoothAddress() + ": " + e.getMessage());
} catch (IOException e) {
Logger.getLogger(BluetoothManager.class.getName()).log(Level.SEVERE,"launch","Could not connect to " + d.getBluetoothAddress() + ": " + e.getMessage());
e.printStackTrace();
return false;
}
......
package BluetoothJavaServer.src.edu.kufpg.bluetooth.server;
package Bluetooth;
public enum BluetoothServiceUuids {
SDP(0x0001),
......
package BluetoothJavaServer.src.edu.kufpg.bluetooth.server;
package Bluetooth;
import Interfaces.Observable;
import Interfaces.Observer;
import Vue.FXMLVueController;
import java.io.EOFException;
import java.io.IOException;
......@@ -8,21 +10,21 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import sun.misc.IOUtils;
public class BluetoothThread extends Thread {
public class BluetoothThread extends Thread implements Observable {
private static final int PACKET_SIZE = 18;
private BluetoothConnection connection;
private boolean keepGoing = true;
private String buffer;
private FXMLVueController observer;
private Observer observer;
public BluetoothThread(BluetoothConnection connection, FXMLVueController observer) {
public BluetoothThread(BluetoothConnection connection, Observer observer) {
this.connection = connection;
this.observer = observer;
}
public void notifyObserver(){
observer.update(this);
this.observer.update(this);
}
public String getBuffer(){
......@@ -41,7 +43,7 @@ public class BluetoothThread extends Thread {
notifyObserver();
} catch (Exception e) {
System.out.println("Could not read stream" + e);
Logger.getLogger(BluetoothThread.class.getName()).log(Level.SEVERE,"Could not read stream",e);
}
}
......@@ -76,7 +78,5 @@ public class BluetoothThread extends Thread {
public void sendInstruction(String instruction)throws IOException {
connection.getOutputStream().write(instruction.getBytes());
}
}
}
\ No newline at end of file
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Interfaces;
/**
*
* @author puiss
*/
public interface Observable {
void notifyObserver();
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Interfaces;
/**
*
* @author puiss
*/
public interface Observer {
void update(Observable obs);
}
......@@ -5,8 +5,10 @@
*/
package Vue;
import BluetoothJavaServer.src.edu.kufpg.bluetooth.server.BluetoothManager;
import BluetoothJavaServer.src.edu.kufpg.bluetooth.server.BluetoothThread;
import Bluetooth.BluetoothManager;
import Bluetooth.BluetoothThread;
import Interfaces.Observable;
import Interfaces.Observer;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.logging.Level;
......@@ -28,7 +30,7 @@ import javafx.scene.layout.HBox;
*
* @author invite
*/
public class FXMLVueController implements Initializable {
public class FXMLVueController implements Initializable, Observer {
@FXML
private GridPane accueil;
......@@ -155,14 +157,17 @@ public class FXMLVueController implements Initializable {
this.buttonBluetooth.setDisable(true);
} catch (Exception ex) {
Logger.getLogger(FXMLVueController.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
public void update(BluetoothThread t){
// MAJ LA VUE
System.err.println(t.getBuffer());
@Override
public void update(Observable obs) {
if(obs instanceof BluetoothThread){
Logger.getLogger(FXMLVueController.class.getName()).log(Level.FINE,"update",(BluetoothThread obs).getBuffer());
System.out.println(((BluetoothThread) obs).getBuffer());
}
}
}
......@@ -5,7 +5,6 @@
*/
package app;
import BluetoothJavaServer.src.edu.kufpg.bluetooth.server.*;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
......
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