mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-03 06:28:27 -04:00
AP_RTC: add parameter for source types we will set the system time from
This commit is contained in:
parent
22a94addd5
commit
f83e65e04e
@ -13,6 +13,31 @@ const char *AP_RTC::_clock_source_types[] = {
|
|||||||
"NONE",
|
"NONE",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
AP_RTC::AP_RTC()
|
||||||
|
{
|
||||||
|
AP_Param::setup_object_defaults(this, var_info);
|
||||||
|
if (_singleton != nullptr) {
|
||||||
|
// it's an error to get here. But I don't want to include
|
||||||
|
// AP_HAL here
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_singleton = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// table of user settable parameters
|
||||||
|
const AP_Param::GroupInfo AP_RTC::var_info[] = {
|
||||||
|
|
||||||
|
// @Param: _TYPES
|
||||||
|
// @DisplayName: Allowed sources of RTC time
|
||||||
|
// @Description: Specifies which sources of UTC time will be accepted
|
||||||
|
// @Bitmask: 0:GPS,1:MAVLINK_SYSTEM_TIME,2:HW
|
||||||
|
// @User: Advanced
|
||||||
|
AP_GROUPINFO("_TYPES", 1, AP_RTC, allowed_types, 1),
|
||||||
|
|
||||||
|
AP_GROUPEND
|
||||||
|
};
|
||||||
|
|
||||||
void AP_RTC::set_utc_usec(uint64_t time_utc_usec, source_type type)
|
void AP_RTC::set_utc_usec(uint64_t time_utc_usec, source_type type)
|
||||||
{
|
{
|
||||||
if (type >= rtc_source_type) {
|
if (type >= rtc_source_type) {
|
||||||
@ -20,6 +45,11 @@ void AP_RTC::set_utc_usec(uint64_t time_utc_usec, source_type type)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check it's from an allowed sources:
|
||||||
|
if (!(allowed_types & (1<<type))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const uint64_t now = AP_HAL::micros64();
|
const uint64_t now = AP_HAL::micros64();
|
||||||
const int64_t tmp = int64_t(time_utc_usec) - int64_t(now);
|
const int64_t tmp = int64_t(time_utc_usec) - int64_t(now);
|
||||||
if (tmp < rtc_shift) {
|
if (tmp < rtc_shift) {
|
||||||
|
@ -1,26 +1,26 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AP_Param/AP_Param.h>
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
class AP_RTC {
|
class AP_RTC {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
AP_RTC() {
|
AP_RTC();
|
||||||
if (_singleton != nullptr) {
|
|
||||||
// it's an error to get here. But I don't want to include
|
static const struct AP_Param::GroupInfo var_info[];
|
||||||
// AP_HAL here
|
|
||||||
return;
|
AP_Int8 allowed_types;
|
||||||
}
|
|
||||||
_singleton = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ordering is important in source_type; lower-numbered is
|
// ordering is important in source_type; lower-numbered is
|
||||||
// considered a better time source.
|
// considered a better time source. These values are documented
|
||||||
|
// and used in the parameters!
|
||||||
enum source_type : uint8_t {
|
enum source_type : uint8_t {
|
||||||
SOURCE_GPS,
|
SOURCE_GPS = 0,
|
||||||
SOURCE_MAVLINK_SYSTEM_TIME,
|
SOURCE_MAVLINK_SYSTEM_TIME = 1,
|
||||||
SOURCE_HW,
|
SOURCE_HW = 2,
|
||||||
SOURCE_NONE,
|
SOURCE_NONE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user