Java Code Examples for javax.bluetooth.LocalDevice

The following are top voted examples for showing how to use javax.bluetooth.LocalDevice. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: pcstatus   File: BluetoothSPPServer.java   Source Code and License 7 votes vote down vote up
/**
 * if bluetooth connection is available, <code>sendBluetoothMessage()</code> run <code>sendReciveMessageThread()</code>.
 * Else, checks if Bluetooth is activated and chooses if close connection or wait again
 */
void sendBluetoothMessage() {
    if (connectionIsAvaible) {
        if (outStream != null) {
            if (sendReciveMessageThread.isInterrupted()) {
                messageThreadExecutor.execute(sendReciveMessageThread);
                System.out.println("thread creato e avviato");
                sendBluetoothMessage();
            } else {
                sendReciveMessageThread.interrupt();
                messageThreadExecutor.execute(sendReciveMessageThread);
            }
        }
    } else {
        try {
            if (LocalDevice.getLocalDevice() != null && !LocalDevice.getLocalDevice().getFriendlyName().equals("null"))
                System.out.println("connessione non stabilita " + LocalDevice.getLocalDevice().getFriendlyName());
            else {
                closeConnection();
            }
        } catch (BluetoothStateException | NullPointerException e) {
            e.printStackTrace();
            closeConnection();
        }
    }
}
 
Example 2
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 7 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 3
Project: ShootOFF   File: BluetoothServer.java   Source Code and License 6 votes vote down vote up
private Optional<String> getLocalAddress() {
	try {
		final LocalDevice localDevice = LocalDevice.getLocalDevice();

		// Insert colons into the address because android needs them
		final StringBuilder addressBuilder = new StringBuilder();
		final String originalAddress = localDevice.getBluetoothAddress();
		for (int i = 0; i < originalAddress.length(); i++) {
			addressBuilder.append(originalAddress.charAt(i));
			if (i > 0 && i < originalAddress.length() - 1 && i % 2 != 0) addressBuilder.append(':');
		}

		return Optional.of(addressBuilder.toString());
	} catch (BluetoothStateException e) {
		logger.error("Failed to access local bluetooth device to fetch its address. Ensure the "
				+ "system's bluetooth service is started with \"sudo systemctl start bluetooth\" "
				+ "and the bluetooth stack is on in the system settings", e);
		return Optional.empty();
	}
}
 
Example 4
Project: PanBox   File: PAKBluetoothPairingHandler.java   Source Code and License 6 votes vote down vote up
public PAKBluetoothPairingHandler(String password, String eMail,
		String firstName, String lastName, String deviceName,
		X509Certificate ownerCertEnc, X509Certificate ownerCertSign,
		Map<String, X509Certificate> knownDevices,
		Collection<VCard> knownContacts) throws IOException {
	super(PairingType.SLAVE, password, eMail, firstName, lastName,
			deviceName, ownerCertEnc, ownerCertSign, knownDevices,
			knownContacts);
	UUID uuid = new UUID(0x1101); // TODO: Create new unique UUID
	String connectionString = "btspp://localhost:" + uuid
			+ ";name=PanboxImportListener;encrypt=false;authenticate=false";
	streamConnNotifier = (StreamConnectionNotifier) Connector.open(
			connectionString, Connector.READ_WRITE);
	ServiceRecord record = LocalDevice.getLocalDevice().getRecord(
			streamConnNotifier);
	logger.debug("PAKBluetoothPairingHandler : connection is up at: "
			+ record.getConnectionURL(0, false));
}
 
Example 5
Project: PanBox   File: PAKBluetoothPairingHandler.java   Source Code and License 6 votes vote down vote up
public PAKBluetoothPairingHandler(String password, String eMail,
		String firstName, String lastName, String deviceName,
		char[] keyPassword, PrivateKey ownerKeyEnc,
		PrivateKey ownerKeySign, Map<String, X509Certificate> knownDevices,
		Collection<VCard> knownContacts) throws IOException {
	super(PairingType.MASTER, password, eMail, firstName, lastName,
			deviceName, keyPassword, ownerKeyEnc, ownerKeySign,
			knownDevices, knownContacts);
	UUID uuid = new UUID(0x1101); // TODO: Create new unique UUID
	String connectionString = "btspp://localhost:" + uuid
			+ ";name=PanboxImportListener;encrypt=false;authenticate=false";
	streamConnNotifier = (StreamConnectionNotifier) Connector.open(
			connectionString, Connector.READ_WRITE);
	ServiceRecord record = LocalDevice.getLocalDevice().getRecord(
			streamConnNotifier);
	logger.debug("PAKBluetoothPairingHandler : connection is up at: "
			+ record.getConnectionURL(0, false));
}
 
Example 6
Project: PanBox   File: PanboxClient.java   Source Code and License 6 votes vote down vote up
public BluetoothPairingInformation initDevicePairingBluetooth()
		throws BluetoothStateException, InterruptedException {
	// This is the first time we are going to touch the Bluetooth API so we
	// should attach our logger to the com.intel.bluetooth logging
	appendBluetoothLogging();

	// Make bluetooth device discoverbale!
	LocalDevice local = LocalDevice.getLocalDevice();
	try {
		local.setDiscoverable(DiscoveryAgent.GIAC);
	} catch (BluetoothStateException e) {
		logger.debug(
				"PanboxClient : initDevicePairingBluetooth : First try to set discoverable failed. Will try again in 1sec.");
		Thread.sleep(1000);
		local.setDiscoverable(DiscoveryAgent.GIAC);
	}

	// setting LocalDevice is only need for Linux, since on Windows we
	// bluecove only supports one device!
	BluetoothPairingInformation info = new BluetoothPairingInformation(local);
	extendPairingInformation(info);
	return info;
}
 
Example 7
Project: Blaubot   File: rfcommserver.java   Source Code and License 6 votes vote down vote up
public static void main(String args[]) {
    try {
        LocalDevice local = LocalDevice.getLocalDevice();
        System.out.println("Server Started:\n"
                + local.getBluetoothAddress()
                + "\n" + local.getFriendlyName());

        rfcommserver ff = new rfcommserver();
        while (true) {
            ff.startserver();
        } //while
    }  //try
    catch (Exception e) {
        System.err.print(e.toString());
    }
}
 
