From ebed883e8a718681b85f24c4ea60dbb3fec0976e Mon Sep 17 00:00:00 2001 From: Adrian Del Grosso <10929341+ad3154@users.noreply.github.com> Date: Sun, 31 Mar 2024 17:10:07 -0600 Subject: [PATCH] [TC]: Allow disabling the data dictionary to save on binary/RAM size --- isobus/CMakeLists.txt | 7 +++++++ isobus/include/isobus/isobus/isobus_data_dictionary.hpp | 2 ++ isobus/src/isobus_data_dictionary.cpp | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/isobus/CMakeLists.txt b/isobus/CMakeLists.txt index 3b20ae6b0..8e79ed228 100644 --- a/isobus/CMakeLists.txt +++ b/isobus/CMakeLists.txt @@ -100,6 +100,9 @@ prepend(ISOBUS_INCLUDE ${ISOBUS_INCLUDE_DIR} ${ISOBUS_INCLUDE}) option(DISABLE_CAN_STACK_LOGGER "Compiles out all logging to minimize binary size" OFF) +option(DISABLE_ISOBUS_DATA_DICTIONARY + "Disables the ISOBUS data dictionary to minimize binary size" OFF) + # Create the library from the source and include files add_library(Isobus ${ISOBUS_SRC} ${ISOBUS_INCLUDE}) add_library(${PROJECT_NAME}::Isobus ALIAS Isobus) @@ -116,6 +119,10 @@ if(CAN_STACK_DISABLE_THREADS OR ARDUINO) message(STATUS "Disabled built-in multi-threading for CAN stack.") target_compile_definitions(Isobus PUBLIC CAN_STACK_DISABLE_THREADS) endif() +if(DISABLE_ISOBUS_DATA_DICTIONARY) + message(STATUS "ISOBUS data dictionary is disabled.") + target_compile_definitions(Isobus PUBLIC DISABLE_ISOBUS_DATA_DICTIONARY) +endif() # Specify the include directory to be exported for other moduels to use. The # PUBLIC keyword here allows other libraries or exectuables to link to this diff --git a/isobus/include/isobus/isobus/isobus_data_dictionary.hpp b/isobus/include/isobus/isobus/isobus_data_dictionary.hpp index 5fb1100f9..91bfd2146 100644 --- a/isobus/include/isobus/isobus/isobus_data_dictionary.hpp +++ b/isobus/include/isobus/isobus/isobus_data_dictionary.hpp @@ -37,7 +37,9 @@ namespace isobus static const Entry &get_entry(std::uint16_t dataDictionaryIdentifier); private: +#ifndef DISABLE_ISOBUS_DATA_DICTIONARY static const Entry DDI_ENTRIES[715]; ///< A lookup table of all DDI entries in ISO11783-11 +#endif static const Entry DEFAULT_ENTRY; ///< A default "unknown" DDI to return if a DDI is not in the database }; } // namespace isobus diff --git a/isobus/src/isobus_data_dictionary.cpp b/isobus/src/isobus_data_dictionary.cpp index a33f93e06..5ce41ac8c 100644 --- a/isobus/src/isobus_data_dictionary.cpp +++ b/isobus/src/isobus_data_dictionary.cpp @@ -13,6 +13,7 @@ namespace isobus { const DataDictionary::Entry &DataDictionary::get_entry(std::uint16_t dataDictionaryIdentifier) { +#ifndef DISABLE_ISOBUS_DATA_DICTIONARY for (std::uint_fast16_t i = 0; i < sizeof(DDI_ENTRIES) / sizeof(DataDictionary::Entry); i++) { if (DDI_ENTRIES[i].ddi == dataDictionaryIdentifier) @@ -20,11 +21,13 @@ namespace isobus return DDI_ENTRIES[i]; } } +#endif return DEFAULT_ENTRY; } const DataDictionary::Entry DataDictionary::DEFAULT_ENTRY = { 65535, "Unknown", "Unknown", 0.0f }; +#ifndef DISABLE_ISOBUS_DATA_DICTIONARY // The table below is auto-generated, and is not to be edited manually. const DataDictionary::Entry DataDictionary::DDI_ENTRIES[] = { { 0, "Internal Data Base DDI", "None", 1.0f }, @@ -743,5 +746,6 @@ namespace isobus { 57344, "65534 Proprietary DDI Range", "None", 0.0f }, { 65535, "Reserved", "None", 0.0f }, }; +#endif } // namespace isobus