Sorry, you need to enable JavaScript to visit this website.

Connectivity

Connectivity

Services

Services initialization

The HU Connectivity module makes it easy to discover nearby HUs and establish communication with
them. It uses technologies such as Bluetooth, Wi-Fi or direct cable connection. The messages are
exchanged with nearby devices in real-time, regardless of network connectivity. Sample use case:

  • Share location (e.g. destination) with HU

  • Share full route with HU

  • Forward map update (e.g. IQ Maps package) with HU

The primary goal of the HU Connectivity module is to provide a platform that is simple, reliable
and performant. The developed SDK should automatically detect which communication channels are
available and use the most valuable one, leveraging the strengths of each while circumventing
their respective weaknesses. For instance, when the user is close to the car and BT connection
with HU is established, BLE should be used. However, when the user is e.g. in the office, the Wi-Fi
connection with NavCloud in the middle should be used. The user may also force a specific channel
to be used each time and ignore other possibilities. In the most positive scenario, the communication
channel should be transparent for the user and the developer, allowing them to focus on the features
that are important for them.

To obtain access to this module you will need to add following dependency to your build.gradle file:

implementation("com.tomtom.online:sdk-connectivity-services:2.4307")

Services module gives access to ConnectivityApi interface and PriorityConnectivityApi implementation.
ConnectivityApi is used to manage connections and send data between devices. In addition it also accepts multiple communicators that will be used to send/receive data.

ConnectivityApi provides access to the following methods:

  • Connect

  • Disconnect

  • Send(Command)

In order to create an instance use PriorityConnectivityApiBuilder and provide required parameters to it which are:

  • StatusHandler

  • One or more CommunicatorFactory

  • One or more CommandModule

val connectivityApi = PriorityConnectivityApiBuilder(applicationContext)
    .addCommunicator(communicatorFactory1)
    .addCommunicator(communicatorFactory2)
    .addModule(commandModule)
    .withStatusHandler(statusHandler)
    .build()

StatusHandler will be used by ConnectivityApi for notification of an operations status.
To achieve that implement StatusHandler interface or create an ReferenceStatusHandler in the following manner:

protected val statusHandler = ReferenceStatusHandler(
    onReadStatusReady = { communicatorInfo, status -> onReadStatusReady(communicatorInfo, status) },
    onWriteStatusReady = { communicatorInfo, status -> onWriteStatusReady(communicatorInfo, status) },
    onConnectionStatusReady = { communicatorInfo, status -> onConnectionStatusReady(communicatorInfo, status) },
    onDisconnect = { communicatorInfo -> onDisconnect(communicatorInfo) }
)

Communicators

By default, ConnectivityApi does not support any Communicator. Several communicator modules adapt
specific connection type:

  • Bluetooth Low Energy Server

  • Bluetooth Low Energy Client

Commands

ConnectivityApi allows to send data between devices. The data is represented by Command. By
default, ConnectivityApi does not support any specific Command, therefore support for default commands
needs to be configured manually.

Step 1: To obtain access to default commands module you will need to add following dependency to
your build.gradle file:

implementation("com.tomtom.online:sdk-connectivity-commands:2.4307")

Step 2: Add common commands modules to the builder, as shown below:

val connectivityApi = PriorityConnectivityApiBuilder(applicationContext)
    .addCommunicator(communicatorFactory1)
    .addCommunicator(communicatorFactory2)
    .addModule(commandModule)
    .withStatusHandler(statusHandler)
    .build()

 

CommandCommonModule will provide proper CommandSerializer, CommandDeserializer and
CommandTypeMappingFactory which are necessary for correct serialization/deserialization of Command

Custom Commands

If you need to send command that common commands module does not support or you wish to use a
different serialization/deserialization/mapping for an existing Command,
you can easily create your own implementation.

Serialization

To provide a serializer for a command create a class that implements the CommandSerializer and
class that implements CommandSerializersFactory which will return map of custom serializers.
Finally pass it to the ConnectivityApiBuilder:

val connectivityApi = PriorityConnectivityApiBuilder(applicationContext)
    .addCommunicator(communicatorFactory1)
    .addSerializer(MyCommandSerializersFactory())
    .withStatusHandler(statusHandler)
    .build()

Deserialization

To provide a deserializer for a command create a class that implements the CommandDeserializer
and class that implements CommandDeserializersFactory which will return map of custom deserializers.
Finally pass it to the ConnectivityApiBuilder:

val connectivityApi = PriorityConnectivityApiBuilder(applicationContext)
    .addCommunicator(communicatorFactory1)
    .addDeserializer(MyCommandDeserializersFactory())
    .withStatusHandler(statusHandler)
    .build()

Mapping

Each of command should have defined header that will be represented by single Short value wrapped
with CommandType. This value is used to recognize specific command during deserialization.

When adding new command or when you wish to provide different CommandType for existing command
you can provide your own mapping by implementing CommandTypeMappingFactory:

class MyCommandTypeMappingFactory : CommandTypeMappingFactory {
    override fun create(): Map<CommandType, Class<out Command>> {
        val mapping = mutableMapOf<CommandType, Class<out Command>>()
        mapping[MY_COMMAND] = MyCommand::class.java
        return mapping.toMap()
    }

    companion object {
        val MY_COMMAND = CommandType(0)
    }
}

Then pass it to the ConnectivityApiBuilder:

val connectivityApi = PriorityConnectivityApiBuilder(applicationContext)
    .addCommunicator(communicatorFactory1)
    .addMapping(MyCommandTypeMappingFactory())
    .withStatusHandler(statusHandler)
    .build()

Module

Alternatively you can implement CommandModule interface which will provide complete set of extensions.

class MyCommandModule : CommandModule {

    override fun createDeserializerFactory(): CommandDeserializersFactory {
        return MyCommandDeserializersFactory()
    }

    override fun createMappingFactory(): CommandTypeMappingFactory {
        return MyCommandTypeMappingFactory()
    }

    override fun createSerializerFactory(): CommandSerializersFactory {
        return MyCommandSerializersFactory()
    }
}

Bluetooth Low Energy

Bluetooth Low Energy initialization

Maps SDK for Android provides users with ability to share data through Bluetooth Low Energy.

To obtain access to this module you will need to add proper dependency to your build.gradle file:

Client:

implementation("com.tomtom.online:sdk-connectivity-bluetooth-le:2.4307")

 

To use Bluetooth Low Energy module you will need to create an BleClientFactory and pass to it ConnectionParams.

Specify communication parameters of a device in the following manner:

  • Client side:

        return BleClientConnectionParams(macAddress)

Bluetooth Low Energy Server

Bluetooth Low Energy initialization

Maps SDK for Android provides users with ability to share data through Bluetooth Low Energy.

To obtain access to this module you will need to add proper dependency to your build.gradle file:

Server:

implementation("com.tomtom.online:sdk-connectivity-server-bt-le:2.4307")

 

To use Bluetooth Low Energy module you will need to create an BleServerFactory and pass to it ConnectionParams.

Specify communication parameters of a device in the following manner:

  • Server side:

        return BleServerConnectionParams.Builder().build()

Api Reference

API Reference for Connectivity



Older versions Changes between current version

Connectivity_2.4.292

N/A

Connectivity_2.4.287

N/A

Connectivity_2.4.283

N/A

Connectivity_2.4.264

N/A

Connectivity_2.4.260

N/A

You are here