From 31c345fc4bb5c8f0248ac99bd823431c54a82173 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Thu, 20 May 2021 12:34:15 +1000 Subject: [PATCH] Tools: add support for AP_Logger into AP_Periph --- Tools/AP_Periph/AP_Periph.cpp | 24 ++++++++++++++++++++++++ Tools/AP_Periph/AP_Periph.h | 8 ++++++++ Tools/AP_Periph/Parameters.cpp | 13 +++++++++++++ Tools/AP_Periph/Parameters.h | 6 ++++++ Tools/AP_Periph/wscript | 2 ++ Tools/ardupilotwaf/boards.py | 4 ++++ 6 files changed, 57 insertions(+) diff --git a/Tools/AP_Periph/AP_Periph.cpp b/Tools/AP_Periph/AP_Periph.cpp index dda41f6753..34fbe86127 100644 --- a/Tools/AP_Periph/AP_Periph.cpp +++ b/Tools/AP_Periph/AP_Periph.cpp @@ -64,6 +64,18 @@ const struct app_descriptor app_descriptor __attribute__((section(".app_descript const struct app_descriptor app_descriptor; #endif +AP_Periph_FW::AP_Periph_FW() +#if HAL_LOGGING_ENABLED + : logger(g.log_bitmask) +#endif +{} + +#if HAL_LOGGING_ENABLED +const struct LogStructure AP_Periph_FW::log_structure[] = { + LOG_COMMON_STRUCTURES, +}; +#endif + void AP_Periph_FW::init() { @@ -94,6 +106,10 @@ void AP_Periph_FW::init() AFIO->MAPR = mapr | AFIO_MAPR_CAN_REMAP_REMAP2 | AFIO_MAPR_SPI3_REMAP; #endif +#if HAL_LOGGING_ENABLED + logger.Init(log_structure, ARRAY_SIZE(log_structure)); +#endif + printf("Booting %08x:%08x %u/%u len=%u 0x%08x\n", app_descriptor.image_crc1, app_descriptor.image_crc2, @@ -108,6 +124,10 @@ void AP_Periph_FW::init() #ifdef HAL_PERIPH_ENABLE_GPS if (gps.get_type(0) != AP_GPS::GPS_Type::GPS_TYPE_NONE && g.gps_port >= 0) { serial_manager.set_protocol_and_baud(g.gps_port, AP_SerialManager::SerialProtocol_GPS, AP_SERIALMANAGER_GPS_BAUD); +#if HAL_LOGGING_ENABLED + #define MASK_LOG_GPS (1<<2) + gps.set_log_gps_bit(MASK_LOG_GPS); +#endif gps.init(serial_manager); } #endif @@ -343,6 +363,10 @@ void AP_Periph_FW::update() } #endif +#if HAL_LOGGING_ENABLED + logger.periodic_tasks(); +#endif + can_update(); hal.scheduler->delay(1); #if (defined(HAL_PERIPH_NEOPIXEL_COUNT_WITHOUT_NOTIFY) && HAL_PERIPH_NEOPIXEL_COUNT_WITHOUT_NOTIFY == 8) || defined(HAL_PERIPH_ENABLE_NOTIFY) diff --git a/Tools/AP_Periph/AP_Periph.h b/Tools/AP_Periph/AP_Periph.h index 04dce7c11b..1767ee5d1c 100644 --- a/Tools/AP_Periph/AP_Periph.h +++ b/Tools/AP_Periph/AP_Periph.h @@ -7,6 +7,7 @@ #include #include "SRV_Channel/SRV_Channel.h" #include +#include #include #include #include @@ -48,6 +49,8 @@ extern const struct app_descriptor app_descriptor; class AP_Periph_FW { public: + AP_Periph_FW(); + void init(); void update(); @@ -169,6 +172,11 @@ public: AP_Notify notify; #endif +#if HAL_LOGGING_ENABLED + static const struct LogStructure log_structure[]; + AP_Logger logger; +#endif + // setup the var_info table AP_Param param_loader{var_info}; diff --git a/Tools/AP_Periph/Parameters.cpp b/Tools/AP_Periph/Parameters.cpp index e94106691a..b596dab43b 100644 --- a/Tools/AP_Periph/Parameters.cpp +++ b/Tools/AP_Periph/Parameters.cpp @@ -260,6 +260,19 @@ const AP_Param::Info AP_Periph_FW::var_info[] = { GOBJECT(notify, "NTF_", AP_Notify), #endif +#if HAL_LOGGING_ENABLED + // @Group: LOG + // @Path: ../libraries/AP_Logger/AP_Logger.cpp + GOBJECT(logger, "LOG", AP_Logger), + + // @Param: LOG_BITMASK + // @DisplayName: Log bitmask + // @Description: 4 byte bitmap of log types to enable + // @Bitmask: 2:GPS + // @User: Standard + GSCALAR(log_bitmask, "LOG_BITMASK", 4), +#endif + AP_VAREND }; diff --git a/Tools/AP_Periph/Parameters.h b/Tools/AP_Periph/Parameters.h index 4b758029a2..a4e03a3ab1 100644 --- a/Tools/AP_Periph/Parameters.h +++ b/Tools/AP_Periph/Parameters.h @@ -38,6 +38,8 @@ public: k_param_msp_port, k_param_notify, k_param_esc_pwm_type, + k_param_logger, + k_param_log_bitmask, }; AP_Int16 format_version; @@ -91,6 +93,10 @@ public: AP_Int32 serial_number; +#if HAL_LOGGING_ENABLED + AP_Int32 log_bitmask; +#endif + Parameters() {} }; diff --git a/Tools/AP_Periph/wscript b/Tools/AP_Periph/wscript index 3f0c4a9bdd..750b40ff0f 100644 --- a/Tools/AP_Periph/wscript +++ b/Tools/AP_Periph/wscript @@ -40,6 +40,8 @@ def build(bld): 'SRV_Channel', 'AP_Notify', 'AP_SerialLED', + 'AP_Logger', + 'AP_Filesystem', ], exclude_src=[ 'libraries/AP_HAL_ChibiOS/Storage.cpp' diff --git a/Tools/ardupilotwaf/boards.py b/Tools/ardupilotwaf/boards.py index 42a14723f0..1ba0d0f3c3 100644 --- a/Tools/ardupilotwaf/boards.py +++ b/Tools/ardupilotwaf/boards.py @@ -558,6 +558,10 @@ class sitl_periph_gps(sitl): APJ_BOARD_ID = 100, HAL_NO_GCS = 1, HAL_LOGGING_ENABLED = 0, + HAL_LOGGING_MAVLINK_ENABLED = 0, + HAL_MISSION_ENABLED = 0, + HAL_RALLY_ENABLED = 0, + HAL_SCHEDULER_ENABLED = 0, ) # libcanard is written for 32bit platforms env.CXXFLAGS += [