Changeset 293 in ntrip


Ignore:
Timestamp:
Nov 12, 2006, 3:32:52 PM (17 years ago)
Author:
mervart
Message:

* empty log message *

Location:
trunk/BNC
Files:
2 added
5 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/RTIGS/rtigs.cpp

    r248 r293  
     1/* rtigs.cpp
     2 * - Source functions
     3 *
     4 * Copyright (c) 2006
     5 * Geoscience Australia
     6 *
     7 * Written by James Stewart
     8 * E-mail: James.Stewart@ga.gov.au
     9 *
     10 * Enquiries contact
     11 * Michael Moore
     12 * E-mail: Michael.Moore@ga.gov.au
     13 *
     14 * Based on the GNU General Public License published Icecast 1.3.12
     15 *
     16 * This program is free software; you can redistribute it and/or
     17 * modify it under the terms of the GNU General Public License
     18 * as published by the Free Software Foundation; either version 2
     19 * of the License, or (at your option) any later version.
     20 *
     21 * This program is distributed in the hope that it will be useful,
     22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     24 * GNU General Public License for more details.
     25 *
     26 * You should have received a copy of the GNU General Public License
     27 * along with this program; if not, write to the Free Software
     28 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
     29 */
    130
    2 /* -------------------------------------------------------------------------
    3  * BKG NTRIP Client
    4  * -------------------------------------------------------------------------
    5  *
    6  * Class:      rtigs
    7  *
    8  * Purpose:    RTIGS Decoder
    9  *
    10  * Author:     L. Mervart
    11  *
    12  * Created:    24-Aug-2006
    13  *
    14  * Changes:   
    15  *
    16  * -----------------------------------------------------------------------*/
     31#include <string.h>
     32#include "rtigs.h"
    1733
    18 #include "rtigs.h"
    19 #include "bncconst.h"
    20 
    21 using namespace std;
    22 
    23 #undef L1
    24 #undef L2
    25 
    26 // Constructor
    27 ////////////////////////////////////////////////////////////////////////////
    28 rtigs::rtigs() {
     34void bytes_to_rtigsh(RTIGSH *rtigsh, unsigned char *packet) {
     35  memcpy(rtigsh, packet, sizeof(RTIGSH));
     36  revbytes((unsigned char *)&(rtigsh->rec_id), 2);
     37  revbytes((unsigned char *)&(rtigsh->sta_id), 2);
     38  revbytes((unsigned char *)&(rtigsh->GPSTime), 4);
     39  revbytes((unsigned char *)&(rtigsh->num_bytes), 2);
    2940}
    3041
    31 // Destructor
    32 ////////////////////////////////////////////////////////////////////////////
    33 rtigs::~rtigs() {
     42int rtigso_to_raw(RTIGSO *rtigso, GPSEpoch *gpse) {
     43  struct JPL_COMP_OBS_T soc;
     44  int ptr = 0;
     45  unsigned char * p1;
     46  unsigned char * p2;
     47
     48  double CA_Range = 0.00;
     49  double P1_Range, P2_Range, L1_Cycles, L2_Cycles;
     50  double L1_Diff = 0.00;
     51  double L2_Diff = 0.00;
     52
     53  long long ABS_CA_Range = 0;
     54
     55  double L1_Phase = 0.00;
     56  double L2_Phase = 0.00;
     57
     58  int ABS_L1_Diff = 0;
     59  int ABS_L2_Diff = 0;
     60  int ABS_L1_Phase = 0;
     61  int ABS_L2_Phase = 0;
     62
     63  gpse->num_sv    = rtigso->num_obs;
     64  gpse->GPSTime   = rtigso->GPSTime;
     65  gpse->sta_id    = rtigso->sta_id;
     66
     67  for(ptr = 0; ptr < rtigso->num_obs; ptr++) {
     68    memset(&soc, 0, sizeof(struct JPL_COMP_OBS_T));
     69    memcpy(&(soc.prn), &(rtigso->data[ptr][0]), 1);
     70    memcpy(&(soc.epoch_sequence), &(rtigso->data[ptr][1]), 2);
     71    memcpy(&(soc.ca_range[0]), &(rtigso->data[ptr][3]), 18);
     72
     73    p1 = ((unsigned char *)&ABS_CA_Range);
     74    p2 = &(soc.ca_range[0]);
     75
     76    p1[4] = (p2[0] & 0xF);
     77    p1[3] = p2[1];
     78    p1[2] = p2[2];
     79    p1[1] = p2[3];
     80    p1[0] = p2[4];
     81
     82    p1 = (unsigned char *)&ABS_L1_Diff;
     83    p2 = (unsigned char *)&(soc.L1_range_phase[0]);
     84
     85    if(p2[0] & 0x80)
     86      L1_Diff = -1.000;
     87    else
     88      L1_Diff = 1.000;
     89
     90    p1[2] = (p2[0] & 0x40) >> 6;
     91    p1[1] = ((p2[0] & 0x3F) << 2) + ((p2[1] & 0xC0) >> 6);
     92    p1[0] = ((p2[1] & 0x3F) << 2) + ((p2[2] & 0xC0) >> 6);
     93
     94    if(p2[2] & 0x20)
     95      L1_Phase = -1.000;
     96    else
     97      L1_Phase =  1.000;
     98
     99    p1 = (unsigned char *)&ABS_L1_Phase;
     100    p1[2] = (p2[2] & 0x1F);
     101    p1[1] = p2[3];
     102    p1[0] = p2[4];
     103
     104
     105
     106    p1 = (unsigned char *)&ABS_L2_Diff;
     107    p2 = (unsigned char *)&(soc.L2_range_phase[0]);
     108
     109    if(p2[0] & 0x80)
     110      L2_Diff = -1.000;
     111    else
     112      L2_Diff = 1.000;
     113
     114    p1[2] = (p2[0] & 0x40) >> 6;
     115    p1[1] = ((p2[0] & 0x3F) << 2) + ((p2[1] & 0xC0) >> 6);
     116    p1[0] = ((p2[1] & 0x3F) << 2) + ((p2[2] & 0xC0) >> 6);
     117
     118    if(p2[2] & 0x20)
     119      L2_Phase = -1.000;
     120    else
     121      L2_Phase =  1.000;
     122
     123    p1 = (unsigned char *)&ABS_L2_Phase;
     124    p1[2] = (p2[2] & 0x1F);
     125    p1[1] = p2[3];
     126    p1[0] = p2[4];
     127
     128    p2 = &(soc.ca_range[0]);
     129    if(p2[0] & 0x20)
     130      ABS_L2_Phase += (1 << 22);
     131    if(p2[0] & 0x10)
     132      ABS_L1_Phase += (1 << 22);
     133
     134    L1_Phase = L1_Phase * (((double)ABS_L1_Phase) / 50000.00);
     135    L2_Phase = L2_Phase * (((double)ABS_L2_Phase) / 50000.00);
     136
     137    L1_Diff = L1_Diff * (((double)ABS_L1_Diff) / 1000.00);
     138    L2_Diff = L2_Diff * (((double)ABS_L2_Diff) / 1000.00);
     139
     140    CA_Range = (double)ABS_CA_Range / 1000;
     141    P1_Range = CA_Range + L1_Diff;
     142    P2_Range = CA_Range + L2_Diff;
     143
     144    L1_Cycles = ((CA_Range + L1_Phase) - (SF2 * L2_Diff)) / W1;
     145    L2_Cycles = ((CA_Range + L2_Phase) - (SF1 * L2_Diff)) / W2;
     146
     147    gpse->sv[ptr].prn         = soc.prn;
     148    gpse->sv[ptr].locktime  = soc.epoch_sequence;
     149    gpse->sv[ptr].CARange   = CA_Range;
     150    gpse->sv[ptr].CASnr     = soc.CA_snr;
     151
     152    gpse->sv[ptr].P1Range   = P1_Range;
     153    gpse->sv[ptr].L1Phase   = L1_Cycles;
     154    gpse->sv[ptr].L1Snr     = soc.L1_snr;
     155
     156    gpse->sv[ptr].P2Range   = P2_Range;
     157    gpse->sv[ptr].L2Phase   = L2_Cycles;
     158    gpse->sv[ptr].L2Snr     = soc.L2_snr;
     159  }
     160  return 0;
    34161}
    35162
    36 //
    37 ////////////////////////////////////////////////////////////////////////////
    38 void rtigs::Decode(char* buffer, int bufLen) {
     163int rtigsm_to_raw(RTIGSM *rtigsm, GPSMet *met) {
     164  met->GPSTime = rtigsm->GPSTime;
     165  met->sta_id = rtigsm->sta_id;
     166  met->temperature = rtigsm->temp;
     167  met->pressure = rtigsm->press;
     168  met->humidity = rtigsm->humid;
     169  revbytes((unsigned char *)&met->temperature, 4);
     170  revbytes((unsigned char *)&met->pressure, 4);
     171  revbytes((unsigned char *)&met->humidity, 4);
     172  return 0;
     173}
    39174
    40   // Append the incomming data to the internal buffer
    41   // ------------------------------------------------
    42   _buffer.append( QByteArray(buffer, bufLen) );
     175void revbytes(unsigned char *buf, unsigned char size) {
     176  unsigned char tmp;
     177  unsigned char *ptr1 = buf;
     178  unsigned char *ptr2 = buf + (size - 1);
    43179
    44   // Find the beginning of the message
    45   // ---------------------------------
    46   bool found = false;
    47   for (int ii = 0; ii < _buffer.size(); ii++) {
    48     unsigned short xx;
    49     memcpy( (void*) &xx, &_buffer.data()[ii], sizeof(xx) );
    50     if (_GPSTrans.f_IsLittleEndian) {
    51       SwitchBytes( (char*) &xx, sizeof(xx) );
    52     }
    53     if (xx == 200) {
    54       _buffer = _buffer.mid(ii);
    55       found = true;
    56       break;
    57     }
     180  while(ptr1 < ptr2) {
     181    tmp = *ptr1;
     182    *ptr1 = *ptr2;
     183    *ptr2 = tmp;
     184    ptr1++;
     185    ptr2--;
    58186  }
    59 
    60   if (! found) {
    61     _buffer.clear();
    62     return;
    63   }
    64 
    65   unsigned char* p_buf = (unsigned char*) _buffer.data(); 
    66 
    67   unsigned short messType = _GPSTrans.GetRTIGSHdrRecType(p_buf);
    68   unsigned short numbytes = _GPSTrans.GetRTIGSHdrRecBytes(p_buf);
    69 
    70   // Not enough new data, return
    71   // ---------------------------
    72   if (_buffer.size() < numbytes) {
    73     return;
    74   }
    75 
    76   // Decode the epoch
    77   // ----------------
    78   if (messType == 200) {
    79     RTIGSO_T  rtigs_obs;
    80     short numObs = _GPSTrans.Decode_RTIGS_Obs(p_buf, numbytes, rtigs_obs);
    81 
    82     for (short ii = 0; ii < numObs; ii++) {
    83       Observation* obs = new Observation();
    84 
    85       obs->SVPRN    = _GPSTrans.DecObs.Obs[ii].sat_prn;
    86       obs->GPSWeek  = _GPSTrans.DecObs.Obs[ii].GPSTime / (7 * 86400);
    87       obs->GPSWeeks = _GPSTrans.DecObs.Obs[ii].GPSTime % (7 * 86400);
    88       obs->C1       = _GPSTrans.DecObs.Obs[ii].l1_pseudo_range;
    89       obs->P1       = _GPSTrans.DecObs.Obs[ii].p1_pseudo_range;
    90       obs->P2       = _GPSTrans.DecObs.Obs[ii].p2_pseudo_range;
    91       obs->L1       = _GPSTrans.DecObs.Obs[ii].p1_phase;
    92       obs->L2       = _GPSTrans.DecObs.Obs[ii].p2_phase;
    93       obs->SNR1     = int(_GPSTrans.DecObs.Obs[ii].l1_sn * 10);
    94       obs->SNR2     = int(_GPSTrans.DecObs.Obs[ii].l2_sn * 10);
    95 
    96       _obsList.push_back(obs);
    97     }
    98   }
    99 
    100   // Unprocessed bytes remain in buffer
    101   // ----------------------------------
    102   _buffer = _buffer.mid(numbytes);
    103187}
  • trunk/BNC/RTIGS/rtigs.h

    r67 r293  
    1 
    2 #ifndef RTIGS_H
    3 #define RTIGS_H
    4 
    5 #include <QByteArray>
    6 
    7 #include "../RTCM/GPSDecoder.h"
    8 #include "cgps_transform.h"
    9 
    10 class rtigs : public GPSDecoder {
    11 public:
    12   rtigs();
    13   ~rtigs();
    14   void Decode(char* buffer = 0, int bufLen = 0);
    15 private:
    16   CGPS_Transform _GPSTrans;
    17   QByteArray     _buffer;
    18 } ;
     1/* Defines for the RTIGS <--> Raw Converter
     2 * - Source functions
     3 *
     4 * Copyright (c) 2006
     5 * Geoscience Australia
     6 *
     7 * Written by James Stewart
     8 * E-mail: James.Stewart@ga.gov.au
     9 *
     10 * Enquiries contact
     11 * Michael Moore
     12 * E-mail: Michael.Moore@ga.gov.au
     13 *
     14 * Based on the GNU General Public License published Icecast 1.3.12
     15 *
     16 * This program is free software; you can redistribute it and/or
     17 * modify it under the terms of the GNU General Public License
     18 * as published by the Free Software Foundation; either version 2
     19 * of the License, or (at your option) any later version.
     20 *
     21 * This program is distributed in the hope that it will be useful,
     22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     24 * GNU General Public License for more details.
     25 *
     26 * You should have received a copy of the GNU General Public License
     27 * along with this program; if not, write to the Free Software
     28 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
     29 */
     30#ifndef __RTIGS_H_INCLUDED__
     31#define __RTIGS_H_INCLUDED__ 1
     32
     33typedef unsigned int    u_int32_t;
     34typedef unsigned short  u_int16_t;
     35typedef unsigned char   u_int8_t;
     36typedef unsigned char   u_char;
     37
     38#define  C                      ((double)299792458.00)          /* speed of light in vaccuum  */
     39#define  F1                     ((double)1575.42E+06)           /* GPS L1 frequency        */
     40#define  F2                     ((double)1227.60E+06)           /* GPS L2 frequency        */
     41#define  F1_SQUARE      (F1 * F1)               /* GPS L1 frequency squared   */
     42#define  F2_SQUARE      (F2 * F2)               /* GPS L2 frequency squared   */
     43#define  W1                     ((double)(C / F1))              /* GPS L1 wavelength          */
     44#define  W2                     ((double)(C / F2))              /* GPS L2 wavelength          */
     45#define  F1ION          (F2_SQUARE / (F1_SQUARE - F2_SQUARE)) /* L1 iono scale factor */
     46#define  F2ION          (F1_SQUARE / (F1_SQUARE - F2_SQUARE)) /* L2 iono scale factor */
     47#define  SF1            (F1ION + F2ION)
     48#define  SF2            (F1ION * 2)
     49#define  SF3            (F2ION * 2)
     50#define  MAXCYCLEOSL1 374               // changed to fit 83.88 metres 441 Feb. 24/2004 ~100m in cycles was 526
     51#define  MAXCYCLEOSL2 291               // changed to fit 83.88 metres 343 Feb. 24/2004 was ~100m in cycles 410
     52
     53/* RTIGSH_T Structure -> RTIGS Header structure, Used For Working Out What Sort Of Packet We Got */
     54struct RTIGSH_T
     55        {
     56        u_int16_t       rec_id;
     57        u_int16_t       sta_id;
     58        u_int32_t       GPSTime;
     59        u_int16_t       num_bytes;
     60        u_int8_t        IODS;
     61        u_int8_t        misc;
     62        };
     63
     64
     65/* RTIGSS_T Structure -> RTIGS Station structure, normally rec_id = 100 */
     66struct RTIGSS_T
     67        {
     68        u_int16_t       rec_id;
     69        u_int16_t       sta_id;
     70        u_int32_t       GPSTime;
     71        u_int16_t       num_bytes;
     72        u_int8_t        IODS;
     73        u_int8_t        sta_rec_type;
     74        u_char          IGS_UniqueID[8];
     75        };
     76
     77
     78/* RTIGSO_T Structure -> RTIGS Observation structure, normally rec_id = 200 */
     79struct RTIGSO_T
     80        {
     81        u_int16_t       rec_id;
     82        u_int16_t       sta_id;
     83        u_int32_t       GPSTime;
     84        u_int16_t       num_bytes;
     85        u_int8_t        IODS;
     86        u_int8_t        num_obs;
     87        u_char          data[12][21];
     88        };
     89
     90/* RTIGSE_T Structure -> RTIGS Ephemeris structure, normally rec_id = 300 */
     91struct RTIGSE_T
     92        {
     93        u_int16_t       rec_id;
     94        u_int16_t       sta_id;
     95        u_int32_t       GPSTime;
     96        u_int16_t       num_bytes;
     97        u_int8_t        IODS;
     98        u_int8_t        prn;
     99        u_char          data[72];
     100        };
     101
     102
     103/* RTIGSM_T Structure -> RTIGS Met structure, normally rec_id = 400 */
     104struct RTIGSM_T
     105        {
     106        u_int16_t       rec_id;
     107        u_int16_t       sta_id;
     108        u_int32_t       GPSTime;
     109        u_int16_t       num_bytes;
     110        u_int8_t        IODS;
     111        u_int8_t        num_obs;
     112        long            temp;
     113        long            press;
     114        long            humid;
     115        };
     116
     117/* The 21 Byte SOC Compressed Observation Structure per SV */
     118struct JPL_COMP_OBS_T
     119        {
     120        unsigned char prn;                      // satellite ID
     121        unsigned short epoch_sequence;  // like Ashtech seq number of phase epochs
     122                                                                        // was like this, now modulo 10 hours,
     123                                                                        // each digit is now 1 sec, not .05 secs like before
     124        unsigned char ca_range[5];                      // ca range in millimeters
     125                                                                // first 4 bits are status bits, as follows
     126                                                                // if bit 7 on, sucessful packing of ca_range
     127                                                                // if bit 6 on, Z track mode or AS is on
     128                                                                // if bit 5 on, overflow of L2_block phase
     129                                                                // if bit 4 on, overflow of L1_block phase
     130                                                                // next 36 bits are the observable
     131                                                                // 68719.476735 is the max allowable obsev.
     132                                                                // if not packed, L2_block and L1_block is
     133                                                                // just then packed with 0s
     134
     135        unsigned char CA_snr;           // receiver snr for ca  in dbHz KML the SNR is (DBHz * 4.25) rounded to an int  (max is 60.0)
     136        unsigned char L2_range_phase[5];
     137                                                                // first 2 bytes and 2 bits is for the range, next 6 bits and 2 bytes are for phase.
     138                                                                //
     139                                                                // range units are in millimeters, from -131071 to 131071   (2^17 - 1)
     140                                                                // 0000 0000 0000 0000 01 would be +1 mm
     141                                                                // 100000000000000001 would be -1 mm
     142                                                                // 0100 0000 0000 0000 00 would be  65536 mm
     143                                                                // 1100 0000 0000 0000 00 would be -65536 mm
     144                                                                // 0111 1111 1111 1111 11 would be  131071 mm
     145                                                                // 111111111111111111 woule be -131071 mm
     146                                                                // dynamic range must be <= 131.071 meters
     147                                                                //
     148                                                                // phase units are in 2/100 millimeters from -4194304 to 4194304
     149                                                                // 00 0000 0000 0000 0000 0001  would be +.02 mm
     150                                                                // 10 0000 0000 0000 0000 0001  would be -.02 mm
     151                                                                // 01 1111 1111 1111 1111 1111  ( 2097151) would be  41943.02 mm
     152                                                                // 11 1111 1111 1111 1111 1111  (-2097151) would be -41943.02 mm
     153                                                                //                              (2^21 - 1)*2 mm
     154                                                                // dynamic range must be <= 41.94302 meters
     155                                                                //
     156                                                                // note if the limits are exceded, a -0 (minus zero) is returned
     157                                                                // indicating not a number
     158                                                                //
     159                                                                // Note however, we extended this dynamic range to 83.88606 meters as
     160                                                                // below with the spare bits in the ca_range field. If this limit
     161                                                                // is exceeded we return a -0 ( minus zero )
     162        unsigned char L2_snr;           // snr for this data type  in dbHz, the SNR is (DBHz * 4.25) rounded to an int (max is 60.0 )
     163        unsigned char L1_range_phase[5];                // same as format for L2_range_phase
     164        unsigned char L1_snr;           // snr for this data type  in dbHz, the SNR is (DBHz * 4.25) rounded to an int (max is 60.0 )
     165        };
     166
     167
     168/* GPSSatellite Structure -> 44 Byte raw SV Structure */
     169struct GPSSatellite
     170        {
     171        unsigned char prn;
     172        unsigned char CASnr;
     173        unsigned char L1Snr;
     174        unsigned char L2Snr;
     175        double  CARange;
     176        double  P1Range;
     177        double  L1Phase;
     178        double  P2Range;
     179        double  L2Phase;
     180        unsigned short locktime;
     181        };
     182
     183/* GPSEpoch Structure -> raw epoch Structure */
     184struct GPSEpoch_T
     185        {
     186        unsigned int    GPSTime;
     187        unsigned short  sta_id;
     188        unsigned char   num_sv;
     189        unsigned char   padding;
     190        struct GPSSatellite sv[12];
     191        };
     192
     193struct GPSMet_T
     194        {
     195        unsigned int GPSTime;
     196        unsigned short sta_id;
     197        long temperature;
     198        long humidity;
     199        long pressure;
     200        };
     201
     202typedef struct RTIGSO_T RTIGSO;
     203typedef struct RTIGSE_T RTIGSE;
     204typedef struct RTIGSS_T RTIGSS;
     205typedef struct RTIGSM_T RTIGSM;
     206typedef struct RTIGSH_T RTIGSH;
     207typedef struct GPSEpoch_T GPSEpoch;
     208typedef struct GPSMet_T GPSMet;
     209
     210
     211/* Function Declarations */
     212extern void bytes_to_rtigsh(RTIGSH *rtigsh, unsigned char *packet);
     213extern int rtigso_to_raw(RTIGSO *rtigso, GPSEpoch *gpse);
     214extern int rtigsm_to_raw(RTIGSM *rtigsm, GPSMet *met);
     215
     216
     217void revbytes(unsigned char *buf, unsigned char size);
    19218
    20219#endif
     220
     221
  • trunk/BNC/bnc.pro

    r243 r293  
    1616          RTCM/GPSDecoder.h RTCM/RTCM2.h RTCM/RTCM2Decoder.h          \
    1717          RTCM3/rtcm3.h RTCM3/rtcm3torinex.h                          \
    18           RTIGS/rtigs.h RTIGS/cgps_transform.h RTIGS/rtacp.h          \
    19           RTIGS/rtigs_records.h  RTIGS/rtstruct.h
    20 
     18          RTIGS/rtigs.h RTIGS/RTIGSDecoder.h
    2119
    2220SOURCES = bncmain.cpp bncgetthread.cpp  bncwindow.cpp bnctabledlg.cpp \
     
    2523          RTCM/RTCM2.cpp RTCM/RTCM2Decoder.cpp                        \
    2624          RTCM3/rtcm3.cpp RTCM3/rtcm3torinex.cpp                      \
    27           RTIGS/rtigs.cpp RTIGS/cgps_transform.cpp
     25          RTIGS/rtigs.cpp RTIGS/RTIGSDecoder.cpp
    2826
    2927RC_FILE = bnc.rc
  • trunk/BNC/bncgetthread.cpp

    r280 r293  
    5252#include "RTCM/RTCM2Decoder.h"
    5353#include "RTCM3/rtcm3.h"
    54 #include "RTIGS/rtigs.h"
     54#include "RTIGS/RTIGSDecoder.h"
    5555
    5656using namespace std;
     
    241241    else if (_format.indexOf("RTIGS") != -1) {
    242242      emit(newMessage("Get Data: " + _staID + " in RTIGS format"));
    243       _decoder = new rtigs();
     243      _decoder = new RTIGSDecoder();
    244244    }
    245245    else {
Note: See TracChangeset for help on using the changeset viewer.