diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ab0a194..ccca06ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ - Ignore UnlockConnector when handler not set ([#271](https://github.com/matth-x/MicroOcpp/pull/271)) - Reject ChargingProfile if unit not supported ([#271](https://github.com/matth-x/MicroOcpp/pull/271)) - Fix building with debug level warn and error +- Reduce debug output FW size overhead ([#304](https://github.com/matth-x/MicroOcpp/pull/304)) - Fix transaction freeze in offline mode ([#279](https://github.com/matth-x/MicroOcpp/pull/279), [#287](https://github.com/matth-x/MicroOcpp/pull/287)) - Fix compilation error caused by `PRId32` ([#279](https://github.com/matth-x/MicroOcpp/pull/279)) - Don't load FW-mngt. module when no handlers set ([#271](https://github.com/matth-x/MicroOcpp/pull/271)) diff --git a/CMakeLists.txt b/CMakeLists.txt index fe8120b7..d46d1ecf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,6 +63,7 @@ set(MO_SRC src/MicroOcpp/Operations/InstallCertificate.cpp src/MicroOcpp/Operations/UnlockConnector.cpp src/MicroOcpp/Operations/UpdateFirmware.cpp + src/MicroOcpp/Debug.cpp src/MicroOcpp/Platform.cpp src/MicroOcpp/Core/SimpleRequestFactory.cpp src/MicroOcpp/Core/OperationRegistry.cpp diff --git a/src/MicroOcpp.cpp b/src/MicroOcpp.cpp index a2bb0cdb..d4a62e24 100644 --- a/src/MicroOcpp.cpp +++ b/src/MicroOcpp.cpp @@ -445,7 +445,6 @@ bool endTransaction(const char *idTag, const char *reason, unsigned int connecto res = endTransaction_authorized(idTag, reason, connectorId); } else { MO_DBG_INFO("endTransaction: idTag doesn't match"); - (void)0; } } return res; @@ -977,7 +976,6 @@ void setCertificateStore(std::unique_ptr certStore) certService->setCertificateStore(std::move(certStore)); } else { MO_DBG_ERR("OOM"); - (void)0; } } #endif //MO_ENABLE_CERT_MGMT diff --git a/src/MicroOcpp/Core/Configuration.cpp b/src/MicroOcpp/Core/Configuration.cpp index 090c4445..4ef802fa 100644 --- a/src/MicroOcpp/Core/Configuration.cpp +++ b/src/MicroOcpp/Core/Configuration.cpp @@ -79,7 +79,6 @@ ConfigurationContainer *declareContainer(const char *filename, bool accessible) if (container->isAccessible() != accessible) { MO_DBG_ERR("%s: conflicting accessibility declarations (expect %s)", filename, container->isAccessible() ? "accessible" : "inaccessible"); - (void)0; } return container.get(); @@ -95,7 +94,6 @@ std::shared_ptr loadConfiguration(TConfig type, const char *key, } if (container->isAccessible() != accessible) { MO_DBG_ERR("conflicting accessibility for %s", key); - (void)0; } container->loadStaticKey(*config.get(), key); return config; diff --git a/src/MicroOcpp/Core/ConfigurationContainerFlash.cpp b/src/MicroOcpp/Core/ConfigurationContainerFlash.cpp index 74263b3e..ccffc9dc 100644 --- a/src/MicroOcpp/Core/ConfigurationContainerFlash.cpp +++ b/src/MicroOcpp/Core/ConfigurationContainerFlash.cpp @@ -181,7 +181,6 @@ class ConfigurationContainerFlash : public ConfigurationContainer { } } else { MO_DBG_ERR("OOM: %s", key); - (void)0; } } diff --git a/src/MicroOcpp/Core/FilesystemUtils.cpp b/src/MicroOcpp/Core/FilesystemUtils.cpp index 3817b280..df1285fe 100644 --- a/src/MicroOcpp/Core/FilesystemUtils.cpp +++ b/src/MicroOcpp/Core/FilesystemUtils.cpp @@ -134,7 +134,6 @@ bool FilesystemUtils::remove_if(std::shared_ptr filesystem, s if (ret != 0) { MO_DBG_ERR("ftw_root: %i", ret); - (void)0; } return ret == 0; diff --git a/src/MicroOcpp/Core/FtpMbedTLS.cpp b/src/MicroOcpp/Core/FtpMbedTLS.cpp index 156ae14c..d8f6cd5c 100644 --- a/src/MicroOcpp/Core/FtpMbedTLS.cpp +++ b/src/MicroOcpp/Core/FtpMbedTLS.cpp @@ -411,7 +411,6 @@ void FtpTransferMbedTLS::send_cmd(const char *cmd, const char *arg, bool disable MO_DBG_DEBUG("SEND: %s %s", cmd, !strncmp((char*) cmd, "PASS", strlen("PASS")) ? "***" : arg ? (char*) arg : ""); - (void)0; } int ret = -1; @@ -647,7 +646,6 @@ void FtpTransferMbedTLS::process_ctrl() { return; } else if (!strncmp("200", line, 3)) { //PBSZ -> 0 and PROT -> P accepted MO_DBG_INFO("PBSZ/PROT success: %s", line); - (void)0; } else if (!strncmp("221", line, 3)) { // Server Goodbye MO_DBG_DEBUG("closing ctrl connection"); close_ctrl(); diff --git a/src/MicroOcpp/Core/Request.cpp b/src/MicroOcpp/Core/Request.cpp index 956f0609..aae5accc 100644 --- a/src/MicroOcpp/Core/Request.cpp +++ b/src/MicroOcpp/Core/Request.cpp @@ -308,7 +308,6 @@ bool Request::restore(std::unique_ptr opStorage, Model * } } else { MO_DBG_ERR("cannot set unique msgID counter"); - (void)0; //skip this step but don't abort restore } @@ -330,10 +329,8 @@ bool Request::restore(std::unique_ptr opStorage, Model * if (success) { MO_DBG_DEBUG("restored opNr %i: %s", opStore->getOpNr(), operation->getOperationType()); - (void)0; } else { MO_DBG_ERR("restore opNr %i error", opStore->getOpNr()); - (void)0; } return success; diff --git a/src/MicroOcpp/Core/RequestQueue.cpp b/src/MicroOcpp/Core/RequestQueue.cpp index ea809a52..16fa9562 100644 --- a/src/MicroOcpp/Core/RequestQueue.cpp +++ b/src/MicroOcpp/Core/RequestQueue.cpp @@ -242,10 +242,8 @@ void RequestQueue::receiveResponse(JsonArray json) { //didn't find matching Request if (json[0] == MESSAGE_TYPE_CALLERROR) { MO_DBG_DEBUG("Received CALLERROR did not abort a pending operation"); - (void)0; } else { MO_DBG_WARN("Received response doesn't match any pending operation"); - (void)0; } } } diff --git a/src/MicroOcpp/Core/RequestQueueStorageStrategy.cpp b/src/MicroOcpp/Core/RequestQueueStorageStrategy.cpp index a9b61422..26e24aaa 100644 --- a/src/MicroOcpp/Core/RequestQueueStorageStrategy.cpp +++ b/src/MicroOcpp/Core/RequestQueueStorageStrategy.cpp @@ -42,7 +42,6 @@ void VolatileRequestQueue::push_back(std::unique_ptr op) { if (queue.size() >= MO_OPERATIONCACHE_MAXSIZE) { MO_DBG_WARN("unsafe number of cached operations"); - (void)0; } queue.push_back(std::move(op)); diff --git a/src/MicroOcpp/Core/RequestStore.cpp b/src/MicroOcpp/Core/RequestStore.cpp index 056bfc9f..601eb34b 100644 --- a/src/MicroOcpp/Core/RequestStore.cpp +++ b/src/MicroOcpp/Core/RequestStore.cpp @@ -153,7 +153,6 @@ void RequestStore::advanceOpNr(unsigned int oldOpNr) { if (oldOpNr != (unsigned int) opBeginInt->getInt()) { if ((oldOpNr + MO_MAX_OPNR - (unsigned int) opBeginInt->getInt()) % MO_MAX_OPNR < 100) { MO_DBG_ERR("synchronization failure - try to fix"); - (void)0; } else { MO_DBG_ERR("synchronization failure"); return; @@ -187,7 +186,6 @@ void RequestStore::advanceOpNr(unsigned int oldOpNr) { bool success = filesystem->remove(fn); if (!success) { MO_DBG_ERR("error deleting %s", fn); - (void)0; } } diff --git a/src/MicroOcpp/Debug.cpp b/src/MicroOcpp/Debug.cpp new file mode 100644 index 00000000..71f42343 --- /dev/null +++ b/src/MicroOcpp/Debug.cpp @@ -0,0 +1,54 @@ +// matth-x/MicroOcpp +// Copyright Matthias Akstaller 2019 - 2024 +// MIT License + +#include + +#include + +const char *level_label [] = { + "", //MO_DL_NONE 0x00 + "ERROR", //MO_DL_ERROR 0x01 + "warning", //MO_DL_WARN 0x02 + "info", //MO_DL_INFO 0x03 + "debug", //MO_DL_DEBUG 0x04 + "verbose" //MO_DL_VERBOSE 0x05 +}; + +#if MO_DBG_FORMAT == MO_DF_MINIMAL +void mo_dbg_print_prefix(int level, const char *fn, int line) { + (void)0; +} + +#elif MO_DBG_FORMAT == MO_DF_COMPACT +void mo_dbg_print_prefix(int level, const char *fn, int line) { + size_t l = strlen(fn); + size_t r = l; + while (l > 0 && fn[l-1] != '/' && fn[l-1] != '\\') { + l--; + if (fn[l] == '.') r = l; + } + MO_CONSOLE_PRINTF("%.*s:%i ", (int) (r - l), fn + l, line); +} + +#elif MO_DBG_FORMAT == MO_DF_FILE_LINE +void mo_dbg_print_prefix(int level, const char *fn, int line) { + size_t l = strlen(fn); + while (l > 0 && fn[l-1] != '/' && fn[l-1] != '\\') { + l--; + } + MO_CONSOLE_PRINTF("[MO] %s (%s:%i): ", level_label[level], fn + l, line); +} + +#elif MO_DBG_FORMAT == MO_DF_FULL +void mo_dbg_print_prefix(int level, const char *fn, int line) { + MO_CONSOLE_PRINTF("[MO] %s (%s:%i): ", level_label[level], fn, line); +} + +#else +#error invalid MO_DBG_FORMAT definition +#endif + +void mo_dbg_print_suffix() { + MO_CONSOLE_PRINTF("\n"); +} diff --git a/src/MicroOcpp/Debug.h b/src/MicroOcpp/Debug.h index 59b8c227..51e71216 100644 --- a/src/MicroOcpp/Debug.h +++ b/src/MicroOcpp/Debug.h @@ -32,81 +32,52 @@ #define MO_DBG_FORMAT MO_DF_FILE_LINE //default #endif +#ifdef __cplusplus +extern "C" { +#endif -#if MO_DBG_FORMAT == MO_DF_MINIMAL -#define MO_DBG(level, X) \ - do { \ - MO_CONSOLE_PRINTF X; \ - MO_CONSOLE_PRINTF("\n"); \ - } while (0); - -#elif MO_DBG_FORMAT == MO_DF_COMPACT -#define MO_DBG(level, X) \ - do { \ - const char *_mo_file = __FILE__; \ - size_t _mo_l = sizeof(__FILE__); \ - size_t _mo_r = _mo_l; \ - while (_mo_l > 0 && _mo_file[_mo_l-1] != '/' && _mo_file[_mo_l-1] != '\\') { \ - _mo_l--; \ - if (_mo_file[_mo_l] == '.') _mo_r = _mo_l; \ - } \ - MO_CONSOLE_PRINTF("%.*s:%i ", (int) (_mo_r - _mo_l), _mo_file + _mo_l,__LINE__); \ - MO_CONSOLE_PRINTF X; \ - MO_CONSOLE_PRINTF("\n"); \ - } while (0); - -#elif MO_DBG_FORMAT == MO_DF_FILE_LINE -#define MO_DBG(level, X) \ - do { \ - const char *_mo_file = __FILE__; \ - size_t _mo_l = sizeof(__FILE__); \ - for (; _mo_l > 0 && _mo_file[_mo_l-1] != '/' && _mo_file[_mo_l-1] != '\\'; _mo_l--); \ - MO_CONSOLE_PRINTF("[MO] %s (%s:%i): ",level, _mo_file + _mo_l,__LINE__); \ - MO_CONSOLE_PRINTF X; \ - MO_CONSOLE_PRINTF("\n"); \ - } while (0); - -#elif MO_DBG_FORMAT == MO_DF_FULL -#define MO_DBG(level, X) \ - do { \ - MO_CONSOLE_PRINTF("[MO] %s (%s:%i): ",level, __FILE__,__LINE__); \ - MO_CONSOLE_PRINTF X; \ - MO_CONSOLE_PRINTF("\n"); \ - } while (0); +void mo_dbg_print_prefix(int level, const char *fn, int line); +void mo_dbg_print_suffix(); -#else -#error invalid MO_DBG_FORMAT definition +#ifdef __cplusplus +} #endif +#define MO_DBG(level, X) \ + do { \ + mo_dbg_print_prefix(level, __FILE__, __LINE__); \ + MO_CONSOLE_PRINTF X; \ + mo_dbg_print_suffix(); \ + } while (0) #if MO_DBG_LEVEL >= MO_DL_ERROR -#define MO_DBG_ERR(...) MO_DBG("ERROR",(__VA_ARGS__)) +#define MO_DBG_ERR(...) MO_DBG(MO_DL_ERROR,(__VA_ARGS__)) #else -#define MO_DBG_ERR(...) +#define MO_DBG_ERR(...) ((void)0) #endif #if MO_DBG_LEVEL >= MO_DL_WARN -#define MO_DBG_WARN(...) MO_DBG("warning",(__VA_ARGS__)) +#define MO_DBG_WARN(...) MO_DBG(MO_DL_WARN,(__VA_ARGS__)) #else -#define MO_DBG_WARN(...) +#define MO_DBG_WARN(...) ((void)0) #endif #if MO_DBG_LEVEL >= MO_DL_INFO -#define MO_DBG_INFO(...) MO_DBG("info",(__VA_ARGS__)) +#define MO_DBG_INFO(...) MO_DBG(MO_DL_INFO,(__VA_ARGS__)) #else -#define MO_DBG_INFO(...) +#define MO_DBG_INFO(...) ((void)0) #endif #if MO_DBG_LEVEL >= MO_DL_DEBUG -#define MO_DBG_DEBUG(...) MO_DBG("debug",(__VA_ARGS__)) +#define MO_DBG_DEBUG(...) MO_DBG(MO_DL_DEBUG,(__VA_ARGS__)) #else -#define MO_DBG_DEBUG(...) +#define MO_DBG_DEBUG(...) ((void)0) #endif #if MO_DBG_LEVEL >= MO_DL_VERBOSE -#define MO_DBG_VERBOSE(...) MO_DBG("verbose",(__VA_ARGS__)) +#define MO_DBG_VERBOSE(...) MO_DBG(MO_DL_VERBOSE,(__VA_ARGS__)) #else -#define MO_DBG_VERBOSE(...) +#define MO_DBG_VERBOSE(...) ((void)0) #endif #ifdef MO_TRAFFIC_OUT @@ -124,8 +95,8 @@ } while (0) #else -#define MO_DBG_TRAFFIC_OUT(...) -#define MO_DBG_TRAFFIC_IN(...) +#define MO_DBG_TRAFFIC_OUT(...) ((void)0) +#define MO_DBG_TRAFFIC_IN(...) ((void)0) #endif #endif diff --git a/src/MicroOcpp/Model/Boot/BootService.cpp b/src/MicroOcpp/Model/Boot/BootService.cpp index 68c96fa4..cd89ca66 100644 --- a/src/MicroOcpp/Model/Boot/BootService.cpp +++ b/src/MicroOcpp/Model/Boot/BootService.cpp @@ -40,7 +40,6 @@ BootService::BootService(Context& context, std::shared_ptr fi if (!preBootTransactionsBool) { MO_DBG_ERR("initialization error"); - (void)0; } //Register message handler for TriggerMessage operation diff --git a/src/MicroOcpp/Model/ConnectorBase/Connector.cpp b/src/MicroOcpp/Model/ConnectorBase/Connector.cpp index bf8da718..652851c1 100644 --- a/src/MicroOcpp/Model/ConnectorBase/Connector.cpp +++ b/src/MicroOcpp/Model/ConnectorBase/Connector.cpp @@ -68,7 +68,6 @@ Connector::Connector(Context& context, int connectorId) transaction = model.getTransactionStore()->getLatestTransaction(connectorId); } else { MO_DBG_ERR("must initialize TxStore before Connector"); - (void)0; } } @@ -398,7 +397,6 @@ void Connector::loop() { if (!transaction) { MO_DBG_ERR("could not begin FreeVend Tx"); - (void)0; } } @@ -574,7 +572,6 @@ std::shared_ptr Connector::allocateTransaction() { if (tx) { MO_DBG_DEBUG("created silent transaction"); - (void)0; } } } diff --git a/src/MicroOcpp/Model/Metering/MeterStore.cpp b/src/MicroOcpp/Model/Metering/MeterStore.cpp index 7c27308f..f3ebe2bc 100644 --- a/src/MicroOcpp/Model/Metering/MeterStore.cpp +++ b/src/MicroOcpp/Model/Metering/MeterStore.cpp @@ -20,7 +20,6 @@ TransactionMeterData::TransactionMeterData(unsigned int connectorId, unsigned in if (!filesystem) { MO_DBG_DEBUG("volatile mode"); - (void)0; } } @@ -151,7 +150,6 @@ MeterStore::MeterStore(std::shared_ptr filesystem) : filesyst if (!filesystem) { MO_DBG_DEBUG("volatile mode"); - (void)0; } } @@ -293,7 +291,6 @@ bool MeterStore::remove(unsigned int connectorId, unsigned int txNr) { if (success) { MO_DBG_DEBUG("Removed meter values for cId %u, txNr %u", connectorId, txNr); - (void)0; } else { MO_DBG_DEBUG("corrupted fs"); } diff --git a/src/MicroOcpp/Model/Reservation/Reservation.cpp b/src/MicroOcpp/Model/Reservation/Reservation.cpp index 78c40b60..9c596b85 100644 --- a/src/MicroOcpp/Model/Reservation/Reservation.cpp +++ b/src/MicroOcpp/Model/Reservation/Reservation.cpp @@ -31,7 +31,6 @@ Reservation::Reservation(Model& model, unsigned int slot) : model(model), slot(s if (!connectorIdInt || !expiryDateRawString || !idTagString || !reservationIdInt || !parentIdTagString) { MO_DBG_ERR("initialization failure"); - (void)0; } } diff --git a/src/MicroOcpp/Model/SmartCharging/SmartChargingService.cpp b/src/MicroOcpp/Model/SmartCharging/SmartChargingService.cpp index 8f77f3e3..742ca1fa 100644 --- a/src/MicroOcpp/Model/SmartCharging/SmartChargingService.cpp +++ b/src/MicroOcpp/Model/SmartCharging/SmartChargingService.cpp @@ -175,7 +175,6 @@ void SmartChargingConnector::loop(){ void SmartChargingConnector::setSmartChargingOutput(std::function limitOutput) { if (this->limitOutput) { MO_DBG_WARN("replacing existing SmartChargingOutput"); - (void)0; } this->limitOutput = limitOutput; } @@ -532,7 +531,6 @@ void SmartChargingService::setSmartChargingOutput(unsigned int connectorId, std: if (connectorId == 0) { if (this->limitOutput) { MO_DBG_WARN("replacing existing SmartChargingOutput"); - (void)0; } this->limitOutput = limitOutput; } else { diff --git a/src/MicroOcpp/Model/Transactions/TransactionDeserialize.cpp b/src/MicroOcpp/Model/Transactions/TransactionDeserialize.cpp index 895c1634..0c66ce11 100644 --- a/src/MicroOcpp/Model/Transactions/TransactionDeserialize.cpp +++ b/src/MicroOcpp/Model/Transactions/TransactionDeserialize.cpp @@ -240,7 +240,6 @@ bool deserializeTransaction(Transaction& tx, JsonObject state) { MO_DBG_DEBUG("Stop RPC | req: %i, conf: %i", tx.getStopSync().isRequested(), tx.getStopSync().isConfirmed()); if (tx.isSilent()) { MO_DBG_DEBUG(" | silent Tx"); - (void)0; } return true; diff --git a/src/MicroOcpp/Model/Variables/Variable.cpp b/src/MicroOcpp/Model/Variables/Variable.cpp index 65ff402e..ac9b10c2 100644 --- a/src/MicroOcpp/Model/Variables/Variable.cpp +++ b/src/MicroOcpp/Model/Variables/Variable.cpp @@ -96,11 +96,9 @@ const ComponentId& Variable::getComponentId() const { void Variable::setInt(int val, AttributeType) { MO_DBG_ERR("type err"); - (void)0; } void Variable::setBool(bool val, AttributeType) { MO_DBG_ERR("type err"); - (void)0; } bool Variable::setString(const char *val, AttributeType) { MO_DBG_ERR("type err"); diff --git a/src/MicroOcpp/Model/Variables/VariableService.cpp b/src/MicroOcpp/Model/Variables/VariableService.cpp index 72e4ab52..c77b06a6 100644 --- a/src/MicroOcpp/Model/Variables/VariableService.cpp +++ b/src/MicroOcpp/Model/Variables/VariableService.cpp @@ -123,7 +123,6 @@ VariableContainer *VariableService::declareContainer(const char *filename, bool if (container->isAccessible() != accessible) { MO_DBG_ERR("%s: conflicting accessibility declarations (expect %s)", filename, container->isAccessible() ? "accessible" : "inaccessible"); - (void)0; } return container.get(); @@ -142,7 +141,6 @@ Variable *VariableService::getVariable(Variable::InternalDataType type, const Co } if (container->isAccessible() != accessible) { MO_DBG_ERR("conflicting accessibility for %s", name); - (void)0; } return variable; } diff --git a/src/MicroOcpp/Operations/Authorize.cpp b/src/MicroOcpp/Operations/Authorize.cpp index 3bf34528..f3688913 100644 --- a/src/MicroOcpp/Operations/Authorize.cpp +++ b/src/MicroOcpp/Operations/Authorize.cpp @@ -18,7 +18,6 @@ Authorize::Authorize(Model& model, const char *idTagIn) : model(model) { snprintf(idTag, IDTAG_LEN_MAX + 1, "%s", idTagIn); } else { MO_DBG_WARN("Format violation of idTag. Discard idTag"); - (void)0; } } diff --git a/src/MicroOcpp/Operations/GetConfiguration.cpp b/src/MicroOcpp/Operations/GetConfiguration.cpp index 1dbaabb2..be08e9dd 100644 --- a/src/MicroOcpp/Operations/GetConfiguration.cpp +++ b/src/MicroOcpp/Operations/GetConfiguration.cpp @@ -89,7 +89,9 @@ std::unique_ptr GetConfiguration::createConf(){ } if (!doc || doc->capacity() < jcapacity) { - if (doc) {MO_DBG_ERR("OOM");(void)0;} + if (doc) { + MO_DBG_ERR("OOM"); + } errorCode = "InternalError"; errorDescription = "Query too big. Try fewer keys"; diff --git a/src/MicroOcpp/Operations/MeterValues.cpp b/src/MicroOcpp/Operations/MeterValues.cpp index 32fdd96c..b00be35f 100644 --- a/src/MicroOcpp/Operations/MeterValues.cpp +++ b/src/MicroOcpp/Operations/MeterValues.cpp @@ -42,7 +42,6 @@ std::unique_ptr MeterValues::createReq() { entries.push_back(std::move(entry)); } else { MO_DBG_ERR("Energy meter reading not convertible to JSON"); - (void)0; } } diff --git a/src/MicroOcpp/Operations/Reset.cpp b/src/MicroOcpp/Operations/Reset.cpp index 9f61eaaf..87c8f855 100644 --- a/src/MicroOcpp/Operations/Reset.cpp +++ b/src/MicroOcpp/Operations/Reset.cpp @@ -27,7 +27,6 @@ void Reset::processReq(JsonObject payload) { if (auto rService = model.getResetService()) { if (!rService->getExecuteReset()) { MO_DBG_ERR("No reset handler set. Abort operation"); - (void)0; //resetAccepted remains false } else { if (!rService->getPreReset() || rService->getPreReset()(isHard) || isHard) { diff --git a/src/MicroOcpp/Operations/StatusNotification.cpp b/src/MicroOcpp/Operations/StatusNotification.cpp index 81908e8f..94437ca5 100644 --- a/src/MicroOcpp/Operations/StatusNotification.cpp +++ b/src/MicroOcpp/Operations/StatusNotification.cpp @@ -37,7 +37,6 @@ const char *cstrFromOcppEveState(ChargePointStatus state) { #endif default: MO_DBG_ERR("ChargePointStatus not specified"); - (void)0; /* fall through */ case (ChargePointStatus::NOT_SET): return "NOT_SET"; @@ -51,7 +50,6 @@ StatusNotification::StatusNotification(int connectorId, ChargePointStatus curren if (currentStatus != ChargePointStatus::NOT_SET) { MO_DBG_INFO("New status: %s (connectorId %d)", cstrFromOcppEveState(currentStatus), connectorId); - (void)0; } } diff --git a/src/MicroOcpp/Operations/StopTransaction.cpp b/src/MicroOcpp/Operations/StopTransaction.cpp index 8cee8615..e2df5442 100644 --- a/src/MicroOcpp/Operations/StopTransaction.cpp +++ b/src/MicroOcpp/Operations/StopTransaction.cpp @@ -124,7 +124,7 @@ std::unique_ptr StopTransaction::createReq() { transaction->setStopTimestamp(transaction->getStartTimestamp() + 1); //1s behind startTime to keep order in backend DB } else { MO_DBG_ERR("failed to determine StopTx timestamp"); - (void)0; //send invalid value + //send invalid value } } diff --git a/src/MicroOcpp/Platform.cpp b/src/MicroOcpp/Platform.cpp index c05ac8e0..df3635e9 100644 --- a/src/MicroOcpp/Platform.cpp +++ b/src/MicroOcpp/Platform.cpp @@ -6,13 +6,15 @@ #ifdef MO_CUSTOM_CONSOLE +char _mo_console_msg_buf [MO_CUSTOM_CONSOLE_MAXMSGSIZE]; + namespace MicroOcpp { void (*mocpp_console_out_impl)(const char *msg) = nullptr; } -void MicroOcpp::mocpp_console_out(const char *msg) { - if (mocpp_console_out_impl) { - mocpp_console_out_impl(msg); +void _mo_console_out(const char *msg) { + if (MicroOcpp::mocpp_console_out_impl) { + MicroOcpp::mocpp_console_out_impl(msg); } } diff --git a/src/MicroOcpp/Platform.h b/src/MicroOcpp/Platform.h index eb0c5a2b..9f65e3f5 100644 --- a/src/MicroOcpp/Platform.h +++ b/src/MicroOcpp/Platform.h @@ -5,12 +5,6 @@ #ifndef MO_PLATFORM_H #define MO_PLATFORM_H -#ifdef __cplusplus -#define EXT_C extern "C" -#else -#define EXT_C -#endif - #define MO_PLATFORM_NONE 0 #define MO_PLATFORM_ARDUINO 1 #define MO_PLATFORM_ESPIDF 2 @@ -30,25 +24,32 @@ #endif #ifdef MO_CUSTOM_CONSOLE -#include +#include #ifndef MO_CUSTOM_CONSOLE_MAXMSGSIZE #define MO_CUSTOM_CONSOLE_MAXMSGSIZE 192 #endif +#ifdef __cplusplus +extern "C" { +#endif + +extern char _mo_console_msg_buf [MO_CUSTOM_CONSOLE_MAXMSGSIZE]; //define msg_buf in data section to save memory (see https://github.com/matth-x/MicroOcpp/pull/304) +void _mo_console_out(const char *msg); + void mocpp_set_console_out(void (*console_out)(const char *msg)); -namespace MicroOcpp { -void mocpp_console_out(const char *msg); +#ifdef __cplusplus } +#endif + #define MO_CONSOLE_PRINTF(X, ...) \ do { \ - char msg [MO_CUSTOM_CONSOLE_MAXMSGSIZE]; \ - auto _mo_ret = snprintf(msg, MO_CUSTOM_CONSOLE_MAXMSGSIZE, X, ##__VA_ARGS__); \ + auto _mo_ret = snprintf(_mo_console_msg_buf, MO_CUSTOM_CONSOLE_MAXMSGSIZE, X, ##__VA_ARGS__); \ if (_mo_ret < 0 || _mo_ret >= MO_CUSTOM_CONSOLE_MAXMSGSIZE) { \ - sprintf(msg + MO_CUSTOM_CONSOLE_MAXMSGSIZE - 7, " [...]"); \ + sprintf(_mo_console_msg_buf + MO_CUSTOM_CONSOLE_MAXMSGSIZE - 7, " [...]"); \ } \ - MicroOcpp::mocpp_console_out(msg); \ + _mo_console_out(_mo_console_msg_buf); \ } while (0) #else #define mocpp_set_console_out(X) \ @@ -76,9 +77,9 @@ void mocpp_console_out(const char *msg); #endif #ifdef MO_CUSTOM_TIMER -void mocpp_set_timer(unsigned long (*get_ms)()); +extern "C" void mocpp_set_timer(unsigned long (*get_ms)()); -unsigned long mocpp_tick_ms_custom(); +extern "C" unsigned long mocpp_tick_ms_custom(); #define mocpp_tick_ms mocpp_tick_ms_custom #else @@ -86,10 +87,10 @@ unsigned long mocpp_tick_ms_custom(); #include #define mocpp_tick_ms millis #elif MO_PLATFORM == MO_PLATFORM_ESPIDF -unsigned long mocpp_tick_ms_espidf(); +extern "C" unsigned long mocpp_tick_ms_espidf(); #define mocpp_tick_ms mocpp_tick_ms_espidf #elif MO_PLATFORM == MO_PLATFORM_UNIX -unsigned long mocpp_tick_ms_unix(); +extern "C" unsigned long mocpp_tick_ms_unix(); #define mocpp_tick_ms mocpp_tick_ms_unix #endif #endif