// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0x90545(%rip), %rdi     # 0x12470b
callq 0x58dc2
leaq 0x2791de(%rip), %rax    # 0x30d3b0
movl $0x1, (%rax)
callq 0x58b08
movsd %xmm0, -0x30(%rbp)
callq 0x588d2
movl %eax, %ecx
leaq 0x187188(%rip), %rax    # 0x21b378
movl (%rax), %edx
testl %edx, %edx
je 0x9452f
leaq 0x187157(%rip), %rax    # 0x21b358
movsd (%rax), %xmm0
movsd -0x30(%rbp), %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %esi
cltd
idivl %esi
testl %edx, %edx
jne 0x9452f
leaq 0x279345(%rip), %rax    # 0x30d578
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%rax)
movzwl %cx, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd 0x776ba(%rip), %xmm1    # 0x10b908
addsd 0x77642(%rip), %xmm1    # 0x10b898
movsd %xmm1, -0x40(%rbp)
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0xd492e
addsd -0x40(%rbp), %xmm0
leaq 0x2792fe(%rip), %rax    # 0x30d570
movsd %xmm0, (%rax)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x9428c
leaq 0x1aace7(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x587be
movl %eax, %ebx
cmpl $0x100, %eax            # imm = 0x100
jb 0x942a4
leaq 0x1aaccf(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x942ba
leaq 0x1aacb9(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x942d0
leaq 0x1aaca3(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x942e6
leaq 0x1aac8d(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
movzbl %bl, %r13d
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x94300
leaq 0x1aac73(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
testl %r13d, %r13d
je 0x9452f
leaq 0x1aac60(%rip), %rbx    # 0x23ef70
callq 0x58b08
movsd %xmm0, -0x40(%rbp)
callq 0x58b08
movsd %xmm0, -0x30(%rbp)
callq 0x58a30
movss %xmm0, -0x34(%rbp)
callq 0x587be
movl %eax, %r15d
cmpl $0x100, %eax            # imm = 0x100
jb 0x94340
orb $0x8, (%rbx)
callq 0x587be
movl %eax, %r12d
cmpl $0x100, %eax            # imm = 0x100
jb 0x94352
orb $0x8, (%rbx)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x94361
orb $0x8, (%rbx)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x94370
orb $0x8, (%rbx)
callq 0x588d2
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x94384
orb $0x8, (%rbx)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x94393
orb $0x8, (%rbx)
callq 0x587be
movl %eax, %r14d
cmpl $0x100, %eax            # imm = 0x100
jb 0x943a5
orb $0x8, (%rbx)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x943b4
orb $0x8, (%rbx)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x943c3
orb $0x8, (%rbx)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x943d2
orb $0x8, (%rbx)
movzbl %r12b, %ebx
cmpb $0x2, %r15b
jae 0x943e5
testl %ebx, %ebx
jne 0x9443d
jmp 0x9451f
movzbl %r15b, %eax
addl $-0x2, %eax
cmpl $0x3, %eax
ja 0x9441f
leaq 0x8b348(%rip), %rcx     # 0x11f740
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
addl $0xd2, %ebx
jmp 0x9443d
cmpb $0x5, %r12b
ja 0x9443a
addl $0x9e, %ebx
jmp 0x9443d
addl $0xc0, %ebx
jmp 0x9443d
cmpb $0x6, %r15b
setne %al
cmpb $-0x1, %r12b
sete %cl
orb %al, %cl
jne 0x9451f
addl $0x40, %ebx
jmp 0x9443d
addl $0x1b, %ebx
xorps %xmm0, %xmm0
cvtss2sd -0x34(%rbp), %xmm0
movl %ebx, %eax
imulq $0x348, %rax, %rax      # imm = 0x348
leaq 0x1aab5b(%rip), %rcx    # 0x23efb0
movsd %xmm0, 0x30(%rcx,%rax)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, 0x28(%rcx,%rax)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, 0x38(%rcx,%rax)
xorl %edx, %edx
movl %edx, 0x68(%rcx,%rax)
movl %edx, 0xa8(%rcx,%rax)
movl %edx, 0xe8(%rcx,%rax)
cmpb $0xf, %r14b
jne 0x94499
addq 0xbbaae(%rip), %rax     # 0x14ff40
movl $0x80, 0x68(%rax)
movl %ebx, %edi
callq 0xdc1dd
leaq 0x278ea5(%rip), %rcx    # 0x30d34c
orl %eax, (%rcx)
movss -0x34(%rbp), %xmm0
ucomiss 0x78bdb(%rip), %xmm0    # 0x10d090
leaq 0x278e84(%rip), %r14    # 0x30d340
jne 0x944c0
jnp 0x944dd
cmpl $0x0, (%r14)
jne 0x944d3
leaq 0x184377(%rip), %rax    # 0x218844
movl $0x7e2, (%rax)          # imm = 0x7E2
movl %ebx, %edi
callq 0xdc1dd
orl %eax, (%r14)
movsd -0x40(%rbp), %xmm0
ucomisd 0x74c2e(%rip), %xmm0    # 0x109118
jne 0x944ee
jnp 0x944fe
movl %ebx, %edi
callq 0xdc1dd
leaq 0x278e4c(%rip), %rcx    # 0x30d348
orl %eax, (%rcx)
movsd -0x30(%rbp), %xmm0
ucomisd 0x74c0d(%rip), %xmm0    # 0x109118
jne 0x9450f
jnp 0x9451f
movl %ebx, %edi
callq 0xdc1dd
leaq 0x278e27(%rip), %rcx    # 0x30d344
orl %eax, (%rcx)
decl %r13d
leaq 0x1aaa47(%rip), %rbx    # 0x23ef70
jne 0x94310
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq