From e7b369473b67c8015153881f354bd97f65f4df9c Mon Sep 17 00:00:00 2001 From: ES-Alexander Date: Tue, 2 May 2023 23:42:24 +1000 Subject: [PATCH] Tools: logger_metadata: add emit_md --- .gitignore | 1 + Tools/autotest/logger_metadata/emit_md.py | 82 +++++++++++++++++++++++ Tools/autotest/logger_metadata/parse.py | 2 + 3 files changed, 85 insertions(+) create mode 100644 Tools/autotest/logger_metadata/emit_md.py diff --git a/.gitignore b/.gitignore index 58913bfed4..c5fae8527c 100644 --- a/.gitignore +++ b/.gitignore @@ -125,6 +125,7 @@ parameters.edn LogMessages.html LogMessages.rst LogMessages.xml +LogMessages.md # JetBrains IDE files .idea/* # CMake diff --git a/Tools/autotest/logger_metadata/emit_md.py b/Tools/autotest/logger_metadata/emit_md.py new file mode 100644 index 0000000000..d6d1cb7877 --- /dev/null +++ b/Tools/autotest/logger_metadata/emit_md.py @@ -0,0 +1,82 @@ +import os +import time +import emitter + +class MDEmitter(emitter.Emitter): + def preface(self): + if os.getenv('BRDOC') is not None: + now = time.strftime('%Y-%m-%dT%H:%M:%S%z') + now = now[:-2] + ':' + now[-2:] + return '\n'.join(( + '+++', + 'title = "Onboard Log Messages"', + 'description = "Message listing for DataFlash autopilot logs."', + f'date = {now}', + 'template = "docs/page.html"', + 'sort_by = "weight"', + 'weight = 30', + 'draft = false', + '[extra]', + 'toc = true', + 'top = false', + '+++\n', + '', + 'This is a list of log messages which may be present in DataFlash (`.bin`) ' + 'logs produced and stored onboard ArduSub vehicles (see [Log Parameters]' + '(../parameters/#log-parameters) for creation details). ' + 'It is possible to [add a new message]' + '(https://ardupilot.org/dev/docs/code-overview-adding-a-new-log-message.html) ' + 'by modifying the firmware.\n', + 'DataFlash logs can be downloaded and analysed ' + '[from a computer](http://www.ardusub.com/reference/data-logging.html#downloading) ' + 'or [through BlueOS]' + '(@/software/onboard/BlueOS-1.1/advanced-usage/index.md#log-browser).\n' + )) + + return """ + + +

Onboard Message Log Messages

+
+ +

This is a list of log messages which may be present in logs produced and stored onboard ArduPilot vehicles.

+ + +[toc exclude="Onboard Message Log Messages"] + +""" + def postface(self): + return "" + + def start(self): + self.fh = open("LogMessages.md", mode='w') + print(self.preface(), file=self.fh) + + def emit(self, doccos, enumerations=None): + self.start() + for docco in doccos: + print(f'## {docco.name}', file=self.fh) + desc = '' + if docco.description is not None: + desc += docco.description + 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) + 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) + print("", file=self.fh) + self.stop() + + def stop(self): + print(self.postface(), file=self.fh) + self.fh.close() diff --git a/Tools/autotest/logger_metadata/parse.py b/Tools/autotest/logger_metadata/parse.py index f7d4bd9e71..d66d557cf3 100755 --- a/Tools/autotest/logger_metadata/parse.py +++ b/Tools/autotest/logger_metadata/parse.py @@ -11,6 +11,7 @@ import sys import emit_html import emit_rst import emit_xml +import emit_md import enum_parse from enum_parse import EnumDocco @@ -50,6 +51,7 @@ class LoggerDocco(object): emit_html.HTMLEmitter(), emit_rst.RSTEmitter(), emit_xml.XMLEmitter(), + emit_md.MDEmitter(), ] class Docco(object):