// File: /workspace/github_cpp_makefile_star2_O1/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, %ebx
cmpl $0x8, %edi
leaq 0x89a45(%rip), %rax     # 0x124c38
leaq 0x89a5a(%rip), %rcx     # 0x124c54
cmoveq %rax, %rcx
cmpl $0x6, %edi
leaq 0x89a14(%rip), %rdi     # 0x124c1c
cmovneq %rcx, %rdi
callq 0x58e77
cmpl $0x6, %ebx
jne 0x9b226
leaq 0x271fe7(%rip), %rax    # 0x30d204
cmpl $0x0, (%rax)
jne 0x9b4c8
leaq 0x271ff3(%rip), %rax    # 0x30d220
movl %ebx, (%rax)
leaq 0x17fdee(%rip), %rax    # 0x21b024
cmpl %ebx, (%rax)
je 0x9b241
movl %ebx, (%rax)
callq 0x47650
callq 0x588f0
movzwl %ax, %r14d
shll $0x8, %r14d
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x9b264
leaq 0x1a3d0f(%rip), %rcx    # 0x23ef70
orb $0x8, (%rcx)
movzbl %al, %eax
orl %eax, %r14d
callq 0x589b0
movl %eax, %eax
cvtsi2sd %rax, %xmm1
divsd 0x6ddaa(%rip), %xmm1    # 0x109028
cvtsi2sd %r14d, %xmm0
addsd %xmm1, %xmm0
leaq 0x2722ea(%rip), %rcx    # 0x30d578
leaq 0x2722a3(%rip), %rax    # 0x30d538
movsd (%rax), %xmm1
addsd 0x705df(%rip), %xmm1    # 0x10b880
movsd 0x70657(%rip), %xmm2    # 0x10b900
divsd %xmm2, %xmm1
cvttpd2dq %xmm1, %xmm1
cvtdq2pd %xmm1, %xmm1
movsd %xmm0, (%rcx)
mulsd %xmm2, %xmm1
addsd 0x705c3(%rip), %xmm1    # 0x10b888
movapd %xmm1, -0x40(%rbp)
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0xd41e0
addsd -0x40(%rbp), %xmm0
leaq 0x27228f(%rip), %rax    # 0x30d570
movsd %xmm0, (%rax)
testl %ebx, %ebx
jle 0x9b4c8
callq 0x587d1
movl %eax, %r12d
cmpl $0x100, %eax            # imm = 0x100
jb 0x9b306
leaq 0x1a3c6d(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
leal -0x21(%r12), %eax
cmpb $-0x20, %al
jb 0x9b4c0
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x9b329
leaq 0x1a3c4a(%rip), %rcx    # 0x23ef70
orb $0x8, (%rcx)
xorl %ecx, %ecx
testb $-0x40, %al
setne %cl
shll $0x7, %ecx
movzbl %r12b, %eax
imulq $0x348, %rax, %r15      # imm = 0x348
leaq 0x1a3c6b(%rip), %r13    # 0x23efb0
movl %ecx, 0x68(%r13,%r15)
callq 0x58952
movl %eax, %r14d
callq 0x589b0
movl %eax, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x6dcbf(%rip), %xmm0    # 0x109028
movl %r14d, %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
addsd %xmm0, %xmm1
leaq 0x2721f9(%rip), %rax    # 0x30d578
movsd (%rax), %xmm0
movsd %xmm1, -0x40(%rbp)
subsd %xmm1, %xmm0
mulsd 0x704cc(%rip), %xmm0    # 0x10b860
cmpl $0x0, 0x218(%r13,%r15)
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
jle 0x9b3ab
movapd %xmm0, %xmm2
movzbl %r12b, %r12d
leaq 0x1a3bfa(%rip), %rax    # 0x23efb0
movsd %xmm2, 0x38(%rax,%r15)
movsd %xmm2, -0x50(%rbp)
ucomisd %xmm1, %xmm2
jne 0x9b3ca
jnp 0x9b3db
movl %r12d, %edi
callq 0xdbb74
leaq 0x271f6f(%rip), %rcx    # 0x30d348
orl %eax, (%rcx)
callq 0x588f0
movl %eax, %r14d
callq 0x588f0
leaq 0x1a2fa1(%rip), %rcx    # 0x23e390
movq (%rcx), %rdi
movzwl %ax, %r13d
movzwl %r14w, %r14d
testq %rdi, %rdi
je 0x9b422
leaq 0x17d4be(%rip), %rax    # 0x2188c4
cmpb $0x0, (%rax)
je 0x9b422
leaq 0x8985e(%rip), %rsi     # 0x124c70
movl %r12d, %edx
movl %r14d, %ecx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x9560
addq 0xb4b17(%rip), %r15     # 0x14ff40
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
mulsd 0x832bf(%rip), %xmm1    # 0x11e6f8
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
addsd %xmm1, %xmm0
mulsd 0x82c43(%rip), %xmm0    # 0x11e090
mulsd 0x832ab(%rip), %xmm0    # 0x11e700
cmpl $0x0, 0x218(%r15)
xorpd %xmm1, %xmm1
jle 0x9b467
movapd %xmm0, %xmm1
movsd %xmm1, -0x48(%rbp)
movsd %xmm1, 0x28(%r15)
callq 0x58952
leaq 0x1a2f12(%rip), %rcx    # 0x23e390
movq (%rcx), %rdi
testq %rdi, %rdi
je 0x9b4bb
leaq 0x17d437(%rip), %rcx    # 0x2188c4
cmpb $0x0, (%rcx)
je 0x9b4bb
leaq 0x17d33b(%rip), %rcx    # 0x2187d4
movzbl (%rcx), %ecx
leaq 0x897de(%rip), %rsi     # 0x124c81
movsd -0x40(%rbp), %xmm0
movsd -0x48(%rbp), %xmm1
movsd -0x50(%rbp), %xmm2
movl %eax, %edx
movb $0x3, %al
callq 0x9560
callq 0x588f0
decl %ebx
jne 0x9b2ed
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq