Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP_HAL: add power status bits to logger metadata #26127

Merged
merged 3 commits into from Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions Tools/autotest/logger_metadata/enum_parse.py
Expand Up @@ -92,6 +92,10 @@ def match_enum_line(self, line):
raise ValueError("Failed to match (%s)" % line)

def enumerations_from_file(self, source_file):
def debug(x):
pass
# if source_file == "/home/pbarker/rc/ardupilot/libraries/AP_HAL/AnalogIn.h":
# debug = print
state_outside = "outside"
state_inside = "inside"

Expand All @@ -103,6 +107,7 @@ def enumerations_from_file(self, source_file):
in_class = None
while True:
line = f.readline()
# debug(f"{state} line: {line}")
if line == "":
break
line = line.rstrip()
Expand All @@ -113,7 +118,7 @@ def enumerations_from_file(self, source_file):
if re.match("class .*;", line) is not None:
# forward-declaration of a class
continue
m = re.match("class *(\w+)", line)
m = re.match("class *([:\w]+)", line)
if m is not None:
in_class = m.group(1)
continue
Expand All @@ -125,6 +130,7 @@ def enumerations_from_file(self, source_file):
if m is not None:
# all one one line! Thanks!
enum_name = m.group(2)
debug("ol: %s: %s" % (source_file, enum_name))
entries_string = m.group(3)
entry_names = [x.strip() for x in entries_string.split(",")]
count = 0
Expand All @@ -139,7 +145,7 @@ def enumerations_from_file(self, source_file):
m = re.match(".*enum\s*(class)? *([\w]+)\s*(?::.*_t)? *{", line)
if m is not None:
enum_name = m.group(2)
# print("%s: %s" % (source_file, enum_name))
debug("%s: %s" % (source_file, enum_name))
entries = []
last_value = None
state = state_inside
Expand Down Expand Up @@ -172,7 +178,7 @@ def enumerations_from_file(self, source_file):
if name is None:
skip_enumeration = True
continue
# print(" name=(%s) value=(%s) comment=(%s)\n" % (name, value, comment))
debug(" name=(%s) value=(%s) comment=(%s)\n" % (name, value, comment))
if value is None:
if last_value is None:
value = 0
Expand All @@ -190,6 +196,7 @@ def enumerations_from_file(self, source_file):
class Enumeration(object):

def __init__(self, name, entries):
# print("creating enum %s" % name)
self.name = name
self.entries = entries

Expand Down Expand Up @@ -246,4 +253,4 @@ def run(self):
sys.exit(1)

s.run()
print("Enumerations: %s" % s.enumerations)
# print("Enumerations: %s" % s.enumerations)
7 changes: 6 additions & 1 deletion Tools/autotest/logger_metadata/parse.py
Expand Up @@ -325,15 +325,20 @@ def search_messagedef_start(self,line,prevmessagedef=""):

def parse_file(self, filepath):
with open(filepath) as f:
# print("Opened (%s)" % filepath)
# print("Opened (%s)" % filepath)
lines = f.readlines()
f.close()
def debug(x):
pass
# if filepath == "/home/pbarker/rc/ardupilot/libraries/AP_HAL/AnalogIn.h":
# debug = print
state_outside = "outside"
state_inside = "inside"
messagedef = ""
state = state_outside
docco = None
for line in lines:
debug(f"{state}: {line}")
if messagedef:
messagedef = messagedef + line
if "}" in line or ";" in line:
Expand Down
10 changes: 10 additions & 0 deletions libraries/AP_HAL/AnalogIn.h
Expand Up @@ -42,6 +42,16 @@ class AP_HAL::AnalogIn {
// failures can still be diagnosed
virtual uint16_t accumulated_power_status_flags(void) const { return 0; }

// this enum class is 1:1 with MAVLink's MAV_POWER_STATUS enumeration!
enum class PowerStatusFlag : uint16_t {
BRICK_VALID = 1, // main brick power supply valid
SERVO_VALID = 2, // main servo power supply valid for FMU
USB_CONNECTED = 4, // USB power is connected
PERIPH_OVERCURRENT = 8, // peripheral supply is in over-current state
PERIPH_HIPOWER_OVERCURRENT = 16, // hi-power peripheral supply is in over-current state
CHANGED = 32, // Power status has changed since boot
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a static assert to make sure they match?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a static assert to make sure they match?

I can (and I did for an GPS patch), but I don't want to :-)

These are so static - and only used for documentation - so I got lazy. As soon as we used these in the actual ArduPilot code they'd definitely need that assertion.

Also - PRs welcome ;-)

#if HAL_WITH_MCU_MONITORING
virtual float mcu_temperature(void) { return 0; }
virtual float mcu_voltage(void) { return 0; }
Expand Down
2 changes: 2 additions & 0 deletions libraries/AP_Logger/LogStructure.h
Expand Up @@ -954,7 +954,9 @@ struct PACKED log_VER {
// @Field: Vcc: Flight board voltage
// @Field: VServo: Servo rail voltage
// @Field: Flags: System power flags
// @FieldBitmaskEnum: Flags: AP_HAL::AnalogIn::PowerStatusFlag
// @Field: AccFlags: Accumulated System power flags; all flags which have ever been set
// @FieldBitmaskEnum: AccFlags: AP_HAL::AnalogIn::PowerStatusFlag
// @Field: Safety: Hardware Safety Switch status

// @LoggerMessage: MCU
Expand Down