Changeset 2704 in ntrip


Ignore:
Timestamp:
Nov 16, 2010, 1:44:01 PM (13 years ago)
Author:
mervart
Message:
 
Location:
trunk/BNC
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/test_bnc_qt.cpp

    r2259 r2704  
    4242#include <iostream>
    4343#include <iomanip>
    44 
    45 #include "RTCM/GPSDecoder.h"
    46 #include "bnctime.h"
    47 extern "C" {
    48 #include "RTCM3/rtcm3torinex.h"
    49 }
    50 
    5144#include <QTcpSocket>
    5245
    5346using namespace std;
    5447
    55 void RTCM3Error(const char*, ...) {}
     48class t_obsInternal {
     49  public:
     50  int    flags;
     51  char   StatID[20+1];  // Station ID
     52  char   satSys;        // Satellite System ('G' or 'R')
     53  int    satNum;        // Satellite Number (PRN for GPS NAVSTAR)
     54  int    slot;          // Slot (Channel) Number (for Glonass)
     55  int    GPSWeek;       // Week of GPS-Time
     56  double GPSWeeks;      // Second of Week (GPS-Time)
     57  double C1;            // CA-code pseudorange (meters)
     58  double C2;            // CA-code pseudorange (meters)
     59  double P1;            // P1-code pseudorange (meters)
     60  double P2;            // P2-code pseudorange (meters)
     61  double L1;            // L1 carrier phase (cycles)
     62  double L2;            // L2 carrier phase (cycles)
     63  int    slip_cnt_L1;   // L1 cumulative loss of continuity indicator (negative value = undefined)
     64  int    slip_cnt_L2;   // L2 cumulative loss of continuity indicator (negative value = undefined)
     65  int    lock_timei_L1; // L1 last lock time indicator                (negative value = undefined)
     66  int    lock_timei_L2; // L2 last lock time indicator                (negative value = undefined)
     67  double S1;            // L1 signal-to noise ratio
     68  double S2;            // L2 signal-to noise ratio
     69  int    SNR1;          // L1 signal-to noise ratio (mapped to integer)
     70  int    SNR2;          // L2 signal-to noise ratio (mapped to integer)
     71};
    5672
    57 int main(int /* argc */, char** /* argv */) {
     73int main(int argc, char** argv) {
    5874
    59   int    year  = 2010;
    60   int    month =    1;
    61   int    day   =   10;
    62   int    hour  =   12;
    63   int    min   =   30;
    64   double sec   =  0.0;
     75  if (argc != 2) {
     76    cerr << "Usage: test_bnc_qt port\n";
     77    exit(1);
     78  }
    6579
    66   bncTime tt;
    67   tt.set(year, month, day, hour, min, sec);
    68   cout << tt.timestr() << " Moscow time (UTC + 3h)" << endl;
    69   cout << "GPS-UTC: " << gnumleap(year, month, day) << endl;
     80  int port = atoi(argv[1]);
     81
     82  QTcpSocket socketObs;
     83
     84  socketObs.connectToHost("127.0.0.1", port);
     85  if (!socketObs.waitForConnected(10000)) {
     86    cerr << "socketObs: not connected on port " << port << endl;
     87    exit(1);
     88  }
     89
     90  cout.setf(ios::fixed);
     91
     92  // Receive Data
     93  // ------------
     94  const char begObs[] = "BEGOBS";
     95  const char begEpoch[] = "BEGEPOCH";
     96  const char endEpoch[] = "ENDEPOCH";
     97  const unsigned begObsNBytes   = sizeof(begObs) - 1;
     98  const unsigned begEpochNBytes = sizeof(begEpoch) - 1;
     99  const unsigned endEpochNBytes = sizeof(endEpoch) - 1;
     100
     101  QByteArray buffer;
     102
     103  while (true) {
     104    if (socketObs.state() != QAbstractSocket::ConnectedState) {
     105      cerr << "socketObs: disconnected" << endl;
     106      exit(1);
     107    }
     108
     109    if ( socketObs.bytesAvailable() ) {
     110      buffer += socketObs.readAll();
     111
     112      // Skip begEpoch and endEpoch Marks
     113      // --------------------------------
     114      for (;;) {
     115        int i1 = buffer.indexOf(begEpoch);
     116        if (i1 == -1) {
     117          break;
     118        }
     119        else {
     120          buffer.remove(i1, begEpochNBytes);
     121          cout << endl;
     122        }
     123      }
     124      for (;;) {
     125        int i2 = buffer.indexOf(endEpoch);
     126        if (i2 == -1) {
     127          break;
     128        }
     129        else {
     130          buffer.remove(i2, endEpochNBytes);
     131        }
     132      }
     133      for (;;) {
     134        int i3 = buffer.indexOf(begObs);
     135        if (i3 == -1) {
     136          break;
     137        }
     138        else {
     139          buffer.remove(i3, begObsNBytes);
     140        }
     141      }
     142
     143      // Interpret a portion of buffer as observation
     144      // --------------------------------------------
     145      t_obsInternal* obs;
     146      const int obsSize = sizeof(t_obsInternal);
    70147
    71148
    72   int week = tt.gpsw();
    73   int tow  = int(tt.gpssec());
    74   updatetime(&week, &tow, tow*1000, 1);
    75   bncTime t2(week, tow);
    76   cout << t2.timestr() << " UTC " << endl;
     149      while (buffer.size() >= obsSize) {
    77150
    78   week = tt.gpsw();
    79   tow  = int(tt.gpssec());
    80   updatetime(&week, &tow, tow*1000, 0);
    81   bncTime t3(week, tow);
    82   cout << t3.timestr() << " GPS " << endl;
     151        obs = (t_obsInternal*) (buffer.left(obsSize).data());
    83152
     153        cout << obs->StatID                      << " "
     154             << obs->satSys << obs->satNum       << " "
     155             << obs->GPSWeek                     << " "
     156             << setprecision(2) << obs->GPSWeeks << " "
     157             << setprecision(4) << obs->C1       << " "
     158             << setprecision(4) << obs->C2       << " "
     159             << setprecision(4) << obs->P1       << " "
     160             << setprecision(4) << obs->P2       << " "
     161             << setprecision(4) << obs->L1       << " "
     162             << setprecision(4) << obs->L2       << " "
     163             <<                    obs->slip_cnt_L1 << " "
     164             <<                    obs->slip_cnt_L2 << " "
     165             << setprecision(4) << obs->S1       << " "
     166             << setprecision(4) << obs->S2       << " "
     167             <<                    obs->SNR1     << " "
     168             <<                    obs->SNR2     << endl;
    84169
    85 //  if (argc != 2) {
    86 //    cerr << "Usage: test_bnc_qt port\n";
    87 //    exit(1);
    88 //  }
    89 //
    90 //  int port = atoi(argv[1]);
    91 //
    92 //  QTcpSocket socketObs;
    93 //
    94 //  socketObs.connectToHost("127.0.0.1", port);
    95 //  if (!socketObs.waitForConnected(10000)) {
    96 //    cerr << "socketObs: not connected on port " << port << endl;
    97 //    exit(1);
    98 //  }
    99 //
    100 //  cout.setf(ios::fixed);
    101 //
    102 //  // Receive Data
    103 //  // ------------
    104 //  const char begObs[] = "BEGOBS";
    105 //  const char begEpoch[] = "BEGEPOCH";
    106 //  const char endEpoch[] = "ENDEPOCH";
    107 //  const unsigned begObsNBytes   = sizeof(begObs) - 1;
    108 //  const unsigned begEpochNBytes = sizeof(begEpoch) - 1;
    109 //  const unsigned endEpochNBytes = sizeof(endEpoch) - 1;
    110 //
    111 //  QByteArray buffer;
    112 //
    113 //  while (true) {
    114 //    if (socketObs.state() != QAbstractSocket::ConnectedState) {
    115 //      cerr << "socketObs: disconnected" << endl;
    116 //      exit(1);
    117 //    }
    118 //
    119 //    if ( socketObs.bytesAvailable() ) {
    120 //      buffer += socketObs.readAll();
    121 //
    122 //      // Skip begEpoch and endEpoch Marks
    123 //      // --------------------------------
    124 //      for (;;) {
    125 //        int i1 = buffer.indexOf(begEpoch);
    126 //        if (i1 == -1) {
    127 //          break;
    128 //        }
    129 //        else {
    130 //          buffer.remove(i1, begEpochNBytes);
    131 //          cout << endl;
    132 //        }
    133 //      }
    134 //      for (;;) {
    135 //        int i2 = buffer.indexOf(endEpoch);
    136 //        if (i2 == -1) {
    137 //          break;
    138 //        }
    139 //        else {
    140 //          buffer.remove(i2, endEpochNBytes);
    141 //        }
    142 //      }
    143 //      for (;;) {
    144 //        int i3 = buffer.indexOf(begObs);
    145 //        if (i3 == -1) {
    146 //          break;
    147 //        }
    148 //        else {
    149 //          buffer.remove(i3, begObsNBytes);
    150 //        }
    151 //      }
    152 //
    153 //      // Interpret a portion of buffer as observation
    154 //      // --------------------------------------------
    155 //      t_obsInternal* obs;
    156 //      const int obsSize = sizeof(t_obsInternal);
    157 //
    158 //
    159 //      while (buffer.size() >= obsSize) {
    160 //
    161 //        obs = (t_obsInternal*) (buffer.left(obsSize).data());
    162 //
    163 //        cout << obs->StatID                      << " "
    164 //             << obs->satSys << obs->satNum       << " "
    165 //             << obs->GPSWeek                     << " "
    166 //             << setprecision(2) << obs->GPSWeeks << " "
    167 //             << setprecision(4) << obs->C1       << " "
    168 //             << setprecision(4) << obs->C2       << " "
    169 //             << setprecision(4) << obs->P1       << " "
    170 //             << setprecision(4) << obs->P2       << " "
    171 //             << setprecision(4) << obs->L1       << " "
    172 //             << setprecision(4) << obs->L2       << " "
    173 //             <<                    obs->slip_cnt_L1 << " "
    174 //             <<                    obs->slip_cnt_L2 << " "
    175 //             << setprecision(4) << obs->S1       << " "
    176 //             << setprecision(4) << obs->S2       << " "
    177 //             <<                    obs->SNR1     << " "
    178 //             <<                    obs->SNR2     << endl;
    179 //
    180 //        buffer.remove(0,obsSize);
    181 //      }
    182 //    }
    183 //    else {
    184 //      socketObs.waitForReadyRead(1);
    185 //    }
    186 //  }
     170        buffer.remove(0,obsSize);
     171      }
     172    }
     173    else {
     174      socketObs.waitForReadyRead(1);
     175    }
     176  }
    187177
    188178  return 0;
  • trunk/BNC/test_bnc_qt.pro

    r2259 r2704  
    66INCLUDEPATH = . ./RTCM3
    77
    8 HEADERS = bnctime.h   RTCM3/rtcm3torinex.h RTCM3/timeutils.h
     8HEADERS = bnctime.h
    99
    10 SOURCES = test_bnc_qt.cpp \
    11           bnctime.cpp RTCM3/rtcm3torinex.c RTCM3/timeutils.cpp
     10SOURCES = test_bnc_qt.cpp
    1211
    1312QT += network
Note: See TracChangeset for help on using the changeset viewer.