[2520] | 1 | // Part of BNC, a utility for retrieving decoding and
|
---|
| 2 | // converting GNSS data streams from NTRIP broadcasters.
|
---|
| 3 | //
|
---|
| 4 | // Copyright (C) 2007
|
---|
| 5 | // German Federal Agency for Cartography and Geodesy (BKG)
|
---|
| 6 | // http://www.bkg.bund.de
|
---|
| 7 | // Czech Technical University Prague, Department of Geodesy
|
---|
| 8 | // http://www.fsv.cvut.cz
|
---|
| 9 | //
|
---|
| 10 | // Email: euref-ip@bkg.bund.de
|
---|
| 11 | //
|
---|
| 12 | // This program is free software; you can redistribute it and/or
|
---|
| 13 | // modify it under the terms of the GNU General Public License
|
---|
| 14 | // as published by the Free Software Foundation, version 2.
|
---|
| 15 | //
|
---|
| 16 | // This program is distributed in the hope that it will be useful,
|
---|
| 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | // GNU General Public License for more details.
|
---|
| 20 | //
|
---|
| 21 | // You should have received a copy of the GNU General Public License
|
---|
| 22 | // along with this program; if not, write to the Free Software
|
---|
| 23 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
| 24 |
|
---|
| 25 | /* -------------------------------------------------------------------------
|
---|
| 26 | * BKG NTRIP Client
|
---|
| 27 | * -------------------------------------------------------------------------
|
---|
| 28 | *
|
---|
| 29 | * Class: bncRawFile
|
---|
| 30 | *
|
---|
| 31 | * Purpose: This class stores/reads BNC raw file
|
---|
| 32 | *
|
---|
| 33 | * Author: L. Mervart
|
---|
| 34 | *
|
---|
| 35 | * Created: 23-Aug-2010
|
---|
| 36 | *
|
---|
| 37 | * Changes:
|
---|
| 38 | *
|
---|
| 39 | * -----------------------------------------------------------------------*/
|
---|
| 40 |
|
---|
| 41 | #include "bncrawfile.h"
|
---|
[5070] | 42 | #include "bnccore.h"
|
---|
[2520] | 43 | #include "bncutils.h"
|
---|
[3327] | 44 | #include "bncsettings.h"
|
---|
[2520] | 45 |
|
---|
| 46 | using namespace std;
|
---|
| 47 |
|
---|
[2529] | 48 | #define RAW_FILE_VERSION "1"
|
---|
| 49 |
|
---|
[2520] | 50 | // Constructor
|
---|
| 51 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3004] | 52 | bncRawFile::bncRawFile(const QByteArray& fileName, const QByteArray& staID,
|
---|
[3524] | 53 | inpOutFlag ioFlg) {
|
---|
[3004] | 54 |
|
---|
[2542] | 55 | _fileName = fileName; expandEnvVar(_fileName);
|
---|
[3524] | 56 | _format = "unset";
|
---|
[3548] | 57 | _staID = staID;
|
---|
[2523] | 58 | _inpFile = 0;
|
---|
[2522] | 59 | _outFile = 0;
|
---|
[2523] | 60 | _version = 0;
|
---|
[2520] | 61 |
|
---|
[2523] | 62 | // Initialize for Input
|
---|
| 63 | // --------------------
|
---|
| 64 | if (ioFlg == input) {
|
---|
| 65 | _inpFile = new QFile(_fileName);
|
---|
| 66 | _inpFile->open(QIODevice::ReadOnly);
|
---|
[2524] | 67 | QString line = _inpFile->readLine();
|
---|
| 68 | QStringList lst = line.split(' ');
|
---|
| 69 | _version = lst.value(0).toInt();
|
---|
[2520] | 70 | }
|
---|
[2523] | 71 |
|
---|
| 72 | // Initialize for Output
|
---|
| 73 | // ---------------------
|
---|
[3327] | 74 | else {
|
---|
[2542] | 75 | QDate currDate = currentDateAndTimeGPS().date();
|
---|
| 76 | _currentFileName = _fileName + "_" + currDate.toString("yyMMdd");
|
---|
[3327] | 77 | _outFile = new QFile(_currentFileName);
|
---|
| 78 | bncSettings settings;
|
---|
| 79 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
|
---|
| 80 | QFile::exists(_currentFileName) ) {
|
---|
| 81 | _outFile->open(QIODevice::WriteOnly | QIODevice::Append);
|
---|
| 82 | }
|
---|
| 83 | else {
|
---|
| 84 | _outFile->open(QIODevice::WriteOnly);
|
---|
| 85 | _outFile->write(RAW_FILE_VERSION " Version of BNC raw file");
|
---|
| 86 | }
|
---|
[2523] | 87 | }
|
---|
[2520] | 88 | }
|
---|
| 89 |
|
---|
| 90 | // Destructor
|
---|
| 91 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 92 | bncRawFile::~bncRawFile() {
|
---|
[2525] | 93 | delete _inpFile;
|
---|
| 94 | delete _outFile;
|
---|
[2520] | 95 | }
|
---|
| 96 |
|
---|
| 97 | // Raw Output
|
---|
| 98 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 99 | void bncRawFile::writeRawData(const QByteArray& data, const QByteArray& staID,
|
---|
| 100 | const QByteArray& format) {
|
---|
| 101 | if (_outFile) {
|
---|
[2542] | 102 | QDate currDate = currentDateAndTimeGPS().date();
|
---|
| 103 | QString hlp = _fileName + "_" + currDate.toString("yyMMdd");
|
---|
| 104 | if (hlp != _currentFileName) {
|
---|
| 105 | _currentFileName = hlp;
|
---|
| 106 | delete _outFile;
|
---|
| 107 | _outFile = new QFile(_currentFileName);
|
---|
| 108 | _outFile->open(QIODevice::WriteOnly);
|
---|
| 109 | _outFile->write(RAW_FILE_VERSION " Version of BNC raw file");
|
---|
| 110 | }
|
---|
| 111 |
|
---|
[2529] | 112 | QString chunkHeader = QString("\n%1 %2 %3 %4\n")
|
---|
| 113 | .arg(currentDateAndTimeGPS().toString(Qt::ISODate))
|
---|
| 114 | .arg(QString(staID))
|
---|
| 115 | .arg(QString(format))
|
---|
| 116 | .arg(data.size());
|
---|
[2520] | 117 | _outFile->write(chunkHeader.toAscii());
|
---|
| 118 | _outFile->write(data);
|
---|
| 119 | _outFile->flush();
|
---|
| 120 | }
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 |
|
---|
| 124 | // Raw Input
|
---|
| 125 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2527] | 126 | QByteArray bncRawFile::readChunk(){
|
---|
[2520] | 127 |
|
---|
[2524] | 128 | QByteArray data;
|
---|
[2520] | 129 |
|
---|
[2524] | 130 | if (_inpFile) {
|
---|
| 131 | QString line = _inpFile->readLine();
|
---|
[2543] | 132 | if (line.indexOf("Version of BNC raw file") != -1) {
|
---|
| 133 | line = _inpFile->readLine();
|
---|
| 134 | }
|
---|
[2530] | 135 | if (!line.isEmpty()) {
|
---|
| 136 | QStringList lst = line.split(' ');
|
---|
| 137 |
|
---|
[5068] | 138 | delete BNC_CORE->_currentDateAndTimeGPS;
|
---|
| 139 | BNC_CORE->_currentDateAndTimeGPS =
|
---|
[2530] | 140 | new QDateTime(QDateTime::fromString(lst.value(0), Qt::ISODate));
|
---|
| 141 |
|
---|
| 142 | _staID = lst.value(1).toAscii();
|
---|
| 143 | _format = lst.value(2).toAscii();
|
---|
| 144 | int nBytes = lst.value(3).toInt();
|
---|
| 145 |
|
---|
| 146 | data = _inpFile->read(nBytes);
|
---|
| 147 |
|
---|
| 148 | _inpFile->read(1); // read '\n' character
|
---|
| 149 | }
|
---|
[2524] | 150 | }
|
---|
| 151 |
|
---|
| 152 | return data;
|
---|
[2520] | 153 | }
|
---|
| 154 |
|
---|