@@ -355,61 +355,170 @@ bool deserializeTransactionEventChargingState(const char *chargingStateCstr, Tra
355355
356356#endif // MO_ENABLE_V201
357357
358+ #if MO_ENABLE_V201
359+ bool g_ocpp_tx_compat_v201;
360+
361+ void ocpp_tx_compat_setV201 (bool isV201) {
362+ g_ocpp_tx_compat_v201 = isV201;
363+ }
364+ #endif
365+
358366int ocpp_tx_getTransactionId (OCPP_Transaction *tx) {
367+ #if MO_ENABLE_V201
368+ if (g_ocpp_tx_compat_v201) {
369+ MO_DBG_ERR (" only supported in v16" );
370+ return -1 ;
371+ }
372+ #endif // MO_ENABLE_V201
359373 return reinterpret_cast <MicroOcpp::Transaction*>(tx)->getTransactionId ();
360374}
375+ #if MO_ENABLE_V201
376+ const char *ocpp_tx_getTransactionIdV201 (OCPP_Transaction *tx) {
377+ if (!g_ocpp_tx_compat_v201) {
378+ MO_DBG_ERR (" only supported in v201" );
379+ return nullptr ;
380+ }
381+ return reinterpret_cast <MicroOcpp::Ocpp201::Transaction*>(tx)->transactionId ;
382+ }
383+ #endif // MO_ENABLE_V201
361384bool ocpp_tx_isAuthorized (OCPP_Transaction *tx) {
385+ #if MO_ENABLE_V201
386+ if (g_ocpp_tx_compat_v201) {
387+ return reinterpret_cast <MicroOcpp::Ocpp201::Transaction*>(tx)->isAuthorized ;
388+ }
389+ #endif // MO_ENABLE_V201
362390 return reinterpret_cast <MicroOcpp::Transaction*>(tx)->isAuthorized ();
363391}
364392bool ocpp_tx_isIdTagDeauthorized (OCPP_Transaction *tx) {
393+ #if MO_ENABLE_V201
394+ if (g_ocpp_tx_compat_v201) {
395+ return reinterpret_cast <MicroOcpp::Ocpp201::Transaction*>(tx)->isDeauthorized ;
396+ }
397+ #endif // MO_ENABLE_V201
365398 return reinterpret_cast <MicroOcpp::Transaction*>(tx)->isIdTagDeauthorized ();
366399}
367400
368401bool ocpp_tx_isRunning (OCPP_Transaction *tx) {
402+ #if MO_ENABLE_V201
403+ if (g_ocpp_tx_compat_v201) {
404+ auto transaction = reinterpret_cast <MicroOcpp::Ocpp201::Transaction*>(tx);
405+ return transaction->started && !transaction->stopped ;
406+ }
407+ #endif // MO_ENABLE_V201
369408 return reinterpret_cast <MicroOcpp::Transaction*>(tx)->isRunning ();
370409}
371410bool ocpp_tx_isActive (OCPP_Transaction *tx) {
411+ #if MO_ENABLE_V201
412+ if (g_ocpp_tx_compat_v201) {
413+ return reinterpret_cast <MicroOcpp::Ocpp201::Transaction*>(tx)->active ;
414+ }
415+ #endif // MO_ENABLE_V201
372416 return reinterpret_cast <MicroOcpp::Transaction*>(tx)->isActive ();
373417}
374418bool ocpp_tx_isAborted (OCPP_Transaction *tx) {
419+ #if MO_ENABLE_V201
420+ if (g_ocpp_tx_compat_v201) {
421+ auto transaction = reinterpret_cast <MicroOcpp::Ocpp201::Transaction*>(tx);
422+ return !transaction->active && !transaction->started ;
423+ }
424+ #endif // MO_ENABLE_V201
375425 return reinterpret_cast <MicroOcpp::Transaction*>(tx)->isAborted ();
376426}
377427bool ocpp_tx_isCompleted (OCPP_Transaction *tx) {
428+ #if MO_ENABLE_V201
429+ if (g_ocpp_tx_compat_v201) {
430+ auto transaction = reinterpret_cast <MicroOcpp::Ocpp201::Transaction*>(tx);
431+ return transaction->stopped && transaction->seqNos .empty ();
432+ }
433+ #endif // MO_ENABLE_V201
378434 return reinterpret_cast <MicroOcpp::Transaction*>(tx)->isCompleted ();
379435}
380436
381437const char *ocpp_tx_getIdTag (OCPP_Transaction *tx) {
438+ #if MO_ENABLE_V201
439+ if (g_ocpp_tx_compat_v201) {
440+ auto transaction = reinterpret_cast <MicroOcpp::Ocpp201::Transaction*>(tx);
441+ return transaction->idToken .get ();
442+ }
443+ #endif // MO_ENABLE_V201
382444 return reinterpret_cast <MicroOcpp::Transaction*>(tx)->getIdTag ();
383445}
384446
385447bool ocpp_tx_getBeginTimestamp (OCPP_Transaction *tx, char *buf, size_t len) {
448+ #if MO_ENABLE_V201
449+ if (g_ocpp_tx_compat_v201) {
450+ return reinterpret_cast <MicroOcpp::Ocpp201::Transaction*>(tx)->beginTimestamp .toJsonString (buf, len);
451+ }
452+ #endif // MO_ENABLE_V201
386453 return reinterpret_cast <MicroOcpp::Transaction*>(tx)->getBeginTimestamp ().toJsonString (buf, len);
387454}
388455
389456int32_t ocpp_tx_getMeterStart (OCPP_Transaction *tx) {
457+ #if MO_ENABLE_V201
458+ if (g_ocpp_tx_compat_v201) {
459+ MO_DBG_ERR (" only supported in v16" );
460+ return -1 ;
461+ }
462+ #endif // MO_ENABLE_V201
390463 return reinterpret_cast <MicroOcpp::Transaction*>(tx)->getMeterStart ();
391464}
392465
393466bool ocpp_tx_getStartTimestamp (OCPP_Transaction *tx, char *buf, size_t len) {
467+ #if MO_ENABLE_V201
468+ if (g_ocpp_tx_compat_v201) {
469+ MO_DBG_ERR (" only supported in v16" );
470+ return -1 ;
471+ }
472+ #endif // MO_ENABLE_V201
394473 return reinterpret_cast <MicroOcpp::Transaction*>(tx)->getStartTimestamp ().toJsonString (buf, len);
395474}
396475
397476const char *ocpp_tx_getStopIdTag (OCPP_Transaction *tx) {
477+ #if MO_ENABLE_V201
478+ if (g_ocpp_tx_compat_v201) {
479+ auto transaction = reinterpret_cast <MicroOcpp::Ocpp201::Transaction*>(tx);
480+ return transaction->stopIdToken ? transaction->stopIdToken ->get () : " " ;
481+ }
482+ #endif // MO_ENABLE_V201
398483 return reinterpret_cast <MicroOcpp::Transaction*>(tx)->getStopIdTag ();
399484}
400485
401486int32_t ocpp_tx_getMeterStop (OCPP_Transaction *tx) {
487+ #if MO_ENABLE_V201
488+ if (g_ocpp_tx_compat_v201) {
489+ MO_DBG_ERR (" only supported in v16" );
490+ return -1 ;
491+ }
492+ #endif // MO_ENABLE_V201
402493 return reinterpret_cast <MicroOcpp::Transaction*>(tx)->getMeterStop ();
403494}
404495
405496void ocpp_tx_setMeterStop (OCPP_Transaction* tx, int32_t meter) {
497+ #if MO_ENABLE_V201
498+ if (g_ocpp_tx_compat_v201) {
499+ MO_DBG_ERR (" only supported in v16" );
500+ return ;
501+ }
502+ #endif // MO_ENABLE_V201
406503 return reinterpret_cast <MicroOcpp::Transaction*>(tx)->setMeterStop (meter);
407504}
408505
409506bool ocpp_tx_getStopTimestamp (OCPP_Transaction *tx, char *buf, size_t len) {
507+ #if MO_ENABLE_V201
508+ if (g_ocpp_tx_compat_v201) {
509+ MO_DBG_ERR (" only supported in v16" );
510+ return -1 ;
511+ }
512+ #endif // MO_ENABLE_V201
410513 return reinterpret_cast <MicroOcpp::Transaction*>(tx)->getStopTimestamp ().toJsonString (buf, len);
411514}
412515
413516const char *ocpp_tx_getStopReason (OCPP_Transaction *tx) {
517+ #if MO_ENABLE_V201
518+ if (g_ocpp_tx_compat_v201) {
519+ auto transaction = reinterpret_cast <MicroOcpp::Ocpp201::Transaction*>(tx);
520+ return serializeTransactionStoppedReason (transaction->stoppedReason );
521+ }
522+ #endif // MO_ENABLE_V201
414523 return reinterpret_cast <MicroOcpp::Transaction*>(tx)->getStopReason ();
415524}
0 commit comments