// File: /workspace/github_cpp_makefile_star2_O1/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 0xa25ab(%rip), %rdi     # 0x122c1f
callq 0x58e77
leaq 0xa157a(%rip), %rax     # 0x121bfa
leaq 0x1be871(%rip), %rcx    # 0x23eef8
movq %rax, (%rcx)
callq 0x58b86
movsd %xmm0, -0x30(%rbp)
callq 0x58b86
movsd %xmm0, -0x38(%rbp)
callq 0x587d1
movl %eax, %r14d
cmpl $0x100, %eax            # imm = 0x100
jb 0x806b7
leaq 0x1be8bc(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
leaq 0x19acca(%rip), %rax    # 0x21b388
cmpl $0x0, (%rax)
je 0x806d2
movsd -0x30(%rbp), %xmm0
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xa495
leaq 0x28d002(%rip), %rax    # 0x30d6e0
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
leaq 0x28d03a(%rip), %r15    # 0x30d728
movl (%r15), %edx
xorpd %xmm0, %xmm0
xorl %edi, %edi
xorl %esi, %esi
callq 0xd41e0
addsd -0x38(%rbp), %xmm0
addsd 0x8b175(%rip), %xmm0    # 0x10b880
movsd 0x2f16f5(%rip), %xmm1   # 0x371e08
ucomisd %xmm0, %xmm1
jbe 0x80733
movq $0x0, 0x2f16e4(%rip) # 0x371e08
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsd %xmm0, 0x2f16cd(%rip)   # 0x371e08
movsd 0x8b1fd(%rip), %xmm1    # 0x10b940
addsd -0x30(%rbp), %xmm1
divsd 0x888e8(%rip), %xmm1    # 0x109038
cvttsd2si %xmm1, %eax
movslq %eax, %rcx
leaq 0x28cff2(%rip), %rdx    # 0x30d750
movq %rcx, (%rdx)
leaq 0x28cfd8(%rip), %rdx    # 0x30d740
movl %ecx, (%rdx)
leaq 0x28cfd3(%rip), %rdx    # 0x30d744
movl %ecx, (%rdx)
leaq 0x28cfc2(%rip), %rdx    # 0x30d73c
movl %ecx, (%rdx)
leaq 0x28cba5(%rip), %rcx    # 0x30d328
divsd 0x8b175(%rip), %xmm0    # 0x10b900
movl $0x11, (%rcx)
cvttsd2si %xmm0, %ecx
leaq 0x28cf9c(%rip), %r12    # 0x30d738
movw %cx, (%r12)
leaq 0x28cb84(%rip), %rdx    # 0x30d32c
cmpl $0x0, (%rdx)
jne 0x807ba
leaq 0x198090(%rip), %rsi    # 0x218844
movl $0x806, (%rsi)          # imm = 0x806
movl $0x11, (%rdx)
leaq 0x19abb1(%rip), %rdx    # 0x21b378
movl (%rdx), %esi
testl %esi, %esi
je 0x807d9
xorl %edx, %edx
divl %esi
testl %edx, %edx
jne 0x808e8
movzbl %r14b, %r14d
movsd -0x30(%rbp), %xmm0
divsd 0x8884e(%rip), %xmm0    # 0x109038
leaq 0x28cd87(%rip), %rax    # 0x30d578
movsd %xmm0, (%rax)
movzwl %cx, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd 0x8b0f9(%rip), %xmm1    # 0x10b900
addsd 0x8b079(%rip), %xmm1    # 0x10b888
movsd %xmm1, -0x38(%rbp)
xorl %r13d, %r13d
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0xd41e0
addsd -0x38(%rbp), %xmm0
leaq 0x28cd42(%rip), %rax    # 0x30d570
movsd %xmm0, (%rax)
leaq 0x1bdb57(%rip), %r12    # 0x23e390
cmpq $0x0, (%r12)
je 0x8089e
xorl %edi, %edi
callq 0xd0c46
movq (%r12), %rdi
leaq 0x28ce52(%rip), %rax    # 0x30d6a4
movl (%rax), %edx
leaq 0x28ce41(%rip), %rax    # 0x30d69c
movl (%rax), %ecx
leaq 0x28ce3c(%rip), %rax    # 0x30d6a0
movl (%rax), %r8d
leaq 0x28ce3a(%rip), %rax    # 0x30d6a8
movl (%rax), %r9d
leaq 0x28ce34(%rip), %rax    # 0x30d6ac
movl (%rax), %r10d
leaq 0x28ce2e(%rip), %rax    # 0x30d6b0
movl (%rax), %r11d
leaq 0xa23a5(%rip), %rsi     # 0x122c31
xorl %eax, %eax
pushq %r14
pushq %rbx
pushq %r11
pushq %r10
callq 0x9560
addq $0x20, %rsp
movl $0x218, %eax            # imm = 0x218
leaq 0x1be706(%rip), %rcx    # 0x23efb0
movl %r13d, (%rcx,%rax)
movl %r13d, -0x1fc(%rcx,%rax)
addq $0x348, %rax            # imm = 0x348
cmpq $0xcd358, %rax          # imm = 0xCD358
jne 0x808aa
testl %r14d, %r14d
leaq 0x28ce6a(%rip), %r12    # 0x30d738
je 0x808e8
movl %ebx, %edi
testb $0x1, %bl
jne 0x808de
callq 0x800b0
jmp 0x808e3
callq 0x7fb65
decl %r14d
jne 0x808d0
movsd -0x30(%rbp), %xmm0
divsd 0x88743(%rip), %xmm0    # 0x109038
divsd 0x8871b(%rip), %xmm0    # 0x109018
movsd %xmm0, -0x30(%rbp)
movl $0x7cf, %edi            # imm = 0x7CF
movl $0x8, %esi
movl $0x16, %edx
callq 0xd4110
movzwl (%r12), %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
addsd 0x9dd1e(%rip), %xmm1    # 0x11e648
addsd -0x30(%rbp), %xmm0
mulsd 0x8afc9(%rip), %xmm1    # 0x10b900
addsd %xmm1, %xmm0
callq 0x5c837
leaq 0x28cb76(%rip), %rax    # 0x30d4bd
cmpb $0x3, (%rax)
jne 0x80978
xorps %xmm1, %xmm1
cvtsi2sdl (%r15), %xmm1
xorpd %xmm0, %xmm0
subsd %xmm1, %xmm0
callq 0x5c907
leaq 0x28cb3c(%rip), %rax    # 0x30d4a4
orb $0x1, (%rax)
leaq 0x28ca5a(%rip), %rax    # 0x30d3cc
movl $0x1, (%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7327e