Skip to content

Commit ca17325

Browse files
committed
[central system] Add skeleton of quick start example
1 parent cf6ead4 commit ca17325

24 files changed

+528
-81
lines changed

examples/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ The following examples are available :
88

99
How to run the examples:
1010
* Customize the *config.ini* file of the selected example with the URL of the Central System and the other connection parameters has well has the OCPP configuration keys
11-
* Run the exmaple using the **-w** option to specify the path of the configuration file
11+
* Run the example using the **-w** option to specify the path of the configuration file

examples/common/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
# Common utility class for examples library
33
add_library(examples_common STATIC
4+
DefaultCentralSystemEventsHandler.cpp
45
DefaultChargePointEventsHandler.cpp
56

67
config/OcppConfig.cpp
@@ -14,4 +15,5 @@ target_include_directories(examples_common PUBLIC . config simulators)
1415
target_link_libraries(examples_common
1516
json
1617
chargepoint
18+
centralsystem
1719
)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
MIT License
3+
4+
Copyright (c) 2020 Cedric Jimenez
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
25+
#include "DefaultCentralSystemEventsHandler.h"
26+
27+
#include <iostream>
28+
29+
using namespace std;
30+
using namespace ocpp::centralsystem;
31+
32+
/** @brief Constructor */
33+
DefaultCentralSystemEventsHandler::DefaultCentralSystemEventsHandler() : m_chargepoints() { }
34+
35+
/** @brief Destructor */
36+
DefaultCentralSystemEventsHandler::~DefaultCentralSystemEventsHandler() { }
37+
38+
// ICentralSystemEventsHandler interface
39+
40+
/** @copydoc bool ICentralSystemEventsHandler::checkCredentials(const std::string&, const std::string&) */
41+
bool DefaultCentralSystemEventsHandler::checkCredentials(const std::string& chargepoint_id, const std::string& password)
42+
{
43+
cout << "Check credentials for [" << chargepoint_id << "] : " << password << endl;
44+
return true;
45+
}
46+
47+
/** @copydoc bool ICentralSystemEventsHandler::chargePointConnected(std::shared_ptr<ICentralSystem::IChargePoint>) */
48+
void DefaultCentralSystemEventsHandler::chargePointConnected(std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint> chargepoint)
49+
{
50+
cout << "Charge point [" << chargepoint->identifier() << "] connected" << endl;
51+
auto iter_chargepoint = m_chargepoints.find(chargepoint->identifier());
52+
if (iter_chargepoint == m_chargepoints.end())
53+
{
54+
m_chargepoints[chargepoint->identifier()] = chargepoint;
55+
}
56+
else
57+
{
58+
cout << "Charge point [" << chargepoint->identifier() << "] already connected" << endl;
59+
chargepoint.reset();
60+
}
61+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
MIT License
3+
4+
Copyright (c) 2020 Cedric Jimenez
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
25+
#ifndef DEFAULTCENTRALSYSTEMEVENTSHANDLER_H
26+
#define DEFAULTCENTRALSYSTEMEVENTSHANDLER_H
27+
28+
#include "ICentralSystemEventsHandler.h"
29+
30+
#include <map>
31+
32+
/** @brief Default central system event handlers implementation for the examples */
33+
class DefaultCentralSystemEventsHandler : public ocpp::centralsystem::ICentralSystemEventsHandler
34+
{
35+
public:
36+
/** @brief Constructor */
37+
DefaultCentralSystemEventsHandler();
38+
39+
/** @brief Destructor */
40+
virtual ~DefaultCentralSystemEventsHandler();
41+
42+
// ICentralSystemEventsHandler interface
43+
44+
/** @copydoc bool ICentralSystemEventsHandler::checkCredentials(const std::string&, const std::string&) */
45+
bool checkCredentials(const std::string& chargepoint_id, const std::string& password) override;
46+
47+
/** @copydoc bool ICentralSystemEventsHandler::chargePointConnected(std::shared_ptr<ICentralSystem::IChargePoint>) */
48+
void chargePointConnected(std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint> chargepoint) override;
49+
50+
private:
51+
/** @brief Connected charge points */
52+
std::map<std::string, std::shared_ptr<ocpp::centralsystem::ICentralSystem::IChargePoint>> m_chargepoints;
53+
};
54+
55+
#endif // DEFAULTCENTRALSYSTEMEVENTSHANDLER_H

examples/common/config/CentralSystemConfig.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,29 @@ class CentralSystemConfig : public ocpp::config::ICentralSystemConfig
4848
// Communication parameters
4949

5050
/** @brief Listen URL */
51-
std::string listenUrl() const override { return getString("ListenUrl"); };
51+
std::string listenUrl() const override { return getString("ListenUrl"); }
52+
/** @brief Enable HTTP basic authentication */
53+
bool httpBasicAuthent() const override { return getBool("HttpBasicAuthent"); }
5254
/** @brief Call request timeout */
5355
std::chrono::milliseconds callRequestTimeout() const override { return get<std::chrono::milliseconds>("CallRequestTimeout"); }
5456
/** @brief Cipher list to use for TLSv1.2 connections */
5557
std::string tlsv12CipherList() const override { return getString("Tlsv12CipherList"); }
5658
/** @brief Cipher list to use for TLSv1.3 connections */
5759
std::string tlsv13CipherList() const override { return getString("Tlsv13CipherList"); }
5860
/** @brief ECDH curve to use for TLS connections */
59-
std::string tlsvEcdhCurve() const override { return getString("TlsEcdhCurve"); }
61+
std::string tlsEcdhCurve() const override { return getString("TlsEcdhCurve"); }
62+
/** @brief Server certificate */
63+
std::string tlsServerCertificate() const override { return getString("TlsServerCertificate"); }
64+
/** @brief Server certificate's private key */
65+
std::string tlsServerCertificatePrivateKey() const override { return getString("TlsServerCertificatePrivateKey"); }
66+
/** @brief Server certificate's private key passphrase */
67+
std::string tlsServerCertificatePrivateKeyPassphrase() const override { return getString("TlsServerCertificatePrivateKeyPassphrase"); }
68+
/** @brief Certification Authority signing chain for the server certificate */
69+
std::string tlsServerCertificateCa() const override { return getString("TlsServerCertificateCa"); }
70+
/** @brief Certification Authority signing chain for the clients certificates */
71+
std::string tlsClientCertificateCa() const override { return getString("TlsClientCertificateCa"); }
72+
/** @brief Enable client authentication using certificate */
73+
bool tlsClientCertificateAuthent() const override { return getBool("TlsClientCertificateAuthent"); }
6074

6175
// Logs
6276

examples/common/config/ChargePointConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class ChargePointConfig : public ocpp::config::IChargePointConfig
6262
/** @brief Cipher list to use for TLSv1.3 connections */
6363
std::string tlsv13CipherList() const override { return getString("Tlsv13CipherList"); }
6464
/** @brief ECDH curve to use for TLS connections */
65-
std::string tlsvEcdhCurve() const override { return getString("TlsEcdhCurve"); }
65+
std::string tlsEcdhCurve() const override { return getString("TlsEcdhCurve"); }
6666
/** @brief Allow TLS connections using self-signed certificates
6767
* (Warning : enabling this feature is not recommended in production) */
6868
bool tlsAllowSelfSignedCertificates() const override { return getBool("TlsAllowSelfSignedCertificates"); }
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Quick start Central System example
2+
3+
## Description
4+
5+
This example simulates a central system which accepts any charge point.
6+
7+
The central system loops on its connected charge points. For each charge point it simulates the following operations :
8+
9+
* Get configuration
10+
* Trigger messages : status notification, meter values
11+
12+
There is a 10s break between 2 charge points communication.
13+
14+
## Command line
15+
16+
quick_start_centralsystem [-w working_dir] [-r]
17+
18+
* -w : Working directory where to store the configuration file (Default = current directory)
19+
* -r : Reset all the OCPP persistent data
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
[CentralSystem]
2-
DatabasePath=./quick_start_central_system.db
2+
DatabasePath=./quick_start_centralsystem.db
33
JsonSchemasPath=../../schemas/ocpp16/
44
ListenUrl=ws://127.0.0.1:8180/steve/websocket/CentralSystemService/
5+
HttpBasicAuthent=false
6+
CallRequestTimeout=2000
57
Tlsv12CipherList=ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-WITH-AES-256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:TLS-PSK-WITH-AES-256-GCM-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-WITH-AES-128-GCM-SHA256:DHE-RSA-AES128-GCM-SHA256:TLS-PSK-WITH-AES-128-GCM-SHA256
68
Tlsv13CipherList=TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384
79
TlsEcdhCurve=prime256v1
8-
CallRequestTimeout=2000
10+
TlsServerCertificate=../../examples/certificates/OpenOCPP_CentralSystem.pem
11+
TlsServerCertificatePrivateKey=../../examples/certificates/OpenOCPP_CentralSystem-private.key
12+
TlsServerCertificatePrivateKeyPassphrase=
13+
TlsServerCertificateCa=../../examples/certificates/OpenOCPP_CA.pem
14+
TlsClientCertificateCa=
15+
TlsClientCertificateAuthent=false
916
LogMaxEntriesCount=2000

examples/quick_start_centralsystem/main.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ SOFTWARE.
2323
*/
2424

2525
#include "CentralSystemDemoConfig.h"
26+
#include "DefaultCentralSystemEventsHandler.h"
2627
#include "ICentralSystem.h"
2728

2829
#include <cstring>
@@ -32,11 +33,6 @@ SOFTWARE.
3233

3334
using namespace ocpp::centralsystem;
3435

35-
/** @brief EVent handler */
36-
class CentralSystemEventHandler : public ICentralSystemEventsHandler
37-
{
38-
};
39-
4036
/** @brief Entry point */
4137
int main(int argc, char* argv[])
4238
{
@@ -98,7 +94,7 @@ int main(int argc, char* argv[])
9894
CentralSystemDemoConfig config(path);
9995

10096
// Event handler
101-
CentralSystemEventHandler event_handler;
97+
DefaultCentralSystemEventsHandler event_handler;
10298

10399
// Instanciate central system
104100
std::unique_ptr<ICentralSystem> central_system = ICentralSystem::create(config.stackConfig(), event_handler);

src/centralsystem/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
# Library target
77
add_library(centralsystem STATIC
88
CentralSystem.cpp
9+
10+
chargepoint/ChargePointProxy.cpp
911
)
1012

1113
# Exported includes
1214
target_include_directories(centralsystem PUBLIC interface)
1315

1416
# Private includes
15-
target_include_directories(centralsystem PRIVATE authent
17+
target_include_directories(centralsystem PRIVATE chargepoint
1618
config)
1719

1820
# Dependencies

0 commit comments

Comments
 (0)