source: ntrip/trunk/BNC/bncnetquerys.cpp@ 1957

Last change on this file since 1957 was 1760, checked in by weber, 16 years ago

* empty log message *

File size: 4.4 KB
Line 
1/* -------------------------------------------------------------------------
2 * BKG NTRIP Client
3 * -------------------------------------------------------------------------
4 *
5 * Class: bncnetquerys
6 *
7 * Purpose: Serial Communication Requests, no NTRIP
8 *
9 * Author: G. Weber
10 *
11 * Created: 8-Mar-2009
12 *
13 * Changes:
14 *
15 * -----------------------------------------------------------------------*/
16
17#include "bncnetquerys.h"
18
19using namespace std;
20
21#define BNCVERSION "1.7"
22
23// Constructor
24////////////////////////////////////////////////////////////////////////////
25bncNetQueryS::bncNetQueryS() {
26
27 _serialPort = 0;
28
29}
30
31// Destructor
32////////////////////////////////////////////////////////////////////////////
33bncNetQueryS::~bncNetQueryS() {
34 delete _serialPort;
35}
36
37//
38////////////////////////////////////////////////////////////////////////////
39void bncNetQueryS::stop() {
40#ifndef sparc
41 if (_serialPort) {
42 }
43#endif
44 _status = finished;
45}
46
47//
48/////////////////////////////////////////////////////////////////////////////
49void bncNetQueryS::waitForRequestResult(const QUrl&, QByteArray&) {
50}
51
52//
53////////////////////////////////////////////////////////////////////////////
54void bncNetQueryS::waitForReadyRead(QByteArray& outData) {
55 if (_serialPort) {
56 while (true) {
57 int nb = _serialPort->bytesAvailable();
58 if (nb > 0) {
59 outData = _serialPort->read(nb);
60 return;
61 }
62 }
63 }
64}
65
66// Connect to Serial Port
67////////////////////////////////////////////////////////////////////////////
68void bncNetQueryS::startRequest(const QUrl& url, const QByteArray& gga) {
69
70 QByteArray dummy_gga = gga;
71
72 _url = url;
73 if (_url.scheme().isEmpty()) {
74 _url.setScheme("http");
75 }
76 if (_url.path().isEmpty()) {
77 _url.setPath("/");
78 }
79
80 QString hlp;
81 QStringList hlpL;
82 hlp = _url.host().toAscii().replace("-"," ");
83 hlpL = hlp.split(" ");
84
85 // Serial Port
86 // -----------
87 QString _portString;
88 if (hlpL.size() == 6) {
89 _portString = hlpL[hlpL.size()-6].replace("com","COM");
90 } else {
91 _portString = "/" + hlpL[hlpL.size()-7] + "/" + hlpL[hlpL.size()-6].replace("ttys","ttyS");
92 }
93 _serialPort = new QextSerialPort(_portString);
94
95 // Baud Rate
96 // ---------
97 hlp = hlpL[hlpL.size()-1];
98 if (hlp == "110") {
99 _serialPort->setBaudRate(BAUD110);
100 }
101 else if (hlp == "300") {
102 _serialPort->setBaudRate(BAUD300);
103 }
104 else if (hlp == "600") {
105 _serialPort->setBaudRate(BAUD600);
106 }
107 else if (hlp == "1200") {
108 _serialPort->setBaudRate(BAUD1200);
109 }
110 else if (hlp == "2400") {
111 _serialPort->setBaudRate(BAUD2400);
112 }
113 else if (hlp == "4800") {
114 _serialPort->setBaudRate(BAUD4800);
115 }
116 else if (hlp == "9600") {
117 _serialPort->setBaudRate(BAUD9600);
118 }
119 else if (hlp == "19200") {
120 _serialPort->setBaudRate(BAUD19200);
121 }
122 else if (hlp == "38400") {
123 _serialPort->setBaudRate(BAUD38400);
124 }
125 else if (hlp == "57600") {
126 _serialPort->setBaudRate(BAUD57600);
127 }
128 else if (hlp == "115200") {
129 _serialPort->setBaudRate(BAUD115200);
130 }
131
132 // Parity
133 // ------
134 hlp = hlpL[hlpL.size()-4].toUpper();
135 if (hlp == "NONE") {
136 _serialPort->setParity(PAR_NONE);
137 }
138 else if (hlp == "ODD") {
139 _serialPort->setParity(PAR_ODD);
140 }
141 else if (hlp == "EVEN") {
142 _serialPort->setParity(PAR_EVEN);
143 }
144 else if (hlp == "SPACE") {
145 _serialPort->setParity(PAR_SPACE);
146 }
147
148 // Data Bits
149 // ---------
150 hlp = hlpL[hlpL.size()-5];
151 if (hlp == "5") {
152 _serialPort->setDataBits(DATA_5);
153 }
154 else if (hlp == "6") {
155 _serialPort->setDataBits(DATA_6);
156 }
157 else if (hlp == "7") {
158 _serialPort->setDataBits(DATA_7);
159 }
160 else if (hlp == "8") {
161 _serialPort->setDataBits(DATA_8);
162 }
163
164 // Stop Bits
165 // ---------
166 hlp = hlpL[hlpL.size()-3];
167 if (hlp == "1") {
168 _serialPort->setStopBits(STOP_1);
169 }
170 else if (hlp == "2") {
171 _serialPort->setStopBits(STOP_2);
172 }
173
174 // Flow Control
175 // ------------
176 hlp = hlpL[hlpL.size()-2].toUpper();
177 if (hlp == "XONXOFF") {
178 _serialPort->setFlowControl(FLOW_XONXOFF);
179 }
180 else if (hlp == "HARDWARE") {
181 _serialPort->setFlowControl(FLOW_HARDWARE);
182 }
183 else {
184 _serialPort->setFlowControl(FLOW_OFF);
185 }
186
187 _status = running;
188
189 _serialPort->open(QIODevice::ReadWrite|QIODevice::Unbuffered);
190 if (!_serialPort->isOpen()) {
191 delete _serialPort;
192 _serialPort = 0;
193 _status = error;
194 emit newMessage(_url.path().toAscii().replace(0,1,"") + ": Cannot open serial port " + _portString.toAscii(), true);
195 return;
196 }
197}
198
Note: See TracBrowser for help on using the repository browser.