source: ntrip/trunk/BNS/bns.cpp@ 773

Last change on this file since 773 was 770, checked in by mervart, 17 years ago

* empty log message *

File size: 3.5 KB
Line 
1/* -------------------------------------------------------------------------
2 * BKG NTRIP Server
3 * -------------------------------------------------------------------------
4 *
5 * Class: bns
6 *
7 * Purpose: This class implements the main application behaviour
8 *
9 * Author: L. Mervart
10 *
11 * Created: 29-Mar-2008
12 *
13 * Changes:
14 *
15 * -----------------------------------------------------------------------*/
16
17#include <iostream>
18
19#include "bns.h"
20
21using namespace std;
22
23// Constructor
24////////////////////////////////////////////////////////////////////////////
25t_bns::t_bns(QObject* parent) : QThread(parent) {
26
27 this->setTerminationEnabled(true);
28
29 _bnseph = new t_bnseph(parent);
30
31 connect(_bnseph, SIGNAL(newMessage(QByteArray)),
32 this, SLOT(slotMessage(const QByteArray)));
33
34 connect(_bnseph, SIGNAL(error(QByteArray)),
35 this, SLOT(slotError(const QByteArray)));
36
37 _clkServer = 0;
38 _clkSocket = 0;
39
40 _outSocket = 0;
41}
42
43// Destructor
44////////////////////////////////////////////////////////////////////////////
45t_bns::~t_bns() {
46 deleteBnsEph();
47 delete _clkServer;
48 delete _outSocket;
49}
50
51// Delete bns thread
52////////////////////////////////////////////////////////////////////////////
53void t_bns::deleteBnsEph() {
54 if (_bnseph) {
55 _bnseph->terminate();
56 _bnseph->wait(100);
57 delete _bnseph;
58 _bnseph = 0;
59 }
60}
61
62// Write a Program Message
63////////////////////////////////////////////////////////////////////////////
64void t_bns::slotMessage(const QByteArray msg) {
65 cout << msg.data() << endl;
66 emit(newMessage(msg));
67}
68
69// Write a Program Message
70////////////////////////////////////////////////////////////////////////////
71void t_bns::slotError(const QByteArray msg) {
72 cerr << msg.data() << endl;
73 deleteBnsEph();
74 emit(error(msg));
75}
76
77// New Connection
78////////////////////////////////////////////////////////////////////////////
79void t_bns::slotNewConnection() {
80 _clkSocket = _clkServer->nextPendingConnection();
81}
82
83// Start the Communication with NTRIP Caster
84////////////////////////////////////////////////////////////////////////////
85void t_bns::openCaster() {
86
87 QSettings settings;
88 QString host = settings.value("outHost").toString();
89 int port = settings.value("outPort").toInt();
90
91 _outSocket = new QTcpSocket();
92 _outSocket->connectToHost(host, port);
93
94 QString mountpoint = settings.value("mountpoint").toString();
95 QString password = settings.value("password").toString();
96
97 QByteArray msg = "SOURCE " + password.toAscii() + " /" +
98 mountpoint.toAscii() + "\r\n" +
99 "Source-Agent: NTRIP BNS/1.0\r\n\r\n";
100
101 _outSocket->write(msg);
102
103 QByteArray ans = _outSocket->readLine();
104
105 if (ans.indexOf("OK") == -1) {
106 delete _outSocket;
107 _outSocket = 0;
108 }
109}
110
111// Start
112////////////////////////////////////////////////////////////////////////////
113void t_bns::run() {
114
115 slotMessage("============ Start BNS ============");
116
117 // Start Thread that retrieves broadcast Ephemeris
118 // -----------------------------------------------
119 _bnseph->start();
120
121 // Open the connection to NTRIP Caster
122 // -----------------------------------
123 openCaster();
124
125 // Start listening for rtnet results
126 // ---------------------------------
127 QSettings settings;
128 _clkServer = new QTcpServer;
129 _clkServer->listen(QHostAddress::Any, settings.value("clkPort").toInt());
130 connect(_clkServer, SIGNAL(newConnection()),this, SLOT(slotNewConnection()));
131
132 // Endless loop
133 // ------------
134 while (true) {
135 if (_clkSocket) {
136
137 }
138 else {
139 msleep(100);
140 }
141 }
142}
143
Note: See TracBrowser for help on using the repository browser.