[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"
|
---|
| 42 | #include "bncapp.h"
|
---|
| 43 | #include "bncutils.h"
|
---|
| 44 |
|
---|
| 45 | using namespace std;
|
---|
| 46 |
|
---|
[2529] | 47 | #define RAW_FILE_VERSION "1"
|
---|
| 48 |
|
---|
[2520] | 49 | // Constructor
|
---|
| 50 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3004] | 51 | bncRawFile::bncRawFile(const QByteArray& fileName, const QByteArray& staID,
|
---|
| 52 | const QByteArray& format, inpOutFlag ioFlg) {
|
---|
| 53 |
|
---|
[2542] | 54 | _fileName = fileName; expandEnvVar(_fileName);
|
---|
[3004] | 55 | _staID = staID;
|
---|
[2520] | 56 | _format = format;
|
---|
[2523] | 57 | _inpFile = 0;
|
---|
[2522] | 58 | _outFile = 0;
|
---|
[2523] | 59 | _version = 0;
|
---|
[2520] | 60 |
|
---|
[2523] | 61 | // Initialize for Input
|
---|
| 62 | // --------------------
|
---|
| 63 | if (ioFlg == input) {
|
---|
| 64 | _inpFile = new QFile(_fileName);
|
---|
| 65 | _inpFile->open(QIODevice::ReadOnly);
|
---|
[2524] | 66 | QString line = _inpFile->readLine();
|
---|
| 67 | QStringList lst = line.split(' ');
|
---|
| 68 | _version = lst.value(0).toInt();
|
---|
[2520] | 69 | }
|
---|
[2523] | 70 |
|
---|
| 71 | // Initialize for Output
|
---|
| 72 | // ---------------------
|
---|
| 73 | else {
|
---|
[2542] | 74 | QDate currDate = currentDateAndTimeGPS().date();
|
---|
| 75 | _currentFileName = _fileName + "_" + currDate.toString("yyMMdd");
|
---|
| 76 | _outFile = new QFile(_currentFileName);
|
---|
[2523] | 77 | _outFile->open(QIODevice::WriteOnly);
|
---|
[2529] | 78 | _outFile->write(RAW_FILE_VERSION " Version of BNC raw file");
|
---|
[2523] | 79 | }
|
---|
[2520] | 80 | }
|
---|
| 81 |
|
---|
| 82 | // Destructor
|
---|
| 83 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 84 | bncRawFile::~bncRawFile() {
|
---|
[2525] | 85 | delete _inpFile;
|
---|
| 86 | delete _outFile;
|
---|
[2520] | 87 | }
|
---|
| 88 |
|
---|
| 89 | // Raw Output
|
---|
| 90 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 91 | void bncRawFile::writeRawData(const QByteArray& data, const QByteArray& staID,
|
---|
| 92 | const QByteArray& format) {
|
---|
| 93 | if (_outFile) {
|
---|
[2542] | 94 | QDate currDate = currentDateAndTimeGPS().date();
|
---|
| 95 | QString hlp = _fileName + "_" + currDate.toString("yyMMdd");
|
---|
| 96 | if (hlp != _currentFileName) {
|
---|
| 97 | _currentFileName = hlp;
|
---|
| 98 | delete _outFile;
|
---|
| 99 | _outFile = new QFile(_currentFileName);
|
---|
| 100 | _outFile->open(QIODevice::WriteOnly);
|
---|
| 101 | _outFile->write(RAW_FILE_VERSION " Version of BNC raw file");
|
---|
| 102 | }
|
---|
| 103 |
|
---|
[2529] | 104 | QString chunkHeader = QString("\n%1 %2 %3 %4\n")
|
---|
| 105 | .arg(currentDateAndTimeGPS().toString(Qt::ISODate))
|
---|
| 106 | .arg(QString(staID))
|
---|
| 107 | .arg(QString(format))
|
---|
| 108 | .arg(data.size());
|
---|
[2520] | 109 | _outFile->write(chunkHeader.toAscii());
|
---|
| 110 | _outFile->write(data);
|
---|
| 111 | _outFile->flush();
|
---|
| 112 | }
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 | // Raw Input
|
---|
| 117 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2527] | 118 | QByteArray bncRawFile::readChunk(){
|
---|
[2520] | 119 |
|
---|
[2524] | 120 | QByteArray data;
|
---|
[2520] | 121 |
|
---|
[2524] | 122 | if (_inpFile) {
|
---|
| 123 | QString line = _inpFile->readLine();
|
---|
[2543] | 124 | if (line.indexOf("Version of BNC raw file") != -1) {
|
---|
| 125 | line = _inpFile->readLine();
|
---|
| 126 | }
|
---|
[2530] | 127 | if (!line.isEmpty()) {
|
---|
| 128 | QStringList lst = line.split(' ');
|
---|
| 129 |
|
---|
| 130 | bncApp* app = (bncApp*) qApp;
|
---|
| 131 | delete app->_currentDateAndTimeGPS;
|
---|
| 132 | app->_currentDateAndTimeGPS =
|
---|
| 133 | new QDateTime(QDateTime::fromString(lst.value(0), Qt::ISODate));
|
---|
| 134 |
|
---|
| 135 | _staID = lst.value(1).toAscii();
|
---|
| 136 | _format = lst.value(2).toAscii();
|
---|
| 137 | int nBytes = lst.value(3).toInt();
|
---|
| 138 |
|
---|
| 139 | data = _inpFile->read(nBytes);
|
---|
| 140 |
|
---|
| 141 | _inpFile->read(1); // read '\n' character
|
---|
| 142 | }
|
---|
[2524] | 143 | }
|
---|
| 144 |
|
---|
| 145 | return data;
|
---|
[2520] | 146 | }
|
---|
| 147 |
|
---|