|
From: <rus...@us...> - 2008-06-04 02:02:24
|
Revision: 153
http://gearbox.svn.sourceforge.net/gearbox/?rev=153&view=rev
Author: russo2503v
Date: 2008-06-03 19:02:30 -0700 (Tue, 03 Jun 2008)
Log Message:
-----------
removed mga functionality. moved nmea into the driver
Modified Paths:
--------------
gearbox/trunk/submitted/gbxgarminacfr/CMakeLists.txt
gearbox/trunk/submitted/gbxgarminacfr/driver.cpp
Added Paths:
-----------
gearbox/trunk/submitted/gbxgarminacfr/nmea.cpp
gearbox/trunk/submitted/gbxgarminacfr/nmea.h
Removed Paths:
-------------
gearbox/trunk/submitted/gbxgarminacfr/gbxgpsutilacfr/
Modified: gearbox/trunk/submitted/gbxgarminacfr/CMakeLists.txt
===================================================================
--- gearbox/trunk/submitted/gbxgarminacfr/CMakeLists.txt 2008-06-04 01:32:03 UTC (rev 152)
+++ gearbox/trunk/submitted/gbxgarminacfr/CMakeLists.txt 2008-06-04 02:02:30 UTC (rev 153)
@@ -9,17 +9,13 @@
# SET( int_libs GbxUtilAcfr GbxSerialAcfr GbxGpsUtilAcfr )
GBX_REQUIRE_TARGETS( build LIB ${lib_name} ${int_libs} )
-SET( private_libs GbxGpsUtilAcfr )
-
IF( build )
- ADD_SUBDIRECTORY( gbxgpsutilacfr )
-
INCLUDE( ${GBX_CMAKE_DIR}/UseBasicRules.cmake )
FILE( GLOB hdrs *.h )
FILE( GLOB srcs *.cpp )
- SET( dep_libs ${int_libs} ${private_libs} )
+ SET( dep_libs ${int_libs} )
GBX_ADD_LIBRARY( ${lib_name} SHARED ${srcs} )
TARGET_LINK_LIBRARIES( ${lib_name} ${dep_libs} )
Modified: gearbox/trunk/submitted/gbxgarminacfr/driver.cpp
===================================================================
--- gearbox/trunk/submitted/gbxgarminacfr/driver.cpp 2008-06-04 01:32:03 UTC (rev 152)
+++ gearbox/trunk/submitted/gbxgarminacfr/driver.cpp 2008-06-04 02:02:30 UTC (rev 153)
@@ -11,7 +11,7 @@
#include <iostream>
#include <sstream>
#include <gbxsickacfr/gbxutilacfr/gbxutilacfr.h>
-#include <gbxgarminacfr/gbxgpsutilacfr/nmea.h>
+#include "nmea.h"
#include <cstdlib>
#include <sys/time.h>
#include <time.h>
Copied: gearbox/trunk/submitted/gbxgarminacfr/nmea.cpp (from rev 152, gearbox/trunk/submitted/gbxgarminacfr/gbxgpsutilacfr/nmea.cpp)
===================================================================
--- gearbox/trunk/submitted/gbxgarminacfr/nmea.cpp (rev 0)
+++ gearbox/trunk/submitted/gbxgarminacfr/nmea.cpp 2008-06-04 02:02:30 UTC (rev 153)
@@ -0,0 +1,208 @@
+/*
+ * GearBox Project: Peer-Reviewed Open-Source Libraries for Robotics
+ * http://gearbox.sf.net/
+ * Copyright (c) 2004-2008 Mathew Ridley, Alex Brooks, Alexei Makarenko, Tobias Kaupp
+ *
+ * This distribution is licensed to you under the terms described in
+ * the LICENSE file included in this distribution.
+ *
+ */
+
+#include <stdio.h>
+#include <string>
+#include <iostream>
+#include <assert.h>
+#include <gbxsickacfr/gbxutilacfr/tokenise.h>
+
+//////////////////////////////
+
+// Ensure we have strnlen
+// eg. Solaris doesn't define strnlen in string.h, so define it here.
+#if !HAVE_STRNLEN
+
+#include <cstring>
+
+// inline the fucker to guard against multiple inclusion, without the
+// hassle of a special lib.
+inline size_t strnlen(const char *s, size_t maxlen)
+{
+ char *p;
+ if (s == NULL) {
+ return maxlen;
+ }
+ p = (char *)memchr(s, 0, maxlen);
+ if (p == NULL) {
+ return maxlen;
+ }
+ return ((p - s) + 1);
+}
+#endif
+
+//////////////////////////////
+
+#include "nmea.h"
+
+using namespace std;
+using namespace gbxgpsutilacfr;
+
+const char NMEAStartOfSentence = '$';
+const char NMEAChecksumDelim = '*';
+
+
+//*************************************************************
+//The blank constructor
+NmeaMessage::NmeaMessage()
+{
+ init();
+}
+
+//**************************************************************
+void NmeaMessage::init()
+{
+ haveSentence_ = false;
+ haveTokens_ = false;
+ haveCheckSum_ = false;
+ checkSumOK_ = false;
+
+ // Now clear the internal data store
+ sentence_[0] = 0;
+ dataTokens_.clear();
+}
+
+
+//****************************************************************
+NmeaMessage::NmeaMessage(const char *sentence, int testCheckSum)
+{
+ init();
+ setSentence(sentence,testCheckSum);
+}
+
+
+//**********************************************************************
+//Load the data as requested and test the checksum if we are asked to.
+void NmeaMessage::setSentence(const char *data, int AddOrTestCheckSum)
+{
+ init();
+
+ strncpy(sentence_,data, MAX_SENTENCE_LEN);
+
+ //terminate just in case, Note that we have a buffer which is
+ //MAX_SENTENCE_LEN + 1 long!
+
+ sentence_[MAX_SENTENCE_LEN] = '\0';
+ haveSentence_ = true;
+
+ switch(AddOrTestCheckSum)
+ {
+ case TestChecksum: //This is for Rx'd data that we need to test for correct reception
+ testChecksumOk(); break;
+ case AddChecksum: //This is for Tx data that needs to checksummed before sending
+ addCheckSum(); checkSumOK_ = true; break;
+ case DontTestOrAddChecksum:
+ break;
+ default:
+ assert(true);
+ }
+}
+
+
+//*****************************************************************
+bool NmeaMessage::testChecksumOk()
+{
+ haveCheckSum_ = true;
+ checkSumOK_ = false;
+
+ //First save the checksum chars from the existing message
+ char* ptr;
+ char chksum_HIB,chksum_LOB;
+
+ //First save the existing two checksum chars from the message
+ //These are straight after the '*' character
+ ptr = strchr(sentence_, NMEAChecksumDelim);
+ if(!ptr){return false;}
+
+ //save the high and low bytes of the checksum
+ //Make sure they are in upper case!
+ chksum_HIB = toupper(*(++ptr));
+ chksum_LOB = toupper(*(ptr + 1));
+
+
+ //invalidate the existing checksum
+ *ptr = *(ptr+1) = 'x';
+
+ //****NOTE** We leave the ptr pointing at the first chksum byte
+
+ //Re-calculate our own copy of the checksum
+ addCheckSum();
+
+ //Now compare our saved version with our new ones
+ if((chksum_HIB == *ptr) && (chksum_LOB == *(ptr+1))){
+ //all looked good!
+ checkSumOK_ = true;
+ return true;
+ }
+
+ //failed the checksum!
+ return false;
+}
+
+
+//*****************************************************
+// Add the checksum chars to an existing message
+// NOTE: this assumes that there is allready space in the message for
+// the checksum, and that the checksum delimiter is there
+
+void NmeaMessage::addCheckSum(){
+
+ assert( haveSentence_ );
+
+ haveCheckSum_ = true;
+
+ //check that we have the '$' at the start
+ if(sentence_[0]!= NMEAStartOfSentence)
+ {return;}
+
+ unsigned char chkRunning = 0;
+
+ int loopCount;
+ unsigned char nextChar;
+ for( loopCount =1; loopCount < MAX_SENTENCE_LEN; loopCount++){
+
+ nextChar = static_cast<unsigned char>(sentence_[loopCount]);
+
+ // no delimiter uh oh
+ if((nextChar=='\r')||(nextChar=='\n')||(nextChar=='\0')){
+ throw NmeaException("nmea: cannot calculate checksum, missing '*'\n");
+ return;
+ }
+
+ // goodie we found it
+ if(nextChar==NMEAChecksumDelim)
+ {break;}
+
+ //Keep the running total going
+ chkRunning ^= nextChar;
+ }
+
+ //Put the byte values as upper case HEX back into the message
+ sprintf(sentence_ + loopCount + 1,"%02X",chkRunning);
+}
+
+
+//**********************************************************************
+// Parse the data fields of our message...
+void NmeaMessage::parseTokens(){
+
+ //We should not attempt to be parsing a message twice...
+ assert (numDataTokens() == 0);
+
+ //Split the message at the commas
+ //TODO cope with missing fields
+ dataTokens_ = gbxsickacfr::gbxutilacfr::tokenise(sentence_, ",");
+
+ //Now discard the $ and the * from the first and last tokens...
+ //TODO : - dataTokens_[0] =
+
+ //keep track of what we have done.
+ haveTokens_ = true;
+}
Copied: gearbox/trunk/submitted/gbxgarminacfr/nmea.h (from rev 152, gearbox/trunk/submitted/gbxgarminacfr/gbxgpsutilacfr/nmea.h)
===================================================================
--- gearbox/trunk/submitted/gbxgarminacfr/nmea.h (rev 0)
+++ gearbox/trunk/submitted/gbxgarminacfr/nmea.h 2008-06-04 02:02:30 UTC (rev 153)
@@ -0,0 +1,122 @@
+/*
+ * GearBox Project: Peer-Reviewed Open-Source Libraries for Robotics
+ * http://gearbox.sf.net/
+ * Copyright (c) 2004-2008 Alex Brooks, Alexei Makarenko, Tobias Kaupp, Duncan Mercer
+ *
+ * This distribution is licensed to you under the terms described in
+ * the LICENSE file included in this distribution.
+ *
+ */
+
+#include <vector>
+#include <string>
+
+// #include <hydroportability/sharedlib.h>
+
+#ifndef GBXGPSUTILACFR_NMEA_H
+#define GBXGPSUTILACFR_NMEA_H
+
+
+
+/*
+
+for further info:
+
+http://www.kh-gps.de/nmea-faq.htm
+http://vancouver-webpages.com/peter/nmeafaq.txt
+
+NMEA-0183 sentence
+
+$aaccc,c--c*hh<CR><LF>
+|| || || |
+|| || || \________ <CR><LF> - End of sentence (0xOD 0xOA)
+|| || |\__________ hh - Checksum field hexadecimal [optional]
+|| || \___________ * - Checksum delimiter (0x2A) [optional]
+|| |\_______________ c--c - Data sentence block
+|| \________________ , - Field delimiter (0x2c)
+|\_____________________ aaccc - Address field/Command
+\______________________ $ - Start of sentence
+
+ The optional checksum field consists of a "*" and two hex digits
+ representing the exclusive OR of all characters between, but not
+ including, the "$" and "*". A checksum is required on some
+ sentences.
+
+*/
+
+namespace gbxgpsutilacfr {
+
+
+// class SOEXPORT NmeaException : public std::exception
+class NmeaException : public std::exception
+{
+public:
+
+ NmeaException(const char *message)
+ : message_(message) {}
+ NmeaException(const std::string &message)
+ : message_(message) {}
+ virtual ~NmeaException() throw() {}
+ virtual const char* what() const throw() { return message_.c_str(); }
+
+protected:
+ std::string message_;
+};
+
+
+#define MAX_SENTENCE_LEN 256
+
+// When using class to send data, need to add checksum, when reciving data need to test checksum
+// Checksums are usually optional
+enum{TestChecksum, AddChecksum, DontTestOrAddChecksum};
+
+// class SOEXPORT NmeaMessage{
+class NmeaMessage
+{
+public:
+ NmeaMessage();
+ NmeaMessage(const char *sentence, int testCheckSum = DontTestOrAddChecksum);
+
+ // Set up the internal data for a sentence
+ void setSentence(const char *data, int testCheckSum = DontTestOrAddChecksum);
+
+ // Do we only have the raw string ?
+ bool haveSentence() const { return haveSentence_; };
+ // Have we parsed fields ?
+ bool haveTokens() const { return haveTokens_; };
+ // have we a valid checksum ?
+ bool haveValidChecksum() const { return checkSumOK_; };
+ // have we checked the checksum?
+ bool haveTestedChecksum()const { return haveCheckSum_; };
+ // calculate the checksum from sentence
+ // Note that this function may throw NMEA_Exception...
+ bool testChecksumOk();
+ // Return the raw sentence string
+ const char * sentence() { return sentence_; };
+ // Return a single data token as a string
+ std::string& getDataToken(int i) { return dataTokens_[i]; };
+
+ // Return the number of fields
+ int numDataTokens() const { return dataTokens_.size(); };
+ //Tokenise the string that we received
+ void parseTokens();
+
+private:
+ void init();
+ void addCheckSum();
+ // Do we only have the raw string ?
+ bool haveSentence_;
+ // Have we parsed data into tokens ?
+ bool haveTokens_;
+ // Have we a checksum and is it valid?
+ bool haveCheckSum_;
+ bool checkSumOK_;
+ // The raw sentence, allow for terminator
+ char sentence_[MAX_SENTENCE_LEN+1];
+ // The tokenised data
+ std::vector<std::string> dataTokens_;
+};
+
+}
+
+#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|