ardupilot/libraries/AP_GPS/GPS.cpp

99 lines
2.5 KiB
C++
Raw Normal View History

// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: t -*-
#include <FastSerial.h>
#define GPS_DEBUGGING 0
#if GPS_DEBUGGING
2012-08-17 03:19:44 -03:00
#include <FastSerial.h>
# define Debug(fmt, args ...) do {Serial.printf("%s:%d: " fmt "\n", __FUNCTION__, __LINE__, ## args); delay(0); } while(0)
#else
2012-08-17 03:19:44 -03:00
# define Debug(fmt, args ...)
#endif
#include <AP_Common.h>
#include <AP_Math.h>
#include "GPS.h"
#if defined(ARDUINO) && ARDUINO >= 100
2012-08-17 03:19:44 -03:00
#include "Arduino.h"
#else
2012-08-17 03:19:44 -03:00
#include "WProgram.h"
#endif
void
GPS::update(void)
{
2012-08-17 03:19:44 -03:00
bool result;
uint32_t tnow;
2011-10-28 15:52:50 -03:00
// call the GPS driver to process incoming data
result = read();
2012-08-17 03:19:44 -03:00
tnow = millis();
2011-10-28 15:52:50 -03:00
// if we did not get a message, and the idle timer has expired, re-init
if (!result) {
if ((tnow - _idleTimer) > idleTimeout) {
2012-08-17 03:19:44 -03:00
Debug("gps read timeout %lu %lu", (unsigned long)tnow, (unsigned long)_idleTimer);
2011-10-28 15:52:50 -03:00
_status = NO_GPS;
init(_nav_setting);
2011-10-28 15:52:50 -03:00
// reset the idle timer
_idleTimer = tnow;
2011-10-28 15:52:50 -03:00
}
} else {
// we got a message, update our status correspondingly
_status = fix ? GPS_OK : NO_FIX;
valid_read = true;
new_data = true;
// reset the idle timer
_idleTimer = tnow;
2012-08-17 03:19:44 -03:00
if (_status == GPS_OK) {
last_fix_time = _idleTimer;
_last_ground_speed_cm = ground_speed;
if (_have_raw_velocity) {
// the GPS is able to give us velocity numbers directly
_velocity_north = _vel_north * 0.01;
_velocity_east = _vel_east * 0.01;
} else {
float gps_heading = ToRad(ground_course * 0.01);
float gps_speed = ground_speed * 0.01;
float sin_heading, cos_heading;
cos_heading = cos(gps_heading);
sin_heading = sin(gps_heading);
_velocity_north = gps_speed * cos_heading;
_velocity_east = gps_speed * sin_heading;
}
}
2011-10-28 15:52:50 -03:00
}
}
void
GPS::setHIL(uint32_t _time, float _latitude, float _longitude, float _altitude,
float _ground_speed, float _ground_course, float _speed_3d, uint8_t _num_sats)
{
}
// XXX this is probably the wrong way to do it, too
void
GPS::_error(const char *msg)
{
2011-10-28 15:52:50 -03:00
Serial.println(msg);
}
///
/// write a block of configuration data to a GPS
///
void GPS::_write_progstr_block(Stream *_fs, const prog_char *pstr, uint8_t size)
{
2012-08-17 03:19:44 -03:00
while (size--) {
_fs->write(pgm_read_byte(pstr++));
}
}