// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
leaq 0x86f56(%rip), %rdi     # 0x10e6e5
callq 0x520bf
callq 0x51c47
movl %eax, %r14d
callq 0x51c47
callq 0x51c63
callq 0x51c63
cwtl
cvtsi2sd %eax, %xmm0
divsd 0x6b870(%rip), %xmm0    # 0xf3028
leaq 0x270609(%rip), %rax    # 0x2f7dc8
movsd %xmm0, (%rax)
leaq 0x26faea(%rip), %rax    # 0x2f72b4
movl $0x1, (%rax)
callq 0x51c63
callq 0x51cf3
movl %eax, %ebx
callq 0x51cf3
callq 0x51cf3
movl %eax, %r15d
callq 0x51cf3
callq 0x51cf3
movl %eax, %r12d
callq 0x51cf3
leaq 0x26fc2a(%rip), %rcx    # 0x2f742c
movl %ebx, %edx
cvtsi2sd %rdx, %xmm2
movl %r15d, %edx
cvtsi2sd %rdx, %xmm0
divsd 0x80edf(%rip), %xmm0    # 0x1086f8
movl (%rcx), %edx
cvtsi2sd %r12d, %xmm1
testb %r14b, %r14b
je 0x87877
orl $0x2, %edx
movl %edx, (%rcx)
leaq 0x27050f(%rip), %rcx    # 0x2f7d40
movsd %xmm2, (%rcx)
leaq 0x27050c(%rip), %rcx    # 0x2f7d48
movsd %xmm0, (%rcx)
leaq 0x270599(%rip), %rcx    # 0x2f7de0
movsd %xmm1, (%rcx)
leaq 0x2704fe(%rip), %rcx    # 0x2f7d50
movl %eax, (%rcx)
leaq 0x270509(%rip), %rax    # 0x2f7d64
orb $0x2, (%rax)
leaq 0x2704fb(%rip), %rax    # 0x2f7d60
orb $0x2, (%rax)
leaq 0x26fa49(%rip), %rax    # 0x2f72b8
orb $0x2, (%rax)
jmp 0x8792d
orl $0x1, %edx
movl %edx, (%rcx)
leaq 0x2704a5(%rip), %rcx    # 0x2f7d28
movsd %xmm2, (%rcx)
leaq 0x2704a2(%rip), %rcx    # 0x2f7d30
movsd %xmm0, (%rcx)
leaq 0x27053f(%rip), %rcx    # 0x2f7dd8
movsd %xmm1, (%rcx)
leaq 0x270494(%rip), %rcx    # 0x2f7d38
leaq 0x2704b9(%rip), %rdx    # 0x2f7d64
orb $0x1, (%rdx)
leaq 0x2704ab(%rip), %rdx    # 0x2f7d60
orb $0x1, (%rdx)
leaq 0x26f9f9(%rip), %rdx    # 0x2f72b8
orb $0x1, (%rdx)
movl %eax, (%rcx)
movl %eax, %ecx
andb $0x1, %cl
leaq 0x270450(%rip), %rdx    # 0x2f7d20
movb %cl, (%rdx)
leaq 0x26fa03(%rip), %rcx    # 0x2f72dc
pushq $0x3
popq %rdx
movl %edx, (%rcx)
xorl %ecx, %ecx
testb $0x40, %al
sete %cl
leaq 0x27042c(%rip), %rax    # 0x2f7d18
movl %ecx, (%rax)
leaq 0x26f9eb(%rip), %rax    # 0x2f72e0
movl %edx, (%rax)
cmpl $0x1, %ebx
je 0x87911
cmpl $0x64, %ebx
je 0x8790d
cmpl $0x3e8, %ebx            # imm = 0x3E8
jne 0x87915
movb $-0x7d, %al
jmp 0x87917
movb $-0x7e, %al
jmp 0x87917
movb $0x2, %al
jmp 0x87917
xorl %eax, %eax
leaq 0x270405(%rip), %rcx    # 0x2f7d23
movb %al, (%rcx)
leaq 0x26f9a9(%rip), %rax    # 0x2f72d0
movl $0x4, (%rax)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x6b202