// File: /workspace/github_cpp_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edi, %ebx
leaq 0xa2835(%rip), %rdi     # 0x122cff
callq 0x58dc2
leaq 0xa1804(%rip), %rax     # 0x121cda
leaq 0x1bea1b(%rip), %rcx    # 0x23eef8
movq %rax, (%rcx)
callq 0x58b08
movsd %xmm0, -0x30(%rbp)
callq 0x58b08
movsd %xmm0, -0x38(%rbp)
callq 0x587be
movl %eax, %r14d
cmpl $0x100, %eax            # imm = 0x100
jb 0x8050d
leaq 0x1bea66(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
leaq 0x19ae74(%rip), %rax    # 0x21b388
cmpl $0x0, (%rax)
je 0x80528
movsd -0x30(%rbp), %xmm0
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xa477
leaq 0x28d1ac(%rip), %rax    # 0x30d6e0
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
leaq 0x28d1e4(%rip), %r15    # 0x30d728
movl (%r15), %edx
xorpd %xmm0, %xmm0
xorl %edi, %edi
xorl %esi, %esi
callq 0xd492e
addsd -0x38(%rbp), %xmm0
addsd 0x8b32f(%rip), %xmm0    # 0x10b890
movsd 0x2f189f(%rip), %xmm1   # 0x371e08
ucomisd %xmm0, %xmm1
jbe 0x80589
movq $0x0, 0x2f188e(%rip) # 0x371e08
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsd %xmm0, 0x2f1877(%rip)   # 0x371e08
movsd 0x8b3af(%rip), %xmm1    # 0x10b948
movsd -0x30(%rbp), %xmm2
addsd %xmm2, %xmm1
divsd 0x88a8e(%rip), %xmm1    # 0x109038
cvttsd2si %xmm1, %eax
movslq %eax, %rcx
leaq 0x28d198(%rip), %rdx    # 0x30d750
movq %rcx, (%rdx)
leaq 0x28d17e(%rip), %rdx    # 0x30d740
movl %ecx, (%rdx)
leaq 0x28d179(%rip), %rdx    # 0x30d744
movl %ecx, (%rdx)
leaq 0x28d168(%rip), %rdx    # 0x30d73c
movl %ecx, (%rdx)
leaq 0x28cd4b(%rip), %rcx    # 0x30d328
divsd 0x8b323(%rip), %xmm0    # 0x10b908
movl $0x11, (%rcx)
cvttsd2si %xmm0, %ecx
leaq 0x28d142(%rip), %r12    # 0x30d738
movw %cx, (%r12)
leaq 0x28cd2a(%rip), %rdx    # 0x30d32c
cmpl $0x0, (%rdx)
jne 0x80614
leaq 0x198236(%rip), %rsi    # 0x218844
movl $0x806, (%rsi)          # imm = 0x806
movl $0x11, (%rdx)
leaq 0x19ad57(%rip), %rdx    # 0x21b378
movl (%rdx), %esi
testl %esi, %esi
je 0x8063c
xorl %edx, %edx
divl %esi
testl %edx, %edx
je 0x8063c
divsd 0x88a01(%rip), %xmm2    # 0x109038
jmp 0x80759
movzbl %r14b, %r14d
divsd 0x889f0(%rip), %xmm2    # 0x109038
leaq 0x28cf29(%rip), %rax    # 0x30d578
movsd %xmm2, (%rax)
movzwl %cx, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x8b2a3(%rip), %xmm0    # 0x10b908
addsd 0x8b22b(%rip), %xmm0    # 0x10b898
movsd %xmm0, -0x38(%rbp)
xorl %r13d, %r13d
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
movsd %xmm2, -0x30(%rbp)
movapd %xmm2, %xmm0
callq 0xd492e
addsd -0x38(%rbp), %xmm0
leaq 0x28cedb(%rip), %rax    # 0x30d570
movsd %xmm0, (%rax)
leaq 0x1bdcf0(%rip), %r12    # 0x23e390
cmpq $0x0, (%r12)
je 0x80705
xorl %edi, %edi
callq 0xd12da
movq (%r12), %rdi
leaq 0x28cfeb(%rip), %rax    # 0x30d6a4
movl (%rax), %edx
leaq 0x28cfda(%rip), %rax    # 0x30d69c
movl (%rax), %ecx
leaq 0x28cfd5(%rip), %rax    # 0x30d6a0
movl (%rax), %r8d
leaq 0x28cfd3(%rip), %rax    # 0x30d6a8
movl (%rax), %r9d
leaq 0x28cfcd(%rip), %rax    # 0x30d6ac
movl (%rax), %r10d
leaq 0x28cfc7(%rip), %rax    # 0x30d6b0
movl (%rax), %r11d
leaq 0xa261e(%rip), %rsi     # 0x122d11
xorl %eax, %eax
pushq %r14
pushq %rbx
pushq %r11
pushq %r10
callq 0x9560
addq $0x20, %rsp
movl $0x218, %eax            # imm = 0x218
leaq 0x1be89f(%rip), %rcx    # 0x23efb0
movl %r13d, (%rcx,%rax)
movl %r13d, -0x1fc(%rcx,%rax)
addq $0x348, %rax            # imm = 0x348
cmpq $0xcd358, %rax          # imm = 0xCD358
jne 0x80711
testl %r14d, %r14d
movsd -0x30(%rbp), %xmm2
leaq 0x28cffe(%rip), %r12    # 0x30d738
je 0x80759
movl %ebx, %edi
testb $0x1, %bl
jne 0x8074a
callq 0x7fee8
jmp 0x8074f
callq 0x7f99a
decl %r14d
movsd -0x30(%rbp), %xmm2
jne 0x8073c
divsd 0x888b7(%rip), %xmm2    # 0x109018
movsd %xmm2, -0x30(%rbp)
movl $0x7cf, %edi            # imm = 0x7CF
movl $0x8, %esi
movl $0x16, %edx
callq 0xd485e
movzwl (%r12), %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
addsd 0x9df5a(%rip), %xmm1    # 0x11e6e8
addsd -0x30(%rbp), %xmm0
mulsd 0x8b16d(%rip), %xmm1    # 0x10b908
addsd %xmm1, %xmm0
callq 0x5c71d
leaq 0x28cd12(%rip), %rax    # 0x30d4bd
cmpb $0x3, (%rax)
jne 0x807dc
xorps %xmm1, %xmm1
cvtsi2sdl (%r15), %xmm1
xorpd %xmm0, %xmm0
subsd %xmm1, %xmm0
callq 0x5c7ed
leaq 0x28ccd8(%rip), %rax    # 0x30d4a4
orb $0x1, (%rax)
leaq 0x28cbf6(%rip), %rax    # 0x30d3cc
movl $0x1, (%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x730e8