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

Last change on this file since 259 was 235, checked in by mervart, 18 years ago

* empty log message *

File size: 2.7 KB
Line 
1
2// MinGW: g++ test_bnc.cpp -lws2_32
3
4#include <iostream>
5#include <iomanip>
6
7#ifdef WIN32
8#include <winsock2.h> // link with ws2_32.lib
9#endif
10
11#include "RTCM/GPSDecoder.h"
12
13using namespace std;
14
15const char begEpoch = 'A';
16const char begObs = 'B';
17const char endEpoch = 'C';
18
19int main(int argc, char* argv[]) {
20
21 // Initialize Winsock
22 // ------------------
23 WSADATA wsaData;
24 int iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
25 if (iResult != NO_ERROR) {
26 cerr << "Error at WSAStartup" << endl;
27 return 1;
28 }
29
30 // Create a SOCKET for connecting to server
31 // ----------------------------------------
32 SOCKET ConnectSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
33 if (ConnectSocket == INVALID_SOCKET) {
34 cerr << "Error at socket: " << WSAGetLastError() << endl;
35 WSACleanup();
36 return 1;
37 }
38
39 // The sockaddr_in structure specifies the address family,
40 // IP address, and port of the server to be connected to.
41 // -------------------------------------------------------
42 sockaddr_in clientService;
43 clientService.sin_family = AF_INET;
44 clientService.sin_addr.s_addr = inet_addr( "127.0.0.1" );
45 clientService.sin_port = htons(1968);
46
47 // Connect to server
48 // -----------------
49 if (connect( ConnectSocket, (SOCKADDR*) &clientService,
50 sizeof(clientService) ) == SOCKET_ERROR) {
51 cerr << "Failed to connect" << endl;
52 WSACleanup();
53 return 1;
54 }
55
56 // Receive Data
57 // ------------
58 int bytesRecv = 0;
59 Observation obs;
60 char flag = ' ';
61 cout.setf(ios::showpoint | ios::fixed);
62 while (true) {
63 if (bytesRecv == SOCKET_ERROR) {
64 cerr << "recv failed: " << WSAGetLastError() << endl;
65 break;
66 }
67 else {
68 bytesRecv = recv( ConnectSocket, &flag, 1, 0 );
69 if (flag == begObs) {
70 bytesRecv = recv( ConnectSocket, (char*) &obs, sizeof(obs), 0);
71 cout << setw(5) << obs.StatID << " "
72 << setw(2) << obs.SVPRN << " "
73 << setw(4) << obs.GPSWeek << " "
74 << setw(10) << setprecision(2) << obs.GPSWeeks << " "
75 << setw(14) << setprecision(4) << obs.C1 << " "
76 << setw(14) << setprecision(4) << obs.P1 << " "
77 << setw(14) << setprecision(4) << obs.P2 << " "
78 << setw(14) << setprecision(4) << obs.L1 << " "
79 << setw(14) << setprecision(4) << obs.L2 << " "
80 << setw(4) << obs.SNR1 << " "
81 << setw(4) << obs.SNR2 << endl;
82 }
83 }
84 }
85
86 WSACleanup();
87 return 0;
88}
89
90
Note: See TracBrowser for help on using the repository browser.