mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-11 02:18:29 -04:00
Change MediaTek timestamps to millisecond Time of Day
Add epoch method to return timestamp epoch. git-svn-id: https://arducopter.googlecode.com/svn/trunk@1589 f9c3cf11-9bcb-44bc-f272-b75c42450872
This commit is contained in:
parent
2edaf389e7
commit
d5e48364a1
@ -30,6 +30,9 @@ AP_GPS_MTK::init(void)
|
|||||||
|
|
||||||
// set 4Hz update rate
|
// set 4Hz update rate
|
||||||
_port->print(MTK_OUTPUT_4HZ);
|
_port->print(MTK_OUTPUT_4HZ);
|
||||||
|
|
||||||
|
// set initial epoch code
|
||||||
|
_epoch = TIME_OF_DAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process bytes available from the stream
|
// Process bytes available from the stream
|
||||||
@ -132,8 +135,14 @@ restart:
|
|||||||
ground_course = _swapl(&_buffer.msg.ground_course) / 10000;
|
ground_course = _swapl(&_buffer.msg.ground_course) / 10000;
|
||||||
num_sats = _buffer.msg.satellites;
|
num_sats = _buffer.msg.satellites;
|
||||||
|
|
||||||
// XXX docs say this is UTC, but our clients expect msToW
|
// time from gps is UTC, but convert here to msToD
|
||||||
time = _swapl(&_buffer.msg.utc_time);
|
long time_utc = _swapl(&_buffer.msg.utc_time);
|
||||||
|
long temp = (time_utc/10000000);
|
||||||
|
time_utc -= temp*10000000;
|
||||||
|
time = temp * 3600000;
|
||||||
|
temp = (time_utc/100000);
|
||||||
|
time_utc -= temp*100000;
|
||||||
|
time += temp * 60000 + time_utc;
|
||||||
|
|
||||||
parsed = true;
|
parsed = true;
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,11 @@ AP_GPS_MTK16::init(void)
|
|||||||
|
|
||||||
// set 4Hz update rate
|
// set 4Hz update rate
|
||||||
_port->print(MTK_OUTPUT_4HZ);
|
_port->print(MTK_OUTPUT_4HZ);
|
||||||
|
|
||||||
|
// set initial epoch code
|
||||||
|
_epoch = TIME_OF_DAY;
|
||||||
|
_time_offset = 0;
|
||||||
|
_offset_calculated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process bytes available from the stream
|
// Process bytes available from the stream
|
||||||
@ -47,9 +52,9 @@ AP_GPS_MTK16::init(void)
|
|||||||
bool
|
bool
|
||||||
AP_GPS_MTK16::read(void)
|
AP_GPS_MTK16::read(void)
|
||||||
{
|
{
|
||||||
uint8_t data;
|
uint8_t data;
|
||||||
int numc;
|
int numc;
|
||||||
bool parsed = false;
|
bool parsed = false;
|
||||||
|
|
||||||
numc = _port->available();
|
numc = _port->available();
|
||||||
for (int i = 0; i < numc; i++) { // Process bytes received
|
for (int i = 0; i < numc; i++) { // Process bytes received
|
||||||
@ -122,12 +127,34 @@ restart:
|
|||||||
ground_course = _buffer.msg.ground_course;
|
ground_course = _buffer.msg.ground_course;
|
||||||
num_sats = _buffer.msg.satellites;
|
num_sats = _buffer.msg.satellites;
|
||||||
hdop = _buffer.msg.hdop;
|
hdop = _buffer.msg.hdop;
|
||||||
|
date = _buffer.msg.utc_date;
|
||||||
// XXX docs say this is UTC, but our clients expect msToW
|
|
||||||
time = _swapl(&_buffer.msg.utc_time);
|
// time from gps is UTC, but convert here to msToD
|
||||||
|
long time_utc = _buffer.msg.utc_time;
|
||||||
|
long temp = (time_utc/10000000);
|
||||||
|
time_utc -= temp*10000000;
|
||||||
|
time = temp * 3600000;
|
||||||
|
temp = (time_utc/100000);
|
||||||
|
time_utc -= temp*100000;
|
||||||
|
time += temp * 60000 + time_utc;
|
||||||
|
|
||||||
parsed = true;
|
parsed = true;
|
||||||
|
|
||||||
|
/* Waiting on clarification of MAVLink protocol!
|
||||||
|
if(!_offset_calculated && parsed) {
|
||||||
|
long tempd1 = date;
|
||||||
|
long day = tempd1/10000;
|
||||||
|
tempd1 -= day * 10000;
|
||||||
|
long month = tempd1/100;
|
||||||
|
long year = tempd1 - month * 100;
|
||||||
|
_time_offset = _calc_epoch_offset(day, month, year);
|
||||||
|
_epoch = UNIX_EPOCH;
|
||||||
|
_offset_calculated = TRUE;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return parsed;
|
return parsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +55,10 @@ private:
|
|||||||
// State machine state
|
// State machine state
|
||||||
uint8_t _step;
|
uint8_t _step;
|
||||||
uint8_t _payload_counter;
|
uint8_t _payload_counter;
|
||||||
|
|
||||||
|
// Time from UNIX Epoch offset
|
||||||
|
long _time_offset;
|
||||||
|
bool _offset_calculated;
|
||||||
|
|
||||||
// Receive buffer
|
// Receive buffer
|
||||||
union {
|
union {
|
||||||
|
@ -27,6 +27,8 @@ AP_GPS_UBLOX::init(void)
|
|||||||
// right reporting configuration.
|
// right reporting configuration.
|
||||||
|
|
||||||
_port->flush();
|
_port->flush();
|
||||||
|
|
||||||
|
_epoch = TIME_OF_WEEK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process bytes available from the stream
|
// Process bytes available from the stream
|
||||||
|
@ -43,6 +43,22 @@ public:
|
|||||||
///
|
///
|
||||||
GPS_Status status(void) { return _status; }
|
GPS_Status status(void) { return _status; }
|
||||||
|
|
||||||
|
/// GPS time epoch codes
|
||||||
|
///
|
||||||
|
enum GPS_Time_Epoch {
|
||||||
|
TIME_OF_DAY = 0, ///<
|
||||||
|
TIME_OF_WEEK = 1, ///< Ublox
|
||||||
|
TIME_OF_YEAR = 2, ///< MTK, NMEA
|
||||||
|
UNIX_EPOCH = 3 ///< If available
|
||||||
|
}; ///< SIFR?
|
||||||
|
|
||||||
|
|
||||||
|
/// Query GPS time epoch
|
||||||
|
///
|
||||||
|
/// @returns Current GPS time epoch code
|
||||||
|
///
|
||||||
|
GPS_Time_Epoch epoch(void) { return _epoch; }
|
||||||
|
|
||||||
/// Startup initialisation.
|
/// Startup initialisation.
|
||||||
///
|
///
|
||||||
/// This routine performs any one-off initialisation required to set the
|
/// This routine performs any one-off initialisation required to set the
|
||||||
@ -53,7 +69,7 @@ public:
|
|||||||
virtual void init(void) = 0;
|
virtual void init(void) = 0;
|
||||||
|
|
||||||
// Properties
|
// Properties
|
||||||
long time; ///< GPS time (FORMAT TBD)
|
long time; ///< GPS time (milliseconds from epoch)
|
||||||
long date; ///< GPS date (FORMAT TBD)
|
long date; ///< GPS date (FORMAT TBD)
|
||||||
long latitude; ///< latitude in degrees * 10,000,000
|
long latitude; ///< latitude in degrees * 10,000,000
|
||||||
long longitude; ///< longitude in degrees * 10,000,000
|
long longitude; ///< longitude in degrees * 10,000,000
|
||||||
@ -122,6 +138,9 @@ protected:
|
|||||||
/// printf vs. the potential benefits
|
/// printf vs. the potential benefits
|
||||||
///
|
///
|
||||||
void _error(const char *msg);
|
void _error(const char *msg);
|
||||||
|
|
||||||
|
/// Time epoch code for the gps in use
|
||||||
|
GPS_Time_Epoch _epoch;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -139,6 +158,7 @@ private:
|
|||||||
|
|
||||||
/// Our current status
|
/// Our current status
|
||||||
GPS_Status _status;
|
GPS_Status _status;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline long
|
inline long
|
||||||
|
Loading…
Reference in New Issue
Block a user