// File: /workspace/github_cpp_makefile_star2_O3/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 $0x18, %rsp
leaq 0x8c7ce(%rip), %rdi     # 0x124ad3
callq 0x58dc2
leaq 0x2a5ae3(%rip), %rax    # 0x33ddf4
orb $0x10, (%rax)
leaq 0x274ebd(%rip), %rax    # 0x30d1d8
andb $-0x9, (%rax)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x98334
leaq 0x1a6c3f(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x9834a
leaq 0x1a6c29(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x588d2
movl %eax, %ebx
callq 0x58964
movl %eax, %r14d
callq 0x588d2
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x98374
leaq 0x1a6bff(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x9838a
leaq 0x1a6be9(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x587be
movl %eax, %ecx
cmpl $0x100, %eax            # imm = 0x100
jb 0x983a2
leaq 0x1a6bd1(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
leaq 0x182fcf(%rip), %rax    # 0x21b378
movl (%rax), %edx
testl %edx, %edx
je 0x988f8
cvtsi2sd %r14d, %xmm0
divsd 0x70c78(%rip), %xmm0    # 0x109038
leaq 0x182f91(%rip), %rax    # 0x21b358
movsd (%rax), %xmm1
movapd %xmm0, %xmm2
mulsd %xmm1, %xmm2
cvttsd2si %xmm2, %eax
xorps %xmm2, %xmm2
cvtsi2sd %edx, %xmm2
mulsd %xmm1, %xmm2
cvttsd2si %xmm2, %esi
cltd
idivl %esi
testl %edx, %edx
jne 0x988f8
movzbl %cl, %r12d
leaq 0x27517c(%rip), %rax    # 0x30d578
movsd %xmm0, (%rax)
movzwl %bx, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd 0x734f6(%rip), %xmm1    # 0x10b908
addsd 0x7347e(%rip), %xmm1    # 0x10b898
movsd %xmm1, -0x38(%rbp)
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0xd492e
addsd -0x38(%rbp), %xmm0
leaq 0x27513a(%rip), %rax    # 0x30d570
movsd %xmm0, (%rax)
testl %r12d, %r12d
je 0x988f8
leaq 0x1a6b26(%rip), %r13    # 0x23ef70
callq 0x587be
movl %eax, %r14d
cmpl $0x100, %eax            # imm = 0x100
jb 0x9845e
orb $0x8, (%r13)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x9846f
orb $0x8, (%r13)
movl %r14d, %ecx
andl $0xf, %ecx
cmpl $0x5, %ecx
ja 0x98494
movzbl %al, %ebx
movl %ecx, %eax
leaq 0x873a2(%rip), %rcx     # 0x11f828
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
addl $0x40, %ebx
jmp 0x984a6
xorl %ebx, %ebx
jmp 0x984a6
addl $0x12c, %ebx            # imm = 0x12C
jmp 0x984a6
addl $0xc8, %ebx
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x984b7
orb $0x8, (%r13)
callq 0x587be
movl %eax, %r15d
cmpl $0x100, %eax            # imm = 0x100
jb 0x984cb
orb $0x8, (%r13)
callq 0x58b08
movsd %xmm0, -0x40(%rbp)
callq 0x58b08
movsd %xmm0, -0x38(%rbp)
callq 0x58a30
movss %xmm0, -0x2c(%rbp)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x984fa
orb $0x8, (%r13)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x9850b
orb $0x8, (%r13)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x9851c
orb $0x8, (%r13)
callq 0x588d2
movzwl %ax, %r13d
callq 0x588d2
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
testb $0x1, %r13b
je 0x9853d
movsd -0x40(%rbp), %xmm2
xorpd %xmm0, %xmm0
testb $0x2, %r13b
je 0x9854c
movss -0x2c(%rbp), %xmm0
testb $0x4, %r13b
je 0x98557
movsd -0x38(%rbp), %xmm1
testl %ebx, %ebx
je 0x988e8
andl $0x8, %r13d
shll $0x4, %r13d
testb $-0x10, %r14b
je 0x9865f
shrl $0x4, %r14d
andl $0xf, %r14d
cmpl $0x4, %r14d
je 0x98812
cmpl $0x2, %r14d
je 0x98744
cmpl $0x1, %r14d
jne 0x988e8
movl %ebx, %eax
imulq $0x348, %rax, %rax      # imm = 0x348
leaq 0x1a6a09(%rip), %rdx    # 0x23efb0
movsd %xmm2, 0x88(%rdx,%rax)
movss %xmm0, -0x2c(%rbp)
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x80(%rdx,%rax)
movzbl %r15b, %ecx
xorps %xmm0, %xmm0
cvtsi2ss %ecx, %xmm0
movsd %xmm1, 0x78(%rdx,%rax)
movl %r13d, 0xa8(%rdx,%rax)
movss %xmm0, 0x70(%rdx,%rax)
testb %r15b, %r15b
movsd %xmm1, -0x38(%rbp)
je 0x9860a
movl %ebx, %edi
movsd %xmm2, -0x40(%rbp)
callq 0xdc1dd
movsd -0x40(%rbp), %xmm2
movsd -0x38(%rbp), %xmm1
leaq 0x274d54(%rip), %rcx    # 0x30d35c
orl %eax, (%rcx)
ucomisd 0x70b06(%rip), %xmm2    # 0x109118
jne 0x98616
jnp 0x9862b
movl %ebx, %edi
callq 0xdc1dd
movsd -0x38(%rbp), %xmm1
leaq 0x274d2f(%rip), %rcx    # 0x30d358
orl %eax, (%rcx)
ucomisd 0x70ae5(%rip), %xmm1    # 0x109118
jne 0x98637
jnp 0x98647
movl %ebx, %edi
callq 0xdc1dd
leaq 0x274d0f(%rip), %rcx    # 0x30d354
orl %eax, (%rcx)
movss -0x2c(%rbp), %xmm0
ucomiss 0x74a3d(%rip), %xmm0    # 0x10d090
leaq 0x274cf6(%rip), %r14    # 0x30d350
jmp 0x988da
movl %ebx, %eax
imulq $0x348, %rax, %rax      # imm = 0x348
leaq 0x1a6941(%rip), %rdx    # 0x23efb0
movsd %xmm2, 0x38(%rdx,%rax)
movss %xmm0, -0x2c(%rbp)
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x30(%rdx,%rax)
movzbl %r15b, %ecx
xorps %xmm0, %xmm0
cvtsi2ss %ecx, %xmm0
movsd %xmm1, 0x28(%rdx,%rax)
movl %r13d, 0x68(%rdx,%rax)
movss %xmm0, 0x20(%rdx,%rax)
testb %r15b, %r15b
movsd %xmm1, -0x38(%rbp)
je 0x986c9
movl %ebx, %edi
movsd %xmm2, -0x40(%rbp)
callq 0xdc1dd
movsd -0x40(%rbp), %xmm2
movsd -0x38(%rbp), %xmm1
leaq 0x274c85(%rip), %rcx    # 0x30d34c
orl %eax, (%rcx)
ucomisd 0x70a47(%rip), %xmm2    # 0x109118
jne 0x986d5
jnp 0x986ea
movl %ebx, %edi
callq 0xdc1dd
movsd -0x38(%rbp), %xmm1
leaq 0x274c60(%rip), %rcx    # 0x30d348
orl %eax, (%rcx)
ucomisd 0x70a26(%rip), %xmm1    # 0x109118
jne 0x986f6
jnp 0x98706
movl %ebx, %edi
callq 0xdc1dd
leaq 0x274c40(%rip), %rcx    # 0x30d344
orl %eax, (%rcx)
movss -0x2c(%rbp), %xmm0
ucomiss 0x7497e(%rip), %xmm0    # 0x10d090
jne 0x9871a
jnp 0x988e8
leaq 0x274c1f(%rip), %r14    # 0x30d340
cmpl $0x0, (%r14)
jne 0x988de
leaq 0x180112(%rip), %rax    # 0x218844
movl $0x7e2, (%rax)          # imm = 0x7E2
leaq 0x274c01(%rip), %r14    # 0x30d340
jmp 0x988de
movl %ebx, %eax
imulq $0x348, %rax, %rax      # imm = 0x348
leaq 0x1a685c(%rip), %rdx    # 0x23efb0
movsd %xmm2, 0xc8(%rdx,%rax)
movss %xmm0, -0x2c(%rbp)
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xc0(%rdx,%rax)
movzbl %r15b, %ecx
xorps %xmm0, %xmm0
cvtsi2ss %ecx, %xmm0
movsd %xmm1, 0xb8(%rdx,%rax)
movl %r13d, 0xe8(%rdx,%rax)
movss %xmm0, 0xb0(%rdx,%rax)
testb %r15b, %r15b
movsd %xmm1, -0x38(%rbp)
je 0x987bd
movl %ebx, %edi
movsd %xmm2, -0x40(%rbp)
callq 0xdc1dd
movsd -0x40(%rbp), %xmm2
movsd -0x38(%rbp), %xmm1
leaq 0x274bb1(%rip), %rcx    # 0x30d36c
orl %eax, (%rcx)
ucomisd 0x70953(%rip), %xmm2    # 0x109118
jne 0x987c9
jnp 0x987de
movl %ebx, %edi
callq 0xdc1dd
movsd -0x38(%rbp), %xmm1
leaq 0x274b8c(%rip), %rcx    # 0x30d368
orl %eax, (%rcx)
ucomisd 0x70932(%rip), %xmm1    # 0x109118
jne 0x987ea
jnp 0x987fa
movl %ebx, %edi
callq 0xdc1dd
leaq 0x274b6c(%rip), %rcx    # 0x30d364
orl %eax, (%rcx)
movss -0x2c(%rbp), %xmm0
ucomiss 0x7488a(%rip), %xmm0    # 0x10d090
leaq 0x274b53(%rip), %r14    # 0x30d360
jmp 0x988da
movl %ebx, %eax
imulq $0x348, %rax, %rax      # imm = 0x348
leaq 0x1a678e(%rip), %rdx    # 0x23efb0
movsd %xmm2, 0x108(%rdx,%rax)
movss %xmm0, -0x2c(%rbp)
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x100(%rdx,%rax)
movzbl %r15b, %ecx
xorps %xmm0, %xmm0
cvtsi2ss %ecx, %xmm0
movsd %xmm1, 0xf8(%rdx,%rax)
movl %r13d, 0x128(%rdx,%rax)
movss %xmm0, 0xf0(%rdx,%rax)
testb %cl, %cl
movsd %xmm1, -0x38(%rbp)
je 0x9888a
movl %ebx, %edi
movsd %xmm2, -0x40(%rbp)
callq 0xdc1dd
movsd -0x40(%rbp), %xmm2
movsd -0x38(%rbp), %xmm1
leaq 0x274af4(%rip), %rcx    # 0x30d37c
orl %eax, (%rcx)
ucomisd 0x70886(%rip), %xmm2    # 0x109118
jne 0x98896
jnp 0x988ab
movl %ebx, %edi
callq 0xdc1dd
movsd -0x38(%rbp), %xmm1
leaq 0x274acf(%rip), %rcx    # 0x30d378
orl %eax, (%rcx)
ucomisd 0x70865(%rip), %xmm1    # 0x109118
jne 0x988b7
jnp 0x988c7
movl %ebx, %edi
callq 0xdc1dd
leaq 0x274aaf(%rip), %rcx    # 0x30d374
orl %eax, (%rcx)
movss -0x2c(%rbp), %xmm0
ucomiss 0x747bd(%rip), %xmm0    # 0x10d090
leaq 0x274a96(%rip), %r14    # 0x30d370
jne 0x988de
jnp 0x988e8
movl %ebx, %edi
callq 0xdc1dd
orl %eax, (%r14)
decl %r12d
leaq 0x1a667e(%rip), %r13    # 0x23ef70
jne 0x9844a
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq