Skip to content

Commit a98330d

Browse files
authored
Merge pull request #167 from c-jimenez/release/v1.4.1
Release/v1.4.1
2 parents 61bbd45 + 62c8a06 commit a98330d

File tree

9 files changed

+101
-38
lines changed

9 files changed

+101
-38
lines changed

3rdparty/CMakeLists.txt

+18-15
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,22 @@ target_include_directories(doctest INTERFACE doctest/doctest)
1414
# SQLite 3
1515
add_subdirectory(sqlite3)
1616

17-
# Use default flags for the libwebsockets library
18-
if (NOT MSVC)
19-
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG_INIT} -O0 -g3 -ggdb3")
20-
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG_INIT} -O0 -g3 -ggdb3")
21-
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE_INIT} -O2 -DNDEBUG")
22-
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE_INIT} -O2 -DNDEBUG")
23-
else()
24-
set(DISABLED_WARNING_LWS "/WX- /wd4191 /wd4996")
25-
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG_INIT} ${DISABLED_WARNING_LWS}")
26-
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG_INIT} ${DISABLED_WARNING_LWS}")
27-
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE_INIT} ${DISABLED_WARNING_LWS}")
28-
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE_INIT} ${DISABLED_WARNING_LWS}")
29-
endif()
17+
# libwebsockets
18+
if(${BUILD_LWS_LIBRARY})
19+
# Use default flags for the libwebsockets library
20+
if (NOT MSVC)
21+
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG_INIT} -O0 -g3 -ggdb3")
22+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG_INIT} -O0 -g3 -ggdb3")
23+
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE_INIT} -O2 -DNDEBUG")
24+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE_INIT} -O2 -DNDEBUG")
25+
else()
26+
set(DISABLED_WARNING_LWS "/WX- /wd4191 /wd4996")
27+
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG_INIT} ${DISABLED_WARNING_LWS}")
28+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG_INIT} ${DISABLED_WARNING_LWS}")
29+
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE_INIT} ${DISABLED_WARNING_LWS}")
30+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE_INIT} ${DISABLED_WARNING_LWS}")
31+
endif()
3032

31-
set(LWS_WITH_NETLINK OFF)
32-
add_subdirectory(libwebsockets)
33+
set(LWS_WITH_NETLINK OFF)
34+
add_subdirectory(libwebsockets)
35+
endif()

CMakeLists.txt

+7-1
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.0
8+
VERSION 1.4.1
99
)
1010

1111
# Definitions for Version.h file
@@ -35,6 +35,12 @@ add_subdirectory(3rdparty)
3535
# OpenSSL is mandatory
3636
find_package(OpenSSL REQUIRED COMPONENTS SSL Crypto)
3737

38+
# libwesockets is mandatory if not built along the Open OCPP library
39+
if(NOT ${BUILD_LWS_LIBRARY})
40+
find_package(PkgConfig)
41+
pkg_check_modules(LIB_WEBSOCKETS REQUIRED libwebsockets)
42+
endif()
43+
3844
# Tests
3945
if(${BUILD_UNIT_TESTS})
4046
enable_testing()

CMakeLists_Options.txt

+3
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ option(BUILD_UNIT_TESTS "Build unit tests" ON)
2222

2323
# Examples
2424
option(BUILD_EXAMPLES "Build examples" ON)
25+
26+
# Build the libwebsocket library along with the Open OCPP library
27+
option(BUILD_LWS_LIBRARY "Build libwebsocket library" ON)

examples/common/DefaultCentralSystemEventsHandler.cpp

