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

Last change on this file since 1752 was 1752, checked in by weber, 15 years ago

* empty log message *

File size: 4.5 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 printf("4800\n");
115 _serialPort->setBaudRate(BAUD4800);
116 }
117 else if (hlp == "9600") {
118 _serialPort->setBaudRate(BAUD9600);
119 }
120 else if (hlp == "19200") {
121 _serialPort->setBaudRate(BAUD19200);
122 }
123 else if (hlp == "38400") {
124 _serialPort->setBaudRate(BAUD38400);
125 }
126 else if (hlp == "57600") {
127 _serialPort->setBaudRate(BAUD57600);
128 }
129 else if (hlp == "115200") {
130 _serialPort->setBaudRate(BAUD115200);
131 }
132
133 // Parity
134 // ------
135 hlp = hlpL[hlpL.size()-4].toUpper();
136 if (hlp == "NONE") {
137 printf("NONE\n");
138 _serialPort->setParity(PAR_NONE);
139 }
140 else if (hlp == "ODD") {
141 _serialPort->setParity(PAR_ODD);
142 }
143 else if (hlp == "EVEN") {
144 _serialPort->setParity(PAR_EVEN);
145 }
146 else if (hlp == "SPACE") {
147 _serialPort->setParity(PAR_SPACE);
148 }
149
150 // Data Bits
151 // ---------
152 hlp = hlpL[hlpL.size()-5];
153 if (hlp == "5") {
154 _serialPort->setDataBits(DATA_5);
155 }
156 else if (hlp == "6") {
157 _serialPort->setDataBits(DATA_6);
158 }
159 else if (hlp == "7") {
160 _serialPort->setDataBits(DATA_7);
161 }
162 else if (hlp == "8") {
163 printf("8\n");
164 _serialPort->setDataBits(DATA_8);
165 }
166
167 // Stop Bits
168 // ---------
169 hlp = hlpL[hlpL.size()-3];
170 if (hlp == "1") {
171 printf("1\n");
172 _serialPort->setStopBits(STOP_1);
173 }
174 else if (hlp == "2") {
175 _serialPort->setStopBits(STOP_2);
176 }
177
178 // Flow Control
179 // ------------
180 hlp = hlpL[hlpL.size()-2].toUpper();
181 if (hlp == "XONXOFF") {
182 printf("XONXOFF\n");
183 _serialPort->setFlowControl(FLOW_XONXOFF);
184 }
185 else if (hlp == "HARDWARE") {
186 _serialPort->setFlowControl(FLOW_HARDWARE);
187 }
188 else {
189 _serialPort->setFlowControl(FLOW_OFF);
190 }
191
192 _status = running;
193 _serialPort->open(QIODevice::ReadWrite|QIODevice::Unbuffered);
194 if (!_serialPort->isOpen()) {
195 delete _serialPort;
196 _serialPort = 0;
197 _status = error;
198 emit(newMessage(("Cannot open serial port\n"), true));
199 return;
200 }
201}
202
Note: See TracBrowser for help on using the repository browser.