Skip to content

Commit 2bc2141

Browse files
ADAS functionality
1 parent b128952 commit 2bc2141

27 files changed

+1669
-1
lines changed

changelog/unreleased/features/7538.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Added Advanced Driver Assistance Systems (ADAS) functionality as an experimental API.

examples/src/main/java/com/mapbox/navigation/examples/core/MapboxNavigationActivity.kt

+9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import android.content.res.Configuration
55
import android.content.res.Resources
66
import android.location.Location
77
import android.os.Bundle
8+
import android.util.Log
89
import android.view.View.INVISIBLE
910
import android.view.View.VISIBLE
1011
import android.widget.Toast
@@ -21,6 +22,7 @@ import com.mapbox.maps.plugin.LocationPuck2D
2122
import com.mapbox.maps.plugin.animation.camera
2223
import com.mapbox.maps.plugin.gestures.gestures
2324
import com.mapbox.maps.plugin.locationcomponent.location
25+
import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI
2426
import com.mapbox.navigation.base.TimeFormat
2527
import com.mapbox.navigation.base.extensions.applyDefaultNavigationOptions
2628
import com.mapbox.navigation.base.extensions.applyLanguageAndVoiceUnitOptions
@@ -33,6 +35,7 @@ import com.mapbox.navigation.base.route.RouterFailure
3335
import com.mapbox.navigation.base.route.RouterOrigin
3436
import com.mapbox.navigation.core.MapboxNavigation
3537
import com.mapbox.navigation.core.MapboxNavigationProvider
38+
import com.mapbox.navigation.core.adasis.AdasisConfig
3639
import com.mapbox.navigation.core.directions.session.RoutesObserver
3740
import com.mapbox.navigation.core.formatter.MapboxDistanceFormatter
3841
import com.mapbox.navigation.core.trip.session.LocationMatcherResult
@@ -431,22 +434,28 @@ class MapboxNavigationActivity : AppCompatActivity() {
431434
mapboxNavigation.startTripSession()
432435
}
433436

437+
@OptIn(ExperimentalPreviewMapboxNavigationAPI::class)
434438
override fun onStart() {
435439
super.onStart()
436440
mapboxNavigation.registerRoutesObserver(routesObserver)
437441
mapboxNavigation.registerNavigationSessionStateObserver(navigationSessionStateObserver)
438442
mapboxNavigation.registerRouteProgressObserver(routeProgressObserver)
439443
mapboxNavigation.registerLocationObserver(locationObserver)
440444
mapboxNavigation.registerVoiceInstructionsObserver(voiceInstructionsObserver)
445+
mapboxNavigation.setAdasisMessageCallback(AdasisConfig.Builder().build()) { message ->
446+
Log.d("AdasisTest.", "Adasis message: $message")
447+
}
441448
}
442449

450+
@OptIn(ExperimentalPreviewMapboxNavigationAPI::class)
443451
override fun onStop() {
444452
super.onStop()
445453
mapboxNavigation.unregisterRoutesObserver(routesObserver)
446454
mapboxNavigation.unregisterNavigationSessionStateObserver(navigationSessionStateObserver)
447455
mapboxNavigation.unregisterRouteProgressObserver(routeProgressObserver)
448456
mapboxNavigation.unregisterLocationObserver(locationObserver)
449457
mapboxNavigation.unregisterVoiceInstructionsObserver(voiceInstructionsObserver)
458+
mapboxNavigation.resetAdasisMessageCallback()
450459
}
451460

452461
override fun onDestroy() {

libnavigation-core/api/current.txt

+262
Large diffs are not rendered by default.

libnavigation-core/src/main/java/com/mapbox/navigation/core/MapboxNavigation.kt

+42
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ import com.mapbox.navigation.base.trip.notification.NotificationAction
4444
import com.mapbox.navigation.base.trip.notification.TripNotification
4545
import com.mapbox.navigation.base.trip.notification.TripNotificationInterceptor
4646
import com.mapbox.navigation.core.accounts.BillingController
47+
import com.mapbox.navigation.core.adasis.ADASISv2MessageCallback
48+
import com.mapbox.navigation.core.adasis.AdasisConfig
4749
import com.mapbox.navigation.core.arrival.ArrivalController
4850
import com.mapbox.navigation.core.arrival.ArrivalObserver
4951
import com.mapbox.navigation.core.arrival.ArrivalProgressObserver
@@ -92,6 +94,8 @@ import com.mapbox.navigation.core.routealternatives.RouteAlternativesRequestCall
9294
import com.mapbox.navigation.core.routeoptions.RouteOptionsUpdater
9395
import com.mapbox.navigation.core.routerefresh.RouteRefreshController
9496
import com.mapbox.navigation.core.routerefresh.RouteRefreshControllerProvider
97+
import com.mapbox.navigation.core.sensor.SensorData
98+
import com.mapbox.navigation.core.sensor.UpdateExternalSensorDataCallback
9599
import com.mapbox.navigation.core.telemetry.MapboxNavigationTelemetry
96100
import com.mapbox.navigation.core.telemetry.events.FeedbackEvent
97101
import com.mapbox.navigation.core.telemetry.events.FeedbackHelper
@@ -1303,6 +1307,7 @@ class MapboxNavigation @VisibleForTesting internal constructor(
13031307
ReachabilityService.removeReachabilityObserver(it)
13041308
reachabilityObserverId = null
13051309
}
1310+
resetAdasisMessageCallback()
13061311

13071312
isDestroyed = true
13081313
hasInstance = false
@@ -1979,6 +1984,43 @@ class MapboxNavigation @VisibleForTesting internal constructor(
19791984
)
19801985
}
19811986

