KallistoManager

public abstract class KallistoManager

KallistoManager provides the interactions related to the Kallisto Devices. This class is used as base for the other managers.

Allows the developer to get Kallisto devices, create bonds, register for system events, register for battery events and to update the device firmware.

Fields

ACTUATOR_SERVICE_CONNECTED

public static final String ACTUATOR_SERVICE_CONNECTED

A broadcast action used to signalize when the Actuator Manager connects to the remote service and is ready to receive requests.

SENSOR_SERVICE_CONNECTED

public static final String SENSOR_SERVICE_CONNECTED

A broadcast action used to signalize when the Sensor Manager connects to the remote service and is ready to receive requests.

SERVICE_DISCONNECTED

public static final String SERVICE_DISCONNECTED

A broadcast action used to signalize when the remote service exits. No new request are accepted and the ongoing request will fail.

This broadcast is sent when disconnect() is called and the remote service finished cleaning resources or when the Android system decides to kill the service. Refer to the Android documentation for more information of the second case.

SERVICE_FAILED

public static final String SERVICE_FAILED

A broadcast action used to signalize a failure in starting the remote service. This can happen for some reasons:

  • pt.fraunhofer.kallisto.service.KallistoService or pt.fraunhofer.kallisto.service.KallistoDfuService not declared in manifest;

  • Bluetooth LE not available on the smartphone;

  • Service binding fails

Constructors

KallistoManager

protected KallistoManager(Context context, BleDeviceManagerConfiguration bleConfiguration, LoggerConfiguration loggerConfiguration)

KallistoManager constructor.

Parameters
  • context – A valid context.

  • bleConfiguration – The BLE configuration. Can be null, the default will be used.

  • loggerConfiguration – The logger configuration. Can be null, the default will be used.

Methods

createBond

public boolean createBond(Kallisto Kallisto)

Creates a bond with the passed Kallisto device.

For now, only Just Works pairing is supported.

Once connected to a bonded device, the device will stay connected even if not in use.

Requires Android API > 19.

Blocking function.

Parameters
  • Kallisto – The Kallisto device to create a bond with.

Returns

true if everything went ok.

disableServiceNotification

public boolean disableServiceNotification()

Disables remote service persistent notification.

Returns

true if all went ok

disconnect

public abstract void disconnect()

Disconnects from the remote service. Will trigger all cleanup routines in the service.

Always call it when done with the service.

doNotStayConnected

public boolean doNotStayConnected(Kallisto Kallisto)

Resets the stay connected flag of the desired Kallisto device.

Disables the behaviour described in stayConnected(Kallisto).

Calling this function will trigger a disconnection, if the device is not being used.

Blocking function if the device is connected but not in use.

This is the default behaviour.

Parameters
  • Kallisto – The Kallisto device to set the stay connected flag.

Returns

true if everything went ok.

enableServiceNotification

public boolean enableServiceNotification(String title, String text)

Enables remote service persistent notification.

Used for debug purposes.

Parameters
  • title – title of notification

  • text – text of notification

Returns

true if all went ok

getKallisto

public Kallisto getKallisto(String macAddress)

Get a Kallisto device with the passed MAC address.

Parameters
  • macAddress – The MAC address of the desired Kallisto device. Should follow the same format of BluetoothDevice.getAddress().

Returns

The desired Kallisto device or null if not found.

getKallisto

public Kallisto getKallisto(KallistoSensor sensor)

Get the Kallisto device that contains the passed KallistoSensor.

Parameters
Returns

The desired Kallisto device or null if not found.

getKallistoList

public List<Kallisto> getKallistoList()

Get the current Kallisto device list.

Returns

A list of the available Kallisto devices.

getRegisteredKallistos

public List<Kallisto> getRegisteredKallistos(BatteryEventListener listener)

Returns a list of Kallisto devices whose the passed listener is registered to.

Parameters
Returns

A list of Kallisto devices the passed listener is registered to.

getRssi

public int getRssi(Kallisto Kallisto)

Gets the current RSSI of the passed Kallisto device.

Parameters
  • Kallisto – The Kallisto device from which the RSSI will be returned.

Returns

The RSSI value or Integer.MAX_VALUE if the Kallisto is invalid or an error happened.

getScannerConfiguration

public ScannerConfiguration getScannerConfiguration()

Gets the current scanner configuration.

Returns

The scanner configuration.

getScannerFilter

public ScannerFilter getScannerFilter()

Gets the current scanner filter.

Returns

The scanner filter.

isBonded

public boolean isBonded(Kallisto Kallisto)

Gets the current pairing state of the passed Kallisto device.

Parameters
  • Kallisto – The Kallisto device to check the pairing state.

Returns

true if a bond is found.

isBound

public boolean isBound()

Checks if the manager is bound to the remote service.

Returns

true if service is bound

reboot

public boolean reboot(Kallisto Kallisto)

Reboots the passed Kallisto device.

Not every type device supports rebooting, use Kallisto.getModeChangeSupport() to check if is available.

Rebooting will trigger a disconnection (if connected), even if the device is being used or the stayConnected(Kallisto) flag is enabled triggering a SystemEventType.LINK_LOSS system event.

Blocking function.

Parameters
  • Kallisto – The Kallisto device to reboot.

