Skip to content

Commit ad0fe21

Browse files
committed
init with v201 in C-API directly
1 parent 91b0738 commit ad0fe21

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

src/MicroOcpp_c.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "MicroOcpp_c.h"
66
#include "MicroOcpp.h"
77

8+
#include <MicroOcpp/Version.h>
89
#include <MicroOcpp/Model/Certificates/Certificate_c.h>
910
#include <MicroOcpp/Core/Context.h>
1011
#include <MicroOcpp/Model/Model.h>
@@ -15,11 +16,14 @@
1516

1617
MicroOcpp::Connection *ocppSocket = nullptr;
1718

18-
void ocpp_initialize(OCPP_Connection *conn, const char *chargePointModel, const char *chargePointVendor, struct OCPP_FilesystemOpt fsopt, bool autoRecover) {
19-
ocpp_initialize_full(conn, ChargerCredentials(chargePointModel, chargePointVendor), fsopt, autoRecover);
19+
void ocpp_initialize(OCPP_Connection *conn, const char *chargePointModel, const char *chargePointVendor, struct OCPP_FilesystemOpt fsopt, bool autoRecover, bool ocpp201) {
20+
ocpp_initialize_full(conn, ocpp201 ?
21+
ChargerCredentials::v201(chargePointModel, chargePointVendor) :
22+
ChargerCredentials(chargePointModel, chargePointVendor),
23+
fsopt, autoRecover, ocpp201);
2024
}
2125

22-
void ocpp_initialize_full(OCPP_Connection *conn, const char *bootNotificationCredentials, struct OCPP_FilesystemOpt fsopt, bool autoRecover) {
26+
void ocpp_initialize_full(OCPP_Connection *conn, const char *bootNotificationCredentials, struct OCPP_FilesystemOpt fsopt, bool autoRecover, bool ocpp201) {
2327
if (!conn) {
2428
MO_DBG_ERR("conn is null");
2529
}
@@ -28,7 +32,10 @@ void ocpp_initialize_full(OCPP_Connection *conn, const char *bootNotificationCre
2832

2933
MicroOcpp::FilesystemOpt adaptFsopt = fsopt;
3034

31-
mocpp_initialize(*ocppSocket, bootNotificationCredentials, MicroOcpp::makeDefaultFilesystemAdapter(adaptFsopt), autoRecover, MicroOcpp::ProtocolVersion(1,6));
35+
mocpp_initialize(*ocppSocket, bootNotificationCredentials, MicroOcpp::makeDefaultFilesystemAdapter(adaptFsopt), autoRecover,
36+
ocpp201 ?
37+
MicroOcpp::ProtocolVersion(2,0,1) :
38+
MicroOcpp::ProtocolVersion(1,6));
3239
}
3340

3441
void ocpp_deinitialize() {

src/MicroOcpp_c.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,16 @@ void ocpp_initialize(
6060
const char *chargePointModel, //model name of this charger (e.g. "My Charger")
6161
const char *chargePointVendor, //brand name (e.g. "My Company Ltd.")
6262
struct OCPP_FilesystemOpt fsopt, //If this library should format the flash if necessary. Find further options in ConfigurationOptions.h
63-
bool autoRecover); //automatically sanitize the local data store when the lib detects recurring crashes. During development, `false` is recommended
63+
bool autoRecover, //automatically sanitize the local data store when the lib detects recurring crashes. During development, `false` is recommended
64+
bool ocpp201); //true to select OCPP 2.0.1, false for OCPP 1.6
6465

6566
//same as above, but more fields for the BootNotification
6667
void ocpp_initialize_full(
6768
OCPP_Connection *conn, //WebSocket adapter for MicroOcpp
6869
const char *bootNotificationCredentials, //e.g. '{"chargePointModel":"Demo Charger","chargePointVendor":"My Company Ltd."}' (refer to OCPP 1.6 Specification - Edition 2 p. 60)
6970
struct OCPP_FilesystemOpt fsopt, //If this library should format the flash if necessary. Find further options in ConfigurationOptions.h
70-
bool autoRecover); //automatically sanitize the local data store when the lib detects recurring crashes. During development, `false` is recommended
71+
bool autoRecover, //automatically sanitize the local data store when the lib detects recurring crashes. During development, `false` is recommended
72+
bool ocpp201); //true to select OCPP 2.0.1, false for OCPP 1.6
7173

7274
void ocpp_deinitialize();
7375

tests/Api.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ TEST_CASE( "C API test" ) {
195195
fsopt.formatFsOnFail = true;
196196

197197
MicroOcpp::LoopbackConnection loopback;
198-
ocpp_initialize(reinterpret_cast<OCPP_Connection*>(&loopback), "test-runner1234", "vendor", fsopt, false);
198+
ocpp_initialize(reinterpret_cast<OCPP_Connection*>(&loopback), "test-runner1234", "vendor", fsopt, false, false);
199199

200200
auto context = getOcppContext();
201201
auto& model = context->getModel();

0 commit comments

Comments
 (0)