Example 8
Project: briar   File: BluetoothPlugin.java   Source Code and License 6 votes vote down vote up
public boolean start() throws IOException {
	// Initialise the Bluetooth stack
	try {
		localDevice = LocalDevice.getLocalDevice();
	} catch(UnsatisfiedLinkError e) {
		// On Linux the user may need to install libbluetooth-dev
		if(OsUtils.isLinux())
			callback.showMessage("BLUETOOTH_INSTALL_LIBS");
		return false;
	}
	if(LOG.isLoggable(INFO))
		LOG.info("Local address " + localDevice.getBluetoothAddress());
	running = true;
	bind();
	return true;
}
 
Example 9
Project: dazzl   File: MonitoringThreadImpl.java   Source Code and License 6 votes vote down vote up
/**
 * Creates a new instance.
 * 
 */
MonitoringThreadImpl() throws BluetoothException
{
    super("Bluetooth Monitoring"); //$NON-NLS-1$
    try
    {
        this.localDevice = LocalDevice.getLocalDevice();
    }
    catch (BluetoothStateException e)
    {
        throw new BluetoothException(e.getMessage());
    }

    this.localAddress = localDevice.getBluetoothAddress();
    this.localName = localDevice.getFriendlyName();
    this.discoveryAgent = localDevice.getDiscoveryAgent();

    logger.debug("LocalAdress: " + localAddress + ", Name: " + localName); //$NON-NLS-1$ //$NON-NLS-2$
    
    this.monitoringListeners = new ArrayList();
    this.discoveryInProgress = false;
    this.pass = 0;
}
 
Example 10
Project: commcare-j2me   File: BluetoothClient.java   Source Code and License 6 votes vote down vote up
/**
 * Process the search/download requests.
 */
public void init() {

    try {
        // create/get a local device and discovery agent
        LocalDevice localDevice = LocalDevice.getLocalDevice();
        discoveryAgent = localDevice.getDiscoveryAgent();
    } catch (Exception e) {
        eventListener.errorOccured("Can't initialize bluetooth: ", e);
        System.err.println("Can't initialize bluetooth: " + e);
    }

    // initialize some optimization variables
    uuidSet = new UUID[2];

    // ok, we are interesting in btspp services only
    uuidSet[0] = new UUID(0x1101);

    // and only known ones, that allows pictures
    uuidSet[1] = SERVER_UUID;
}
 
Example 11
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 12
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 13
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 14
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 15
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 16
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 17
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 18
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 19
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 20
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 21
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 22
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 23
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 24
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 25
Project: GPLshared   File: BluetoothServiceDiscovery.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * This method is used to re-establish a connection to a device when we have the address.  
 *
 * @param address The address to the device
 */
public void startServiceSearch(String address){
    // Connects to a remote device with the given address     
    RemoteDeviceInstance remoteDevice = new RemoteDeviceInstance(address);
    try{
        localDevice = LocalDevice.getLocalDevice();   
        agent = localDevice.getDiscoveryAgent();
        uuids[0] = new UUID(uuidString, false);
        servicesFound = new Vector();
        devicesFound = new Vector();
        agent.searchServices(attributes,uuids,remoteDevice,this);
    }catch(BluetoothStateException bse) {
        log.logException("BluetoothServiceDiscovery.startServiceSearch()",bse, false);
        // throw bse;
    }
}
 
Example 26
Project: worldmap-classic   File: Util.java   Source Code and License 6 votes vote down vote up
public static void printLocalDevice(LocalDevice dev) {
	System.out.println("Print Local Device " + dev.getBluetoothAddress());
	System.out.println("Name: " + dev.getFriendlyName());
	DeviceClass devClass = dev.getDeviceClass();
	if (devClass != null) {
		System.out.println("MajorDevice:"
				+ majorToName(devClass.getMajorDeviceClass()));
		System.out.println("MinorDevice:"
				+ minorToName(devClass.getMajorDeviceClass(),
				devClass.getMinorDeviceClass()));
		System.out.println("ServiceClass:");
		String[] str = Util.majorServiceToName(devClass.getServiceClasses());
		for (int i = 0; i < str.length; i++) {
			System.out.println("  " + str[i]);
		}
	}

}
 
Example 27
Project: BGSEP   File: BluetoothServer.java   Source Code and License 6 votes vote down vote up
private BluetoothServer() {
	clients = new ConcurrentHashMap<Integer, BluetoothClient>();
	try {
		device = LocalDevice.getLocalDevice();
		if (device != null) {
			if (!LocalDevice.isPowerOn()) {
				System.out.println("Device power is off. Turn it on!");
				System.exit(1);
			}
		} else {
			System.out.println("No device");
			System.exit(1);
		}
	} catch (BluetoothStateException e) {
		System.out.println(e.getMessage());
		System.exit(1);

	}
}
 
Example 28
Project: mkRemote   File: BluetoothMouseMoveServer.java   Source Code and License 6 votes vote down vote up
public void start() {
    try {
        localDevice = LocalDevice.getLocalDevice();
        address = Bluetooth
                .formatAddress(localDevice.getBluetoothAddress());
        try {
            if (!localDevice.setDiscoverable(DiscoveryAgent.GIAC)) {
                logger.debug("Could not set discoverable to GIAC");
            }
        } catch (Throwable sd) {
            logger.debug("Could not set discoverable to GIAC", sd);
        }
        thread = new BluetoothServerThread();
        thread.setName("BluetoothMouseMoveServer");
        thread.start();
        bluetoothSupported = true;
    } catch (Throwable t) {
        logger.debug("Bluetooth not supported due to {}", t.toString());
    }
}
 
Example 29
Project: PanBox   File: PAKBluetoothPairingHandler.java   Source Code and License 5 votes vote down vote up
@Override
public void initCommunication() throws Exception {
	this.dataInputStream = new ObjectInputStream(
			connection.openDataInputStream());
	this.dataOutputStream = new ObjectOutputStream(
			connection.openDataOutputStream());
	this.idA = RemoteDevice.getRemoteDevice(connection)
			.getBluetoothAddress();
	this.idB = LocalDevice.getLocalDevice().getBluetoothAddress();
}
 
