Skip to content

Commit 78a853e

Browse files
authored
Merge pull request #195 from c-jimenez/develop
v1.5.0
2 parents 4fc2d4e + 65731ea commit 78a853e

22 files changed

+274
-76
lines changed

.vscode/launch.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,26 @@
3838
"target": "${workspaceRoot}/build_gcc_native/tests/chargepoint/smartcharging/test_smartcharging_setpoint",
3939
"cwd": "${workspaceRoot}",
4040
"valuesFormatting": "parseText"
41+
},
42+
{
43+
"type": "cppdbg",
44+
"request": "attach",
45+
"name": "Join process",
46+
"program": "${workspaceRoot}/bin/gcc_native/quick_start_chargepoint",
47+
"processId": "${command:pickProcess}",
48+
"MIMode": "gdb",
49+
"setupCommands": [
50+
{
51+
"description": "Activer l'impression en mode Pretty pour gdb",
52+
"text": "-enable-pretty-printing",
53+
"ignoreFailures": true
54+
},
55+
{
56+
"description": "Définir la version désassemblage sur Intel",
57+
"text": "-gdb-set disassembly-flavor intel",
58+
"ignoreFailures": true
59+
}
60+
]
4161
}
4262
]
4363
}

3rdparty/CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ endif()
88
target_include_directories(rapidjson INTERFACE rapidjson/include)
99

1010
# Doctest is an header only on library
11-
add_library(doctest INTERFACE)
12-
target_include_directories(doctest INTERFACE doctest/doctest)
11+
if(${INSTALL_DOCTEST})
12+
add_library(doctest INTERFACE)
13+
target_include_directories(doctest INTERFACE doctest/doctest)
14+
endif()
1315

1416
# SQLite 3
15-
add_subdirectory(sqlite3)
17+
if(${BUILD_SQLITE})
18+
add_subdirectory(sqlite3)
19+
endif()
1620

1721
# libwebsockets
1822
if(${BUILD_LWS_LIBRARY})

CMakeLists.txt

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
cmake_minimum_required(VERSION 3.13)
66

77
project(OpenOCPP DESCRIPTION "Open Source C++ implementation of the OCPP 1.6 protocol"
8-
VERSION 1.4.3
8+
VERSION 1.5.0
99
)
1010

1111
# Definitions for Version.h file
@@ -89,29 +89,32 @@ if(${BUILD_STATIC_LIBRARY})
8989
endif()
9090

9191
# Open OCPP dynamic library
92-
add_library(open-ocpp-dynamic SHARED
93-
src/version.cpp)
94-
target_link_libraries(open-ocpp-dynamic
95-
centralsystem
96-
chargepoint
97-
localcontroller
98-
config
99-
database
100-
messages
101-
rpc
102-
helpers
103-
log
104-
version
105-
x509
106-
json
107-
ws
108-
websockets
109-
)
110-
set_target_properties(open-ocpp-dynamic PROPERTIES
111-
OUTPUT_NAME "open-ocpp"
112-
VERSION ${PROJECT_VERSION}
113-
SOVERSION ${PROJECT_VERSION_MAJOR}
114-
)
92+
if (${BUILD_SHARED_LIBRARY})
93+
add_library(open-ocpp-dynamic SHARED
94+
src/version.cpp)
95+
target_link_libraries(open-ocpp-dynamic
96+
centralsystem
97+
chargepoint
98+
localcontroller
99+
config
100+
database
101+
messages
102+
rpc
103+
helpers
104+
log
105+
version
106+
x509
107+
json
108+
ws
109+
websockets
110+
)
111+
set_target_properties(open-ocpp-dynamic PROPERTIES
112+
OUTPUT_NAME "open-ocpp"
113+
VERSION ${PROJECT_VERSION}
114+
SOVERSION ${PROJECT_VERSION_MAJOR}
115+
)
116+
set(OPEN_OCPP_SHARED_TARGET open-ocpp-dynamic)
117+
endif()
115118

