Skip to content

Commit c13163e

Browse files
maaikezPietfried
authored andcommitted
Add tests for device model. Remove 'required' from the database.
Signed-off-by: Maaike Zijderveld, iolar <git.mail@iolar.nl>
1 parent fa39dc4 commit c13163e

13 files changed

+394
-275
lines changed

config/v201/component_config/custom/Connector_1_1.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
}
2020
],
2121
"description": "This variable reports current availability state for the Connector. Optional, because already reported in StatusNotification.",
22-
"type": "string"
22+
"type": "string",
23+
"default": ""
2324
},
2425
"ConnectorAvailable": {
2526
"variable_name": "Available",

config/v201/component_config/custom/Connector_2_1.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
}
2020
],
2121
"description": "This variable reports current availability state for the Connector. Optional, because already reported in StatusNotification.",
22-
"type": "string"
22+
"type": "string",
23+
"default": ""
2324
},
2425
"ConnectorAvailable": {
2526
"variable_name": "Available",

config/v201/component_config/standardized/InternalCtrlr.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -841,17 +841,17 @@
841841
"characteristics": {
842842
"supportsMonitoring": true,
843843
"dataType": "SequenceList",
844-
"valuesList": "ocpp2.0.1,ocpp2.1"
844+
"valuesList": "2.0.1,2.1"
845845
},
846846
"attributes": [
847847
{
848848
"type": "Actual",
849849
"mutability": "ReadOnly",
850-
"value": "ocpp2.1,ocpp2.0.1"
850+
"value": "2.1,2.0.1"
851851
}
852852
],
853853
"description": "List of supported OCPP versions in order of preference",
854-
"default": "ocpp2.1,ocpp2.0.1",
854+
"default": "2.1,2.0.1",
855855
"type": "string"
856856
}
857857
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE VARIABLE
2+
ADD REQUIRED INTEGER DEFAULT FALSE;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE VARIABLE
2+
DROP COLUMN REQUIRED;

include/ocpp/v201/init_device_model_db.hpp

+1-7
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,13 @@ namespace ocpp::v201 {
4343
/// \brief Class that holds a component.
4444
///
4545
/// When the component is read from the database, the component id will be set.
46-
/// When the component is read from the component config file, the 'required' vector will be filled.
4746
///
4847
struct ComponentKey {
4948
std::optional<uint64_t> db_id; ///< \brief Component id in the database.
5049
std::string name; ///< \brief Component name.
5150
std::optional<std::string> instance; ///< \brief Component instance.
5251
std::optional<int32_t> evse_id; ///< \brief Component evse id.
5352
std::optional<int32_t> connector_id; ///< \brief Component connector id.
54-
std::vector<std::string> required; ///< \brief List of required variables.
5553

5654
///
5755
/// \brief operator <, needed to add this class as key in a map.
@@ -85,8 +83,6 @@ struct DeviceModelVariable {
8583
VariableCharacteristics characteristics;
8684
/// \brief Variable attributes
8785
std::vector<DbVariableAttribute> attributes;
88-
/// \brief True if variable is required
89-
bool required;
9086
/// \brief Variable instance
9187
std::optional<std::string> instance;
9288
/// \brief Default value, if this is set in the component config json
@@ -221,11 +217,9 @@ class InitDeviceModelDb : public common::DatabaseHandlerCommon {
221217
///
222218
/// \brief Get all component properties (variables) from the given (component) json.
223219
/// \param component_properties The json component properties
224-
/// \param required_properties The vector of required properties of this component.
225220
/// \return A vector with all Variables belonging to this component.
226221
///
227-
std::vector<DeviceModelVariable> get_all_component_properties(const json& component_properties,
228-
std::vector<std::string> required_properties);
222+
std::vector<DeviceModelVariable> get_all_component_properties(const json& component_properties);
229223

230224
///
231225
/// \brief Insert variable characteristics

lib/ocpp/common/types.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -1061,11 +1061,11 @@ namespace conversions {
10611061
std::string ocpp_protocol_version_to_string(OcppProtocolVersion e) {
10621062
switch (e) {
10631063
case OcppProtocolVersion::v16:
1064-
return "ocpp1.6";
1064+
return "1.6";
10651065
case OcppProtocolVersion::v201:
1066-
return "ocpp2.0.1";
1066+
return "2.0.1";
10671067
case OcppProtocolVersion::v21:
1068-
return "ocpp2.1";
1068+
return "2.1";
10691069
case OcppProtocolVersion::Unknown:
10701070
return "unknown";
10711071
}
@@ -1074,13 +1074,13 @@ std::string ocpp_protocol_version_to_string(OcppProtocolVersion e) {
10741074
}
10751075

10761076
OcppProtocolVersion string_to_ocpp_protocol_version(const std::string& s) {
1077-
if (s == "ocpp1.6") {
1077+
if (s == "1.6") {
10781078
return OcppProtocolVersion::v16;
10791079
}
1080-
if (s == "ocpp2.0.1") {
1080+
if (s == "2.0.1") {
10811081
return OcppProtocolVersion::v201;
10821082
}
1083-
if (s == "ocpp2.1") {
1083+
if (s == "2.1") {
10841084
return OcppProtocolVersion::v21;
10851085
}
10861086
if (s == "unknown") {

lib/ocpp/v201/ctrlr_component_variables.cpp

+99-99
Original file line numberDiff line numberDiff line change
@@ -35,104 +35,6 @@ const Variable Overload = {"Overload"};
3535
const Variable Fallback = {"Fallback"};
3636
}; // namespace StandardizedVariables
3737

38-
const std::vector<std::pair<ComponentVariable, std::vector<RequiredComponentVariable>>>
39-
required_component_available_variables{
40-
{ControllerComponentVariables::AlignedDataCtrlrAvailable,
41-
{ControllerComponentVariables::AlignedDataInterval, ControllerComponentVariables::AlignedDataMeasurands,
42-
ControllerComponentVariables::AlignedDataTxEndedInterval,
43-
ControllerComponentVariables::AlignedDataTxEndedMeasurands}},
44-
{ControllerComponentVariables::LocalAuthListCtrlrAvailable,
45-
{ControllerComponentVariables::LocalAuthListCtrlrEntries,
46-
ControllerComponentVariables::ItemsPerMessageSendLocalList,
47-
ControllerComponentVariables::BytesPerMessageSendLocalList}},
48-
{ControllerComponentVariables::SampledDataCtrlrAvailable,
49-
{ControllerComponentVariables::SampledDataTxEndedMeasurands,
50-
ControllerComponentVariables::SampledDataTxEndedInterval,
51-
ControllerComponentVariables::SampledDataTxStartedMeasurands,
52-
ControllerComponentVariables::SampledDataTxUpdatedMeasurands,
53-
ControllerComponentVariables::SampledDataTxUpdatedInterval}},
54-
{ControllerComponentVariables::SmartChargingCtrlrAvailable,
55-
{ControllerComponentVariables::ChargingProfileMaxStackLevel,
56-
ControllerComponentVariables::ChargingScheduleChargingRateUnit,
57-
ControllerComponentVariables::PeriodsPerSchedule, ControllerComponentVariables::EntriesChargingProfiles,
58-
ControllerComponentVariables::LimitChangeSignificance,
59-
ControllerComponentVariables::CompositeScheduleDefaultLimitAmps,
60-
ControllerComponentVariables::CompositeScheduleDefaultLimitWatts,
61-
ControllerComponentVariables::CompositeScheduleDefaultNumberPhases,
62-
ControllerComponentVariables::SupplyVoltage}},
63-
{ControllerComponentVariables::TariffCostCtrlrAvailableTariff,
64-
{ControllerComponentVariables::TariffFallbackMessage}},
65-
{ControllerComponentVariables::TariffCostCtrlrAvailableCost,
66-
{ControllerComponentVariables::TotalCostFallbackMessage,
67-
ControllerComponentVariables::TariffCostCtrlrCurrency}},
68-
{ControllerComponentVariables::MonitoringCtrlrAvailable,
69-
{ControllerComponentVariables::ItemsPerMessageSetVariableMonitoring,
70-
ControllerComponentVariables::BytesPerMessageSetVariableMonitoring}},
71-
{ControllerComponentVariables::DisplayMessageCtrlrAvailable,
72-
{ControllerComponentVariables::NumberOfDisplayMessages,
73-
ControllerComponentVariables::DisplayMessageSupportedFormats,
74-
ControllerComponentVariables::DisplayMessageSupportedPriorities}}};
75-
76-
const std::vector<RequiredComponentVariable> required_variables{
77-
ControllerComponentVariables::ChargePointId,
78-
ControllerComponentVariables::NetworkConnectionProfiles,
79-
ControllerComponentVariables::ChargeBoxSerialNumber,
80-
ControllerComponentVariables::ChargePointModel,
81-
ControllerComponentVariables::ChargePointVendor,
82-
ControllerComponentVariables::FirmwareVersion,
83-
ControllerComponentVariables::SupportedCiphers12,
84-
ControllerComponentVariables::SupportedCiphers13,
85-
ControllerComponentVariables::LogMessagesFormat,
86-
ControllerComponentVariables::NumberOfConnectors,
87-
ControllerComponentVariables::SupportedOcppVersions,
88-
ControllerComponentVariables::AuthorizeRemoteStart,
89-
ControllerComponentVariables::LocalAuthorizeOffline,
90-
ControllerComponentVariables::LocalPreAuthorize,
91-
ControllerComponentVariables::ChargingStationAvailabilityState,
92-
ControllerComponentVariables::ChargingStationAvailable,
93-
ControllerComponentVariables::ChargingStationSupplyPhases,
94-
ControllerComponentVariables::ClockCtrlrDateTime,
95-
ControllerComponentVariables::TimeSource,
96-
ControllerComponentVariables::BytesPerMessageGetReport,
97-
ControllerComponentVariables::BytesPerMessageGetVariables,
98-
ControllerComponentVariables::BytesPerMessageSetVariables,
99-
ControllerComponentVariables::ItemsPerMessageGetReport,
100-
ControllerComponentVariables::ItemsPerMessageGetVariables,
101-
ControllerComponentVariables::ItemsPerMessageSetVariables,
102-
ControllerComponentVariables::ContractValidationOffline,
103-
ControllerComponentVariables::FileTransferProtocols,
104-
ControllerComponentVariables::MessageTimeout,
105-
ControllerComponentVariables::MessageAttemptInterval,
106-
ControllerComponentVariables::MessageAttempts,
107-
ControllerComponentVariables::NetworkConfigurationPriority,
108-
ControllerComponentVariables::NetworkProfileConnectionAttempts,
109-
ControllerComponentVariables::OfflineThreshold,
110-
ControllerComponentVariables::ResetRetries,
111-
ControllerComponentVariables::RetryBackOffRandomRange,
112-
ControllerComponentVariables::RetryBackOffRepeatTimes,
113-
ControllerComponentVariables::RetryBackOffWaitMinimum,
114-
ControllerComponentVariables::UnlockOnEVSideDisconnect,
115-
ControllerComponentVariables::WebSocketPingInterval,
116-
ControllerComponentVariables::CertificateEntries,
117-
ControllerComponentVariables::SecurityCtrlrIdentity,
118-
ControllerComponentVariables::OrganizationName,
119-
ControllerComponentVariables::SecurityProfile,
120-
ControllerComponentVariables::EVConnectionTimeOut,
121-
ControllerComponentVariables::StopTxOnEVSideDisconnect,
122-
ControllerComponentVariables::StopTxOnInvalidId,
123-
ControllerComponentVariables::TxStartPoint,
124-
ControllerComponentVariables::TxStopPoint,
125-
ControllerComponentVariables::TxStartPoint,
126-
ControllerComponentVariables::TxStopPoint};
127-
128-
// Note: Power is also required, but the value is not required but the maxLimit. So that is why it is not added here.
129-
const std::vector<Variable> required_evse_variables{
130-
EvseComponentVariables::Available, EvseComponentVariables::AvailabilityState, EvseComponentVariables::SupplyPhases};
131-
132-
const std::vector<Variable> required_connector_variables{
133-
ConnectorComponentVariables::Available, ConnectorComponentVariables::AvailabilityState,
134-
ConnectorComponentVariables::SupplyPhases, ConnectorComponentVariables::Type};
135-
13638
namespace ControllerComponentVariables {
13739
const ComponentVariable InternalCtrlrEnabled = {
13840
ControllerComponents::InternalCtrlr,
@@ -1278,7 +1180,7 @@ namespace ConnectorComponentVariables {
12781180

12791181
const Variable Available = {"Available"};
12801182
const Variable AvailabilityState = {"AvailabilityState"};
1281-
const Variable Type = {"Type"};
1183+
const Variable Type = {"ConnectorType"};
12821184
const Variable SupplyPhases = {"SupplyPhases"};
12831185

12841186
ComponentVariable get_component_variable(const int32_t evse_id, const int32_t connector_id, const Variable& variable) {
@@ -1291,5 +1193,103 @@ ComponentVariable get_component_variable(const int32_t evse_id, const int32_t co
12911193
}
12921194
} // namespace ConnectorComponentVariables
12931195

1196+
const std::vector<std::pair<ComponentVariable, std::vector<RequiredComponentVariable>>>
1197+
required_component_available_variables{
1198+
{ControllerComponentVariables::AlignedDataCtrlrAvailable,
1199+
{ControllerComponentVariables::AlignedDataInterval, ControllerComponentVariables::AlignedDataMeasurands,
1200+
ControllerComponentVariables::AlignedDataTxEndedInterval,
1201+
ControllerComponentVariables::AlignedDataTxEndedMeasurands}},
1202+
{ControllerComponentVariables::LocalAuthListCtrlrAvailable,
1203+
{ControllerComponentVariables::LocalAuthListCtrlrEntries,
1204+
ControllerComponentVariables::ItemsPerMessageSendLocalList,
1205+
ControllerComponentVariables::BytesPerMessageSendLocalList}},
1206+
{ControllerComponentVariables::SampledDataCtrlrAvailable,
1207+
{ControllerComponentVariables::SampledDataTxEndedMeasurands,
1208+
ControllerComponentVariables::SampledDataTxEndedInterval,
1209+
ControllerComponentVariables::SampledDataTxStartedMeasurands,
1210+
ControllerComponentVariables::SampledDataTxUpdatedMeasurands,
1211+
ControllerComponentVariables::SampledDataTxUpdatedInterval}},
1212+
{ControllerComponentVariables::SmartChargingCtrlrAvailable,
1213+
{ControllerComponentVariables::ChargingProfileMaxStackLevel,
1214+
ControllerComponentVariables::ChargingScheduleChargingRateUnit,
1215+
ControllerComponentVariables::PeriodsPerSchedule, ControllerComponentVariables::EntriesChargingProfiles,
1216+
ControllerComponentVariables::LimitChangeSignificance,
1217+
ControllerComponentVariables::CompositeScheduleDefaultLimitAmps,
1218+
ControllerComponentVariables::CompositeScheduleDefaultLimitWatts,
1219+
ControllerComponentVariables::CompositeScheduleDefaultNumberPhases,
1220+
ControllerComponentVariables::SupplyVoltage}},
1221+
{ControllerComponentVariables::TariffCostCtrlrAvailableTariff,
1222+
{ControllerComponentVariables::TariffFallbackMessage}},
1223+
{ControllerComponentVariables::TariffCostCtrlrAvailableCost,
1224+
{ControllerComponentVariables::TotalCostFallbackMessage,
1225+
ControllerComponentVariables::TariffCostCtrlrCurrency}},
1226+
{ControllerComponentVariables::MonitoringCtrlrAvailable,
1227+
{ControllerComponentVariables::ItemsPerMessageSetVariableMonitoring,
1228+
ControllerComponentVariables::BytesPerMessageSetVariableMonitoring}},
1229+
{ControllerComponentVariables::DisplayMessageCtrlrAvailable,
1230+
{ControllerComponentVariables::NumberOfDisplayMessages,
1231+
ControllerComponentVariables::DisplayMessageSupportedFormats,
1232+
ControllerComponentVariables::DisplayMessageSupportedPriorities}}};
1233+
1234+
const std::vector<RequiredComponentVariable> required_variables{
1235+
ControllerComponentVariables::ChargePointId,
1236+
ControllerComponentVariables::NetworkConnectionProfiles,
1237+
ControllerComponentVariables::ChargeBoxSerialNumber,
1238+
ControllerComponentVariables::ChargePointModel,
1239+
ControllerComponentVariables::ChargePointVendor,
1240+
ControllerComponentVariables::FirmwareVersion,
1241+
ControllerComponentVariables::SupportedCiphers12,
1242+
ControllerComponentVariables::SupportedCiphers13,
1243+
ControllerComponentVariables::LogMessagesFormat,
1244+
ControllerComponentVariables::NumberOfConnectors,
1245+
ControllerComponentVariables::SupportedOcppVersions,
1246+
ControllerComponentVariables::AuthorizeRemoteStart,
1247+
ControllerComponentVariables::LocalAuthorizeOffline,
1248+
ControllerComponentVariables::LocalPreAuthorize,
1249+
ControllerComponentVariables::ChargingStationAvailabilityState,
1250+
ControllerComponentVariables::ChargingStationAvailable,
1251+
ControllerComponentVariables::ChargingStationSupplyPhases,
1252+
ControllerComponentVariables::ClockCtrlrDateTime,
1253+
ControllerComponentVariables::TimeSource,
1254+
ControllerComponentVariables::BytesPerMessageGetReport,
1255+
ControllerComponentVariables::BytesPerMessageGetVariables,
1256+
ControllerComponentVariables::BytesPerMessageSetVariables,
1257+
ControllerComponentVariables::ItemsPerMessageGetReport,
1258+
ControllerComponentVariables::ItemsPerMessageGetVariables,
1259+
ControllerComponentVariables::ItemsPerMessageSetVariables,
1260+
ControllerComponentVariables::ContractValidationOffline,
1261+
ControllerComponentVariables::FileTransferProtocols,
1262+
ControllerComponentVariables::MessageTimeout,
1263+
ControllerComponentVariables::MessageAttemptInterval,
1264+
ControllerComponentVariables::MessageAttempts,
1265+
ControllerComponentVariables::NetworkConfigurationPriority,
1266+
ControllerComponentVariables::NetworkProfileConnectionAttempts,
1267+
ControllerComponentVariables::OfflineThreshold,
1268+
ControllerComponentVariables::ResetRetries,
1269+
ControllerComponentVariables::RetryBackOffRandomRange,
1270+
ControllerComponentVariables::RetryBackOffRepeatTimes,
1271+
ControllerComponentVariables::RetryBackOffWaitMinimum,
1272+
ControllerComponentVariables::UnlockOnEVSideDisconnect,
1273+
ControllerComponentVariables::WebSocketPingInterval,
1274+
ControllerComponentVariables::CertificateEntries,
1275+
ControllerComponentVariables::SecurityCtrlrIdentity,
1276+
ControllerComponentVariables::OrganizationName,
1277+
ControllerComponentVariables::SecurityProfile,
1278+
ControllerComponentVariables::EVConnectionTimeOut,
1279+
ControllerComponentVariables::StopTxOnEVSideDisconnect,
1280+
ControllerComponentVariables::StopTxOnInvalidId,
1281+
ControllerComponentVariables::TxStartPoint,
1282+
ControllerComponentVariables::TxStopPoint,
1283+
ControllerComponentVariables::TxStartPoint,
1284+
ControllerComponentVariables::TxStopPoint};
1285+
1286+
// Note: Power is also required, but the value is not required but the maxLimit. So that is why it is not added here.
1287+
const std::vector<Variable> required_evse_variables{
1288+
EvseComponentVariables::Available, EvseComponentVariables::AvailabilityState, EvseComponentVariables::SupplyPhases};
1289+
1290+
const std::vector<Variable> required_connector_variables{
1291+
ConnectorComponentVariables::Available, ConnectorComponentVariables::AvailabilityState,
1292+
ConnectorComponentVariables::SupplyPhases, ConnectorComponentVariables::Type};
1293+
12941294
} // namespace v201
12951295
} // namespace ocpp

lib/ocpp/v201/device_model.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ void DeviceModel::check_variable_has_value(const ComponentVariable& component_va
129129
const auto response = this->request_value_internal(component_variable.component,
130130
component_variable.variable.value(), attribute, value, true);
131131

132-
if (response != GetVariableStatusEnum::Accepted || value.empty()) {
133-
throw DeviceModelError("Required variable " + component_variable.variable->name.get() +
134-
" does not have a value in the device model");
132+
if (response != GetVariableStatusEnum::Accepted) {
133+
throw DeviceModelError("Required variable " + component_variable.variable->name.get() + " of component " +
134+
component_variable.component.name.get() + " does not have a value in the device model");
135135
}
136136
}
137137

@@ -563,7 +563,7 @@ void DeviceModel::check_integrity(const std::map<int32_t, int32_t>& evse_connect
563563
}
564564
}
565565
} catch (const DeviceModelError& e) {
566-
EVLOG_error << "Integrity check in Device Model failed:" << e.what();
566+
EVLOG_error << "Integrity check in Device Model failed: " << e.what();
567567
throw e;
568568
}
569569
}

0 commit comments

Comments
 (0)