00001 #pragma ident "$Id: AshtechPBEN.cpp 819 2007-10-09 17:46:08Z ocibu $"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
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
00059 clear(fmtbit | lenbit | crcbit);
00060 string& rawData = stream.rawData;
00061
00062
00063
00064 if (id == "" && rawData.size()>=11 &&
00065 rawData.substr(0,7) == preamble &&
00066 rawData[10]==',')
00067 id = rawData.substr(7,3);
00068
00069
00070
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
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 }