// File: 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
subq $0x60, %rsp
movl %edi, -0x4(%rbp)
cmpl $0x6, -0x4(%rbp)
jne 0xd2fcf
leaq 0xb5020(%rip), %rdi     # 0x187fe8
callq 0x7add0
jmp 0xd2ff1
cmpl $0x8, -0x4(%rbp)
jne 0xd2fe3
leaq 0xb5028(%rip), %rdi     # 0x188004
callq 0x7add0
jmp 0xd2fef
leaq 0xb5036(%rip), %rdi     # 0x188020
callq 0x7add0
jmp 0xd2ff1
cmpl $0x6, -0x4(%rbp)
jne 0xd3008
leaq 0x2993e6(%rip), %rax    # 0x36c3e4
cmpl $0x0, (%rax)
je 0xd3008
jmp 0xd33ac
movl -0x4(%rbp), %ecx
leaq 0x2993ee(%rip), %rax    # 0x36c400
movl %ecx, (%rax)
movl -0x4(%rbp), %eax
leaq 0x1a71e6(%rip), %rcx    # 0x27a204
cmpl (%rcx), %eax
je 0xd3033
movl -0x4(%rbp), %ecx
leaq 0x1a71d8(%rip), %rax    # 0x27a204
movl %ecx, (%rax)
callq 0x63c20
callq 0x7a560
movzwl %ax, %eax
shll $0x8, %eax
movl %eax, -0x8(%rbp)
callq 0x7a510
movzbl %al, %ecx
movl -0x8(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x8(%rbp)
callq 0x7a680
movl %eax, %eax
cvtsi2sd %rax, %xmm0
movsd 0x9bfc3(%rip), %xmm1    # 0x16f028
divsd %xmm1, %xmm0
leaq 0x2996e8(%rip), %rax    # 0x36c758
movsd %xmm0, (%rax)
movl -0x8(%rbp), %eax
cvtsi2sd %rax, %xmm0
leaq 0x2996d5(%rip), %rax    # 0x36c758
addsd (%rax), %xmm0
leaq 0x2996ca(%rip), %rax    # 0x36c758
movsd %xmm0, (%rax)
leaq 0x29967f(%rip), %rax    # 0x36c718
movsd (%rax), %xmm0
movsd 0x9e573(%rip), %xmm1    # 0x171618
subsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
movsd -0x18(%rbp), %xmm0
movsd 0x9e5cd(%rip), %xmm1    # 0x171688
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0xc(%rbp)
cvtsi2sdl -0xc(%rbp), %xmm0
movsd 0x9e5b5(%rip), %xmm1    # 0x171688
mulsd %xmm1, %xmm0
movsd 0x9e539(%rip), %xmm1    # 0x171618
addsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
leaq 0x299669(%rip), %rax    # 0x36c758
movsd (%rax), %xmm0
xorl %edx, %edx
movl %edx, %edi
movl %edx, %esi
callq 0x122210
movaps %xmm0, %xmm1
movsd -0x58(%rbp), %xmm0
addsd %xmm1, %xmm0
leaq 0x29963f(%rip), %rax    # 0x36c750
movsd %xmm0, (%rax)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0xd33ac
callq 0x7a510
movzbl %al, %eax
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jg 0xd313e
jmp 0xd339e
cmpl $0x20, -0x20(%rbp)
jle 0xd3149
jmp 0xd339e
callq 0x7a510
movzbl %al, %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
andl $0xc0, %eax
cmpl $0x0, %eax
je 0xd316a
movl $0x80, -0x50(%rbp)
jmp 0xd3171
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %edx
movslq -0x20(%rbp), %rax
imulq $0x348, %rax, %rcx      # imm = 0x348
leaq 0x1cb00a(%rip), %rax    # 0x29e190
movl %edx, 0x68(%rax,%rcx)
callq 0x7a5f0
movl %eax, -0x8(%rbp)
callq 0x7a680
movl %eax, %eax
cvtsi2sd %rax, %xmm0
movsd 0x9be82(%rip), %xmm1    # 0x16f028
divsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movl -0x8(%rbp), %eax
cvtsi2sd %rax, %xmm0
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq 0x299590(%rip), %rax    # 0x36c758
movsd (%rax), %xmm0
subsd -0x30(%rbp), %xmm0
movsd 0x9e40f(%rip), %xmm1    # 0x1715e8
mulsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movslq -0x20(%rbp), %rcx
leaq 0x1cafa3(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
cvtsi2sdl 0x218(%rax), %xmm1
xorps %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jb 0xd3210
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
movslq -0x20(%rbp), %rcx
leaq 0x1caf70(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movsd %xmm0, 0x38(%rax)
movsd -0x38(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xd3241
jp 0xd3241
jmp 0xd325d
movl -0x20(%rbp), %edi
callq 0x12d280
movl %eax, %ecx
leaq 0x2992d6(%rip), %rax    # 0x36c528
orl (%rax), %ecx
leaq 0x2992cd(%rip), %rax    # 0x36c528
movl %ecx, (%rax)
callq 0x7a560
movzwl %ax, %eax
movl %eax, -0x44(%rbp)
callq 0x7a560
movzwl %ax, %eax
movl %eax, -0x48(%rbp)
leaq 0x1ca2f6(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0xd32ae
leaq 0x1a481d(%rip), %rax    # 0x277aa4
cmpb $0x0, (%rax)
je 0xd32ae
leaq 0x1ca2dd(%rip), %rax    # 0x29d570
movq (%rax), %rdi
movl -0x20(%rbp), %edx
movl -0x44(%rbp), %ecx
movl -0x48(%rbp), %r8d
leaq 0xb4d95(%rip), %rsi     # 0x18803c
movb $0x0, %al
callq 0x9550
movl -0x44(%rbp), %eax
cvtsi2sd %rax, %xmm0
movsd 0xafdba(%rip), %xmm1    # 0x183078
mulsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movl -0x48(%rbp), %eax
cvtsi2sd %rax, %xmm0
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd 0xaf84f(%rip), %xmm0    # 0x182b30
mulsd -0x40(%rbp), %xmm0
movsd 0xafd8a(%rip), %xmm1    # 0x183078
divsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movslq -0x20(%rbp), %rcx
leaq 0x1cae8e(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
cvtsi2sdl 0x218(%rax), %xmm1
xorps %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jb 0xd3325
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
movslq -0x20(%rbp), %rcx
leaq 0x1cae5b(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movsd %xmm0, 0x28(%rax)
callq 0x7a5f0
movl %eax, -0x4c(%rbp)
leaq 0x1ca21d(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0xd3399
leaq 0x1a4744(%rip), %rax    # 0x277aa4
cmpb $0x0, (%rax)
je 0xd3399
leaq 0x1ca204(%rip), %rax    # 0x29d570
movq (%rax), %rdi
movsd -0x30(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
movsd -0x38(%rbp), %xmm2
movl -0x4c(%rbp), %edx
leaq 0x1a462c(%rip), %rax    # 0x2779b4
movzbl (%rax), %ecx
leaq 0xb4cbb(%rip), %rsi     # 0x18804d
movb $0x3, %al
callq 0x9550
callq 0x7a560
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xd311c
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)