From 2c0e2aab154302b84514334692a1c9bcd96789ba Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Mon, 11 Sep 2017 11:59:37 +1000 Subject: [PATCH] Tools: LogAnalyzer: derive motor count from frame type MSG --- Tools/LogAnalyzer/DataflashLog.py | 26 ++++++++++++++++++++- Tools/LogAnalyzer/tests/TestMotorBalance.py | 3 +++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Tools/LogAnalyzer/DataflashLog.py b/Tools/LogAnalyzer/DataflashLog.py index 1c71f325af..cccef464e3 100644 --- a/Tools/LogAnalyzer/DataflashLog.py +++ b/Tools/LogAnalyzer/DataflashLog.py @@ -429,6 +429,7 @@ class DataflashLog(object): self.lineCount = 0 self.skippedLines = 0 self.backpatch_these_modechanges = [] + self.frame = None if logfile: self.read(logfile, format, ignoreBadlines) @@ -451,6 +452,23 @@ class DataflashLog(object): else: return "" + def num_motor_channels(self): + motor_channels_for_frame = { + "QUAD": 4, + "HEXA": 6, + "Y6": 6, + "OCTA": 8, + "OCTA_QUAD": 8, +# "HELI": 1, +# "HELI_DUAL": 2, + "TRI": 3, + "SINGLE": 1, + "COAX": 2, + "TAILSITTER": 1, + "DODECA_HEXA" : 12, + } + return motor_channels_for_frame[self.frame] + def read(self, logfile, format="auto", ignoreBadlines=False): '''returns on successful log read (including bad lines if ignoreBadlines==True), will throw an Exception otherwise''' # TODO: dataflash log parsing code is pretty hacky, should re-write more methodically @@ -558,6 +576,9 @@ class DataflashLog(object): for (lineNumber, e) in self.backpatch_these_modechanges: self.handleModeChange(lineNumber, e) + def set_frame(self, frame): + self.frame = frame + def process(self, lineNumber, e): if e.NAME == 'FMT': cls = e.to_class() @@ -569,8 +590,11 @@ class DataflashLog(object): elif e.NAME == "PARM": self.parameters[e.Name] = e.Value elif e.NAME == "MSG": + tokens = e.Message.split(' ') + if not self.frame: + if "Frame" in tokens[0]: + self.set_frame(tokens[1]) if not self.vehicleType: - tokens = e.Message.split(' ') try: self.set_vehicleType_from_MSG_vehicle(tokens[0]); except ValueError: diff --git a/Tools/LogAnalyzer/tests/TestMotorBalance.py b/Tools/LogAnalyzer/tests/TestMotorBalance.py index 85e9e7f1f8..17f4c1e94b 100644 --- a/Tools/LogAnalyzer/tests/TestMotorBalance.py +++ b/Tools/LogAnalyzer/tests/TestMotorBalance.py @@ -35,6 +35,9 @@ class TestBalanceTwist(Test): if num_channels < len(ch[i]): num_channels = len(ch[i]) + if logdata.frame: + num_channels = logdata.num_motor_channels() + if num_channels < 2: return