diff --git a/Tools/msg/px_generate_uorb_compressed_fields.py b/Tools/msg/px_generate_uorb_compressed_fields.py index bcd2287e4f..f654eef440 100755 --- a/Tools/msg/px_generate_uorb_compressed_fields.py +++ b/Tools/msg/px_generate_uorb_compressed_fields.py @@ -146,6 +146,7 @@ def write_fields_to_hpp_file(file_name: str, definitions: dict, window_length: i format_list: [str]): max_tokenized_field_length, max_tokenized_field_length_msg = max( ((len(definitions[k]['fields']), k) for k in definitions), key=itemgetter(0)) + max_untokenized_field_length = max(definitions[k]['fields_total_length'] for k in definitions) max_num_orb_ids = max(len(definitions[k]['orb_ids']) for k in definitions) max_num_orb_id_dependencies = max(len(definitions[k]['dependencies']) for k in definitions) @@ -167,6 +168,7 @@ const uint8_t* orb_compressed_message_formats(); unsigned orb_compressed_message_formats_size(); static constexpr unsigned orb_tokenized_fields_max_length = {MAX_TOKENIZED_FIELD_LENGTH}; // {MAX_TOKENIZED_FIELD_LENGTH_MSG} +static constexpr unsigned orb_untokenized_fields_max_length = {MAX_UNTOKENIZED_FIELD_LENGTH}; static constexpr unsigned orb_compressed_max_num_orb_ids = {MAX_NUM_ORB_IDS}; static constexpr unsigned orb_compressed_max_num_orb_id_dependencies = {MAX_NUM_ORB_ID_DEPENDENCIES}; @@ -179,6 +181,7 @@ static constexpr unsigned orb_compressed_heatshrink_lookahead_length = {LOOKAHEA ''' .replace('{MAX_TOKENIZED_FIELD_LENGTH}', str(max_tokenized_field_length)) .replace('{MAX_TOKENIZED_FIELD_LENGTH_MSG}', max_tokenized_field_length_msg) + .replace('{MAX_UNTOKENIZED_FIELD_LENGTH}', str(max_untokenized_field_length)) .replace('{MAX_NUM_ORB_IDS}', str(max_num_orb_ids)) .replace('{MAX_NUM_ORB_ID_DEPENDENCIES}', str(max_num_orb_id_dependencies)) .replace('{WINDOW_LENGTH}', str(window_length)) diff --git a/Tools/msg/templates/uorb/msg.json.em b/Tools/msg/templates/uorb/msg.json.em index 4f6a9111ad..31be5d61aa 100644 --- a/Tools/msg/templates/uorb/msg.json.em +++ b/Tools/msg/templates/uorb/msg.json.em @@ -42,6 +42,7 @@ for field in spec.parsed_fields(): { @# join all msg files in one line e.g: "float[3] position;float[3] velocity;bool armed;" "fields": @( json.dumps(bytearray(";".join(topic_fields)+";", 'utf-8').decode('unicode_escape')) ), + "fields_total_length": @(sum([len(convert_type(field.type))+1+len(field.name)+1 for field in sorted_fields])), "orb_ids": @( json.dumps([ all_topics.index(topic) for topic in topics]) ), "main_orb_id": @( all_topics.index(name_snake_case) if name_snake_case in all_topics else -1 ), "dependencies": @( json.dumps(list(set(dependencies))) ), diff --git a/platforms/common/uORB/uORBMessageFieldsTest.cpp b/platforms/common/uORB/uORBMessageFieldsTest.cpp index 03d25b9a26..f677d9737e 100644 --- a/platforms/common/uORB/uORBMessageFieldsTest.cpp +++ b/platforms/common/uORB/uORBMessageFieldsTest.cpp @@ -53,7 +53,10 @@ public: TEST_F(uORBMessageFieldsTest, decompressed_formats_match) { - char buffer[1500]; + char buffer[1600]; + static_assert(uORB::orb_untokenized_fields_max_length < sizeof(buffer) - HEATSHRINK_DECODER_INPUT_BUFFER_SIZE(_), + "msg definition too long / buffer too short"); + uORB::MessageFormatReader format_reader(buffer, sizeof(buffer)); px4::Bitset formats_found; diff --git a/src/modules/logger/logger.cpp b/src/modules/logger/logger.cpp index 89b3cfe50d..ecb05295d6 100644 --- a/src/modules/logger/logger.cpp +++ b/src/modules/logger/logger.cpp @@ -69,6 +69,10 @@ //#define DBGPRINT //write status output every few seconds +static_assert(uORB::orb_untokenized_fields_max_length < sizeof(ulog_message_format_s::format) - + HEATSHRINK_DECODER_INPUT_BUFFER_SIZE(_), + "msg definition too long / buffer too short"); + #if defined(DBGPRINT) // needed for mallinfo #if defined(__PX4_POSIX) && !defined(__PX4_DARWIN)