// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heathgps.cpp
// Function: parse_venus_ext_raw()
void parse_venus_ext_raw()
{
int count;
int i;
int svid;
int prn;

int snr;
double range;
double phase;
float doppler;
int lli;

int flags;
int week;
int tow;
double meas_tow;
int xtow;
int gnss;
int meas;
int freq;
int lti;

   // extended raw measurements
   log_packet_id("venus_ext_raw");

   saw_venus_raw |= 0x10;
   minor_alarms &= (~MINOR_NO_TRACK);

   tsip_byte();  // message version
   tsip_byte();  // iod
   week = tsip_word();  // week
   tow = tsip_dword();  // tow in msecs
   tsip_word();         // measurement period
   tsip_byte();         // measurement indicator
   tsip_byte();         // reserved
   count = tsip_byte();

   meas_tow = tow / 1000.0; // measurement tow
   if(raw_msg_rate == 0) return;
   xtow = (int) (meas_tow*nav_rate);  // raw Hz 

   if(1) {  // this causes time stamp faults in CSRS-PPP  //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);
   }
   else {  // Only 1Hz nav rate
      if(((int) meas_tow % raw_msg_rate) != 0) return;  // drop unwanted messages

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


if(0 && log_file) fprintf(log_file, "\njd_obs:%.9f  count:%d  week:%d\n", jd_obs, count, week);

   for(i=0; i<count; i++) {
      gnss = tsip_byte();
      meas = gnss >> 4;
      gnss &= 0x0F;

      svid = prn = tsip_byte();
      if     (gnss == 5) prn += 200; // Beidou  201..237
      else if(gnss == 3) prn += 300; // Galileo 301..350 (Heather values)
      else if(gnss == 2) prn += 64;  // Glonass 65..96
      else if(gnss == 1) prn += 0;   // SBAS    120..158
      else if(gnss == 0) prn += 0;   // GPS     1..37 (s/b 1..32)
      else prn = 0;

      freq = tsip_byte();
      lti = freq >> 4;   //lock time
      freq &= 0x0F;      //Glonass only

      snr = tsip_byte();
      range = tsip_double();
      phase = tsip_double();
      doppler = tsip_single();
      tsip_byte();   // pseudorange sdev
      tsip_byte();   // carrierphase sdev
      tsip_byte();   // doppler sdev
      flags = tsip_word();
      tsip_word();   // reserved

      if((flags & 0x01) == 0) range = 0.0;
      if((flags & 0x02) == 0) doppler = 0.0F;
      if((flags & 0x04) == 0) phase = 0.0;
      if((flags & 0x08) == 0) lli = 0;
      else                    lli = LOCK_LOST;
if(0 && log_file) fprintf(log_file, "  svid:%d  prn:%d  gnss:%d  meas:%02X  flags:%04X\n", svid, prn, gnss, meas, flags);

      if((prn >= 1) && (prn <= MAX_PRN)) {  // !!!! we need to handle non-C/A code "meas" value
         if(meas == 0) {  // L1 C/A
            sat[prn].range = range;
            sat[prn].doppler = doppler;
            sat[prn].code_phase = phase;
            sat[prn].ca_lli = lli;
            sat[prn].sig_level = (float) snr;

            if(snr != 0)  {
               have_snr |= rinex_gnss(prn);
            }
            if(range != 0.0) {
               have_range |= rinex_gnss(prn);
            }
            if(phase != 0.0)  {
               have_phase |= rinex_gnss(prn);
            }

            if(doppler != 0.0F) {
               if(have_doppler == 0) need_redraw = 2018;
               have_doppler |= rinex_gnss(prn);
            }
         }
         else if(meas == 1) {  // L1
            sat[prn].l1_range = range;
            sat[prn].l1_doppler = doppler;
            sat[prn].l1_code_phase = phase;
            sat[prn].l1_lli = lli;
            sat[prn].l1_sig_level = (float) snr;

            if(snr != 0) {
               have_l1_snr   |= rinex_gnss(prn);
            }
            if(range != 0.0F) {
               have_l1_range |= rinex_gnss(prn);
            }
            if(phase != 0.0F) {
               have_l1_phase |= rinex_gnss(prn);
            }
            if(doppler != 0.0F) {
               have_l1_doppler |= rinex_gnss(prn);
            }
         }
         else if(meas == 2) {  // L2
            sat[prn].l2_range = range;
            sat[prn].l2_doppler = doppler;
            sat[prn].l2_code_phase = phase;
            sat[prn].l2_lli = lli;
            sat[prn].l2_sig_level = (float) snr;

            if(snr != 0) {
               have_l2_snr   |= rinex_gnss(prn);
            }
            if(range != 0.0) {
               have_l2_range |= rinex_gnss(prn);
            }
            if(phase != 0.0 ) {
               have_l2_phase |= rinex_gnss(prn);
            }
            if(doppler != 0.0F) {
               have_l2_doppler |= rinex_gnss(prn);
            }
         }
         else if(meas == 4) {  // L5  E5A B2I  GLONASS L3
            sat[prn].l5_range = range;
            sat[prn].l5_doppler = doppler;
            sat[prn].l5_code_phase = phase;
            sat[prn].l5_lli = lli;
            sat[prn].l5_sig_level = (float) snr;

            if(snr != 0) {
               have_l5_snr   |= rinex_gnss(prn);
            }
            if(range != 0.0) {
               have_l5_range |= rinex_gnss(prn);
            }
            if(phase != 0.0) {
               have_l5_phase |= rinex_gnss(prn);
            }
            if(doppler != 0.0F) {
               have_l5_doppler |= rinex_gnss(prn);
            }
         }
         else if(meas == 5) {  // Galileo E5B
         }
         else if(meas == 6) {  // Galileo E6
         }
      }
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
leaq 0x847b3(%rip), %rdi     # 0x10ea1b
callq 0x520bf
leaq 0x29db80(%rip), %rax    # 0x327df4
orb $0x10, (%rax)
leaq 0x26cf5a(%rip), %rax    # 0x2f71d8
andb $-0x9, (%rax)
callq 0x51c47
callq 0x51c47
callq 0x51c63
movl %eax, %ebx
callq 0x51cf3
movl %eax, %r14d
callq 0x51c63
callq 0x51c47
callq 0x51c47
callq 0x51c47
movl %eax, %ecx
leaq 0x17b0c1(%rip), %rax    # 0x205378
movl (%rax), %edx
testl %edx, %edx
je 0x8a2f4
cvtsi2sd %r14d, %xmm0
divsd 0x68d6e(%rip), %xmm0    # 0xf3038
leaq 0x17b087(%rip), %rax    # 0x205358
movsd (%rax), %xmm1
movapd %xmm0, %xmm2
mulsd %xmm1, %xmm2
cvttsd2si %xmm2, %eax
cvtsi2sd %edx, %xmm2
mulsd %xmm1, %xmm2
cvttsd2si %xmm2, %esi
cltd
idivl %esi
testl %edx, %edx
je 0x8a303
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzbl %cl, %r12d
leaq 0x26d26a(%rip), %rax    # 0x2f7578
movsd %xmm0, (%rax)
movzwl %bx, %eax
cvtsi2sd %eax, %xmm1
mulsd 0x6b65f(%rip), %xmm1    # 0xf5980
addsd 0x6b5e7(%rip), %xmm1    # 0xf5910
movsd %xmm1, -0x30(%rbp)
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0xc2faf
addsd -0x30(%rbp), %xmm0
leaq 0x26d22b(%rip), %rax    # 0x2f7570
movsd %xmm0, (%rax)
subl $0x1, %r12d
jb 0x8a2f4
callq 0x51c47
movl %eax, %r14d
movzbl %al, %r13d
movl %r13d, %ebx
andl $0xf, %ebx
callq 0x51c47
cmpl $0x5, %ebx
ja 0x8a383
movzbl %al, %edx
leaq 0x7f3f7(%rip), %rcx     # 0x10976c
movslq (%rcx,%rbx,4), %rax
addq %rcx, %rax
jmpq *%rax
addl $0x40, %edx
jmp 0x8a39a
movl $0x0, -0x30(%rbp)
jmp 0x8a39d
addl $0x12c, %edx            # imm = 0x12C
jmp 0x8a39a
addl $0xc8, %edx
movl %edx, -0x30(%rbp)
callq 0x51c47
callq 0x51c47
movl %eax, %r15d
callq 0x51e6f
movsd %xmm0, -0x48(%rbp)
callq 0x51e6f
movsd %xmm0, -0x40(%rbp)
callq 0x51dc3
movss %xmm0, -0x34(%rbp)
callq 0x51c47
callq 0x51c47
callq 0x51c47
callq 0x51c63
movzwl %ax, %ebx
callq 0x51c63
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
testb $0x1, %bl
je 0x8a3f6
movsd -0x48(%rbp), %xmm2
xorpd %xmm0, %xmm0
testb $0x2, %bl
je 0x8a404
movss -0x34(%rbp), %xmm0
testb $0x4, %bl
movl -0x30(%rbp), %edi
je 0x8a411
movsd -0x40(%rbp), %xmm1
testl %edi, %edi
je 0x8a349
andl $0x8, %ebx
shll $0x4, %ebx
movl %edi, %ecx
movzbl %r15b, %eax
cmpb $0xf, %r14b
ja 0x8a514
imulq $0x348, %rcx, %rcx      # imm = 0x348
leaq 0x19eb73(%rip), %rdx    # 0x228fb0
movsd %xmm2, 0x38(%rdx,%rcx)
movss %xmm0, -0x34(%rbp)
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x30(%rdx,%rcx)
cvtsi2ss %eax, %xmm0
movsd %xmm1, 0x28(%rdx,%rcx)
movl %ebx, 0x68(%rdx,%rcx)
movss %xmm0, 0x20(%rdx,%rcx)
testb %al, %al
movsd %xmm1, -0x40(%rbp)
je 0x8a492
movl -0x30(%rbp), %edi
movsd %xmm2, -0x48(%rbp)
callq 0xca4da
movsd -0x48(%rbp), %xmm2
movsd -0x40(%rbp), %xmm1
movl -0x30(%rbp), %edi
leaq 0x26cebc(%rip), %rcx    # 0x2f734c
orl %eax, (%rcx)
ucomisd 0x68c7e(%rip), %xmm2    # 0xf3118
jne 0x8a49e
jnp 0x8a4b7
movl -0x30(%rbp), %edi
callq 0xca4da
movsd -0x40(%rbp), %xmm1
movl -0x30(%rbp), %edi
leaq 0x26ce93(%rip), %rcx    # 0x2f7348
orl %eax, (%rcx)
ucomisd 0x68c59(%rip), %xmm1    # 0xf3118
jne 0x8a4c3
jnp 0x8a4d7
movl -0x30(%rbp), %edi
callq 0xca4da
movl -0x30(%rbp), %edi
leaq 0x26ce6f(%rip), %rcx    # 0x2f7344
orl %eax, (%rcx)
movss -0x34(%rbp), %xmm0
ucomiss 0x6cc2d(%rip), %xmm0    # 0xf7110
jne 0x8a4eb
jnp 0x8a349
leaq 0x26ce4e(%rip), %rbx    # 0x2f7340
cmpl $0x0, (%rbx)
jne 0x8a7a0
leaq 0x178342(%rip), %rax    # 0x202844
movl $0x7e2, (%rax)          # imm = 0x7E2
leaq 0x26ce31(%rip), %rbx    # 0x2f7340
jmp 0x8a7a0
shrl $0x4, %r13d
cmpl $0x4, %r13d
je 0x8a6ce
cmpl $0x2, %r13d
je 0x8a5ff
cmpl $0x1, %r13d
jne 0x8a349
imulq $0x348, %rcx, %rcx      # imm = 0x348
leaq 0x19ea6c(%rip), %rdx    # 0x228fb0
movsd %xmm2, 0x88(%rdx,%rcx)
movss %xmm0, -0x34(%rbp)
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x80(%rdx,%rcx)
cvtsi2ss %eax, %xmm0
movsd %xmm1, 0x78(%rdx,%rcx)
movl %ebx, 0xa8(%rdx,%rcx)
movss %xmm0, 0x70(%rdx,%rcx)
testb %al, %al
movsd %xmm1, -0x40(%rbp)
je 0x8a5a2
movl -0x30(%rbp), %edi
movsd %xmm2, -0x48(%rbp)
callq 0xca4da
movsd -0x48(%rbp), %xmm2
movsd -0x40(%rbp), %xmm1
movl -0x30(%rbp), %edi
leaq 0x26cdbc(%rip), %rcx    # 0x2f735c
orl %eax, (%rcx)
ucomisd 0x68b6e(%rip), %xmm2    # 0xf3118
jne 0x8a5ae
jnp 0x8a5c7
movl -0x30(%rbp), %edi
callq 0xca4da
movsd -0x40(%rbp), %xmm1
movl -0x30(%rbp), %edi
leaq 0x26cd93(%rip), %rcx    # 0x2f7358
orl %eax, (%rcx)
ucomisd 0x68b49(%rip), %xmm1    # 0xf3118
jne 0x8a5d3
jnp 0x8a5e7
movl -0x30(%rbp), %edi
callq 0xca4da
movl -0x30(%rbp), %edi
leaq 0x26cd6f(%rip), %rcx    # 0x2f7354
orl %eax, (%rcx)
movss -0x34(%rbp), %xmm0
ucomiss 0x6cb1d(%rip), %xmm0    # 0xf7110
leaq 0x26cd56(%rip), %rbx    # 0x2f7350
jmp 0x8a798
imulq $0x348, %rcx, %rcx      # imm = 0x348
leaq 0x19e9a3(%rip), %rdx    # 0x228fb0
movsd %xmm2, 0xc8(%rdx,%rcx)
movss %xmm0, -0x34(%rbp)
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xc0(%rdx,%rcx)
cvtsi2ss %eax, %xmm0
movsd %xmm1, 0xb8(%rdx,%rcx)
movl %ebx, 0xe8(%rdx,%rcx)
movss %xmm0, 0xb0(%rdx,%rcx)
testb %al, %al
movsd %xmm1, -0x40(%rbp)
je 0x8a671
movl -0x30(%rbp), %edi
movsd %xmm2, -0x48(%rbp)
callq 0xca4da
movsd -0x48(%rbp), %xmm2
movsd -0x40(%rbp), %xmm1
movl -0x30(%rbp), %edi
leaq 0x26ccfd(%rip), %rcx    # 0x2f736c
orl %eax, (%rcx)
ucomisd 0x68a9f(%rip), %xmm2    # 0xf3118
jne 0x8a67d
jnp 0x8a696
movl -0x30(%rbp), %edi
callq 0xca4da
movsd -0x40(%rbp), %xmm1
movl -0x30(%rbp), %edi
leaq 0x26ccd4(%rip), %rcx    # 0x2f7368
orl %eax, (%rcx)
ucomisd 0x68a7a(%rip), %xmm1    # 0xf3118
jne 0x8a6a2
jnp 0x8a6b6
movl -0x30(%rbp), %edi
callq 0xca4da
movl -0x30(%rbp), %edi
leaq 0x26ccb0(%rip), %rcx    # 0x2f7364
orl %eax, (%rcx)
movss -0x34(%rbp), %xmm0
ucomiss 0x6ca4e(%rip), %xmm0    # 0xf7110
leaq 0x26cc97(%rip), %rbx    # 0x2f7360
jmp 0x8a798
imulq $0x348, %rcx, %rcx      # imm = 0x348
leaq 0x19e8d4(%rip), %rdx    # 0x228fb0
movsd %xmm2, 0x108(%rdx,%rcx)
movss %xmm0, -0x34(%rbp)
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x100(%rdx,%rcx)
cvtsi2ss %eax, %xmm0
movsd %xmm1, 0xf8(%rdx,%rcx)
movl %ebx, 0x128(%rdx,%rcx)
movss %xmm0, 0xf0(%rdx,%rcx)
testb %al, %al
movsd %xmm1, -0x40(%rbp)
je 0x8a740
movl -0x30(%rbp), %edi
movsd %xmm2, -0x48(%rbp)
callq 0xca4da
movsd -0x48(%rbp), %xmm2
movsd -0x40(%rbp), %xmm1
movl -0x30(%rbp), %edi
leaq 0x26cc3e(%rip), %rcx    # 0x2f737c
orl %eax, (%rcx)
ucomisd 0x689d0(%rip), %xmm2    # 0xf3118
jne 0x8a74c
jnp 0x8a765
movl -0x30(%rbp), %edi
callq 0xca4da
movsd -0x40(%rbp), %xmm1
movl -0x30(%rbp), %edi
leaq 0x26cc15(%rip), %rcx    # 0x2f7378
orl %eax, (%rcx)
ucomisd 0x689ab(%rip), %xmm1    # 0xf3118
jne 0x8a771
jnp 0x8a785
movl -0x30(%rbp), %edi
callq 0xca4da
movl -0x30(%rbp), %edi
leaq 0x26cbf1(%rip), %rcx    # 0x2f7374
orl %eax, (%rcx)
movss -0x34(%rbp), %xmm0
ucomiss 0x6c97f(%rip), %xmm0    # 0xf7110
leaq 0x26cbd8(%rip), %rbx    # 0x2f7370
jne 0x8a7a0
jnp 0x8a349
callq 0xca4da
orl %eax, (%rbx)
jmp 0x8a349