1987+
/**
1988+
* Asynchronously passes in the current sensor data of the user.
1989+
*
1990+
* @param data The current sensor data of user
1991+
* @param callback Callback which is called when the async operation is completed
1992+
*/
1993+
@ExperimentalPreviewMapboxNavigationAPI
1994+
fun updateExternalSensorData(data: SensorData, callback: UpdateExternalSensorDataCallback) {
1995+
navigator.updateExternalSensorData(data.toNativeSensorData()) {
1996+
callback.onResult(it)
1997+
}
1998+
}
1999+
2000+
/**
2001+
* Sets a callback for ADASIS messages
2002+
*
2003+
* @param callback Message callback
2004+
* @param adasisConfig Adasis config
2005+
*/
2006+
@ExperimentalPreviewMapboxNavigationAPI
2007+
fun setAdasisMessageCallback(adasisConfig: AdasisConfig, callback: ADASISv2MessageCallback) {
2008+
navigator.setAdasisMessageCallback(
2009+
{ message ->
2010+
callback.onMessage(message)
2011+
},
2012+
adasisConfig.toNativeAdasisConfig()
2013+
)
2014+
}
2015+
2016+
/**
2017+
* Resets a callback for ADASIS messages
2018+
*/
2019+
@ExperimentalPreviewMapboxNavigationAPI
2020+
fun resetAdasisMessageCallback() {
2021+
navigator.resetAdasisMessageCallback()
2022+
}
2023+
19822024
internal fun registerOnRoutesSetStartedObserver(observer: SetNavigationRoutesStartedObserver) {
19832025
directionsSession.registerSetNavigationRoutesStartedObserver(observer)
19842026
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.mapbox.navigation.core
2+
3+
import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI
4+
5+
/**
6+
* A class that provides Navigation SDK information, like version name
7+
*/
8+
@ExperimentalPreviewMapboxNavigationAPI
9+
object NavigationSdkInformationProvider {
10+
11+
/**
12+
* Returns Navigation SDK version name
13+
*/
14+
val versionName: String
15+
get() = BuildConfig.MAPBOX_NAVIGATION_VERSION_NAME
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.mapbox.navigation.core.adasis
2+
3+
import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI
4+
5+
/**
6+
* Callback which is getting called to report ADASISv2Message
7+
*/
8+
@ExperimentalPreviewMapboxNavigationAPI
9+
fun interface ADASISv2MessageCallback {
10+
11+
/**
12+
* Called when ADASIS message is available
13+
* @param messageBuffer Message buffer in format specified via [AdasisConfigDataSending.messageBinaryFormat]
14+
*/
15+
fun onMessage(messageBuffer: List<Byte>)
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package com.mapbox.navigation.core.adasis
2+
3+
import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI
4+
5+
/**
6+
* Configuration of ADASISv2 feature.
7+
*
8+
* @param dataSending data sending configuration
9+
* @param pathOptions ADASISv2 path level specific configurations
10+
*/
11+
@ExperimentalPreviewMapboxNavigationAPI
12+
class AdasisConfig private constructor(
13+
val dataSending: AdasisConfigDataSending,
14+
val pathOptions: AdasisConfigPathOptions,
15+
) {
16+
17+
@JvmSynthetic
18+
internal fun toNativeAdasisConfig(): com.mapbox.navigator.AdasisConfig {
19+
return com.mapbox.navigator.AdasisConfig(
20+
dataSending.toNativeAdasisConfigDataSending(),
21+
pathOptions.toNativeAdasisConfigPathOptions(),
22+
)
23+
}
24+
25+
/**
26+
* Indicates whether some other object is "equal to" this one.
27+
*/
28+
override fun equals(other: Any?): Boolean {
29+
if (this === other) return true
30+
if (javaClass != other?.javaClass) return false
31+
32+
other as AdasisConfig
33+
34+
if (dataSending != other.dataSending) return false
35+
if (pathOptions != other.pathOptions) return false
36+
37+
return true
38+
}
39+
40+
/**
41+
* Returns a hash code value for the object.
42+
*/
43+
override fun hashCode(): Int {
44+
var result = dataSending.hashCode()
45+
result = 31 * result + pathOptions.hashCode()
46+
return result
47+
}
48+
49+
/**
50+
* Returns a string representation of the object.
51+
*/
52+
override fun toString(): String {
53+
return "AdasisConfig(" +
54+
"dataSending=$dataSending, " +
55+
"pathsOptions=$pathOptions" +
56+
")"
57+
}
58+
59+
/**
60+
* Builder for [AdasisConfig]
61+
*/
62+
class Builder {
63+
64+
private var dataSending: AdasisConfigDataSending = AdasisConfigDataSending(
65+
AdasisMessageBinaryFormat.FlatBuffers
66+
)
67+
68+
private var pathOptions: AdasisConfigPathOptions = AdasisConfigPathOptions(
69+
Stub(AdasisConfigMessageOptions()),
70+
Segment(AdasisConfigMessageOptions()),
71+
ProfileShort(AdasisConfigMessageOptions(), AdasisConfigProfileShortTypeOptions()),
72+
ProfileLong(AdasisConfigMessageOptions(), AdasisConfigProfileLongTypeOptions())
73+
)
74+
75+
/**
76+
* Data sending configuration
77+
*/
78+
fun dataSending(dataSending: AdasisConfigDataSending) = apply {
79+
this.dataSending = dataSending
80+
}
81+
82+
/**
83+
* ADASISv2 path level specific configurations
84+
*/
85+
fun pathOptions(pathsOptions: AdasisConfigPathOptions) = apply {
86+
this.pathOptions = pathsOptions
87+
}
88+
89+
/**
90+
* Build the [AdasisConfig]
91+
*/
92+
fun build() = AdasisConfig(
93+
dataSending = dataSending,
94+
pathOptions = pathOptions
95+
)
96+
}
97+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package com.mapbox.navigation.core.adasis
2+
3+
import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI
4+
5+
/**
6+
* Data sending configuration
7+
*
8+
* @param messageBinaryFormat binary format in which Adasis message will be sent
9+
* @param messageIntervalMs interval between sending messages in milliseconds
10+
* @param messagesInPackage number of messages in one package (one message is 8 bytes)
11+
* @param metadataCycleSeconds time in seconds between repetition of META-DATA message
12+
* @param enableRetransmission if true, retransmission will be enabled
13+
* (package will be appended with retransmission data, messages from previous cycles)
14+
* @param retransmissionMeters after passing this distance, messages will not be retransmitted
15+
*/
16+
@ExperimentalPreviewMapboxNavigationAPI
17+
class AdasisConfigDataSending(
18+
val messageBinaryFormat: AdasisMessageBinaryFormat,
19+
val messageIntervalMs: Int = 80,
20+
val messagesInPackage: Int = 20,
21+
val metadataCycleSeconds: Int = 5,
22+
val enableRetransmission: Boolean = true,
23+
val retransmissionMeters: Int = 300,
24+
) {
25+
26+
@JvmSynthetic
27+
internal fun toNativeAdasisConfigDataSending(): com.mapbox.navigator.AdasisConfigDataSending {
28+
return com.mapbox.navigator.AdasisConfigDataSending(
29+
messageBinaryFormat.toNativeMessageBinaryFormat(),
30+
messageIntervalMs,
31+
messagesInPackage,
32+
metadataCycleSeconds,
33+
enableRetransmission,
34+
retransmissionMeters,
35+
)
36+
}
37+
38+
/**
39+
* Indicates whether some other object is "equal to" this one.
40+
*/
41+
override fun equals(other: Any?): Boolean {
42+
if (this === other) return true
43+
if (javaClass != other?.javaClass) return false
44+
45+
other as AdasisConfigDataSending
46+
47+
if (messageBinaryFormat != other.messageBinaryFormat) return false
48+
if (messageIntervalMs != other.messageIntervalMs) return false
49+
if (messagesInPackage != other.messagesInPackage) return false
50+
if (metadataCycleSeconds != other.metadataCycleSeconds) return false
51+
if (enableRetransmission != other.enableRetransmission) return false
52+
if (retransmissionMeters != other.retransmissionMeters) return false
53+
54+
return true
55+
}
56+
57+
/**
58+
* Returns a hash code value for the object.
59+
*/
60+
override fun hashCode(): Int {
61+
var result = messageIntervalMs
62+
result = 31 * result + messageBinaryFormat.hashCode()
63+
result = 31 * result + messagesInPackage
64+
result = 31 * result + metadataCycleSeconds.hashCode()
65+
result = 31 * result + enableRetransmission.hashCode()
66+
result = 31 * result + retransmissionMeters.hashCode()
67+
return result
68+
}
69+
70+
/**
71+
* Returns a string representation of the object.
72+
*/
73+
override fun toString(): String {
74+
return "AdasisConfigDataSending(" +
75+
"messageBinaryFormat=$messageBinaryFormat, " +
76+
"messageIntervalMs=$messageIntervalMs, " +
77+
"messagesInPackage=$messagesInPackage, " +
78+
"messagesInPackage=$messagesInPackage, " +
79+
"metadataCycleSeconds=$metadataCycleSeconds, " +
80+
"enableRetransmission=$enableRetransmission, " +
81+
"retransmissionMeters=$retransmissionMeters" +
82+
")"
83+
}
84+
}

0 commit comments

Comments
 (0)