diff --git a/src/core/common.h b/src/core/common.h index aa49be717..3fce072dc 100644 --- a/src/core/common.h +++ b/src/core/common.h @@ -52,22 +52,39 @@ using string_vector = std::vector; #define F_(string_name) (__pstr__##string_name) #define FL_(list_name) (__pstr__L_##list_name) +// Counter for translations created by MAKE_TRANSLATION +extern uint32_t translation_count_; +#include +#include +inline void increment_translation_count_impl(const char * translation_name) { + // Use a static set to track which translations we've already counted by name + // Using std::string ensures we compare by value, not by pointer address + // This ensures we only count each unique translation once, even if included in multiple files + static std::set counted_translations; + std::string name(translation_name); + if (counted_translations.find(name) == counted_translations.end()) { + extern uint32_t translation_count_; + translation_count_++; + counted_translations.insert(name); + } +} + // The language settings below must match system.cpp #if defined(EMSESP_TEST) // in Test mode use two languages (en & de) to save flash memory needed for the tests #define MAKE_WORD_TRANSLATION(list_name, en, de, ...) static const char * const __pstr__L_##list_name[] = {en, de, nullptr}; -#define MAKE_TRANSLATION(list_name, shortname, en, de, ...) static const char * const __pstr__L_##list_name[] = {shortname, en, de, nullptr}; +#define MAKE_TRANSLATION(list_name, shortname, en, de, ...) static const char * const __pstr__L_##list_name[] = {shortname, en, de, nullptr}; static int __translation_counter_##list_name = (increment_translation_count_impl(#list_name), 0); #elif defined(EMSESP_EN_ONLY) // EN only #define MAKE_WORD_TRANSLATION(list_name, en, ...) static const char * const __pstr__L_##list_name[] = {en, nullptr}; -#define MAKE_TRANSLATION(list_name, shortname, en, ...) static const char * const __pstr__L_##list_name[] = {shortname, en, nullptr}; +#define MAKE_TRANSLATION(list_name, shortname, en, ...) static const char * const __pstr__L_##list_name[] = {shortname, en, nullptr}; static int __translation_counter_##list_name = (increment_translation_count_impl(#list_name), 0); #elif defined(EMSESP_DE_ONLY) // EN + DE #define MAKE_WORD_TRANSLATION(list_name, en, de, ...) static const char * const __pstr__L_##list_name[] = {en, de, nullptr}; -#define MAKE_TRANSLATION(list_name, shortname, en, de, ...) static const char * const __pstr__L_##list_name[] = {shortname, en, de, nullptr}; +#define MAKE_TRANSLATION(list_name, shortname, en, de, ...) static const char * const __pstr__L_##list_name[] = {shortname, en, de, nullptr}; static int __translation_counter_##list_name = (increment_translation_count_impl(#list_name), 0); #else #define MAKE_WORD_TRANSLATION(list_name, ...) static const char * const __pstr__L_##list_name[] = {__VA_ARGS__, nullptr}; -#define MAKE_TRANSLATION(list_name, ...) static const char * const __pstr__L_##list_name[] = {__VA_ARGS__, nullptr}; +#define MAKE_TRANSLATION(list_name, ...) static const char * const __pstr__L_##list_name[] = {__VA_ARGS__, nullptr}; static int __translation_counter_##list_name = (increment_translation_count_impl(#list_name), 0); #endif #define MAKE_NOTRANSLATION(list_name, ...) static const char * const __pstr__L_##list_name[] = {__VA_ARGS__, nullptr}; diff --git a/src/core/emsesp.cpp b/src/core/emsesp.cpp index 4ee114cea..270b3ee71 100644 --- a/src/core/emsesp.cpp +++ b/src/core/emsesp.cpp @@ -26,6 +26,9 @@ static_assert(uuid::thread_safe, "uuid-common must be thread-safe"); static_assert(uuid::log::thread_safe, "uuid-log must be thread-safe"); static_assert(uuid::console::thread_safe, "uuid-console must be thread-safe"); +// Translation counter - incremented by MAKE_TRANSLATION macro (must be global, not in namespace) +uint32_t translation_count_ = 0; + namespace emsesp { // Static member definitions @@ -288,7 +291,7 @@ void EMSESP::show_ems(uuid::console::Shell & shell) { shell.printfln(" #read fails (after %d retries): %d", TxService::MAXIMUM_TX_RETRIES, txservice_.telegram_read_fail_count()); shell.printfln(" #write fails (after %d retries): %d", TxService::MAXIMUM_TX_RETRIES, txservice_.telegram_write_fail_count()); shell.printfln(" Rx line quality: %d%%", rxservice_.quality()); - shell.printfln(" Tx line quality: %d%%", (txservice_.read_quality() + txservice_.read_quality()) / 2); + shell.printfln(" Tx line quality: %d%%", (txservice_.read_quality() + txservice_.write_quality()) / 2); shell.println(); } @@ -1691,7 +1694,7 @@ void EMSESP::start() { device_library_ = { #include "device_library.h" }; - LOG_INFO("Loaded EMS device library (%d entries)", device_library_.size()); + LOG_INFO("Library loaded: %d EMS devices, %d device entities, %s", device_library_.size(), ::translation_count_, system_.languages_string().c_str()); system_.reload_settings(); // ... and store some of the settings locally diff --git a/src/core/system.cpp b/src/core/system.cpp index dbb9a9132..8e1effb19 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -107,6 +107,19 @@ bool System::command_send(const char * value, const int8_t id) { return EMSESP::txservice_.send_raw(value); // ignore id } +// return string of languages and count +std::string System::languages_string() { + std::string languages_string = std::to_string(NUM_LANGUAGES) + " languages ("; + for (uint8_t i = 0; i < NUM_LANGUAGES; i++) { + languages_string += languages[i]; + if (i != NUM_LANGUAGES - 1) { + languages_string += ","; + } + } + languages_string += ")"; + return languages_string; +} + // returns last response from MQTT bool System::command_response(const char * value, const int8_t id, JsonObject output) { JsonDocument doc; @@ -1779,7 +1792,7 @@ bool System::command_info(const char * value, const int8_t id, JsonObject output node["busReadsFailed"] = EMSESP::txservice_.telegram_read_fail_count(); node["busWritesFailed"] = EMSESP::txservice_.telegram_write_fail_count(); node["busRxLineQuality"] = EMSESP::rxservice_.quality(); - node["busTxLineQuality"] = (EMSESP::txservice_.read_quality() + EMSESP::txservice_.read_quality()) / 2; + node["busTxLineQuality"] = (EMSESP::txservice_.read_quality() + EMSESP::txservice_.write_quality()) / 2; // Settings node = output["settings"].to(); diff --git a/src/core/system.h b/src/core/system.h index c151e2fd5..01bf97f88 100644 --- a/src/core/system.h +++ b/src/core/system.h @@ -291,6 +291,8 @@ class System { void wifi_reconnect(); void show_users(uuid::console::Shell & shell); + static std::string languages_string(); + uint32_t FStotal() { return fstotal_; }