Skip to content

Commit bcfe1ba

Browse files
committed
refactor TxNotification
1 parent 9aa9b44 commit bcfe1ba

File tree

21 files changed

+85
-165
lines changed

21 files changed

+85
-165
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Changed
6+
7+
- Change `MicroOcpp::TxNotification` into C-style enum, replace `OCPP_TxNotication`
8+
39
## [1.2.0] - 2024-11-03
410

511
### Changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ set(MO_SRC
7878
src/MicroOcpp/Model/Certificates/CertificateService.cpp
7979
src/MicroOcpp/Model/ConnectorBase/ConnectorsCommon.cpp
8080
src/MicroOcpp/Model/ConnectorBase/Connector.cpp
81-
src/MicroOcpp/Model/ConnectorBase/Notification.cpp
8281
src/MicroOcpp/Model/Diagnostics/DiagnosticsService.cpp
8382
src/MicroOcpp/Model/FirmwareManagement/FirmwareService.cpp
8483
src/MicroOcpp/Model/Heartbeat/HeartbeatService.cpp

src/MicroOcpp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ bool endTransaction(const char *idTag, const char *reason, unsigned int connecto
543543
MO_DBG_DEBUG("Authorize rejected (%s), continue transaction", idTag_capture.c_str());
544544
auto connector = context->getModel().getConnector(connectorId);
545545
if (connector) {
546-
connector->updateTxNotification(TxNotification::AuthorizationRejected);
546+
connector->updateTxNotification(TxNotification_AuthorizationRejected);
547547
}
548548
return;
549549
}
@@ -558,7 +558,7 @@ bool endTransaction(const char *idTag, const char *reason, unsigned int connecto
558558
MO_DBG_DEBUG("Authorization timeout (%s), continue transaction", idTag_capture.c_str());
559559
auto connector = context->getModel().getConnector(connectorId);
560560
if (connector) {
561-
connector->updateTxNotification(TxNotification::AuthorizationTimeout);
561+
connector->updateTxNotification(TxNotification_AuthorizationTimeout);
562562
}
563563
});
564564

@@ -1140,7 +1140,7 @@ void setStopTxReadyInput(std::function<bool()> stopTxReady, unsigned int connect
11401140
connector->setStopTxReadyInput(stopTxReady);
11411141
}
11421142

