source: ntrip/trunk/BNC/src/bncrawfile.cpp@ 9154

Last change on this file since 9154 was 8204, checked in by wiese, 7 years ago

CHANGE: #105 toAscii deprecated

File size: 4.5 KB
Line 
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 "bnccore.h"
43#include "bncutils.h"
44#include "bncsettings.h"
45
46using namespace std;
47
48#define RAW_FILE_VERSION "1"
49
50// Constructor
51////////////////////////////////////////////////////////////////////////////
52bncRawFile::bncRawFile(const QByteArray& fileName, const QByteArray& staID,
53 inpOutFlag ioFlg) {
54
55 _fileName = fileName; expandEnvVar(_fileName);
56 _format = "unset";
57 _staID = staID;
58 _inpFile = 0;
59 _outFile = 0;
60 _version = 0;
61
62 // Initialize for Input
63 // --------------------
64 if (ioFlg == input) {
65 _inpFile = new QFile(_fileName);
66 _inpFile->open(QIODevice::ReadOnly);
67 QString line = _inpFile->readLine();
68 QStringList lst = line.split(' ');
69 _version = lst.value(0).toInt();
70 }
71
72 // Initialize for Output
73 // ---------------------
74 else {
75 QDate currDate = currentDateAndTimeGPS().date();
76 _currentFileName = _fileName + "_" + currDate.toString("yyMMdd");
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 }
87 }
88}
89
90// Destructor
91////////////////////////////////////////////////////////////////////////////
92bncRawFile::~bncRawFile() {
93 delete _inpFile;
94 delete _outFile;
95}
96
97// Raw Output
98////////////////////////////////////////////////////////////////////////////
99void bncRawFile::writeRawData(const QByteArray& data, const QByteArray& staID,
100 const QByteArray& format) {
101 if (_outFile) {
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
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());
117 _outFile->write(chunkHeader.toLatin1());
118 _outFile->write(data);
119 _outFile->flush();
120 }
121}
122
123
124// Raw Input
125////////////////////////////////////////////////////////////////////////////
126QByteArray bncRawFile::readChunk(){
127
128 QByteArray data;
129
130 if (_inpFile) {
131 QString line = _inpFile->readLine();
132 if (line.indexOf("Version of BNC raw file") != -1) {
133 line = _inpFile->readLine();
134 }
135 if (!line.isEmpty()) {
136 QStringList lst = line.split(' ');
137
138 BNC_CORE->setDateAndTimeGPS(QDateTime(QDateTime::fromString(lst.value(0), Qt::ISODate)));
139
140 _staID = lst.value(1).toLatin1();
141 _format = lst.value(2).toLatin1();
142 int nBytes = lst.value(3).toInt();
143
144 data = _inpFile->read(nBytes);
145
146 _inpFile->read(1); // read '\n' character
147 }
148 }
149
150 return data;
151}
152
Note: See TracBrowser for help on using the repository browser.