116119
# Install commands
117120
include(GNUInstallDirs)
@@ -121,7 +124,7 @@ file(GLOB_RECURSE PUBLIC_HEADERS
121124
file(GLOB OCPP_SCHEMAS
122125
LIST_DIRECTORIES false RELATIVE ${CMAKE_SOURCE_DIR} "${CMAKE_SOURCE_DIR}/schemas/*.json")
123126

124-
install(TARGETS open-ocpp-dynamic ${OPEN_OCPP_STATIC_TARGET}
127+
install(TARGETS ${OPEN_OCPP_SHARED_TARGET} ${OPEN_OCPP_STATIC_TARGET}
125128
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
126129
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
127130
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
@@ -145,12 +148,14 @@ set(PKG_CONFIG_INCLUDEDIR "\${prefix}/include/openocpp")
145148
set(PKG_CONFIG_LIBS "-L\${libdir}")
146149
set(PKG_CONFIG_CFLAGS "-I\${includedir}")
147150

148-
set(LIB_NAME "open-ocpp")
149-
configure_file(
150-
"${CMAKE_CURRENT_SOURCE_DIR}/deploy/libopen-ocpp.pc.in"
151-
"${CMAKE_CURRENT_BINARY_DIR}/libopen-ocpp.pc"
152-
)
153-
install(FILES "${CMAKE_BINARY_DIR}/libopen-ocpp.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
151+
if(${BUILD_SHARED_LIBRARY})
152+
set(LIB_NAME "open-ocpp")
153+
configure_file(
154+
"${CMAKE_CURRENT_SOURCE_DIR}/deploy/libopen-ocpp.pc.in"
155+
"${CMAKE_CURRENT_BINARY_DIR}/libopen-ocpp.pc"
156+
)
157+
install(FILES "${CMAKE_BINARY_DIR}/libopen-ocpp.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
158+
endif()
154159

155160
if(${BUILD_STATIC_LIBRARY})
156161
set(LIB_NAME "open-ocpp_static")

CMakeLists_Options.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ if(EXTERNAL_LOGGER)
1414
add_compile_definitions(EXTERNAL_LOGGER=1)
1515
endif()
1616

17+
# Shared library
18+
option(BUILD_SHARED_LIBRARY "Build Open OCPP as a shared library" ON)
19+
1720
# Static library
1821
option(BUILD_STATIC_LIBRARY "Build Open OCPP as a static library" ON)
1922

@@ -26,6 +29,12 @@ option(BUILD_EXAMPLES "Build examples"
2629
# Build the libwebsocket library along with the Open OCPP library
2730
option(BUILD_LWS_LIBRARY "Build libwebsocket library" ON)
2831

32+
# Build the sqlite3 library along with the Open OCPP library
33+
option(BUILD_SQLITE "Build sqlite3 library" ON)
34+
35+
# Install the Doctest header
36+
option(INSTALL_DOCTEST "Install doctest headers" ON)
37+
2938
# Use only the CrtAllocator in Rapidjson, not the MemoryPoolAllocator
3039
option(USE_CRT_ALLOC_FOR_RAPIDJSON "Use the CrtAllocator for Rapidjson instead of the MemoryPoolAllocator" OFF)
3140
if(USE_CRT_ALLOC_FOR_RAPIDJSON)

examples/common/DefaultChargePointEventsHandler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,15 @@ bool DefaultChargePointEventsHandler::remoteStartTransactionRequested(unsigned i
169169
bool ret = false;
170170
cout << "Remote start transaction : " << connector_id << " - " << id_tag << endl;
171171

172-
if(connector_id > m_config.ocppConfig().numberOfConnectors() || connector_id == 0)
172+
if (connector_id > m_config.ocppConfig().numberOfConnectors() || connector_id == 0)
173173
{
174-
ret=false;
174+
ret = false;
175175
}
176176
else
177177
{
178178
m_remote_start_pending[connector_id - 1u] = true;
179179
m_remote_start_id_tag[connector_id - 1u] = id_tag;
180-
ret=true;
180+
ret = true;
181181
}
182182
return ret;
183183
}

examples/common/config/OcppConfig.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ ocpp::types::ConfigurationStatus OcppConfig::setConfiguration(const std::string&
207207
}
208208
}
209209

210-
if (ret != ConfigurationStatus::Rejected)
211-
{
210+
if (ret != ConfigurationStatus::Rejected)
211+
{
212212
if ((it->second & PARAM_OCPP) != 0)
213213
{
214214
m_config.set(OCPP_PARAMS, key, value);
@@ -225,7 +225,7 @@ ocpp::types::ConfigurationStatus OcppConfig::setConfiguration(const std::string&
225225
{
226226
ret = ConfigurationStatus::Accepted;
227227
}
228-
}
228+
}
229229
}
230230
else
231231
{

examples/security_centralsystem/CentralSystemEventsHandler.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ SOFTWARE.
2525
#include "CentralSystemEventsHandler.h"
2626
#include "ChargePointDatabase.h"
2727

28+
#include <array>
2829
#include <iostream>
2930
#include <random>
3031
#include <sstream>
@@ -99,7 +100,8 @@ bool CentralSystemEventsHandler::checkCredentials(const std::string& chargepoint
99100
{
100101
bool ret = false;
101102

102-
cout << "Check credentials for [" << chargepoint_id << "] : " << password << endl;
103+
std::string hex_encoded_password = ocpp::helpers::toHexString(password);
104+
cout << "Check credentials for [" << chargepoint_id << "] : " << hex_encoded_password << endl;
103105

104106
// HTTP Basic Authentication is for Charge Points configured with Security Profile 1 or 2 only
105107

@@ -111,7 +113,7 @@ bool CentralSystemEventsHandler::checkCredentials(const std::string& chargepoint
111113
{
112114
if ((security_profile == 1u) || (security_profile == 2u))
113115
{
114-
ret = (password == authent_key);
116+
ret = (hex_encoded_password == authent_key);
115117
}
116118
else
117119
{
@@ -257,14 +259,18 @@ ocpp::types::RegistrationStatus CentralSystemEventsHandler::ChargePointRequestHa
257259
}
258260
else
259261
{
260-
// Generate an authent key for the charge point : minimal 16 bytes, max : 20 bytes
261-
std::stringstream ss_authent_key;
262-
ss_authent_key << std::hex;
263-
for (int i = 0; i < 5; i++)
262+
// Generate an authent key for the charge point : minimal 8 bytes, max : 20 bytes
263+
std::mt19937 rand_gen;
264+
std::uniform_int_distribution<unsigned int> rand_distrib;
265+
std::random_device rd;
266+
rand_gen.seed(rd());
267+
268+
std::array<uint8_t, 17u> authent_key_bytes;
269+
for (auto& val : authent_key_bytes)
264270
{
265-
ss_authent_key << std::setfill('0') << std::setw(4) << std::rand();
271+
val = static_cast<uint8_t>(rand_distrib(rand_gen));
266272
}
267-
m_authent_key = ss_authent_key.str();
273+
m_authent_key = ocpp::helpers::toHexString(authent_key_bytes);
268274

269275
// Add the charge point to the database
270276
m_chargepoint_db.addChargePoint(this->proxy()->identifier(), serial_number, vendor, model, 0, m_authent_key);

src/chargepoint/ChargePoint.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ void ChargePoint::rcpMessageSent(const std::string& msg)
990990
void ChargePoint::configurationValueChanged(const std::string& key)
991991
{
992992
// Check configuration key
993-
if (key == "AuthorizationKey")
993+
if (key == "authorizationkey")
994994
{
995995
// Reconnect with new authorization key
996996
if (m_ocpp_config.securityProfile() != 3)
@@ -1001,7 +1001,7 @@ void ChargePoint::configurationValueChanged(const std::string& key)
10011001

10021002
m_security_manager.logSecurityEvent(SECEVT_RECONFIG_SECURITY_PARAMETER, "AuthorizationKey");
10031003
}
1004-
else if (key == "SecurityProfile")
1004+
else if (key == "securityprofile")
10051005
{
10061006
// Reconnect with new profile
10071007
LOG_INFO << "SecurityProfile modified, reconnect with new security profile";
@@ -1164,8 +1164,10 @@ bool ChargePoint::doConnect()
11641164
std::string authorization_key = m_ocpp_config.authorizationKey();
11651165
if (!authorization_key.empty() && (security_profile <= 2))
11661166
{
1167-
credentials.user = m_stack_config.chargePointIdentifier();
1168-
credentials.password = authorization_key;
1167+
auto authentication_key = ocpp::helpers::fromHexString(authorization_key);
1168+
credentials.user = m_stack_config.chargePointIdentifier();
1169+
credentials.password = std::string(reinterpret_cast<const char*>(authentication_key.data()), authorization_key.size());
1170+
credentials.password.resize(authentication_key.size());
11691171
}
11701172
if (security_profile != 1)
11711173
{

src/chargepoint/config/ConfigManager.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@ ConfigManager::~ConfigManager() { }
4949
/** @copydoc void registerCheckFunction(const std::string&, ConfigurationValueCheckFunc) */
5050
void ConfigManager::registerCheckFunction(const std::string& key, ConfigurationValueCheckFunc func)
5151
{
52-
m_specific_checks[key] = func;
52+
auto lower_case_key = ocpp::helpers::tolower(key);
53+
m_specific_checks[lower_case_key] = func;
5354
}
5455

5556
/** @copydoc void IConfigManager::registerConfigChangedListener(const std::string&, IConfigChangedListener&) */
5657
void ConfigManager::registerConfigChangedListener(const std::string& key, IConfigChangedListener& listener)
5758
{
58-
m_listeners[key] = &listener;
59+
auto lower_case_key = ocpp::helpers::tolower(key);
60+
m_listeners[lower_case_key] = &listener;
5961
}
6062

6163
/** @copydoc bool GenericMessageHandler<RequestType, ResponseType>::handleMessage(const RequestType& request,
@@ -93,10 +95,11 @@ bool ConfigManager::handleMessage(const ocpp::messages::ChangeConfigurationReq&
9395
response.status = ConfigurationStatus::Accepted;
9496

9597
// Specific check
96-
auto it = m_specific_checks.find(request.key);
98+
auto lower_case_key = ocpp::helpers::tolower(request.key);
99+
auto it = m_specific_checks.find(lower_case_key);
97100
if (it != m_specific_checks.end())
98101
{
99-
response.status = it->second(request.key, request.value);
102+
response.status = it->second(lower_case_key, request.value);
100103
}
101104
if (response.status == ConfigurationStatus::Accepted)
102105
{
@@ -105,10 +108,10 @@ bool ConfigManager::handleMessage(const ocpp::messages::ChangeConfigurationReq&
105108
if (response.status == ConfigurationStatus::Accepted)
106109
{
107110
// Notify change
108-
auto iter = m_listeners.find(request.key);
111+
auto iter = m_listeners.find(lower_case_key);
109112
if (iter != m_listeners.end())
110113
{
111-
iter->second->configurationValueChanged(request.key);
114+
iter->second->configurationValueChanged(lower_case_key);
112115
}
113116
}
114117
}

src/chargepoint/security/SecurityManager.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -669,15 +669,16 @@ bool SecurityManager::handleMessage(const ocpp::messages::InstallCertificateReq&
669669
ocpp::types::ConfigurationStatus SecurityManager::checkAuthorizationKeyParameter(const std::string& key, const std::string& value)
670670
{
671671
(void)key;
672-
ConfigurationStatus ret = ConfigurationStatus::Accepted;
672+
ConfigurationStatus ret = ConfigurationStatus::Rejected;
673673

674-
// Authorization key length for security profiles 1 and 2 must be between 32 and 40 bytes
675-
unsigned int security_profile = m_ocpp_config.securityProfile();
676-
if ((security_profile == 1) || (security_profile == 2))
674+
// Authorization key length for security profiles 1 and 2 must be between 16 and 40 bytes
675+
// and must be a valid hexadecimal representation
676+
if ((value.size() >= 16u) && (value.size() <= 40u))
677677
{
678-
if ((value.size() < 32u) || (value.size() > 40u))
678+
auto key_bytes = ocpp::helpers::fromHexString(value);
679+
if (key_bytes.size() == (value.size() / 2u))
679680
{
680-
ret = ConfigurationStatus::Rejected;
681+
ret = ConfigurationStatus::Accepted;
681682
}
682683
}
683684

src/chargepoint/smartcharging/ProfileDatabase.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ std::string ProfileDatabase::serialize(const ocpp::types::ChargingProfile& profi
362362

363363
rapidjson::StringBuffer buffer;
364364
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
365+
writer.SetMaxDecimalPlaces(1); // OCPP decimals have 1 digit precision
365366
profile_json.Accept(writer);
366367
profile_str = buffer.GetString();
367368
return profile_str;

src/chargepoint/smartcharging/SmartChargingManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ bool SmartChargingManager::handleMessage(const ocpp::messages::SetChargingProfil
303303
}
304304
else
305305
{
306-
ret = false;
306+
ret = false;
307307
error_message = "Recurring profiles must have a start schedule and a duration";
308308
}
309309
}

src/messages/IMessageConverter.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ class IMessageConverter
9494
json.AddMember(rapidjson::StringRef(name), rapidjson::Value(value), *allocator);
9595
}
9696

97+
/**
98+
* @brief Helper function to fill a floating point value in a JSON object
99+
* @param json JSON object to fill
100+
* @param field Name of the field to fill
101+
* @param value Floating point value to fill
102+
*/
103+
void fill(rapidjson::Value& json, const char* name, const double value)
104+
{
105+
json.AddMember(rapidjson::StringRef(name), rapidjson::Value(value), *allocator);
106+
}
107+
97108
/**
98109
* @brief Helper function to fill a string value in a JSON object
99110
* @param json JSON object to fill

src/messages/MessagesValidator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ along with OpenOCPP. If not, see <http://www.gnu.org/licenses/>.
1919
#ifndef OPENOCPP_MESSAGESVALIDATOR_H
2020
#define OPENOCPP_MESSAGESVALIDATOR_H
2121

22-
#include <JsonValidator.h>
22+
#include "JsonValidator.h"
2323

2424
#include <filesystem>
2525
#include <memory>

0 commit comments

Comments
 (0)