Skip to content

Commit 6b6dc93

Browse files
authored
Merge pull request #17 from c-jimenez/dev/rpc_server
Dev/rpc server
2 parents 0035623 + 74c9606 commit 6b6dc93

File tree

74 files changed

+2078
-717
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+2078
-717
lines changed

.github/release.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# .github/release.yml
2+
3+
changelog:
4+
exclude:
5+
labels:
6+
- duplicate
7+
categories:
8+
- title: New Features 🎉
9+
labels:
10+
- enhancement
11+
- title: Bug fixes 🛠
12+
labels:
13+
- bug
14+
- title: Other Changes
15+
labels:
16+
- "*"

src/chargepoint/ChargePoint.cpp

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ along with OpenOCPP. If not, see <http://www.gnu.org/licenses/>.
2727
#include "MessageDispatcher.h"
2828
#include "MeterValuesManager.h"
2929
#include "ReservationManager.h"
30-
#include "RpcClient.h"
3130
#include "SmartChargingManager.h"
3231
#include "StatusManager.h"
3332
#include "TransactionManager.h"
@@ -106,6 +105,9 @@ ChargePoint::ChargePoint(const ocpp::config::IChargePointConfig& stack_config,
106105

107106
// Uptime timer
108107
m_uptime_timer.setCallback(std::bind(&ChargePoint::processUptime, this));
108+
109+
// Random numbers
110+
std::srand(time(nullptr));
109111
}
110112

111113
/** @brief Destructor */
@@ -200,11 +202,13 @@ bool ChargePoint::start()
200202

201203
// Allocate resources
202204
m_ws_client = std::unique_ptr<ocpp::websockets::IWebsocketClient>(ocpp::websockets::WebsocketFactory::newClient());
203-
m_rpc_client = std::make_unique<ocpp::rpc::RpcClient>(*m_ws_client, "ocpp1.6", std::rand());
205+
m_rpc_client = std::make_unique<ocpp::rpc::RpcClient>(*m_ws_client, "ocpp1.6");
204206
m_rpc_client->registerListener(*this);
207+
m_rpc_client->registerClientListener(*this);
205208
m_rpc_client->registerSpy(*this);
206209
m_msg_dispatcher = std::make_unique<ocpp::messages::MessageDispatcher>(m_stack_config.jsonSchemasPath());
207-
m_msg_sender = std::make_unique<ocpp::messages::GenericMessageSender>(m_stack_config, *m_rpc_client, m_messages_converter);
210+
m_msg_sender = std::make_unique<ocpp::messages::GenericMessageSender>(
211+
*m_rpc_client, m_messages_converter, m_stack_config.callRequestTimeout());
208212

209213
m_config_manager = std::make_unique<ConfigManager>(m_ocpp_config, m_messages_converter, *m_msg_dispatcher);
210214
m_trigger_manager = std::make_unique<TriggerMessageManager>(m_connectors, m_messages_converter, *m_msg_dispatcher);
@@ -571,7 +575,7 @@ bool ChargePoint::notifyFirmwareUpdateStatus(bool success)
571575
return ret;
572576
}
573577

574-
/** @copydoc void IRpcClientListener::rpcClientConnected() */
578+
/** @copydoc void RpcClient::IListener::rpcClientConnected() */
575579
void ChargePoint::rpcClientConnected()
576580
{
577581
LOG_INFO << "Connected to Central System";
@@ -580,7 +584,7 @@ void ChargePoint::rpcClientConnected()
580584
m_events_handler.connectionStateChanged(true);
581585
}
582586

583-
/** @copydoc void IRpcClientListener::rpcClientFailed() */
587+
/** @copydoc void RpcClient::IListener::rpcClientFailed() */
584588
void ChargePoint::rpcClientFailed()
585589
{
586590
LOG_ERROR << "Connection failed with Central System";
@@ -600,44 +604,44 @@ void ChargePoint::rpcClientFailed()
600604
m_events_handler.connectionFailed(last_status);
601605
}
602606

