Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
- Operation GetInstalledCertificateIds, UC M03 ([#262](https://github.com/matth-x/MicroOcpp/pull/262))
- Operation DeleteCertificate, UC M04 ([#262](https://github.com/matth-x/MicroOcpp/pull/262))
- Operation InstallCertificate, UC M05 ([#262](https://github.com/matth-x/MicroOcpp/pull/262))
- `ProtocolVersion` selects v1.6 or v2.0.1 ([#247](https://github.com/matth-x/MicroOcpp/pull/247))
- Build flag `MO_ENABLE_V201` set to 1 enables OCPP 2.0.1 features ([#247](https://github.com/matth-x/MicroOcpp/pull/247))
- Variables (non-persistent), UCs B05 - B06 ([#247](https://github.com/matth-x/MicroOcpp/pull/247))
- Transactions (preview only), UCs E01 - E12 ([#247](https://github.com/matth-x/MicroOcpp/pull/247))
- StatusNotification compatibility ([#247](https://github.com/matth-x/MicroOcpp/pull/247))

## [1.1.0] - 2024-02-27

Expand Down
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ set(MO_SRC
src/MicroOcpp/Operations/GetDiagnostics.cpp
src/MicroOcpp/Operations/GetInstalledCertificateIds.cpp
src/MicroOcpp/Operations/GetLocalListVersion.cpp
src/MicroOcpp/Operations/GetVariables.cpp
src/MicroOcpp/Operations/Heartbeat.cpp
src/MicroOcpp/Operations/MeterValues.cpp
src/MicroOcpp/Operations/RemoteStartTransaction.cpp
Expand All @@ -47,9 +48,11 @@ set(MO_SRC
src/MicroOcpp/Operations/Reset.cpp
src/MicroOcpp/Operations/SendLocalList.cpp
src/MicroOcpp/Operations/SetChargingProfile.cpp
src/MicroOcpp/Operations/SetVariables.cpp
src/MicroOcpp/Operations/StartTransaction.cpp
src/MicroOcpp/Operations/StatusNotification.cpp
src/MicroOcpp/Operations/StopTransaction.cpp
src/MicroOcpp/Operations/TransactionEvent.cpp
src/MicroOcpp/Operations/TriggerMessage.cpp
src/MicroOcpp/Operations/InstallCertificate.cpp
src/MicroOcpp/Operations/UnlockConnector.cpp
Expand All @@ -60,6 +63,7 @@ set(MO_SRC
src/MicroOcpp/Model/Authorization/AuthorizationData.cpp
src/MicroOcpp/Model/Authorization/AuthorizationList.cpp
src/MicroOcpp/Model/Authorization/AuthorizationService.cpp
src/MicroOcpp/Model/Authorization/IdToken.cpp
src/MicroOcpp/Model/Boot/BootService.cpp
src/MicroOcpp/Model/Certificates/Certificate.cpp
src/MicroOcpp/Model/Certificates/Certificate_c.cpp
Expand All @@ -83,7 +87,11 @@ set(MO_SRC
src/MicroOcpp/Model/SmartCharging/SmartChargingService.cpp
src/MicroOcpp/Model/Transactions/Transaction.cpp
src/MicroOcpp/Model/Transactions/TransactionDeserialize.cpp
src/MicroOcpp/Model/Transactions/TransactionService.cpp
src/MicroOcpp/Model/Transactions/TransactionStore.cpp
src/MicroOcpp/Model/Variables/Variable.cpp
src/MicroOcpp/Model/Variables/VariableContainer.cpp
src/MicroOcpp/Model/Variables/VariableService.cpp
src/MicroOcpp.cpp
src/MicroOcpp_c.cpp
)
Expand Down Expand Up @@ -135,6 +143,8 @@ set(MO_SRC_UNIT
tests/Configuration.cpp
tests/Reservation.cpp
tests/LocalAuthList.cpp
tests/Variables.cpp
tests/Transactions.cpp
#tests/Certificates.cpp # add if MbedTLS is available
)

Expand Down
73 changes: 70 additions & 3 deletions src/MicroOcpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <MicroOcpp/Model/Reservation/ReservationService.h>
#include <MicroOcpp/Model/Boot/BootService.h>
#include <MicroOcpp/Model/Reset/ResetService.h>
#include <MicroOcpp/Model/Variables/VariableService.h>
#include <MicroOcpp/Model/Transactions/TransactionService.h>
#include <MicroOcpp/Model/Certificates/CertificateService.h>
#include <MicroOcpp/Model/Certificates/CertificateMbedTLS.h> //default CertStore implementation depends on MbedTLS
#include <MicroOcpp/Core/SimpleRequestFactory.h>
Expand All @@ -30,7 +32,6 @@
#include <MicroOcpp/Operations/CustomOperation.h>

#include <MicroOcpp/Debug.h>
#include <MicroOcpp/Version.h>

namespace MicroOcpp {
namespace Facade {
Expand Down Expand Up @@ -201,7 +202,39 @@ ChargerCredentials::ChargerCredentials(const char *cpModel, const char *cpVendor
}
}

void mocpp_initialize(Connection& connection, const char *bootNotificationCredentials, std::shared_ptr<FilesystemAdapter> fs, bool autoRecover, std::unique_ptr<CertificateStore> certStore) {
ChargerCredentials ChargerCredentials::v201(const char *cpModel, const char *cpVendor, const char *fWv, const char *cpSNr, const char *meterSNr, const char *meterType, const char *cbSNr, const char *iccid, const char *imsi) {

ChargerCredentials res;

StaticJsonDocument<512> creds;
if (cpSNr)
creds["serialNumber"] = cpSNr;
if (cpModel)
creds["model"] = cpModel;
if (cpVendor)
creds["vendorName"] = cpVendor;
if (fWv)
creds["firmwareVersion"] = fWv;
if (iccid)
creds["modem"]["iccid"] = iccid;
if (imsi)
creds["modem"]["imsi"] = imsi;

if (creds.overflowed()) {
MO_DBG_ERR("Charger Credentials too long");
}

size_t written = serializeJson(creds, res.payload, 512);

if (written < 2) {
MO_DBG_ERR("Charger Credentials could not be written");
sprintf(res.payload, "{}");
}

return res;
}

void mocpp_initialize(Connection& connection, const char *bootNotificationCredentials, std::shared_ptr<FilesystemAdapter> fs, bool autoRecover, MicroOcpp::ProtocolVersion version, std::unique_ptr<CertificateStore> certStore) {
if (context) {
MO_DBG_WARN("already initialized. To reinit, call mocpp_deinitialize() before");
return;
Expand Down Expand Up @@ -236,7 +269,7 @@ void mocpp_initialize(Connection& connection, const char *bootNotificationCreden

configuration_init(filesystem); //call before each other library call

context = new Context(connection, filesystem, bootstats.bootNr);
context = new Context(connection, filesystem, bootstats.bootNr, version);
auto& model = context->getModel();

model.setTransactionStore(std::unique_ptr<TransactionStore>(
Expand All @@ -259,6 +292,13 @@ void mocpp_initialize(Connection& connection, const char *bootNotificationCreden
model.setResetService(std::unique_ptr<ResetService>(
new ResetService(*context)));

#if MO_ENABLE_V201
model.setVariableService(std::unique_ptr<VariableService>(
new VariableService(*context, filesystem)));
model.setTransactionService(std::unique_ptr<TransactionService>(
new TransactionService(*context)));
#endif

std::unique_ptr<CertificateStore> certStoreUse;
if (certStore) {
certStoreUse = std::move(certStore);
Expand Down Expand Up @@ -497,6 +537,15 @@ void setConnectorPluggedInput(std::function<bool()> pluggedInput, unsigned int c
MO_DBG_ERR("OCPP uninitialized"); //need to call mocpp_initialize before
return;
}
#if MO_ENABLE_V201
if (context->getVersion().major == 2) {
if (auto txService = context->getModel().getTransactionService()) {
if (auto evse = txService->getEvse(connectorId)) {
evse->setConnectorPluggedInput(pluggedInput);
}
}
}
#endif
auto connector = context->getModel().getConnector(connectorId);
if (!connector) {
MO_DBG_ERR("could not find connector");
Expand Down Expand Up @@ -633,6 +682,15 @@ void setEvReadyInput(std::function<bool()> evReadyInput, unsigned int connectorI
MO_DBG_ERR("OCPP uninitialized"); //need to call mocpp_initialize before
return;
}
#if MO_ENABLE_V201
if (context->getVersion().major == 2) {
if (auto txService = context->getModel().getTransactionService()) {
if (auto evse = txService->getEvse(connectorId)) {
evse->setEvReadyInput(evReadyInput);
}
}
}
#endif
auto connector = context->getModel().getConnector(connectorId);
if (!connector) {
MO_DBG_ERR("could not find connector");
Expand All @@ -646,6 +704,15 @@ void setEvseReadyInput(std::function<bool()> evseReadyInput, unsigned int connec
MO_DBG_ERR("OCPP uninitialized"); //need to call mocpp_initialize before
return;
}
#if MO_ENABLE_V201
if (context->getVersion().major == 2) {
if (auto txService = context->getModel().getTransactionService()) {
if (auto evse = txService->getEvse(connectorId)) {
evse->setEvseReadyInput(evseReadyInput);
}
}
}
#endif
auto connector = context->getModel().getConnector(connectorId);
if (!connector) {
MO_DBG_ERR("could not find connector");
Expand Down
22 changes: 19 additions & 3 deletions src/MicroOcpp.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// matth-x/MicroOcpp
// Copyright Matthias Akstaller 2019 - 2023
// Copyright Matthias Akstaller 2019 - 2024
// MIT License

#ifndef ARDUINOOCPP_H
#define ARDUINOOCPP_H
#ifndef MO_MICROOCPP_H
#define MO_MICROOCPP_H

#include <ArduinoJson.h>
#include <memory>
Expand All @@ -18,6 +18,7 @@
#include <MicroOcpp/Model/Transactions/Transaction.h>
#include <MicroOcpp/Model/ConnectorBase/Notification.h>
#include <MicroOcpp/Model/ConnectorBase/ChargePointErrorData.h>
#include <MicroOcpp/Version.h>
#include <MicroOcpp/Model/Certificates/Certificate.h>

using MicroOcpp::OnReceiveConfListener;
Expand Down Expand Up @@ -70,6 +71,20 @@ struct ChargerCredentials {
const char *chargeBoxSerialNumber = nullptr,
const char *iccid = nullptr,
const char *imsi = nullptr);

/*
* OCPP 2.0.1 compatible charger credentials. Use this if initializing the library with ProtocolVersion(2,0,1)
*/
static ChargerCredentials v201(
const char *chargePointModel = "Demo Charger",
const char *chargePointVendor = "My Company Ltd.",
const char *firmwareVersion = nullptr,
const char *chargePointSerialNumber = nullptr,
const char *meterSerialNumber = nullptr,
const char *meterType = nullptr,
const char *chargeBoxSerialNumber = nullptr,
const char *iccid = nullptr,
const char *imsi = nullptr);

operator const char *() {return payload;}

Expand All @@ -95,6 +110,7 @@ void mocpp_initialize(
std::shared_ptr<MicroOcpp::FilesystemAdapter> filesystem =
MicroOcpp::makeDefaultFilesystemAdapter(MicroOcpp::FilesystemOpt::Use_Mount_FormatOnFail), //If this library should format the flash if necessary. Find further options in ConfigurationOptions.h
bool autoRecover = false, //automatically sanitize the local data store when the lib detects recurring crashes. Not recommended during development
MicroOcpp::ProtocolVersion version = MicroOcpp::ProtocolVersion(1,6),
std::unique_ptr<MicroOcpp::CertificateStore> certStore = nullptr); //optionally use custom Cert Store (default depends on MbedTLS)

/*
Expand Down
8 changes: 6 additions & 2 deletions src/MicroOcpp/Core/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

using namespace MicroOcpp;

Context::Context(Connection& connection, std::shared_ptr<FilesystemAdapter> filesystem, uint16_t bootNr)
: connection(connection), model{bootNr}, reqQueue{operationRegistry, &model, filesystem} {
Context::Context(Connection& connection, std::shared_ptr<FilesystemAdapter> filesystem, uint16_t bootNr, ProtocolVersion version)
: connection(connection), model{version, bootNr}, reqQueue{operationRegistry, &model, filesystem} {

preBootQueue = std::unique_ptr<RequestQueue>(new RequestQueue(operationRegistry, &model, nullptr)); //pre boot queue doesn't need persistency
preBootQueue->setConnection(connection);
Expand Down Expand Up @@ -64,3 +64,7 @@ Model& Context::getModel() {
OperationRegistry& Context::getOperationRegistry() {
return operationRegistry;
}

const ProtocolVersion& Context::getVersion() {
return model.getVersion();
}
7 changes: 5 additions & 2 deletions src/MicroOcpp/Core/Context.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// matth-x/MicroOcpp
// Copyright Matthias Akstaller 2019 - 2023
// Copyright Matthias Akstaller 2019 - 2024
// MIT License

#ifndef MO_CONTEXT_H
Expand All @@ -10,6 +10,7 @@
#include <MicroOcpp/Core/OperationRegistry.h>
#include <MicroOcpp/Core/RequestQueue.h>
#include <MicroOcpp/Model/Model.h>
#include <MicroOcpp/Version.h>

namespace MicroOcpp {

Expand All @@ -26,7 +27,7 @@ class Context {
std::unique_ptr<RequestQueue> preBootQueue;

public:
Context(Connection& connection, std::shared_ptr<FilesystemAdapter> filesystem, uint16_t bootNr);
Context(Connection& connection, std::shared_ptr<FilesystemAdapter> filesystem, uint16_t bootNr, ProtocolVersion version);
~Context();

void loop();
Expand All @@ -41,6 +42,8 @@ class Context {
Model& getModel();

OperationRegistry& getOperationRegistry();

const ProtocolVersion& getVersion();
};

} //end namespace MicroOcpp
Expand Down
69 changes: 69 additions & 0 deletions src/MicroOcpp/Model/Authorization/IdToken.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// matth-x/MicroOcpp
// Copyright Matthias Akstaller 2019 - 2024
// MIT License

#include <MicroOcpp/Version.h>

#if MO_ENABLE_V201

#include <MicroOcpp/Model/Authorization/IdToken.h>

#include <string.h>
#include <stdio.h>

#include <MicroOcpp/Debug.h>

using namespace MicroOcpp;

IdToken::IdToken() {
idToken[0] = '\0';
}

IdToken::IdToken(const char *token, Type type) : type(type) {
auto ret = snprintf(idToken, MO_IDTOKEN_LEN_MAX + 1, "%s", token);
if (ret < 0 || ret >= MO_IDTOKEN_LEN_MAX + 1) {
MO_DBG_ERR("invalid token");
*idToken = '\0';
}
}

const char *IdToken::get() const {
return *idToken ? idToken : nullptr;;
}

const char *IdToken::getTypeCstr() const {
const char *res = nullptr;
switch (type) {
case Type::Central:
res = "Central";
break;
case Type::eMAID:
res = "eMAID";
break;
case Type::ISO14443:
res = "ISO14443";
break;
case Type::ISO15693:
res = "ISO15693";
break;
case Type::KeyCode:
res = "KeyCode";
break;
case Type::Local:
res = "Local";
break;
case Type::MacAddress:
res = "MacAddress";
break;
case Type::NoAuthorization:
res = "NoAuthorization";
break;
}

if (!res) {
MO_DBG_ERR("internal error");
}
return res ? res : "";
}

#endif // MO_ENABLE_V201
Loading