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_Logger: Add enum information to VER log message metadata #26308

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions Tools/autotest/logger_metadata/enum_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ def match_enum_line(self, line):
if m is not None:
return (m.group(1), 1 << int(m.group(2)), m.group(3))

# Match: "#define FRED 1 // optional comment"
m = re.match(r"#define\s*([A-Z0-9_a-z]+)\s+(-?\d+) *(// *(.*) *)?$", line)
if m is not None:
return (m.group(1), m.group(2), m.group(4))

if m is None:
raise ValueError("Failed to match (%s)" % line)

Expand All @@ -116,7 +121,13 @@ def debug(x):
break
line = line.rstrip()
# print("state=%s line: %s" % (state, line))
if re.match(r"\s*//.*", line):
# Skip single-line comments - unless they contain LoggerEnum tags
if re.match(r"\s*//.*", line) and "LoggerEnum" not in line:
continue
# Skip multi-line comments
if re.match(r"\s*/\*.*", line):
while "*/" not in line:
line = f.readline()
continue
if state == "outside":
if re.match("class .*;", line) is not None:
Expand Down Expand Up @@ -154,6 +165,19 @@ def debug(x):
last_value = None
state = state_inside
skip_enumeration = False
continue

# // @LoggerEnum: NAME - can be used around for #define sets
m = re.match(r".*@LoggerEnum: *([\w]+)", line)
if m is not None:
enum_name = m.group(1)
debug("%s: %s" % (source_file, enum_name))
entries = []
last_value = None
state = state_inside
skip_enumeration = False
continue

continue
if state == "inside":
if re.match(r"\s*$", line):
Expand All @@ -164,7 +188,7 @@ def debug(x):
continue
if re.match(r"#else", line):
continue
if re.match(r".*}\s*\w*(\s*=\s*[\w:]+)?;", line):
if re.match(r".*}\s*\w*(\s*=\s*[\w:]+)?;", line) or "@LoggerEnumEnd" in line:
# potential end of enumeration
if not skip_enumeration:
if enum_name is None:
Expand Down
4 changes: 4 additions & 0 deletions libraries/AP_HAL/AP_HAL_Boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
#pragma once

// @LoggerEnum: HAL_BOARD
#define HAL_BOARD_SITL 3
// #define HAL_BOARD_SMACCM 4 // unused
// #define HAL_BOARD_PX4 5 // unused
Expand All @@ -16,7 +17,9 @@
#define HAL_BOARD_ESP32 12
#define HAL_BOARD_QURT 13
#define HAL_BOARD_EMPTY 99
// @LoggerEnumEnd

// @LoggerEnum: HAL_BOARD_SUBTYPE
/* Default board subtype is -1 */
#define HAL_BOARD_SUBTYPE_NONE -1

Expand Down Expand Up @@ -70,6 +73,7 @@
#define HAL_BOARD_SUBTYPE_ESP32_NICK 6006
#define HAL_BOARD_SUBTYPE_ESP32_S3DEVKIT 6007
#define HAL_BOARD_SUBTYPE_ESP32_S3EMPTY 6008
// @LoggerEnumEnd

/* InertialSensor driver types */
#define HAL_INS_NONE 0
Expand Down
3 changes: 3 additions & 0 deletions libraries/AP_Logger/LogStructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,9 @@ struct PACKED log_VER {
// @Description: Ardupilot version
// @Field: TimeUS: Time since system startup
// @Field: BT: Board type
// @FieldValueEnum: BT: HAL_BOARD
// @Field: BST: Board subtype
// @FieldValueEnum: BST: HAL_BOARD_SUBTYPE
// @Field: Maj: Major version number
// @Field: Min: Minor version number
// @Field: Pat: Patch number
Expand All @@ -1143,6 +1145,7 @@ struct PACKED log_VER {
// @Field: FWS: Firmware version string
// @Field: APJ: Board ID
// @Field: BU: Build vehicle type
// @FieldValueEnum: BU: APM_BUILD
// @Field: FV: Filter version

// @LoggerMessage: MOTB
Expand Down
2 changes: 2 additions & 0 deletions libraries/AP_Vehicle/AP_Vehicle_Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
Also note that code needs to support other APM_BUILD_DIRECTORY
values for example sketches
*/
// @LoggerEnum: APM_BUILD
#define APM_BUILD_Rover 1
#define APM_BUILD_ArduCopter 2
#define APM_BUILD_ArduPlane 3
Expand All @@ -32,6 +33,7 @@
#define APM_BUILD_AP_Bootloader 11
#define APM_BUILD_Blimp 12
#define APM_BUILD_Heli 13
// @LoggerEnumEnd

#ifdef APM_BUILD_DIRECTORY
/*
Expand Down
Loading