Skip to content

Commit

Permalink
Adding a simple persistence provider
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Schildt <sebastian.schildt@de.bosch.com>
  • Loading branch information
SebastianSchildt committed Oct 27, 2024
1 parent f70153a commit cb17d89
Show file tree
Hide file tree
Showing 8 changed files with 902 additions and 0 deletions.
25 changes: 25 additions & 0 deletions kuksa-persistence-provider/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "kuksa-persistence-provider"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "4.5.20", features = ["derive"] }
tinyjson = "2.5.1"
kuksa = { git = "https://github.com/eclipse-kuksa/kuksa-databroker.git", branch = "feature/refactor_kuksa_crate", package = "kuksa" }
log = "0.4.22"
env_logger = "0.11.5"
regex = "1.11.0"
#Only this version is compatible with kuksa crate. 0.13 is not
prost-types = "0.11.9"
tokio = { version="1.40.0", features = ["full"] }

#Still broken due to closed repo
#djson = { git="https://github.com/dependix/platform.git" , optional = true }
djson = { path="platform/modules/json-al/djson_rust/" , optional = true }

[features]
# use djson library
djson = [ "dep:djson" ]
71 changes: 71 additions & 0 deletions kuksa-persistence-provider/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# KUKSA Persistence Provider

All data in KUKSA is ephemereal. However, in a car there is often data that does not change over the lifetime of a vehicle, and data where you want changes to be persisted over ignition cycles.

This provider can achieve this. It can restore certain values upon startup, either sensor (current) values, or actuations.

An example for one-time restoration of current values are attributes that are maybe not set in a default VSS model deployed to ALL cars of a specific variant, but nevertheless are constant of a specific car, such as the VIN or the Vehicle Color.

This provider can also watch (subscribe) certain current or actuation values. This is useful when interacting with components that do not provide their own persistence management. Assume a climate control UI that can react on unser input and interact with the HVAC system, but is otherwise stateless. By watching and restoring the desired target temperature, the user's preference is saved and restored, without the HVAC UI needing any specific code to handle this.

## Configuration: config,json

Main configuration is in config.json, and example may look like this

```json
{
"restore-only": {
"values": [
"Vehicle.VehicleIdentification.VIN",
"Vehicle.VehicleIdentification.VehicleInteriorColor"
],
"actuators": [
"Vehicle.Cabin.Infotainment.HMI.TemperatureUnit"
]
},

"restore-and-watch": {
"values": [
"Vehicle.Cabin.Infotainment.HMI.TemperatureUnit",
"Vehicle.Cabin.HVAC.Station.Row4.Passenger.FanSpeed"
],
"actuators": [
"Vehicle.Cabin.Infotainment.Media.Volume"
]
},
"state-storage": {
"type": "file",
"path": "statestore.json"
}
}
```

## restore-only section

These elements will be restored from the state store upon startup, but their values will not be watched and updated for changes. You can define whether the current values (values) will be restored or whether a target value is set (actuators).

## restore-and-watch

These elements will be restored from the state store upon startup. It is the intention to also monitor their state and update it in the state store. You can define whether the current values (values) will be restored and watched or whether a target value is set (actuators) and watched. As restore-and-watch includes restore, there is no need to add paths in restore-and-watch to restore-only as well.

## state-storage

Configures the state sotrage used to retrieve values. Currently supported: file

## File storage: statestore.json

This is a valid state store for the file storage.
*Note: ALl VALUES NEED TO BE STORED AS STRING*.
As the statestore does not make a difference between current and target (actuation) values it is currently not possible to watch or restore both for a single VSS path.

```json

{
"Vehicle.VehicleIdentification.VIN": {
"value": "DEADBEEF"
},
"Vehicle.VehicleIdentification.VehicleInteriorColor": {
"value": "Black"
}
}
```
25 changes: 25 additions & 0 deletions kuksa-persistence-provider/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"restore-only": {
"values": [
"Vehicle.VehicleIdentification.VIN",
"Vehicle.VehicleIdentification.VehicleInteriorColor"
],
"actuators": [
"Vehicle.Cabin.Infotainment.HMI.TemperatureUnit"
]
},

"restore-and-watch": {
"values": [
"Vehicle.Cabin.Infotainment.HMI.TemperatureUnit",
"Vehicle.Cabin.HVAC.Station.Row4.Passenger.FanSpeed"
],
"actuators": [
"Vehicle.Cabin.Infotainment.Media.Volume"
]
},
"state-storage": {
"type": "file",
"path": "statestore.json"
}
}
Loading

0 comments on commit cb17d89

Please sign in to comment.