1143-
void setTxNotificationOutput(std::function<void(MicroOcpp::Transaction*,MicroOcpp::TxNotification)> notificationOutput, unsigned int connectorId) {
1143+
void setTxNotificationOutput(std::function<void(MicroOcpp::Transaction*,TxNotification)> notificationOutput, unsigned int connectorId) {
11441144
if (!context) {
11451145
MO_DBG_ERR("OCPP uninitialized"); //need to call mocpp_initialize before
11461146
return;

src/MicroOcpp.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <MicroOcpp/Core/Memory.h>
1717
#include <MicroOcpp/Model/Metering/SampledValue.h>
1818
#include <MicroOcpp/Model/Transactions/Transaction.h>
19-
#include <MicroOcpp/Model/ConnectorBase/Notification.h>
2019
#include <MicroOcpp/Model/ConnectorBase/ChargePointErrorData.h>
2120
#include <MicroOcpp/Model/ConnectorBase/ChargePointStatus.h>
2221
#include <MicroOcpp/Model/ConnectorBase/UnlockConnectorResult.h>
@@ -332,7 +331,7 @@ void setStartTxReadyInput(std::function<bool()> startTxReady, unsigned int conne
332331

333332
void setStopTxReadyInput(std::function<bool()> stopTxReady, unsigned int connectorId = 1); //Input if charger is ready for StopTransaction
334333

335-
void setTxNotificationOutput(std::function<void(MicroOcpp::Transaction*,MicroOcpp::TxNotification)> notificationOutput, unsigned int connectorId = 1); //called when transaction state changes (see TxNotification for possible events). Transaction can be null
334+
void setTxNotificationOutput(std::function<void(MicroOcpp::Transaction*,TxNotification)> notificationOutput, unsigned int connectorId = 1); //called when transaction state changes (see TxNotification for possible events). Transaction can be null
336335

337336
#if MO_ENABLE_CONNECTOR_LOCK
338337
/*

src/MicroOcpp/Model/ConnectorBase/Connector.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ void Connector::loop() {
311311
transaction->setInactive();
312312
transaction->commit();
313313

314-
updateTxNotification(TxNotification::ConnectionTimeout);
314+
updateTxNotification(TxNotification_ConnectionTimeout);
315315
}
316316
}
317317

@@ -372,7 +372,7 @@ void Connector::loop() {
372372

373373
transaction->commit();
374374

375-
updateTxNotification(TxNotification::StartTx);
375+
updateTxNotification(TxNotification_StartTx);
376376

377377
//fetchFrontRequest will create the StartTransaction and pass it to the message sender
378378
return;
@@ -416,7 +416,7 @@ void Connector::loop() {
416416

417417
transaction->commit();
418418

419-
updateTxNotification(TxNotification::StopTx);
419+
updateTxNotification(TxNotification_StopTx);
420420

421421
//fetchFrontRequest will create the StopTransaction and pass it to the message sender
422422
return;
@@ -736,7 +736,7 @@ std::shared_ptr<Transaction> Connector::beginTransaction(const char *idTag) {
736736
if (parentIdTag) {
737737
//parentIdTag known
738738
MO_DBG_INFO("connector %u reserved - abort transaction", connectorId);
739-
updateTxNotification(TxNotification::ReservationConflict);
739+
updateTxNotification(TxNotification_ReservationConflict);
740740
return nullptr;
741741
} else {
742742
//parentIdTag unkown but local authorization failed in any case
@@ -776,7 +776,7 @@ std::shared_ptr<Transaction> Connector::beginTransaction(const char *idTag) {
776776
}
777777
transaction->setAuthorized();
778778

779-
updateTxNotification(TxNotification::Authorized);
779+
updateTxNotification(TxNotification_Authorized);
780780
}
781781

782782
transaction->commit();
@@ -798,7 +798,7 @@ std::shared_ptr<Transaction> Connector::beginTransaction(const char *idTag) {
798798
MO_DBG_DEBUG("Authorize rejected (%s), abort tx process", tx->getIdTag());
799799
tx->setIdTagDeauthorized();
800800
tx->commit();
801-
updateTxNotification(TxNotification::AuthorizationRejected);
801+
updateTxNotification(TxNotification_AuthorizationRejected);
802802
return;
803803
}
804804

@@ -820,7 +820,7 @@ std::shared_ptr<Transaction> Connector::beginTransaction(const char *idTag) {
820820
MO_DBG_INFO("connector %u reserved - abort transaction", connectorId);
821821
tx->setInactive();
822822
tx->commit();
823-
updateTxNotification(TxNotification::ReservationConflict);
823+
updateTxNotification(TxNotification_ReservationConflict);
824824
return;
825825
}
826826
}
@@ -835,7 +835,7 @@ std::shared_ptr<Transaction> Connector::beginTransaction(const char *idTag) {
835835
tx->setAuthorized();
836836
tx->commit();
837837

838-
updateTxNotification(TxNotification::Authorized);
838+
updateTxNotification(TxNotification_Authorized);
839839
});
840840

841841
//capture local auth and reservation check in for timeout handler
@@ -850,7 +850,7 @@ std::shared_ptr<Transaction> Connector::beginTransaction(const char *idTag) {
850850
MO_DBG_DEBUG("Abort transaction process (%s), timeout, expired local auth", tx->getIdTag());
851851
tx->setInactive();
852852
tx->commit();
853-
updateTxNotification(TxNotification::AuthorizationTimeout);
853+
updateTxNotification(TxNotification_AuthorizationTimeout);
854854
return;
855855
}
856856

@@ -859,7 +859,7 @@ std::shared_ptr<Transaction> Connector::beginTransaction(const char *idTag) {
859859
MO_DBG_INFO("connector %u reserved (offline) - abort transaction", connectorId);
860860
tx->setInactive();
861861
tx->commit();
862-
updateTxNotification(TxNotification::ReservationConflict);
862+
updateTxNotification(TxNotification_ReservationConflict);
863863
return;
864864
}
865865

@@ -871,7 +871,7 @@ std::shared_ptr<Transaction> Connector::beginTransaction(const char *idTag) {
871871
tx->setAuthorized();
872872
tx->commit();
873873

874-
updateTxNotification(TxNotification::Authorized);
874+
updateTxNotification(TxNotification_Authorized);
875875
return;
876876
}
877877

@@ -882,14 +882,14 @@ std::shared_ptr<Transaction> Connector::beginTransaction(const char *idTag) {
882882
}
883883
tx->setAuthorized();
884884
tx->commit();
885-
updateTxNotification(TxNotification::Authorized);
885+
updateTxNotification(TxNotification_Authorized);
886886
return;
887887
}
888888

889889
MO_DBG_DEBUG("Abort transaction process (%s): timeout", tx->getIdTag());
890890
tx->setInactive();
891891
tx->commit();
892-
updateTxNotification(TxNotification::AuthorizationTimeout);
892+
updateTxNotification(TxNotification_AuthorizationTimeout);
893893
return; //offline tx disabled
894894
});
895895
context.initiateRequest(std::move(authorize));
@@ -1184,7 +1184,7 @@ std::unique_ptr<Request> Connector::fetchFrontRequest() {
11841184

11851185
const char* idTagInfoStatus = response["idTagInfo"]["status"] | "_Undefined";
11861186
if (strcmp(idTagInfoStatus, "Accepted")) {
1187-
updateTxNotification(TxNotification::DeAuthorized);
1187+
updateTxNotification(TxNotification_DeAuthorized);
11881188
}
11891189
});
11901190
auto transactionFront_capture = transactionFront;

src/MicroOcpp/Model/ConnectorBase/Connector.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
#include <MicroOcpp/Model/ConnectorBase/ChargePointStatus.h>
99
#include <MicroOcpp/Model/ConnectorBase/ChargePointErrorData.h>
10-
#include <MicroOcpp/Model/ConnectorBase/Notification.h>
1110
#include <MicroOcpp/Model/ConnectorBase/UnlockConnectorResult.h>
11+
#include <MicroOcpp/Model/Transactions/Transaction.h>
1212
#include <MicroOcpp/Core/RequestQueue.h>
1313
#include <MicroOcpp/Core/ConfigurationKeyValue.h>
1414
#include <MicroOcpp/Core/FilesystemAdapter.h>
@@ -31,7 +31,6 @@ namespace MicroOcpp {
3131
class Context;
3232
class Model;
3333
class Operation;
34-
class Transaction;
3534

3635
class Connector : public RequestEmitter, public MemoryManaged {
3736
private:

src/MicroOcpp/Model/ConnectorBase/Notification.cpp

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/MicroOcpp/Model/ConnectorBase/Notification.h

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/MicroOcpp/Model/Transactions/Transaction.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,35 @@
55
#ifndef TRANSACTION_H
66
#define TRANSACTION_H
77

8+
/* General Tx defs */
9+
#ifdef __cplusplus
10+
extern "C" {
11+
#endif //__cplusplus
12+
13+
//TxNotification - event from MO to the main firmware to notify it about transaction state changes
14+
typedef enum {
15+
UNDEFINED,
16+
17+
//Authorization events
18+
TxNotification_Authorized, //success
19+
TxNotification_AuthorizationRejected, //IdTag/token not authorized
20+
TxNotification_AuthorizationTimeout, //authorization failed - offline
21+
TxNotification_ReservationConflict, //connector/evse reserved for other IdTag
22+
23+
TxNotification_ConnectionTimeout, //user took to long to plug vehicle after the authorization
24+
TxNotification_DeAuthorized, //server rejected StartTx/TxEvent
25+
TxNotification_RemoteStart, //authorized via RemoteStartTx/RequestStartTx
26+
TxNotification_RemoteStop, //stopped via RemoteStopTx/RequestStopTx
27+
28+
//Tx lifecycle events
29+
TxNotification_StartTx, //entered running state (StartTx/TxEvent was initiated)
30+
TxNotification_StopTx, //left running state (StopTx/TxEvent was initiated)
31+
} TxNotification;
32+
33+
#ifdef __cplusplus
34+
}
35+
#endif //__cplusplus
36+
837
#ifdef __cplusplus
938

1039
#include <MicroOcpp/Core/Time.h>

src/MicroOcpp/Operations/RemoteStartTransaction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void RemoteStartTransaction::processReq(JsonObject payload) {
106106
} else {
107107
tx = selectConnector->beginTransaction_authorized(idTag);
108108
}
109-
selectConnector->updateTxNotification(TxNotification::RemoteStart);
109+
selectConnector->updateTxNotification(TxNotification_RemoteStart);
110110
if (tx) {
111111
if (chargingProfileId >= 0) {
112112
tx->setTxProfileId(chargingProfileId);

0 commit comments

Comments
 (0)