Skip to content

Commit 6413337

Browse files
committed
[central system] Add charge point proxy implementation + update quick start central system example
1 parent ca17325 commit 6413337

File tree

16 files changed

+1129
-19
lines changed

16 files changed

+1129
-19
lines changed

examples/common/DefaultCentralSystemEventsHandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ bool DefaultCentralSystemEventsHandler::checkCredentials(const std::string& char
4343
cout << "Check credentials for [" << chargepoint_id << "] : " << password << endl;
4444
return true;
4545
}
46-
46+
#include <thread>
4747
/** @copydoc bool ICentralSystemEventsHandler::chargePointConnected(std::shared_ptr<ICentralSystem::IChargePoint>) */
4848
void DefaultCentralSystemEventsHandler::chargePointConnected(std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint> chargepoint)
4949
{

examples/common/DefaultCentralSystemEventsHandler.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ class DefaultCentralSystemEventsHandler : public ocpp::centralsystem::ICentralSy
4747
/** @copydoc bool ICentralSystemEventsHandler::chargePointConnected(std::shared_ptr<ICentralSystem::IChargePoint>) */
4848
void chargePointConnected(std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint> chargepoint) override;
4949

50+
// API
51+
52+
/** @brief Get the list of the connected charge points */
53+
std::map<std::string, std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint>>& chargePoints() { return m_chargepoints; }
54+
5055
private:
5156
/** @brief Connected charge points */
5257
std::map<std::string, std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint>> m_chargepoints;

examples/quick_start_centralsystem/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This example simulates a central system which accepts any charge point.
77
The central system loops on its connected charge points. For each charge point it simulates the following operations :
88

99
* Get configuration
10+
* Set heartbeat interval to 10s
1011
* Trigger messages : status notification, meter values
1112

1213
There is a 10s break between 2 charge points communication.

examples/quick_start_centralsystem/main.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ SOFTWARE.
3232
#include <thread>
3333

3434
using namespace ocpp::centralsystem;
35+
using namespace ocpp::types;
3536

3637
/** @brief Entry point */
3738
int main(int argc, char* argv[])
@@ -106,6 +107,58 @@ int main(int argc, char* argv[])
106107

107108
// From now on the stack is alive :)
108109

110+
// App loop
111+
while (true)
112+
{
113+
// Wait for at least 1 connected charge point
114+
while (event_handler.chargePoints().size() == 0)
115+
{
116+
std::this_thread::sleep_for(std::chrono::milliseconds(250));
117+
}
118+
119+
// For each connected charge point
120+
for (auto& iter_chargepoint : event_handler.chargePoints())
121+
{
122+
auto& chargepoint = iter_chargepoint.second;
123+
124+
std::cout << "---------------------------------------------" << std::endl;
125+
std::cout << "Charge point : " << chargepoint->identifier() << std::endl;
126+
std::cout << "---------------------------------------------" << std::endl;
127+
128+
std::cout << "Read whole charge point configuration..." << std::endl;
129+
std::vector<std::string> keys;
130+
std::vector<KeyValue> config_keys;
131+
std::vector<std::string> unknown_keys;
132+
if (chargepoint->getConfiguration(keys, config_keys, unknown_keys))
133+
{
134+
std::cout << "Configuration keys :" << std::endl;
135+
for (const KeyValue& key_value : config_keys)
136+
{
137+
std::cout << " - " << key_value.key.str() << " = " << (key_value.value.isSet() ? key_value.value.value().str() : "")
138+
<< " " << (key_value.readonly ? "(read-only)" : "") << std::endl;
139+
}
140+
}
141+
else
142+
{
143+
std::cout << "Failed!" << std::endl;
144+
}
145+
146+
std::cout << "Configure heartbeat interval..." << std::endl;
147+
ConfigurationStatus config_status = chargepoint->changeConfiguration("HeartbeatInterval", "10");
148+
std::cout << ConfigurationStatusHelper.toString(config_status) << std::endl;
149+
150+
std::cout << "Trigger status notification..." << std::endl;
151+
TriggerMessageStatus trigger_status = chargepoint->triggerMessage(MessageTrigger::StatusNotification, Optional<unsigned int>());
152+
std::cout << TriggerMessageStatusHelper.toString(trigger_status) << std::endl;
153+
154+
std::cout << "Trigger meter values on connector 0..." << std::endl;
155+
trigger_status = chargepoint->triggerMessage(MessageTrigger::MeterValues, 0);
156+
std::cout << TriggerMessageStatusHelper.toString(trigger_status) << std::endl;
157+
158+
std::this_thread::sleep_for(std::chrono::seconds(10));
159+
}
160+
}
161+
109162
std::this_thread::sleep_for(std::chrono::milliseconds(5000000));
110163

111164
return 0;

src/centralsystem/CentralSystem.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ CentralSystem::CentralSystem(const ocpp::config::ICentralSystemConfig& stack_con
5151
m_worker_pool(2u), // 1 asynchronous timer operations + 1 for asynchronous responses
5252
m_database(),
5353
m_internal_config(m_database),
54+
m_messages_converter(),
5455
m_ws_server(),
5556
m_rpc_server(),
5657
m_uptime_timer(m_timer_pool, "Uptime timer"),
@@ -233,8 +234,8 @@ void CentralSystem::rpcClientConnected(const std::string& chargepoint_id, std::s
233234
LOG_INFO << "Connection from Charge Point [" << chargepoint_id << "]";
234235

235236
// Instanciate proxy
236-
std::shared_ptr<ICentralSystem::IChargePoint> chargepoint(
237-
new ChargePointProxy(chargepoint_id, client, m_stack_config.jsonSchemasPath()));
237+
std::shared_ptr<ICentralSystem::IChargePoint> chargepoint(new ChargePointProxy(
238+
chargepoint_id, client, m_stack_config.jsonSchemasPath(), m_messages_converter, m_stack_config.callRequestTimeout()));
238239

239240
// Notify connection
240241
m_events_handler.chargePointConnected(chargepoint);

src/centralsystem/CentralSystem.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ along with OpenOCPP. If not, see <http://www.gnu.org/licenses/>.
2222
#include "Database.h"
2323
#include "ICentralSystem.h"
2424
#include "InternalConfigManager.h"
25+
#include "MessagesConverter.h"
2526
#include "RpcServer.h"
2627
#include "Timer.h"
2728
#include "TimerPool.h"
@@ -88,6 +89,9 @@ class CentralSystem : public ICentralSystem, public ocpp::rpc::RpcServer::IListe
8889
/** @brief Internal configuration manager */
8990
ocpp::config::InternalConfigManager m_internal_config;
9091

92+
/** @brief Messages converter */
93+
ocpp::messages::MessagesConverter m_messages_converter;
94+
9195
/** @brief Websocket server */
9296
std::unique_ptr<ocpp::websockets::IWebsocketServer> m_ws_server;
9397
/** @brief RPC server */

0 commit comments

Comments
 (0)