Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logger Metadata: Provide format and unit/multiplier info for log messages #25861

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions Tools/autotest/logger_metadata/emit_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,24 @@ def emit(self, doccos, enumerations):
print(' <h2>%s</h2>' %
docco.description, file=self.fh)
print(' <table>', file=self.fh)
print(" <tr><th>FieldName</th><th>Description</th><tr>",
print(" <tr><th>FieldName</th><th>Units/Type</th><th>Description</th><tr>",
file=self.fh)
for f in docco.fields_order:
if "description" in docco.fields[f]:
fdesc = docco.fields[f]["description"]
else:
fdesc = ""
print(' <tr><td>%s</td><td>%s</td></tr>' % (f, fdesc),
if "units" in docco.fields[f] and docco.fields[f]["units"]!="":
ftypeunits = docco.fields[f]["units"]
elif "fmt" in docco.fields[f] and "char" in docco.fields[f]["fmt"]:
ftypeunits = docco.fields[f]["fmt"]
elif "bitmaskenum" in docco.fields[f]:
ftypeunits = "bitmask"
elif "valueenum" in docco.fields[f]:
ftypeunits = "enum"
else:
ftypeunits = ""
print(' <tr><td>%s</td><td>%s</td><td>%s</td></tr>' % (f, ftypeunits, fdesc),
file=self.fh)
print(' </table>', file=self.fh)

Expand Down
14 changes: 12 additions & 2 deletions Tools/autotest/logger_metadata/emit_md.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,23 @@ def emit(self, doccos, enumerations=None):
if docco.url is not None:
desc += f' ([Read more...]({docco.url}))'
print(desc, file=self.fh)
print("\n|FieldName|Description|\n|---|---|", file=self.fh)
print("\n|FieldName|Units/Type|Description|\n|---|---|---|", file=self.fh)
for f in docco.fields_order:
if "description" in docco.fields[f]:
fdesc = docco.fields[f]["description"]
else:
fdesc = ""
print(f'|{f}|{fdesc}|', file=self.fh)
if "units" in docco.fields[f] and docco.fields[f]["units"]!="":
ftypeunits = docco.fields[f]["units"]
elif "fmt" in docco.fields[f] and "char" in docco.fields[f]["fmt"]:
ftypeunits = docco.fields[f]["fmt"]
elif "bitmaskenum" in docco.fields[f]:
ftypeunits = "bitmask"
elif "valueenum" in docco.fields[f]:
ftypeunits = "enum"
else:
ftypeunits = ""
print(f'|{f}|{ftypeunits}|{fdesc}|', file=self.fh)
print("", file=self.fh)
self.stop()

Expand Down
14 changes: 13 additions & 1 deletion Tools/autotest/logger_metadata/emit_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,23 @@ def emit(self, doccos, enumerations):

rows = []
for f in docco.fields_order:
# Populate the description column
if "description" in docco.fields[f]:
fdesc = docco.fields[f]["description"]
else:
fdesc = ""
# Initialise Type/Unit and check for enum/bitfields
ftypeunit = ""
fieldnamething = None
if "bitmaskenum" in docco.fields[f]:
fieldnamething = "bitmaskenum"
table_label = "Bitmask values"
ftypeunit = "bitmask"
elif "valueenum" in docco.fields[f]:
fieldnamething = "valueenum"
table_label = "Values"
ftypeunit = "enum"
# If an enum/bitmask is defined, build the table
if fieldnamething is not None:
enum_name = docco.fields[f][fieldnamething]
if enum_name not in enumerations:
Expand All @@ -62,7 +68,13 @@ def emit(self, doccos, enumerations):
comment = ""
bitmaskrows.append([enumentry.name, str(enumentry.value), comment])
fdesc += "\n%s:\n\n%s" % (table_label, self.tablify(bitmaskrows))
rows.append([f, fdesc])
# Populate the Type/Units column
if "units" in docco.fields[f] and docco.fields[f]["units"] != "":
ftypeunit = docco.fields[f]["units"]
elif "fmt" in docco.fields[f] and "char" in docco.fields[f]["fmt"]:
ftypeunit = docco.fields[f]["fmt"]
# Add the new row
rows.append([f, ftypeunit, fdesc])

print(self.tablify(rows), file=self.fh)

Expand Down
35 changes: 24 additions & 11 deletions Tools/autotest/logger_metadata/emit_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,37 @@ def emit(self, doccos, enumerations):

xml_fields = etree.SubElement(xml_logformat, 'fields')
for f in docco.fields_order:
xml_field = etree.SubElement(xml_fields, 'field', name=f)
units = docco.fields[f]['units'] if "units" in docco.fields[f] else ""
fmt = docco.fields[f]['fmt'] if "fmt" in docco.fields[f] else ""
xml_field = etree.SubElement(xml_fields, 'field', name=f, units=units, type=fmt)
if "description" in docco.fields[f]:
xml_description2 = etree.SubElement(xml_field, 'description')
xml_description2.text = docco.fields[f]["description"]
# Check for enum/bitfield
fieldnamething = None
if "bitmaskenum" in docco.fields[f]:
enum_name = docco.fields[f]["bitmaskenum"]
fieldnamething = "bitmaskenum"
xmlenumtag = "bitmask"
xmlentrytag = "bit"
elif "valueenum" in docco.fields[f]:
fieldnamething = "valueenum"
xmlenumtag = "enum"
xmlentrytag = "element"
# If an enum/bitmask is defined, include this in the XML
if fieldnamething is not None:
enum_name = docco.fields[f][fieldnamething]
if enum_name not in enumerations:
raise Exception("Unknown enum (%s) (have %s)" %
(enum_name, "\n".join(sorted(enumerations.keys()))))
bit_mask = enumerations[enum_name]
xml_bitmask = etree.SubElement(xml_field, 'bitmask')
for bit in bit_mask.entries:
xml_bitmask_bit = etree.SubElement(xml_bitmask, 'bit', name=bit.name)
xml_bitmask_bit_value = etree.SubElement(xml_bitmask_bit, 'value')
xml_bitmask_bit_value.text = str(bit.value)
if bit.comment is not None:
xml_bitmask_bit_comment = etree.SubElement(xml_bitmask_bit, 'description')
xml_bitmask_bit_comment.text = bit.comment
enum = enumerations[enum_name]
xml_enum = etree.SubElement(xml_field, xmlenumtag, name=enum_name)
for entry in enum.entries:
xml_enum_entry = etree.SubElement(xml_enum, xmlentrytag, name=entry.name)
xml_enum_entry_value = etree.SubElement(xml_enum_entry, 'value')
xml_enum_entry_value.text = str(entry.value)
if entry.comment is not None:
xml_enum_entry_comment = etree.SubElement(xml_enum_entry, 'description')
xml_enum_entry_comment.text = entry.comment
if xml_fields.text is None and not len(xml_fields):
xml_fields.text = '\n' # add </param> on next line in case of empty element.
self.stop()
Expand Down
1 change: 1 addition & 0 deletions Tools/autotest/logger_metadata/enum_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class EnumDocco(object):
"Copter": "ArduCopter",
"Plane": "ArduPlane",
"Tracker": "AntennaTracker",
"Blimp": "Blimp",
}

def __init__(self, vehicle):
Expand Down
Loading