BioRadio SDK - Java Android  1.1
BioRadio SDK - Java Android Documentation

Welcome to the BioRadio Java API for Android from Great Lakes NeuroTechnologies. This guide is intended for developers seeking to incorporate the BioRadio into their own applications. The API provides methods to scan, connect, configure, and stream data from the device.

Prerequisites

  • Java 8. Direct Download.
  • Android device running minimum OS - 7.0 Nougat (API level 24).

    Getting Started

The first task when working with a BioRadio is to identify its MAC address in order to establish a connection. If you already know your MAC ID, you can get a reference to a BioRadioDevice by instantiating a BioRadioDeviceManager and calling getBluetoothDevice(long).

{Java}
import com.glneurotech.devices.bioradio.*;
import com.glneurotech.devices.bioradio.configuration.*;
//You need a string _macID for the bluetooth device in format: "AA:BB:CC:DD:EE:FF"
string _macId = "AA:BB:CC:DD:EE:FF";
//Step 1: Create an android transport provider.
AndroidTransportProvider trans = new AndroidTransportProvider();
//Step 2: Create a BioRadio device manager.
BioRadioDeviceManager mgr = new BioRadioDeviceManager(trans);
//Step 3:Create a device using the _macID and dispaly the device info.
BioRadioDevice _device;
try {
device = mgr.getBluetoothDevice(_macId);
BatteryInfo battery = _device.GetBatteryInfo();
System.out.println("Voltage: " + battery.voltage);
LocalDateTime deviceTime = _device.getDeviceTime();
System.out.println("Current Device Time: " + deviceTime.toString());
//Update the device date and time if is off with more than 5 seconds.
if (deviceTime.compareTo(LocalDateTime.now().plusSeconds(-5)) < 0 || deviceTime.compareTo(LocalDateTime.now().plusSeconds(5)) > 0)
{
_device.setDeviceTime();
deviceTime = _device.getDeviceTime();
System.out.println("New Device Time: " + deviceTime.toString());
}
} catch (TimeoutException ex) {
ex.printStackTrace();
} catch (InterruptedException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} finally {
_device.disconnect();
}

If you do not know the MAC ID of your device, you can initiate a scan using the discoverBluetoothDevices() method. This method will return a list of discovered devices by their device ID and MAC ID.

Configuring the Device

The BioRadio can be configured in various ways depending on the intended application. The BioRadioConfiguration class is used to define the configuration of a device. The device's current configuration can be retrieved by calling getConfiguration() and it can be programmed using setConfiguration(BioRadioConfiguration value).

{Java}
//Setting the configuration using an xml file.
_device.setConfiguration(getExternalFilesDir(null) + "/ExampleBioRadioConfiguration.xml");
//Getting the device configuration:
BioRadioConfiguration config;
config = _device.getConfiguration();
//Display some of configurations:
BioRadioConfiguration config = _device.getConfiguration();
System.out.println("Termination: " + config.getTermination());
System.out.println("Name: " + config.getName());
System.out.println("PatientGroundDriven: " + config.getPatientGroundDriven());
System.out.println("PerformLeadOffDetection: " + config.getPerformLeadOffDetection());
System.out.println("SampleRate: " + config.getSampleRate());

Acquiring Data

Once your device has been located and configured, you may start acquisition by calling startAcquisition(). The device will then begin streaming signal data to your application. The BioRadio API receives the data from the BioRadio and makes it available to applications using the various Signal groups. Signal groups are collections of signals that share certain properties, such as sample rate or physical location on the device. Each signal group contains zero or more signals, based on the configuration of the device. There are various ways to retrieve the data from the signals, based on your application requirements. A common method that can be used for this purpose is getScaledValueArray().

{Java}
//Start acquisition and display the scaled values. (for 20 seconds)
scrollViewText.setText("Feel free to press a BioRadio button");
_device.startAcquisition();
bool continueLoop = true;
while (DateTime.Now < endTime && continueLoop)
int i = 0;
while (i < 3000) {
for (SignalGroup signalGroup : _device.getSignalGroups()) {
for (Signal signal : signalGroup) {
double[] samples = signal.getScaledValueArray();
for (double val : samples) {
i++;
_displayInfo += "\nFrom: " + signal.getName() + " - Value_ " + i + " : " + String.format("%1$s ", val);
if (i > 3000) {
_device.stopAcquisition();
break;
}
}
}
}
}
_device.stopAcquisition();
_device.disconnect();

Memory Mode

Data recorded to the BioRadio internal memory can be consumed using this API. To get started, create a VirtualDeviceAdapter using createVirtualDevice(String value). The VirtualDeviceAdapter serves as a wrapper around a device object from which data can be read.

{Java}
//Using a DAT file - ex:8F142215.DAT
System.out.println("Will now try to open a dat file");
com.glneurotech.devices.bioradio.VirtualDeviceAdapter virtualDevice = mgr.createVirtualDevice(getExternalFilesDir(null) + "/8F142215.DAT");
BioRadioDevice deviceInstance = (BioRadioDevice)virtualDevice.getBaseDevice();
// Loop over the file until we reach the end.
while (!virtualDevice.getEndOfFileReached()) {
// Feed the next chunk of file data. This causes the VirtualDeviceAdapter to parse the next set
// of data and make it available on its BaseDevice's Signal instances.
virtualDevice.feedNextChunk(10240);
// Iterate through the BioPotential signals and read all samples.
// This example assumes the input file only contains biopotential data, and no data in the other device signal groups.
for (Signal signal : deviceInstance.getBioPotentialSignals()) {
double[] data = signal.getScaledValueArray();
for (double value : data) {
System.out.printf("%1$s ", value);
}
}
}