Skip to content

Commit

Permalink
[TC]: Allow disabling the data dictionary to save on binary/RAM size
Browse files Browse the repository at this point in the history
  • Loading branch information
ad3154 committed Apr 6, 2024
1 parent a2c1a12 commit ebed883
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions isobus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions isobus/include/isobus/isobus/isobus_data_dictionary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions isobus/src/isobus_data_dictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@ 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)
{
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 },
Expand Down Expand Up @@ -743,5 +746,6 @@ namespace isobus
{ 57344, "65534 Proprietary DDI Range", "None", 0.0f },
{ 65535, "Reserved", "None", 0.0f },
};
#endif

} // namespace isobus

0 comments on commit ebed883

Please sign in to comment.