Merge branch 'master' into sdlog2_rtc

This commit is contained in:
Lorenz Meier
2015-01-04 18:54:01 +01:00
3 changed files with 20 additions and 17 deletions
+14 -11
View File
@@ -947,14 +947,18 @@ MavlinkReceiver::handle_message_system_time(mavlink_message_t *msg)
clock_gettime(CLOCK_REALTIME, &tv); clock_gettime(CLOCK_REALTIME, &tv);
// date -d @1234567890: Sat Feb 14 02:31:30 MSK 2009 // date -d @1234567890: Sat Feb 14 02:31:30 MSK 2009
bool onb_unix_valid = tv.tv_sec > 1234567890ULL; bool onb_unix_valid = tv.tv_sec > PX4_EPOCH_SECS;
bool ofb_unix_valid = time.time_unix_usec > 1234567890ULL * 1000ULL; bool ofb_unix_valid = time.time_unix_usec > PX4_EPOCH_SECS * 1000ULL;
if (!onb_unix_valid && ofb_unix_valid) { if (!onb_unix_valid && ofb_unix_valid) {
tv.tv_sec = time.time_unix_usec / 1000000ULL; tv.tv_sec = time.time_unix_usec / 1000000ULL;
tv.tv_nsec = (time.time_unix_usec % 1000000ULL) * 1000ULL; tv.tv_nsec = (time.time_unix_usec % 1000000ULL) * 1000ULL;
clock_settime(CLOCK_REALTIME, &tv); if(clock_settime(CLOCK_REALTIME, &tv)) {
warnx("[timesync] synced.."); warn("failed setting clock");
}
else {
warnx("[timesync] UTC time synced.");
}
} }
} }
@@ -965,7 +969,7 @@ MavlinkReceiver::handle_message_timesync(mavlink_message_t *msg)
mavlink_timesync_t tsync; mavlink_timesync_t tsync;
mavlink_msg_timesync_decode(msg, &tsync); mavlink_msg_timesync_decode(msg, &tsync);
uint64_t now_ns = hrt_absolute_time() * 1000 ; uint64_t now_ns = hrt_absolute_time() * 1000LL ;
if (tsync.tc1 == 0) { if (tsync.tc1 == 0) {
@@ -980,13 +984,12 @@ MavlinkReceiver::handle_message_timesync(mavlink_message_t *msg)
} else if (tsync.tc1 > 0) { } else if (tsync.tc1 > 0) {
int64_t offset_ns = (9*_time_offset + (tsync.ts1 + now_ns - tsync.tc1*2)/2 )/10; // average offset int64_t offset_ns = (tsync.ts1 + now_ns - tsync.tc1*2)/2 ;
int64_t dt = _time_offset - offset_ns; int64_t dt = _time_offset - offset_ns;
if (dt > 10000000 || dt < -1000000) { // 10 millisecond skew if (dt > 10000000LL || dt < -10000000LL) { // 10 millisecond skew
_time_offset = (tsync.ts1 + now_ns - tsync.tc1*2)/2; _time_offset = offset_ns;
warnx("[timesync] Resetting."); warnx("[timesync] Hard setting offset.");
} else { } else {
smooth_time_offset(offset_ns); smooth_time_offset(offset_ns);
} }
@@ -1469,7 +1472,7 @@ uint64_t MavlinkReceiver::to_hrt(uint64_t usec)
void MavlinkReceiver::smooth_time_offset(uint64_t offset_ns) void MavlinkReceiver::smooth_time_offset(uint64_t offset_ns)
{ {
/* alpha = 0.75 fixed for now. The closer alpha is to 1.0, /* alpha = 0.6 fixed for now. The closer alpha is to 1.0,
* the faster the moving average updates in response to * the faster the moving average updates in response to
* new offset samples. * new offset samples.
*/ */
+2
View File
@@ -75,6 +75,8 @@
#include "mavlink_ftp.h" #include "mavlink_ftp.h"
#define PX4_EPOCH_SECS 1234567890ULL
class Mavlink; class Mavlink;
class MavlinkReceiver class MavlinkReceiver
+4 -6
View File
@@ -66,20 +66,18 @@ nshterm_main(int argc, char *argv[])
int fd = -1; int fd = -1;
int armed_fd = orb_subscribe(ORB_ID(actuator_armed)); int armed_fd = orb_subscribe(ORB_ID(actuator_armed));
struct actuator_armed_s armed; struct actuator_armed_s armed;
/* we assume the system does not provide arming status feedback */
bool armed_updated = false;
/* try the first 30 seconds or if arming system is ready */ /* try to bring up the console - stop doing so if the system gets armed */
while ((retries < 300) || armed_updated) { while (true) {
/* abort if an arming topic is published and system is armed */ /* abort if an arming topic is published and system is armed */
bool updated = false; bool updated = false;
if (orb_check(armed_fd, &updated)) { orb_check(armed_fd, &updated)
if (updated) {
/* the system is now providing arming status feedback. /* the system is now providing arming status feedback.
* instead of timing out, we resort to abort bringing * instead of timing out, we resort to abort bringing
* up the terminal. * up the terminal.
*/ */
armed_updated = true;
orb_copy(ORB_ID(actuator_armed), armed_fd, &armed); orb_copy(ORB_ID(actuator_armed), armed_fd, &armed);
if (armed.armed) { if (armed.armed) {