Example 30
Project: GPLshared   File: BluetoothNetwork.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method returns the node address.
   *
   * @param input String "localNode" to retreive the address of the local device. 
   * A ServiceRecord or StreamConnection object to retreive the address of a 
   * remote device.
   * 
   * @return The node network address.
   * @throws IOException 
   */
  public String getNodeAddress(Object input) throws IOException{      
  		
// Checks whether the input is a String and the String equals "localnode".
// If so the address of the LocalDevice is returned.
if(input.getClass().isInstance(new String())){
	String inputString = (String)input;
	// Make sure that we won't get any UPPER/lower case problems
	inputString.toLowerCase();
	if(inputString.equals("localnode"))return LocalDevice.getLocalDevice().getBluetoothAddress();
}
  	
      // Input type is object because superclass cannot relate to ServiceRecord which is a bluetooth specific class.
      // This method is valid either the input type is ServiceRecord or StreamConnection.
      RemoteDevice remoteDevice = null;
      try{
          ServiceRecord serviceRecord = (ServiceRecord) input;
          remoteDevice = serviceRecord.getHostDevice();            
      }catch(ClassCastException cce1){
          // Could not cast the input object to ServiceRecord. Trying streamConnection instead ;-)
          try{
              StreamConnection streamConnection = (StreamConnection) input;            
              remoteDevice = RemoteDevice.getRemoteDevice(streamConnection);
          }catch(ClassCastException cce2){
              //This will only happen if the input object type is wrong
              log.logException("BluetoothNetwork.getNodeAddress()",cce2,false);
          }catch(IOException ioe){
              log.logException("BluetoothNetwork.getNodeAddress()",ioe,false);
              throw ioe;
          }            
      }
      return remoteDevice.getBluetoothAddress();
  }
 
Example 31
Project: GPLshared   File: BluetoothNetwork.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method returns the node address.
   *
   * @param input String "localNode" to retreive the address of the local device. 
   * A ServiceRecord or StreamConnection object to retreive the address of a 
   * remote device.
   * 
   * @return The node network address.
   * @throws IOException 
   */
  public String getNodeAddress(Object input) throws IOException{      
  		
// Checks whether the input is a String and the String equals "localnode".
// If so the address of the LocalDevice is returned.
if(input.getClass().isInstance(new String())){
	String inputString = (String)input;
	// Make sure that we won't get any UPPER/lower case problems
	inputString.toLowerCase();
	if(inputString.equals("localnode"))return LocalDevice.getLocalDevice().getBluetoothAddress();
}
  	
      // Input type is object because superclass cannot relate to ServiceRecord which is a bluetooth specific class.
      // This method is valid either the input type is ServiceRecord or StreamConnection.
      RemoteDevice remoteDevice = null;
      try{
          ServiceRecord serviceRecord = (ServiceRecord) input;
          remoteDevice = serviceRecord.getHostDevice();            
      }catch(ClassCastException cce1){
          // Could not cast the input object to ServiceRecord. Trying streamConnection instead ;-)
          try{
              StreamConnection streamConnection = (StreamConnection) input;            
              remoteDevice = RemoteDevice.getRemoteDevice(streamConnection);
          }catch(ClassCastException cce2){
              //This will only happen if the input object type is wrong
              log.logException("BluetoothNetwork.getNodeAddress()",cce2,false);
          }catch(IOException ioe){
              log.logException("BluetoothNetwork.getNodeAddress()",ioe,false);
              throw ioe;
          }            
      }
      return remoteDevice.getBluetoothAddress();
  }
 
Example 32
Project: GPLshared   File: BluetoothNetwork.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method returns the node address.
   *
   * @param input String "localNode" to retreive the address of the local device. 
   * A ServiceRecord or StreamConnection object to retreive the address of a 
   * remote device.
   * 
   * @return The node network address.
   * @throws IOException 
   */
  public String getNodeAddress(Object input) throws IOException{      
  		
// Checks whether the input is a String and the String equals "localnode".
// If so the address of the LocalDevice is returned.
if(input.getClass().isInstance(new String())){
	String inputString = (String)input;
	// Make sure that we won't get any UPPER/lower case problems
	inputString.toLowerCase();
	if(inputString.equals("localnode"))return LocalDevice.getLocalDevice().getBluetoothAddress();
}
  	
      // Input type is object because superclass cannot relate to ServiceRecord which is a bluetooth specific class.
      // This method is valid either the input type is ServiceRecord or StreamConnection.
      RemoteDevice remoteDevice = null;
      try{
          ServiceRecord serviceRecord = (ServiceRecord) input;
          remoteDevice = serviceRecord.getHostDevice();            
      }catch(ClassCastException cce1){
          // Could not cast the input object to ServiceRecord. Trying streamConnection instead ;-)
          try{
              StreamConnection streamConnection = (StreamConnection) input;            
              remoteDevice = RemoteDevice.getRemoteDevice(streamConnection);
          }catch(ClassCastException cce2){
              //This will only happen if the input object type is wrong
              log.logException("BluetoothNetwork.getNodeAddress()",cce2,false);
          }catch(IOException ioe){
              log.logException("BluetoothNetwork.getNodeAddress()",ioe,false);
              throw ioe;
          }            
      }
      return remoteDevice.getBluetoothAddress();
  }
 
