Skip to content

Commit 54095e3

Browse files
authored
Merge pull request #181 from c-jimenez/release/v1.4.2
Release/v1.4.2
2 parents a98330d + 0972ba5 commit 54095e3

File tree

12 files changed

+166
-58
lines changed

12 files changed

+166
-58
lines changed

CMakeLists.txt

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

1111
# Definitions for Version.h file

examples/common/DefaultChargePointEventsHandler.cpp

+6-14
Original file line numberDiff line numberDiff line change
@@ -168,24 +168,16 @@ bool DefaultChargePointEventsHandler::remoteStartTransactionRequested(unsigned i
168168
{
169169
bool ret = false;
170170
cout << "Remote start transaction : " << connector_id << " - " << id_tag << endl;
171-
if (connector_id != 0)
171+
172+
if(connector_id > m_config.ocppConfig().numberOfConnectors() || connector_id == 0)
172173
{
173-
m_remote_start_pending[connector_id - 1u] = true;
174-
m_remote_start_id_tag[connector_id - 1u] = id_tag;
175-
ret = true;
174+
ret=false;
176175
}
177176
else
178177
{
179-
for (size_t i = 1; i <= m_config.ocppConfig().numberOfConnectors(); i++)
180-
{
181-
if (m_chargepoint->getConnectorStatus(i) < ChargePointStatus::Charging)
182-
{
183-
m_remote_start_pending[i - 1u] = true;
184-
m_remote_start_id_tag[i - 1u] = id_tag;
185-
ret = true;
186-
break;
187-
}
188-
}
178+
m_remote_start_pending[connector_id - 1u] = true;
179+
m_remote_start_id_tag[connector_id - 1u] = id_tag;
180+
ret=true;
189181
}
190182
return ret;
191183
}

examples/common/config/OcppConfig.cpp

+3-3
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
{

src/chargepoint/reservation/ReservationManager.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ ocpp::types::AuthorizationStatus ReservationManager::isTransactionAllowed(unsign
102102
if (connector)
103103
{
104104
// Check if connector is reserved
105-
if (connector->status == ChargePointStatus::Reserved)
105+
if (!connector->reservation_id_tag.empty())
106106
{
107107
// Check if id tag match
108108
if (id_tag == connector->reservation_id_tag)
@@ -130,7 +130,7 @@ ocpp::types::AuthorizationStatus ReservationManager::isTransactionAllowed(unsign
130130
{
131131
// Check if connector 0 is reserved
132132
Connector& charge_point = m_connectors.getChargePointConnector();
133-
if (charge_point.status == ChargePointStatus::Reserved)
133+
if (!charge_point.reservation_id_tag.empty())
134134
{
135135
// Ensure that the module functions properly even when the gun is inserted first by the user.
136136
if (m_connectors.getConnector(connector_id)->status == ChargePointStatus::Preparing)
@@ -234,6 +234,7 @@ bool ReservationManager::handleMessage(const ocpp::messages::ReserveNowReq& requ
234234
m_status_manager.updateConnectorStatus(connector->id, ChargePointStatus::Reserved);
235235
m_events_handler.reservationStarted(connector->id);
236236
});
237+
237238
break;
238239
}
239240

@@ -293,7 +294,7 @@ bool ReservationManager::handleMessage(const ocpp::messages::CancelReservationRe
293294
response.status = CancelReservationStatus::Rejected;
294295
for (const Connector* connector : m_connectors.getConnectors())
295296
{
296-
if ((connector->status == ChargePointStatus::Reserved) && (connector->reservation_id == request.reservationId))
297+
if ((!connector->reservation_id_tag.empty()) && (connector->reservation_id == request.reservationId))
297298
{
298299
// Cancel reservation
299300
m_worker_pool.run<void>([this, connector_id = connector->id] { endReservation(connector_id, true); });
@@ -316,7 +317,7 @@ void ReservationManager::checkExpiries()
316317
// Check reservations
317318
for (const Connector* connector : m_connectors.getConnectors())
318319
{
319-
if ((connector->status == ChargePointStatus::Reserved) && (connector->reservation_expiry_date <= now))
320+
if ((!connector->reservation_id_tag.empty()) && (connector->reservation_expiry_date <= now))
320321
{
321322
// End reservation
322323
m_worker_pool.run<void>(std::bind(&ReservationManager::endReservation, this, connector->id, false));

src/chargepoint/status/StatusManager.cpp

+14-16
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void StatusManager::updateConnectionStatus(bool is_connected)
113113
}
114114

115115
// Restart heartbeat process
116-
m_heartbeat_timer.start(m_heartbeat_timer.getInterval());
116+
m_heartbeat_timer.start(m_ocpp_config.heartbeatInterval());
117117
}
118118
}
119119
else
@@ -144,24 +144,22 @@ bool StatusManager::updateConnectorStatus(unsigned int conn
144144
Connector* connector = m_connectors.getConnector(connector_id);
145145
if (connector)
146146
{
147+
std::lock_guard<std::mutex> lock(connector->mutex);
148+
147149
// Check if status has changed
148150
if (connector->status != status)
149151
{
150-
{
151-
std::lock_guard<std::mutex> lock(connector->mutex);
152-
153-
// Save new status
154-
connector->status = status;
155-
connector->status_timestamp = DateTime::now();
156-
connector->error_code = error_code;
157-
connector->info = info;
158-
connector->vendor_id = vendor_id;
159-
connector->vendor_error = vendor_error;
160-
m_connectors.saveConnector(connector->id);
161-
}
162-
163152
LOG_INFO << "Connector " << connector_id << " : " << ChargePointStatusHelper.toString(status);
164153

154+
// Save new status
155+
connector->status = status;
156+
connector->status_timestamp = DateTime::now();
157+
connector->error_code = error_code;
158+
connector->info = info;
159+
connector->vendor_id = vendor_id;
160+
connector->vendor_error = vendor_error;
161+
m_connectors.saveConnector(connector->id);
162+
165163
// Check registration status
166164
if (m_registration_status == RegistrationStatus::Accepted)
167165
{
@@ -170,7 +168,7 @@ bool StatusManager::updateConnectorStatus(unsigned int conn
170168
if (duration == std::chrono::seconds(0))
171169
{
172170
// Notify now
173-
statusNotificationProcess(connector_id);
171+
m_worker_pool.run<void>(std::bind(&StatusManager::statusNotificationProcess, this, connector_id));
174172
}
175173
else
176174
{
@@ -197,7 +195,7 @@ void StatusManager::resetHeartBeatTimer()
197195
{
198196
if (m_heartbeat_timer.isStarted())
199197
{
200-
m_heartbeat_timer.restart(m_heartbeat_timer.getInterval());
198+
m_heartbeat_timer.restart(m_ocpp_config.heartbeatInterval());
201199
}
202200
}
203201

src/chargepoint/transaction/TransactionManager.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ ocpp::types::AuthorizationStatus TransactionManager::startTransaction(unsigned i
9898
start_transaction_req.timestamp = DateTime::now();
9999

100100
// Check reservations
101-
if (connector->status == ChargePointStatus::Reserved)
101+
if (!connector->reservation_id_tag.empty())
102102
{
103103
// Fill reservation id
104104
start_transaction_req.reservationId = connector->reservation_id;
@@ -112,7 +112,7 @@ ocpp::types::AuthorizationStatus TransactionManager::startTransaction(unsigned i
112112
if (m_ocpp_config.reserveConnectorZeroSupported())
113113
{
114114
Connector& charge_point = m_connectors.getChargePointConnector();
115-
if (charge_point.status == ChargePointStatus::Reserved)
115+
if (!charge_point.reservation_id_tag.empty())
116116
{
117117
// Check if this transaction can be used for the charge point reservation
118118
if (m_reservation_manager.isTransactionAllowed(Connectors::CONNECTOR_ID_CHARGE_POINT, id_tag) ==

src/tools/x509/Certificate.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ Certificate::Certificate(const Certificate& copy)
8888
m_validity_to(copy.m_validity_to),
8989
m_issuer(copy.m_issuer),
9090
m_issuer_string(copy.m_issuer_string),
91+
m_issuer_der(copy.m_issuer_der),
9192
m_is_self_signed(copy.m_is_self_signed)
9293
{
9394
// Duplicate OpenSSL object

src/websockets/Url.cpp

+52-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ along with OpenOCPP. If not, see <http://www.gnu.org/licenses/>.
1818

1919
#include "Url.h"
2020

21+
#include <iomanip>
2122
#include <regex>
23+
#include <sstream>
2224

2325
namespace ocpp
2426
{
@@ -46,9 +48,9 @@ Url::Url(const std::string& url)
4648

4749
// Convert path
4850
m_path = match[10].str();
49-
if (m_path.empty())
51+
if (!m_path.empty())
5052
{
51-
m_path = "/";
53+
m_path = encode(m_path);
5254
}
5355

5456
// Convert port
@@ -68,11 +70,59 @@ Url::Url(const std::string& url)
6870
m_is_valid = false;
6971
}
7072
}
73+
74+
// Rebuild URL
75+
if (m_is_valid)
76+
{
77+
std::stringstream encoded_url;
78+
encoded_url << m_protocol << "://";
79+
if (!m_username.empty() || !m_password.empty())
80+
{
81+
encoded_url << m_username;
82+
if (!m_password.empty())
83+
{
84+
encoded_url << ":" << m_password;
85+
}
86+
encoded_url << "@";
87+
}
88+
encoded_url << m_address;
89+
if (m_port != 0)
90+
{
91+
encoded_url << ":" << m_port;
92+
}
93+
encoded_url << m_path;
94+
m_url = encoded_url.str();
95+
}
7196
}
7297
}
7398

7499
/** @brief Destructor */
75100
Url::~Url() { }
76101

102+
/** @brief Encode an URL */
103+
std::string Url::encode(const std::string& url) const
104+
{
105+
std::stringstream encoded_url;
106+
encoded_url << std::hex;
107+
108+
for (const auto& c : url)
109+
{
110+
// Safe characters
111+
if (((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')) || ((c >= '0') && (c <= '9')) || (c == '/'))
112+
{
113+
// No encoding
114+
encoded_url << c;
115+
}
116+
else
117+
{
118+
// Percent encoding
119+
encoded_url << '%';
120+
encoded_url << std::setw(2) << std::setfill('0') << static_cast<int>(c);
121+
}
122+
}
123+
124+
return encoded_url.str();
125+
}
126+
77127
} // namespace websockets
78128
} // namespace ocpp

src/websockets/Url.h

+3
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ class Url
113113
unsigned int m_port;
114114
/** @brief Path part of the URL */
115115
std::string m_path;
116+
117+
/** @brief Encode an URL */
118+
std::string encode(const std::string& url) const;
116119
};
117120

118121
} // namespace websockets

src/websockets/libwebsockets/LibWebsocketClient.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ bool LibWebsocketClient::connect(const std::string& url,
9898
info.port = CONTEXT_PORT_NO_LISTEN;
9999
info.protocols = protocols;
100100
info.timeout_secs = static_cast<unsigned int>(std::chrono::duration_cast<std::chrono::seconds>(connect_timeout).count());
101-
info.log_cx = &m_logs_context;
102-
m_credentials = credentials;
101+
info.connect_timeout_secs =
102+
static_cast<unsigned int>(std::chrono::duration_cast<std::chrono::seconds>(connect_timeout).count());
103+
info.log_cx = &m_logs_context;
104+
m_credentials = credentials;
103105
if (m_url.protocol() == "wss")
104106
{
105107
if (!m_credentials.tls12_cipher_list.empty())
@@ -505,6 +507,12 @@ int LibWebsocketClient::eventCallback(struct lws* wsi, enum lws_callback_reasons
505507
{
506508
retry = true;
507509
}
510+
511+
SendMsg* msg;
512+
while (client->m_send_msgs.pop(msg, 0))
513+
{
514+
delete msg;
515+
}
508516
break;
509517

510518
default:

src/websockets/libwebsockets/LibWebsocketClientPool.cpp

+13-6
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void LibWebsocketClientPool::process()
144144

145145
// Dummy vhost to handle context related events
146146
struct lws_protocols protocols[] = {{"LibWebsocketClientPool", &LibWebsocketClientPool::eventCallback, 0, 0, 0, this, 0},
147-
LWS_PROTOCOL_LIST_TERM};
147+
LWS_PROTOCOL_LIST_TERM};
148148
struct lws_context_creation_info vhost_info;
149149
memset(&vhost_info, 0, sizeof(vhost_info));
150150
vhost_info.protocols = protocols;
@@ -443,11 +443,12 @@ void LibWebsocketClientPool::Client::connectCallback(struct lws_sorted_usec_list
443443
// Fill vhost information
444444
struct lws_context_creation_info vhost_info;
445445
memset(&vhost_info, 0, sizeof(vhost_info));
446-
vhost_info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
447-
vhost_info.port = CONTEXT_PORT_NO_LISTEN;
448-
vhost_info.timeout_secs = client->m_connect_timeout;
449-
vhost_info.protocols = protocols;
450-
vhost_info.log_cx = &pool->m_logs_context;
446+
vhost_info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
447+
vhost_info.port = CONTEXT_PORT_NO_LISTEN;
448+
vhost_info.timeout_secs = client->m_connect_timeout;
449+
vhost_info.connect_timeout_secs = client->m_connect_timeout;
450+
vhost_info.protocols = protocols;
451+
vhost_info.log_cx = &pool->m_logs_context;
451452
if (client->m_url.protocol() == "wss")
452453
{
453454
if (!client->m_credentials.tls12_cipher_list.empty())
@@ -686,6 +687,12 @@ int LibWebsocketClientPool::Client::eventCallback(
686687
{
687688
retry = true;
688689
}
690+
691+
SendMsg* msg;
692+
while (client->m_send_msgs.pop(msg, 0))
693+
{
694+
delete msg;
695+
}
689696
break;
690697

691698
default:

0 commit comments

Comments
 (0)