Skip to content

Commit

Permalink
Merge pull request #195 from c-jimenez/develop
Browse files Browse the repository at this point in the history
v1.5.0
  • Loading branch information
c-jimenez authored Mar 10, 2024
2 parents 4fc2d4e + 65731ea commit 78a853e
Show file tree
Hide file tree
Showing 22 changed files with 274 additions and 76 deletions.
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,26 @@
"target": "${workspaceRoot}/build_gcc_native/tests/chargepoint/smartcharging/test_smartcharging_setpoint",
"cwd": "${workspaceRoot}",
"valuesFormatting": "parseText"
},
{
"type": "cppdbg",
"request": "attach",
"name": "Join process",
"program": "${workspaceRoot}/bin/gcc_native/quick_start_chargepoint",
"processId": "${command:pickProcess}",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Activer l'impression en mode Pretty pour gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Définir la version désassemblage sur Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}
10 changes: 7 additions & 3 deletions 3rdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ endif()
target_include_directories(rapidjson INTERFACE rapidjson/include)

# Doctest is an header only on library
add_library(doctest INTERFACE)
target_include_directories(doctest INTERFACE doctest/doctest)
if(${INSTALL_DOCTEST})
add_library(doctest INTERFACE)
target_include_directories(doctest INTERFACE doctest/doctest)
endif()

# SQLite 3
add_subdirectory(sqlite3)
if(${BUILD_SQLITE})
add_subdirectory(sqlite3)
endif()

# libwebsockets
if(${BUILD_LWS_LIBRARY})
Expand Down
67 changes: 36 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
cmake_minimum_required(VERSION 3.13)

project(OpenOCPP DESCRIPTION "Open Source C++ implementation of the OCPP 1.6 protocol"
VERSION 1.4.3
VERSION 1.5.0
)

# Definitions for Version.h file
Expand Down Expand Up @@ -89,29 +89,32 @@ if(${BUILD_STATIC_LIBRARY})
endif()

# Open OCPP dynamic library
add_library(open-ocpp-dynamic SHARED
src/version.cpp)
target_link_libraries(open-ocpp-dynamic
centralsystem
chargepoint
localcontroller
config
database
messages
rpc
helpers
log
version
x509
json
ws
websockets
)
set_target_properties(open-ocpp-dynamic PROPERTIES
OUTPUT_NAME "open-ocpp"
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
)
if (${BUILD_SHARED_LIBRARY})
add_library(open-ocpp-dynamic SHARED
src/version.cpp)
target_link_libraries(open-ocpp-dynamic
centralsystem
chargepoint
localcontroller
config
database
messages
rpc
helpers
log
version
x509
json
ws
websockets
)
set_target_properties(open-ocpp-dynamic PROPERTIES
OUTPUT_NAME "open-ocpp"
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
)
set(OPEN_OCPP_SHARED_TARGET open-ocpp-dynamic)
endif()

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

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

set(LIB_NAME "open-ocpp")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/deploy/libopen-ocpp.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/libopen-ocpp.pc"
)
install(FILES "${CMAKE_BINARY_DIR}/libopen-ocpp.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
if(${BUILD_SHARED_LIBRARY})
set(LIB_NAME "open-ocpp")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/deploy/libopen-ocpp.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/libopen-ocpp.pc"
)
install(FILES "${CMAKE_BINARY_DIR}/libopen-ocpp.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
endif()

if(${BUILD_STATIC_LIBRARY})
set(LIB_NAME "open-ocpp_static")
Expand Down
9 changes: 9 additions & 0 deletions CMakeLists_Options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ if(EXTERNAL_LOGGER)
add_compile_definitions(EXTERNAL_LOGGER=1)
endif()

# Shared library
option(BUILD_SHARED_LIBRARY "Build Open OCPP as a shared library" ON)

# Static library
option(BUILD_STATIC_LIBRARY "Build Open OCPP as a static library" ON)

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

# Build the sqlite3 library along with the Open OCPP library
option(BUILD_SQLITE "Build sqlite3 library" ON)

# Install the Doctest header
option(INSTALL_DOCTEST "Install doctest headers" ON)

# Use only the CrtAllocator in Rapidjson, not the MemoryPoolAllocator
option(USE_CRT_ALLOC_FOR_RAPIDJSON "Use the CrtAllocator for Rapidjson instead of the MemoryPoolAllocator" OFF)
if(USE_CRT_ALLOC_FOR_RAPIDJSON)
Expand Down
6 changes: 3 additions & 3 deletions examples/common/DefaultChargePointEventsHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,15 @@ bool DefaultChargePointEventsHandler::remoteStartTransactionRequested(unsigned i
bool ret = false;
cout << "Remote start transaction : " << connector_id << " - " << id_tag << endl;

if(connector_id > m_config.ocppConfig().numberOfConnectors() || connector_id == 0)
if (connector_id > m_config.ocppConfig().numberOfConnectors() || connector_id == 0)
{
ret=false;
ret = false;
}
else
{
m_remote_start_pending[connector_id - 1u] = true;
m_remote_start_id_tag[connector_id - 1u] = id_tag;
ret=true;
ret = true;
}
return ret;
}
Expand Down
6 changes: 3 additions & 3 deletions examples/common/config/OcppConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ ocpp::types::ConfigurationStatus OcppConfig::setConfiguration(const std::string&
}
}