+32-6
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ using namespace ocpp::x509;
4545
DefaultCentralSystemEventsHandler::DefaultCentralSystemEventsHandler(std::filesystem::path iso_v2g_root_ca,
4646
std::filesystem::path iso_mo_root_ca,
4747
bool set_pending_status)
48-
: m_iso_v2g_root_ca(iso_v2g_root_ca),
48+
: m_chargepoints_mutex(),
49+
m_iso_v2g_root_ca(iso_v2g_root_ca),
4950
m_iso_mo_root_ca(iso_mo_root_ca),
5051
m_set_pending_status(set_pending_status),
5152
m_chargepoints(),
@@ -83,6 +84,9 @@ bool DefaultCentralSystemEventsHandler::checkCredentials(const std::string& char
8384
void DefaultCentralSystemEventsHandler::chargePointConnected(std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint> chargepoint)
8485
{
8586
cout << "Charge point [" << chargepoint->identifier() << "] connected" << endl;
87+
88+
std::lock_guard<std::mutex> lock(m_chargepoints_mutex);
89+
8690
auto iter_chargepoint = m_chargepoints.find(chargepoint->identifier());
8791
if (iter_chargepoint == m_chargepoints.end())
8892
{
@@ -103,13 +107,38 @@ void DefaultCentralSystemEventsHandler::removeChargePoint(const std::string& ide
103107
[this, identifier = identifier]
104108
{
105109
std::this_thread::sleep_for(std::chrono::milliseconds(50));
110+
111+
std::lock_guard<std::mutex> lock(m_chargepoints_mutex);
106112
m_chargepoints.erase(identifier);
107113
m_pending_chargepoints.erase(identifier);
108114
m_accepted_chargepoints.erase(identifier);
109115
});
110116
t.detach();
111117
}
112118

119+
/** @brief Indicate if a charge point must be accepted */
120+
bool DefaultCentralSystemEventsHandler::isAcceptedChargePoint(const std::string& identifier)
121+
{
122+
std::lock_guard<std::mutex> lock(m_chargepoints_mutex);
123+
return (m_accepted_chargepoints.find(identifier) != m_accepted_chargepoints.end());
124+
}
125+
126+
/** @brief Add a charge point to the pending list */
127+
void DefaultCentralSystemEventsHandler::addPendingChargePoint(
128+
std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint> chargepoint)
129+
{
130+
std::lock_guard<std::mutex> lock(m_chargepoints_mutex);
131+
m_pending_chargepoints[chargepoint->identifier()] = chargepoint;
132+
}
133+
134+
/** @brief Add a charge point to the accepted list */
135+
void DefaultCentralSystemEventsHandler::addAcceptedChargePoint(
136+
std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint> chargepoint)
137+
{
138+
std::lock_guard<std::mutex> lock(m_chargepoints_mutex);
139+
m_accepted_chargepoints[chargepoint->identifier()] = chargepoint;
140+
}
141+
113142
/** @brief Constructor */
114143
DefaultCentralSystemEventsHandler::ChargePointRequestHandler::ChargePointRequestHandler(
115144
DefaultCentralSystemEventsHandler& event_handler, std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint>& chargepoint)
@@ -170,12 +199,9 @@ ocpp::types::RegistrationStatus DefaultCentralSystemEventsHandler::ChargePointRe
170199
ocpp::types::RegistrationStatus ret = RegistrationStatus::Accepted;
171200
if (m_event_handler.setPendingEnabled())
172201
{
173-
auto accepted_chargepoint = m_event_handler.acceptedChargePoints();
174-
auto iter_accepted = accepted_chargepoint.find(m_chargepoint->identifier());
175-
if (iter_accepted == accepted_chargepoint.end())
202+
if (!m_event_handler.isAcceptedChargePoint(m_chargepoint->identifier()))
176203
{
177-
m_event_handler.pendingChargePoints()[m_chargepoint->identifier()] = m_chargepoint;
178-
204+
m_event_handler.addPendingChargePoint(m_chargepoint);
179205
ret = RegistrationStatus::Pending;
180206
}
181207
}

examples/common/DefaultCentralSystemEventsHandler.h

+26-8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ SOFTWARE.
3030

3131
#include <filesystem>
3232
#include <map>
33+
#include <mutex>
3334

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

240-
/** @brief Get the list of the connected charge points */
241-
std::map<std::string, std::shared_ptr<ChargePointRequestHandler>>& chargePoints() { return m_chargepoints; }
241+
/** @brief Get the number connected charge points */
242+
size_t chargePointsCount()
243+
{
244+
std::lock_guard<std::mutex> lock(m_chargepoints_mutex);
245+
return m_chargepoints.size();
246+
}
242247

243-
/** @brief Get the list of the pending charge points */
244-
std::map<std::string, std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint>>& pendingChargePoints()
248+
/** @brief Get the list of the connected charge points */
249+
std::map<std::string, std::shared_ptr<ChargePointRequestHandler>> chargePoints()
245250
{
246-
return m_pending_chargepoints;
251+
std::lock_guard<std::mutex> lock(m_chargepoints_mutex);
252+
return m_chargepoints;
247253
}
248254

249-
/** @brief Get the list of the accepted charge points */
250-
std::map<std::string, std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint>>& acceptedChargePoints()
255+
/** @brief Get the list of the pending charge points */
256+
std::map<std::string, std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint>> pendingChargePoints()
251257
{
252-
return m_accepted_chargepoints;
258+
std::lock_guard<std::mutex> lock(m_chargepoints_mutex);
259+
return m_pending_chargepoints;
253260
}
254261

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

273+
/** @brief Indicate if a charge point must be accepted */
274+
bool isAcceptedChargePoint(const std::string& identifier);
275+
276+
/** @brief Add a charge point to the pending list */
277+
void addPendingChargePoint(std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint> chargepoint);
278+
279+
/** @brief Add a charge point to the accepted list */
280+
void addAcceptedChargePoint(std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint> chargepoint);
281+
266282
protected:
283+
/** @brief Mutex for charge point list */
284+
std::mutex m_chargepoints_mutex;
267285
/** @brief Path to the V2G root CA */
268286
std::filesystem::path m_iso_v2g_root_ca;
269287
/** @brief Path to the MO root CA */

examples/iso15118_centralsystem/main.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,11 @@ int main(int argc, char* argv[])
148148
while (true)
149149
{
150150
// For each pending charge point
151-
for (auto& iter_chargepoint : event_handler.pendingChargePoints())
151+
auto pending_chargepoints = event_handler.pendingChargePoints();
152+
for (auto& iter_chargepoint : pending_chargepoints)
152153
{
153-
auto chargepoint = iter_chargepoint.second;
154-
auto iter_accepted = event_handler.acceptedChargePoints().find(chargepoint->identifier());
155-
if (iter_accepted == event_handler.acceptedChargePoints().end())
154+
auto chargepoint = iter_chargepoint.second;
155+
if (!event_handler.isAcceptedChargePoint(chargepoint->identifier()))
156156
{
157157
std::cout << "---------------------------------------------" << std::endl;
158158
std::cout << "Pending Charge point : " << chargepoint->identifier() << std::endl;
@@ -239,7 +239,7 @@ int main(int argc, char* argv[])
239239
}
240240

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

244244
// Trigger a boot notification to force it to update its registration status
245245
chargepoint->triggerMessage(MessageTrigger::BootNotification, Optional<unsigned int>());

examples/quick_start_centralsystem/main.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ int main(int argc, char* argv[])
118118
std::this_thread::sleep_for(std::chrono::seconds(1));
119119

120120
// For each connected charge point
121-
for (auto& iter_chargepoint : event_handler.chargePoints())
121+
auto connected_chargepoints = event_handler.chargePoints();
122+
for (auto& iter_chargepoint : connected_chargepoints)
122123
{
123124
{
124125
auto chargepoint = iter_chargepoint.second->proxy();

src/chargepoint/reservation/ReservationManager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ bool ReservationManager::handleMessage(const ocpp::messages::CancelReservationRe
296296
if ((connector->status == ChargePointStatus::Reserved) && (connector->reservation_id == request.reservationId))
297297
{
298298
// Cancel reservation
299-
m_worker_pool.run<void>([this, &connector] { endReservation(connector->id, true); });
299+
m_worker_pool.run<void>([this, connector_id = connector->id] { endReservation(connector_id, true); });
300300

301301
// Prepare response
302302
response.status = CancelReservationStatus::Accepted;

src/chargepoint/transaction/TransactionManager.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ bool TransactionManager::handleMessage(const ocpp::messages::RemoteStartTransact
299299
}
300300
}
301301
}
302-
else
302+
else if (!request.connectorId.isSet())
303303
{
304304
// The user application will determine which connector to use
305305
authorized = m_events_handler.remoteStartTransactionRequested(Connectors::CONNECTOR_ID_CHARGE_POINT, request.idTag.str());
@@ -309,6 +309,12 @@ bool TransactionManager::handleMessage(const ocpp::messages::RemoteStartTransact
309309
authorized = m_smart_charging_manager.installTxProfile(Connectors::CONNECTOR_ID_CHARGE_POINT, request.chargingProfile);
310310
}
311311
}
312+
else
313+
{
314+
// Connector id is set but equal to CONNECTOR_ID_CHARGE_POINT
315+
// This is not allowed by the ocpp1.6 standard
316+
authorized = false;
317+
}
312318

313319
// Response
314320
if (authorized)

0 commit comments

Comments
 (0)