source: ntrip/trunk/BNC/test_bnc.cpp@ 622

Last change on this file since 622 was 465, checked in by mervart, 17 years ago

* empty log message *

File size: 3.9 KB
Line 
1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters,
3// written by Leos Mervart.
4//
5// Copyright (C) 2006
6// German Federal Agency for Cartography and Geodesy (BKG)
7// http://www.bkg.bund.de
8// Czech Technical University Prague, Department of Geodesy
9// http://www.fsv.cvut.cz
10//
11// Email: euref-ip@bkg.bund.de
12//
13// This program is free software; you can redistribute it and/or
14// modify it under the terms of the GNU General Public License
15// as published by the Free Software Foundation, version 2.
16//
17// This program is distributed in the hope that it will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20// GNU General Public License for more details.
21//
22// You should have received a copy of the GNU General Public License
23// along with this program; if not, write to the Free Software
24// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
26// MinGW: g++ test_bnc.cpp -lws2_32
27
28#include <iostream>
29#include <iomanip>
30
31#ifdef WIN32
32#include <winsock2.h> // link with ws2_32.lib
33#endif
34
35#include "RTCM/GPSDecoder.h"
36
37using namespace std;
38
39const char begEpoch = 'A';
40const char begObs = 'B';
41const char endEpoch = 'C';
42
43int main(int argc, char* argv[]) {
44
45 // Initialize Winsock
46 // ------------------
47 WSADATA wsaData;
48 int iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
49 if (iResult != NO_ERROR) {
50 cerr << "Error at WSAStartup" << endl;
51 return 1;
52 }
53
54 // Create a SOCKET for connecting to server
55 // ----------------------------------------
56 SOCKET ConnectSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
57 if (ConnectSocket == INVALID_SOCKET) {
58 cerr << "Error at socket: " << WSAGetLastError() << endl;
59 WSACleanup();
60 return 1;
61 }
62
63 // The sockaddr_in structure specifies the address family,
64 // IP address, and port of the server to be connected to.
65 // -------------------------------------------------------
66 sockaddr_in clientService;
67 clientService.sin_family = AF_INET;
68 clientService.sin_addr.s_addr = inet_addr( "127.0.0.1" );
69 clientService.sin_port = htons(1968);
70
71 // Connect to server
72 // -----------------
73 if (connect( ConnectSocket, (SOCKADDR*) &clientService,
74 sizeof(clientService) ) == SOCKET_ERROR) {
75 cerr << "Failed to connect" << endl;
76 WSACleanup();
77 return 1;
78 }
79
80 // Receive Data
81 // ------------
82 int bytesRecv = 0;
83 Observation obs;
84 char flag = ' ';
85 cout.setf(ios::showpoint | ios::fixed);
86 while (true) {
87 if (bytesRecv == SOCKET_ERROR) {
88 cerr << "recv failed: " << WSAGetLastError() << endl;
89 break;
90 }
91 else {
92 bytesRecv = recv( ConnectSocket, &flag, 1, 0 );
93 if (flag == begObs) {
94 bytesRecv = recv( ConnectSocket, (char*) &obs, sizeof(obs), 0);
95 cout << setw(5) << obs.StatID << " "
96 << obs.satSys << setw(2) << obs.satNum << " "
97 << setw(4) << obs.GPSWeek << " "
98 << setw(10) << setprecision(2) << obs.GPSWeeks << " "
99 << setw(14) << setprecision(4) << obs.C1 << " "
100 << setw(14) << setprecision(4) << obs.C2 << " "
101 << setw(14) << setprecision(4) << obs.P1 << " "
102 << setw(14) << setprecision(4) << obs.P2 << " "
103 << setw(14) << setprecision(4) << obs.L1 << " "
104 << setw(14) << setprecision(4) << obs.L2 << " "
105 << setw(14) << setprecision(4) << obs.S1 << " "
106 << setw(14) << setprecision(4) << obs.S2 << " "
107 << setw(4) << obs.SNR1 << " "
108 << setw(4) << obs.SNR2 << endl;
109 }
110 }
111 }
112
113 WSACleanup();
114 return 0;
115}
116
117
Note: See TracBrowser for help on using the repository browser.