2017-09-28 19:20:59 -03:00
|
|
|
from LogAnalyzer import Test, TestResult
|
2014-01-27 02:38:57 -04:00
|
|
|
import DataflashLog
|
2017-09-28 19:20:59 -03:00
|
|
|
from VehicleType import VehicleType
|
2014-01-27 02:38:57 -04:00
|
|
|
|
|
|
|
import math # for isnan()
|
|
|
|
|
|
|
|
|
|
|
|
class TestParams(Test):
|
2014-08-12 12:54:15 -03:00
|
|
|
'''test for any obviously bad parameters in the config'''
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
Test.__init__(self)
|
|
|
|
self.name = "Parameters"
|
|
|
|
|
|
|
|
|
|
|
|
# helper functions
|
|
|
|
def __checkParamIsEqual(self, paramName, expectedValue, logdata):
|
|
|
|
value = logdata.parameters[paramName]
|
|
|
|
if value != expectedValue:
|
|
|
|
self.result.status = TestResult.StatusType.FAIL
|
2017-07-21 20:28:28 -03:00
|
|
|
self.result.statusMessage = self.result.statusMessage + "%s set to %s, expecting %s\n" % (paramName, repr(value), repr(expectedValue))
|
2014-08-12 12:54:15 -03:00
|
|
|
def __checkParamIsLessThan(self, paramName, maxValue, logdata):
|
|
|
|
value = logdata.parameters[paramName]
|
|
|
|
if value >= maxValue:
|
|
|
|
self.result.status = TestResult.StatusType.FAIL
|
2017-07-21 20:28:28 -03:00
|
|
|
self.result.statusMessage = self.result.statusMessage + "%s set to %s, expecting less than %s\n" % (paramName, repr(value), repr(maxValue))
|
2014-08-12 12:54:15 -03:00
|
|
|
def __checkParamIsMoreThan(self, paramName, minValue, logdata):
|
|
|
|
value = logdata.parameters[paramName]
|
|
|
|
if value <= minValue:
|
|
|
|
self.result.status = TestResult.StatusType.FAIL
|
2017-07-21 20:28:28 -03:00
|
|
|
self.result.statusMessage = self.result.statusMessage + "%s set to %s, expecting less than %s\n" % (paramName, repr(value), repr(minValue))
|
2014-08-12 12:54:15 -03:00
|
|
|
|
|
|
|
|
|
|
|
def run(self, logdata, verbose):
|
|
|
|
self.result = TestResult()
|
|
|
|
self.result.status = TestResult.StatusType.GOOD # GOOD by default, tests below will override it if they fail
|
|
|
|
|
|
|
|
# check all params for NaN
|
2020-07-16 20:22:10 -03:00
|
|
|
for name,value in logdata.parameters.items():
|
2014-08-12 12:54:15 -03:00
|
|
|
if math.isnan(value):
|
|
|
|
self.result.status = TestResult.StatusType.FAIL
|
|
|
|
self.result.statusMessage = self.result.statusMessage + name + " is NaN\n"
|
|
|
|
|
2014-08-12 12:58:02 -03:00
|
|
|
try:
|
|
|
|
# add parameter checks below using the helper functions, any failures will trigger a FAIL status and accumulate info in statusMessage
|
|
|
|
# if more complex checking or correlations are required you can access parameter values directly using the logdata.parameters[paramName] dict
|
2017-09-23 22:51:51 -03:00
|
|
|
if logdata.vehicleType == VehicleType.Copter:
|
2014-08-12 12:58:02 -03:00
|
|
|
self.__checkParamIsEqual ("MAG_ENABLE", 1, logdata)
|
2017-12-01 18:11:11 -04:00
|
|
|
if "THR_MIN" in logdata.parameters:
|
|
|
|
self.__checkParamIsLessThan("THR_MIN", 200, logdata)
|
|
|
|
self.__checkParamIsLessThan("THR_MID", 701, logdata)
|
|
|
|
self.__checkParamIsMoreThan("THR_MID", 299, logdata)
|
2014-08-12 12:58:02 -03:00
|
|
|
# TODO: add more parameter tests, these are just an example...
|
2017-09-23 22:51:51 -03:00
|
|
|
elif logdata.vehicleType == VehicleType.Plane:
|
2014-08-12 12:58:02 -03:00
|
|
|
# TODO: add parameter checks for plane...
|
|
|
|
pass
|
2017-09-23 22:51:51 -03:00
|
|
|
elif logdata.vehicleType == VehicleType.Rover:
|
2014-08-12 12:58:02 -03:00
|
|
|
# TODO: add parameter checks for rover...
|
|
|
|
pass
|
|
|
|
|
|
|
|
if self.result.status == TestResult.StatusType.FAIL:
|
|
|
|
self.result.statusMessage = "Bad parameters found:\n" + self.result.statusMessage
|
|
|
|
except KeyError as e:
|
|
|
|
self.result.status = TestResult.StatusType.FAIL
|
2017-07-21 20:28:28 -03:00
|
|
|
self.result.statusMessage = str(e) + ' not found'
|