2013-05-29 20:52:21 -03:00
|
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
2013-08-29 02:34:34 -03:00
|
|
|
|
/*
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-09-07 01:20:34 -03:00
|
|
|
|
//
|
2012-08-21 23:19:51 -03:00
|
|
|
|
// GPS_406.cpp - 406 GPS library for Arduino
|
|
|
|
|
// Code by Michael Smith, Jason Short, Jordi Mu<4D>oz and Jose Julio. DIYDrones.com
|
|
|
|
|
// This code works with boards based on ATMega168/328 ATMega1280 (Serial port 1)
|
2010-09-07 01:20:34 -03:00
|
|
|
|
//
|
2012-09-27 02:18:44 -03:00
|
|
|
|
#include <AP_HAL.h>
|
|
|
|
|
|
2010-09-06 17:16:50 -03:00
|
|
|
|
#include "AP_GPS_406.h"
|
2012-09-27 02:18:44 -03:00
|
|
|
|
|
|
|
|
|
extern const AP_HAL::HAL& hal;
|
2010-09-06 17:16:50 -03:00
|
|
|
|
|
2010-09-07 01:20:34 -03:00
|
|
|
|
static const char init_str[] = "$PSRF100,0,57600,8,1,0*37";
|
2010-09-06 17:16:50 -03:00
|
|
|
|
|
|
|
|
|
// Public Methods ////////////////////////////////////////////////////////////////////
|
2012-12-17 22:31:05 -04:00
|
|
|
|
void AP_GPS_406::init(AP_HAL::UARTDriver *s, enum GPS_Engine_Setting nav_setting)
|
2010-09-06 17:16:50 -03:00
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
|
_change_to_sirf_protocol(); // Changes to SIRF protocol and sets baud rate
|
|
|
|
|
_configure_gps(); // Function to configure GPS, to output only the desired msg's
|
2010-09-06 17:16:50 -03:00
|
|
|
|
|
2012-12-17 22:31:05 -04:00
|
|
|
|
AP_GPS_SIRF::init(s, nav_setting); // let the superclass do anything it might need here
|
2010-09-06 17:16:50 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Private Methods //////////////////////////////////////////////////////////////
|
|
|
|
|
|
2011-10-28 15:52:50 -03:00
|
|
|
|
void
|
2010-09-07 01:20:34 -03:00
|
|
|
|
AP_GPS_406::_configure_gps(void)
|
2010-09-06 17:16:50 -03:00
|
|
|
|
{
|
2012-08-21 23:19:51 -03:00
|
|
|
|
const uint8_t gps_header[] = {0xA0, 0xA2, 0x00, 0x08, 0xA6, 0x00};
|
|
|
|
|
const uint8_t gps_payload[] = {0x02, 0x04, 0x07, 0x09, 0x1B};
|
|
|
|
|
const uint8_t gps_checksum[] = {0xA8, 0xAA, 0xAD, 0xAF, 0xC1};
|
|
|
|
|
const uint8_t gps_ender[] = {0xB0, 0xB3};
|
2011-10-28 15:52:50 -03:00
|
|
|
|
|
2012-08-18 04:35:38 -03:00
|
|
|
|
for(int16_t z = 0; z < 2; z++) {
|
|
|
|
|
for(int16_t x = 0; x < 5; x++) {
|
2012-08-21 23:19:51 -03:00
|
|
|
|
_port->write(gps_header, sizeof(gps_header)); // Prints the msg header, is the same header for all msg..
|
|
|
|
|
_port->write(gps_payload[x]); // Prints the payload, is not the same for every msg
|
|
|
|
|
for(int16_t y = 0; y < 6; y++) // Prints 6 zeros
|
2011-10-28 15:52:50 -03:00
|
|
|
|
_port->write((uint8_t)0);
|
2012-08-21 23:19:51 -03:00
|
|
|
|
_port->write(gps_checksum[x]); // Print the Checksum
|
|
|
|
|
_port->write(gps_ender[0]); // Print the Ender of the string, is same on all msg's.
|
|
|
|
|
_port->write(gps_ender[1]); // ender
|
2011-10-28 15:52:50 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-09-06 17:16:50 -03:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-07 01:20:34 -03:00
|
|
|
|
// The EM406 defalts to NMEA at 4800bps. We want to switch it to SiRF binary
|
|
|
|
|
// mode at a higher rate.
|
|
|
|
|
//
|
|
|
|
|
// The change is sticky, but only for as long as the internal supercap holds
|
|
|
|
|
// settings (usually less than a week).
|
|
|
|
|
//
|
2011-10-28 15:52:50 -03:00
|
|
|
|
void
|
2010-09-07 01:20:34 -03:00
|
|
|
|
AP_GPS_406::_change_to_sirf_protocol(void)
|
2010-09-06 17:16:50 -03:00
|
|
|
|
{
|
2012-09-27 02:18:44 -03:00
|
|
|
|
// this is a bit grody...
|
|
|
|
|
AP_HAL::UARTDriver *fs = (AP_HAL::UARTDriver*)_port;
|
2010-09-06 17:16:50 -03:00
|
|
|
|
|
2011-10-28 15:52:50 -03:00
|
|
|
|
fs->begin(4800);
|
2012-09-27 02:18:44 -03:00
|
|
|
|
hal.scheduler->delay(300);
|
2011-10-28 15:52:50 -03:00
|
|
|
|
_port->print(init_str);
|
2012-09-27 02:18:44 -03:00
|
|
|
|
hal.scheduler->delay(300);
|
2010-09-07 01:20:34 -03:00
|
|
|
|
|
2011-10-28 15:52:50 -03:00
|
|
|
|
fs->begin(9600);
|
2012-09-27 02:18:44 -03:00
|
|
|
|
hal.scheduler->delay(300);
|
2011-10-28 15:52:50 -03:00
|
|
|
|
_port->print(init_str);
|
2012-09-27 02:18:44 -03:00
|
|
|
|
hal.scheduler->delay(300);
|
2010-09-22 21:20:11 -03:00
|
|
|
|
|
2011-10-28 15:52:50 -03:00
|
|
|
|
fs->begin(GPS_406_BITRATE);
|
2012-09-27 02:18:44 -03:00
|
|
|
|
hal.scheduler->delay(300);
|
2011-10-28 15:52:50 -03:00
|
|
|
|
_port->print(init_str);
|
2012-09-27 02:18:44 -03:00
|
|
|
|
hal.scheduler->delay(300);
|
2010-09-06 17:16:50 -03:00
|
|
|
|
}
|
|
|
|
|
|