Introduction

VERSION 0.12.0
PUBLIC PREVIEW

The Vehicle module offers a VehicleProvider, which is an interface for getting the current state of the vehicle and listening to the changes of the vehicle’s state. That way the integrator can provide its implementation of it and inject in when needed in other TomTom’s modules, like Navigation. On the other hand, TomTom offers the thread-safe implementation of a VehicleProviderInterface, which is a DefaultVehicleProvider that helps the integrator monitor the current state of the vehicle by letting the integrator set the initial vehicle’s state, update the vehicle’s state, and listen to the changes of the vehicle’s state. After creation DefaultVehicleProvider returns an empty non-commercial car as the current’s vehicle snapshot.

Project set up

You have to add the Vehicle module dependency in the build.gradle of your application module and synchronize the project:

1dependencies {
2 implementation "com.tomtom.sdk.vehicle:vehicle:{latestVersion}"
3}

Setting initial vehicle’s state

This sets the vehicle to the initial profile, modified by the listed VehicleParameters. The following code snippet shows how to set the profile for an electric engine car. If vehicle parameters are not applicable to the vehicle type, IllegalArgumentException will be thrown.

1val vehicleType = VehicleType.Car
2
3val currentChargeParameter = CurrentCharge(Energy.kilowattHours(30.0))
4val maxChargeParameter = MaxCharge(Energy.kilowattHours(60.0))
5val electricEngineParameters = ElectricEngine(listOf(currentChargeParameter, maxChargeParameter))
6val vehicleParameters = listOf(electricEngineParameters)
7
8defaultVehicleProvider.setVehicle(vehicleType, vehicleParameters)

Updating the vehicle’s state

This updates the listed VehicleParameters in the current vehicle profile. If a parameter, which is not MaxSpeed or CommercialVehicle, was not previously set, it will throw an IllegalArgumentException. MaxSpeed can be updated for every vehicle type. CommercialVehicle can be updated for a motorized vehicle type.

1val updatedCurrentChargeParameter = CurrentCharge(Energy.kilowattHours(25.0))
2val updatedElectricEngineParameters = ElectricEngine(listOf(updatedCurrentChargeParameter))
3val updatedVehicleParameters = listOf(updatedElectricEngineParameters)
4
5defaultVehicleProvider.updateVehicleState(updatedVehicleParameters)

Snapshot of the current vehicle’s state

The following code snippet shows how to get the snapshot of the current vehicle’s state:

val currentVehicleSnapshot = defaultVehicleProvider.vehicleSnapshot

Next steps

Since you have learned basic use cases, here are recommendations for the next steps: