Changeset 59 in ntrip


Ignore:
Timestamp:
Aug 24, 2006, 2:16:23 PM (18 years ago)
Author:
mervart
Message:

* empty log message *

Location:
trunk/BNC
Files:
7 edited

Legend:

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

    r56 r59  
     1
     2/* -------------------------------------------------------------------------
     3 * Bernese 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 * -----------------------------------------------------------------------*/
     17
    118#include "rtigs.h"
    219
    3 #define MAXSTREAM 10000
     20using namespace std;
    421
     22// Constructor
    523////////////////////////////////////////////////////////////////////////////
    6 void SwitchBytes( char *Start, int Size ) {
    7   char Tmp;
    8   char *End = Start + Size - 1;
    9   for( Tmp = *Start; Start < End; Tmp = *Start ){
    10     *Start++ = *End;
    11     *End-- = Tmp;
    12   }
     24rtigs::rtigs() : GPSDecoder() {
    1325}
    1426
    15 int main() {
     27// Destructor
     28////////////////////////////////////////////////////////////////////////////
     29rtigs::~rtigs() {
     30}
    1631
    17   unsigned char  data_stream[MAXSTREAM];
    18   unsigned short numbytes;
     32//
     33////////////////////////////////////////////////////////////////////////////
     34void rtigs::Decode(char* buffer, int bufLen) {
     35
    1936  RTIGSS_T       rtigs_sta;
    2037  RTIGSO_T       rtigs_obs;
     
    2542  unsigned short statID;
    2643  unsigned short messType;
    27   CGPS_Transform GPSTrans;
    2844
    29   memset(data_stream , 0, sizeof(data_stream));
    30 
    31   // use something like recvfrom
    32   FILE* inpFile = fopen("RTIGS.txt", "rb");
    33 
    34   while (true) {
    35     size_t nr = 0;
    36    if (inpFile) {
    37      nr = fread(data_stream, sizeof(unsigned char), MAXSTREAM, inpFile);
    38      if (nr == 0) exit(0);
    39      cout << "Number of bytes read: " << nr << endl;
    40    }
    41    else {
    42      exit(1);
    43    }
    44  
    45    // Find the beginning of the message
    46    // ---------------------------------
    47    size_t sz = sizeof(unsigned short);
    48    bool   found = false;
    49    size_t ii;
    50    for (ii = 0; ii < nr - sz; ii += sz) {
    51      unsigned short xx;
    52      memcpy( (void*) &xx, &data_stream[ii], sz);
    53      SwitchBytes( (char*) &xx, sz);
    54      if (xx == 200) {
    55        found = true;
    56        break;
    57      }
    58    }
    59    if (! found) {
    60      cout << "Message not found\n";
    61      exit(0);
    62    }
    63    else {
    64      cout << "Message found at " << ii << endl;
    65    }
    66 
    67 
    68    messType = GPSTrans.GetRTIGSHdrRecType(&data_stream[ii]);
    69    numbytes = GPSTrans.GetRTIGSHdrRecBytes(&data_stream[ii]);
    70    statID   = GPSTrans.GetRTIGSHdrStaID(&data_stream[ii]);
    71 
    72    cout << "messType " << messType << endl;
    73    cout << "numbytes " << numbytes << endl;
    74    cout << "statID "   << statID   << endl;
    75 
    76    switch (messType) {
    77    case 100:
    78      GPSTrans.Decode_RTIGS_Sta(&data_stream[ii], numbytes , rtigs_sta);
    79      break;
    80    case 200:
    81      retval = GPSTrans.Decode_RTIGS_Obs(&data_stream[ii], numbytes , rtigs_obs);
    82      if (retval >= 1) {
    83        GPSTrans.print_CMEAS();
    84      }
    85      break;
    86    case 300:
    87      retval = GPSTrans.Decode_RTIGS_Eph(&data_stream[ii], numbytes , rtigs_eph, PRN);
    88      break;
    89    case 400:
    90      retval = GPSTrans.Decode_RTIGS_Met(&data_stream[ii], numbytes , &rtigs_met);
    91      break;
    92    }
     45  // Find the beginning of the message
     46  // ---------------------------------
     47  size_t sz = sizeof(unsigned short);
     48  bool   found = false;
     49  size_t ii;
     50  for (ii = 0; ii < nr - sz; ii += sz) {
     51    unsigned short xx;
     52    memcpy( (void*) &xx, &buffer[ii], sz);
     53    SwitchBytes( (char*) &xx, sz);
     54    if (xx == 200) {
     55      found = true;
     56      break;
     57    }
     58  }
     59  if (! found) {
     60    cout << "Message not found\n";
     61    return;
     62  }
     63  else {
     64    cout << "Message found at " << ii << endl;
    9365  }
    9466
    95   return 0;
    96 }
     67  messType = _GPSTrans.GetRTIGSHdrRecType(&buffer[ii]);
     68  numbytes = _GPSTrans.GetRTIGSHdrRecBytes(&buffer[ii]);
     69  statID   = _GPSTrans.GetRTIGSHdrStaID(&buffer[ii]);
    9770
    98 // Constructor
    99 ////////////////////////////////////////////////////////////////////////////
    100 CGPS_Transform::CGPS_Transform() {
     71  cout << "messType " << messType << endl;
     72  cout << "numbytes " << numbytes << endl;
     73  cout << "statID "   << statID   << endl;
    10174
    102   // Decoded Obs Array of 12 CMeas Observation Records
    103   memset((void *)&DecObs, 0, sizeof(ARR_OBS_T     ));
    104 
    105   // Keplarian Broadcast Eph
    106   memset((void *)&TNAV_Eph,0, sizeof(ARR_TNAV_T   ));
    107 
    108   NumObsRead = -1;
    109   CAFlag = -1;
    110   ASFlag = -1;
    111   P2Flag = -1;
    112   P1Flag = -1;
    113   InitEndianFlag();
    114 
    115   memset (PhaseArcStartTime, 0, sizeof(PhaseArcStartTime));
    116 }
    117 
    118 // Destructor
    119 ////////////////////////////////////////////////////////////////////////////
    120 CGPS_Transform::~CGPS_Transform() {
    121 }
    122 
    123 //
    124 ////////////////////////////////////////////////////////////////////////////
    125 unsigned short CGPS_Transform::GetRTIGSHdrRecType(unsigned char *RTIGS_Str)
    126 {
    127         unsigned short recordID;
    128         memcpy ((void *)&recordID,RTIGS_Str, sizeof(recordID));
    129         if (f_IsLittleEndian)
    130         {
    131                 SwitchBytes( (char *)&recordID, sizeof(recordID) );
    132         }
    133         return recordID;
    134 }
    135 
    136 //
    137 ////////////////////////////////////////////////////////////////////////////
    138 unsigned short CGPS_Transform::GetRTIGSHdrRecBytes(unsigned char *RTIGS_Str)
    139 {
    140         unsigned short bytes;
    141         memcpy ((void *)&bytes,&RTIGS_Str[8], sizeof(bytes));
    142         if (f_IsLittleEndian)
    143         {
    144                 SwitchBytes( (char *)&bytes, sizeof(bytes) );
    145         }
    146         return bytes;
    147 
    148 }
    149 
    150 //
    151 ////////////////////////////////////////////////////////////////////////////
    152 unsigned short CGPS_Transform::GetRTIGSHdrStaID(unsigned char *RTIGS_Str)
    153 {
    154         unsigned short StaID = 0;
    155         memcpy ((void *)&StaID, &RTIGS_Str[2], sizeof(StaID));
    156         if (f_IsLittleEndian)
    157         {
    158                 SwitchBytes( (char *)&StaID, sizeof(StaID) );
    159         }
    160         return StaID;
    161 }
    162 
    163 
    164 //
    165 ////////////////////////////////////////////////////////////////////////////
    166 void CGPS_Transform::InitEndianFlag() {
    167   short one = 1;
    168   char *cp = (char *)&one;
    169   if (*cp== 0) {
    170     f_IsLittleEndian = false;
    171   }
    172   else {
    173     f_IsLittleEndian = true;
     75  switch (messType) {
     76  case 100:
     77    _GPSTrans.Decode_RTIGS_Sta(&buffer[ii], numbytes , rtigs_sta);
     78    break;
     79  case 200:
     80    retval = _GPSTrans.Decode_RTIGS_Obs(&buffer[ii], numbytes , rtigs_obs);
     81    if (retval >= 1) {
     82      _GPSTrans.print_CMEAS();
     83    }
     84    break;
     85  case 300:
     86    retval = _GPSTrans.Decode_RTIGS_Eph(&buffer[ii], numbytes , rtigs_eph, PRN);
     87    break;
     88  case 400:
     89    retval = _GPSTrans.Decode_RTIGS_Met(&buffer[ii], numbytes , &rtigs_met);
     90    break;
    17491  }
    17592}
    176 
    177 
    178 //
    179 ////////////////////////////////////////////////////////////////////////////
    180 unsigned long  CGPS_Transform::JPL_xtractLongVal (unsigned startBitNbr, unsigned xtractNbrBits, const char *msg)
    181 {
    182   unsigned long    retValue=0, i=0;
    183 
    184   unsigned short posBit     = xtractNbrBits - 1;
    185 
    186   for(i=0; i<xtractNbrBits; i++, startBitNbr++)
    187     {
    188     unsigned short numShift   = 7 - (startBitNbr % 8);
    189     unsigned short byteNbr    = startBitNbr / 8;
    190     retValue     |= (((msg[byteNbr] >> numShift) & 0x0001) << posBit--);
    191 
    192     }
    193 
    194   return retValue;
    195 }
    196 
    197 //
    198 ////////////////////////////////////////////////////////////////////////////
    199 inline void   CGPS_Transform::SwitchIGS_Sta_HdrBytes( RTIGSS_T *StaHdr)
    200 {
    201   SwitchBytes( (char *)&StaHdr->GPSTime, sizeof(unsigned long) );
    202   SwitchBytes( (char *)&StaHdr->num_bytes, sizeof(unsigned short) );
    203   SwitchBytes( (char *)&StaHdr->rec_id, sizeof(unsigned short) );
    204   SwitchBytes( (char *)&StaHdr->sta_id, sizeof(unsigned short) );
    205 }
    206 
    207 //
    208 ////////////////////////////////////////////////////////////////////////////
    209 inline void  CGPS_Transform::SwitchIGS_Obs_HdrBytes( RTIGSO_T *ObsHdr)
    210 {
    211   SwitchBytes( (char *)&ObsHdr->GPSTime, sizeof(unsigned long) );
    212   SwitchBytes( (char *)&ObsHdr->num_bytes, sizeof(unsigned short) );
    213   SwitchBytes( (char *)&ObsHdr->rec_id, sizeof(unsigned short) );       
    214   SwitchBytes( (char *)&ObsHdr->sta_id, sizeof(unsigned short) );
    215 }
    216 
    217 //
    218 ////////////////////////////////////////////////////////////////////////////
    219 inline void  CGPS_Transform::SwitchIGS_Eph_HdrBytes( RTIGSE_T *EphHdr)
    220 
    221 {
    222   SwitchBytes( (char *)&EphHdr->CollectedGPSTime, sizeof(unsigned long) );
    223   SwitchBytes( (char *)&EphHdr->num_bytes, sizeof(unsigned short) );
    224   SwitchBytes( (char *)&EphHdr->rec_id, sizeof(unsigned short) );
    225   SwitchBytes( (char *)&EphHdr->sta_id, sizeof(unsigned short) );
    226 }
    227 
    228 //
    229 ////////////////////////////////////////////////////////////////////////////
    230 inline short  CGPS_Transform::SwitchIGS_Met_RecBytes( RTIGSM_T *MetHdr)
    231 {
    232 short retval = 1;
    233 short i, num_items;
    234   num_items = (short)MetHdr->numobs;
    235   SwitchBytes( (char *)&MetHdr->GPSTime, sizeof(unsigned long) );
    236   SwitchBytes( (char *)&MetHdr->num_bytes, sizeof(unsigned short) );
    237   SwitchBytes( (char *)&MetHdr->rec_id, sizeof(unsigned short) );
    238   SwitchBytes( (char *)&MetHdr->sta_id, sizeof(unsigned short) );
    239 
    240     /*switch met data bytes*/       
    241   for (i=0; i < num_items; i++)
    242   {
    243     if (&MetHdr->mets[i] != NULL)
    244     {
    245       SwitchBytes( (char *)&MetHdr->mets[i], sizeof(long) );
    246     }
    247     else
    248     {
    249       retval = -1;
    250     }
    251 
    252   }
    253 return retval;
    254 }
    255 //
    256 ////////////////////////////////////////////////////////////////////////////
    257 
    258 short CGPS_Transform::Save_TNAV_T_To_Container(TNAV_T *rtcurrent_eph, short &prn)
    259 {
    260 short retval = 1;//, i;
    261 long PRN;
    262 
    263   PRN = rtcurrent_eph->Satellite;
    264 
    265   if (f_IsLittleEndian)
    266   {       
    267     SwitchBytes( (char *)&PRN, sizeof(PRN));
    268   }
    269 
    270   if ((PRN > 0) && (PRN <= 32))
    271   {
    272     memcpy( (void *)&TNAV_Eph.Eph[(PRN-1)]  ,rtcurrent_eph,sizeof(TNAV_T));
    273     prn = (short)PRN;
    274   }
    275   else
    276   {
    277     retval = -1;
    278   }
    279 return retval;
    280 }
    281 
    282 //
    283 ////////////////////////////////////////////////////////////////////////////
    284 short CGPS_Transform::CA_Extract(char * CAStr, double &CA_Rng)
    285 {
    286 
    287 
    288 unsigned long CARng2, CARng1;
    289 short retval = 0;
    290 double dtemp;
    291 
    292 
    293   CGPS_Transform::CAFlag = JPL_xtractLongVal(0, 1,  CAStr);       
    294   CGPS_Transform::ASFlag = JPL_xtractLongVal(1, 1,  CAStr);       
    295   CGPS_Transform::P2Flag = JPL_xtractLongVal(2, 1,  CAStr);       
    296   CGPS_Transform::P1Flag = JPL_xtractLongVal(3, 1,  CAStr);
    297 
    298   if (CAFlag)
    299   {
    300       //Read most significant bits 
    301     CARng2 = JPL_xtractLongVal(4, 4,  CAStr);   
    302       //Read an int's worth of data
    303     CARng1 = JPL_xtractLongVal (8,32,CAStr);
    304 //  if (f_IsLittleEndian == false)
    305 //  {
    306       //KML June 8/2004
    307       //Added this code to deal with Big Endian architectures     
    308 //    SwitchBytes( (char *) &CARng2, sizeof(CARng2) );
    309 //    SwitchBytes( (char *) &CARng1, sizeof(CARng1) );
    310 //  }
    311 
    312     dtemp = 0.0;
    313     dtemp = CARng2;
    314 
    315     CA_Rng = dtemp*pow ((double)2,32);
    316     CA_Rng +=       CARng1;
    317 
    318     CA_Rng /= 1000;   //CA in metres
    319   }
    320   else
    321   {
    322     retval = -1;
    323   }
    324 return retval;
    325 }
    326 
    327 //
    328 ////////////////////////////////////////////////////////////////////////////
    329 short CGPS_Transform::P1_P2_Block_Extract(char * P1P2Str, double CA, double &Rng , double &Phase, double &RngF2Delta,short decode_F1orF2Flag )
    330 {
    331 short retval =0;
    332 short PhaseOverFlowFlag;
    333 long SignFlag,temp;
    334 
    335 double RngDelta, PhaseDelta;
    336 
    337   if (decode_F1orF2Flag == 1)
    338   {
    339     PhaseOverFlowFlag = CGPS_Transform::P1Flag;
    340   }
    341   else if (decode_F1orF2Flag == 2)
    342   {
    343     PhaseOverFlowFlag = CGPS_Transform::P2Flag;
    344   }
    345     //*****************************
    346     // Decode Pseudo Range
    347     //*****************************
    348   SignFlag = JPL_xtractLongVal (0,1,P1P2Str);
    349   temp = JPL_xtractLongVal (1,17,P1P2Str);
    350 
    351 //KML June 8/2004
    352 //      if (f_IsLittleEndian == false)
    353 //      {
    354   //Added this code to deal with Big Endian architectures
    355 //  SwitchBytes( (char *) &temp, sizeof(temp) );
    356 //      }
    357 
    358 
    359   RngDelta = temp;
    360   RngDelta /= 1000.0;
    361 
    362 
    363   if (SignFlag)
    364   {
    365     RngDelta *= -1;       
    366   }
    367 
    368 
    369   if (decode_F1orF2Flag == 2)
    370   {
    371     RngF2Delta = RngDelta;
    372   }
    373 
    374   Rng = CA +  RngDelta;
    375 
    376     //***************************
    377     // Decode Phase
    378     //***************************
    379 
    380   SignFlag = JPL_xtractLongVal (18,1, P1P2Str);
    381   temp = JPL_xtractLongVal (19,21, P1P2Str);
    382 //      if (f_IsLittleEndian == false)
    383 //      {
    384 
    385   //KML June 8th 2004
    386   //Added this code to deal with Big Endian architectures
    387 //  SwitchBytes( (char *) &temp, sizeof(temp) );
    388 //      }
    389 
    390   PhaseDelta =    temp;
    391 
    392   PhaseDelta =    PhaseDelta * 2 / 100000;
    393 
    394 
    395 
    396 
    397     //Phase overflow add to phase
    398   if(PhaseOverFlowFlag)
    399   {
    400     PhaseDelta += MAXL1L2;
    401   }
    402 
    403   if (SignFlag)
    404   {
    405     PhaseDelta *= -1;       
    406   }
    407 
    408   if (decode_F1orF2Flag == 1)
    409   {
    410     // frequency 1
    411     Phase = (CA - (ScaleFactor2*RngF2Delta)+ PhaseDelta) / L1;
    412   }
    413   else if (decode_F1orF2Flag == 2)
    414   {
    415     // frequency 2     
    416     Phase = (CA - (ScaleFactor1*RngF2Delta)+ PhaseDelta) / L2;
    417   }
    418   else
    419   {
    420     retval =-1;
    421   }
    422 return retval;
    423 }
    424 
    425 //
    426 ////////////////////////////////////////////////////////////////////////////
    427 short CGPS_Transform::Decode_RTIGS_Sta(unsigned char *RTIGS_Str,  unsigned short RTIGS_Bytes, RTIGSS_T &rtigs_sta)
    428 {
    429 short retval = 1;
    430   memcpy ((void *)&rtigs_sta.rec_id, &RTIGS_Str[0], (sizeof(RTIGSS_T) - sizeof(rtigs_sta.data)));
    431   if (f_IsLittleEndian)
    432   {
    433     SwitchIGS_Sta_HdrBytes( &rtigs_sta);
    434   }
    435   if (rtigs_sta.rec_id == 100)
    436   {
    437     if (rtigs_sta.sta_rec_type ==0 )
    438     {
    439       rtigs_sta.data = NULL;     
    440     }
    441     else
    442     {
    443       retval = -2;    //no other type supported at this time
    444     }
    445   }
    446 
    447 
    448   else
    449   {
    450 
    451 
    452     retval = -1;
    453 
    454   }
    455 
    456 return retval ;
    457 }
    458 
    459 //
    460 ////////////////////////////////////////////////////////////////////////////
    461 short CGPS_Transform::Decode_RTIGS_Soc_Obs(unsigned char *SocStr,  short &StrPos, short CMeasIndex, short SocBytes, unsigned long GPSTime)
    462 {
    463 short retval =1;
    464 double CA,  RngF2Delta,  PhaseL1,PhaseL2, P1, P2;
    465 //static unsigned short PhaseArcStartTime[MAXSV]; moved to class header
    466 JPL_COMP_OBS_T GPSObs;
    467 //printf("String pos %hd Total Bytes %hd\n", StrPos,SocBytes);
    468 
    469   if ((StrPos <= SocBytes) && ((CMeasIndex >= 0 ) &&  (CMeasIndex < MAXSV )))
    470   {
    471    
    472     memcpy((void *)&GPSObs.prn, (void *)&SocStr[StrPos], 1);
    473 
    474     if ((GPSObs.prn > 0 ) && (GPSObs.prn <= 32))
    475     {
    476       StrPos+=1;
    477 
    478       memcpy((void *)&GPSObs.epoch_sequence, (void *)&SocStr[StrPos],2);
    479 
    480       if (f_IsLittleEndian == false)
    481       {
    482   //KML June 8/2003
    483   //Added this code to deal with Big Endian architectures
    484   SwitchBytes( (char *) &GPSObs.epoch_sequence, sizeof(GPSObs.epoch_sequence) );
    485       }
    486 
    487     //******************************
    488     // Read and decode CA
    489     //******************************
    490       StrPos+=2;
    491       memcpy((void *)&GPSObs.ca_range, (void *)&SocStr[StrPos],5);
    492       CA_Extract(GPSObs.ca_range, CA);
    493 
    494       if (CGPS_Transform::CAFlag)       //Defined in the Class by CA_Extract
    495       {
    496     //************************************
    497     // Read CA SNR
    498     //************************************
    499   StrPos+=5;
    500   memcpy((void *)&GPSObs.CA_snr, (void *)&SocStr[StrPos],1);
    501     //************************************
    502     // Read and decode P2 L2
    503     //************************************
    504   StrPos+=1;
    505   memcpy((void *)&GPSObs.L2_range_phase, (void *)&SocStr[StrPos],5);
    506 
    507   P1_P2_Block_Extract(GPSObs.L2_range_phase,  CA, P2 , PhaseL2, RngF2Delta, 2 );
    508 
    509 
    510   StrPos+=5;
    511   memcpy((void *)&GPSObs.L2_snr, (void *)&SocStr[StrPos],1);
    512       //************************************
    513       // Read and decode P1 L1
    514       //************************************
    515   StrPos+=1;
    516 
    517 
    518   memcpy((void *)&GPSObs.L1_range_phase, (void *)&SocStr[StrPos],5);
    519 
    520   P1_P2_Block_Extract(GPSObs.L1_range_phase, CA, P1, PhaseL1, RngF2Delta, 1);
    521 
    522   StrPos+=5;
    523   memcpy((void *)&GPSObs.L1_snr, (void *)&SocStr[StrPos],1);
    524   StrPos+=1;
    525 
    526   DecObs.Obs[CMeasIndex].GPSTime = GPSTime;    /* broadcast time sec.*/
    527   DecObs.Obs[CMeasIndex].chn = CMeasIndex + 1; /* Channel not real*/
    528   DecObs.Obs[CMeasIndex].sat_prn = GPSObs.prn; /* satellite ID*/
    529   DecObs.Obs[CMeasIndex].ntrvl = 1;      /* number of seconds Changed from 0 to 1 Nov. 25/2003*/
    530   DecObs.Obs[CMeasIndex].flag[0] = 4;    /*observation quality flags*/   //KML Changed Nov. 25/2000 to 4 to indicate Benchmark
    531 
    532   if (PhaseArcStartTime[(short)(GPSObs.prn-1)] !=  GPSObs.epoch_sequence)
    533   {
    534     PhaseArcStartTime[(short)(GPSObs.prn-1)] =  GPSObs.epoch_sequence;
    535     DecObs.Obs[CMeasIndex].flag[0] |= 0x20;
    536   }
    537 
    538   DecObs.Obs[CMeasIndex].l1_pseudo_range = CA;      /* frequency-1 CA pseudorange */
    539   DecObs.Obs[CMeasIndex].l1_phase = PhaseL1;      /* frequency-1 CA carrier phase   */
    540       //****************************************************
    541       // Changed SNR Ashtech to DBHz Nov 15/2002
    542       //****************************************************
    543   DecObs.Obs[CMeasIndex].l1_sn  =  GPSObs.CA_snr;
    544 
    545   DecObs.Obs[CMeasIndex].p1_pseudo_range = P1;  /* frequency-1 P1 carrier phase   */
    546   DecObs.Obs[CMeasIndex].p1_phase  =  PhaseL1;    /* frequency-1 P1 pseudorange */
    547 
    548   DecObs.Obs[CMeasIndex].p1_sn = GPSObs.L1_snr;
    549 
    550   DecObs.Obs[CMeasIndex].l2_pseudo_range = P2;    /* frequency-2 pseudorange (XCorr) */
    551   DecObs.Obs[CMeasIndex].l2_phase = PhaseL2;  /* frequency-2 carrier phase (XCorr)  */
    552 
    553   DecObs.Obs[CMeasIndex].l2_sn = GPSObs.L2_snr;
    554   DecObs.Obs[CMeasIndex].p2_pseudo_range  = P2;       /* frequency-2 pseudorange     */
    555   DecObs.Obs[CMeasIndex].p2_phase = PhaseL2;      /* frequency-2 carrier phase   */
    556       }
    557       else
    558       {
    559       //skip this obs
    560   DecObs.Obs[CMeasIndex].sat_prn = 0;
    561       }
    562     }
    563     else
    564     {
    565       retval = -2;
    566 
    567     }
    568   }
    569   else
    570   {
    571     retval = -1;
    572   }
    573 return retval;
    574 }
    575 
    576 //
    577 ////////////////////////////////////////////////////////////////////////////
    578 short CGPS_Transform::RTIGSO_Str_To_CMEAS(unsigned char *RTIGSO_Str, short RTIGS_Bytes, RTIGSO_T &rtigs_obs)
    579 {
    580 short retval =1,i, StrPos;//, HdrRetval;
    581 //short  NumObs= 0;
    582 short decoded_cnt = 0;
    583 short  IGSObsMinusPtr;
    584 
    585 
    586   //************************************
    587   // Zero out CMEAS_T container
    588   //************************************
    589 memset((void *)&DecObs.Obs[0], 0 , sizeof(ARR_OBS_T) );
    590 
    591     //***********************************************
    592     // Decode Header store in class container
    593     //***********************************************
    594 
    595 
    596   StrPos = IGSObsMinusPtr = sizeof(RTIGSO_T) - sizeof (rtigs_obs.data);
    597 
    598   cout << "StrPos " << StrPos << endl;
    599 
    600   memcpy ((void *)&rtigs_obs.rec_id, RTIGSO_Str, IGSObsMinusPtr);
    601 
    602   if (f_IsLittleEndian)
    603   {
    604     SwitchIGS_Obs_HdrBytes( &rtigs_obs);
    605   }
    606 
    607 
    608   // printf("RecNumber : %hd Station ID %hd Num Obs %hd NumBytes %hd\n",rtigs_obs.rec_id, rtigs_obs.sta_id, rtigs_obs.num_obs, rtigs_obs.num_bytes);
    609 
    610   if((rtigs_obs.rec_id == 200) && (rtigs_obs.num_obs <= MAXCHANNELS_FOR_SOCKETS_TYPE1))
    611   {
    612     for (i = 0 ; i < rtigs_obs.num_obs;i++)
    613     {
    614     //*********************************************
    615     // the following function decodes the soc
    616     // structure and writes the obs to the
    617     // class's CMEAS container
    618     //*********************************************
    619 
    620       if (Decode_RTIGS_Soc_Obs( RTIGSO_Str, StrPos, decoded_cnt, RTIGS_Bytes, rtigs_obs.GPSTime) < 0)
    621       {
    622     retval = -2;
    623       }
    624       else
    625       {
    626   decoded_cnt ++;
    627       }
    628     }//end of for
    629     retval = NumObsRead = decoded_cnt; //NumObsRead class member
    630   }
    631   else
    632   {
    633     retval = -1;
    634   }
    635 //ObsSeqNum++;
    636 return retval;
    637 }
    638 
    639 
    640 //
    641 ////////////////////////////////////////////////////////////////////////////
    642 short CGPS_Transform::Decode_RTIGS_Obs(unsigned char *RTIGSO_Str,  unsigned short RTIGS_Bytes,RTIGSO_T &rtigs_obs)
    643 {
    644   short retval = 1;//, i;
    645 
    646 
    647   if ((retval = RTIGSO_Str_To_CMEAS(RTIGSO_Str, RTIGS_Bytes, rtigs_obs)) < 0)
    648   {
    649     retval = -1;
    650   }
    651 
    652 return retval;
    653 }
    654 
    655 //
    656 ////////////////////////////////////////////////////////////////////////////
    657 short  CGPS_Transform::Decode_RTIGS_Met(unsigned char *RTIGS_Str,  unsigned short RTIGS_Bytes, RTIGSM_T *rtigs_met)
    658 {
    659 short retval = 1;
    660 short numbytes = 0;
    661 numbytes = sizeof(RTIGSM_T) -  sizeof(rtigs_met->mets);
    662 memcpy ((void *)rtigs_met, RTIGS_Str, numbytes);
    663 
    664     if ((short)rtigs_met->numobs <= 3)
    665   {
    666     if (rtigs_met->mets != NULL)
    667     {
    668       memcpy ((void *)&rtigs_met->mets[0], &RTIGS_Str[numbytes], ((short)rtigs_met->numobs * sizeof(long)) );
    669       if (f_IsLittleEndian)
    670       {
    671   SwitchIGS_Met_RecBytes( rtigs_met);
    672       }
    673       if (rtigs_met->rec_id != 400)
    674       {
    675   retval = -1;
    676       }
    677     }
    678     else
    679     {
    680       retval = -2;
    681       delete [] rtigs_met->mets;
    682     }
    683   }
    684   else
    685   {
    686     printf("failed number of Obs\n");
    687   }
    688 
    689 return retval;
    690 }
    691 
    692 //
    693 ////////////////////////////////////////////////////////////////////////////
    694 short CGPS_Transform::Decode_RTIGS_Eph(unsigned char *RTIGS_Str,  unsigned short RTIGS_Bytes, RTIGSE_T &rtigs_eph, short &PRN)
    695 {
    696   short retval = 1;//, i;
    697   short  index = 0;
    698   short prn;
    699   const short SubFrameSize = 24;
    700   TNAV_T trans_eph;
    701   index = sizeof(RTIGSE_T ) - sizeof (rtigs_eph.data);
    702 
    703   memcpy ((void *)&rtigs_eph.rec_id, &RTIGS_Str[0], index);       //copy header into struct from string
    704   if (f_IsLittleEndian)
    705   {
    706     SwitchIGS_Eph_HdrBytes( &rtigs_eph);
    707   }
    708 
    709   if (rtigs_eph.rec_id == 300)
    710   {
    711     //*********************************************
    712     // the following method saves the eph
    713     // in the class's TNAV_T container
    714     //*********************************************
    715     trans_eph.GPSCollectedTime =    rtigs_eph.CollectedGPSTime;
    716     trans_eph. Satellite = (long)rtigs_eph.prn;
    717     //********************************************
    718     // Container class is in network byte order
    719     //********************************************
    720     if (f_IsLittleEndian)
    721     {
    722       SwitchBytes( (char *)&trans_eph.GPSCollectedTime, sizeof(trans_eph.GPSCollectedTime) );
    723       SwitchBytes( (char *)&trans_eph. Satellite, sizeof(trans_eph. Satellite) );
    724     }
    725 
    726     memcpy((void *)&trans_eph.SubFrame1, (const void *)&RTIGS_Str[index], SubFrameSize);
    727     memcpy((void *)&trans_eph.SubFrame2, (const void *)&RTIGS_Str[(index + SubFrameSize)], SubFrameSize);
    728     memcpy((void *)&trans_eph.SubFrame3, (const void *)&RTIGS_Str[(index + (SubFrameSize * 2)) ], SubFrameSize);
    729     if (Save_TNAV_T_To_Container(&trans_eph, prn) >= 1)       //function saves eph in container and returns prn
    730     {
    731   PRN = prn;
    732     }
    733     else
    734     {
    735       retval = -1;
    736     }
    737   }
    738   else
    739   {
    740     retval = -1;
    741   }
    742 
    743 return retval;
    744 }
    745 
    746 void CGPS_Transform::print_CMEAS()
    747 {
    748 short i;
    749         printf("\nGPSTime   SV    CA      SNR     P1      SNR     P2      SNR\n");
    750         printf("Seconds         (m)     DBHz    (m)     DBHz    (m)     DBHz\n");
    751         for (i=0; i < NumObsRead ; i++)
    752         {
    753                 printf("%ld %2hd %10.1lf %4.1f %10.1lf %4.1f %10.1lf %4.1f \n",DecObs.Obs[i].GPSTime, DecObs.Obs[i].sat_prn,
    754                                                                                 DecObs.Obs[i].l1_pseudo_range,DecObs.Obs[i].l1_sn,
    755                                                                                 DecObs.Obs[i].p1_pseudo_range, DecObs.Obs[i].p1_sn,
    756                                                                                 DecObs.Obs[i].l2_pseudo_range,DecObs.Obs[i].l2_sn);
    757         }
    758 }
    759 
  • trunk/BNC/RTIGS/rtigs.h

    r55 r59  
    11
    2 #ifndef CGPS_TRANSFORM_H
    3 #define CGPS_TRANSFORM_H
     2#ifndef RTIGS_H
     3#define RTIGS_H
    44
    5 #include <string.h>
    6 #include <stdio.h>
    7 #include <math.h>
    8 #include <sys/time.h>
    9 #include <iostream>
     5#include "../RTCM/GPSDecoder.h"
     6#include "cgps_transform.h"
    107
    11 using namespace std;
    12 
    13 #include "rtacp.h"
    14 #include "rtstruct.h"
    15 #include "rtigs_records.h"
    16 
    17 #define MAXCHANNELS_FOR_SOCKETS_TYPE1 12
    18 #define MAXSV        32
    19 #define ScaleFactor1 4.0914555603263203   //(f1ion + f2ion)
    20 #define ScaleFactor2 2 * F1ION
    21 #define MAXL1L2      41.94302
    22 
    23 void SwitchBytes( char *Start, int Size );
    24 
    25 typedef struct
    26 {
    27     unsigned char prn;       // satellite ID
    28     unsigned short epoch_sequence; // like Ashtech seq number of phase epochs
    29         // was like this, now modulo 10 hours,
    30         // each digit is now 1 sec, not .05 secs like before
    31 
    32     char ca_range[5];    // ca range in millimeters
    33         // first 4 bits are status bits, as follows
    34         // if bit 7 on, sucessful packing of ca_range
    35         // if bit 6 on, Z track mode or AS is on
    36         // if bit 5 on, overflow of L2_block phase
    37         // if bit 4 on, overflow of L1_block phase
    38         // next 36 bits are the observable
    39         // 68719.476735 is the max allowable obsev.
    40         // if not packed, L2_block and L1_block is
    41         // just then packed with 0s
    42 
    43     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)
    44 
    45     char L2_range_phase[5];
    46         // first 2 bytes and 2 bits is for the range, next 6 bits and 2 bytes are for phase.
    47         //
    48         // range units are in millimeters, from -131071 to 131071  (2^17 - 1)
    49         // 0000 0000 0000 0000 01 would be +1 mm
    50         // 1000 0000 0000 0000 01 would be -1 mm
    51         // 0100 0000 0000 0000 00 would be 65536 mm
    52         // 1100 0000 0000 0000 00 would be -65536 mm
    53         // 0111 1111 1111 1111 11 would be 131071 mm
    54         // 1111 1111 1111 1111 11 woule be -131071 mm
    55         // dynamic range must be <= 131.071 meters
    56         //
    57         // phase units are in 2/100 millimeters from -4194304 to 4194304
    58         // 00 0000 0000 0000 0000 0001 would be +.02 mm
    59         // 10 0000 0000 0000 0000 0001 would be -.02 mm
    60         // 01 1111 1111 1111 1111 1111 ( 2097151) would be 41943.02 mm
    61         // 11 1111 1111 1111 1111 1111 (-2097151) would be -41943.02 mm
    62         //   (2^21 - 1)*2 mm
    63         // dynamic range must be <= 41.94302 meters
    64         //
    65         // note if the limits are exceded, a -0 (minus zero) is returned
    66         // indicating not a number
    67         //
    68         // Note however, we extended this dynamic range to 83.88606 meters as
    69         // below with the spare bits in the ca_range field. If this limit
    70         // is exceeded we return a -0 ( minus zero )
    71     unsigned char L2_snr;  // snr for this data type in dbHz KML the SNR is (DBHz * 4.25) rounded to an int (max is 60.0 )
    72 
    73     char L1_range_phase[5]; // same as format for L2_range_phase
    74 
    75     unsigned char L1_snr;  // snr for this data type in dbHz KML the SNR is (DBHz * 4.25) rounded to an int (max is 60.0 )
    76 
    77 } JPL_COMP_OBS_T;
    78 
    79 typedef struct
    80 {
    81    TNAV_T   Eph[MAXSV];      //32 prns
    82 } ARR_TNAV_T;
    83 
    84 typedef struct {
    85    CMEAS_T  Obs[MAXSV];   //32 obs
    86 } ARR_OBS_T ;
    87 
    88 class CGPS_Transform {
     8class rtigs : public GPSDecoder {
     9public:
     10  rtigs();
     11  ~rtigs();
     12  void Decode(char* buffer = 0, int bufLen = 0);
    8913private:
    90   ARR_OBS_T     DecObs;
    91   ARR_TNAV_T    TNAV_Eph;
    92   short         NumObsRead;
    93   short         CAFlag;
    94   short          ASFlag;
    95   short          P2Flag;
    96   short          P1Flag;
    97   bool           f_IsLittleEndian;
    98   unsigned short PhaseArcStartTime[MAXSV];
    99 public:
    100   CGPS_Transform();
    101   ~CGPS_Transform();
    102   void           InitEndianFlag();
    103   short          Decode_Soc_Obs(unsigned char  *SocStr, short &StrIndex, short index, short SocBytes);
    104   short          Decode_RTIGS_Soc_Obs(unsigned char *SocStr,  short &StrPos, short CMeasIndex, short SocBytes, unsigned long GPSTime);
    105   short          RTIGSO_Str_To_CMEAS(unsigned char *RTIGSO_Str, short RTIGS_Bytes, RTIGSO_T &rtigs_obs); //done needs testing KML
    106   void           print_CMEAS();
    107   short          Save_TNAV_T_To_Container(TNAV_T *rtcurrent_eph, short &prn);
    108   short          CA_Extract(char * CAStr, double &CA_Rng);                 //done
    109   short          P1_P2_Block_Extract(char * P1P2Str, double CA, double &Rng , double &Phase, double &RngF2Delta,short decode_F1orF2Flag );//done
    110   unsigned long  JPL_xtractLongVal (unsigned startBitNbr, unsigned xtractNbrBits, const char *msg);        //done
    111   inline void    SwitchIGS_Sta_HdrBytes( RTIGSS_T *StaHdr);
    112   inline void    SwitchIGS_Obs_HdrBytes( RTIGSO_T *ObsHdr);
    113   inline void    SwitchIGS_Eph_HdrBytes( RTIGSE_T *EphHdr);
    114   inline short   SwitchIGS_Met_RecBytes( RTIGSM_T *MetHdr);
    115   unsigned short GetRTIGSHdrRecType(unsigned char *RTIGS_Str);
    116   unsigned short GetRTIGSHdrStaID(unsigned char *RTIGS_Str);
    117   unsigned short GetRTIGSHdrRecBytes(unsigned char *RTIGS_Str);
    118   unsigned long  GetRTIGSHdrGPSSeconds(unsigned char *RTIGS_Str);
    119   short          Decode_RTIGS_Sta(unsigned char *RTIGS_Str,   unsigned short RTIGS_Bytes, RTIGSS_T &rtigs_sta_dec);        // contents of record contain all info
    120   short          Decode_RTIGS_Obs(unsigned char *RTIGS_Str,  unsigned  short RTIGS_Bytes, RTIGSO_T &rtigs_obs);    // stores obs in class container
    121   short          Decode_RTIGS_Eph(unsigned char *RTIGS_Str,  unsigned  short RTIGS_Bytes, RTIGSE_T &rtigs_eph, short arrPRN[]);    // stores eph in class container
    122   short          Decode_RTIGS_Eph(unsigned char *RTIGS_Str,  unsigned  short RTIGS_Bytes, RTIGSE_T &rtigs_eph, short &PRN); //stors in class and returns prn
    123   short          Decode_RTIGS_Met(unsigned char *RTIGS_Str,   unsigned short RTIGS_Bytes, RTIGSM_T *rtigs_met);    // contents of record contain all info.
    124 };
     14  CGPS_Transform _GPSTrans;
     15} ;
    12516
    12617#endif
  • trunk/BNC/bncgetthread.cpp

    r39 r59  
    3333                           const QByteArray& mountPoint,
    3434                           const QByteArray& user,
    35                            const QByteArray& password) {
     35                           const QByteArray& password,
     36                           const QByteArray& format) {
    3637  _host       = host;
    3738  _port       = port;
     
    4142  _user       = user;
    4243  _password   = password;
     44  _format     = format;
    4345  _socket     = 0;
    4446}
     
    135137  rtcmFilter = new RTCM('A',true);
    136138
     139  qWarning("Get Data: " + _mountPoint + " " + _format);
     140
    137141  // Read Incoming Data
    138142  // ------------------
  • trunk/BNC/bncgetthread.h

    r35 r59  
    1616                const QByteArray& mountPoint,
    1717                const QByteArray& user,
    18                 const QByteArray& password);
     18                const QByteArray& password,
     19                const QByteArray& format);
    1920   ~bncGetThread();
    2021   static QTcpSocket* bncGetThread::request(const QString& host, int port,
     
    4142   QByteArray  _user;
    4243   QByteArray  _password;
     44   QByteArray  _format;
    4345};
    4446
  • trunk/BNC/bncmain.cpp

    r36 r59  
    8383    QListIterator<QString> it(settings.value("mountPoints").toStringList());
    8484    while (it.hasNext()) {
    85       QUrl url(it.next());
     85      QStringList hlp = it.next().split(" ");
     86      QUrl url(hlp[0]);
    8687      QByteArray mountPoint = url.path().mid(1).toAscii();
     88      QByteArray format     = hlp[1].toAscii();
    8789
    8890      bncGetThread* getThread = new bncGetThread(url.host(), url.port(),
    8991                                                 proxyHost, proxyPort,
    90                                                  mountPoint, user, password);
     92                                                 mountPoint, user, password,
     93                                                 format);
    9194      caster->addGetThread(getThread);
    9295
  • trunk/BNC/bnctabledlg.cpp

    r35 r59  
    165165  if (_table) {
    166166    for (int ir = 0; ir < _table->rowCount(); ir++) {
    167       QTableWidgetItem* item = _table->item(ir,0);
     167      QTableWidgetItem* item   = _table->item(ir,0);
     168      QString           format = _table->item(ir,2)->text();
     169      format.replace(" ", "_");
    168170      if (_table->isItemSelected(item)) {
    169171        QUrl url;
     
    171173        url.setPort(_casterPortLineEdit->text().toInt());
    172174        url.setPath(item->text());
    173         mountPoints->push_back(url.toString());
     175
     176        mountPoints->push_back(url.toString() + " " + format);
    174177      }
    175178    }
  • trunk/BNC/bncwindow.cpp

    r35 r59  
    9292  _outFileLineEdit    = new QLineEdit(settings.value("outFile").toString());
    9393  _outPortLineEdit    = new QLineEdit(settings.value("outPort").toString());
    94   _mountPointsTable   = new QTableWidget(0,1);
     94  _mountPointsTable   = new QTableWidget(0,2);
    9595  _mountPointsTable->setMaximumHeight(100);
    9696  _mountPointsTable->horizontalHeader()->hide();
     
    106106  int iRow = 0;
    107107  while (it.hasNext()) {
    108     QString mPoint = it.next();
     108    QStringList hlp = it.next().split(" ");
     109    QString mPoint = hlp[0];
     110    QString format = hlp[1];
    109111    _mountPointsTable->insertRow(iRow);
    110112    _mountPointsTable->setItem(iRow, 0, new QTableWidgetItem(mPoint));
     113    _mountPointsTable->setItem(iRow, 1, new QTableWidgetItem(format));
    111114    iRow++;
    112115  }
     
    161164  QListIterator<QString> it(*mountPoints);
    162165  while (it.hasNext()) {
    163     QString mPoint = it.next();
     166    QStringList hlp = it.next().split(" ");
     167    QString mPoint = hlp[0];
     168    QString format = hlp[1];
    164169    _mountPointsTable->insertRow(iRow);
    165170    _mountPointsTable->setItem(iRow, 0, new QTableWidgetItem(mPoint));
     171    _mountPointsTable->setItem(iRow, 1, new QTableWidgetItem(format));
    166172    iRow++;
    167173  }
     
    184190  QStringList mountPoints;
    185191  for (int iRow = 0; iRow < _mountPointsTable->rowCount(); iRow++) {
    186     mountPoints.append(_mountPointsTable->item(iRow, 0)->text());
     192    mountPoints.append(_mountPointsTable->item(iRow, 0)->text() +
     193                       " " + _mountPointsTable->item(iRow, 1)->text());
    187194  }
    188195  settings.setValue("mountPoints", mountPoints);
     
    221228    QUrl url(_mountPointsTable->item(iRow, 0)->text());
    222229    QByteArray mountPoint = url.path().mid(1).toAscii();
     230    QByteArray format     = _mountPointsTable->item(iRow, 1)->text().toAscii();
    223231
    224232    bncGetThread* getThread = new bncGetThread(url.host(), url.port(),
    225233                                               proxyHost, proxyPort,
    226                                                mountPoint, user, password);
     234                                               mountPoint, user, password,
     235                                               format);
    227236    _bncCaster->addGetThread(getThread);
    228237
Note: See TracChangeset for help on using the changeset viewer.