Skip to content
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

Variable and configuration key documentation #733

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
62 changes: 62 additions & 0 deletions doc/variableAndConfigurationKeyIntegration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Access and control of variables and configuration keys

Check notice on line 1 in doc/variableAndConfigurationKeyIntegration/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/variableAndConfigurationKeyIntegration/README.md#L1

Expected: [None]; Actual: # Access and control of variables and configuration keys

Libocpp provides an API to access and control variables and configuration keys for OCPP1.6 and OCPP2.0.1. The term **configuration keys** is used in connection with the OCPP1.6 specification and the term **variables** is used in connection with the OCPP2.0.1 specification.

Check notice on line 3 in doc/variableAndConfigurationKeyIntegration/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/variableAndConfigurationKeyIntegration/README.md#L3

Expected: 80; Actual: 273

The interfaces and implementations for these operations differ between OCPP1.6 and OCPP2.0.1 in this library. This section provides an overview of the integration and mechanisms used for the different protocol versions.

Check notice on line 5 in doc/variableAndConfigurationKeyIntegration/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/variableAndConfigurationKeyIntegration/README.md#L5

Expected: 80; Actual: 219

Note that almost all standardized OCPP1.6 configuration keys configure the control flow within the libocpp library itself. This is very different for OCPP2.0.1, where the device model includes all kinds of different telemetry and configuration data of physical and logical components of a charging station.

Check notice on line 7 in doc/variableAndConfigurationKeyIntegration/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/variableAndConfigurationKeyIntegration/README.md#L7

Expected: 0 or 2; Actual: 1

Check notice on line 7 in doc/variableAndConfigurationKeyIntegration/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/variableAndConfigurationKeyIntegration/README.md#L7

Expected: 80; Actual: 307

## OCPP1.6

The OCPP1.6 specification distributes standardized configuration keys into the feature profiles that it defines. This design is also applied by libocpp. Libocpp uses a JSON config to load the configuration keys into memory at startup. Example configs are located within [here](../../config/v16/).

Check notice on line 11 in doc/variableAndConfigurationKeyIntegration/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/variableAndConfigurationKeyIntegration/README.md#L11

Expected: 80; Actual: 296

### Getting variables

Configuration keys can be requested by the CSMS using a `GetConfiguration.req` or by the libocpp consumer using the `get_configuration_key` function of the `v16/charge_point.hpp`.

Check notice on line 15 in doc/variableAndConfigurationKeyIntegration/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/variableAndConfigurationKeyIntegration/README.md#L15

Expected: 80; Actual: 179

### Setting variables

The following sequence diagram shows how libocpp handles an incoming ChangeConfiguration.req message by the CSMS:

Check notice on line 19 in doc/variableAndConfigurationKeyIntegration/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/variableAndConfigurationKeyIntegration/README.md#L19

Expected: 80; Actual: 113

![Sequence Diagram for ChangeConfiguration.req](csms_change_configuration_key.png)

If the CSMS uses a `ChangeConfiguration.req` to change a configuration key, libocpp validates the request and if the request is valid it writes the updated configuration key into a `user_config.json`. This user config serves as a persistent overlay of the original config and is patched on top of the original config at startup.

Check notice on line 23 in doc/variableAndConfigurationKeyIntegration/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/variableAndConfigurationKeyIntegration/README.md#L23

Expected: 80; Actual: 328

If a `ChangeConfiguration.req` could be applied successfully, libocpp uses two callback mechanism to notify the consumer application about the change. The consumer can opt to register a callback for a single configuration key. This callback is executed if this configuration key is changed. The other or additional option is to register a generic callback that is executed if no specific callback is registered for the changed configuration key.

Check notice on line 25 in doc/variableAndConfigurationKeyIntegration/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/variableAndConfigurationKeyIntegration/README.md#L25

Expected: 80; Actual: 445

The following sequence diagram shows how libocpp handles a request of the consumer to change a custom configuration key.

Check notice on line 27 in doc/variableAndConfigurationKeyIntegration/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/variableAndConfigurationKeyIntegration/README.md#L27

Expected: 80; Actual: 120

![Sequence Diagram for setting a custom configuration key](set_custom_configuration_key.png)

The libocpp API for OCPP1.6 only allows to set custom configuration keys. It does not allow to set any of the standardized configuration keys, since all of them are internally managed. Except for this the sequence is similar to the mechanism described previously.

Check notice on line 31 in doc/variableAndConfigurationKeyIntegration/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/variableAndConfigurationKeyIntegration/README.md#L31

Expected: 80; Actual: 263

## OCPP2.0.1

Libocpp applies the design and data structures of the device model for Component, Variables, VariableCharacteristics, VariableAttributes and VariableMonitors that is described in part 1 Architecture & Topology of the OCPP2.0.1 specification.

Check notice on line 35 in doc/variableAndConfigurationKeyIntegration/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/variableAndConfigurationKeyIntegration/README.md#L35

Expected: 80; Actual: 241

The following simplified UML diagram provides an overview of the relationship between the relevant classes:

Check notice on line 37 in doc/variableAndConfigurationKeyIntegration/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/variableAndConfigurationKeyIntegration/README.md#L37

Expected: 80; Actual: 107

### Device Model Integration

![UML Diagram](device_model_uml.png)

The ChargePoint class contains a reference to the DeviceModel. This implementation is within libocpp. This allows to access the device model structure and to do sanity checks and validations (e.g. by using the VariableCharacteristics) before requesting operations at the actual DeviceModelStorage. Libocpp currently provides an example implementation of the DeviceModelStorage (DeviceModelStorageSqlite) but it can also be provided externally, to allow the usage of different storage achitectures and designs. If provided externally, the implementation needs to provide an implementation for the interface defined within the [DevideModelStroage](../../include/ocpp/v201/device_model_storage.hpp).

Check notice on line 43 in doc/variableAndConfigurationKeyIntegration/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/variableAndConfigurationKeyIntegration/README.md#L43

Expected: 80; Actual: 697

### Getting variables

Check notice on line 45 in doc/variableAndConfigurationKeyIntegration/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/variableAndConfigurationKeyIntegration/README.md#L45

Multiple headings with the same content

Variables can be requested by the CSMS using a `GetVariables.req` or using the `get_variables` function of the `v201/charge_point.hpp`.

Check notice on line 47 in doc/variableAndConfigurationKeyIntegration/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/variableAndConfigurationKeyIntegration/README.md#L47

Expected: 80; Actual: 135

### Setting variables

Check notice on line 49 in doc/variableAndConfigurationKeyIntegration/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/variableAndConfigurationKeyIntegration/README.md#L49

Multiple headings with the same content

The following sections describe how libocpp manages requests to set variable values in the device model.

Check notice on line 51 in doc/variableAndConfigurationKeyIntegration/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/variableAndConfigurationKeyIntegration/README.md#L51

Expected: 80; Actual: 104

![UML Diagram](csms_set_variables_sequence.png)

A `SetVariables.req` initiated from the CSMS can contain requests for multiple variables at the same time. For each of the requests libocpp validates if the requests can be validated logically (e.g. NetworkConfigurationPriority is invalid) and using the VariableCharacteristics (e.g. value invalid for datatype, value exceeds defined maxLimit, etc.). In case the validation is successful, libocpp uses the device model reference to request to set the value of the variable. The response for each individual request is sent back in the `SetVariables.conf`.

Check notice on line 55 in doc/variableAndConfigurationKeyIntegration/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/variableAndConfigurationKeyIntegration/README.md#L55

Expected: 80; Actual: 555

After the `SetVariables.conf` message was sent to the CSMS, each successful request to change a value of a variable is processed internally (e.g. to update the HeartbeatInterval timer) and the variable_changed_callback is executed to notify the libocpp consumer application about the change.

Check notice on line 57 in doc/variableAndConfigurationKeyIntegration/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/variableAndConfigurationKeyIntegration/README.md#L57

Expected: 0 or 2; Actual: 1

Check notice on line 57 in doc/variableAndConfigurationKeyIntegration/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/variableAndConfigurationKeyIntegration/README.md#L57

Expected: 80; Actual: 292

