Skip to content

Introduce common classes for v1 and v2 protocols #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/actions/run-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ runs:
using: "composite"
steps:
- name: Run 'test' with Gradle Wrapper
run: ./gradlew test -Ddatabroker.tag="${{ inputs.databroker-version }}" -Dkotest.tags="${{ inputs.kotest-tag}}"
run: ./gradlew test -Ddatabroker.tag="${{ inputs.databroker-version }}" -Dkotest.tags="${{ inputs['kotest-tag'] }}" -Ddatabroker.timeout=30
shell: bash
continue-on-error: true

- name: Upload Test Reports
if: ${{ inputs.upload-test-reports == 'true' }}
if: ${{ inputs['upload-test-reports'] == 'true' }}
uses: actions/upload-artifact@v4
with:
name: test-reports
Expand All @@ -34,12 +35,12 @@ runs:
retention-days: 14

- name: Create Code Coverage Reports
if: ${{ inputs.upload-code-coverage-reports == 'true' }}
if: ${{ inputs['upload-code-coverage-reports'] == 'true' }}
run: ./gradlew jacocoRootReport
shell: bash

- name: Upload Code Coverage Report
if: ${{ inputs.upload-code-coverage-reports == 'true' }}
if: ${{ inputs['upload-code-coverage-reports'] == 'true' }}
uses: actions/upload-artifact@v4
with:
name: code-coverage
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/daily_integration_main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ jobs:
- name: Run Tests
uses: ./.github/actions/run-tests
with:
upload-test-reports: true
upload-test-reports: 'true'
databroker-version: main
kotest-tag: "Integration"
39 changes: 24 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,52 @@ Currently the following protocols are supported:
- kuksa.val.v1
- kuksa.val.v2

Unsupported protocols:
- sdv.databroker.v1

## kuksa.val.v1

You can interact with the Databroker using the kuksa.val.v1 interface by using the
org.eclipse.kuksa.connectivity.databroker.v1.DataBrokerConnector class.
You can interact with the Databroker using the kuksa.val.v1 interface. The interface is exposed by the org.eclipse.kuksa.connectivity.databroker.DataBrokerConnection#kuksaValV1 property.

After successfully connecting the following methods are supported by org.eclipse.kuksa.connectivity.databroker.v1.DataBrokerConnection:
- subscribe(SubscribeRequest, VssPathListener)
- unsubscribe(SubscribeRequest, VssPathListener)
- subscribe(VssNodeSubscribeRequest<T>, VssNodeListener<T>)
- unsubscribe(VssNodeSubscribeRequest<T>, VssNodeListener<T>)
- fetch(FetchRequest): GetResponse
- fetch(VssNodeFetchRequest<T>): T
- fetch<T : VssNode>(VssNodeFetchRequest<T>)
- subscribe(SubscribeRequest, VssPathListener)
- subscribe(SubscribeRequest): Flow<SubscribeResponse>
- subscribe<T : VssNode>(VssNodeSubscribeRequest, VssNodeListener<T>)
- update(UpdateRequest): SetResponse
- update(VssNodeUpdateRequest<T>): VssNodeUpdateResponse
- update<T : VssNode>(request: VssNodeUpdateRequest<T>): VssNodeUpdateResponse
- streamedUpdate(StreamObserver<...Response>): StreamObserver<...Request>

## kuksa.val.v2

You can interact with the Databroker using the kuksa.val.v1 interface by using the
org.eclipse.kuksa.connectivity.databroker.v2.DataBrokerConnectorV2 class.
You can interact with the Databroker using the kuksa.val.v2 interface. The interface is exposed by the org.eclipse.kuksa.connectivity.databroker.DataBrokerConnection#kuksaValV1 property.

