Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 3 → Rev 4

/DUBwise/src/BTSearcher.java
0,0 → 1,116
/***************************************
*
* searches 4 Bluetooth Devices
*
* Author: Marcus -LiGi- Bueschleb
*
* see README for further Infos
*
****************************************/
 
import javax.bluetooth.*;
 
public class BTSearcher
implements DiscoveryListener
{
private LocalDevice m_LclDevice = null;
private DiscoveryAgent m_DscrAgent=null;
 
 
 
public boolean searching=true;
public boolean error=false;
public String err_log="none";
 
 
public final int MAX_DEVICES=10;
 
public RemoteDevice[] remote_devices;
public int remote_device_count=0;
public String[] remote_device_name;
public String[] remote_device_mac;
 
 
public BTSearcher()
{
 
remote_devices=new RemoteDevice[MAX_DEVICES];
remote_device_name=new String[MAX_DEVICES];
remote_device_mac=new String[MAX_DEVICES];
 
remote_device_count=0;
}
 
public void search()
{
searching=true;
remote_device_count=0;
try
{
//First get the local device and obtain the discovery agent.
m_LclDevice = LocalDevice.getLocalDevice();
m_DscrAgent= m_LclDevice.getDiscoveryAgent();
m_DscrAgent.startInquiry(DiscoveryAgent.GIAC,this);
}
catch (BluetoothStateException ex)
{
error=true;
err_log+="Problem in searching the blue tooth devices\n" + ex;
}
 
}
 
public void inquiryCompleted(int transID) {
 
try {
for(int i=0;i<remote_device_count;i++)
{
remote_device_name[i]=remote_devices[i].getFriendlyName(true);
remote_device_mac[i]=remote_devices[i].getBluetoothAddress();
 
}
}
catch (Exception e)
{
err_log+="Problem in searching the blue tooth devices";
}
searching=false;
}
 
 
public void search_again()
{
}
 
//Called when device is found during inquiry
public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod)
{
try
{
if (remote_device_count!=(MAX_DEVICES-1))
{
remote_devices[remote_device_count]=btDevice;
remote_device_count++;
}
}
catch (Exception e)
{
err_log+=("Device Discovered Error: " + e);
}
 
}
 
 
public void serviceSearchCompleted(int transID, int respCode)
{ }
 
public void servicesDiscovered(int transID, ServiceRecord[] records)
{ }
 
 
 
}