// File: /workspace/github_cpp_makefile_star2_O2/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 0x876bf(%rip), %rdi     # 0x10e653
callq 0x520bf
leaq 0x270410(%rip), %rax    # 0x2f73b0
movl $0x1, (%rax)
callq 0x51e6f
movsd %xmm0, -0x30(%rbp)
callq 0x51c63
movl %eax, %ecx
leaq 0x17e3ba(%rip), %rax    # 0x205378
movl (%rax), %edx
testl %edx, %edx
je 0x86fef
leaq 0x17e38d(%rip), %rax    # 0x205358
movsd (%rax), %xmm0
movsd -0x30(%rbp), %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
cvtsi2sd %edx, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %esi
cltd
idivl %esi
testl %edx, %edx
je 0x86ffe
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x270573(%rip), %rax    # 0x2f7578
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%rax)
movzwl %cx, %eax
cvtsi2sd %eax, %xmm1
mulsd 0x6e963(%rip), %xmm1    # 0xf5980
addsd 0x6e8eb(%rip), %xmm1    # 0xf5910
movsd %xmm1, -0x40(%rbp)
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0xc2faf
addsd -0x40(%rbp), %xmm0
leaq 0x27052f(%rip), %rax    # 0x2f7570
movsd %xmm0, (%rax)
callq 0x51c47
callq 0x51c47
movzbl %al, %r13d
callq 0x51c47
callq 0x51c47
callq 0x51c47
callq 0x51c47
subl $0x1, %r13d
jb 0x86fef
callq 0x51e6f
movsd %xmm0, -0x40(%rbp)
callq 0x51e6f
movsd %xmm0, -0x30(%rbp)
callq 0x51dc3
movss %xmm0, -0x34(%rbp)
callq 0x51c47
movl %eax, %r12d
callq 0x51c47
movl %eax, %r15d
movzbl %al, %ebx
callq 0x51c47
callq 0x51c47
callq 0x51c63
callq 0x51c47
callq 0x51c47
callq 0x51c47
movl %eax, %r14d
callq 0x51c47
callq 0x51c47
callq 0x51c47
cmpb $0x2, %r12b
jae 0x870da
testl %ebx, %ebx
jne 0x87134
jmp 0x87067
movzbl %r12b, %eax
addl $-0x2, %eax
cmpl $0x3, %eax
ja 0x87114
leaq 0x82597(%rip), %rcx     # 0x109684
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
addl $0xd2, %ebx
jmp 0x87134
addl $0xc0, %ebx
jmp 0x87134
cmpb $0x5, %r15b
ja 0x87131
addl $0x9e, %ebx
jmp 0x87134
cmpb $0x6, %r12b
setne %al
cmpl $0xff, %ebx
sete %cl
orb %al, %cl
jne 0x87067
addl $0x40, %ebx
jmp 0x87134
addl $0x1b, %ebx
cvtss2sd -0x34(%rbp), %xmm0
movl %ebx, %eax
imulq $0x348, %rax, %rax      # imm = 0x348
leaq 0x1a1e67(%rip), %rcx    # 0x228fb0
movsd %xmm0, 0x30(%rcx,%rax)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, 0x28(%rcx,%rax)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, 0x38(%rcx,%rax)
andl $0x0, 0x68(%rcx,%rax)
andl $0x0, 0xa8(%rcx,%rax)
andl $0x0, 0xe8(%rcx,%rax)
cmpb $0xf, %r14b
jne 0x8718e
addq 0xb2dc1(%rip), %rax     # 0x139f48
movl $0x80, 0x68(%rax)
movl %ebx, %edi
callq 0xca4da
leaq 0x2701b0(%rip), %rcx    # 0x2f734c
orl %eax, (%rcx)
movss -0x34(%rbp), %xmm0
ucomiss 0x6ff66(%rip), %xmm0    # 0xf7110
leaq 0x27018f(%rip), %r14    # 0x2f7340
jne 0x871b5
jnp 0x871d2
cmpl $0x0, (%r14)
jne 0x871c8
leaq 0x17b682(%rip), %rax    # 0x202844
movl $0x7e2, (%rax)          # imm = 0x7E2
movl %ebx, %edi
callq 0xca4da
orl %eax, (%r14)
movsd -0x40(%rbp), %xmm0
ucomisd 0x6bf39(%rip), %xmm0    # 0xf3118
jne 0x871e3
jnp 0x871f3
movl %ebx, %edi
callq 0xca4da
leaq 0x270157(%rip), %rcx    # 0x2f7348
orl %eax, (%rcx)
movsd -0x30(%rbp), %xmm0
ucomisd 0x6bf18(%rip), %xmm0    # 0xf3118
jne 0x87208
jnp 0x87067
movl %ebx, %edi
callq 0xca4da
leaq 0x27012e(%rip), %rcx    # 0x2f7344
orl %eax, (%rcx)
jmp 0x87067