Returns

true if device rebooted.

refreshCache

public void refreshCache()

Updates the Kallisto device list.

This will clear the remote service device list and start a de.sensry.kallisto.bluetooth.scanner.ScannerConfiguration.ScanConfiguration.ONE_SHOT, ScannerConfiguration.MEDIUM_SCAN in order to get a fresh device list.

Triggers a SystemEventType.CACHE_CLEARED system event.

registerBatteryListener

public boolean registerBatteryListener(BatteryEventListener listener, Kallisto Kallisto)

Register a new listener for the passed Kallisto device.

Blocking function.

Parameters
Returns

true if the battery monitoring was started successfully.

registerSystemListener

public boolean registerSystemListener(SystemEventListener listener, int eventLevel)

Registers a SystemEventListener for system events of the passed levels. The available levels are SystemEventType.TYPE_ERROR and SystemEventType.TYPE_INFO.

A listener registered for SystemEventType.TYPE_INFO events will receive SystemEventType.TYPE_ERROR events too.

Parameters
Returns

true if everything went ok.

removeBond

public boolean removeBond(Kallisto Kallisto)

Removes the bond with the passed Kallisto device.

Removing a bond will trigger a disconnection (if connected), even if the device is being used or the stayConnected(Kallisto) flag is enabled triggering a SystemEventType.LINK_LOSS system event.

Requires Android API > 19.

Parameters
  • Kallisto – The Kallisto device to remove the bond.

Returns

true if everything went ok.

shipMode

public boolean shipMode(Kallisto Kallisto)

Puts the passed Kallisto device in ship mode (see datasheet).

Not every type device supports this mode, use Kallisto.getModeChangeSupport() to check if is available.

Putting the device in ship mode is only possible if the device is not being used.

Blocking function.

Parameters
  • Kallisto – The Kallisto device to enter ship mode.

Returns

true if device entered ship mode.

startDfu

public boolean startDfu(String filePath, DfuEventListener listener, Kallisto Kallisto)

Starts the Device Firmware Update (DFU) procedure for the passed Kallisto device.

Refer to the firmware documentation for instructions how to build a compatible update package.

Only one Kallisto device can be under update process at any given time.

Blocking function.

Parameters
  • filePath – Absolute filepath of the update package to be flashed onto the device.

  • listener – The listener to receive DFU events.

  • Kallisto – The Kallisto device to be updated.

Returns

true if the update process started successfully.

startDfu

public boolean startDfu(int resId, DfuEventListener listener, Kallisto Kallisto)

Starts the Device Firmware Update (DFU) procedure for the passed Kallisto device.

Refer to the firmware documentation for instructions how to build a compatible update package.

Only one Kallisto device can be under update process at any given time.

Blocking function.

Parameters
  • resId – Resource id of the .zip to be flashed onto the device. The file should be in /res/raw.

  • listener – The listener to receive DFU events.

  • Kallisto – The Kallisto device to be updated.

Returns

true if the update process started successfully.

stayConnected

public boolean stayConnected(Kallisto Kallisto)

Sets the stay connected flag of the desired Kallisto device.

Since all connections are opportunistic and are killed when the device is not in use, this signals the remote service that the device should stay connected even when not in use.

Calling this function will trigger a connection, if not connected, and start device discovery.

Blocking function if the device is disconnected.

Parameters
  • Kallisto – The Kallisto device to set the stay connected flag.

Returns

true if everything went ok.

stopDfu

public boolean stopDfu(Kallisto Kallisto)

Stops the current Device Firmware Update (DFU) procedure of the passed Kallisto device.

The device will rollback to the previous firmware or, if only contains bootloader, will stay in DFU mode waiting for a valid package.

Parameters
  • Kallisto – The Kallisto device to stop the DFU process.

Returns

true if the update process stopped successfully.

unregisterBatteryListener

public boolean unregisterBatteryListener(BatteryEventListener listener, Kallisto Kallisto)

Unregisters the listener for the passed Kallisto device.

Blocking function if the device is no longer in use.

Parameters
Returns

true if everything went ok.

unregisterBatteryListener

public boolean unregisterBatteryListener(BatteryEventListener listener)

Unregisters a listener for all Kallisto device.

Blocking function if the device is no longer in use.

Parameters
Returns

true if everything went ok.

unregisterSystemListener

public void unregisterSystemListener(SystemEventListener listener)

Unregisters the listener.

Parameters

updateScannerConfiguration

public void updateScannerConfiguration(ScannerConfiguration configuration)

Sets the scan parameters for the KallistoService Scanner thread.

Calling this function will stop any on-going scan in order to update it to the new desired configuration.

Triggers a SystemEventType.SCAN_CHANGED system event.

Parameters
  • configuration – The desired scanner configuration. If null is passed, the default configuration will be used.

updateScannerFilter

public void updateScannerFilter(ScannerFilter filter)

Sets the scanner filter.

The current Kallisto list will be filtered to reflect the new filter. For each device filtered according to the new filter, a SystemEventType.LINK_REMOVED system event will be triggered.

Triggers a SystemEventType.SCAN_CHANGED system event.

Parameters
  • filter – The desired scan filter. If null is passed, the default filter will be used.