if (ret != ConfigurationStatus::Rejected)
{
if (ret != ConfigurationStatus::Rejected)
{
if ((it->second & PARAM_OCPP) != 0)
{
m_config.set(OCPP_PARAMS, key, value);
Expand All @@ -225,7 +225,7 @@ ocpp::types::ConfigurationStatus OcppConfig::setConfiguration(const std::string&
{
ret = ConfigurationStatus::Accepted;
}
}
}
}
else
{
Expand Down
22 changes: 14 additions & 8 deletions examples/security_centralsystem/CentralSystemEventsHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ SOFTWARE.
#include "CentralSystemEventsHandler.h"
#include "ChargePointDatabase.h"

#include <array>
#include <iostream>
#include <random>
#include <sstream>
Expand Down Expand Up @@ -99,7 +100,8 @@ bool CentralSystemEventsHandler::checkCredentials(const std::string& chargepoint
{
bool ret = false;

cout << "Check credentials for [" << chargepoint_id << "] : " << password << endl;
std::string hex_encoded_password = ocpp::helpers::toHexString(password);
cout << "Check credentials for [" << chargepoint_id << "] : " << hex_encoded_password << endl;

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

Expand All @@ -111,7 +113,7 @@ bool CentralSystemEventsHandler::checkCredentials(const std::string& chargepoint
{
if ((security_profile == 1u) || (security_profile == 2u))
{
ret = (password == authent_key);
ret = (hex_encoded_password == authent_key);
}
else
{
Expand Down Expand Up @@ -257,14 +259,18 @@ ocpp::types::RegistrationStatus CentralSystemEventsHandler::ChargePointRequestHa
}
else
{
// Generate an authent key for the charge point : minimal 16 bytes, max : 20 bytes
std::stringstream ss_authent_key;
ss_authent_key << std::hex;
for (int i = 0; i < 5; i++)
// Generate an authent key for the charge point : minimal 8 bytes, max : 20 bytes
std::mt19937 rand_gen;
std::uniform_int_distribution<unsigned int> rand_distrib;
std::random_device rd;
rand_gen.seed(rd());

std::array<uint8_t, 17u> authent_key_bytes;
for (auto& val : authent_key_bytes)
{
ss_authent_key << std::setfill('0') << std::setw(4) << std::rand();
val = static_cast<uint8_t>(rand_distrib(rand_gen));
}
m_authent_key = ss_authent_key.str();
m_authent_key = ocpp::helpers::toHexString(authent_key_bytes);

// Add the charge point to the database
m_chargepoint_db.addChargePoint(this->proxy()->identifier(), serial_number, vendor, model, 0, m_authent_key);
Expand Down
10 changes: 6 additions & 4 deletions src/chargepoint/ChargePoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ void ChargePoint::rcpMessageSent(const std::string& msg)
void ChargePoint::configurationValueChanged(const std::string& key)
{
// Check configuration key
if (key == "AuthorizationKey")
if (key == "authorizationkey")
{
// Reconnect with new authorization key
if (m_ocpp_config.securityProfile() != 3)
Expand All @@ -1001,7 +1001,7 @@ void ChargePoint::configurationValueChanged(const std::string& key)

m_security_manager.logSecurityEvent(SECEVT_RECONFIG_SECURITY_PARAMETER, "AuthorizationKey");
}
else if (key == "SecurityProfile")
else if (key == "securityprofile")
{
// Reconnect with new profile
LOG_INFO << "SecurityProfile modified, reconnect with new security profile";
Expand Down Expand Up @@ -1164,8 +1164,10 @@ bool ChargePoint::doConnect()
std::string authorization_key = m_ocpp_config.authorizationKey();
if (!authorization_key.empty() && (security_profile <= 2))
{
credentials.user = m_stack_config.chargePointIdentifier();
credentials.password = authorization_key;
auto authentication_key = ocpp::helpers::fromHexString(authorization_key);
credentials.user = m_stack_config.chargePointIdentifier();
credentials.password = std::string(reinterpret_cast<const char*>(authentication_key.data()), authorization_key.size());
credentials.password.resize(authentication_key.size());
}
if (security_profile != 1)
{
Expand Down
15 changes: 9 additions & 6 deletions src/chargepoint/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ ConfigManager::~ConfigManager() { }
/** @copydoc void registerCheckFunction(const std::string&, ConfigurationValueCheckFunc) */
void ConfigManager::registerCheckFunction(const std::string& key, ConfigurationValueCheckFunc func)
{
m_specific_checks[key] = func;
auto lower_case_key = ocpp::helpers::tolower(key);
m_specific_checks[lower_case_key] = func;
}

/** @copydoc void IConfigManager::registerConfigChangedListener(const std::string&, IConfigChangedListener&) */
void ConfigManager::registerConfigChangedListener(const std::string& key, IConfigChangedListener& listener)
{
m_listeners[key] = &listener;
auto lower_case_key = ocpp::helpers::tolower(key);
m_listeners[lower_case_key] = &listener;
}

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

// Specific check
auto it = m_specific_checks.find(request.key);
auto lower_case_key = ocpp::helpers::tolower(request.key);
auto it = m_specific_checks.find(lower_case_key);
if (it != m_specific_checks.end())
{
response.status = it->second(request.key, request.value);
response.status = it->second(lower_case_key, request.value);
}
if (response.status == ConfigurationStatus::Accepted)
{
Expand All @@ -105,10 +108,10 @@ bool ConfigManager::handleMessage(const ocpp::messages::ChangeConfigurationReq&
if (response.status == ConfigurationStatus::Accepted)
{
// Notify change
auto iter = m_listeners.find(request.key);
auto iter = m_listeners.find(lower_case_key);
if (iter != m_listeners.end())
{
iter->second->configurationValueChanged(request.key);
iter->second->configurationValueChanged(lower_case_key);
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions src/chargepoint/security/SecurityManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,15 +669,16 @@ bool SecurityManager::handleMessage(const ocpp::messages::InstallCertificateReq&
ocpp::types::ConfigurationStatus SecurityManager::checkAuthorizationKeyParameter(const std::string& key, const std::string& value)
{
(void)key;
ConfigurationStatus ret = ConfigurationStatus::Accepted;
ConfigurationStatus ret = ConfigurationStatus::Rejected;

// Authorization key length for security profiles 1 and 2 must be between 32 and 40 bytes
unsigned int security_profile = m_ocpp_config.securityProfile();
if ((security_profile == 1) || (security_profile == 2))
// Authorization key length for security profiles 1 and 2 must be between 16 and 40 bytes
// and must be a valid hexadecimal representation
if ((value.size() >= 16u) && (value.size() <= 40u))
{
if ((value.size() < 32u) || (value.size() > 40u))
auto key_bytes = ocpp::helpers::fromHexString(value);
if (key_bytes.size() == (value.size() / 2u))
{
ret = ConfigurationStatus::Rejected;
ret = ConfigurationStatus::Accepted;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/chargepoint/smartcharging/ProfileDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ std::string ProfileDatabase::serialize(const ocpp::types::ChargingProfile& profi

rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
writer.SetMaxDecimalPlaces(1); // OCPP decimals have 1 digit precision
profile_json.Accept(writer);
profile_str = buffer.GetString();
return profile_str;
Expand Down
2 changes: 1 addition & 1 deletion src/chargepoint/smartcharging/SmartChargingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ bool SmartChargingManager::handleMessage(const ocpp::messages::SetChargingProfil
}
else
{
ret = false;
ret = false;
error_message = "Recurring profiles must have a start schedule and a duration";
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/messages/IMessageConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ class IMessageConverter
json.AddMember(rapidjson::StringRef(name), rapidjson::Value(value), *allocator);
}

/**
* @brief Helper function to fill a floating point value in a JSON object
* @param json JSON object to fill
* @param field Name of the field to fill
* @param value Floating point value to fill
*/
void fill(rapidjson::Value& json, const char* name, const double value)
{
json.AddMember(rapidjson::StringRef(name), rapidjson::Value(value), *allocator);
}

/**
* @brief Helper function to fill a string value in a JSON object
* @param json JSON object to fill
Expand Down
2 changes: 1 addition & 1 deletion src/messages/MessagesValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ along with OpenOCPP. If not, see <http://www.gnu.org/licenses/>.
#ifndef OPENOCPP_MESSAGESVALIDATOR_H
#define OPENOCPP_MESSAGESVALIDATOR_H

#include <JsonValidator.h>
#include "JsonValidator.h"

#include <filesystem>
#include <memory>
Expand Down
Loading

0 comments on commit 78a853e

Please sign in to comment.