Skip to content
Merged
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
33 changes: 18 additions & 15 deletions 3rdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,22 @@ target_include_directories(doctest INTERFACE doctest/doctest)
# SQLite 3
add_subdirectory(sqlite3)

# Use default flags for the libwebsockets library
if (NOT MSVC)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG_INIT} -O0 -g3 -ggdb3")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG_INIT} -O0 -g3 -ggdb3")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE_INIT} -O2 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE_INIT} -O2 -DNDEBUG")
else()
set(DISABLED_WARNING_LWS "/WX- /wd4191 /wd4996")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG_INIT} ${DISABLED_WARNING_LWS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG_INIT} ${DISABLED_WARNING_LWS}")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE_INIT} ${DISABLED_WARNING_LWS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE_INIT} ${DISABLED_WARNING_LWS}")
endif()
# libwebsockets
if(${BUILD_LWS_LIBRARY})
# Use default flags for the libwebsockets library
if (NOT MSVC)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG_INIT} -O0 -g3 -ggdb3")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG_INIT} -O0 -g3 -ggdb3")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE_INIT} -O2 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE_INIT} -O2 -DNDEBUG")
else()
set(DISABLED_WARNING_LWS "/WX- /wd4191 /wd4996")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG_INIT} ${DISABLED_WARNING_LWS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG_INIT} ${DISABLED_WARNING_LWS}")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE_INIT} ${DISABLED_WARNING_LWS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE_INIT} ${DISABLED_WARNING_LWS}")
endif()

set(LWS_WITH_NETLINK OFF)
add_subdirectory(libwebsockets)
set(LWS_WITH_NETLINK OFF)
add_subdirectory(libwebsockets)
endif()
8 changes: 7 additions & 1 deletion 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.0
VERSION 1.4.1
)

# Definitions for Version.h file
Expand Down Expand Up @@ -35,6 +35,12 @@ add_subdirectory(3rdparty)
# OpenSSL is mandatory
find_package(OpenSSL REQUIRED COMPONENTS SSL Crypto)

# libwesockets is mandatory if not built along the Open OCPP library
if(NOT ${BUILD_LWS_LIBRARY})
find_package(PkgConfig)
pkg_check_modules(LIB_WEBSOCKETS REQUIRED libwebsockets)
endif()

# Tests
if(${BUILD_UNIT_TESTS})
enable_testing()
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists_Options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ option(BUILD_UNIT_TESTS "Build unit tests" ON)

# Examples
option(BUILD_EXAMPLES "Build examples" ON)

