// File: /workspace/github_cpp_makefile_star2_O1/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 0x8c7fa(%rip), %rdi     # 0x1249f3
callq 0x58e77
leaq 0x2a5bef(%rip), %rax    # 0x33ddf4
orb $0x10, (%rax)
leaq 0x274fc9(%rip), %rax    # 0x30d1d8
andb $-0x9, (%rax)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x98228
leaq 0x1a6d4b(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x9823e
leaq 0x1a6d35(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x588f0
movl %eax, %ebx
callq 0x589b0
movl %eax, %r14d
callq 0x588f0
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x98268
leaq 0x1a6d0b(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x9827e
leaq 0x1a6cf5(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x587d1
movl %eax, %ecx
cmpl $0x100, %eax            # imm = 0x100
jb 0x98296
leaq 0x1a6cdd(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
leaq 0x1830db(%rip), %rax    # 0x21b378
movl (%rax), %edx
testl %edx, %edx
je 0x987ec
cvtsi2sd %r14d, %xmm0
divsd 0x70d84(%rip), %xmm0    # 0x109038
leaq 0x18309d(%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 0x987ec
movzbl %cl, %r12d
leaq 0x275288(%rip), %rax    # 0x30d578
movsd %xmm0, (%rax)
movzwl %bx, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd 0x735fa(%rip), %xmm1    # 0x10b900
addsd 0x7357a(%rip), %xmm1    # 0x10b888
movsd %xmm1, -0x38(%rbp)
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0xd41e0
addsd -0x38(%rbp), %xmm0
leaq 0x275246(%rip), %rax    # 0x30d570
movsd %xmm0, (%rax)
testl %r12d, %r12d
je 0x987ec
leaq 0x1a6c32(%rip), %r13    # 0x23ef70
callq 0x587d1
movl %eax, %r14d
cmpl $0x100, %eax            # imm = 0x100
jb 0x98352
orb $0x8, (%r13)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x98363
orb $0x8, (%r13)
movl %r14d, %ecx
andl $0xf, %ecx
cmpl $0x5, %ecx
ja 0x98388
movzbl %al, %ebx
movl %ecx, %eax
leaq 0x873d6(%rip), %rcx     # 0x11f750
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
addl $0x40, %ebx
jmp 0x9839a
xorl %ebx, %ebx
jmp 0x9839a
addl $0x12c, %ebx            # imm = 0x12C
jmp 0x9839a
addl $0xc8, %ebx
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x983ab
orb $0x8, (%r13)
callq 0x587d1
movl %eax, %r15d
cmpl $0x100, %eax            # imm = 0x100
jb 0x983bf
orb $0x8, (%r13)
callq 0x58b86
movsd %xmm0, -0x40(%rbp)
callq 0x58b86
movsd %xmm0, -0x38(%rbp)
callq 0x58aae
movss %xmm0, -0x2c(%rbp)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x983ee
orb $0x8, (%r13)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x983ff
orb $0x8, (%r13)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x98410
orb $0x8, (%r13)
callq 0x588f0
movzwl %ax, %r13d
callq 0x588f0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
testb $0x1, %r13b
je 0x98431
movsd -0x40(%rbp), %xmm2
xorpd %xmm0, %xmm0
testb $0x2, %r13b
je 0x98440
movss -0x2c(%rbp), %xmm0
testb $0x4, %r13b
je 0x9844b
movsd -0x38(%rbp), %xmm1
testl %ebx, %ebx
jle 0x987dc
andl $0x8, %r13d
shll $0x4, %r13d
testb $-0x10, %r14b
je 0x98553
shrl $0x4, %r14d
andl $0xf, %r14d
cmpl $0x4, %r14d
je 0x98706
cmpl $0x2, %r14d
je 0x98638
cmpl $0x1, %r14d
jne 0x987dc
movl %ebx, %eax
imulq $0x348, %rax, %rax      # imm = 0x348
leaq 0x1a6b15(%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 0x984fe
movl %ebx, %edi
movsd %xmm2, -0x40(%rbp)
callq 0xdbb74
movsd -0x40(%rbp), %xmm2
movsd -0x38(%rbp), %xmm1
leaq 0x274e60(%rip), %rcx    # 0x30d35c
orl %eax, (%rcx)
ucomisd 0x70c12(%rip), %xmm2    # 0x109118
jne 0x9850a
jnp 0x9851f
movl %ebx, %edi
callq 0xdbb74
movsd -0x38(%rbp), %xmm1
leaq 0x274e3b(%rip), %rcx    # 0x30d358
orl %eax, (%rcx)
ucomisd 0x70bf1(%rip), %xmm1    # 0x109118
jne 0x9852b
jnp 0x9853b
movl %ebx, %edi
callq 0xdbb74
leaq 0x274e1b(%rip), %rcx    # 0x30d354
orl %eax, (%rcx)
movss -0x2c(%rbp), %xmm0
ucomiss 0x74ab5(%rip), %xmm0    # 0x10cffc
leaq 0x274e02(%rip), %r14    # 0x30d350
jmp 0x987ce
movl %ebx, %eax
imulq $0x348, %rax, %rax      # imm = 0x348
leaq 0x1a6a4d(%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 0x985bd
movl %ebx, %edi
movsd %xmm2, -0x40(%rbp)
callq 0xdbb74
movsd -0x40(%rbp), %xmm2
movsd -0x38(%rbp), %xmm1
leaq 0x274d91(%rip), %rcx    # 0x30d34c
orl %eax, (%rcx)
ucomisd 0x70b53(%rip), %xmm2    # 0x109118
jne 0x985c9
jnp 0x985de
movl %ebx, %edi
callq 0xdbb74
movsd -0x38(%rbp), %xmm1
leaq 0x274d6c(%rip), %rcx    # 0x30d348
orl %eax, (%rcx)
ucomisd 0x70b32(%rip), %xmm1    # 0x109118
jne 0x985ea
jnp 0x985fa
movl %ebx, %edi
callq 0xdbb74
leaq 0x274d4c(%rip), %rcx    # 0x30d344
orl %eax, (%rcx)
movss -0x2c(%rbp), %xmm0
ucomiss 0x749f6(%rip), %xmm0    # 0x10cffc
jne 0x9860e
jnp 0x987dc
leaq 0x274d2b(%rip), %r14    # 0x30d340
cmpl $0x0, (%r14)
jne 0x987d2
leaq 0x18021e(%rip), %rax    # 0x218844
movl $0x7e2, (%rax)          # imm = 0x7E2
leaq 0x274d0d(%rip), %r14    # 0x30d340
jmp 0x987d2
movl %ebx, %eax
imulq $0x348, %rax, %rax      # imm = 0x348
leaq 0x1a6968(%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 0x986b1
movl %ebx, %edi
movsd %xmm2, -0x40(%rbp)
callq 0xdbb74
movsd -0x40(%rbp), %xmm2
movsd -0x38(%rbp), %xmm1
leaq 0x274cbd(%rip), %rcx    # 0x30d36c
orl %eax, (%rcx)
ucomisd 0x70a5f(%rip), %xmm2    # 0x109118
jne 0x986bd
jnp 0x986d2
movl %ebx, %edi
callq 0xdbb74
movsd -0x38(%rbp), %xmm1
leaq 0x274c98(%rip), %rcx    # 0x30d368
orl %eax, (%rcx)
ucomisd 0x70a3e(%rip), %xmm1    # 0x109118
jne 0x986de
jnp 0x986ee
movl %ebx, %edi
callq 0xdbb74
leaq 0x274c78(%rip), %rcx    # 0x30d364
orl %eax, (%rcx)
movss -0x2c(%rbp), %xmm0
ucomiss 0x74902(%rip), %xmm0    # 0x10cffc
leaq 0x274c5f(%rip), %r14    # 0x30d360
jmp 0x987ce
movl %ebx, %eax
imulq $0x348, %rax, %rax      # imm = 0x348
leaq 0x1a689a(%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 0x9877e
movl %ebx, %edi
movsd %xmm2, -0x40(%rbp)
callq 0xdbb74
movsd -0x40(%rbp), %xmm2
movsd -0x38(%rbp), %xmm1
leaq 0x274c00(%rip), %rcx    # 0x30d37c
orl %eax, (%rcx)
ucomisd 0x70992(%rip), %xmm2    # 0x109118
jne 0x9878a
jnp 0x9879f
movl %ebx, %edi
callq 0xdbb74
movsd -0x38(%rbp), %xmm1
leaq 0x274bdb(%rip), %rcx    # 0x30d378
orl %eax, (%rcx)
ucomisd 0x70971(%rip), %xmm1    # 0x109118
jne 0x987ab
jnp 0x987bb
movl %ebx, %edi
callq 0xdbb74
leaq 0x274bbb(%rip), %rcx    # 0x30d374
orl %eax, (%rcx)
movss -0x2c(%rbp), %xmm0
ucomiss 0x74835(%rip), %xmm0    # 0x10cffc
leaq 0x274ba2(%rip), %r14    # 0x30d370
jne 0x987d2
jnp 0x987dc
movl %ebx, %edi
callq 0xdbb74
orl %eax, (%r14)
decl %r12d
leaq 0x1a678a(%rip), %r13    # 0x23ef70
jne 0x9833e
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq