public class

BluetoothVehicleInterface

extends BytestreamDataSource
implements VehicleInterface
java.lang.Object
   ↳ com.openxc.sources.BaseVehicleDataSource
     ↳ com.openxc.sources.ContextualVehicleDataSource
       ↳ com.openxc.sources.BytestreamDataSource
         ↳ com.openxc.interfaces.bluetooth.BluetoothVehicleInterface

Class Overview

A vehicle data source reading measurements from an Bluetooth-enabled OpenXC device. This class tries to connect to a previously paired Bluetooth device with a given MAC address. If found, it opens a socket to the device and streams both read and write OpenXC messages. This class requires both the android.permission.BLUETOOTH and android.permission.BLUETOOTH_ADMIN permissions.

Summary

Constants
String DEVICE_NAME_PREFIX
[Expand]
Inherited Constants
From class com.openxc.sources.BytestreamDataSource
[Expand]
Inherited Fields
From class com.openxc.sources.BytestreamDataSource
Public Constructors
BluetoothVehicleInterface(SourceCallback callback, Context context, String address)
BluetoothVehicleInterface(Context context, String address)
Public Methods
boolean isConnected()
Return true if the data source is actively connected to its target, be it a USB endpoint, a Bluetooth channel, a trace file, etc.
void setPollingStatus(boolean enabled)
Control whether periodic polling is used to detect a Bluetooth VI.
boolean setResource(String otherAddress)
Change the resource used by the instance to connect to the interface, restarting any neccessary services.
synchronized void stop()
Clear the callback so no further updates are sent.
String toString()
Protected Methods
void connect()
Initiate a connection to the vehicle interface.
void disconnect()
Perform any cleanup necessary to disconnect from the interface.
String getTag()
Return a string suitable as a tag for logging.
int read(byte[] bytes)
Read data from the source into the given array.
boolean write(byte[] bytes)
[Expand]
Inherited Methods
From class com.openxc.sources.BytestreamDataSource
From class com.openxc.sources.ContextualVehicleDataSource
From class com.openxc.sources.BaseVehicleDataSource
From class java.lang.Object
From interface com.openxc.DataPipeline.Operator
From interface com.openxc.interfaces.VehicleInterface
From interface com.openxc.sinks.VehicleDataSink
From interface com.openxc.sources.VehicleDataSource
From interface java.lang.Runnable

Constants

public static final String DEVICE_NAME_PREFIX

Constant Value: "OpenXC-VI-"

Public Constructors

public BluetoothVehicleInterface (SourceCallback callback, Context context, String address)

public BluetoothVehicleInterface (Context context, String address)

Public Methods

public boolean isConnected ()

Return true if the data source is actively connected to its target, be it a USB endpoint, a Bluetooth channel, a trace file, etc. The source is capable of providing new vehicle data. Returns true if connected, false otherwise.

public void setPollingStatus (boolean enabled)

Control whether periodic polling is used to detect a Bluetooth VI. This class opens a Bluetooth socket and will accept incoming connections from a VI that can act as the Bluetooth master. For VIs that are only able to act as slave, we have to poll for a connection occasionally to see if it's within range.

public boolean setResource (String otherAddress)

Change the resource used by the instance to connect to the interface, restarting any neccessary services.

Parameters
otherAddress The new resource to use for the interface.
Returns
  • true if the resource was different and the interface was restarted.

public synchronized void stop ()

Clear the callback so no further updates are sent. Subclasses should be sure to call super.stop() so they also stop sending updates when killed by a user.

public String toString ()

Protected Methods

protected void connect ()

Initiate a connection to the vehicle interface.

protected void disconnect ()

Perform any cleanup necessary to disconnect from the interface.

protected String getTag ()

Return a string suitable as a tag for logging.

protected int read (byte[] bytes)

Read data from the source into the given array. No more than bytes.length bytes will be read, and there is no guarantee that any bytes will be read at all.

Parameters
bytes the destination array for bytes from the data source.
Returns
  • the number of bytes that were actually copied into bytes.
Throws
IOException

protected boolean write (byte[] bytes)