// File: /workspace/github_cpp_makefile_star2_O1/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 0x904ef(%rip), %rdi     # 0x12462b
callq 0x58e77
leaq 0x279268(%rip), %rax    # 0x30d3b0
movl $0x1, (%rax)
callq 0x58b86
movsd %xmm0, -0x30(%rbp)
callq 0x588f0
movl %eax, %ecx
leaq 0x187212(%rip), %rax    # 0x21b378
movl (%rax), %edx
testl %edx, %edx
je 0x9419a
leaq 0x1871e5(%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
je 0x941a9
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2793c8(%rip), %rax    # 0x30d578
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%rax)
movzwl %cx, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd 0x77735(%rip), %xmm1    # 0x10b900
addsd 0x776b5(%rip), %xmm1    # 0x10b888
movsd %xmm1, -0x40(%rbp)
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0xd41e0
addsd -0x40(%rbp), %xmm0
leaq 0x279381(%rip), %rax    # 0x30d570
movsd %xmm0, (%rax)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x94209
leaq 0x1aad6a(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x587d1
movl %eax, %ebx
cmpl $0x100, %eax            # imm = 0x100
jb 0x94221
leaq 0x1aad52(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x94237
leaq 0x1aad3c(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x9424d
leaq 0x1aad26(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x94263
leaq 0x1aad10(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
movzbl %bl, %r13d
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x9427d
leaq 0x1aacf6(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
testl %r13d, %r13d
je 0x9419a
leaq 0x1aace3(%rip), %rbx    # 0x23ef70
callq 0x58b86
movsd %xmm0, -0x40(%rbp)
callq 0x58b86
movsd %xmm0, -0x30(%rbp)
callq 0x58aae
movss %xmm0, -0x34(%rbp)
callq 0x587d1
movl %eax, %r15d
cmpl $0x100, %eax            # imm = 0x100
jb 0x942bd
orb $0x8, (%rbx)
callq 0x587d1
movl %eax, %r12d
cmpl $0x100, %eax            # imm = 0x100
jb 0x942cf
orb $0x8, (%rbx)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x942de
orb $0x8, (%rbx)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x942ed
orb $0x8, (%rbx)
callq 0x588f0
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x94301
orb $0x8, (%rbx)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x94310
orb $0x8, (%rbx)
callq 0x587d1
movl %eax, %r14d
cmpl $0x100, %eax            # imm = 0x100
jb 0x94322
orb $0x8, (%rbx)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x94331
orb $0x8, (%rbx)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x94340
orb $0x8, (%rbx)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x9434f
orb $0x8, (%rbx)
movzbl %r12b, %ebx
cmpb $0x2, %r15b
jae 0x94449
testl %ebx, %ebx
jle 0x9449e
xorps %xmm0, %xmm0
cvtss2sd -0x34(%rbp), %xmm0
movl %ebx, %eax
imulq $0x348, %rax, %rax      # imm = 0x348
leaq 0x1aac33(%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 0x943c1
addq 0xbbb86(%rip), %rax     # 0x14ff40
movl $0x80, 0x68(%rax)
movl %ebx, %edi
callq 0xdbb74
leaq 0x278f7d(%rip), %rcx    # 0x30d34c
orl %eax, (%rcx)
movss -0x34(%rbp), %xmm0
ucomiss 0x78c1f(%rip), %xmm0    # 0x10cffc
leaq 0x278f5c(%rip), %r14    # 0x30d340
jne 0x943e8
jnp 0x94405
cmpl $0x0, (%r14)
jne 0x943fb
leaq 0x18444f(%rip), %rax    # 0x218844
movl $0x7e2, (%rax)          # imm = 0x7E2
movl %ebx, %edi
callq 0xdbb74
orl %eax, (%r14)
movsd -0x40(%rbp), %xmm0
ucomisd 0x74d06(%rip), %xmm0    # 0x109118
jne 0x94416
jnp 0x94426
movl %ebx, %edi
callq 0xdbb74
leaq 0x278f24(%rip), %rcx    # 0x30d348
orl %eax, (%rcx)
movsd -0x30(%rbp), %xmm0
ucomisd 0x74ce5(%rip), %xmm0    # 0x109118
jne 0x94437
jnp 0x9449e
movl %ebx, %edi
callq 0xdbb74
leaq 0x278eff(%rip), %rcx    # 0x30d344
orl %eax, (%rcx)
jmp 0x9449e
movzbl %r15b, %eax
addl $-0x2, %eax
cmpl $0x3, %eax
ja 0x9448c
leaq 0x8b20c(%rip), %rcx     # 0x11f668
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
addl $0xd2, %ebx
jmp 0x9435d
cmpb $0x5, %r12b
ja 0x944b3
addl $0x9e, %ebx
jmp 0x9435d
addl $0xc0, %ebx
jmp 0x9435d
cmpb $0x6, %r15b
setne %al
cmpb $-0x1, %r12b
sete %cl
orb %al, %cl
je 0x944bb
decl %r13d
leaq 0x1aaac8(%rip), %rbx    # 0x23ef70
jne 0x9428d
jmp 0x9419a
addl $0x1b, %ebx
jmp 0x9435d
addl $0x40, %ebx
jmp 0x9435d