Example 33
Project: GPLshared   File: BluetoothNetwork.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method returns the node address.
   *
   * @param input String "localNode" to retreive the address of the local device. 
   * A ServiceRecord or StreamConnection object to retreive the address of a 
   * remote device.
   * 
   * @return The node network address.
   * @throws IOException 
   */
  public String getNodeAddress(Object input) throws IOException{      
  		
// Checks whether the input is a String and the String equals "localnode".
// If so the address of the LocalDevice is returned.
if(input.getClass().isInstance(new String())){
	String inputString = (String)input;
	// Make sure that we won't get any UPPER/lower case problems
	inputString.toLowerCase();
	if(inputString.equals("localnode"))return LocalDevice.getLocalDevice().getBluetoothAddress();
}
  	
      // Input type is object because superclass cannot relate to ServiceRecord which is a bluetooth specific class.
      // This method is valid either the input type is ServiceRecord or StreamConnection.
      RemoteDevice remoteDevice = null;
      try{
          ServiceRecord serviceRecord = (ServiceRecord) input;
          remoteDevice = serviceRecord.getHostDevice();            
      }catch(ClassCastException cce1){
          // Could not cast the input object to ServiceRecord. Trying streamConnection instead ;-)
          try{
              StreamConnection streamConnection = (StreamConnection) input;            
              remoteDevice = RemoteDevice.getRemoteDevice(streamConnection);
          }catch(ClassCastException cce2){
              //This will only happen if the input object type is wrong
              log.logException("BluetoothNetwork.getNodeAddress()",cce2,false);
          }catch(IOException ioe){
              log.logException("BluetoothNetwork.getNodeAddress()",ioe,false);
              throw ioe;
          }            
      }
      return remoteDevice.getBluetoothAddress();
  }
 
Example 34
Project: GPLshared   File: BluetoothNetwork.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method returns the node address.
   *
   * @param input String "localNode" to retreive the address of the local device. 
   * A ServiceRecord or StreamConnection object to retreive the address of a 
   * remote device.
   * 
   * @return The node network address.
   * @throws IOException 
   */
  public String getNodeAddress(Object input) throws IOException{      
  		
// Checks whether the input is a String and the String equals "localnode".
// If so the address of the LocalDevice is returned.
if(input.getClass().isInstance(new String())){
	String inputString = (String)input;
	// Make sure that we won't get any UPPER/lower case problems
	inputString.toLowerCase();
	if(inputString.equals("localnode"))return LocalDevice.getLocalDevice().getBluetoothAddress();
}
  	
      // Input type is object because superclass cannot relate to ServiceRecord which is a bluetooth specific class.
      // This method is valid either the input type is ServiceRecord or StreamConnection.
      RemoteDevice remoteDevice = null;
      try{
          ServiceRecord serviceRecord = (ServiceRecord) input;
          remoteDevice = serviceRecord.getHostDevice();            
      }catch(ClassCastException cce1){
          // Could not cast the input object to ServiceRecord. Trying streamConnection instead ;-)
          try{
              StreamConnection streamConnection = (StreamConnection) input;            
              remoteDevice = RemoteDevice.getRemoteDevice(streamConnection);
          }catch(ClassCastException cce2){
              //This will only happen if the input object type is wrong
              log.logException("BluetoothNetwork.getNodeAddress()",cce2,false);
          }catch(IOException ioe){
              log.logException("BluetoothNetwork.getNodeAddress()",ioe,false);
              throw ioe;
          }            
      }
      return remoteDevice.getBluetoothAddress();
  }
 
Example 35
Project: GPLshared   File: BluetoothNetwork.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method returns the node address.
   *
   * @param input String "localNode" to retreive the address of the local device. 
   * A ServiceRecord or StreamConnection object to retreive the address of a 
   * remote device.
   * 
   * @return The node network address.
   * @throws IOException 
   */
  public String getNodeAddress(Object input) throws IOException{      
  		
// Checks whether the input is a String and the String equals "localnode".
// If so the address of the LocalDevice is returned.
if(input.getClass().isInstance(new String())){
	String inputString = (String)input;
	// Make sure that we won't get any UPPER/lower case problems
	inputString.toLowerCase();
	if(inputString.equals("localnode"))return LocalDevice.getLocalDevice().getBluetoothAddress();
}
  	
      // Input type is object because superclass cannot relate to ServiceRecord which is a bluetooth specific class.
      // This method is valid either the input type is ServiceRecord or StreamConnection.
      RemoteDevice remoteDevice = null;
      try{
          ServiceRecord serviceRecord = (ServiceRecord) input;
          remoteDevice = serviceRecord.getHostDevice();            
      }catch(ClassCastException cce1){
          // Could not cast the input object to ServiceRecord. Trying streamConnection instead ;-)
          try{
              StreamConnection streamConnection = (StreamConnection) input;            
              remoteDevice = RemoteDevice.getRemoteDevice(streamConnection);
          }catch(ClassCastException cce2){
              //This will only happen if the input object type is wrong
              log.logException("BluetoothNetwork.getNodeAddress()",cce2,false);
          }catch(IOException ioe){
              log.logException("BluetoothNetwork.getNodeAddress()",ioe,false);
              throw ioe;
          }            
      }
      return remoteDevice.getBluetoothAddress();
  }
 
Example 36
Project: GPLshared   File: BluetoothNetwork.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method returns the node address.
   *
   * @param input String "localNode" to retreive the address of the local device. 
   * A ServiceRecord or StreamConnection object to retreive the address of a 
   * remote device.
   * 
   * @return The node network address.
   * @throws IOException 
   */
  public String getNodeAddress(Object input) throws IOException{      
  		
// Checks whether the input is a String and the String equals "localnode".
// If so the address of the LocalDevice is returned.
if(input.getClass().isInstance(new String())){
	String inputString = (String)input;
	// Make sure that we won't get any UPPER/lower case problems
	inputString.toLowerCase();
	if(inputString.equals("localnode"))return LocalDevice.getLocalDevice().getBluetoothAddress();
}
  	
      // Input type is object because superclass cannot relate to ServiceRecord which is a bluetooth specific class.
      // This method is valid either the input type is ServiceRecord or StreamConnection.
      RemoteDevice remoteDevice = null;
      try{
          ServiceRecord serviceRecord = (ServiceRecord) input;
          remoteDevice = serviceRecord.getHostDevice();            
      }catch(ClassCastException cce1){
          // Could not cast the input object to ServiceRecord. Trying streamConnection instead ;-)
          try{
              StreamConnection streamConnection = (StreamConnection) input;            
              remoteDevice = RemoteDevice.getRemoteDevice(streamConnection);
          }catch(ClassCastException cce2){
              //This will only happen if the input object type is wrong
              log.logException("BluetoothNetwork.getNodeAddress()",cce2,false);
          }catch(IOException ioe){
              log.logException("BluetoothNetwork.getNodeAddress()",ioe,false);
              throw ioe;
          }            
      }
      return remoteDevice.getBluetoothAddress();
  }
 