# Build the libwebsocket library along with the Open OCPP library
option(BUILD_LWS_LIBRARY "Build libwebsocket library" ON)
38 changes: 32 additions & 6 deletions examples/common/DefaultCentralSystemEventsHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ using namespace ocpp::x509;
DefaultCentralSystemEventsHandler::DefaultCentralSystemEventsHandler(std::filesystem::path iso_v2g_root_ca,
std::filesystem::path iso_mo_root_ca,
bool set_pending_status)
: m_iso_v2g_root_ca(iso_v2g_root_ca),
: m_chargepoints_mutex(),
m_iso_v2g_root_ca(iso_v2g_root_ca),
m_iso_mo_root_ca(iso_mo_root_ca),
m_set_pending_status(set_pending_status),
m_chargepoints(),
Expand Down Expand Up @@ -83,6 +84,9 @@ bool DefaultCentralSystemEventsHandler::checkCredentials(const std::string& char
void DefaultCentralSystemEventsHandler::chargePointConnected(std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint> chargepoint)
{
cout << "Charge point [" << chargepoint->identifier() << "] connected" << endl;

std::lock_guard<std::mutex> lock(m_chargepoints_mutex);

auto iter_chargepoint = m_chargepoints.find(chargepoint->identifier());
if (iter_chargepoint == m_chargepoints.end())
{
Expand All @@ -103,13 +107,38 @@ void DefaultCentralSystemEventsHandler::removeChargePoint(const std::string& ide
[this, identifier = identifier]
{
std::this_thread::sleep_for(std::chrono::milliseconds(50));

std::lock_guard<std::mutex> lock(m_chargepoints_mutex);
m_chargepoints.erase(identifier);
m_pending_chargepoints.erase(identifier);
m_accepted_chargepoints.erase(identifier);
});
t.detach();
}

/** @brief Indicate if a charge point must be accepted */
bool DefaultCentralSystemEventsHandler::isAcceptedChargePoint(const std::string& identifier)
{
std::lock_guard<std::mutex> lock(m_chargepoints_mutex);
return (m_accepted_chargepoints.find(identifier) != m_accepted_chargepoints.end());
}

/** @brief Add a charge point to the pending list */
void DefaultCentralSystemEventsHandler::addPendingChargePoint(
std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint> chargepoint)
{
std::lock_guard<std::mutex> lock(m_chargepoints_mutex);
m_pending_chargepoints[chargepoint->identifier()] = chargepoint;
}

/** @brief Add a charge point to the accepted list */
void DefaultCentralSystemEventsHandler::addAcceptedChargePoint(
std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint> chargepoint)
{
std::lock_guard<std::mutex> lock(m_chargepoints_mutex);
m_accepted_chargepoints[chargepoint->identifier()] = chargepoint;
}

/** @brief Constructor */
DefaultCentralSystemEventsHandler::ChargePointRequestHandler::ChargePointRequestHandler(
DefaultCentralSystemEventsHandler& event_handler, std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint>& chargepoint)
Expand Down Expand Up @@ -170,12 +199,9 @@ ocpp::types::RegistrationStatus DefaultCentralSystemEventsHandler::ChargePointRe
ocpp::types::RegistrationStatus ret = RegistrationStatus::Accepted;
if (m_event_handler.setPendingEnabled())
{
auto accepted_chargepoint = m_event_handler.acceptedChargePoints();
auto iter_accepted = accepted_chargepoint.find(m_chargepoint->identifier());
if (iter_accepted == accepted_chargepoint.end())
if (!m_event_handler.isAcceptedChargePoint(m_chargepoint->identifier()))
{
m_event_handler.pendingChargePoints()[m_chargepoint->identifier()] = m_chargepoint;

m_event_handler.addPendingChargePoint(m_chargepoint);
ret = RegistrationStatus::Pending;
}
}
Expand Down
34 changes: 26 additions & 8 deletions examples/common/DefaultCentralSystemEventsHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ SOFTWARE.

#include <filesystem>
#include <map>
#include <mutex>

/** @brief Default central system event handlers implementation for the examples */
class DefaultCentralSystemEventsHandler : public ocpp::centralsystem::ICentralSystemEventsHandler
Expand Down Expand Up @@ -237,19 +238,25 @@ class DefaultCentralSystemEventsHandler : public ocpp::centralsystem::ICentralSy
std::string m_generated_certificate;
};

/** @brief Get the list of the connected charge points */
std::map<std::string, std::shared_ptr<ChargePointRequestHandler>>& chargePoints() { return m_chargepoints; }
/** @brief Get the number connected charge points */
size_t chargePointsCount()
{
std::lock_guard<std::mutex> lock(m_chargepoints_mutex);
return m_chargepoints.size();
}

/** @brief Get the list of the pending charge points */
std::map<std::string, std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint>>& pendingChargePoints()
/** @brief Get the list of the connected charge points */
std::map<std::string, std::shared_ptr<ChargePointRequestHandler>> chargePoints()
{
return m_pending_chargepoints;
std::lock_guard<std::mutex> lock(m_chargepoints_mutex);
return m_chargepoints;
}

/** @brief Get the list of the accepted charge points */
std::map<std::string, std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint>>& acceptedChargePoints()
/** @brief Get the list of the pending charge points */
std::map<std::string, std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint>> pendingChargePoints()
{
return m_accepted_chargepoints;
std::lock_guard<std::mutex> lock(m_chargepoints_mutex);
return m_pending_chargepoints;
}

/** @brief Path to the V2G root CA */
Expand All @@ -263,7 +270,18 @@ class DefaultCentralSystemEventsHandler : public ocpp::centralsystem::ICentralSy
/** @brief Remove a charge point from the connected charge points */
void removeChargePoint(const std::string& identifier);

/** @brief Indicate if a charge point must be accepted */
bool isAcceptedChargePoint(const std::string& identifier);

/** @brief Add a charge point to the pending list */
void addPendingChargePoint(std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint> chargepoint);

/** @brief Add a charge point to the accepted list */
void addAcceptedChargePoint(std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint> chargepoint);

protected:
/** @brief Mutex for charge point list */
std::mutex m_chargepoints_mutex;
/** @brief Path to the V2G root CA */
std::filesystem::path m_iso_v2g_root_ca;
/** @brief Path to the MO root CA */
Expand Down
10 changes: 5 additions & 5 deletions examples/iso15118_centralsystem/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ int main(int argc, char* argv[])
while (true)
{
// For each pending charge point
for (auto& iter_chargepoint : event_handler.pendingChargePoints())
auto pending_chargepoints = event_handler.pendingChargePoints();
for (auto& iter_chargepoint : pending_chargepoints)
{
auto chargepoint = iter_chargepoint.second;
auto iter_accepted = event_handler.acceptedChargePoints().find(chargepoint->identifier());
if (iter_accepted == event_handler.acceptedChargePoints().end())
auto chargepoint = iter_chargepoint.second;
if (!event_handler.isAcceptedChargePoint(chargepoint->identifier()))
{
std::cout << "---------------------------------------------" << std::endl;
std::cout << "Pending Charge point : " << chargepoint->identifier() << std::endl;
Expand Down Expand Up @@ -239,7 +239,7 @@ int main(int argc, char* argv[])
}

// Accept charge point
event_handler.acceptedChargePoints()[chargepoint->identifier()] = chargepoint;
event_handler.addAcceptedChargePoint(chargepoint);

// Trigger a boot notification to force it to update its registration status
chargepoint->triggerMessage(MessageTrigger::BootNotification, Optional<unsigned int>());
Expand Down
3 changes: 2 additions & 1 deletion examples/quick_start_centralsystem/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ int main(int argc, char* argv[])
std::this_thread::sleep_for(std::chrono::seconds(1));

// For each connected charge point
for (auto& iter_chargepoint : event_handler.chargePoints())
auto connected_chargepoints = event_handler.chargePoints();
for (auto& iter_chargepoint : connected_chargepoints)
{
{
auto chargepoint = iter_chargepoint.second->proxy();
Expand Down
2 changes: 1 addition & 1 deletion src/chargepoint/reservation/ReservationManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ bool ReservationManager::handleMessage(const ocpp::messages::CancelReservationRe
if ((connector->status == ChargePointStatus::Reserved) && (connector->reservation_id == request.reservationId))
{
// Cancel reservation
m_worker_pool.run<void>([this, &connector] { endReservation(connector->id, true); });
m_worker_pool.run<void>([this, connector_id = connector->id] { endReservation(connector_id, true); });

// Prepare response
response.status = CancelReservationStatus::Accepted;
Expand Down
8 changes: 7 additions & 1 deletion src/chargepoint/transaction/TransactionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ bool TransactionManager::handleMessage(const ocpp::messages::RemoteStartTransact
}
}
}
else
else if (!request.connectorId.isSet())
{
// The user application will determine which connector to use
authorized = m_events_handler.remoteStartTransactionRequested(Connectors::CONNECTOR_ID_CHARGE_POINT, request.idTag.str());
Expand All @@ -309,6 +309,12 @@ bool TransactionManager::handleMessage(const ocpp::messages::RemoteStartTransact
authorized = m_smart_charging_manager.installTxProfile(Connectors::CONNECTOR_ID_CHARGE_POINT, request.chargingProfile);
}
}
else
{
// Connector id is set but equal to CONNECTOR_ID_CHARGE_POINT
// This is not allowed by the ocpp1.6 standard
authorized = false;
}

// Response
if (authorized)
Expand Down