diff --git a/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/viewmodel/VssPropertiesViewModel.kt b/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/viewmodel/VssPropertiesViewModel.kt index fb5c23c6..cf153143 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/viewmodel/VssPropertiesViewModel.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/viewmodel/VssPropertiesViewModel.kt @@ -48,9 +48,7 @@ class VSSPropertiesViewModel : ViewModel() { private set val valueTypes: List = ValueCase.values().toList() - val fieldTypes: List = Field.values().toList() - .filterNot { it.toString().contains(EXCLUDED_FIELD_TYPES) } - .minus(listOf(Field.FIELD_UNSPECIFIED, Field.UNRECOGNIZED)) // Not relevant field types + val fieldTypes: List = listOf(Field.FIELD_VALUE, Field.FIELD_ACTUATOR_TARGET) val datapoint: Datapoint get() = vssProperties.valueType.createDatapoint(vssProperties.value) @@ -62,10 +60,6 @@ class VSSPropertiesViewModel : ViewModel() { fun updateVssProperties(vssProperties: VSSProperties = VSSProperties()) { this.vssProperties = vssProperties } - - companion object { - const val EXCLUDED_FIELD_TYPES = "METADATA" - } } @Immutable @@ -73,5 +67,5 @@ data class VSSProperties( val vssPath: String = "Vehicle.Speed", val valueType: ValueCase = ValueCase.VALUE_NOT_SET, val value: String = "130", - val fieldType: Field = Field.FIELD_UNSPECIFIED, + val fieldType: Field = Field.FIELD_VALUE, ) diff --git a/buildSrc/src/main/kotlin/detekt.gradle.kts b/buildSrc/src/main/kotlin/detekt.gradle.kts index 0c52bece..dffee6c0 100644 --- a/buildSrc/src/main/kotlin/detekt.gradle.kts +++ b/buildSrc/src/main/kotlin/detekt.gradle.kts @@ -26,7 +26,7 @@ tasks.withType().configureEach { parallel = true setSource(projectDir) include("**/*.kt", "**/*.kts") - exclude("**/resources/**", "**/build/**") + exclude("**/resources/**", "**/build/**", "**/node_modules/**") config.setFrom(project.file("$rootDir/config/detekt/config.yml")) baseline.set(baselineFile) diff --git a/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/DataBrokerConnection.kt b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/DataBrokerConnection.kt index b8af74a7..6d143183 100644 --- a/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/DataBrokerConnection.kt +++ b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/DataBrokerConnection.kt @@ -34,6 +34,7 @@ import org.eclipse.kuksa.proto.v1.KuksaValV1.GetResponse import org.eclipse.kuksa.proto.v1.KuksaValV1.SetResponse import org.eclipse.kuksa.proto.v1.Types import org.eclipse.kuksa.proto.v1.Types.Datapoint +import org.eclipse.kuksa.proto.v1.Types.Field import org.eclipse.kuksa.subscription.DataBrokerSubscriber import org.eclipse.kuksa.vsscore.model.VssProperty import org.eclipse.kuksa.vsscore.model.VssSpecification @@ -117,7 +118,7 @@ class DataBrokerConnection internal constructor( @JvmOverloads fun subscribe( specification: T, - fields: List = listOf(Types.Field.FIELD_VALUE), + fields: List = listOf(Field.FIELD_VALUE), listener: VssSpecificationListener, ) { fields.forEach { field -> @@ -130,7 +131,7 @@ class DataBrokerConnection internal constructor( */ fun unsubscribe( specification: T, - fields: List = listOf(Types.Field.FIELD_VALUE), + fields: List = listOf(Field.FIELD_VALUE), listener: VssSpecificationListener, ) { fields.forEach { field -> @@ -160,7 +161,7 @@ class DataBrokerConnection internal constructor( @JvmOverloads suspend fun fetch( specification: T, - fields: List = listOf(Types.Field.FIELD_VALUE), + fields: Collection = listOf(Field.FIELD_VALUE), ): T { return withContext(dispatcher) { try { @@ -204,18 +205,22 @@ class DataBrokerConnection internal constructor( /** * Only a [VssProperty] can be updated because they have an actual value. When provided with any parent - * [VssSpecification] then this [update] method will find all [VssProperty] children and updates them instead. + * [VssSpecification] then this [update] method will find all [VssProperty] children and updates their corresponding + * [fields] instead. * Compared to [update] with only one [Property] and [Datapoint], here multiple [SetResponse] will be returned * because a [VssSpecification] may consists of multiple values which may need to be updated. * * @throws DataBrokerException in case the connection to the DataBroker is no longer active * @throws IllegalArgumentException if the [VssProperty] could not be converted to a [Datapoint]. */ - suspend fun update(vssSpecification: VssSpecification): List { + suspend fun update( + vssSpecification: VssSpecification, + fields: List = listOf(Field.FIELD_VALUE), + ): List { val responses = mutableListOf() vssSpecification.vssProperties.forEach { vssProperty -> - val property = Property(vssProperty.vssPath) + val property = Property(vssProperty.vssPath, fields) val response = update(property, vssProperty.datapoint) responses.add(response) } diff --git a/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/DataBrokerTransporter.kt b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/DataBrokerTransporter.kt index 7d62d590..c06c43d6 100644 --- a/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/DataBrokerTransporter.kt +++ b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/DataBrokerTransporter.kt @@ -28,6 +28,8 @@ import io.grpc.stub.StreamObserver import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext +import org.eclipse.kuksa.extension.TAG +import org.eclipse.kuksa.extension.applyDatapoint import org.eclipse.kuksa.proto.v1.KuksaValV1 import org.eclipse.kuksa.proto.v1.KuksaValV1.SubscribeResponse import org.eclipse.kuksa.proto.v1.Types @@ -94,16 +96,21 @@ internal class DataBrokerTransporter( ): KuksaValV1.SetResponse { return withContext(defaultDispatcher) { val blockingStub = VALGrpc.newBlockingStub(managedChannel) - val dataEntry = Types.DataEntry.newBuilder() - .setPath(vssPath) - .setValue(updatedDatapoint) - .build() - val entryUpdate = KuksaValV1.EntryUpdate.newBuilder() - .setEntry(dataEntry) - .addAllFields(fields) - .build() + + val entryUpdates = fields.map { field -> + val dataEntry = Types.DataEntry.newBuilder() + .setPath(vssPath) + .applyDatapoint(updatedDatapoint, field) + .build() + + KuksaValV1.EntryUpdate.newBuilder() + .setEntry(dataEntry) + .addFields(field) + .build() + } + val request = KuksaValV1.SetRequest.newBuilder() - .addUpdates(entryUpdate) + .addAllUpdates(entryUpdates) .build() return@withContext try { @@ -162,7 +169,7 @@ internal class DataBrokerTransporter( } override fun onCompleted() { - Log.d("TAG", "onCompleted() called") + Log.d(TAG, "onCompleted() called") } } diff --git a/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/DataEntryBuilderExtension.kt b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/DataEntryBuilderExtension.kt new file mode 100644 index 00000000..d844a0a0 --- /dev/null +++ b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/DataEntryBuilderExtension.kt @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * + */ + +package org.eclipse.kuksa.extension + +import org.eclipse.kuksa.proto.v1.Types +import org.eclipse.kuksa.proto.v1.Types.Field + +/** + * Applies the given [datapoint] to the given [Types.DataEntry.Builder]. If the [field] is set to + * [Field.FIELD_ACTUATOR_TARGET] it will set the datapoint using [Types.DataEntry.Builder.setActuatorTarget], + * otherwise it it will set the datapoint using [Types.DataEntry.Builder.setValue]. + */ +fun Types.DataEntry.Builder.applyDatapoint( + datapoint: Types.Datapoint, + field: Field, +): Types.DataEntry.Builder { + when (field) { + Field.FIELD_ACTUATOR_TARGET -> { + this.actuatorTarget = datapoint + } + + else -> { + this.value = datapoint + } + } + + return this +}