![UML Diagram](core_set_variables_sequence.png)

If the libocpp consumer application attempts to set a variable using the set_variables function, the flow is almost equal to if the CSMS is using a `SetVariables.req`.

Check notice on line 61 in doc/variableAndConfigurationKeyIntegration/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/variableAndConfigurationKeyIntegration/README.md#L61

Expected: 80; Actual: 167

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@startuml
'https://plantuml.com/sequence-diagram
!pragma teoz true
participant core order 10
participant libocpp order 20
participant device_model order 30
participant csms order 40

autonumber "<b><font color=red>"
skinparam sequenceArrowThickness 2

== SetVariables by Core ==
core->libocpp: set_variables
loop For each SetVariable request
libocpp->libocpp: Logical validation
libocpp->libocpp: Device Model validation
alt request is valid and var internally managed
libocpp->device_model: set_value
device_model->libocpp: set_value response
end
end
loop For each SetVariable request
alt if request was accepted
libocpp->libocpp: Handle variable changed internally
libocpp->core: variable_changed_callback
end
end

libocpp->core: set_variables response

@enduml
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@startuml
'https://plantuml.com/sequence-diagram
!pragma teoz true
participant csms order 10
participant libocpp order 20
participant core order 40
database user_config.json order 30

autonumber "<b><font color=red>"
skinparam sequenceArrowThickness 2

== SetVariables.req by CSMS ==
csms->libocpp: ChangeConfiguration.req
libocpp->libocpp: Internal validation
alt request is valid
libocpp->user_config.json: update configuration key
libocpp->csms: respond with Accepted
libocpp->libocpp: handle change internally
else
libocpp->csms: respond with Rejected
end
alt if request was accepted and custom callback registered for this configuration key
libocpp->core: configuration_key_changed_callback
else if request was accepted and generic callback registered
libocpp->core: generic_configuration_key_changed_callback
end

@enduml
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@startuml
'https://plantuml.com/sequence-diagram
!pragma teoz true
participant csms order 10
participant libocpp order 20
participant device_model order 30
participant core order 40

autonumber "<b><font color=red>"
skinparam sequenceArrowThickness 2

== SetVariables.req by CSMS ==
csms->libocpp: SetVariables.req
loop For each SetVariable request
libocpp->libocpp: Logical internal validation
libocpp->libocpp: Device Model validation
alt request is valid
libocpp->device_model: set_value
device_model->libocpp: set_value response
end
end
libocpp->csms: SetVariables.conf
loop For each SetVariable request
alt if request was accepted
libocpp->libocpp: Handle variable changed internally
libocpp->core: variable_changed_callback
end
end

@enduml
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@startuml
class ChargePoint {
- device_model: DeviceModel
}

class DeviceModel {
- storage: DeviceModelStorage
+ get_device_model(): DeviceModelRepresentation
+ get_value(...): T
+ set_value(...): SetVariableStatusEnum
}

class DeviceModelStorage {
+ get_device_model(): DeviceModelRepresentation
+ get_variable_attribute(...): std::optional<VariableAttribute>
+ set_variable_attribute_value(...): bool
}

note left of ChargePoint
ChargePoint and DeviceModel are
implemented within the library.
end note

note right of DeviceModelStorage
Libocpp contains a DeviceModelStorage implementation
and altenatively a custom implementation can be fed into
the library.
end note

ChargePoint --> DeviceModel
DeviceModel --> DeviceModelStorage

@enduml
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@startuml
'https://plantuml.com/sequence-diagram
!pragma teoz true
participant core order 10
participant libocpp order 20
database user_config.json order 30

autonumber "<b><font color=red>"
skinparam sequenceArrowThickness 2

== Set Custom Configuration Key by Core ==
core->libocpp: Set custom configuration key
libocpp->libocpp: Internal validation
alt request is valid and configuration key is custom
libocpp->user_config.json: update configuration key
libocpp->csms: respond with Accepted
else
libocpp->csms: respond with Rejected
end
alt if request was accepted and custom callback registered for this configuration key
libocpp->core: configuration_key_changed_callback
end

@enduml
Loading