[35] | 1 |
|
---|
[235] | 2 | // MinGW: g++ test_bnc.cpp -lws2_32
|
---|
[38] | 3 |
|
---|
[35] | 4 | #include <iostream>
|
---|
| 5 | #include <iomanip>
|
---|
| 6 |
|
---|
| 7 | #ifdef WIN32
|
---|
| 8 | #include <winsock2.h> // link with ws2_32.lib
|
---|
| 9 | #endif
|
---|
| 10 |
|
---|
[232] | 11 | #include "RTCM/GPSDecoder.h"
|
---|
| 12 |
|
---|
[35] | 13 | using namespace std;
|
---|
| 14 |
|
---|
| 15 | const char begEpoch = 'A';
|
---|
| 16 | const char begObs = 'B';
|
---|
| 17 | const char endEpoch = 'C';
|
---|
| 18 |
|
---|
| 19 | int 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 << " "
|
---|
[232] | 72 | << setw(2) << obs.SVPRN << " "
|
---|
[35] | 73 | << setw(4) << obs.GPSWeek << " "
|
---|
[232] | 74 | << setw(10) << setprecision(2) << obs.GPSWeeks << " "
|
---|
[35] | 75 | << setw(14) << setprecision(4) << obs.C1 << " "
|
---|
[232] | 76 | << setw(14) << setprecision(4) << obs.P1 << " "
|
---|
[35] | 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 << " "
|
---|
[232] | 81 | << setw(4) << obs.SNR2 << endl;
|
---|
[35] | 82 | }
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | WSACleanup();
|
---|
| 87 | return 0;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 |
|
---|