Skip to content

Commit

Permalink
add AdasisMessageContext
Browse files Browse the repository at this point in the history
  • Loading branch information
dzinad committed Jan 12, 2024
1 parent 2bc2141 commit b71478d
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 7 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ allprojects {
// we allow access to snapshots repo if ALLOW_SNAPSHOT_REPOSITORY is set, what means we are running on CI
// with Navigation Native forced to be some snapshot version
// if you need to use snapshots while development, just set `addSnapshotsRepo` to true manually
def addSnapshotsRepo = project.hasProperty('ALLOW_SNAPSHOT_REPOSITORY') ? project.property('ALLOW_SNAPSHOT_REPOSITORY') : (System.getenv("ALLOW_SNAPSHOT_REPOSITORY")?.toBoolean() ?: false)
// def addSnapshotsRepo = project.hasProperty('ALLOW_SNAPSHOT_REPOSITORY') ? project.property('ALLOW_SNAPSHOT_REPOSITORY') : (System.getenv("ALLOW_SNAPSHOT_REPOSITORY")?.toBoolean() ?: false)
def addSnapshotsRepo = true
if (addSnapshotsRepo) {
println("Snapshot repository reference added.")
maven {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import com.mapbox.navigation.core.MapboxNavigationProvider
import com.mapbox.navigation.core.adasis.AdasisConfig
import com.mapbox.navigation.core.directions.session.RoutesObserver
import com.mapbox.navigation.core.formatter.MapboxDistanceFormatter
import com.mapbox.navigation.core.replay.route.ReplayRouteSession
import com.mapbox.navigation.core.trip.session.LocationMatcherResult
import com.mapbox.navigation.core.trip.session.LocationObserver
import com.mapbox.navigation.core.trip.session.NavigationSessionStateObserver
Expand Down Expand Up @@ -271,6 +272,7 @@ class MapboxNavigationActivity : AppCompatActivity() {
logD("sessionId=${mapboxNavigation.getNavigationSessionState().sessionId}", LOG_CATEGORY)
}

@OptIn(ExperimentalPreviewMapboxNavigationAPI::class)
@SuppressLint("MissingPermission")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -432,6 +434,7 @@ class MapboxNavigationActivity : AppCompatActivity() {
// start the trip session to being receiving location updates in free drive
// and later when a route is set, also receiving route progress updates
mapboxNavigation.startTripSession()
ReplayRouteSession().onAttached(mapboxNavigation)
}

@OptIn(ExperimentalPreviewMapboxNavigationAPI::class)
Expand All @@ -442,8 +445,9 @@ class MapboxNavigationActivity : AppCompatActivity() {
mapboxNavigation.registerRouteProgressObserver(routeProgressObserver)
mapboxNavigation.registerLocationObserver(locationObserver)
mapboxNavigation.registerVoiceInstructionsObserver(voiceInstructionsObserver)
mapboxNavigation.setAdasisMessageCallback(AdasisConfig.Builder().build()) { message ->
mapboxNavigation.setAdasisMessageCallback(AdasisConfig.Builder().build()) { message, context ->
Log.d("AdasisTest.", "Adasis message: $message")
Log.d("AdasisTest.", "Context: $context")
}
}

Expand Down
1 change: 1 addition & 0 deletions gradle/artifact-settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ext {
versionName = getVersionName()
}

// latest is 2.18.0-adas-preview-10-SNAPSHOT
def getVersionName() {
if (project.hasProperty('VERSION_NAME')) {
return project.property('VERSION_NAME')
Expand Down
2 changes: 1 addition & 1 deletion gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ext {
// version which we should use in this build
def mapboxNavigatorVersion = System.getenv("FORCE_MAPBOX_NAVIGATION_NATIVE_VERSION")
if (mapboxNavigatorVersion == null || mapboxNavigatorVersion == '') {
mapboxNavigatorVersion = '182.0.0'
mapboxNavigatorVersion = 'nio-adas-lpo-flatbuffers-vectors-11-SNAPSHOT'
}
println("Navigation Native version: " + mapboxNavigatorVersion)
def androidXWorkManagerVersion = project.hasProperty('WORK_MANAGER_VERSION') ? project.property('WORK_MANAGER_VERSION') : '2.7.0'
Expand Down
7 changes: 6 additions & 1 deletion libnavigation-core/api/current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ package com.mapbox.navigation.core {
package com.mapbox.navigation.core.adasis {

@com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI public fun interface ADASISv2MessageCallback {
method public void onMessage(java.util.List<java.lang.Byte> messageBuffer);
method public void onMessage(java.util.List<java.lang.Byte> messageBuffer, com.mapbox.navigation.core.adasis.AdasisMessageContext context);
}

@com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI public final class AdasisConfig {
Expand Down Expand Up @@ -294,6 +294,11 @@ package com.mapbox.navigation.core.adasis {
field public static final com.mapbox.navigation.core.adasis.AdasisMessageBinaryFormat.FlatBuffers INSTANCE;
}

public final class AdasisMessageContext {
method public Long? getPositionMonotonicTimestampNanoseconds();
property public final Long? positionMonotonicTimestampNanoseconds;
}

@com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI public final class EdgeAdasAttributes {
method public java.util.List<com.mapbox.navigation.core.adasis.ValueOnEdge> getCurvatures();
method public java.util.List<com.mapbox.navigation.core.adasis.ValueOnEdge> getSlopes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import com.mapbox.navigation.base.trip.notification.TripNotificationInterceptor
import com.mapbox.navigation.core.accounts.BillingController
import com.mapbox.navigation.core.adasis.ADASISv2MessageCallback
import com.mapbox.navigation.core.adasis.AdasisConfig
import com.mapbox.navigation.core.adasis.AdasisMessageContext
import com.mapbox.navigation.core.arrival.ArrivalController
import com.mapbox.navigation.core.arrival.ArrivalObserver
import com.mapbox.navigation.core.arrival.ArrivalProgressObserver
Expand Down Expand Up @@ -2006,8 +2007,8 @@ class MapboxNavigation @VisibleForTesting internal constructor(
@ExperimentalPreviewMapboxNavigationAPI
fun setAdasisMessageCallback(adasisConfig: AdasisConfig, callback: ADASISv2MessageCallback) {
navigator.setAdasisMessageCallback(
{ message ->
callback.onMessage(message)
{ message, context ->
callback.onMessage(message, AdasisMessageContext.fromNative(context))
},
adasisConfig.toNativeAdasisConfig()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fun interface ADASISv2MessageCallback {
/**
* Called when ADASIS message is available
* @param messageBuffer Message buffer in format specified via [AdasisConfigDataSending.messageBinaryFormat]
* @param context Message context. For details see [AdasisMessageContext] docs
*/
fun onMessage(messageBuffer: List<Byte>)
fun onMessage(messageBuffer: List<Byte>, context: AdasisMessageContext)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.mapbox.navigation.core.adasis

/**
* Context of an adasis message.
*
* @param positionMonotonicTimestampNanoseconds the monotonic time of a position message within a message batch.
* This time is determined based on the monotonic time of the previous location and the lookAhead time.
* If the lookAhead is set to 0, then the positionMonotonicTimestampNanoseconds will be the monotonic time
* of the last location update.
*/
class AdasisMessageContext internal constructor(
val positionMonotonicTimestampNanoseconds: Long?,
) {

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as AdasisMessageContext

if (positionMonotonicTimestampNanoseconds != other.positionMonotonicTimestampNanoseconds) return false

return true
}

override fun hashCode(): Int {
return positionMonotonicTimestampNanoseconds.hashCode()
}

override fun toString(): String {
return "AdasisMessageContext(positionMonotonicTimestampNanoseconds=$positionMonotonicTimestampNanoseconds)"
}

/**
* Temporary method to track NN changes. When NN adds a property to their object,
* this method's compilation will fail.
* In that case conversion both from and to native object should be adjusted.
*/
private fun toNative(): com.mapbox.navigator.AdasisMessageContext {
return com.mapbox.navigator.AdasisMessageContext(this.positionMonotonicTimestampNanoseconds)
}

internal companion object {

fun fromNative(
nativeContext: com.mapbox.navigator.AdasisMessageContext
): AdasisMessageContext {
return AdasisMessageContext(nativeContext.positionMessageTimestamp)
}
}
}

0 comments on commit b71478d

Please sign in to comment.