AshtechPBEN.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: AshtechPBEN.cpp 819 2007-10-09 17:46:08Z ocibu $"
00002 
00003 //============================================================================
00004 //
00005 //  This file is part of GPSTk, the GPS Toolkit.
00006 //
00007 //  The GPSTk is free software; you can redistribute it and/or modify
00008 //  it under the terms of the GNU Lesser General Public License as published
00009 //  by the Free Software Foundation; either version 2.1 of the License, or
00010 //  any later version.
00011 //
00012 //  The GPSTk is distributed in the hope that it will be useful,
00013 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //  GNU Lesser General Public License for more details.
00016 //
00017 //  You should have received a copy of the GNU Lesser General Public
00018 //  License along with GPSTk; if not, write to the Free Software Foundation,
00019 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //  
00021 //  Copyright 2004, The University of Texas at Austin
00022 //
00023 //============================================================================
00024 
00025 //============================================================================
00026 //
00027 //This software developed by Applied Research Laboratories at the University of
00028 //Texas at Austin, under contract to an agency or agencies within the U.S. 
00029 //Department of Defense. The U.S. Government retains all rights to use,
00030 //duplicate, distribute, disclose, or release this software. 
00031 //
00032 //Pursuant to DoD Directive 523024 
00033 //
00034 // DISTRIBUTION STATEMENT A: This software has been approved for public 
00035 //                           release, distribution is unlimited.
00036 //
00037 //=============================================================================
00038 
00039 #include "StringUtils.hpp"
00040 #include "BinUtils.hpp"
00041 
00042 #include "AshtechPBEN.hpp"
00043 #include "AshtechStream.hpp"
00044 #include "TimeConstants.hpp"
00045 
00046 using namespace std;
00047 
00048 namespace gpstk
00049  {
00050    const char* AshtechPBEN::myId = "PBN";
00051 
00052    //---------------------------------------------------------------------------
00053    void AshtechPBEN::reallyGetRecord(FFStream& ffs)
00054       throw(std::exception, FFStreamError, EndOfFile)
00055    {
00056       AshtechStream& stream=dynamic_cast<AshtechStream&>(ffs);
00057 
00058       // make sure the object is reset before starting the search
00059       clear(fmtbit | lenbit | crcbit);
00060       string& rawData = stream.rawData;
00061 
00062       // If this object doesn't have an id set yet, assume that the streams
00063       // most recent read id is what we need to be
00064       if (id == "" && rawData.size()>=11 && 
00065           rawData.substr(0,7) == preamble &&
00066           rawData[10]==',')
00067          id = rawData.substr(7,3);
00068 
00069       // If that didn't work, or this is object is not of the right type,
00070       // then give up.
00071       if (id == "" || !checkId(id))
00072          return;
00073 
00074       readBody(stream);
00075    }
00076 
00077    //---------------------------------------------------------------------------
00078    void AshtechPBEN::decode(const std::string& data)
00079       throw(std::exception, FFStreamError)
00080    {
00081       using gpstk::BinUtils::decodeVar;
00082 
00083       string str(data);
00084       if (str.length() == 69)
00085       {
00086          ascii=false;
00087          header      = str.substr(0,11); str.erase(0,11);
00088          sow         = 1e-3 * decodeVar<int32_t>(str);
00089          sitename    = str.substr(0,4); str.erase(0,4);
00090          navx        = decodeVar<double>(str);
00091          navy        = decodeVar<double>(str);
00092          navz        = decodeVar<double>(str);
00093          navt        = decodeVar<float>(str);
00094          navxdot     = decodeVar<float>(str);
00095          navydot     = decodeVar<float>(str);
00096          navzdot     = decodeVar<float>(str);
00097          navtdot     = decodeVar<float>(str);
00098          pdop        = decodeVar<uint16_t>(str);
00099          lat =  lon =  alt =  numSV =  hdop =  vdop =  tdop = 0;
00100 
00101          checksum = decodeVar<uint16_t>(str);
00102          clear();
00103 
00104          uint16_t csum=0;
00105          int len=data.size()-3-11;
00106          string body(data.substr(11, len));
00107          while (body.size()>1)
00108             csum += decodeVar<uint16_t>(body);
00109 
00110          if (csum != checksum)
00111          {
00112             setstate(crcbit);
00113             if (debugLevel)
00114                cout << "checksum error, computed:" << hex << csum
00115                     << " received:" << checksum << dec << endl;
00116          }
00117 
00118       }
00119       else
00120       {
00121          ascii=true;
00122          header = str.substr(0,11); str.erase(0,11);
00123          stringstream iss(str);
00124          double latMin,lonMin;
00125          char c;
00126          iss >> sow >> c
00127              >> navx>> c >> navy >> c >> navz >> c
00128              >> lat >> c >> latMin >> c >> lon >> c >> lonMin >> c >> alt >> c
00129              >> navxdot>> c  >> navydot>> c  >> navzdot >> c
00130              >> numSV >> c;
00131          getline(iss, sitename, ',');
00132          iss >> pdop>> c  >> hdop>> c  >> vdop>> c  >> tdop;
00133 
00134          // Note that there isn't a checksum on the PBNs
00135 
00136          lat += latMin / 60;
00137          lon += lonMin / 60;
00138          navt = navtdot = 0;
00139          if (iss)
00140             clear();
00141       }
00142 
00143       if (sow>FULLWEEK)
00144          setstate(fmtbit);
00145    }
00146 
00147    //---------------------------------------------------------------------------
00148    void AshtechPBEN::dump(ostream& out) const throw()
00149    {
00150       ostringstream oss;
00151       using gpstk::StringUtils::asString;
00152       using gpstk::StringUtils::leftJustify;
00153 
00154       AshtechData::dump(out);
00155       oss << getName() << "1:"
00156           << " SOW:" << asString(sow, 1)
00157           << " #SV:" << (int)numSV
00158           << " PDOP:" << (int)pdop
00159           << " ClkOff:" << asString(navt, 3) 
00160           << " ClkDft:" << asString(navtdot, 3)
00161           << " sitename:" << sitename
00162           << " " << (ascii?"ascii":"bin")
00163           << endl
00164           << getName() << "2:"
00165           << " X:" << asString(navx, 1)
00166           << " Y:" << asString(navy, 1)
00167           << " Z:" << asString(navz, 1)
00168           << " Vx:" << asString(navxdot, 3)
00169           << " Vy:" << asString(navydot, 3)
00170           << " Vz:" << asString(navzdot, 3)
00171           << endl;
00172       out << oss.str() << flush;
00173    }
00174 } // namespace gpstk

Generated on Thu Feb 9 03:30:54 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1