Example 37
Project: GPLshared   File: BluetoothNetwork.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method returns the node address.
   *
   * @param input String "localNode" to retreive the address of the local device. 
   * A ServiceRecord or StreamConnection object to retreive the address of a 
   * remote device.
   * 
   * @return The node network address.
   * @throws IOException 
   */
  public String getNodeAddress(Object input) throws IOException{      
  		
// Checks whether the input is a String and the String equals "localnode".
// If so the address of the LocalDevice is returned.
if(input.getClass().isInstance(new String())){
	String inputString = (String)input;
	// Make sure that we won't get any UPPER/lower case problems
	inputString.toLowerCase();
	if(inputString.equals("localnode"))return LocalDevice.getLocalDevice().getBluetoothAddress();
}
  	
      // Input type is object because superclass cannot relate to ServiceRecord which is a bluetooth specific class.
      // This method is valid either the input type is ServiceRecord or StreamConnection.
      RemoteDevice remoteDevice = null;
      try{
          ServiceRecord serviceRecord = (ServiceRecord) input;
          remoteDevice = serviceRecord.getHostDevice();            
      }catch(ClassCastException cce1){
          // Could not cast the input object to ServiceRecord. Trying streamConnection instead ;-)
          try{
              StreamConnection streamConnection = (StreamConnection) input;            
              remoteDevice = RemoteDevice.getRemoteDevice(streamConnection);
          }catch(ClassCastException cce2){
              //This will only happen if the input object type is wrong
              log.logException("BluetoothNetwork.getNodeAddress()",cce2,false);
          }catch(IOException ioe){
              log.logException("BluetoothNetwork.getNodeAddress()",ioe,false);
              throw ioe;
          }            
      }
      return remoteDevice.getBluetoothAddress();
  }
 
Example 38
Project: GPLshared   File: BluetoothNetwork.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method returns the node address.
   *
   * @param input String "localNode" to retreive the address of the local device. 
   * A ServiceRecord or StreamConnection object to retreive the address of a 
   * remote device.
   * 
   * @return The node network address.
   * @throws IOException 
   */
  public String getNodeAddress(Object input) throws IOException{      
  		
// Checks whether the input is a String and the String equals "localnode".
// If so the address of the LocalDevice is returned.
if(input.getClass().isInstance(new String())){
	String inputString = (String)input;
	// Make sure that we won't get any UPPER/lower case problems
	inputString.toLowerCase();
	if(inputString.equals("localnode"))return LocalDevice.getLocalDevice().getBluetoothAddress();
}
  	
      // Input type is object because superclass cannot relate to ServiceRecord which is a bluetooth specific class.
      // This method is valid either the input type is ServiceRecord or StreamConnection.
      RemoteDevice remoteDevice = null;
      try{
          ServiceRecord serviceRecord = (ServiceRecord) input;
          remoteDevice = serviceRecord.getHostDevice();            
      }catch(ClassCastException cce1){
          // Could not cast the input object to ServiceRecord. Trying streamConnection instead ;-)
          try{
              StreamConnection streamConnection = (StreamConnection) input;            
              remoteDevice = RemoteDevice.getRemoteDevice(streamConnection);
          }catch(ClassCastException cce2){
              //This will only happen if the input object type is wrong
              log.logException("BluetoothNetwork.getNodeAddress()",cce2,false);
          }catch(IOException ioe){
              log.logException("BluetoothNetwork.getNodeAddress()",ioe,false);
              throw ioe;
          }            
      }
      return remoteDevice.getBluetoothAddress();
  }
 
Example 39
Project: GPLshared   File: BluetoothNetwork.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method returns the node address.
   *
   * @param input String "localNode" to retreive the address of the local device. 
   * A ServiceRecord or StreamConnection object to retreive the address of a 
   * remote device.
   * 
   * @return The node network address.
   * @throws IOException 
   */
  public String getNodeAddress(Object input) throws IOException{      
  		
// Checks whether the input is a String and the String equals "localnode".
// If so the address of the LocalDevice is returned.
if(input.getClass().isInstance(new String())){
	String inputString = (String)input;
	// Make sure that we won't get any UPPER/lower case problems
	inputString.toLowerCase();
	if(inputString.equals("localnode"))return LocalDevice.getLocalDevice().getBluetoothAddress();
}
  	
      // Input type is object because superclass cannot relate to ServiceRecord which is a bluetooth specific class.
      // This method is valid either the input type is ServiceRecord or StreamConnection.
      RemoteDevice remoteDevice = null;
      try{
          ServiceRecord serviceRecord = (ServiceRecord) input;
          remoteDevice = serviceRecord.getHostDevice();            
      }catch(ClassCastException cce1){
          // Could not cast the input object to ServiceRecord. Trying streamConnection instead ;-)
          try{
              StreamConnection streamConnection = (StreamConnection) input;            
              remoteDevice = RemoteDevice.getRemoteDevice(streamConnection);
          }catch(ClassCastException cce2){
              //This will only happen if the input object type is wrong
              log.logException("BluetoothNetwork.getNodeAddress()",cce2,false);
          }catch(IOException ioe){
              log.logException("BluetoothNetwork.getNodeAddress()",ioe,false);
              throw ioe;
          }            
      }
      return remoteDevice.getBluetoothAddress();
  }
 
