• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

/home/jgoppert/Projects/ap/libraries/AP_GPS/AP_GPS_406.cpp

Go to the documentation of this file.
00001 // -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: t -*-
00002 //
00003 //      GPS_406.cpp - 406 GPS library for Arduino
00004 //      Code by Michael Smith, Jason Short, Jordi Muņoz and Jose Julio. DIYDrones.com
00005 //      This code works with boards based on ATMega168/328 ATMega1280 (Serial port 1)
00006 //
00007 //      This library is free software; you can redistribute it and / or
00008 //      modify it under the terms of the GNU Lesser General Public
00009 //      License as published by the Free Software Foundation; either
00010 //      version 2.1 of the License, or (at your option) any later version.
00011 
00012 #include "../FastSerial/FastSerial.h"   // because we need to change baud rates... ugh.
00013 #include "AP_GPS_406.h"
00014 #include "WProgram.h"
00015 
00016 static const char init_str[] = "$PSRF100,0,57600,8,1,0*37";
00017 
00018 // Constructors ////////////////////////////////////////////////////////////////
00019 AP_GPS_406::AP_GPS_406(Stream *s) : AP_GPS_SIRF(s)
00020 {
00021 }
00022 
00023 // Public Methods ////////////////////////////////////////////////////////////////////
00024 void AP_GPS_406::init(void)
00025 {
00026         _change_to_sirf_protocol();             // Changes to SIRF protocol and sets baud rate
00027         _configure_gps();                               // Function to configure GPS, to output only the desired msg's
00028 
00029         AP_GPS_SIRF::init();                    // let the superclass do anything it might need here
00030 }
00031 
00032 // Private Methods //////////////////////////////////////////////////////////////
00033 
00034 void 
00035 AP_GPS_406::_configure_gps(void)
00036 {
00037         const uint8_t gps_header[]              = {0xA0, 0xA2, 0x00, 0x08, 0xA6, 0x00};
00038         const uint8_t gps_payload[]     = {0x02, 0x04, 0x07, 0x09, 0x1B};
00039         const uint8_t gps_checksum[]    = {0xA8, 0xAA, 0xAD, 0xAF, 0xC1};
00040         const uint8_t gps_ender[]               = {0xB0, 0xB3};
00041         
00042         for(int z = 0; z < 2; z++){
00043                 for(int x = 0; x < 5; x++){
00044                         _port->write(gps_header, sizeof(gps_header));   // Prints the msg header, is the same header for all msg..
00045                         _port->write(gps_payload[x]);                                   // Prints the payload, is not the same for every msg
00046                         for(int y = 0; y < 6; y++)                                              // Prints 6 zeros
00047                                 _port->write((uint8_t)0);
00048                         _port->write(gps_checksum[x]);                                  // Print the Checksum
00049                         _port->write(gps_ender[0]);                                             // Print the Ender of the string, is same on all msg's. 
00050                         _port->write(gps_ender[1]);                                             // ender        
00051                 }
00052         }       
00053 }
00054 
00055 // The EM406 defalts to NMEA at 4800bps.  We want to switch it to SiRF binary
00056 // mode at a higher rate.
00057 //
00058 // The change is sticky, but only for as long as the internal supercap holds
00059 // settings (usually less than a week).
00060 //
00061 void 
00062 AP_GPS_406::_change_to_sirf_protocol(void)
00063 {
00064         FastSerial      *fs = (FastSerial *)_port;      // this is a bit grody...
00065 
00066         fs->begin(4800);
00067         delay(300);
00068         _port->print(init_str);
00069         delay(300);
00070 
00071         fs->begin(9600);
00072         delay(300);
00073         _port->print(init_str);
00074         delay(300);
00075 
00076         fs->begin(GPS_406_BITRATE);
00077         delay(300);
00078         _port->print(init_str);
00079         delay(300);
00080 }
00081 

Generated for ArduPilot Libraries by doxygen