#include #include #include #include #include #include #include #include #include #include "Heat_Pwm.h" #include "ToneAlarm_Disco.h" #include "Util.h" using namespace Linux; extern const AP_HAL::HAL& hal; #if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DISCO ToneAlarm_Disco Util::_toneAlarm; #else ToneAlarm Util::_toneAlarm; #endif void Util::init(int argc, char * const *argv) { saved_argc = argc; saved_argv = argv; #ifdef HAL_UTILS_HEAT #if HAL_UTILS_HEAT == HAL_LINUX_HEAT_PWM _heat = new Linux::HeatPwm(HAL_LINUX_HEAT_PWM_NUM, HAL_LINUX_HEAT_KP, HAL_LINUX_HEAT_KI, HAL_LINUX_HEAT_PERIOD_NS); #else #error Unrecognized Heat #endif // #if #else _heat = new Linux::Heat(); #endif // #ifdef } // set current IMU temperatue in degrees C void Util::set_imu_temp(float current) { _heat->set_imu_temp(current); } // set target IMU temperatue in degrees C void Util::set_imu_target_temp(int8_t *target) { _heat->set_imu_target_temp(target); } /** return commandline arguments, if available */ void Util::commandline_arguments(uint8_t &argc, char * const *&argv) { argc = saved_argc; argv = saved_argv; } void Util::set_hw_rtc(uint64_t time_utc_usec) { #if CONFIG_HAL_BOARD_SUBTYPE != HAL_BOARD_SUBTYPE_LINUX_NONE // call superclass method to set time. We've guarded this so we // don't reset the HW clock time on people's laptops. AP_HAL::Util::set_hw_rtc(time_utc_usec); #endif } bool Util::is_chardev_node(const char *path) { struct stat st; if (!path || lstat(path, &st) < 0) { return false; } return S_ISCHR(st.st_mode); } /* always report 256k of free memory. Using mallinfo() isn't useful as it only reported the current heap, which auto-expands. What we're trying to do here is ensure that code which checks for free memory before allocating objects does allow the allocation */ uint32_t Util::available_memory(void) { return 256*1024; } #ifndef HAL_LINUX_DEFAULT_SYSTEM_ID #define HAL_LINUX_DEFAULT_SYSTEM_ID "linux-unknown" #endif /* get a (hopefully unique) machine ID */ bool Util::get_system_id_unformatted(uint8_t buf[], uint8_t &len) { char *cbuf = (char *)buf; // try first to use machine-id file. Most systems will have this const char *paths[] = { "/etc/machine-id", "/var/lib/dbus/machine-id" }; for (uint8_t i=0; i