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

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

Imported sources

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