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