source: ntrip/trunk/BNC/bncrawfile.cpp@ 2530

Last change on this file since 2530 was 2530, checked in by mervart, 14 years ago
File size: 3.8 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 "bncapp.h"
43#include "bncutils.h"
44
45using namespace std;
46
47#define RAW_FILE_VERSION "1"
48
49// Constructor
50////////////////////////////////////////////////////////////////////////////
51bncRawFile::bncRawFile(const QByteArray& fileName, const QByteArray& format,
52 inpOutFlag ioFlg) {
53 _fileName = fileName;
54 _format = format;
55 _staID = fileName.mid(fileName.lastIndexOf(QDir::separator())+1,5);
56 _inpFile = 0;
57 _outFile = 0;
58 _version = 0;
59
60 // Initialize for Input
61 // --------------------
62 if (ioFlg == input) {
63 _inpFile = new QFile(_fileName);
64 _inpFile->open(QIODevice::ReadOnly);
65 QString line = _inpFile->readLine();
66 QStringList lst = line.split(' ');
67 _version = lst.value(0).toInt();
68 }
69
70 // Initialize for Output
71 // ---------------------
72 else {
73 _outFile = new QFile(_fileName);
74 _outFile->open(QIODevice::WriteOnly);
75 _outFile->write(RAW_FILE_VERSION " Version of BNC raw file");
76 }
77}
78
79// Destructor
80////////////////////////////////////////////////////////////////////////////
81bncRawFile::~bncRawFile() {
82 delete _inpFile;
83 delete _outFile;
84}
85
86// Raw Output
87////////////////////////////////////////////////////////////////////////////
88void bncRawFile::writeRawData(const QByteArray& data, const QByteArray& staID,
89 const QByteArray& format) {
90 if (_outFile) {
91 QString chunkHeader = QString("\n%1 %2 %3 %4\n")
92 .arg(currentDateAndTimeGPS().toString(Qt::ISODate))
93 .arg(QString(staID))
94 .arg(QString(format))
95 .arg(data.size());
96 _outFile->write(chunkHeader.toAscii());
97 _outFile->write(data);
98 _outFile->flush();
99 }
100}
101
102
103// Raw Input
104////////////////////////////////////////////////////////////////////////////
105QByteArray bncRawFile::readChunk(){
106
107 QByteArray data;
108
109 if (_inpFile) {
110 QString line = _inpFile->readLine();
111 if (!line.isEmpty()) {
112 QStringList lst = line.split(' ');
113
114 bncApp* app = (bncApp*) qApp;
115 delete app->_currentDateAndTimeGPS;
116 app->_currentDateAndTimeGPS =
117 new QDateTime(QDateTime::fromString(lst.value(0), Qt::ISODate));
118
119 _staID = lst.value(1).toAscii();
120 _format = lst.value(2).toAscii();
121 int nBytes = lst.value(3).toInt();
122
123 data = _inpFile->read(nBytes);
124
125 _inpFile->read(1); // read '\n' character
126 }
127 }
128
129 return data;
130}
131
Note: See TracBrowser for help on using the repository browser.