// File: /workspace/github_cpp_makefile_star2_O1/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 0x8fac7(%rip), %rdi     # 0x1246bd
callq 0x58e77
callq 0x587d1
movl %eax, %r14d
cmpl $0x100, %eax            # imm = 0x100
jb 0x94c14
leaq 0x1aa35f(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x94c2a
leaq 0x1aa349(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x588f0
callq 0x588f0
cwtl
cvtsi2sd %eax, %xmm0
divsd 0x743e7(%rip), %xmm0    # 0x109028
leaq 0x279180(%rip), %rax    # 0x30ddc8
movsd %xmm0, (%rax)
leaq 0x278661(%rip), %rax    # 0x30d2b4
movl $0x1, (%rax)
callq 0x588f0
callq 0x589b0
movl %eax, %ebx
callq 0x589b0
callq 0x589b0
movl %eax, %r15d
callq 0x589b0
callq 0x589b0
movl %eax, %r12d
callq 0x589b0
leaq 0x2787a1(%rip), %rcx    # 0x30d42c
movl %ebx, %edx
cvtsi2sd %rdx, %xmm2
movl %r15d, %edx
xorps %xmm0, %xmm0
cvtsi2sd %rdx, %xmm0
divsd 0x89a2b(%rip), %xmm0    # 0x11e6d0
movl (%rcx), %edx
cvtsi2sd %r12d, %xmm1
testb %r14b, %r14b
je 0x94d03
orl $0x2, %edx
movl %edx, (%rcx)
leaq 0x279083(%rip), %rcx    # 0x30dd40
movsd %xmm2, (%rcx)
leaq 0x279080(%rip), %rcx    # 0x30dd48
movsd %xmm0, (%rcx)
leaq 0x27910d(%rip), %rcx    # 0x30dde0
movsd %xmm1, (%rcx)
leaq 0x279072(%rip), %rcx    # 0x30dd50
movl %eax, (%rcx)
leaq 0x27907d(%rip), %rax    # 0x30dd64
orb $0x2, (%rax)
leaq 0x27906f(%rip), %rax    # 0x30dd60
orb $0x2, (%rax)
leaq 0x2785bd(%rip), %rax    # 0x30d2b8
orb $0x2, (%rax)
jmp 0x94dbb
orl $0x1, %edx
movl %edx, (%rcx)
leaq 0x279019(%rip), %rcx    # 0x30dd28
movsd %xmm2, (%rcx)
leaq 0x279016(%rip), %rcx    # 0x30dd30
movsd %xmm0, (%rcx)
leaq 0x2790b3(%rip), %rcx    # 0x30ddd8
movsd %xmm1, (%rcx)
leaq 0x279008(%rip), %rcx    # 0x30dd38
leaq 0x27902d(%rip), %rdx    # 0x30dd64
orb $0x1, (%rdx)
leaq 0x27901f(%rip), %rdx    # 0x30dd60
orb $0x1, (%rdx)
leaq 0x27856d(%rip), %rdx    # 0x30d2b8
orb $0x1, (%rdx)
movl %eax, (%rcx)
movl %eax, %ecx
andb $0x1, %cl
leaq 0x278fc4(%rip), %rdx    # 0x30dd20
movb %cl, (%rdx)
leaq 0x278577(%rip), %rcx    # 0x30d2dc
movl $0x3, %edx
movl %edx, (%rcx)
xorl %ecx, %ecx
testb $0x40, %al
sete %cl
leaq 0x278f9e(%rip), %rax    # 0x30dd18
movl %ecx, (%rax)
leaq 0x27855d(%rip), %rax    # 0x30d2e0
movl %edx, (%rax)
cmpl $0x1, %ebx
je 0x94d9f
cmpl $0x64, %ebx
je 0x94d9b
cmpl $0x3e8, %ebx            # imm = 0x3E8
jne 0x94da3
movb $-0x7d, %al
jmp 0x94da5
movb $-0x7e, %al
jmp 0x94da5
movb $0x2, %al
jmp 0x94da5
xorl %eax, %eax
leaq 0x278f77(%rip), %rcx    # 0x30dd23
movb %al, (%rcx)
leaq 0x27851b(%rip), %rax    # 0x30d2d0
movl $0x4, (%rax)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x754c4