Example 40
Project: GPLshared   File: BluetoothNetwork.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method returns the node address.
   *
   * @param input String "localNode" to retreive the address of the local device. 
   * A ServiceRecord or StreamConnection object to retreive the address of a 
   * remote device.
   * 
   * @return The node network address.
   * @throws IOException 
   */
  public String getNodeAddress(Object input) throws IOException{      
  		
// Checks whether the input is a String and the String equals "localnode".
// If so the address of the LocalDevice is returned.
if(input.getClass().isInstance(new String())){
	String inputString = (String)input;
	// Make sure that we won't get any UPPER/lower case problems
	inputString.toLowerCase();
	if(inputString.equals("localnode"))return LocalDevice.getLocalDevice().getBluetoothAddress();
}
  	
      // Input type is object because superclass cannot relate to ServiceRecord which is a bluetooth specific class.
      // This method is valid either the input type is ServiceRecord or StreamConnection.
      RemoteDevice remoteDevice = null;
      try{
          ServiceRecord serviceRecord = (ServiceRecord) input;
          remoteDevice = serviceRecord.getHostDevice();            
      }catch(ClassCastException cce1){
          // Could not cast the input object to ServiceRecord. Trying streamConnection instead ;-)
          try{
              StreamConnection streamConnection = (StreamConnection) input;            
              remoteDevice = RemoteDevice.getRemoteDevice(streamConnection);
          }catch(ClassCastException cce2){
              //This will only happen if the input object type is wrong
              log.logException("BluetoothNetwork.getNodeAddress()",cce2,false);
          }catch(IOException ioe){
              log.logException("BluetoothNetwork.getNodeAddress()",ioe,false);
              throw ioe;
          }            
      }
      return remoteDevice.getBluetoothAddress();
  }
 
Example 41
Project: GPLshared   File: BluetoothNetwork.java   Source Code and License 5 votes vote down vote up
/**
   * 
   * This method returns the node address.
   *
   * @param input String "localNode" to retreive the address of the local device. 
   * A ServiceRecord or StreamConnection object to retreive the address of a 
   * remote device.
   * 
   * @return The node network address.
   * @throws IOException 
   */
  public String getNodeAddress(Object input) throws IOException{      
  		
// Checks whether the input is a String and the String equals "localnode".
// If so the address of the LocalDevice is returned.
if(input.getClass().isInstance(new String())){
	String inputString = (String)input;
	// Make sure that we won't get any UPPER/lower case problems
	inputString.toLowerCase();
	if(inputString.equals("localnode"))return LocalDevice.getLocalDevice().getBluetoothAddress();
}
  	
      // Input type is object because superclass cannot relate to ServiceRecord which is a bluetooth specific class.
      // This method is valid either the input type is ServiceRecord or StreamConnection.
      RemoteDevice remoteDevice = null;
      try{
          ServiceRecord serviceRecord = (ServiceRecord) input;
          remoteDevice = serviceRecord.getHostDevice();            
      }catch(ClassCastException cce1){
          // Could not cast the input object to ServiceRecord. Trying streamConnection instead ;-)
          try{
              StreamConnection streamConnection = (StreamConnection) input;            
              remoteDevice = RemoteDevice.getRemoteDevice(streamConnection);
          }catch(ClassCastException cce2){
              //This will only happen if the input object type is wrong
              log.logException("BluetoothNetwork.getNodeAddress()",cce2,false);
          }catch(IOException ioe){
              log.logException("BluetoothNetwork.getNodeAddress()",ioe,false);
              throw ioe;
          }            
      }
      return remoteDevice.getBluetoothAddress();
  }
 
Example 42
Project: sphero-bluecove   File: SpheroDiscovery.java   Source Code and License 5 votes vote down vote up
public ArrayList<Sphero> findNearbySpheros() throws BluetoothStateException, InterruptedException {
	spherosDiscovered.clear();
			
	synchronized(inquiryCompletedEvent) {
           boolean isInquiryStarted = LocalDevice.getLocalDevice().getDiscoveryAgent().startInquiry(DiscoveryAgent.GIAC, (DiscoveryListener) listener);
           if (isInquiryStarted) {
               System.out.println("Waiting for inquiry to complete...");
               inquiryCompletedEvent.wait();
               System.out.println("Found " + spherosDiscovered.size() +  " Sphero(s)!");
           }
       }
	
	// Search for RN-SPP service on Sphero
	UUID serviceUUID = new UUID("0000110100001000800000805F9B34FB", false); // RN-SPP (RN-42)
	
	UUID[] searchUuidSet = new UUID[] { serviceUUID };
	int[] attrIDs = null;

       for(Sphero s : spherosDiscovered) {
           synchronized(serviceSearchCompletedEvent) {
               System.out.println("Searching services on " + s.getBluetoothAddress() + "  " + s.getFriendlyName() + "...");
               LocalDevice.getLocalDevice().getDiscoveryAgent().searchServices(attrIDs, searchUuidSet, s, listener);
               serviceSearchCompletedEvent.wait();
           }
           if(spheroServiceURL == null) {
           	System.out.println("No services found. Using default Sphero service URL.");
           } else {
           	s.setSpheroUrl(spheroServiceURL);
           }
       }
       
	return spherosDiscovered;
}
 
Example 43
Project: worldmap-classic   File: BLUElet.java   Source Code and License 5 votes vote down vote up
/**
 * Start device inquiry. Your application call this method to start inquiry.
 * @param mode int one of DiscoveryAgent.GIAC or DiscoveryAgent.LIAC
 * @param serviceUUIDs UUID[]
 */
public void startInquiry(int mode, UUID[] serviceUUIDs) {
	try {
		this.discoveryMode = mode;
		this.serviceUUIDs = serviceUUIDs;

		// clear previous values first
		devices.removeAllElements();
		deviceClasses.removeAllElements();

		//
		// initialize the JABWT stack
		device = LocalDevice.getLocalDevice(); // obtain reference to singleton
		device.setDiscoverable(DiscoveryAgent.GIAC); // set Discover Mode
		agent = device.getDiscoveryAgent(); // obtain reference to singleton


		boolean result = agent.startInquiry(mode, this.listener = new Listener());

		// update screen with "Please Wait" message
		remotedeviceui.setMsg("[Please Wait...]");

	} catch (BluetoothStateException e) {
		e.printStackTrace();
	}

}
 
Example 44
Project: bluecove-osx   File: SimpleDiscovery.java   Source Code and License 5 votes vote down vote up
public boolean startInquiry() {
	inquiring = false;
	devices = new Vector();
	try {
		inquiring = LocalDevice.getLocalDevice().getDiscoveryAgent().startInquiry(DiscoveryAgent.GIAC, this);
	} catch (BluetoothStateException e) {
		System.err.println("Cannot start inquiry: " + e);
		return false;
	}
	return inquiring;
}
 
