2019-10-18 00:33:17 -03:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2024-10-19 20:47:13 -03:00
|
|
|
'''
|
|
|
|
AP_FLAKE8_CLEAN
|
|
|
|
'''
|
|
|
|
|
2019-10-18 00:33:17 -03:00
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
import argparse
|
2020-03-20 03:05:57 -03:00
|
|
|
import copy
|
2019-10-18 00:33:17 -03:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import emit_html
|
|
|
|
import emit_rst
|
|
|
|
import emit_xml
|
2023-05-02 10:42:24 -03:00
|
|
|
import emit_md
|
2019-10-18 00:33:17 -03:00
|
|
|
|
2020-03-21 03:56:15 -03:00
|
|
|
import enum_parse
|
2023-02-03 14:03:09 -04:00
|
|
|
from enum_parse import EnumDocco
|
2020-03-21 03:56:15 -03:00
|
|
|
|
2019-10-18 00:33:17 -03:00
|
|
|
topdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../')
|
|
|
|
topdir = os.path.realpath(topdir)
|
|
|
|
|
2023-12-22 06:52:52 -04:00
|
|
|
# Regular expressions for finding message information in code comments
|
2020-03-20 03:05:57 -03:00
|
|
|
re_loggermessage = re.compile(r"@LoggerMessage\s*:\s*([\w,]+)", re.MULTILINE)
|
2019-10-18 00:33:17 -03:00
|
|
|
re_commentline = re.compile(r"\s*//")
|
|
|
|
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*(.*)")
|
2020-03-21 03:56:15 -03:00
|
|
|
re_fieldbitmaskenum = re.compile(r"\s*//\s*@FieldBitmaskEnum\s*:\s*(\w+):\s*(.*)")
|
|
|
|
re_fieldvalueenum = re.compile(r"\s*//\s*@FieldValueEnum\s*:\s*(\w+):\s*(.*)")
|
2019-10-18 00:33:17 -03:00
|
|
|
re_vehicles = re.compile(r"\s*//\s*@Vehicles\s*:\s*(.*)")
|
|
|
|
|
2023-12-22 06:52:52 -04:00
|
|
|
# Regular expressions for finding message definitions in structure format
|
|
|
|
re_start_messagedef = re.compile(r"^\s*{?\s*LOG_[A-Z0-9_]+_[MSGTA]+[A-Z0-9_]*\s*,")
|
|
|
|
re_deffield = r'[\s\\]*"?([\w\-#?%]+)"?\s*'
|
2024-10-19 20:47:13 -03:00
|
|
|
re_full_messagedef = re.compile(r'\s*LOG_\w+\s*,\s*\w+\([^)]+\)[\s\\]*,' +
|
|
|
|
f'{re_deffield},{re_deffield},' +
|
|
|
|
r'[\s\\]*"?([\w,]+)"?[\s\\]*,' +
|
|
|
|
f'{re_deffield},{re_deffield}',
|
|
|
|
re.MULTILINE)
|
2023-12-22 06:52:52 -04:00
|
|
|
re_fmt_define = re.compile(r'#define\s+(\w+_FMT)\s+"([\w\-#?%]+)"')
|
|
|
|
re_units_define = re.compile(r'#define\s+(\w+_UNITS)\s+"([\w\-#?%]+)"')
|
|
|
|
re_mults_define = re.compile(r'#define\s+(\w+_MULTS)\s+"([\w\-#?%]+)"')
|
|
|
|
|
|
|
|
# Regular expressions for finding message definitions in Write calls
|
|
|
|
re_start_writecall = re.compile(r"\s*[AP:]*logger[\(\)]*.Write[StreamingCrcl]*\(")
|
|
|
|
re_writefield = r'\s*"([\w\-#?%,]+)"\s*'
|
2024-10-19 20:47:13 -03:00
|
|
|
re_full_writecall = re.compile(r'\s*[AP:]*logger[\(\)]*.Write[StreamingCrcl]*\(' +
|
|
|
|
f'{re_writefield},{re_writefield},{re_writefield},({re_writefield},{re_writefield})?',
|
|
|
|
re.MULTILINE)
|
2023-12-22 06:52:52 -04:00
|
|
|
|
|
|
|
# Regular expression for extracting unit and multipliers from structure
|
|
|
|
re_units_mults_struct = re.compile(r"^\s*{\s*'([\w\-#?%!/])',"+r'\s*"?([\w\-#?%./]*)"?\s*}')
|
|
|
|
|
2019-10-18 00:33:17 -03:00
|
|
|
# TODO: validate URLS actually return 200
|
|
|
|
|
2023-12-22 06:52:52 -04:00
|
|
|
# Lookup tables are populated by reading LogStructure.h
|
|
|
|
log_fmt_lookup = {}
|
|
|
|
log_units_lookup = {}
|
|
|
|
log_mult_lookup = {}
|
|
|
|
|
|
|
|
# Lookup table to convert multiplier to prefix
|
|
|
|
mult_prefix_lookup = {
|
|
|
|
0: "",
|
|
|
|
1: "",
|
|
|
|
1e-1: "d", # deci-
|
|
|
|
1e-2: "c", # centi-
|
|
|
|
1e-3: "m", # milli-
|
|
|
|
1e-6: "μ", # micro-
|
|
|
|
1e-9: "n" # nano-
|
|
|
|
}
|
2019-10-18 00:33:17 -03:00
|
|
|
|
2024-10-19 20:47:13 -03:00
|
|
|
|
2019-10-18 00:33:17 -03:00
|
|
|
class LoggerDocco(object):
|
|
|
|
|
|
|
|
vehicle_map = {
|
2020-03-26 21:51:16 -03:00
|
|
|
"Rover": "Rover",
|
2019-10-18 00:33:17 -03:00
|
|
|
"Sub": "ArduSub",
|
|
|
|
"Copter": "ArduCopter",
|
|
|
|
"Plane": "ArduPlane",
|
|
|
|
"Tracker": "AntennaTracker",
|
2022-01-07 00:47:29 -04:00
|
|
|
"Blimp": "Blimp",
|
2019-10-18 00:33:17 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
def __init__(self, vehicle):
|
|
|
|
self.vehicle = vehicle
|
|
|
|
self.doccos = []
|
|
|
|
self.emitters = [
|
|
|
|
emit_html.HTMLEmitter(),
|
|
|
|
emit_rst.RSTEmitter(),
|
|
|
|
emit_xml.XMLEmitter(),
|
2023-05-02 10:42:24 -03:00
|
|
|
emit_md.MDEmitter(),
|
2019-10-18 00:33:17 -03:00
|
|
|
]
|
2023-12-22 06:52:52 -04:00
|
|
|
self.msg_fmts_list = {}
|
|
|
|
self.msg_units_list = {}
|
|
|
|
self.msg_mults_list = {}
|
2019-10-18 00:33:17 -03:00
|
|
|
|
|
|
|
class Docco(object):
|
|
|
|
|
|
|
|
def __init__(self, name):
|
|
|
|
self.name = name
|
|
|
|
self.url = None
|
2024-10-19 20:47:13 -03:00
|
|
|
if isinstance(name, list):
|
2023-12-22 06:52:52 -04:00
|
|
|
self.description = [None] * len(name)
|
|
|
|
else:
|
|
|
|
self.description = None
|
2019-10-18 00:33:17 -03:00
|
|
|
self.fields = {}
|
2020-03-20 03:05:57 -03:00
|
|
|
self.fields_order = []
|
2019-10-18 00:33:17 -03:00
|
|
|
self.vehicles = None
|
2023-02-03 14:03:09 -04:00
|
|
|
self.bits_enums = []
|
2019-10-18 00:33:17 -03:00
|
|
|
|
2023-12-22 06:52:52 -04:00
|
|
|
def add_name(self, name):
|
|
|
|
# If self.name/description aren't lists, convert them
|
2024-10-19 20:47:13 -03:00
|
|
|
if isinstance(self.name, str):
|
2023-12-22 06:52:52 -04:00
|
|
|
self.name = [self.name]
|
|
|
|
self.description = [self.description]
|
|
|
|
# Replace any existing empty descriptions with empty strings
|
2024-10-19 20:47:13 -03:00
|
|
|
for i in range(0, len(self.description)):
|
2023-12-22 06:52:52 -04:00
|
|
|
if self.description[i] is None:
|
|
|
|
self.description[i] = ""
|
|
|
|
# Extend the name and description lists
|
2024-10-19 20:47:13 -03:00
|
|
|
if isinstance(name, list):
|
2023-12-22 06:52:52 -04:00
|
|
|
self.name.extend(name)
|
|
|
|
self.description.extend([None] * len(name))
|
|
|
|
else:
|
|
|
|
self.name.append(name)
|
|
|
|
self.description.append(None)
|
|
|
|
|
2019-10-18 00:33:17 -03:00
|
|
|
def set_description(self, desc):
|
2024-10-19 20:47:13 -03:00
|
|
|
if isinstance(self.description, list):
|
|
|
|
for i in range(0, len(self.description)):
|
2023-12-22 06:52:52 -04:00
|
|
|
if self.description[i] is None:
|
|
|
|
self.description[i] = desc
|
|
|
|
else:
|
|
|
|
self.description = desc
|
2019-10-18 00:33:17 -03:00
|
|
|
|
|
|
|
def set_url(self, url):
|
|
|
|
self.url = url
|
|
|
|
|
2020-03-20 03:05:57 -03:00
|
|
|
def ensure_field(self, field):
|
2019-10-18 00:33:17 -03:00
|
|
|
if field not in self.fields:
|
|
|
|
self.fields[field] = {}
|
2020-03-20 03:05:57 -03:00
|
|
|
self.fields_order.append(field)
|
|
|
|
|
|
|
|
def set_field_description(self, field, description):
|
2021-04-26 22:17:11 -03:00
|
|
|
if field in self.fields:
|
|
|
|
raise ValueError("Already have field %s in %s" %
|
|
|
|
(field, self.name))
|
2020-03-20 03:05:57 -03:00
|
|
|
self.ensure_field(field)
|
2019-10-18 00:33:17 -03:00
|
|
|
self.fields[field]["description"] = description
|
|
|
|
|
|
|
|
def set_field_bits(self, field, bits):
|
2023-02-03 14:03:09 -04:00
|
|
|
bits = bits.split(",")
|
|
|
|
count = 0
|
|
|
|
entries = []
|
|
|
|
for bit in bits:
|
2024-10-19 20:47:13 -03:00
|
|
|
entries.append(EnumDocco.EnumEntry(bit, 1 << count, None))
|
2023-02-03 14:03:09 -04:00
|
|
|
count += 1
|
|
|
|
bitmask_name = self.name + field
|
|
|
|
self.bits_enums.append(EnumDocco.Enumeration(bitmask_name, entries))
|
2020-03-20 03:05:57 -03:00
|
|
|
self.ensure_field(field)
|
2023-02-03 14:03:09 -04:00
|
|
|
self.fields[field]["bitmaskenum"] = bitmask_name
|
2019-10-18 00:33:17 -03:00
|
|
|
|
2020-03-21 03:56:15 -03:00
|
|
|
def set_fieldbitmaskenum(self, field, bits):
|
|
|
|
self.ensure_field(field)
|
|
|
|
self.fields[field]["bitmaskenum"] = bits
|
|
|
|
|
2023-12-22 06:52:52 -04:00
|
|
|
def set_fieldvalueenum(self, field, bits):
|
2020-03-21 03:56:15 -03:00
|
|
|
self.ensure_field(field)
|
|
|
|
self.fields[field]["valueenum"] = bits
|
|
|
|
|
2019-10-18 00:33:17 -03:00
|
|
|
def set_vehicles(self, vehicles):
|
|
|
|
self.vehicles = vehicles
|
|
|
|
|
2023-12-22 06:52:52 -04:00
|
|
|
def set_fmts(self, fmts):
|
|
|
|
# If no fields are defined, do nothing
|
2024-10-19 20:47:13 -03:00
|
|
|
if len(self.fields_order) == 0:
|
2023-12-22 06:52:52 -04:00
|
|
|
return
|
|
|
|
# Make sure lengths match up
|
|
|
|
if len(fmts) != len(self.fields_order):
|
|
|
|
print(f"Number of fmts don't match fields: msg={self.name} fmts={fmts} num_fields={len(self.fields_order)}")
|
|
|
|
return
|
|
|
|
# Loop through the list
|
2024-10-19 20:47:13 -03:00
|
|
|
for idx in range(0, len(fmts)):
|
2023-12-22 06:52:52 -04:00
|
|
|
if fmts[idx] in log_fmt_lookup:
|
|
|
|
self.fields[self.fields_order[idx]]["fmt"] = log_fmt_lookup[fmts[idx]]
|
|
|
|
else:
|
|
|
|
print(f"Unrecognised format character: {fmts[idx]} in message {self.name}")
|
|
|
|
|
|
|
|
def set_units(self, units, mults):
|
|
|
|
# If no fields are defined, do nothing
|
2024-10-19 20:47:13 -03:00
|
|
|
if len(self.fields_order) == 0:
|
2023-12-22 06:52:52 -04:00
|
|
|
return
|
|
|
|
# Make sure lengths match up
|
|
|
|
if len(units) != len(self.fields_order) or len(units) != len(mults):
|
2024-10-19 20:47:13 -03:00
|
|
|
print(f"Number of units/mults/fields don't match: msg={self.name} units={units} mults={mults} num_fields={len(self.fields_order)}") # noqa:E501
|
2023-12-22 06:52:52 -04:00
|
|
|
return
|
|
|
|
# Loop through the list
|
2024-10-19 20:47:13 -03:00
|
|
|
for idx in range(0, len(units)):
|
2023-12-22 06:52:52 -04:00
|
|
|
# Get the index into fields from field_order
|
|
|
|
f = self.fields_order[idx]
|
|
|
|
# Convert unit char to base unit
|
|
|
|
if units[idx] in log_units_lookup:
|
|
|
|
baseunit = log_units_lookup[units[idx]]
|
|
|
|
else:
|
|
|
|
print(f"Unrecognised units character: {units[idx]} in message {self.name}")
|
|
|
|
continue
|
|
|
|
# Do nothing if this field has no unit defined
|
|
|
|
if baseunit == "":
|
|
|
|
continue
|
|
|
|
# Convert mult char to value
|
|
|
|
if mults[idx] in log_mult_lookup:
|
|
|
|
mult = log_mult_lookup[mults[idx]]
|
|
|
|
mult_num = float(mult)
|
|
|
|
else:
|
|
|
|
print(f"Unrecognised multiplier character: {mults[idx]} in message {self.name}")
|
|
|
|
continue
|
|
|
|
# Check if the defined format for this field contains its own multiplier
|
|
|
|
# If so, the presented value will be the base-unit directly
|
|
|
|
if 'fmt' in self.fields[f] and self.fields[f]['fmt'].endswith("* 100"):
|
|
|
|
self.fields[f]["units"] = baseunit
|
|
|
|
elif 'fmt' in self.fields[f] and "latitude/longitude" in self.fields[f]['fmt']:
|
|
|
|
self.fields[f]["units"] = baseunit
|
|
|
|
# Check if we have a defined prefix for this multiplier
|
|
|
|
elif mult_num in mult_prefix_lookup:
|
|
|
|
self.fields[f]["units"] = f"{mult_prefix_lookup[mult_num]}{baseunit}"
|
|
|
|
# If all else fails, set the unit as the multipler and base unit together
|
|
|
|
else:
|
|
|
|
self.fields[f]["units"] = f"{mult} {baseunit}"
|
|
|
|
|
|
|
|
def populate_lookups(self):
|
|
|
|
# Initialise the lookup tables
|
|
|
|
# Read the contents of the LogStructure.h file
|
|
|
|
structfile = os.path.join(topdir, "libraries", "AP_Logger", "LogStructure.h")
|
|
|
|
with open(structfile) as f:
|
|
|
|
lines = f.readlines()
|
|
|
|
f.close()
|
|
|
|
# Initialise current section to none
|
|
|
|
section = "none"
|
|
|
|
# Loop through the lines in the file
|
|
|
|
for line in lines:
|
|
|
|
# Look for the start of fmt/unit/mult info
|
|
|
|
if line.startswith("Format characters"):
|
|
|
|
section = "fmt"
|
|
|
|
elif line.startswith("const struct UnitStructure"):
|
|
|
|
section = "units"
|
|
|
|
elif line.startswith("const struct MultiplierStructure"):
|
|
|
|
section = "mult"
|
|
|
|
# Read formats from code comment, e.g.:
|
|
|
|
# b : int8_t
|
|
|
|
elif section == "fmt":
|
|
|
|
if "*/" in line:
|
|
|
|
section = "none"
|
|
|
|
else:
|
|
|
|
parts = line.split(":")
|
|
|
|
log_fmt_lookup[parts[0].strip()] = parts[1].strip()
|
|
|
|
# Read units or multipliers from C struct definition, e.g.:
|
|
|
|
# { '2', 1e2 }, or { 'J', "W.s" },
|
|
|
|
elif section != "none":
|
|
|
|
if "};" in line:
|
|
|
|
section = "none"
|
|
|
|
else:
|
|
|
|
u = re_units_mults_struct.search(line)
|
|
|
|
if u is not None and section == "units":
|
|
|
|
log_units_lookup[u.group(1)] = u.group(2)
|
|
|
|
if u is not None and section == "mult":
|
|
|
|
log_mult_lookup[u.group(1)] = u.group(2)
|
|
|
|
|
2019-10-18 00:33:17 -03:00
|
|
|
def search_for_files(self, dirs_to_search):
|
|
|
|
_next = []
|
|
|
|
for _dir in dirs_to_search:
|
2020-08-19 05:50:53 -03:00
|
|
|
_dir = os.path.join(topdir, _dir)
|
2019-10-18 00:33:17 -03:00
|
|
|
for entry in os.listdir(_dir):
|
|
|
|
filepath = os.path.join(_dir, entry)
|
|
|
|
if os.path.isdir(filepath):
|
|
|
|
_next.append(filepath)
|
|
|
|
continue
|
|
|
|
(name, extension) = os.path.splitext(filepath)
|
|
|
|
if extension not in [".cpp", ".h"]:
|
|
|
|
continue
|
|
|
|
self.files.append(filepath)
|
|
|
|
if len(_next):
|
|
|
|
self.search_for_files(_next)
|
|
|
|
|
2024-10-19 20:47:13 -03:00
|
|
|
def parse_messagedef(self, messagedef):
|
2023-12-22 06:52:52 -04:00
|
|
|
# Merge concatinated strings and remove comments
|
|
|
|
messagedef = re.sub(r'"\s+"', '', messagedef)
|
|
|
|
messagedef = re.sub(r'//[^\n]*', '', messagedef)
|
|
|
|
# Extract details from a structure definition
|
|
|
|
d = re_full_messagedef.search(messagedef)
|
|
|
|
if d is not None:
|
|
|
|
self.msg_fmts_list[d.group(1)] = d.group(2)
|
|
|
|
self.msg_units_list[d.group(1)] = d.group(4)
|
|
|
|
self.msg_mults_list[d.group(1)] = d.group(5)
|
|
|
|
return
|
|
|
|
# Extract details from a WriteStreaming call
|
|
|
|
d = re_full_writecall.search(messagedef)
|
|
|
|
if d is not None:
|
|
|
|
if d.group(1) in self.msg_fmts_list:
|
|
|
|
return
|
|
|
|
if d.group(5) is None:
|
|
|
|
self.msg_fmts_list[d.group(1)] = d.group(3)
|
|
|
|
else:
|
|
|
|
self.msg_fmts_list[d.group(1)] = d.group(6)
|
|
|
|
self.msg_units_list[d.group(1)] = d.group(3)
|
|
|
|
self.msg_mults_list[d.group(1)] = d.group(5)
|
|
|
|
return
|
|
|
|
# Didn't parse
|
2024-10-19 20:47:13 -03:00
|
|
|
# print(f"Unable to parse: {messagedef}")
|
2023-12-22 06:52:52 -04:00
|
|
|
|
2024-10-19 20:47:13 -03:00
|
|
|
def search_messagedef_start(self, line, prevmessagedef=""):
|
2023-12-22 06:52:52 -04:00
|
|
|
# Look for the start of a structure definition
|
|
|
|
d = re_start_messagedef.search(line)
|
|
|
|
if d is not None:
|
|
|
|
messagedef = line
|
|
|
|
if "}" in line:
|
|
|
|
self.parse_messagedef(messagedef)
|
|
|
|
return ""
|
|
|
|
else:
|
|
|
|
return messagedef
|
|
|
|
# Look for a new call to WriteStreaming
|
|
|
|
d = re_start_writecall.search(line)
|
|
|
|
if d is not None:
|
|
|
|
messagedef = line
|
|
|
|
if ";" in line:
|
|
|
|
self.parse_messagedef(messagedef)
|
|
|
|
return ""
|
|
|
|
else:
|
|
|
|
return messagedef
|
|
|
|
# If we didn't find a new one, continue with any previous state
|
|
|
|
return prevmessagedef
|
|
|
|
|
2019-10-18 00:33:17 -03:00
|
|
|
def parse_file(self, filepath):
|
|
|
|
with open(filepath) as f:
|
2024-10-19 20:47:13 -03:00
|
|
|
# print("Opened (%s)" % filepath)
|
2019-10-18 00:33:17 -03:00
|
|
|
lines = f.readlines()
|
|
|
|
f.close()
|
2024-10-19 20:47:13 -03:00
|
|
|
|
2024-02-01 23:25:57 -04:00
|
|
|
def debug(x):
|
|
|
|
pass
|
2024-10-19 20:47:13 -03:00
|
|
|
# if filepath == "/home/pbarker/rc/ardupilot/libraries/AP_HAL/AnalogIn.h":
|
|
|
|
# debug = print
|
2023-12-22 06:52:52 -04:00
|
|
|
state_outside = "outside"
|
|
|
|
state_inside = "inside"
|
|
|
|
messagedef = ""
|
|
|
|
state = state_outside
|
|
|
|
docco = None
|
2019-10-18 00:33:17 -03:00
|
|
|
for line in lines:
|
2024-02-01 23:25:57 -04:00
|
|
|
debug(f"{state}: {line}")
|
2023-12-22 06:52:52 -04:00
|
|
|
if messagedef:
|
|
|
|
messagedef = messagedef + line
|
|
|
|
if "}" in line or ";" in line:
|
|
|
|
self.parse_messagedef(messagedef)
|
|
|
|
messagedef = ""
|
2019-10-18 00:33:17 -03:00
|
|
|
if state == state_outside:
|
2023-12-22 06:52:52 -04:00
|
|
|
# Check for start of a message definition
|
2024-10-19 20:47:13 -03:00
|
|
|
messagedef = self.search_messagedef_start(line, messagedef)
|
2023-12-22 06:52:52 -04:00
|
|
|
|
|
|
|
# Check for fmt/unit/mult #define
|
|
|
|
u = re_fmt_define.search(line)
|
|
|
|
if u is not None:
|
|
|
|
self.msg_fmts_list[u.group(1)] = u.group(2)
|
|
|
|
u = re_units_define.search(line)
|
|
|
|
if u is not None:
|
|
|
|
self.msg_units_list[u.group(1)] = u.group(2)
|
|
|
|
u = re_mults_define.search(line)
|
|
|
|
if u is not None:
|
|
|
|
self.msg_mults_list[u.group(1)] = u.group(2)
|
|
|
|
|
|
|
|
# Check for the @LoggerMessage tag indicating the start of the docco block
|
2019-10-18 00:33:17 -03:00
|
|
|
m = re_loggermessage.search(line)
|
|
|
|
if m is None:
|
|
|
|
continue
|
|
|
|
name = m.group(1)
|
2020-03-20 03:05:57 -03:00
|
|
|
if "," in name:
|
|
|
|
name = name.split(",")
|
2019-10-18 00:33:17 -03:00
|
|
|
state = state_inside
|
|
|
|
docco = LoggerDocco.Docco(name)
|
|
|
|
elif state == state_inside:
|
2023-12-22 06:52:52 -04:00
|
|
|
# If this line is not a comment, then this is the end of the docco block
|
2019-10-18 00:33:17 -03:00
|
|
|
if not re_commentline.match(line):
|
|
|
|
state = state_outside
|
|
|
|
if docco.vehicles is None or self.vehicle in docco.vehicles:
|
|
|
|
self.finalise_docco(docco)
|
2023-12-22 06:52:52 -04:00
|
|
|
messagedef = self.search_messagedef_start(line)
|
2019-10-18 00:33:17 -03:00
|
|
|
continue
|
2023-12-22 06:52:52 -04:00
|
|
|
# Check for an multiple @LoggerMessage lines in this docco block
|
|
|
|
m = re_loggermessage.search(line)
|
|
|
|
if m is not None:
|
|
|
|
name = m.group(1)
|
|
|
|
if "," in name:
|
|
|
|
name = name.split(",")
|
|
|
|
docco.add_name(name)
|
|
|
|
continue
|
|
|
|
# Find and extract data from the various docco fields
|
2019-10-18 00:33:17 -03:00
|
|
|
m = re_description.match(line)
|
|
|
|
if m is not None:
|
|
|
|
docco.set_description(m.group(1))
|
|
|
|
continue
|
|
|
|
m = re_url.match(line)
|
|
|
|
if m is not None:
|
|
|
|
docco.set_url(m.group(1))
|
|
|
|
continue
|
|
|
|
m = re_field.match(line)
|
|
|
|
if m is not None:
|
|
|
|
docco.set_field_description(m.group(1), m.group(2))
|
|
|
|
continue
|
|
|
|
m = re_fieldbits.match(line)
|
|
|
|
if m is not None:
|
|
|
|
docco.set_field_bits(m.group(1), m.group(2))
|
|
|
|
continue
|
2020-03-21 03:56:15 -03:00
|
|
|
m = re_fieldbitmaskenum.match(line)
|
|
|
|
if m is not None:
|
|
|
|
docco.set_fieldbitmaskenum(m.group(1), m.group(2))
|
|
|
|
continue
|
|
|
|
m = re_fieldvalueenum.match(line)
|
|
|
|
if m is not None:
|
2023-12-22 06:52:52 -04:00
|
|
|
docco.set_fieldvalueenum(m.group(1), m.group(2))
|
2020-03-21 03:56:15 -03:00
|
|
|
continue
|
2019-10-18 00:33:17 -03:00
|
|
|
m = re_vehicles.match(line)
|
|
|
|
if m is not None:
|
|
|
|
docco.set_vehicles([x.strip() for x in m.group(1).split(',')])
|
|
|
|
continue
|
|
|
|
print("Unknown field (%s)" % str(line))
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
def parse_files(self):
|
|
|
|
for _file in self.files:
|
|
|
|
self.parse_file(_file)
|
|
|
|
|
|
|
|
def emit_output(self):
|
2020-03-20 03:05:57 -03:00
|
|
|
# expand things like PIDR,PIDQ,PIDA into multiple doccos
|
|
|
|
new_doccos = []
|
|
|
|
for docco in self.doccos:
|
2023-08-31 18:45:12 -03:00
|
|
|
if isinstance(docco.name, list):
|
2024-10-19 20:47:13 -03:00
|
|
|
for name, desc in zip(docco.name, docco.description):
|
2020-03-20 03:05:57 -03:00
|
|
|
tmpdocco = copy.copy(docco)
|
|
|
|
tmpdocco.name = name
|
2023-12-22 06:52:52 -04:00
|
|
|
tmpdocco.description = desc
|
2020-03-20 03:05:57 -03:00
|
|
|
new_doccos.append(tmpdocco)
|
|
|
|
else:
|
|
|
|
new_doccos.append(docco)
|
2020-04-01 18:34:42 -03:00
|
|
|
new_doccos = sorted(new_doccos, key=lambda x : x.name)
|
|
|
|
|
2023-12-22 06:52:52 -04:00
|
|
|
# Try to attach the formats/units/multipliers
|
|
|
|
for docco in new_doccos:
|
|
|
|
# Apply the Formats to the docco
|
|
|
|
if docco.name in self.msg_fmts_list:
|
|
|
|
if "FMT" in self.msg_fmts_list[docco.name]:
|
|
|
|
if self.msg_fmts_list[docco.name] in self.msg_fmts_list:
|
|
|
|
docco.set_fmts(self.msg_fmts_list[self.msg_fmts_list[docco.name]])
|
|
|
|
else:
|
|
|
|
docco.set_fmts(self.msg_fmts_list[docco.name])
|
|
|
|
else:
|
|
|
|
print(f"No formats found for message {docco.name}")
|
|
|
|
# Get the Units
|
|
|
|
units = None
|
|
|
|
if docco.name in self.msg_units_list:
|
|
|
|
if "UNITS" in self.msg_units_list[docco.name]:
|
|
|
|
if self.msg_units_list[docco.name] in self.msg_units_list:
|
|
|
|
units = self.msg_units_list[self.msg_units_list[docco.name]]
|
|
|
|
else:
|
|
|
|
units = self.msg_units_list[docco.name]
|
|
|
|
# Get the Multipliers
|
|
|
|
mults = None
|
|
|
|
if docco.name in self.msg_mults_list:
|
|
|
|
if "MULTS" in self.msg_mults_list[docco.name]:
|
|
|
|
if self.msg_mults_list[docco.name] in self.msg_mults_list:
|
|
|
|
mults = self.msg_mults_list[self.msg_mults_list[docco.name]]
|
|
|
|
else:
|
|
|
|
mults = self.msg_mults_list[docco.name]
|
|
|
|
# Apply the units/mults to the docco
|
|
|
|
if units is not None and mults is not None:
|
2024-10-19 20:47:13 -03:00
|
|
|
docco.set_units(units, mults)
|
2023-12-22 06:52:52 -04:00
|
|
|
elif units is not None or mults is not None:
|
|
|
|
print(f"Cannot find matching units/mults for message {docco.name}")
|
|
|
|
|
2020-03-21 03:56:15 -03:00
|
|
|
enums_by_name = {}
|
|
|
|
for enum in self.enumerations:
|
|
|
|
enums_by_name[enum.name] = enum
|
2019-10-18 00:33:17 -03:00
|
|
|
for emitter in self.emitters:
|
2020-03-21 03:56:15 -03:00
|
|
|
emitter.emit(new_doccos, enums_by_name)
|
2019-10-18 00:33:17 -03:00
|
|
|
|
|
|
|
def run(self):
|
2023-12-22 06:52:52 -04:00
|
|
|
self.populate_lookups()
|
2020-03-21 03:56:15 -03:00
|
|
|
self.enumerations = enum_parse.EnumDocco(self.vehicle).get_enumerations()
|
2019-10-18 00:33:17 -03:00
|
|
|
self.files = []
|
|
|
|
self.search_for_files([self.vehicle_map[self.vehicle], "libraries"])
|
|
|
|
self.parse_files()
|
|
|
|
self.emit_output()
|
|
|
|
|
|
|
|
def finalise_docco(self, docco):
|
|
|
|
self.doccos.append(docco)
|
2023-02-03 14:03:09 -04:00
|
|
|
self.enumerations += docco.bits_enums
|
2019-10-18 00:33:17 -03:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
parser = argparse.ArgumentParser(description="Parse parameters.")
|
|
|
|
parser.add_argument("-v", "--verbose", dest='verbose', action='store_true', default=False, help="show debugging output")
|
|
|
|
parser.add_argument("--vehicle", required=True, help="Vehicle type to generate for")
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
s = LoggerDocco(args.vehicle)
|
|
|
|
|
|
|
|
if args.vehicle not in s.vehicle_map:
|
|
|
|
print("Invalid vehicle (choose from: %s)" % str(s.vehicle_map.keys()))
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
s.run()
|