logger: add compressed events metadata file if it exists in the ROMFS

Allows to decode events not (yet) on main.
The file is currently ~15KB.
This commit is contained in:
Beat Küng
2022-10-05 07:44:55 +02:00
parent 02035d94aa
commit dafead6f20
6 changed files with 90 additions and 1 deletions
@@ -90,6 +90,7 @@ add_custom_command(OUTPUT ${component_general_json} ${component_general_json}.xz
--version-file ${PX4_BINARY_DIR}/src/lib/version/build_git_version.h
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/generate_crc.py
${component_general_json}
${PX4_BINARY_DIR}/events/all_events.json.xz
--output ${component_information_header}
DEPENDS
generate_component_general.py
@@ -2,6 +2,7 @@
import argparse
import os
import hashlib
parser = argparse.ArgumentParser(description="""Generate the COMPONENT_INFORMATION checksums (CRC32) header file""")
parser.add_argument('--output', metavar='checksums.h', help='output file')
@@ -30,6 +31,16 @@ def crc_update(buf, crc_table, crc):
crc_table = create_table()
def sha256sum(filename):
h = hashlib.sha256()
b = bytearray(128*1024)
mv = memoryview(b)
with open(filename, 'rb', buffering=0) as f:
for n in iter(lambda : f.readinto(mv), 0):
h.update(mv[:n])
return h.hexdigest()
with open(filename, 'w') as outfile:
outfile.write("#pragma once\n")
outfile.write("#include <stdint.h>\n")
@@ -38,10 +49,12 @@ with open(filename, 'w') as outfile:
file_crc = 0
for line in open(filename, "rb"):
file_crc = crc_update(line, crc_table, file_crc)
file_sha256 = sha256sum(filename)
basename = os.path.basename(filename)
identifier = basename.split('.')[0]
outfile.write("static constexpr uint32_t {:}_crc = {:};\n".format(identifier, file_crc))
outfile.write("static constexpr const char *{:}_sha256 = \"{:}\";\n".format(identifier, file_sha256))
outfile.write("}\n")