603-
/** @copydoc void IRpcClientListener::rpcClientDisconnected() */
604-
void ChargePoint::rpcClientDisconnected()
607+
/** @copydoc void IRpc::IListener::rpcDisconnected() */
608+
void ChargePoint::rpcDisconnected()
605609
{
606610
LOG_ERROR << "Connection lost with Central System";
607611
m_status_manager->updateConnectionStatus(false);
608612
m_transaction_manager->updateConnectionStatus(false);
609613
m_events_handler.connectionStateChanged(false);
610614
}
611615

612-
/** @copydoc void IRpcClientListener::rpcClientError() */
613-
void ChargePoint::rpcClientError()
616+
/** @copydoc void IRpc::IListener::rpcError() */
617+
void ChargePoint::rpcError()
614618
{
615619
LOG_ERROR << "Connection error with Central System";
616620
m_events_handler.connectionStateChanged(false);
617621
}
618622

619-
/** @copydoc void IRpcClientListener::rpcClientCallReceived(const std::string&,
620-
const rapidjson::Value&,
621-
rapidjson::Document&,
622-
const char*&,
623-
std::string&) */
624-
bool ChargePoint::rpcClientCallReceived(const std::string& action,
625-
const rapidjson::Value& payload,
626-
rapidjson::Document& response,
627-
const char*& error_code,
628-
std::string& error_message)
623+
/** @copydoc void IRpc::IListener::rpcCallReceived(const std::string&,
624+
const rapidjson::Value&,
625+
rapidjson::Document&,
626+
const char*&,
627+
std::string&) */
628+
bool ChargePoint::rpcCallReceived(const std::string& action,
629+
const rapidjson::Value& payload,
630+
rapidjson::Document& response,
631+
const char*& error_code,
632+
std::string& error_message)
629633
{
630634
return m_msg_dispatcher->dispatchMessage(action, payload, response, error_code, error_message);
631635
}
632636

633-
/** @copydoc void IRpcClientSpy::rcpClientMessageReceived(const std::string&) */
634-
void ChargePoint::rcpClientMessageReceived(const std::string& msg)
637+
/** @copydoc void IRpc::ISpy::rcpMessageReceived(const std::string&) */
638+
void ChargePoint::rcpMessageReceived(const std::string& msg)
635639
{
636640
LOG_COM << "RX : " << msg;
637641
}
638642

