2015-08-11 03:28:43 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2014-07-06 23:03:26 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX
|
2014-02-23 20:59:24 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
2015-06-27 18:18:09 -03:00
|
|
|
#include <sys/stat.h>
|
2014-02-23 20:59:24 -04:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
2015-01-19 13:30:18 -04:00
|
|
|
#include <time.h>
|
2014-02-23 20:59:24 -04:00
|
|
|
|
|
|
|
extern const AP_HAL::HAL& hal;
|
|
|
|
|
|
|
|
#include "Util.h"
|
2015-09-25 11:07:59 -03:00
|
|
|
#include "Heat_Pwm.h"
|
|
|
|
|
2014-02-23 20:59:24 -04:00
|
|
|
using namespace Linux;
|
|
|
|
|
2014-11-15 01:51:21 -04:00
|
|
|
|
|
|
|
static int state;
|
2015-10-20 18:13:25 -03:00
|
|
|
ToneAlarm Util::_toneAlarm;
|
2015-09-25 11:07:59 -03:00
|
|
|
|
2015-10-20 18:13:25 -03:00
|
|
|
void Util::init(int argc, char * const *argv) {
|
2015-09-25 11:07:59 -03:00
|
|
|
saved_argc = argc;
|
|
|
|
saved_argv = argv;
|
|
|
|
|
|
|
|
#ifdef HAL_UTILS_HEAT
|
|
|
|
#if HAL_UTILS_HEAT == HAL_LINUX_HEAT_PWM
|
2015-10-20 18:13:25 -03:00
|
|
|
_heat = new Linux::HeatPwm(HAL_LINUX_HEAT_PWM_SYSFS_DIR,
|
2015-09-25 11:07:59 -03:00
|
|
|
HAL_LINUX_HEAT_KP,
|
|
|
|
HAL_LINUX_HEAT_KI,
|
|
|
|
HAL_LINUX_HEAT_PERIOD_NS,
|
|
|
|
HAL_LINUX_HEAT_TARGET_TEMP);
|
|
|
|
#else
|
|
|
|
#error Unrecognized Heat
|
|
|
|
#endif // #if
|
|
|
|
#else
|
2015-10-20 18:13:25 -03:00
|
|
|
_heat = new Linux::Heat();
|
2015-09-25 11:07:59 -03:00
|
|
|
#endif // #ifdef
|
|
|
|
}
|
|
|
|
|
2015-10-20 18:13:25 -03:00
|
|
|
void Util::set_imu_temp(float current)
|
2015-09-25 11:07:59 -03:00
|
|
|
{
|
|
|
|
_heat->set_imu_temp(current);
|
|
|
|
}
|
|
|
|
|
2014-02-23 20:59:24 -04:00
|
|
|
/**
|
|
|
|
return commandline arguments, if available
|
|
|
|
*/
|
2015-10-20 18:13:25 -03:00
|
|
|
void Util::commandline_arguments(uint8_t &argc, char * const *&argv)
|
2014-02-23 20:59:24 -04:00
|
|
|
{
|
|
|
|
argc = saved_argc;
|
|
|
|
argv = saved_argv;
|
|
|
|
}
|
|
|
|
|
2015-10-20 18:13:25 -03:00
|
|
|
bool Util::toneAlarm_init()
|
2014-11-15 01:51:21 -04:00
|
|
|
{
|
|
|
|
return _toneAlarm.init();
|
|
|
|
}
|
|
|
|
|
2015-10-20 18:13:25 -03:00
|
|
|
void Util::toneAlarm_set_tune(uint8_t tone)
|
2014-11-15 01:51:21 -04:00
|
|
|
{
|
|
|
|
_toneAlarm.set_tune(tone);
|
|
|
|
}
|
|
|
|
|
2015-10-20 18:13:25 -03:00
|
|
|
void Util::_toneAlarm_timer_tick(){
|
2014-11-15 01:51:21 -04:00
|
|
|
if(state == 0){
|
|
|
|
state = state + _toneAlarm.init_tune();
|
|
|
|
}else if(state == 1){
|
|
|
|
state = state + _toneAlarm.set_note();
|
|
|
|
}
|
|
|
|
if(state == 2){
|
|
|
|
state = state + _toneAlarm.play();
|
|
|
|
}else if(state == 3){
|
|
|
|
state = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(_toneAlarm.is_tune_comp()){
|
|
|
|
state = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-01-19 13:30:18 -04:00
|
|
|
|
2015-10-20 18:13:25 -03:00
|
|
|
void Util::set_system_clock(uint64_t time_utc_usec)
|
2015-01-19 13:30:18 -04:00
|
|
|
{
|
2015-01-22 00:58:20 -04:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE != HAL_BOARD_SUBTYPE_LINUX_NONE
|
2015-01-19 13:30:18 -04:00
|
|
|
timespec ts;
|
|
|
|
ts.tv_sec = time_utc_usec/1.0e6;
|
|
|
|
ts.tv_nsec = (time_utc_usec % 1000000) * 1000;
|
|
|
|
clock_settime(CLOCK_REALTIME, &ts);
|
2015-01-21 07:00:45 -04:00
|
|
|
#endif
|
2015-01-19 13:30:18 -04:00
|
|
|
}
|
|
|
|
|
2015-10-20 18:13:25 -03:00
|
|
|
bool Util::is_chardev_node(const char *path)
|
2015-06-27 18:18:09 -03:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if (!path || lstat(path, &st) < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return S_ISCHR(st.st_mode);
|
|
|
|
}
|
|
|
|
|
2015-11-05 01:06:15 -04:00
|
|
|
/*
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-07-06 23:03:26 -03:00
|
|
|
#endif // CONFIG_HAL_BOARD == HAL_BOARD_LINUX
|