Bluetooth dna is an object for cast the RXTX data. The bluetooth data also get from RXTX broadcast to reach all data.(refer to RXTX DNA)
The Bluetooth object (BluetoothImpl class) properties are as follow:
The Bluetooth object (BluetoothImpl class) properties are as follow:
/** * Connected ID, get from {@link com.infairy.cocina.SDK.gene.EventRXTXDNA#RXTX_ID} */ public String RXTX_ID=""; //RXTX Connected ID /** * bluetooth property (for Bluetooth 4.0 above) * refer to {@link com.infairy.cocina.SDK.device.DevicePool#BLUETOOTH_PROPERTY_NOTIFY, com.infairy.cocina.SDK.device.DevicePool#BLUETOOTH_PROPERTY_INDICATE, com.infairy.cocina.SDK.device.DevicePool#BLUETOOTH_PROPERTY_Read, com.infairy.cocina.SDK.device.DevicePool#BLUETOOTH_PROPERTY_WRITE} */ public String Property=""; /** * Bluetooth property's UUID, assign by manufacture */ public String UUID="";How can we process the bluetooth data? it's easy.
Same as RXTX section, First, import package as follows:
import org.osgi.service.event.Event; import org.osgi.service.event.EventHandler; import com.infairy.cocina.SDK.gene.EventRXTXDNA; import com.infairy.cocina.SDK.device.BluetoothImpl; import com.infairy.cocina.SDK.device.BundleDevice;then, implement "EventHandler" in your bundle class:
package yourBundle; public class BTData implements BundleActivator, EventHandler{ .... }Third, implement HandleEvent() method,
public void handleEvent(Event evnt) { ... }Then, do not forget listen RXTX broadcast channel in start() method,
package yourBundle; public class BTData implements BundleActivator, EventHandler{ .... public void start(BundleContext context) throws Exception { ... device.ListenBroadcast(context, this, device.BROADCAST_CHANNEL_RXTX); } }Last, get bluetooth data from the RXTX.
public void handleEvent(Event evnt) { EventRXTXDNA erxtx=(EventRXTXDNA)evnt.getProperty(device.BROADCAST_RXTX_EVENTOBJECT); if(erxtx==null) return; String RXTXID =erxtx.RXTX_ID; if (RXTXID == null || RXTXID.equals("")) return; String CHIPName = erxtx.RXTX_Device_Name; String rxtxtype=erxtx.RXTX_Connect_Type; if(CHIPName.startsWith("myBTDevice")){ if(rxtxtype.equals(device.RXTX_CONNECT_TYPE_DEVICE_CONNTECTED)){ BluetoothImpl btimpl=new BluetoothImpl(); btimpl.RXTX_ID=RXTXID; btimpl.Property=device.BLUETOOTH_PROPERTY_NOTIFY; btimpl.UUID="0000fff4-0000-1000-8000-00805f9b34fb"; //BlueTooth UUID, device.setBluetoothService(btimpl); }else if(rxtxtype.equals(device.RXTX_CONNECT_TYPE_DEVICE_DISCONNTECTED)){ ;// do the disconnect process return; }else if(rxtxtype.equals(device.RXTX_CONNECT_TYPE_DEVICE_CONNTECT_FAILED)){ ;// do the connect failed process return; }else if(rxtxtype.equals(device.RXTX_CONNECT_TYPE_DEVICE_CONNTECT_TIMEOUT)){ ;// do the time out process return; } byte[] data = erxtx.RXTX_Data; //process data