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

Last change on this file since 201 was 38, checked in by perlt, 19 years ago

* empty log message *

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