Abstract

This documentation is intended to help designing applications for the Velobox' vmkstationd3 that include communication with Velometrik's controller for pressure mats.

Introduction

The bluetooth communication between the Velometrik controller and an application API of the Velobox runs through several layers:

  1. The BlueZ Bluetooth protocol stack for Linux
  2. The Bluetooth Low Energy platform Agnostic Klient "Bleak" library for Python
  3. The Bluetooth Agent of the vmkstationd3 of the Velobox
    (a Python script named btagent.py)
  4. A TCL Interface to btagent.py.
    (A kernel module, named ::kernel::BTSattel for saddle pressure mats)
  5. The Application module that defines the applications API
For program design it is useful to know some internals starting from the bluetooth agent upwards.

The bluetooth agent

The bluetooth agent arranges the bluetooth communication between Velometrik's controller and the vmkstationd3 daemon of the Velobox. After invocation the agent expects commands from stdin that control what happens. Responses go in JSON format to stdout. Pressure values go as comma seperated (ASCII) integer values (one line per pressure image) to stdout too.

The data delivered can be grouped as follows:

Commands

The bluetooth agent has two nested command loops, an inner and an outer command loop. The inner loop has a very limited command set and runs while data will be transferred.

(outer command loop)

(inner command loop)

1)Bluetooth agent will exit on receipt of EOF (Ctrl-D) on stdin too.

Message objects

Every JSON message object has a key named "btevent". Depending on that key's value there may be more keys for the details.

btevent class (error)
disconnected Regular disconnect
error disconnected Unexpected disconnect
fail Pair failed
Start notify failed
Device not found
comm Stop notify failed
client Invalid command
internal Unexpected error, outer loop restarted
debug Debug message

The TCL bluetooth interface

On startup of the vmkstationd3 loading the kernel module ::kernel::BTSattel this module starts the bluetooth agent. It hides the communication details by offering interface procedure calls. To get informations about the connection status and to get the pressure pressure data the application regsisters a connection change handler and a data handler rsp.

Commands (TCL-procedures)

Callbacks for connection changes

To register a callback for connection changes call
::kernel::BTSattel::addConnectionHandler <handler-proc-name>
(Working with namespaces it's a good idea to set the complete namespace path for <handler-proc-name>.)

The connection handler must handle a JSON object string with the key "btevent". Depending on that key's value there may be more keys fore the details. In addition to the message object passed from the bluetooth agent the TCL interface sends the following btevents:

btevent detail-key class (error)value
status devices Array of device objects
(Keys see btagent command scan)
error class The error class
fail Expected device not found
No device found
client disconnect while trying connect (ignored)
msg The error message
ambiguitydevices Array with all device names
data Data are available
To remove a callback for connection changes use
::kernel::BTSattel::removeConnectionHandler <handler-proc-name>

Callbacks for pressure data

To register a callback for pressure data call
::kernel::BTSattel::addDataHandler <handler-proc-name>
(Working with namespaces it's a good idea to set the complete namespace path for <handler-proc-name>.)

The data handler must accept the three arguments "values" (list of pressure values), "n_cols" (number of columns) and "n_rows" (number of rows).

To remove a callback for pressure data use
::kernel::BTSattel::removeDataHandler <handler-proc-name>

Hints for application design