Tools: autotest: logger_metadara: parse @FieldBits to new bitmask format and ouput bitmask in xml

This commit is contained in:
Iampete1 2023-02-03 18:03:09 +00:00 committed by Peter Hall
parent 9b8a61c048
commit 82bcaae9ad
3 changed files with 26 additions and 8 deletions

View File

@ -46,9 +46,6 @@ DO NOT EDIT
fdesc = ""
print(' <tr><td>%s</td><td>%s</td></tr>' % (f, fdesc),
file=self.fh)
# if "bits" in docco.fields[f]:
# print(' <bits>%s</bits>' %
# docco.fields[f]["bits"], file=self.fh)
print(' </table>', file=self.fh)
print("", file=self.fh)

View File

@ -35,9 +35,20 @@ class XMLEmitter(emitter.Emitter):
if "description" in docco.fields[f]:
xml_description2 = etree.SubElement(xml_field, 'description')
xml_description2.text = docco.fields[f]["description"]
if "bits" in docco.fields[f]:
xml_bits = etree.SubElement(xml_field, 'bits')
xml_bits.text = docco.fields[f]["bits"]
if "bitmaskenum" in docco.fields[f]:
enum_name = docco.fields[f]["bitmaskenum"]
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
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()

View File

@ -13,6 +13,7 @@ import emit_rst
import emit_xml
import enum_parse
from enum_parse import EnumDocco
topdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../')
topdir = os.path.realpath(topdir)
@ -23,7 +24,6 @@ re_description = re.compile(r"\s*//\s*@Description\s*:\s*(.*)")
re_url = re.compile(r"\s*//\s*@URL\s*:\s*(.*)")
re_field = re.compile(r"\s*//\s*@Field\s*:\s*(\w+):\s*(.*)")
re_fieldbits = re.compile(r"\s*//\s*@FieldBits\s*:\s*(\w+):\s*(.*)")
re_fieldbits = re.compile(r"\s*//\s*@FieldBits\s*:\s*(\w+):\s*(.*)")
re_fieldbitmaskenum = re.compile(r"\s*//\s*@FieldBitmaskEnum\s*:\s*(\w+):\s*(.*)")
re_fieldvalueenum = re.compile(r"\s*//\s*@FieldValueEnum\s*:\s*(\w+):\s*(.*)")
re_vehicles = re.compile(r"\s*//\s*@Vehicles\s*:\s*(.*)")
@ -61,6 +61,7 @@ class LoggerDocco(object):
self.fields = {}
self.fields_order = []
self.vehicles = None
self.bits_enums = []
def set_description(self, desc):
self.description = desc
@ -81,8 +82,16 @@ class LoggerDocco(object):
self.fields[field]["description"] = description
def set_field_bits(self, field, bits):
bits = bits.split(",")
count = 0
entries = []
for bit in bits:
entries.append(EnumDocco.EnumEntry(bit, 1<<count, None))
count += 1
bitmask_name = self.name + field
self.bits_enums.append(EnumDocco.Enumeration(bitmask_name, entries))
self.ensure_field(field)
self.fields[field]["bits"] = bits
self.fields[field]["bitmaskenum"] = bitmask_name
def set_fieldbitmaskenum(self, field, bits):
self.ensure_field(field)
@ -199,6 +208,7 @@ class LoggerDocco(object):
def finalise_docco(self, docco):
self.doccos.append(docco)
self.enumerations += docco.bits_enums
if __name__ == '__main__':