After successfully connecting the following methods are supported by org.eclipse.kuksa.connectivity.databroker.v2.DataBrokerConnectionV2:
- fetchValue(FetchValueRequestV2): GetValueResponse
- fetchValues(FetchValuesRequestV2): GetValuesResponse
- subscribeById(SubscribeByIdRequestV2): Flow<SubscribeByIdResponse>
- subscribe(SubscribeRequestV2): Flow<SubscribeResponse>
- subscribe(SubscribeRequestV2): Flow<SubscribeResponse> {
- actuate(ActuateRequestV2): ActuateResponse
- batchActuate(BatchActuateRequestV2): BatchActuateResponse
- listMetadata(ListMetadataRequestV2): ListMetadataResponse
- publishValue(PublishValueRequestV2): PublishValueResponse
- openProviderStream(StreamObserver<OpenProviderStreamResponse>): StreamObserver<OpenProviderStreamRequest>
- openProviderStream(StreamObserver<...Response>): StreamObserver<...Request>
- fetchServerInfo(): GetServerInfoResponse

## Integration

*app/build.gradle.kts*
```
implementation("org.eclipse.kuksa:kuksa-java-sdk:<VERSION>")

// uncomment for android
// implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:<x.y.z>")

// uncomment for java
// implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:<x.y.z>")
```

The latest release version can be seen [here](https://github.com/eclipse-kuksa/kuksa-java-sdk/releases).
The latest release version of the kuksa-java-sdk can be seen [here](https://github.com/eclipse-kuksa/kuksa-java-sdk/releases).


See the [quickstart guide](https://github.com/eclipse-kuksa/kuksa-java-sdk/tree/main/docs/QUICKSTART.md) for additional integration options.
Expand Down Expand Up @@ -89,18 +96,20 @@ fun connectInsecure(host: String, port: Int) {
}
```

Sample Code:
```kotlin
fun fetch() {
lifecycleScope.launch {
val request = FetchRequest("Vehicle.Speed", listOf(Field.FIELD_VALUE))
val response = dataBrokerConnection?.fetch(request) ?: return@launch
val response = dataBrokerConnection?.kuksaValV1.fetch(request) ?: return@launch
val entry = entriesList.first() // Don't forget to handle empty responses
val value = entry.value
val speed = value.float
}
}
```

More samples can be found here [here](https://github.com/eclipse-kuksa/kuksa-java-sdk/blob/main/samples/src/main/java/com/example/samples/Main.kt)
Refer to the [quickstart guide](https://github.com/eclipse-kuksa/kuksa-java-sdk/tree/main/docs/QUICKSTART.md) or
[class diagrams](https://github.com/eclipse-kuksa/kuksa-java-sdk/blob/main/docs/kuksa-sdk_class-diagram.puml) for
further insight into the KUKSA SDK API.
Expand Down
42 changes: 27 additions & 15 deletions docs/QUICKSTART.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ Get instantly bootstrapped into the world of the KUKSA Java SDK with the followi
## Integration

*app/build.gradle.kts*

```
implementation("org.eclipse.kuksa:kuksa-java-sdk:<VERSION>")
```

## Connecting to the Databroker

You can use the following snippet for a simple (unsecure) connection to the Databroker.
You can use the following snippet for a simple (unsecure) connection to the Databroker.

*Kotlin*

```kotlin
private var dataBrokerConnection: DataBrokerConnection? = null

Expand All @@ -35,7 +37,9 @@ fun connectInsecure(host: String, port: Int) {
}
}
```

*Java*

```java
void connectInsecure(String host, int port) {
ManagedChannel managedChannel = ManagedChannelBuilder.forAddress(host, port)
Expand Down Expand Up @@ -63,11 +67,12 @@ void connectInsecure(String host, int port) {
## Interacting with the Databroker

*Kotlin*

```kotlin
fun fetch() {
lifecycleScope.launch {
val request = FetchRequest("Vehicle.Speed", Field.FIELD_VALUE)
val response = dataBrokerConnection?.fetch(request) ?: return@launch
val response = dataBrokerConnection?.kuksaValV1.fetch(request) ?: return@launch
val entry = response.entriesList.first() // Don't forget to handle empty responses
val value = entry.value
val speed = value.float
Expand All @@ -78,7 +83,7 @@ fun update() {
lifecycleScope.launch {
val request = UpdateRequest("Vehicle.Speed", Field.FIELD_VALUE)
val datapoint = Datapoint.newBuilder().setFloat(100f).build()
dataBrokerConnection?.update(request, datapoint)
dataBrokerConnection?.kuksaValV1.update(request, datapoint)
}
}

Expand All @@ -90,25 +95,28 @@ fun subscribe() {
val updatedValue = entryUpdate.entry

// handle entry change
when (updatedValue.path) {
when (val vssPath = updatedValue.path) {
"Vehicle.Speed" -> {
val speed = updatedValue.value.float
}
else -> throw IllegalArgumentException("Unhandled vssPath: $vssPath")
}
}
}

dataBrokerConnection?.subscribe(request, listener)
dataBrokerConnection?.kuksaValV1.subscribe(request, listener)
}
```

*Java*

```java
void fetch() {
FetchRequest request = new FetchRequest("Vehicle.Speed", Types.Field.FIELD_VALUE);
dataBrokerConnection.fetch(request, new CoroutineCallback<GetResponse>() {
dataBrokerConnection.kuksaValV1.fetch(request, new CoroutineCallback<GetResponse>() {
@Override
public void onSuccess(GetResponse result) {
result.entriesList.first() // Don't forget to handle empty responses
result.entriesList.first(); // Don't forget to handle empty responses
Types.DataEntry dataEntry = result.getEntriesList().get(0);
Datapoint datapoint = dataEntry.getValue();
float speed = datapoint.getFloat();
Expand All @@ -119,7 +127,7 @@ void fetch() {
void update() {
Datapoint datapoint = Datapoint.newBuilder().setFloat(100f).build();
UpdateRequest request = new UpdateRequest("Vehicle.Speed", datapoint, Types.Field.FIELD_VALUE);
dataBrokerConnection.update(request, new CoroutineCallback<KuksaValV1.SetResponse>() {
dataBrokerConnection.kuksaValV1.update(request, new CoroutineCallback<KuksaValV1.SetResponse>() {
@Override
public void onSuccess(KuksaValV1.SetResponse result) {
// handle result
Expand All @@ -129,16 +137,20 @@ void update() {

void subscribe() {
SubscribeRequest request = new SubscribeRequest("Vehicle.Speed", Types.Field.FIELD_VALUE);
dataBrokerConnection.subscribe(request, new VssPathListener() {
dataBrokerConnection.kuksaValV1.subscribe(request, new VssPathListener() {
@Override
public void onEntryChanged(@NonNull List<EntryUpdate> entryUpdates) {
for (KuksaValV1.EntryUpdate entryUpdate : entryUpdates) {
Types.DataEntry updatedValue = entryUpdate.getEntry();

// handle entry change
switch (updatedValue.getPath()) {
case "Vehicle.Speed":
float speed = updatedValue.getValue().getFloat();
Types.DataEntry updatedValue = entryUpdate.getEntry();

// handle entry change
String vssPath = updatedValue.getPath();
switch (vssPath) {
case "Vehicle.Speed" -> {
float speed = updatedValue.getValue().getFloat();
}
default -> throw new IllegalArgumentException("Unhandled vssPath: " + vssPath);
}
}
}

Expand Down
Loading