ardupilot/libraries/AP_HAL_Linux/Util.cpp

66 lines
1.3 KiB
C++
Raw Normal View History

2014-02-23 20:59:24 -04:00
#include <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>
#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"
using namespace Linux;
static int state;
ToneAlarm LinuxUtil::_toneAlarm;
2014-02-23 20:59:24 -04:00
/**
return commandline arguments, if available
*/
void LinuxUtil::commandline_arguments(uint8_t &argc, char * const *&argv)
{
argc = saved_argc;
argv = saved_argv;
}
bool LinuxUtil::toneAlarm_init()
{
return _toneAlarm.init();
}
void LinuxUtil::toneAlarm_set_tune(uint8_t tone)
{
_toneAlarm.set_tune(tone);
}
void LinuxUtil::_toneAlarm_timer_tick(){
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
void LinuxUtil::set_system_clock(uint64_t time_utc_usec)
{
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);
#endif
2015-01-19 13:30:18 -04:00
}
2014-07-06 23:03:26 -03:00
#endif // CONFIG_HAL_BOARD == HAL_BOARD_LINUX