Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Minimum Android SDK : 29

  • Target Android SDK: 32

  • Compile Android SDK : 32

Introduction

The Victor SDK is made up of two aar libraries, VictoRCore and VictoRCommunications. Both are essential in working with a VictoR device. It is important users add both libraries as dependencies for a Java project dealing with VictoR devices. If working in Android Studio, the libraries can be added to the project by first navigating to the Project Structure option under the File menu.

...

Once the Project Structure window opens, users can add dependencies to the aar libraries.

...

Device Manager

Instantiation

The act of connecting and disconnecting to a device, as well as maintaining a record of connected devices, is handled by the device manager. Before any work can be done on reading, writing, and subscribing to services, users must first create and work with the device manager.

Code Block
languagejava
import com.fn.victorcommunications.VictorBleDeviceManager;

public class MainActivity extends Activity
{
    VictorBleDeviceManager deviceManager;
    
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        deviceManager = new VictorBleDeviceManager(this);
    }
}

Scanning for Devices

Once a VictorBleDeviceManager has been instantiated, a scan must be performed to identify any active VictoR devices accepting connections over bluetooth. By default, scanning for devices is set to take 10 seconds, with a query for any devices with the term “victor” in its name, with case sensitivity not taken into account. Once the scan has completed, a Set of VictorDeviceInfo objects is returned, which each contain the name and address of a VictoR device.

Code Block
languagejava
import com.fn.victorcore.VictorDeviceInfo;
import com.fn.victorcommunications.VictorBleDeviceManager;

public class MainActivity extends Activity
{
    VictorBleDeviceManager deviceManager;
    
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        deviceManager = new VictorBleDeviceManager(this);
    }
    
    public void Scan()
    {
        CompletableFuture<Set<VictorDeviceInfo>> futureScannedDevices = deviceManager.scanForDevices();
    }
}

Setting Scan Parameters

Users have a means to also specify VictorDeviceScanParameters when scanning for VictoR devices. Options include specifying the scan time, the string query for victor device names, and whether the case of the device name is important.

Code Block
languagejava
import com.fn.victorcore.VictorDeviceInfo;
import com.fn.victorcore.VictorDeviceScanParameters;
import com.fn.victorcommunications.VictorBleDeviceManager;

public class MainActivity extends Activity
{    
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        deviceManager = new VictorBleDeviceManager(this);
    }
    
    public void Scan()
    {
        deviceManager = new VictorBleDeviceManager(this);
        
        VictorDeviceScanParameters scanParameters = new VictorDeviceScanParameters();
        scanParameters.setScanTime(3000L);
    
        CompletableFuture<Set<VictorDeviceInfo>> futureScannedDevices = deviceManager.scanForDevices(scanParameters);
    }
}

Device Callbacks

Additionally, users can choose to receive a callback during the act of scanning for devices, rather than having to wait for the scan to complete. Callbacks can be set by passing a VictorDeviceCallback object that defines the onDeviceFound method.

Code Block
languagejava
import com.fn.victorcore.VictorDeviceInfo;
import com.fn.victorcore.VictorDeviceCallback;
import com.fn.victorcommunications.VictorBleDeviceManager;

public class MainActivity extends Activity
{
    private final VictorDeviceCallback deviceCallback = new VictorDeviceCallback()
    {
        @Override
        public void onDeviceFound(VictorDeviceInfo deviceInfo)
        {
            System.out.printf("Found " + deviceInfo + "\n"));
        }
    
        @Override
        public void onConnectionStateChange(VictorDeviceInfo deviceInfo, boolean connected)
        {
              System.out.printf("Got a connection state change from %s.\n", deviceInfo)));
        }
    
        @Override
        public void onAttributeChange(VictorDeviceInfo deviceInfo, UUID attribute, byte[] data)
        {
              System.out.printf("Got an attribute change for attribute %s from %s.\n", attribute, deviceInfo)));
        }
    };
    
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        deviceManager = new VictorBleDeviceManager(this);
    }
    
    public void Scan()
    {
        deviceManager = new VictorBleDeviceManager(this);
    
        CompletableFuture<Set<VictorDeviceInfo>> futureScannedDevices = deviceManager.scanForDevices(deviceCallback);
    }
}

Connecting To A Device

Once a powered on VictoR device has been found by scanning for devices with the VictorBleDeviceManager, the resulting VictorDeviceInfo can be used to connect to the device along with the VictorBleDeviceManager that found the device.

Code Block
languagejava
CompletableFuture<Boolean> futureConnected = deviceManager.connect(deviceInfo.getAddress());

Subscribing to Connection State Changes

It is also possible to subscribe to the connection state of a VictoR device. This results in callbacks being triggered whenever the device is connected to or disconnected from.

Code Block
languagejava
private final VictorDeviceCallback deviceCallback = new VictorDeviceCallback()
{
    @Override
    public void onDeviceFound(VictorDeviceInfo deviceInfo)
    {
        System.out.printf("Found " + deviceInfo + "\n"));
    }

    @Override
    public void onConnectionStateChange(VictorDeviceInfo deviceInfo, boolean connected)
    {
          System.out.printf("Got a connection state change from %s.\n", deviceInfo)));
    }

    @Override
    public void onAttributeChange(VictorDeviceInfo deviceInfo, UUID attribute, byte[] data)
    {
          System.out.printf("Got an attribute change for attribute %s from %s.\n", attribute, deviceInfo)));
    }
};

deviceManager.subscribeConnectionStateChange(deviceInfo.getAddress(), deviceCallback);

Disconnecting From A Device

A VictoR device can be disconnected by using the device manager that originally connected to the device, along with the device’s address.

Code Block
languagejava
CompletableFuture<Boolean> futureDisconnected = deviceManager.disconnect(deviceInfo.getAddress());

Reading From A VictoR Device

In order to read from a VictoR device, once a connection has been established through a device manager, a service object the attribute in question is associated with must first be created. Once the service object has been created, calls to read data from the connected device can be made, given the device manager containing the device has been passed to the service object on creation.

...

NOTE: When reading from a device, please reference the supported ICD document specified above to ensure the attribute itself, as well as reading from the attribute, is supported.

Writing To A VictoR Device

Similar to reading from a VictoR device, writing to a VictoR device requires an established connection with a powered on device through a device manager and a service object that contains the data to be written. Serialization of data when writing to the VictoR device is handled by the service objects, converting the data into a byte array before being sent to the device.

...

NOTE: When writing to a device, please reference the supported ICD document specified above to ensure the attribute itself, as well as writing to the attribute, is supported.

Subscribing To Attribute Changes

Attributes on the VictoR device, when supported, can be subscribed to through the usage of the VictorDeviceCallback class and the service containing the data to be subscribed to.

...