// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movl %edi, %ebx
leaq 0x97e92(%rip), %rdi     # 0x10cc47
callq 0x520bf
leaq 0x96e61(%rip), %rax     # 0x10bc22
leaq 0x1b4130(%rip), %rcx    # 0x228ef8
movq %rax, (%rcx)
callq 0x51e6f
movsd %xmm0, -0x28(%rbp)
callq 0x51e6f
movsd %xmm0, -0x30(%rbp)
callq 0x51c47
movl %eax, %r14d
leaq 0x19059a(%rip), %rax    # 0x205388
cmpl $0x0, (%rax)
je 0x74e02
movsd -0x28(%rbp), %xmm0
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
callq 0xa386
leaq 0x2828d2(%rip), %rax    # 0x2f76e0
movsd (%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq 0x28290a(%rip), %rax    # 0x2f7728
movl (%rax), %edx
xorpd %xmm0, %xmm0
xorl %edi, %edi
xorl %esi, %esi
callq 0xc2faf
addsd -0x30(%rbp), %xmm0
addsd 0x80ace(%rip), %xmm0    # 0xf5908
movsd 0x2e6fc6(%rip), %xmm1   # 0x35be08
ucomisd %xmm0, %xmm1
jbe 0x74e5d
andq $0x0, 0x2e6fb8(%rip)    # 0x35be08
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movsd %xmm0, 0x2e6fa3(%rip)   # 0x35be08
movsd 0x80b53(%rip), %xmm1    # 0xf59c0
movsd -0x28(%rbp), %xmm2
addsd %xmm2, %xmm1
divsd 0x7e1ba(%rip), %xmm1    # 0xf3038
cvttsd2si %xmm1, %eax
movslq %eax, %rcx
leaq 0x2828c4(%rip), %rdx    # 0x2f7750
movq %rcx, (%rdx)
leaq 0x2828aa(%rip), %rdx    # 0x2f7740
movl %ecx, (%rdx)
leaq 0x2828a5(%rip), %rdx    # 0x2f7744
movl %ecx, (%rdx)
leaq 0x282894(%rip), %rdx    # 0x2f773c
movl %ecx, (%rdx)
leaq 0x282477(%rip), %rcx    # 0x2f7328
divsd 0x80ac7(%rip), %xmm0    # 0xf5980
movl $0x11, (%rcx)
cvttsd2si %xmm0, %ecx
leaq 0x28286e(%rip), %r15    # 0x2f7738
movw %cx, (%r15)
leaq 0x282457(%rip), %rdx    # 0x2f732c
cmpl $0x0, (%rdx)
jne 0x74ee7
leaq 0x18d963(%rip), %rsi    # 0x202844
movl $0x806, (%rsi)          # imm = 0x806
movl $0x11, (%rdx)
leaq 0x190484(%rip), %rdx    # 0x205378
movl (%rdx), %esi
testl %esi, %esi
je 0x74f6f
xorl %edx, %edx
divl %esi
testl %edx, %edx
je 0x74f6f
divsd 0x7e12e(%rip), %xmm2    # 0xf3038
divsd 0x7e106(%rip), %xmm2    # 0xf3018
movsd %xmm2, -0x28(%rbp)
pushq $0x8
popq %rsi
pushq $0x16
popq %rdx
movl $0x7cf, %edi            # imm = 0x7CF
callq 0xc2f07
movzwl (%r15), %eax
cvtsi2sd %eax, %xmm1
addsd 0x93729(%rip), %xmm1    # 0x108660
addsd -0x28(%rbp), %xmm0
mulsd 0x80a3c(%rip), %xmm1    # 0xf5980
addsd %xmm1, %xmm0
callq 0x55392
leaq 0x282569(%rip), %rax    # 0x2f74bd
cmpb $0x3, (%rax)
jne 0x74f5e
callq 0x55500
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x694f6
movzbl %r14b, %r14d
divsd 0x7e0bd(%rip), %xmm2    # 0xf3038
leaq 0x2825f6(%rip), %rax    # 0x2f7578
movsd %xmm2, (%rax)
movzwl %cx, %eax
cvtsi2sd %eax, %xmm0
mulsd 0x809eb(%rip), %xmm0    # 0xf5980
addsd 0x80973(%rip), %xmm0    # 0xf5910
movsd %xmm0, -0x30(%rbp)
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
movsd %xmm2, -0x28(%rbp)
movapd %xmm2, %xmm0
callq 0xc2faf
addsd -0x30(%rbp), %xmm0
leaq 0x2825ae(%rip), %rax    # 0x2f7570
movsd %xmm0, (%rax)
leaq 0x1b33c3(%rip), %r12    # 0x228390
cmpq $0x0, (%r12)
je 0x75032
xorl %edi, %edi
callq 0xbfac2
movq (%r12), %rdi
leaq 0x2826be(%rip), %rax    # 0x2f76a4
movl (%rax), %edx
leaq 0x2826ad(%rip), %rax    # 0x2f769c
movl (%rax), %ecx
leaq 0x2826a8(%rip), %rax    # 0x2f76a0
movl (%rax), %r8d
leaq 0x2826a6(%rip), %rax    # 0x2f76a8
movl (%rax), %r9d
leaq 0x2826a0(%rip), %rax    # 0x2f76ac
movl (%rax), %r10d
leaq 0x28269a(%rip), %rax    # 0x2f76b0
movl (%rax), %r11d
leaq 0x97c39(%rip), %rsi     # 0x10cc59
xorl %eax, %eax
pushq %r14
pushq %rbx
pushq %r11
pushq %r10
callq 0x9560
addq $0x20, %rsp
callq 0x56b1c
subl $0x1, %r14d
movsd -0x28(%rbp), %xmm2
jb 0x74f0a
movl %ebx, %edi
testb $0x1, %bl
jne 0x75054
callq 0x7486c
jmp 0x75037
callq 0x743c9
jmp 0x75037