// File: jkingan[P]ladyheather/heathgps.cpp
// Function: parse_ubx_rawx()
void parse_ubx_rawx()
{
double meas_tow;
int ls;
int num_meas;
int rec_stat;
double carrier;
double range;
float doppler;
int gnssid;
int prn;
int snr;
int lli;
int week;
int xtow;

//sprintf(debug_text6, "rawx");
   log_packet_id("UBX_RAWX");
   have_ubx_rawx = 1;

   // get doppler and code phase data (only on special receivers)

   meas_tow = tsip_double(); // measurement tow
   week = tsip_word();  // week

   if(raw_msg_rate == 0) return; 

   if(1 || (nav_rate > 1.0)) {
      xtow = (int) (meas_tow*(double) nav_rate);  // raw Hz 
//    sprintf(debug_text, "meas_tow:%.7f  xtow=%d", meas_tow, xtow);  // rnx3
      if(xtow % (int) ((double)raw_msg_rate*nav_rate)) return;
   }

   obs_tow = meas_tow;
   jd_obs = GPS_EPOCH + ((double) week * 7.0) + jtime(0,0,0,meas_tow);


   ls = tsip_byte();  // leap seconds
   num_meas = tsip_byte();
   rec_stat = tsip_byte();
   tsip_byte();
   tsip_byte();    // reserved
   tsip_byte();
if(0 && debug_file) fprintf(debug_file, "RAWX num_meas:%d  rec_stat:%d\n",num_meas, rec_stat); //rnx3

   while(num_meas--) {
      range = tsip_double();
      carrier = tsip_double();
      doppler = tsip_single();

      gnssid = tsip_byte();   // sat system code
      prn = tsip_byte();      // SVN
      tsip_byte();            // reserved
      tsip_byte();            // glonass freq id
      tsip_word();            // carrier phase locktime counter
      snr = tsip_byte();      // sig level
      tsip_byte();            // peudorange sdev
      lli = tsip_byte();      // carrier phase sdev
      tsip_byte();            // doppler sdev
      tsip_byte();            // stacking status bitfield
      tsip_byte();            // reserved

//carrier = rinex_cppr(prn, range, carrier);  // testing CPPR mode - which makes things worse
//lli = 0;
//if(debug_file) fprintf(debug_file, "prn:%-2d  pr:%.3f  cppr:%.3f\n", prn,range,carrier);

      // convert gnssid:svn to equivalent prn
if(0 && debug_file) fprintf(debug_file, "RAWX gnssid:%d  svn:%2d->", gnssid,prn); //rnx3
      if(gnssid == 0) {       // GPS
      }
      else if(gnssid == 1) {  // SBAS
      }
      else if(gnssid == 2) {  // Galileo
         prn += 210;
      }
      else if(gnssid == 3) {  // Beidou
         if(prn < 6) prn += 158;     // 1..5
         else        prn += (33-6);  // 33..64
      }
      else if(gnssid == 4) {  // IMES
         prn += 172;  // 173..182
         continue;    // does not do raw data
      }
      else if(gnssid == 5) {  // QZSS
         prn += 192;
      }
      else if(gnssid == 6) {  // GLONASS
         if(prn == 255) continue;  // undetermined prn, ignore
         prn += 64;
      }
      else continue;

      if((prn >= 1) && (prn <= MAX_PRN)) { 
if(0 && debug_file) fprintf(debug_file, "%3d (%04X) range:%f carrier:%f  dop:%f\n", prn,rinex_gnss(prn), range,carrier,doppler);
         sat[prn].doppler = doppler;
         sat[prn].code_phase = carrier;
         sat[prn].range = range;

         sat[prn].ca_lli = 0;
         sat[prn].l1_lli = 0;
         sat[prn].l2_lli = 0;
         if(lli == 0x0F) sat[prn].ca_lli |= LOCK_LOST;  // loss of lock
//       sat[prn].sig_level = (float) snr;
//       sat[prn].level_msg = 4;
//       record_sig_levels(prn);

         have_snr |= rinex_gnss(prn);
         if(doppler != 0.0F) {
            if(have_doppler == 0) need_redraw = 2018;
            have_doppler |= rinex_gnss(prn);
         }
         if(range != 0.0) {
            have_range |= rinex_gnss(prn);
         }
         if(carrier != 0.0) {
            have_phase |= rinex_gnss(prn);
         }
      }
   }
if(0 && debug_file) fprintf(debug_file, "have dop:%04X  phase:%04X  range:%04X\n", have_doppler,have_phase,have_range);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
leaq 0xbd4d8(%rip), %rdi     # 0x1879f7
callq 0x7add0
leaq 0x2a2065(%rip), %rax    # 0x36c590
movl $0x1, (%rax)
callq 0x7a9d0
movsd %xmm0, -0x8(%rbp)
callq 0x7a560
movzwl %ax, %eax
movl %eax, -0x40(%rbp)
leaq 0x1b000b(%rip), %rax    # 0x27a558
cmpl $0x0, (%rax)
jne 0xca557
jmp 0xca906
movsd -0x8(%rbp), %xmm0
leaq 0x1affd5(%rip), %rax    # 0x27a538
mulsd (%rax), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
leaq 0x1affe0(%rip), %rcx    # 0x27a558
cvtsi2sdl (%rcx), %xmm0
leaq 0x1affb5(%rip), %rcx    # 0x27a538
mulsd (%rcx), %xmm0
cvttsd2si %xmm0, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0xca598
jmp 0xca906
movsd -0x8(%rbp), %xmm0
leaq 0x2a21b4(%rip), %rax    # 0x36c758
movsd %xmm0, (%rax)
cvtsi2sdl -0x40(%rbp), %xmm0
movsd 0xa70d3(%rip), %xmm1    # 0x171688
mulsd %xmm1, %xmm0
movsd 0xa7057(%rip), %xmm1    # 0x171618
addsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x8(%rbp), %xmm0
xorl %edx, %edx
movl %edx, %edi
movl %edx, %esi
callq 0x122210
movaps %xmm0, %xmm1
movsd -0x50(%rbp), %xmm0
addsd %xmm1, %xmm0
leaq 0x2a2163(%rip), %rax    # 0x36c750
movsd %xmm0, (%rax)
callq 0x7a510
movzbl %al, %eax
movl %eax, -0xc(%rbp)
callq 0x7a510
movzbl %al, %eax
movl %eax, -0x10(%rbp)
callq 0x7a510
movzbl %al, %eax
movl %eax, -0x14(%rbp)
callq 0x7a510
callq 0x7a510
callq 0x7a510
movl -0x10(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x10(%rbp)
cmpl $0x0, %eax
je 0xca906
callq 0x7a9d0
movsd %xmm0, -0x28(%rbp)
callq 0x7a9d0
movsd %xmm0, -0x20(%rbp)
callq 0x7a860
movss %xmm0, -0x2c(%rbp)
callq 0x7a510
movzbl %al, %eax
movl %eax, -0x30(%rbp)
callq 0x7a510
movzbl %al, %eax
movl %eax, -0x34(%rbp)
callq 0x7a510
callq 0x7a510
callq 0x7a560
callq 0x7a510
movzbl %al, %eax
movl %eax, -0x38(%rbp)
callq 0x7a510
callq 0x7a510
movzbl %al, %eax
movl %eax, -0x3c(%rbp)
callq 0x7a510
callq 0x7a510
callq 0x7a510
cmpl $0x0, -0x30(%rbp)
jne 0xca6ad
jmp 0xca748
cmpl $0x1, -0x30(%rbp)
jne 0xca6b8
jmp 0xca746
cmpl $0x2, -0x30(%rbp)
jne 0xca6cb
movl -0x34(%rbp), %eax
addl $0xd2, %eax
movl %eax, -0x34(%rbp)
jmp 0xca744
cmpl $0x3, -0x30(%rbp)
jne 0xca6ef
cmpl $0x6, -0x34(%rbp)
jge 0xca6e4
movl -0x34(%rbp), %eax
addl $0x9e, %eax
movl %eax, -0x34(%rbp)
jmp 0xca6ed
movl -0x34(%rbp), %eax
addl $0x1b, %eax
movl %eax, -0x34(%rbp)
jmp 0xca742
cmpl $0x4, -0x30(%rbp)
jne 0xca705
movl -0x34(%rbp), %eax
addl $0xac, %eax
movl %eax, -0x34(%rbp)
jmp 0xca621
cmpl $0x5, -0x30(%rbp)
jne 0xca718
movl -0x34(%rbp), %eax
addl $0xc0, %eax
movl %eax, -0x34(%rbp)
jmp 0xca73e
cmpl $0x6, -0x30(%rbp)
jne 0xca737
cmpl $0xff, -0x34(%rbp)
jne 0xca72c
jmp 0xca621
movl -0x34(%rbp), %eax
addl $0x40, %eax
movl %eax, -0x34(%rbp)
jmp 0xca73c
jmp 0xca621
jmp 0xca73e
jmp 0xca740
jmp 0xca742
jmp 0xca744
jmp 0xca746
jmp 0xca748
cmpl $0x1, -0x34(%rbp)
jl 0xca901
cmpl $0x3e7, -0x34(%rbp)     # imm = 0x3E7
jg 0xca901
movss -0x2c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movslq -0x34(%rbp), %rcx
leaq 0x1d3a1d(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movsd %xmm0, 0x30(%rax)
movsd -0x20(%rbp), %xmm0
movslq -0x34(%rbp), %rcx
leaq 0x1d39fe(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movsd %xmm0, 0x28(%rax)
movsd -0x28(%rbp), %xmm0
movslq -0x34(%rbp), %rcx
leaq 0x1d39df(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movsd %xmm0, 0x38(%rax)
movslq -0x34(%rbp), %rcx
leaq 0x1d39c5(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movl $0x0, 0x68(%rax)
movslq -0x34(%rbp), %rcx
leaq 0x1d39a9(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movl $0x0, 0xa8(%rax)
movslq -0x34(%rbp), %rcx
leaq 0x1d398a(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movl $0x0, 0xe8(%rax)
cmpl $0xf, -0x3c(%rbp)
jne 0xca841
movslq -0x34(%rbp), %rcx
leaq 0x1d3965(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movl 0x68(%rax), %ecx
orl $0x80, %ecx
movl %ecx, 0x68(%rax)
movl -0x34(%rbp), %edi
callq 0x12d280
movl %eax, %ecx
leaq 0x2a1cda(%rip), %rax    # 0x36c52c
orl (%rax), %ecx
leaq 0x2a1cd1(%rip), %rax    # 0x36c52c
movl %ecx, (%rax)
movss -0x2c(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0xca86e
jp 0xca86e
jmp 0xca8a3
leaq 0x2a1cab(%rip), %rax    # 0x36c520
cmpl $0x0, (%rax)
jne 0xca887
leaq 0x1ad1a3(%rip), %rax    # 0x277a24
movl $0x7e2, (%rax)          # imm = 0x7E2
movl -0x34(%rbp), %edi
callq 0x12d280
movl %eax, %ecx
leaq 0x2a1c88(%rip), %rax    # 0x36c520
orl (%rax), %ecx
leaq 0x2a1c7f(%rip), %rax    # 0x36c520
movl %ecx, (%rax)
movsd -0x28(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xca8b5
jp 0xca8b5
jmp 0xca8d1
movl -0x34(%rbp), %edi
callq 0x12d280
movl %eax, %ecx
leaq 0x2a1c62(%rip), %rax    # 0x36c528
orl (%rax), %ecx
leaq 0x2a1c59(%rip), %rax    # 0x36c528
movl %ecx, (%rax)
movsd -0x20(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xca8e3
jp 0xca8e3
jmp 0xca8ff
movl -0x34(%rbp), %edi
callq 0x12d280
movl %eax, %ecx
leaq 0x2a1c30(%rip), %rax    # 0x36c524
orl (%rax), %ecx
leaq 0x2a1c27(%rip), %rax    # 0x36c524
movl %ecx, (%rax)
jmp 0xca901
jmp 0xca621
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)