639-
/** @copydoc void IRpcClientSpy::rcpClientMessageSent(const std::string&) */
640-
void ChargePoint::rcpClientMessageSent(const std::string& msg)
643+
/** @copydoc void IRpc::ISpy::rcpMessageSent(const std::string&) */
644+
void ChargePoint::rcpMessageSent(const std::string& msg)
641645
{
642646
m_status_manager->resetHeartBeatTimer();
643647
LOG_COM << "TX : " << msg;

src/chargepoint/ChargePoint.h

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ along with OpenOCPP. If not, see <http://www.gnu.org/licenses/>.
2323
#include "Database.h"
2424
#include "IChargePoint.h"
2525
#include "IConfigManager.h"
26-
#include "IRpcClient.h"
2726
#include "InternalConfigManager.h"
2827
#include "MessagesConverter.h"
28+
#include "RpcClient.h"
2929
#include "Timer.h"
3030
#include "TimerPool.h"
3131
#include "WorkerThreadPool.h"
@@ -62,8 +62,9 @@ class MaintenanceManager;
6262

6363
/** @brief Charge point implementation */
6464
class ChargePoint : public IChargePoint,
65-
public ocpp::rpc::IRpcClient::IRpcClientListener,
66-
public ocpp::rpc::IRpcClient::IRpcClientSpy,
65+
public ocpp::rpc::IRpc::IListener,
66+
public ocpp::rpc::IRpc::ISpy,
67+
public ocpp::rpc::RpcClient::IListener,
6768
public IConfigManager::IConfigChangedListener
6869
{
6970
public:
@@ -146,38 +147,40 @@ class ChargePoint : public IChargePoint,
146147
/** @copydoc bool IChargePoint::notifyFirmwareUpdateStatus(bool) */
147148
bool notifyFirmwareUpdateStatus(bool success) override;
148149

149-
// IRpcClientListener interface
150+
// RpcClient::IListener interface
150151

151-
/** @copydoc void IRpcClientListener::rpcClientConnected() */
152+
/** @copydoc void RpcClient::IListener::rpcClientConnected() */
152153
void rpcClientConnected() override;
153154

154-
/** @copydoc void IRpcClientListener::rpcClientFailed() */
155+
/** @copydoc void RpcClient::IListener::rpcClientFailed() */
155156
void rpcClientFailed() override;
156157

157-
/** @copydoc void IRpcClientListener::rpcClientDisconnected() */
158-
void rpcClientDisconnected() override;
158+
// IRpc::IListener interface
159159

160-
/** @copydoc void IRpcClientListener::rpcClientError() */
161-
void rpcClientError() override;
160+
/** @copydoc void IRpc::IListener::rpcDisconnected() */
161+
void rpcDisconnected() override;
162162

163-
/** @copydoc void IRpcClientListener::rpcClientCallReceived(const std::string&,
164-
const rapidjson::Value&,
165-
rapidjson::Document&,
166-
const char*&,
167-
std::string&) */
168-
bool rpcClientCallReceived(const std::string& action,
169-
const rapidjson::Value& payload,
170-
rapidjson::Document& response,
171-
const char*& error_code,
172-
std::string& error_message) override;
163+
/** @copydoc void IRpc::IListener::rpcError() */
164+
void rpcError() override;
173165

174-
/// IRpcClientSpy interface
166+
/** @copydoc void IRpc::IListener::rpcCallReceived(const std::string&,
167+
const rapidjson::Value&,
168+
rapidjson::Document&,
169+
const char*&,
170+
std::string&) */
171+
bool rpcCallReceived(const std::string& action,
172+
const rapidjson::Value& payload,
173+
rapidjson::Document& response,
174+
const char*& error_code,
175+
std::string& error_message) override;
175176

176-
/** @copydoc void IRpcClientSpy::rcpClientMessageReceived(const std::string&) */
177-
void rcpClientMessageReceived(const std::string& msg) override;
177+
/// IRpc::ISpy interface
178178

179-
/** @copydoc void IRpcClientSpy::rcpClientMessageSent(const std::string&) */
180-
void rcpClientMessageSent(const std::string& msg) override;
179+
/** @copydoc void IRpc::ISpy::rcpMessageReceived(const std::string&) */
180+
void rcpMessageReceived(const std::string& msg) override;
181+
182+
/** @copydoc void IRpc::ISpy::rcpMessageSent(const std::string&) */
183+
void rcpMessageSent(const std::string& msg) override;
181184

182185
// IConfigChangedListener interface
183186

@@ -208,7 +211,7 @@ class ChargePoint : public IChargePoint,
208211
/** @brief Websocket s*/
209212
std::unique_ptr<ocpp::websockets::IWebsocketClient> m_ws_client;
210213
/** @brief RPC client */
211-
std::unique_ptr<ocpp::rpc::IRpcClient> m_rpc_client;
214+
std::unique_ptr<ocpp::rpc::RpcClient> m_rpc_client;
212215
/** @brief Message dispatcher */
213216
std::unique_ptr<ocpp::messages::MessageDispatcher> m_msg_dispatcher;
214217
/** @brief Message sender */

src/chargepoint/reservation/ReservationManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ along with OpenOCPP. If not, see <http://www.gnu.org/licenses/>.
2121
#include "Connectors.h"
2222
#include "IChargePointEventsHandler.h"
2323
#include "IOcppConfig.h"
24-
#include "IRpcClient.h"
24+
#include "IRpc.h"
2525
#include "IStatusManager.h"
2626
#include "WorkerThreadPool.h"
2727

@@ -261,7 +261,7 @@ bool ReservationManager::handleMessage(const ocpp::messages::ReserveNowReq& requ
261261
}
262262
else
263263
{
264-
error_code = ocpp::rpc::IRpcClient::RPC_ERROR_PROPERTY_CONSTRAINT_VIOLATION;
264+
error_code = ocpp::rpc::IRpc::RPC_ERROR_PROPERTY_CONSTRAINT_VIOLATION;
265265
error_message = "Invalid connector id";
266266
}
267267

src/chargepoint/smartcharging/SmartChargingManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ bool SmartChargingManager::handleMessage(const ocpp::messages::SetChargingProfil
332332
}
333333
else
334334
{
335-
error_code = ocpp::rpc::IRpcClient::RPC_ERROR_PROPERTY_CONSTRAINT_VIOLATION;
335+
error_code = ocpp::rpc::IRpc::RPC_ERROR_PROPERTY_CONSTRAINT_VIOLATION;
336336
response.status = ChargingProfileStatus::Rejected;
337337
}
338338

src/chargepoint/status/StatusManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ bool StatusManager::handleMessage(const ocpp::messages::ChangeAvailabilityReq& r
288288
}
289289
else
290290
{
291-
error_code = ocpp::rpc::IRpcClient::RPC_ERROR_PROPERTY_CONSTRAINT_VIOLATION;
291+
error_code = ocpp::rpc::IRpc::RPC_ERROR_PROPERTY_CONSTRAINT_VIOLATION;
292292
error_message = "Invalid connector id";
293293
}
294294
return ret;

src/chargepoint/trigger/TriggerMessageManager.cpp

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

1919
#include "TriggerMessageManager.h"
2020
#include "Connectors.h"
21-
#include "IRpcClient.h"
21+
#include "IRpc.h"
2222
#include "Logger.h"
2323

2424
using namespace ocpp::messages;
@@ -91,7 +91,7 @@ bool TriggerMessageManager::handleMessage(const ocpp::messages::TriggerMessageRe
9191
}
9292
else
9393
{
94-
error_code = ocpp::rpc::IRpcClient::RPC_ERROR_PROPERTY_CONSTRAINT_VIOLATION;
94+
error_code = ocpp::rpc::IRpc::RPC_ERROR_PROPERTY_CONSTRAINT_VIOLATION;
9595
error_message = "Invalid connector id";
9696
}
9797
}

src/messages/Authorize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ along with OpenOCPP. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

1919
#include "Authorize.h"
20-
#include "IRpcClient.h"
20+
#include "IRpc.h"
2121
#include "IdTagInfoConverter.h"
2222

2323
using namespace ocpp::types;

src/messages/BootNotification.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ along with OpenOCPP. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

1919
#include "BootNotification.h"
20-
#include "IRpcClient.h"
20+
#include "IRpc.h"
2121

2222
using namespace ocpp::types;
2323

@@ -82,7 +82,7 @@ bool BootNotificationConfConverter::fromJson(const rapidjson::Value& json,
8282
data.status = RegistrationStatusHelper.fromString(json["status"].GetString());
8383
if (!ret)
8484
{
85-
error_code = ocpp::rpc::IRpcClient::RPC_ERROR_TYPE_CONSTRAINT_VIOLATION;
85+
error_code = ocpp::rpc::IRpc::RPC_ERROR_TYPE_CONSTRAINT_VIOLATION;
8686
}
8787
return ret;
8888
}

src/messages/CancelReservation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ along with OpenOCPP. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

1919
#include "CancelReservation.h"
20-
#include "IRpcClient.h"
20+
#include "IRpc.h"
2121

2222
using namespace ocpp::types;
2323

0 commit comments

Comments
 (0)