CommonTime FileSpec::extractCommonTime(const string& filename) const throw(FileSpecException) { // this uses CommonTime::setToString to get the time out try { CommonTime dt(0.L); mixedScanTime(dt, filename, fileSpecString); return dt; } catch(Exception& exc) { // too ambiguous - throw an exception FileSpecException fse(exc); fse.addText("Can't generate a CommonTime for this FileSpec"); GPSTK_THROW(fse); } catch(std::exception& exc) { FileSpecException fse("std::exception: " + string(exc.what())); fse.addText("Can't generate a CommonTime for this FileSpec"); GPSTK_THROW(fse); } catch(...) { FileSpecException fse("unknown exception"); fse.addText("Can't generate a CommonTime for this FileSpec"); GPSTK_THROW(fse); } }
string FileSpec::extractField(const string& filename, const FileSpecType fst) const throw(FileSpecException) { // stupidity check - is it a valid FST? if ((fst <= unknown) || (fst >= end)) { FileSpecException fse("Unknown FileSpecType: " + convertFileSpecType(fst)); GPSTK_THROW(fse); } // check the FileSpec for this type of FST vector<FileSpecElement>::const_iterator itr = fileSpecList.begin(); while (itr != fileSpecList.end()) { // found it - get the substring and return if ((*itr).type == fst) { return filename.substr((*itr).offset, (*itr).numCh); } // didn't find it on this iteration itr++; } // oops - didn't find it. FileSpecException fse("Couldn't find specified FileSpecType: " + convertFileSpecType(fst)); GPSTK_THROW(fse); }
// Outputs the record to the FFStream \a s. void Rinex3NavData::reallyPutRecord(FFStream& ffs) const throw(exception, FFStreamError, StringException) { try { Rinex3NavStream& strm = dynamic_cast<Rinex3NavStream&>(ffs); putPRNEpoch(strm); // put 3 data records for(int i=1; i<=3; i++) putRecord(i, strm); // SBAS and GLO only have 3 records if(satSys == "S" || satSys == "R") return; // GPS QZS BDS and GAL have 7 records, put 4-7 if(satSys == "G" || satSys == "C" || satSys == "E" || satSys == "J") for(int i=4; i<=7; i++) putRecord(i, strm); } catch(exception& e) { FFStreamError fse(string("std::exception: ") + e.what()); GPSTK_THROW(fse); } catch(FFStreamError& fse) { GPSTK_RETHROW(fse); } catch(StringException& se) { GPSTK_RETHROW(se); } } // End of method 'Rinex3NavData::reallyPutRecord(FFStream& ffs)'
string FileSpec::createSearchString() const throw(FileSpecException) { string searchString; // go through the file spec element list... vector<FileSpecElement>::const_iterator itr = fileSpecList.begin(); while (itr != fileSpecList.end()) { // the error case first... if ( ((*itr).type <= unknown) || ((*itr).type >= end) ) { FileSpecException fse("Unknown FileSpecType: " + asString((*itr).type)); GPSTK_THROW(fse); } // just add the fixed fields else if ((*itr).type == fixed) { searchString += (*itr).field; } // replace all the others with question marks for searching else { searchString += string((*itr).numCh, '?'); } itr++; } return searchString; }
/* This function retrieves a RINEX 3 NAV record from the given * FFStream. * If an error is encountered in reading from the stream, the stream * is returned to its original position and its fail-bit is set. * @throws StringException when a StringUtils function fails. * @throws FFStreamError when exceptions(failbit) is set and a read * or formatting error occurs. This also resets the stream * to its pre-read position. */ void Rinex3NavData::reallyGetRecord(FFStream& ffs) throw(exception, FFStreamError, StringException) { try { Rinex3NavStream& strm = dynamic_cast<Rinex3NavStream&>(ffs); // If the header hasn't been read, read it... if(!strm.headerRead) { try { strm >> strm.header; } catch(exception& e) { FFStreamError fse(string("std::exception reading header ") + e.what()); GPSTK_THROW(fse); } catch(FFStreamError& fse) { GPSTK_RETHROW(fse); } } // get the first line, the epoch line getPRNEpoch(strm); // get 3 data records for(int i=1; i<=3; i++) getRecord(i, strm); // SBAS and GLO only have 3 records if(satSys == "S" || satSys == "R") return; // GPS GAL QZSS BDS have 7 records, get 4-7 if(satSys == "G" || satSys == "E" || satSys == "J" || satSys == "C") for(int i=4; i<=7; i++) getRecord(i, strm); } catch(exception& e) { FFStreamError fse(string("std::exception: ") + e.what()); GPSTK_THROW(fse); } catch(FFStreamError& fse) { GPSTK_RETHROW(fse); } catch(StringException& se) { GPSTK_RETHROW(se); } } // End of method 'Rinex3NavData::reallyGetRecord(FFStream& ffs)'
bool FileSpec::hasField(const FileSpecType fst) const throw(FileSpecException) { vector<FileSpecElement>::const_iterator itr = fileSpecList.begin(); while (itr != fileSpecList.end()) { // stupidity check - is it a valid FST? if (((*itr).type <= unknown) || ((*itr).type >= end)) { FileSpecException fse("Unknown FileSpecType: " + convertFileSpecType((*itr).type)); GPSTK_THROW(fse); } if ((*itr).type == fst) return true; itr++; } return false; }
FileSpec::FileSpecType FileSpec::convertFileSpecType(const string& fst) throw(FileSpecException) { if (fst == string("n")) return station; else if (fst == string("r")) return receiver; else if (fst == string("p")) return prn; else if (fst == string("t")) return selected; else if (fst == string("I")) return sequence; else if (fst == string("v")) return version; else if (fst == string("k")) return clock; else if (fst == string("x")) return text; else if (fst == string("Y") || fst == string("y")) return year; else if (fst == string("m")) return month; else if (fst == string("d")) return dayofmonth; else if (fst == string("H")) return hour; else if (fst == string("M")) return minute; else if (fst == string("S")) return second; else if (fst == string("f")) return fsecond; else if (fst == string("G")) return gpsweek; else if (fst == string("F")) return fullgpsweek; else if (fst == string("g")) return gpssecond; else if (fst == string("Q")) return mjd; else if (fst == string("w")) return dayofweek; else if (fst == string("j")) return day; else if (fst == string("s")) return doysecond; else if (fst == string("Z")) return zcount; else if (fst == string("z")) return zcountfloor; else if (fst == string("U")) return unixsec; else if (fst == string("u")) return unixusec; else if (fst == string("C") || fst == string("c")) return fullzcount; else { FileSpecException fse("Unknown FileSpecType: " + fst); GPSTK_THROW(fse); } }
string FileSpec::convertFileSpecType(const FileSpecType fst) throw(FileSpecException) { if (fst == station) return string("n"); else if (fst == receiver) return string("r"); else if (fst == prn) return string("p"); else if (fst == selected) return string("t"); else if (fst == sequence) return string("I"); else if (fst == version) return string("v"); else if (fst == fixed) return string(""); else if (fst == clock) return string("k"); else if (fst == text) return string("x"); else if (fst == year) return string("y"); else if (fst == month) return string("m"); else if (fst == dayofmonth) return string("d"); else if (fst == hour) return string("H"); else if (fst == minute) return string("M"); else if (fst == second) return string("S"); else if (fst == fsecond) return string("f"); else if (fst == gpsweek) return string("G"); else if (fst == fullgpsweek) return string("F"); else if (fst == gpssecond) return string("g"); else if (fst == mjd) return string("Q"); else if (fst == dayofweek) return string("w"); else if (fst == day) return string("j"); else if (fst == doysecond) return string("s"); else if (fst == zcount) return string("Z"); else if (fst == zcountfloor) return string("z"); else if (fst == unixsec) return string("U"); else if (fst == unixusec) return string("u"); else if (fst == fullzcount) return string("C"); else { FileSpecException fse("Unknown FileSpecType: " + asString(fst)); GPSTK_THROW(fse); } }
int HostProcess(pid_t listenerID, FILE* fout, FILE* fin) { HostStuff hoststuff; hoststuff.listenerID=listenerID; hoststuff.fout=fout; hoststuff.fin=fin; hoststuff.cfbInfo.m_fin=fin; pthread_t CommandFeedBackThread; int threadError = pthread_create(&CommandFeedBackThread,NULL,HostProcess_CommandFeedBackThread,&hoststuff.cfbInfo); pthread_mutex_init(&hoststuff.cmd_lock,NULL); sem_init(&hoststuff.cfbInfo.m_CDStatusSocket.m_finish_sem,0,1); sem_init(&hoststuff.cfbInfo.m_CDStatusSocket.m_start_sem,0,0); sem_init(&hoststuff.cfbInfo.m_CDListSocket.m_finish_sem,0,0); sem_init(&hoststuff.cfbInfo.m_CDListSocket.m_start_sem,0,0); sem_init(&hoststuff.cfbInfo.m_ListStatusSocket.m_finish_sem,0,1); sem_init(&hoststuff.cfbInfo.m_ListStatusSocket.m_start_sem,0,0); sem_init(&hoststuff.cfbInfo.m_ListListsSocket.m_finish_sem,0,0); sem_init(&hoststuff.cfbInfo.m_ListListsSocket.m_start_sem,0,0); sem_init(&hoststuff.cfbInfo.m_ListSongsSocket.m_finish_sem,0,0); sem_init(&hoststuff.cfbInfo.m_ListSongsSocket.m_start_sem,0,0); pthread_t WebSocketListenerThread; threadError = pthread_create(&WebSocketListenerThread,NULL,HostProcess_WebSocketListener,&hoststuff); FeiSocketSever server(SOCKET_PORT); if (server.IsValid()) { while (1) { FeiSocketSession se=server.GetSession(); if (se.IsValid()) { char buffer[4096]; char command[256]; int len; len=se.Recieve(buffer,4096); if (len<=0) { se.Close(); break; } buffer[len]=0; FeiSocketFeedBackSession fse(se); IncomingSession(&hoststuff, buffer, &fse); } } } void * ret; pthread_join(WebSocketListenerThread,&ret); pthread_mutex_destroy(&hoststuff.cmd_lock); sem_destroy(&hoststuff.cfbInfo.m_CDStatusSocket.m_finish_sem); sem_destroy(&hoststuff.cfbInfo.m_CDStatusSocket.m_start_sem); sem_destroy(&hoststuff.cfbInfo.m_CDListSocket.m_finish_sem); sem_destroy(&hoststuff.cfbInfo.m_CDListSocket.m_start_sem); sem_destroy(&hoststuff.cfbInfo.m_ListStatusSocket.m_finish_sem); sem_destroy(&hoststuff.cfbInfo.m_ListStatusSocket.m_start_sem); sem_destroy(&hoststuff.cfbInfo.m_ListListsSocket.m_finish_sem); sem_destroy(&hoststuff.cfbInfo.m_ListListsSocket.m_start_sem); sem_destroy(&hoststuff.cfbInfo.m_ListSongsSocket.m_finish_sem); sem_destroy(&hoststuff.cfbInfo.m_ListSongsSocket.m_start_sem); return 0; }
// Construct and write the nth record after the epoch record // @param int n Record number (1-7), for nth record // after the epoch line. // @param Rinex3NavStream strm Stream to read from. void Rinex3NavData::putRecord(const int& nline, Rinex3NavStream& strm) const throw(StringException, FFStreamError) { if(nline < 1 || nline > 7) { FFStreamError fse(string("Invalid line number ") + asString(nline)); GPSTK_THROW(fse); } try { string line; if(strm.header.version < 3) line += string(3, ' '); else line += string(4, ' '); if(nline == 1) { if(satSys == "R" || satSys == "S") { // GLO and GEO line += doubleToScientific(px,19,12,2); line += doubleToScientific(vx,19,12,2); line += doubleToScientific(ax,19,12,2); line += doubleToScientific((double)health,19,12,2); } else if(satSys == "G" || satSys == "C" || satSys == "J") {// GPS,BDS,QZS line += doubleToScientific(IODE,19,12,2); line += doubleToScientific(Crs,19,12,2); line += doubleToScientific(dn,19,12,2); line += doubleToScientific(M0,19,12,2); } else if(satSys == "E") { // GAL line += doubleToScientific(IODnav,19,12,2); line += doubleToScientific(Crs,19,12,2); line += doubleToScientific(dn,19,12,2); line += doubleToScientific(M0,19,12,2); } } else if(nline == 2) { if(satSys == "R" || satSys == "S") { // GLO and GEO line += doubleToScientific(py,19,12,2); line += doubleToScientific(vy,19,12,2); line += doubleToScientific(ay,19,12,2); if(satSys == "R") line += doubleToScientific((double)freqNum,19,12,2); else line += doubleToScientific(accCode,19,12,2); } else { // GPS,GAL,BDS,QZS line += doubleToScientific(Cuc,19,12,2); line += doubleToScientific(ecc,19,12,2); line += doubleToScientific(Cus,19,12,2); line += doubleToScientific(Ahalf,19,12,2); } } else if(nline == 3) { if(satSys == "R" || satSys == "S") { // GLO GEO line += doubleToScientific(pz,19,12,2); line += doubleToScientific(vz,19,12,2); line += doubleToScientific(az,19,12,2); if(satSys == "R") line += doubleToScientific(ageOfInfo,19,12,2); else // GEO line += doubleToScientific(IODN,19,12,2); } else { // GPS,GAL,BDS,QZS line += doubleToScientific(Toe,19,12,2); line += doubleToScientific(Cic,19,12,2); line += doubleToScientific(OMEGA0,19,12,2); line += doubleToScientific(Cis,19,12,2); } } // SBAS and GLO end here else if(nline == 4) { // GPS,GAL,BDS,QZS line += doubleToScientific(i0,19,12,2); line += doubleToScientific(Crc,19,12,2); line += doubleToScientific(w,19,12,2); line += doubleToScientific(OMEGAdot,19,12,2); } else if(nline == 5) { // Internally (Rinex3NavData), weeknum=week of HOW // In RINEX 3 *files*, weeknum is the week of TOE. double wk = double(weeknum); if(HOWtime - Toe > HALFWEEK) wk++; else if(HOWtime - Toe < -(HALFWEEK)) wk--; if(satSys == "G" || satSys == "J") { // GPS QZS line += doubleToScientific(idot,19,12,2); line += doubleToScientific((double)codeflgs,19,12,2); line += doubleToScientific(wk,19,12,2); line += doubleToScientific((double)L2Pdata,19,12,2); } else if(satSys == "E") { // GAL line += doubleToScientific(idot,19,12,2); line += doubleToScientific((double)datasources,19,12,2); line += doubleToScientific(wk,19,12,2); line += doubleToScientific((double) 0,19,12,2); } else if(satSys == "C") { // BDS line += doubleToScientific(idot,19,12,2); line += doubleToScientific((double) 0,19,12,2); line += doubleToScientific(wk,19,12,2); line += doubleToScientific((double) 0,19,12,2); } } else if(nline == 6) { line += doubleToScientific(accuracy,19,12,2); line += doubleToScientific((double)health,19,12,2); if(satSys == "G" || satSys == "J") { // GPS, QZS line += doubleToScientific(Tgd,19,12,2); line += doubleToScientific(IODC,19,12,2); } else if(satSys == "E" || satSys == "C") { // GAL, BDS line += doubleToScientific(Tgd,19,12,2); line += doubleToScientific(Tgd2,19,12,2); } } else if(nline == 7) { line += doubleToScientific(HOWtime,19,12,2); if(satSys == "G" || satSys == "J") { line += doubleToScientific(fitint,19,12,2); } else if(satSys == "E") { ; } else if(satSys == "C") { line += doubleToScientific(IODC,19,12,2); } } strm << stripTrailing(line) << endl; strm.lineNumber++; } catch (std::exception &e) { FFStreamError err("std::exception: " + string(e.what())); GPSTK_THROW(err); } } // End of method 'Rinex3NavData::putRecord(const int& nline,...'
void Rinex3NavData::getRecord(const int& nline, Rinex3NavStream& strm) throw(StringException, FFStreamError) { if(nline < 1 || nline > 7) { FFStreamError fse(string("Invalid line number ") + asString(nline)); GPSTK_THROW(fse); } try { int n(strm.header.version < 3 ? 3 : 4); string line; strm.formattedGetLine(line); if(nline == 1) { if(satSys == "G" || satSys == "J" || satSys == "C") { IODE = StringUtils::for2doub(line.substr(n,19)); n+=19; Crs = StringUtils::for2doub(line.substr(n,19)); n+=19; dn = StringUtils::for2doub(line.substr(n,19)); n+=19; M0 = StringUtils::for2doub(line.substr(n,19)); } else if(satSys == "E") { IODnav = StringUtils::for2doub(line.substr(n,19)); n+=19; Crs = StringUtils::for2doub(line.substr(n,19)); n+=19; dn = StringUtils::for2doub(line.substr(n,19)); n+=19; M0 = StringUtils::for2doub(line.substr(n,19)); } else if(satSys == "R" || satSys == "S") { px = StringUtils::for2doub(line.substr(n,19)); n+=19; vx = StringUtils::for2doub(line.substr(n,19)); n+=19; ax = StringUtils::for2doub(line.substr(n,19)); n+=19; health = (short)StringUtils::for2doub(line.substr(n,19)); } } else if(nline == 2) { if(satSys == "G" || satSys == "E" || satSys == "J" || satSys == "C") { Cuc = StringUtils::for2doub(line.substr(n,19)); n+=19; ecc = StringUtils::for2doub(line.substr(n,19)); n+=19; Cus = StringUtils::for2doub(line.substr(n,19)); n+=19; Ahalf = StringUtils::for2doub(line.substr(n,19)); } else if(satSys == "R" || satSys == "S") { py = StringUtils::for2doub(line.substr(n,19)); n+=19; vy = StringUtils::for2doub(line.substr(n,19)); n+=19; ay = StringUtils::for2doub(line.substr(n,19)); n+=19; if(satSys == "R") freqNum = (short)StringUtils::for2doub(line.substr(n,19)); else // GEO accCode = StringUtils::for2doub(line.substr(n,19)); } } else if(nline == 3) { if(satSys == "G" || satSys == "E" || satSys == "J" || satSys == "C") { Toe = StringUtils::for2doub(line.substr(n,19)); n+=19; Cic = StringUtils::for2doub(line.substr(n,19)); n+=19; OMEGA0 = StringUtils::for2doub(line.substr(n,19)); n+=19; Cis = StringUtils::for2doub(line.substr(n,19)); } else if(satSys == "R" || satSys == "S") { pz = StringUtils::for2doub(line.substr(n,19)); n+=19; vz = StringUtils::for2doub(line.substr(n,19)); n+=19; az = StringUtils::for2doub(line.substr(n,19)); n+=19; if(satSys == "R") ageOfInfo = StringUtils::for2doub(line.substr(n,19)); else // GEO IODN = StringUtils::for2doub(line.substr(n,19)); } } else if(nline == 4) { i0 = StringUtils::for2doub(line.substr(n,19)); n+=19; Crc = StringUtils::for2doub(line.substr(n,19)); n+=19; w = StringUtils::for2doub(line.substr(n,19)); n+=19; OMEGAdot = StringUtils::for2doub(line.substr(n,19)); } else if(nline == 5) { if(satSys == "G" || satSys == "J" || satSys == "C") { idot = StringUtils::for2doub(line.substr(n,19)); n+=19; codeflgs = (short)StringUtils::for2doub(line.substr(n,19)); n+=19; weeknum = (short)StringUtils::for2doub(line.substr(n,19)); n+=19; L2Pdata = (short)StringUtils::for2doub(line.substr(n,19)); } else if(satSys == "E") { idot = StringUtils::for2doub(line.substr(n,19)); n+=19; datasources =(short)StringUtils::for2doub(line.substr(n,19)); n+=19; weeknum =(short)StringUtils::for2doub(line.substr(n,19)); n+=19; } } else if(nline == 6) { Tgd2 = 0.0; if(satSys == "G" || satSys == "J") { accuracy = StringUtils::for2doub(line.substr(n,19)); n+=19; health = short(StringUtils::for2doub(line.substr(n,19))); n+=19; Tgd = StringUtils::for2doub(line.substr(n,19)); n+=19; IODC = StringUtils::for2doub(line.substr(n,19)); } else if(satSys == "E") { accuracy = StringUtils::for2doub(line.substr(n,19)); n+=19; health = short(StringUtils::for2doub(line.substr(n,19))); n+=19; Tgd = StringUtils::for2doub(line.substr(n,19)); n+=19; Tgd2 = StringUtils::for2doub(line.substr(n,19)); } else if(satSys == "C") { accuracy = StringUtils::for2doub(line.substr(n,19)); n+=19; health = short(StringUtils::for2doub(line.substr(n,19))); n+=19; Tgd = StringUtils::for2doub(line.substr(n,19)); n+=19; Tgd2 = StringUtils::for2doub(line.substr(n,19)); } } else if(nline == 7) { HOWtime = long(StringUtils::for2doub(line.substr(n,19))); n+=19; if(satSys == "C") { IODC = StringUtils::for2doub(line.substr(n,19)); n+=19; } else { fitint = StringUtils::for2doub(line.substr(n,19)); n+=19; } // Some RINEX files have HOW < 0. while(HOWtime < 0) { HOWtime += (long)FULLWEEK; weeknum--; } // In RINEX *files*, weeknum is the week of TOE. // Internally (Rinex3NavData), weeknum is week of HOW if(HOWtime - Toe > HALFWEEK) weeknum--; else if(HOWtime - Toe < -HALFWEEK) weeknum++; } } catch (std::exception &e) { FFStreamError err("std::exception: " + string(e.what())); GPSTK_THROW(err); } } // end getRecord()
void FileSpec::init(const string& fileSpec) throw(FileSpecException) { try { fileSpecList.clear(); fileSpecString.clear(); fileSpecString = fileSpec; // holds the offset for where we would be in the real file // name string::size_type offset = 0; // copy the string so we can mess with it string fs(fileSpec); // bit by bit, parse out the string into FileSpecElements, // stripping out the used parts as we go while (!fs.empty()) { string atom; // if fs[0] == '%', then stop to parse. also stop at // the end of the string string::size_type pos = fs.find('%'); atom = fs.substr(0,pos); fs.erase(0,pos); // if it's at the end of the string... // make a FileSpecElement of any remaining // characters and return (fall through the while loop) if (fs.empty()) { if (!atom.empty()) { FileSpecElement fse(atom.size(), offset, fixed, atom); fileSpecList.push_back(fse); } } // found a '%' so parse out this little bit of a file spec, // but make sure to add atom to the FileSpec (if there is any) else { if (!atom.empty()) { FileSpecElement fse(atom.size(), offset, fixed, atom); fileSpecList.push_back(fse); offset += atom.size(); atom.erase(atom.begin(), atom.end()); } // erase the '%' // also make sure that atom holds the string that // makes up this element. atom += fs[0]; fs.erase(0,1); // get any integers that come before the letter we're lookin // for, then erase them int numChs = asInt(fs); if (numChs == 0) numChs = 1; if (fs[0] == '0') atom += '0'; stripLeading(fs, "0"); stripLeading(fs, asString(numChs)); atom += asString(numChs); // get the file spec type and erase that part of the string FileSpecType fst = convertFileSpecType(fs.substr(0,1)); atom += fs[0]; // super special case - %Y -> %4y FIX shouldn't this be <4? if ((fs.substr(0,1) == string("Y")) && (numChs != 4)) numChs = 4; fs.erase(0,1); FileSpecElement fse(numChs, offset, fst, atom); fileSpecList.push_back(fse); offset += numChs; } } // while !fs.empty() } catch(FileSpecException& e) { e.addText("Check your file spec for errors: " + fileSpec); GPSTK_RETHROW(e); } catch(StringException& e) { FileSpecException fse(e); fse.addText("String exception: Check the file spec for errors: " + fileSpec); GPSTK_THROW(fse); } catch(std::exception& e) { FileSpecException fse("std::exception: " + string(e.what())); fse.addText("Check the file spec for errors: " + fileSpec); GPSTK_THROW(fse); } catch(...) { FileSpecException fse("Unknown exception: Check the file spec for errors: " + fileSpec); GPSTK_THROW(fse); } }