00001 #pragma ident "$Id: AshtechData.cpp 861 2007-11-01 14:18:26Z 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 "AshtechData.hpp"
00043 #include "AshtechStream.hpp"
00044
00045 using namespace std;
00046
00047 namespace gpstk
00048 {
00049
00050
00051
00052 const string AshtechData::preamble("$PASHR,");
00053
00054
00055 const string AshtechData::trailer("\015\012");
00056
00057
00058
00059
00060
00061 int AshtechData::debugLevel = 0;
00062
00063
00064 bool AshtechData::hexDump = false;
00065
00066
00067
00068 void AshtechData::reallyGetRecord(FFStream& ffs)
00069 throw(exception, FFStreamError, EndOfFile)
00070 {
00071
00072 AshtechStream& stream=dynamic_cast<AshtechStream&>(ffs);
00073
00074
00075 clear(fmtbit | lenbit | crcbit);
00076 id.clear();
00077
00078 readHeader(stream);
00079 }
00080
00081
00082
00083 void AshtechData::readHeader(AshtechStream& stream)
00084 throw(FFStreamError, EndOfFile)
00085 {
00086 string& rawData = stream.rawData;
00087 size_t i;
00088
00089 while (stream)
00090 {
00091 if (rawData.length() < preamble.length()+4)
00092 {
00093 char buff[512];
00094 stream.read(buff, sizeof(buff));
00095 rawData.append(buff, stream.gcount());
00096 }
00097
00098 if (stream.header)
00099 i = rawData.find(preamble, preamble.length());
00100 else
00101 i = rawData.find(preamble);
00102 stream.header = false;
00103
00104 if (i)
00105 {
00106 i = min (rawData.length(), i);
00107 if (debugLevel>2)
00108 cout << "Tossing " << i
00109 << " bytes at offset: 0x" << hex << stream.getRawPos() << dec
00110 << endl;
00111 if (hexDump)
00112 StringUtils::hexDumpData(cout, rawData.substr(0,i));
00113 rawData.erase(0, i);
00114 }
00115 else
00116 {
00117 id = rawData.substr(7,3);
00118 break;
00119 }
00120 }
00121 stream.header = true;
00122 }
00123
00124
00125 void AshtechData::readBody(AshtechStream& stream)
00126 throw(FFStreamError, EndOfFile)
00127 {
00128 string& rawData = stream.rawData;
00129 const static string term = trailer+preamble;
00130 size_t term_pos = rawData.find(term);
00131
00132 while (stream)
00133 {
00134 term_pos = rawData.find(term);
00135 if (term_pos > 0 && term_pos < rawData.length())
00136 break;
00137
00138 if (stream)
00139 {
00140 char cbuff[512];
00141 stream.read(cbuff, sizeof(cbuff));
00142 rawData.append(cbuff, stream.gcount());
00143 }
00144 else
00145 break;
00146 }
00147
00148 term_pos += trailer.length();
00149 if (hexDump)
00150 StringUtils::hexDumpData(cout, rawData.substr(0,term_pos));
00151
00152 decode(rawData.substr(0, term_pos));
00153
00154 if (!good() && debugLevel>1)
00155 cout << "bad decode starting at at offset 0x"
00156 << hex << stream.getRawPos() << dec
00157 << endl;
00158
00159 rawData.erase(0, term_pos);
00160 stream.header=false;
00161 }
00162
00163
00164
00165 void AshtechData::dump(ostream& out) const throw()
00166 {
00167 ostringstream oss;
00168 oss << getName() << " : id:" << id
00169 << " checksum:" << hex << checksum
00170 << " rdstate:" << rdstate() << dec;
00171 if (crcerr())
00172 oss << "-crc";
00173 if (fmterr())
00174 oss << "-fmt";
00175 if (lenerr())
00176 oss << "-len";
00177 if (parerr())
00178 oss << "-par";
00179
00180 out << oss.str() << endl;
00181 }
00182 }