5
5
#include < GCS_MAVLink/GCS.h>
6
6
#include < time.h>
7
7
8
+ #define DEBUG_RTC_SHIFT 1
9
+
10
+ #if DEBUG_RTC_SHIFT
11
+ #include < AP_Logger/AP_Logger.h>
12
+ #endif
13
+
8
14
extern const AP_HAL::HAL& hal;
9
15
10
16
AP_RTC::AP_RTC ()
@@ -43,9 +49,19 @@ void AP_RTC::set_utc_usec(uint64_t time_utc_usec, source_type type)
43
49
{
44
50
const uint64_t oldest_acceptable_date_us = 1640995200ULL *1000 *1000 ; // 2022-01-01 0:00
45
51
46
- if (type >= rtc_source_type) {
47
- // e.g. system-time message when we've been set by the GPS
48
- return ;
52
+ // only allow time to be moved forward from the same sourcetype
53
+ // while the vehicle is disarmed:
54
+ if (hal.util ->get_soft_armed ()) {
55
+ if (type >= rtc_source_type) {
56
+ // e.g. system-time message when we've been set by the GPS
57
+ return ;
58
+ }
59
+ } else {
60
+ // vehicle is disarmed; accept (e.g.) GPS time source updates
61
+ if (type > rtc_source_type) {
62
+ // e.g. system-time message when we've been set by the GPS
63
+ return ;
64
+ }
49
65
}
50
66
51
67
// check it's from an allowed sources:
@@ -66,6 +82,11 @@ void AP_RTC::set_utc_usec(uint64_t time_utc_usec, source_type type)
66
82
}
67
83
WITH_SEMAPHORE (rsem);
68
84
85
+ #if DEBUG_RTC_SHIFT
86
+ uint64_t old_utc = 0 ;
87
+ UNUSED_RESULT (get_utc_usec (old_utc));
88
+ #endif
89
+
69
90
rtc_shift = tmp;
70
91
71
92
// update hardware clock:
@@ -79,6 +100,32 @@ void AP_RTC::set_utc_usec(uint64_t time_utc_usec, source_type type)
79
100
// update signing timestamp
80
101
GCS_MAVLINK::update_signing_timestamp (time_utc_usec);
81
102
#endif
103
+
104
+ #if DEBUG_RTC_SHIFT
105
+ uint64_t new_utc = 0 ;
106
+ UNUSED_RESULT (get_utc_usec (new_utc));
107
+ if (old_utc != new_utc) {
108
+ if (AP::logger ().should_log (0xFFFF )){
109
+ // log to AP_Logger
110
+ // @LoggerMessage: RTC
111
+ // @Description: Information about RTC clock resets
112
+ // @Field: TimeUS: Time since system startup
113
+ // @Field: old: old time
114
+ // @Field: new: new time
115
+ // @Field: in: new argument time
116
+ AP::logger ().WriteStreaming (
117
+ " RTC" ,
118
+ " TimeUS,old_utc,new_utc" ,
119
+ " sss" ,
120
+ " FFF" ,
121
+ " QQQ" ,
122
+ AP_HAL::micros64 (),
123
+ old_utc,
124
+ new_utc
125
+ );
126
+ }
127
+ }
128
+ #endif
82
129
}
83
130
84
131
bool AP_RTC::get_utc_usec (uint64_t &usec) const
0 commit comments