// File: jkingan[P]ladyheather/heathgps.cpp
// Function: parse_ubx_tp5()
void parse_ubx_tp5()
{
u08 chan;
u32 freq;
u32 lfreq;
u32 duty;
u32 lduty;
S32 dly;
u32 flags;

   log_packet_id("UBX_TP5");

   chan = tsip_byte();     // output number (0 / 1)
   tsip_byte();            // rsvd
   tsip_word();            // rsvd

   cable_delay = (double) (s16) tsip_word();
   cable_delay /= 1.0E9;
// if(have_cable_delay == 0) need_redraw = 2021;
   have_cable_delay = 1;

   tsip_word();            // signed RF delay(ns)
   freq = tsip_dword();    // freq / period
   lfreq = tsip_dword();   // gps locked freq/period
   duty = tsip_dword();    // width / duty cycle
   lduty = tsip_dword();   // gps locked width / duty cycle
   dly = tsip_dword();     // time pulse delay (ns)
   flags = tsip_dword();   // flags

   if(chan) {  // pps2
      saw_ubx_tp5 |= 2;
      pps2_freq = freq;
      pps2_duty = ((double) duty) / (double) (u32) 0xFFFFFFFF;
      pps2_delay = (double) dly;
      pps2_flags = flags;
      have_pps_duty |= 0x02;
      have_pps_freq |= 0x02;
      have_pps_delay |= 0x02;
   }
   else {  // pps1
      saw_ubx_tp5 |= 1;
      pps1_freq = (double) freq;
      pps1_duty = ((double) duty) / (double) (u32) 0xFFFFFFFF;
      pps1_delay = (double) dly;
      pps1_flags = flags;
      have_pps_duty |= 0x01;
      have_pps_freq |= 0x01;
      have_pps_delay |= 0x01;

      if(pps1_flags & 0x0001) pps_enabled = 1;
      else                    pps_enabled = 0;
      have_pps_enable = 3;

      if(pps1_flags & 0x0040) pps_polarity = 0;
      else                    pps_polarity = 1;
      have_pps_polarity = 3;

      if(pps1_freq == 100)       pps_rate = RATE_100PPS;
      else if(pps1_freq == 1000) pps_rate = RATE_1000PPS;
      else if(pps1_freq == 1)    pps_rate = RATE_1PPS;
      else                       pps_rate = RATE_USER;  // user defined rate
      have_pps_rate = 4;
//sprintf(debug_text2, "ubxtp5: rate:%d freq:%g duty:%g  flags:%04X  enbl:%d pol:%d", pps_rate, pps1_freq, pps1_duty, pps1_flags, pps_enabled, pps_polarity);
   }

   show_cable_delay();

//if(chan == 0) { // dddd
//   sprintf(plot_title, "f:%d  lf:%d  d:%d  ld:%d  dly:%d  flags:%08X", freq,lfreq,duty,lduty, dly, flags);
//}
//else {
//   sprintf(debug_text, "f:%d  lf:%d  d:%d  ld:%d  dly:%d  flags:%08X", freq,lfreq,duty,lduty, dly, flags);
//}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
leaq 0xbc8ea(%rip), %rdi     # 0x187a89
callq 0x7add0
callq 0x7a510
movb %al, -0x1(%rbp)
callq 0x7a510
callq 0x7a560
callq 0x7a560
cwtl
cvtsi2sd %eax, %xmm0
leaq 0x2a1de1(%rip), %rax    # 0x36cfa8
movsd %xmm0, (%rax)
leaq 0x2a1dd6(%rip), %rax    # 0x36cfa8
movsd (%rax), %xmm0
movsd 0xa3e4a(%rip), %xmm1    # 0x16f028
divsd %xmm1, %xmm0
leaq 0x2a1dbf(%rip), %rax    # 0x36cfa8
movsd %xmm0, (%rax)
leaq 0x2a12a0(%rip), %rax    # 0x36c494
movl $0x1, (%rax)
callq 0x7a560
callq 0x7a680
movl %eax, -0x8(%rbp)
callq 0x7a680
movl %eax, -0xc(%rbp)
callq 0x7a680
movl %eax, -0x10(%rbp)
callq 0x7a680
movl %eax, -0x14(%rbp)
callq 0x7a680
movl %eax, -0x18(%rbp)
callq 0x7a680
movl %eax, -0x1c(%rbp)
cmpb $0x0, -0x1(%rbp)
je 0xcb2d9
leaq 0x2a13cc(%rip), %rax    # 0x36c60c
movb (%rax), %cl
orb $0x2, %cl
movb %cl, (%rax)
movl -0x8(%rbp), %eax
cvtsi2sd %rax, %xmm0
leaq 0x2a1cca(%rip), %rax    # 0x36cf20
movsd %xmm0, (%rax)
movl -0x10(%rbp), %eax
cvtsi2sd %rax, %xmm0
movsd 0xb7de6(%rip), %xmm1    # 0x183050
divsd %xmm1, %xmm0
leaq 0x2a1cb3(%rip), %rax    # 0x36cf28
movsd %xmm0, (%rax)
cvtsi2sdl -0x18(%rbp), %xmm0
leaq 0x2a1d3b(%rip), %rax    # 0x36cfc0
movsd %xmm0, (%rax)
movl -0x1c(%rbp), %ecx
leaq 0x2a1c9d(%rip), %rax    # 0x36cf30
movl %ecx, (%rax)
leaq 0x2a1ca8(%rip), %rax    # 0x36cf44
movl (%rax), %ecx
orl $0x2, %ecx
leaq 0x2a1c9c(%rip), %rax    # 0x36cf44
movl %ecx, (%rax)
leaq 0x2a1c8f(%rip), %rax    # 0x36cf40
movl (%rax), %ecx
orl $0x2, %ecx
leaq 0x2a1c83(%rip), %rax    # 0x36cf40
movl %ecx, (%rax)
leaq 0x2a11d2(%rip), %rax    # 0x36c498
movl (%rax), %ecx
orl $0x2, %ecx
leaq 0x2a11c6(%rip), %rax    # 0x36c498
movl %ecx, (%rax)
jmp 0xcb472
leaq 0x2a132c(%rip), %rax    # 0x36c60c
movb (%rax), %cl
orb $0x1, %cl
movb %cl, (%rax)
movl -0x8(%rbp), %eax
cvtsi2sd %rax, %xmm0
leaq 0x2a1c12(%rip), %rax    # 0x36cf08
movsd %xmm0, (%rax)
movl -0x10(%rbp), %eax
cvtsi2sd %rax, %xmm0
movsd 0xb7d46(%rip), %xmm1    # 0x183050
divsd %xmm1, %xmm0
leaq 0x2a1bfb(%rip), %rax    # 0x36cf10
movsd %xmm0, (%rax)
cvtsi2sdl -0x18(%rbp), %xmm0
leaq 0x2a1c93(%rip), %rax    # 0x36cfb8
movsd %xmm0, (%rax)
movl -0x1c(%rbp), %ecx
leaq 0x2a1be5(%rip), %rax    # 0x36cf18
movl %ecx, (%rax)
leaq 0x2a1c08(%rip), %rax    # 0x36cf44
movl (%rax), %ecx
orl $0x1, %ecx
leaq 0x2a1bfc(%rip), %rax    # 0x36cf44
movl %ecx, (%rax)
leaq 0x2a1bef(%rip), %rax    # 0x36cf40
movl (%rax), %ecx
orl $0x1, %ecx
leaq 0x2a1be3(%rip), %rax    # 0x36cf40
movl %ecx, (%rax)
leaq 0x2a1132(%rip), %rax    # 0x36c498
movl (%rax), %ecx
orl $0x1, %ecx
leaq 0x2a1126(%rip), %rax    # 0x36c498
movl %ecx, (%rax)
leaq 0x2a1b9d(%rip), %rax    # 0x36cf18
movl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xcb391
leaq 0x2a1b74(%rip), %rax    # 0x36cf00
movb $0x1, (%rax)
jmp 0xcb39b
leaq 0x2a1b68(%rip), %rax    # 0x36cf00
movb $0x0, (%rax)
leaq 0x2a111a(%rip), %rax    # 0x36c4bc
movl $0x3, (%rax)
leaq 0x2a1b69(%rip), %rax    # 0x36cf18
movl (%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0xcb3c8
leaq 0x2a1b38(%rip), %rax    # 0x36cef8
movl $0x0, (%rax)
jmp 0xcb3d5
leaq 0x2a1b29(%rip), %rax    # 0x36cef8
movl $0x1, (%rax)
leaq 0x2a10e4(%rip), %rax    # 0x36c4c0
movl $0x3, (%rax)
leaq 0x2a1b1f(%rip), %rax    # 0x36cf08
movsd (%rax), %xmm0
movsd 0xa3c5b(%rip), %xmm1    # 0x16f050
ucomisd %xmm1, %xmm0
jne 0xcb409
jp 0xcb409
leaq 0x2a1aff(%rip), %rax    # 0x36cf03
movb $-0x7e, (%rax)
jmp 0xcb465
leaq 0x2a1af8(%rip), %rax    # 0x36cf08
movsd (%rax), %xmm0
movsd 0xa3c14(%rip), %xmm1    # 0x16f030
ucomisd %xmm1, %xmm0
jne 0xcb430
jp 0xcb430
leaq 0x2a1ad8(%rip), %rax    # 0x36cf03
movb $-0x7d, (%rax)
jmp 0xcb463
leaq 0x2a1ad1(%rip), %rax    # 0x36cf08
movsd (%rax), %xmm0
movsd 0xa3c25(%rip), %xmm1    # 0x16f068
ucomisd %xmm1, %xmm0
jne 0xcb457
jp 0xcb457
leaq 0x2a1ab1(%rip), %rax    # 0x36cf03
movb $0x2, (%rax)
jmp 0xcb461
leaq 0x2a1aa5(%rip), %rax    # 0x36cf03
movb $0x0, (%rax)
jmp 0xcb463
jmp 0xcb465
leaq 0x2a1044(%rip), %rax    # 0x36c4b0
movl $0x4, (%rax)
callq 0xa0f60
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)