Skip to content

Commit 85e1d93

Browse files
committed
TC_068_CS / Stop transaction - IdTag in StopTransaction matches IdTag in StartTransaction / code simplification
1 parent 5cfcc02 commit 85e1d93

File tree

2 files changed

+20
-29
lines changed

2 files changed

+20
-29
lines changed

examples/ESP/main.cpp

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -103,35 +103,14 @@ void loop() {
103103
if (/* RFID chip detected? */ false) {
104104
String idTag = "0123456789ABCD"; //e.g. idTag = RFID.readIdTag();
105105

106-
if (!getTransaction()) {
107-
//no transaction running or preparing. Begin a new transaction
108-
Serial.printf("[main] Begin Transaction with idTag %s\n", idTag.c_str());
109-
110-
/*
111-
* Begin Transaction. The OCPP lib will prepare transaction by checking the Authorization
112-
* and listen to the ConnectorPlugged Input. When the Authorization succeeds and an EV
113-
* is plugged, the OCPP lib will send the StartTransaction
114-
*/
115-
auto ret = beginTransaction(idTag.c_str());
116-
117-
if (ret) {
118-
Serial.println(F("[main] Transaction initiated. OCPP lib will send a StartTransaction when" \
119-
"ConnectorPlugged Input becomes true and if the Authorization succeeds"));
120-
} else {
121-
Serial.println(F("[main] No transaction initiated"));
122-
}
123-
124-
} else {
125-
//Transaction already initiated. Check if to stop current Tx by RFID card
126-
if (idTag.equals(getTransactionIdTag())) {
127-
//card matches -> user can stop Tx
128-
Serial.println(F("[main] End transaction by RFID card"));
129-
130-
endTransaction(idTag.c_str());
131-
} else {
132-
Serial.println(F("[main] Cannot end transaction by RFID card (different card?)"));
133-
}
134-
}
106+
/*
107+
* Begin Transaction. The OCPP lib will prepare transaction by checking the Authorization
108+
* and listen to the ConnectorPlugged Input. When the Authorization succeeds and an EV
109+
* is plugged, the OCPP lib will send the StartTransaction
110+
*
111+
* If transaction already exists, stop by RFID card (if idTag or parentIdTag match)
112+
*/
113+
authorize(idTag.c_str());
135114
}
136115

137116
//... see MicroOcpp.h for more possibilities

src/MicroOcpp.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,18 @@ void authorize(const char *idTag, OnReceiveConfListener onConf, OnAbortListener
13971397
MO_DBG_ERR("idTag format violation. Expect c-style string with at most %u characters", IDTAG_LEN_MAX);
13981398
return;
13991399
}
1400+
1401+
//check for active transactions
1402+
for (int i = 1; i <= context->getModel().getNumConnectors(); i++) {
1403+
if (isTransactionActive(i)) {
1404+
//this will check both parentIdTag and idTag
1405+
if (endTransaction(idTag, "Local", i)) {
1406+
MO_DBG_INFO("ended active transaction on connector %d for idTag '%s'", i, idTag);
1407+
return;
1408+
}
1409+
}
1410+
}
1411+
14001412
auto authorize = makeRequest(
14011413
new Authorize(context->getModel(), idTag));
14021414
if (onConf)

0 commit comments

Comments
 (0)