// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathgps.cpp
// Function: parse_moto_Eg(int)
void parse_moto_Eg(int num_chans)
{
u32 xtow;
int week;
double jd;
int i;
int prn;
int mode;
double sat_tow;
double range;
double phase;
u32 icp;
u32 icp2;
u32 cycles;
int lli;

   // raw measurement data
   if(num_chans == 6)      log_packet_id("6-chan raw observation info");
   else if(num_chans == 8) log_packet_id("8-chan raw observation info");
   else                    log_packet_id("unkn-chans observation info");

   if((num_chans == 6) && have_moto_Eg) return;

   have_moto_range = num_chans;
   if(num_chans != moto_chans) {
      moto_chans = num_chans;
      config_msg_ofs();
   }

   xtow = tsip_word() * 256;
   xtow += tsip_byte();
   obs_tow = ((double) tsip_dword()) / 1.0E9;
   obs_tow += (double) xtow;

   jd = jd_gps - GPS_EPOCH;   // !!!! will this work
   week = (int) (jd / 7.0);
   jd_obs = GPS_EPOCH + ((double) week * 7.0) + jtime(0,0,0,obs_tow);

   for(i=0; i<num_chans; i++) {
      prn = tsip_byte();
      if(prn <= 0) continue;
      if(prn > 32) continue;

      mode = tsip_byte();
      if(mode & 0xC0) lli = LOCK_LOST;
      else            lli = 0;
      sat[prn].ca_lli = lli;

      xtow = tsip_tbyte();
      sat_tow = ((double) tsip_dword()) / 1.0E9;
      sat_tow += (double) xtow;

      range = (obs_tow - sat_tow) * (LIGHTSPEED*1000.0);  // !!!!! fix end-of-week rollover
if(sat[prn].tracking <= 0.0) range = 0.0;
      sat[prn].range = range;  
      if(range) {
         have_range |= rinex_gnss(prn);
      }

      icp = (u32) (u16) tsip_word();  // raw carrier phase
      icp2 = (u32) (u16) tsip_word();
if(debug_file && show_debug_info) fprintf(debug_file, "@@Eg %2d: %u %u ", prn, icp,icp2);
      phase = ((double) icp) * 65536.0;
      phase += (double) icp2;

      phase = phase * 360.0 / 65536.0;  // in degrees
//phase = phase / 360.0; 
if(sat[prn].tracking <= 0.0) phase = 0.0;
      sat[prn].code_phase = phase;
      if(0 && phase) { 
         have_phase |= rinex_gnss(prn);
      }

      cycles = tsip_tbyte(); // raw code phase
if(debug_file && show_debug_info) fprintf(debug_file, "tow:%.3f  phase:%.3f  range:%.3f  cycles:%d  endian:%d\n", sat_tow, phase, range, cycles, ENDIAN);
      tsip_word(); // code discriminator
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edi, %r14d
cmpl $0x6, %edi
je 0x9b3b7
cmpl $0x8, %r14d
jne 0x9b3d5
leaq 0x89963(%rip), %rdi     # 0x124d18
jmp 0x9b3dc
leaq 0x8993e(%rip), %rdi     # 0x124cfc
callq 0x58dc2
leaq 0x271e3a(%rip), %rax    # 0x30d204
cmpl $0x0, (%rax)
jne 0x9b69d
jmp 0x9b3e1
leaq 0x89958(%rip), %rdi     # 0x124d34
callq 0x58dc2
leaq 0x271e38(%rip), %rax    # 0x30d220
movl %r14d, (%rax)
leaq 0x17fc32(%rip), %rax    # 0x21b024
cmpl %r14d, (%rax)
je 0x9b3ff
movl %r14d, (%rax)
callq 0x4771f
callq 0x588d2
movzwl %ax, %ebx
shll $0x8, %ebx
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x9b420
leaq 0x1a3b53(%rip), %rcx    # 0x23ef70
orb $0x8, (%rcx)
movzbl %al, %eax
orl %eax, %ebx
callq 0x58964
movl %eax, %eax
cvtsi2sd %rax, %xmm1
divsd 0x6dbef(%rip), %xmm1    # 0x109028
cvtsi2sd %ebx, %xmm0
addsd %xmm1, %xmm0
leaq 0x272130(%rip), %rcx    # 0x30d578
leaq 0x2720e9(%rip), %rax    # 0x30d538
movsd (%rax), %xmm1
addsd 0x70435(%rip), %xmm1    # 0x10b890
movsd 0x704a5(%rip), %xmm2    # 0x10b908
divsd %xmm2, %xmm1
cvttpd2dq %xmm1, %xmm1
cvtdq2pd %xmm1, %xmm1
movsd %xmm0, (%rcx)
mulsd %xmm2, %xmm1
addsd 0x70419(%rip), %xmm1    # 0x10b898
movapd %xmm1, -0x40(%rbp)
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0xd492e
addsd -0x40(%rbp), %xmm0
leaq 0x2720d5(%rip), %rax    # 0x30d570
movsd %xmm0, (%rax)
testl %r14d, %r14d
jle 0x9b69d
leaq 0x1a2ee1(%rip), %r13    # 0x23e390
leaq 0x1a3aba(%rip), %r15    # 0x23ef70
xorl %ebx, %ebx
movl %r14d, -0x2c(%rbp)
callq 0x587be
movl %eax, %r12d
cmpl $0x100, %eax            # imm = 0x100
jb 0x9b4cf
orb $0x8, (%r15)
leal -0x21(%r12), %eax
cmpb $-0x20, %al
jb 0x9b692
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x9b4ec
orb $0x8, (%r15)
movzbl %r12b, %edx
xorl %ecx, %ecx
testb $-0x40, %al
setne %cl
shll $0x7, %ecx
movl %edx, -0x40(%rbp)
movl %edx, %eax
imulq $0x348, %rax, %rax      # imm = 0x348
leaq 0x1a3aa3(%rip), %rdx    # 0x23efb0
leaq (%rdx,%rax), %r12
movl %ecx, 0x68(%rdx,%rax)
movl $0x3, %r14d
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x9b52b
orb $0x20, (%r15)
decq %r14
jne 0x9b51b
callq 0x58964
movl %eax, %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
divsd 0x6dae1(%rip), %xmm1    # 0x109028
leaq 0x27202a(%rip), %rax    # 0x30d578
movsd (%rax), %xmm0
movsd %xmm1, -0x50(%rbp)
subsd %xmm1, %xmm0
mulsd 0x7030d(%rip), %xmm0    # 0x10b870
cmpl $0x0, 0x218(%r12)
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
jle 0x9b57a
movapd %xmm0, %xmm2
movsd %xmm2, 0x38(%r12)
movsd %xmm2, -0x48(%rbp)
ucomisd %xmm1, %xmm2
jne 0x9b58e
jnp 0x9b59f
movl -0x40(%rbp), %edi
callq 0xdc1dd
leaq 0x271dab(%rip), %rcx    # 0x30d348
orl %eax, (%rcx)
callq 0x588d2
movl %eax, %r14d
callq 0x588d2
movq (%r13), %rdi
movzwl %ax, %r13d
movzwl %r14w, %r14d
testq %rdi, %rdi
je 0x9b5e0
leaq 0x17d300(%rip), %rax    # 0x2188c4
cmpb $0x0, (%rax)
je 0x9b5e0
leaq 0x89780(%rip), %rsi     # 0x124d50
movl -0x40(%rbp), %edx
movl %r14d, %ecx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x9560
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
mulsd 0x831b8(%rip), %xmm1    # 0x11e7a8
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
addsd %xmm1, %xmm0
mulsd 0x82b34(%rip), %xmm0    # 0x11e138
mulsd 0x831a4(%rip), %xmm0    # 0x11e7b0
cmpl $0x0, 0x218(%r12)
xorpd %xmm1, %xmm1
jle 0x9b61f
movapd %xmm0, %xmm1
movsd %xmm1, -0x40(%rbp)
movsd %xmm1, 0x28(%r12)
movl $0x3, %r14d
leaq 0x1a2d58(%rip), %r13    # 0x23e390
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x9b648
orb $0x20, (%r15)
decq %r14
jne 0x9b638
movq (%r13), %rdi
testq %rdi, %rdi
je 0x9b689
leaq 0x17d267(%rip), %rax    # 0x2188c4
cmpb $0x0, (%rax)
je 0x9b689
leaq 0x17d16b(%rip), %rax    # 0x2187d4
movzbl (%rax), %ecx
leaq 0x896ee(%rip), %rsi     # 0x124d61
movsd -0x50(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
movsd -0x48(%rbp), %xmm2
movb $0x3, %al
callq 0x9560
callq 0x588d2
movl -0x2c(%rbp), %r14d
incl %ebx
cmpl %r14d, %ebx
jne 0x9b4bc
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq