LCOV - code coverage report
Current view: top level - AP_HAL_Linux - Util.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 3 17 17.6 %
Date: 2026-09-09 11:02:08 Functions: 2 10 20.0 %

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include <AP_Common/AP_Common.h>
       4             : #include <AP_HAL/AP_HAL.h>
       5             : 
       6             : #include "Heat.h"
       7             : #if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DISCO
       8             : #include "ToneAlarm_Disco.h"
       9             : #endif
      10             : #include "ToneAlarm.h"
      11             : #include "Semaphores.h"
      12             : 
      13             : namespace Linux {
      14             : 
      15             : enum hw_type {
      16             :     UTIL_HARDWARE_RPI1 = 0,
      17             :     UTIL_HARDWARE_RPI2,
      18             :     UTIL_HARDWARE_RPI4,
      19             :     UTIL_HARDWARE_BEBOP,
      20             :     UTIL_HARDWARE_BEBOP2,
      21             :     UTIL_HARDWARE_DISCO,
      22             :     UTIL_NUM_HARDWARES,
      23             : };
      24             : 
      25             : class Util : public AP_HAL::Util {
      26             : public:
      27             :     static Util *from(AP_HAL::Util *util) {
      28             :         return static_cast<Util*>(util);
      29             :     }
      30             : 
      31             :     void init(int argc, char *const *argv);
      32             : 
      33             :     /**
      34             :        return commandline arguments, if available
      35             :      */
      36             :     void commandline_arguments(uint8_t &argc, char * const *&argv) override;
      37             : 
      38             :     /*
      39             :       get/set system clock in UTC microseconds
      40             :      */
      41             :     void set_hw_rtc(uint64_t time_utc_usec) override;
      42             :     uint64_t get_hw_rtc() const override;
      43             : 
      44           0 :     const char *get_custom_log_directory() const override final { return custom_log_directory; }
      45           0 :     const char *get_custom_terrain_directory() const override final { return custom_terrain_directory; }
      46           2 :     const char *get_custom_storage_directory() const override final { return custom_storage_directory; }
      47             : 
      48           0 :     void set_custom_log_directory(const char *_custom_log_directory) { custom_log_directory = _custom_log_directory; }
      49           0 :     void set_custom_terrain_directory(const char *_custom_terrain_directory) { custom_terrain_directory = _custom_terrain_directory; }
      50           0 :     void set_custom_storage_directory(const char *_custom_storage_directory) {
      51           0 :         custom_storage_directory = _custom_storage_directory;
      52           0 :     }
      53           0 :     void set_custom_defaults_path(const char *_custom_defaults) {
      54           0 :         custom_defaults = _custom_defaults;
      55           0 :     }
      56             : 
      57             :     // get path to custom defaults file for AP_Param
      58           5 :     const char* get_custom_defaults_file() const override final {
      59           5 :         return custom_defaults;
      60             :     }
      61             : 
      62             :     /* Parse cpu set in the form 0; 0,2; or 0-2 */
      63             :     bool parse_cpu_set(const char *s, cpu_set_t *cpu_set) const;
      64             : 
      65             :     bool is_chardev_node(const char *path);
      66             :     void set_imu_temp(float current) override;
      67             :     void set_imu_target_temp(int8_t *target) override;
      68             : 
      69             :     uint32_t available_memory(void) override;
      70             : 
      71             :     bool get_system_id(char buf[50]) override;
      72             :     bool get_system_id_unformatted(uint8_t buf[], uint8_t &len) override;
      73             : 
      74             :     /*
      75             :      * Write a string as specified by @fmt to the file in @path. Note this
      76             :      * should not be used on hot path since it will open, write and close the
      77             :      * file for each call.
      78             :      */
      79             :     int write_file(const char *path, const char *fmt, ...) FMT_PRINTF(3, 4);
      80             : 
      81             :     /*
      82             :      * Read a string as specified by @fmt from the file in @path. Note this
      83             :      * should not be used on hot path since it will open, read and close the
      84             :      * file for each call.
      85             :      */
      86             :     int read_file(const char *path, const char *fmt, ...) FMT_SCANF(3, 4);
      87             : 
      88             :     int get_hw_arm32();
      89             : 
      90           0 :     bool toneAlarm_init(uint8_t types) override { return _toneAlarm.init(); }
      91           0 :     void toneAlarm_set_buzzer_tone(float frequency, float volume, uint32_t duration_ms) override {
      92           0 :         _toneAlarm.set_buzzer_tone(frequency, volume, duration_ms);
      93           0 :     }
      94             : 
      95             :     // fills data with random values of requested size
      96             :     bool get_random_vals(uint8_t* data, size_t size) override;
      97             : 
      98             : private:
      99             : #if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DISCO
     100             :     static ToneAlarm_Disco _toneAlarm;
     101             : #else
     102             :     static ToneAlarm _toneAlarm;
     103             : #endif
     104             :     int saved_argc;
     105             :     Heat *_heat;
     106             :     char *const *saved_argv;
     107             :     const char *custom_log_directory = nullptr;
     108             :     const char *custom_terrain_directory = nullptr;
     109             :     const char *custom_storage_directory = nullptr;
     110             :     const char *custom_defaults = HAL_PARAM_DEFAULTS_PATH;
     111             :     static const char *_hw_names[UTIL_NUM_HARDWARES];
     112             : };
     113             : 
     114             : }

Generated by: LCOV version 1.14