Example 45
Project: bluecove-osx   File: SimpleClient.java   Source Code and License 5 votes vote down vote up
public void run() {
	try {
		Thread.sleep(20000);
	} catch (InterruptedException e) {
		e.printStackTrace();
	}

	if (!this.inquiryCompleted) {
		System.out.println("cancelling inquiry on timeout");

		try {
			if (LocalDevice.getLocalDevice().getDiscoveryAgent().cancelInquiry(client)) {
				System.out.println("inquiry cancelled");		
			}
		} catch (BluetoothStateException bse) {
			System.out.println("Got BluetoothStateException: " + bse);
		}
	}
}
 
Example 46
Project: mkRemote   File: BluetoothServer.java   Source Code and License 5 votes vote down vote up
public void start() {
    try {
        localDevice = LocalDevice.getLocalDevice();
        address = Bluetooth
                .formatAddress(localDevice.getBluetoothAddress());
        logger.debug("Bluetooth stack type is {}",
                LocalDevice.getProperty("bluecove.stack"));
        logger.debug("Bluetooth name {}", localDevice.getFriendlyName());
        logger.debug("Bluetooth address {}", address);
        logger.debug("Bluetooth API Version {}",
                LocalDevice.getProperty("bluetooth.api.version"));
        try {
            if (!localDevice.setDiscoverable(DiscoveryAgent.GIAC)) {
                logger.debug("Could not set discoverable to GIAC");
            }
        } catch (Throwable sd) {
            logger.debug("Could not set discoverable to GIAC", sd);
        }

        thread = new BluetoothServerThread();
        thread.setName("BluetoothServer");
        thread.start();
        bluetoothSupported = true;
    } catch (Throwable t) {
        logger.debug("Bluetooth not supported due to {}", t.toString());
    }
}
 
Example 47
Project: BluetoothRecord   File: ServerCommand.java   Source Code and License 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    
    //display local device address and name
    LocalDevice localDevice = LocalDevice.getLocalDevice();
    System.out.println("Address: "+localDevice.getBluetoothAddress());
    System.out.println("Name: "+localDevice.getFriendlyName());
    
    BTServer BTCommand=new BTServer();
    BTCommand.startServer();
    
}
 
Example 48
Project: jbeagle   File: BeagleUtil.java   Source Code and License 5 votes vote down vote up
/**
 * Try to connect to a txtr beagle
 * 
 * @return the beagle, if found; null, if not found
 * @throws IOException
 *             if an error occurs
 */
public static BeagleConnector searchForBeagle() throws IOException {
	DiscoveryAgent da = LocalDevice.getLocalDevice().getDiscoveryAgent();
	RemoteDevice[] devices = da.retrieveDevices(DiscoveryAgent.PREKNOWN);
	if (devices == null)
		return null;
	for (RemoteDevice r : devices) {
		if ("Beagle".equals(r.getFriendlyName(false)) || "txtr beagle".equals(r.getFriendlyName(false)) ) {
			try {
				StreamConnection connection = (StreamConnection) Connector
						.open("btspp://"
								+ r.getBluetoothAddress()
								+ ":1;authenticate=false;encrypt=false;master=false");
				return new BeagleConnector(connection);
			} catch (IOException e) {
			}
		}
	}
	return null;
}
 
Example 49
Project: Wii-Gesture   File: MoteFinder.java   Source Code and License 5 votes vote down vote up
/**
 * Returns the <code>WiimoteFinder</code> instance.
 * 
 * @return WiimoteFinder
 */
public static MoteFinder getMoteFinder() {
	try {
		// disable PSM minimum flag because the wiimote has a PSM below 0x1001
		System.setProperty(BlueCoveConfigProperties.PROPERTY_JSR_82_PSM_MINIMUM_OFF, "true");

		SingletonHolder.INSTANCE.localDevice = LocalDevice.getLocalDevice();
		SingletonHolder.INSTANCE.discoveryAgent = SingletonHolder.INSTANCE.localDevice.getDiscoveryAgent();
		return SingletonHolder.INSTANCE;
	} catch (BluetoothStateException ex) {
		throw new RuntimeException(ex);
	}
}
 
Example 50
Project: pcstatus   File: ConnectionManager.java   Source Code and License 4 votes vote down vote up
/**
 * this method instantiates the class and starts the server, otherwise
 * tells the model that the bluetooth is unavailable
 */
private void bluetoothThread() {
    try {
        SingletonStaticGeneralStats.getInstance().setBluetoothName(LocalDevice.getLocalDevice().getFriendlyName());
        bluetooth = new BluetoothSPPServer();
        bluetooth.startServerBluetooth();
    } catch (BluetoothStateException e) {
        SingletonStaticGeneralStats.getInstance().setBluetoothServerCreated(false);
        SingletonStaticGeneralStats.getInstance().setBluetoothName("Bluetooth not available");
        System.out.println("bluetooth server no started");
    }
}
 
Example 51
Project: BluetoothChat   File: Main.java   Source Code and License 4 votes vote down vote up
public Main(){
    mainContainer = new ScreensController(this);
    mainContainer.loadScreen("ChatScreen","ChatScreen.fxml");
    mainContainer.loadScreen("StartScreen","StartScreen.fxml");
    mainContainer.loadScreen("LoadingScreen","LoadingScreen.fxml");
    mainContainer.loadScreen("ServerListScreen","ServerListScreen.fxml");
    mainContainer.setScreen("StartScreen");

    try {
        LocalDevice localDevice = LocalDevice.getLocalDevice();
        myName = localDevice.getFriendlyName();
    } catch (BluetoothStateException e) {
        e.printStackTrace();
    }
}
 
Example 52
Project: Ardulink-2   File: BluetoothDiscoveryUtil.java   Source Code and License 4 votes vote down vote up
private static LocalDevice getLocalDevice() {
	try {
		return LocalDevice.getLocalDevice();
	} catch (BluetoothStateException e) {
		throw propagate(e);
	}
}
 
