// File: /workspace/github_cpp_makefile_star2_O2/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 $0x6, %edi
je 0x8cae1
cmpl $0x8, %ebx
jne 0x8cb08
leaq 0x82181(%rip), %rdi     # 0x10ec60
jmp 0x8cb0f
leaq 0x8215c(%rip), %rdi     # 0x10ec44
callq 0x520bf
leaq 0x26a710(%rip), %rax    # 0x2f7204
cmpl $0x0, (%rax)
je 0x8cb14
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8216d(%rip), %rdi     # 0x10ec7c
callq 0x520bf
leaq 0x26a705(%rip), %rax    # 0x2f7220
movl %ebx, (%rax)
leaq 0x178500(%rip), %rax    # 0x205024
cmpl %ebx, (%rax)
je 0x8cb2f
movl %ebx, (%rax)
callq 0x43898
callq 0x51c63
movzwl %ax, %r14d
shll $0x8, %r14d
callq 0x51c47
movzbl %al, %r15d
orl %r14d, %r15d
callq 0x51cf3
movl %eax, %eax
cvtsi2sd %rax, %xmm1
divsd 0x664cc(%rip), %xmm1    # 0xf3028
cvtsi2sd %r15d, %xmm0
addsd %xmm1, %xmm0
leaq 0x26aa0c(%rip), %rcx    # 0x2f7578
leaq 0x26a9c5(%rip), %rax    # 0x2f7538
movsd (%rax), %xmm1
addsd 0x68d89(%rip), %xmm1    # 0xf5908
movsd 0x68df9(%rip), %xmm2    # 0xf5980
divsd %xmm2, %xmm1
cvttpd2dq %xmm1, %xmm1
cvtdq2pd %xmm1, %xmm1
movsd %xmm0, (%rcx)
mulsd %xmm2, %xmm1
addsd 0x68d6d(%rip), %xmm1    # 0xf5910
movapd %xmm1, -0x40(%rbp)
xorl %r14d, %r14d
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0xc2faf
addsd -0x40(%rbp), %xmm0
leaq 0x26a9ae(%rip), %rax    # 0x2f7570
movsd %xmm0, (%rax)
testl %ebx, %ebx
cmovlel %r14d, %ebx
subl $0x1, %ebx
jb 0x8caf9
callq 0x51c47
leal -0x21(%rax), %ecx
cmpb $-0x20, %cl
jb 0x8cbcc
movzbl %al, %r12d
callq 0x51c47
xorl %ecx, %ecx
cmpb $0x40, %al
setae %cl
shll $0x7, %ecx
movl %r12d, %eax
imulq $0x348, %rax, %r15      # imm = 0x348
leaq 0x19c3aa(%rip), %r13    # 0x228fb0
movl %ecx, 0x68(%r13,%r15)
callq 0x51cc5
movl %eax, %r14d
callq 0x51cf3
movl %eax, %eax
cvtsi2sd %rax, %xmm0
divsd 0x66401(%rip), %xmm0    # 0xf3028
movl %r14d, %eax
cvtsi2sd %rax, %xmm1
addsd %xmm0, %xmm1
leaq 0x26a93e(%rip), %rax    # 0x2f7578
movsd (%rax), %xmm0
movsd %xmm1, -0x40(%rbp)
subsd %xmm1, %xmm0
mulsd 0x68c99(%rip), %xmm0    # 0xf58e8
cmpl $0x0, 0x218(%r13,%r15)
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
jle 0x8cc66
movapd %xmm0, %xmm2
leaq 0x19c343(%rip), %rax    # 0x228fb0
movsd %xmm2, 0x38(%rax,%r15)
movsd %xmm2, -0x50(%rbp)
ucomisd %xmm1, %xmm2
jne 0x8cc81
jnp 0x8cc92
movl %r12d, %edi
callq 0xca4da
leaq 0x26a6b8(%rip), %rcx    # 0x2f7348
orl %eax, (%rcx)
callq 0x51c63
movl %eax, %r14d
callq 0x51c63
leaq 0x19b6ea(%rip), %rcx    # 0x228390
movq (%rcx), %rdi
movzwl %ax, %r13d
movzwl %r14w, %r14d
testq %rdi, %rdi
je 0x8ccd9
leaq 0x175c07(%rip), %rax    # 0x2028c4
cmpb $0x0, (%rax)
je 0x8ccd9
leaq 0x81fcf(%rip), %rsi     # 0x10ec98
movl %r12d, %edx
movl %r14d, %ecx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x9560
addq 0xad268(%rip), %r15     # 0x139f48
cvtsi2sd %r14d, %xmm1
mulsd 0x7ba33(%rip), %xmm1    # 0x108720
cvtsi2sd %r13d, %xmm0
addsd %xmm1, %xmm0
mulsd 0x7b4b2(%rip), %xmm0    # 0x1081b0
mulsd 0x7ba22(%rip), %xmm0    # 0x108728
cmpl $0x0, 0x218(%r15)
xorpd %xmm1, %xmm1
jle 0x8cd18
movapd %xmm0, %xmm1
movsd %xmm1, -0x48(%rbp)
movsd %xmm1, 0x28(%r15)
callq 0x51cc5
leaq 0x19b661(%rip), %rcx    # 0x228390
movq (%rcx), %rdi
testq %rdi, %rdi
je 0x8cd6c
leaq 0x175b86(%rip), %rcx    # 0x2028c4
cmpb $0x0, (%rcx)
je 0x8cd6c
leaq 0x175a8a(%rip), %rcx    # 0x2027d4
movzbl (%rcx), %ecx
leaq 0x81f55(%rip), %rsi     # 0x10eca9
movsd -0x40(%rbp), %xmm0
movsd -0x48(%rbp), %xmm1
movsd -0x50(%rbp), %xmm2
movl %eax, %edx
movb $0x3, %al
callq 0x9560
callq 0x51c63
jmp 0x8cbcc