// File: jkingan[P]ladyheather/heathgps.cpp
// Function: parse_rt17_realtime(int)
void parse_rt17_realtime(int rif)
{
double xtow;
double clock;
int sats;
double jd, jd0;
static double last_jd0 = 0.0;

   // parse the rt17 realtime observations data message.
   // This message drives the screen update
   //
   // Claification on the use of the L2 carrier phase and pseudorange fields
   // came from the RTKLIB rt17.c file.

   log_packet_id("Realtime GPS data");
   level_type = "dBc";

   xtow = tsip_double();
   clock = tsip_double();
   sats = tsip_byte();
//sprintf(debug_text, "tow:%.6f  clk:%.6f  sum:%.6f", xtow,clock,xtow+clock);

   if(add_clk_ofs) {  // add receiver clock offset to the GPS time code
      xtow += clock;
   }

   get_clock_time();   // toots - so we can calc the gps week number
   jd0 = clk_jd + jtime(0,0,utc_offset,0.0);  // we are in UTC time, convert to GPS time
   jd0 -= GPS_EPOCH;

   if(1 && (jd0 < last_jd0)) {  // ignore backwards time skips
      last_jd0 = 0.0;
      return;
   }
   last_jd0 = jd0;

   tow = pri_tow = this_tow = survey_tow = (int) ((xtow+500.0)/1000.0);  
   have_tow = 17;

   gps_week = (int) (jd0 / 7.0);
   if(have_week == 0) need_redraw = 2054;
   have_week = 17;

   if(raw_msg_rate) {  // receiver always outputs RAW data at 1 Hz
      if((tow % raw_msg_rate) != 0) goto do_screen;  // drop unwanted messages
   }

   obs_tow = xtow / 1000.0;
   jd_obs = GPS_EPOCH + ((double) gps_week * 7.0) + jtime(0,0,0,obs_tow);

if(debug_file) {
   gregorian(0, jd_obs);
   fprintf(debug_file, "jd_obs gps: %04d/%02d/%02d %02d:%02d:%02d   rif:%02X  sats:%d\n", g_year,g_month,g_day, g_hours,g_minutes,g_seconds, rif,sats);
}

   reset_sat_tracking();
   while(sats--) {
      if(rif & 0x01) {  // concise format (has no L2 doppler)
         rt17_concise(rif);
      }
      else {  // expanded format (has L2 doppler... but NetRS always sends 0!, so why bother)
         rt17_expanded(rif);
      }
   }


   // update the screen
   do_screen:
   jd = xtow / 1000.0;
   jd /= (24.0*60.0*60.0);
   jd += jdate(1999,8,22);
   jd += (((double) gps_week-1024.0) * 7.0);

   set_gregorian_time(jd);   // set time variables

   if(timing_mode == TMODE_UTC) {  // we want UTC time - convert gps time to utc
      gps_to_utc();
   }

   update_gps_screen(1717);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x68, %rsp
movl %edi, -0xc(%rbp)
leaq 0xd625c(%rip), %rdi     # 0x185f8f
callq 0x7add0
leaq 0x1ee399(%rip), %rax    # 0x29e0d8
leaq 0xd5224(%rip), %rcx     # 0x184f6a
movq %rcx, (%rax)
callq 0x7a9d0
movsd %xmm0, -0x18(%rbp)
callq 0x7a9d0
movsd %xmm0, -0x20(%rbp)
callq 0x7a510
movzbl %al, %eax
movl %eax, -0x24(%rbp)
leaq 0x1ca7f9(%rip), %rax    # 0x27a568
cmpl $0x0, (%rax)
je 0xafd83
movsd -0x20(%rbp), %xmm0
addsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
callq 0xa750
leaq 0x2bcb31(%rip), %rax    # 0x36c8c0
movsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
leaq 0x2bcb69(%rip), %rax    # 0x36c908
movl (%rax), %edx
xorl %esi, %esi
xorps %xmm0, %xmm0
movl %esi, %edi
callq 0x122210
movaps %xmm0, %xmm1
movsd -0x40(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
movsd 0xc184d(%rip), %xmm1    # 0x171618
subsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm1
movsd 0x3211f7(%rip), %xmm0   # 0x3d0fd8
ucomisd %xmm1, %xmm0
jbe 0xafdf7
xorps %xmm0, %xmm0
movsd %xmm0, 0x3211e6(%rip)   # 0x3d0fd8
jmp 0xb00aa
movsd -0x38(%rbp), %xmm0
movsd %xmm0, 0x3211d4(%rip)   # 0x3d0fd8
movsd 0xbf3e4(%rip), %xmm0    # 0x16f1f0
addsd -0x18(%rbp), %xmm0
movsd 0xbf217(%rip), %xmm1    # 0x16f030
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
cltq
leaq 0x2bcb06(%rip), %rcx    # 0x36c930
movq %rax, (%rcx)
movl %eax, %ecx
leaq 0x2bcaea(%rip), %rax    # 0x36c920
movl %ecx, (%rax)
leaq 0x2bcae5(%rip), %rax    # 0x36c924
movl %ecx, (%rax)
leaq 0x2bcad4(%rip), %rax    # 0x36c91c
movl %ecx, (%rax)
leaq 0x2bc6b7(%rip), %rax    # 0x36c508
movl $0x11, (%rax)
movsd -0x38(%rbp), %xmm0
movsd 0xc1824(%rip), %xmm1    # 0x171688
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movw %ax, %cx
leaq 0x2bcaa2(%rip), %rax    # 0x36c918
movw %cx, (%rax)
leaq 0x2bc68c(%rip), %rax    # 0x36c50c
cmpl $0x0, (%rax)
jne 0xafe92
leaq 0x1c7b98(%rip), %rax    # 0x277a24
movl $0x806, (%rax)          # imm = 0x806
leaq 0x2bc673(%rip), %rax    # 0x36c50c
movl $0x11, (%rax)
leaq 0x1ca6b2(%rip), %rax    # 0x27a558
cmpl $0x0, (%rax)
je 0xafecb
leaq 0x2bca6a(%rip), %rax    # 0x36c91c
movl (%rax), %eax
leaq 0x1ca69d(%rip), %rcx    # 0x27a558
xorl %edx, %edx
divl (%rcx)
cmpl $0x0, %edx
je 0xafec9
jmp 0xafffd
jmp 0xafecb
movsd -0x18(%rbp), %xmm0
movsd 0xbf158(%rip), %xmm1    # 0x16f030
divsd %xmm1, %xmm0
leaq 0x2bc875(%rip), %rax    # 0x36c758
movsd %xmm0, (%rax)
leaq 0x2bca2a(%rip), %rax    # 0x36c918
movzwl (%rax), %eax
cvtsi2sd %eax, %xmm0
movsd 0xc178b(%rip), %xmm1    # 0x171688
mulsd %xmm1, %xmm0
movsd 0xc170f(%rip), %xmm1    # 0x171618
addsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
leaq 0x2bc83f(%rip), %rax    # 0x36c758
movsd (%rax), %xmm0
xorl %edx, %edx
movl %edx, %edi
movl %edx, %esi
callq 0x122210
movaps %xmm0, %xmm1
movsd -0x48(%rbp), %xmm0
addsd %xmm1, %xmm0
leaq 0x2bc815(%rip), %rax    # 0x36c750
movsd %xmm0, (%rax)
leaq 0x1ed62a(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0xaffc7
leaq 0x2bc7fd(%rip), %rax    # 0x36c750
movsd (%rax), %xmm0
xorl %edi, %edi
callq 0x11dd00
leaq 0x1ed60b(%rip), %rax    # 0x29d570
movq (%rax), %rdi
leaq 0x2bc915(%rip), %rax    # 0x36c884
movl (%rax), %edx
leaq 0x2bc904(%rip), %rax    # 0x36c87c
movl (%rax), %ecx
leaq 0x2bc8ff(%rip), %rax    # 0x36c880
movl (%rax), %r8d
leaq 0x2bc8fd(%rip), %rax    # 0x36c888
movl (%rax), %r9d
leaq 0x2bc8f7(%rip), %rax    # 0x36c88c
movl (%rax), %ebx
leaq 0x2bc8f2(%rip), %rax    # 0x36c890
movl (%rax), %r11d
movl -0xc(%rbp), %r10d
movl -0x24(%rbp), %eax
leaq 0xd5ff2(%rip), %rsi     # 0x185fa1
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movb $0x0, %al
callq 0x9550
callq 0x81c10
movl -0x24(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x24(%rbp)
cmpl $0x0, %eax
je 0xafffb
movl -0xc(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xafff1
movl -0xc(%rbp), %edi
callq 0xaf040
jmp 0xafff9
movl -0xc(%rbp), %edi
callq 0xaf690
jmp 0xaffcc
jmp 0xafffd
movsd -0x18(%rbp), %xmm0
movsd 0xbf026(%rip), %xmm1    # 0x16f030
divsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
movsd 0xbefe8(%rip), %xmm1    # 0x16f008
divsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movl $0x7cf, %edi            # imm = 0x7CF
movl $0x8, %esi
movl $0x16, %edx
callq 0x122140
movaps %xmm0, %xmm1
movsd -0x30(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
leaq 0x2bc8c3(%rip), %rax    # 0x36c918
movzwl (%rax), %eax
cvtsi2sd %eax, %xmm0
movsd 0xd2b24(%rip), %xmm1    # 0x182b88
subsd %xmm1, %xmm0
movsd -0x30(%rbp), %xmm1
movsd 0xc1613(%rip), %xmm2    # 0x171688
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
callq 0x7fb00
leaq 0x2bc60a(%rip), %rax    # 0x36c69d
movzbl (%rax), %eax
cmpl $0x3, %eax
jne 0xb00a0
callq 0x7fcb0
movl $0x6b5, %edi            # imm = 0x6B5
callq 0x9d790
addq $0x68, %rsp
popq %rbx
popq %rbp
retq
nopw %cs:(%rax,%rax)