Example 53
Project: jolie   File: BluetoothService.java   Source Code and License 4 votes vote down vote up
public Value inquire()
	throws FaultException
{
	Value retValue = null;
	try {
		DiscoveryListenerImpl listener = new DiscoveryListenerImpl();
		LocalDevice.getLocalDevice().getDiscoveryAgent().startInquiry(
				DiscoveryAgent.GIAC,
				listener
			);
		retValue = listener.getResult();
	} catch( BluetoothStateException e ) {
		throw new FaultException( e );
	}
	return retValue;
}
 
Example 54
Project: jolie   File: BluetoothService.java   Source Code and License 4 votes vote down vote up
public Boolean setDiscoverable( Integer i )
	throws FaultException
{
	boolean b = false;
	try {
		b = LocalDevice.getLocalDevice().setDiscoverable( i );
	} catch( BluetoothStateException e ) {
		throw new FaultException ( e );
	}
	return b;
}
 
Example 55
Project: OBDig   File: OBDTestClient.java   Source Code and License 4 votes vote down vote up
public static void main(String[] args) throws IOException, InterruptedException {
	LocalDevice localDevice = LocalDevice.getLocalDevice();
	logger.info("Local Device Address: "+localDevice.getBluetoothAddress());
	logger.info("Local Device Name: "+localDevice.getFriendlyName());

	String device = resolveOBDDevice();
	int channel = resolveChannel(device);
	
	//connect to the OBD device
	StreamConnection streamConnection = (StreamConnection) Connector.open(
			String.format(deviceURL, device, channel));

	OutputStream outStream = streamConnection.openOutputStream();
	final InputStream inStream = streamConnection.openInputStream();

	//initiate the looper
	OBDCommandLooper looper = new OBDCommandLooper(inStream, outStream, "1CAF0514A493", new LocalListener(), new ConnectionListener() {
		
		@Override
		public void requestConnectionRetry(IOException reason) {
			logger.warn("requestConnectionRetry: "+reason.getMessage());
		}
		
		@Override
		public void onStatusUpdate(String message) {
			logger.info("onStatusUpdate");				
		}
		
		@Override
		public void onConnectionVerified() {
			logger.info("onConnectionVerified");				
		}
		
		@Override
		public void onAllAdaptersFailed() {
			logger.warn("onAllAdaptersFailed");				
		}
	});
	
	looper.initialize(new LocalExecutor());
	
	//do it 10 seconds
	Thread.sleep(10000);
	
	looper.stopLooper();
	streamConnection.close();
}
 
Example 56
Project: bauhinia   File: BlueCoveLibraryFacade.java   Source Code and License 4 votes vote down vote up
BlueCoveLibraryFacade() throws BluetoothStateException {
	System.setProperty(
			BlueCoveConfigProperties.PROPERTY_JSR_82_PSM_MINIMUM_OFF,
			"true");
	agent = LocalDevice.getLocalDevice().getDiscoveryAgent();
}
 
Example 57
Project: PanBox   File: BluetoothInformationContainer.java   Source Code and License 4 votes vote down vote up
public BluetoothInformationContainer(RemoteDevice remoteDevice, LocalDevice localDevice) {
    this.remoteDevice = remoteDevice;
    this.localDevice = localDevice;
}
 
Example 58
Project: PanBox   File: BluetoothPairingInformation.java   Source Code and License 4 votes vote down vote up
public BluetoothPairingInformation(LocalDevice localDevice) {
	this.localDevice = localDevice;
}
 
Example 59
Project: CaveSurveyBTEmulator   File: BluetoothServer.java   Source Code and License 4 votes vote down vote up
public Map start(String aConfig) {

        deviceDef = new Util().loadDeviceDefinition(aConfig);
        log = new StringBuilder();

        Map<String, Object> info = new HashMap<String, Object>();

        log.append("Starting\n");

        // retrieve the local Bluetooth device object
        LocalDevice local = null;

        // setup the server to listen for connection
        try {
            local = LocalDevice.getLocalDevice();

            local.setDiscoverable(DiscoveryAgent.GIAC);
            log.append("Make ").append(local.getFriendlyName()).append(" discoverable\n");

            String uuidString = (String) deviceDef.get("UUID");
            UUID uuid = new UUID(uuidString, false);
            info.put("UUID", uuidString);

            String url = "btspp://localhost:" + uuid.toString() + ";name=RemoteBluetooth";
            notifier = (StreamConnectionNotifier) Connector.open(url);

            info.put("Local btaddr", local.getBluetoothAddress());
            info.put("Local name ", local.getFriendlyName());

            String bluecoveVersion = LocalDevice.getProperty("bluecove");
            if (bluecoveVersion != null) {
                info.put("bluecove", bluecoveVersion);
                info.put("stack", LocalDevice.getProperty("bluecove.stack"));
                info.put("stack version", LocalDevice.getProperty("bluecove.stack.version"));
                info.put("radio manufacturer", LocalDevice.getProperty("bluecove.radio.manufacturer"));
                info.put("radio version", LocalDevice.getProperty("bluecove.radio.version"));
            }

        } catch (Exception e) {
            e.printStackTrace();
            log.append("Failure:\n").append(e).append("\n");
            info.put("Error", e.getMessage());
            stop();
        }

        connectThread = new ConnectThread();
        connectThread.start();

        return info;
    }
 
Example 60
Project: Blaubot   File: BlaubotJsr82BluetoothAcceptor.java   Source Code and License 4 votes vote down vote up
/**
 * @param blaubotBluetoothAdapter the blaubot adapter
 * @throws BluetoothStateException if we cannot acces the hardware bluetooth adapter
 */
public BlaubotJsr82BluetoothAcceptor(BlaubotJsr82BluetoothAdapter blaubotBluetoothAdapter) throws BluetoothStateException {
    this.blaubotBluetoothAdapter = blaubotBluetoothAdapter;
    this.localDevice = LocalDevice.getLocalDevice();
    this.localDeviceBluetoothMacAddress = localDevice.getBluetoothAddress();
}