// File: /workspace/github_cpp_makefile_star2_O3/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 0x8fb23(%rip), %rdi     # 0x12479d
callq 0x58dc2
callq 0x587be
movl %eax, %r14d
cmpl $0x100, %eax            # imm = 0x100
jb 0x94c98
leaq 0x1aa2db(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x94cae
leaq 0x1aa2c5(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x588d2
callq 0x588d2
cwtl
cvtsi2sd %eax, %xmm0
divsd 0x74363(%rip), %xmm0    # 0x109028
leaq 0x2790fc(%rip), %rax    # 0x30ddc8
movsd %xmm0, (%rax)
leaq 0x2785dd(%rip), %rax    # 0x30d2b4
movl $0x1, (%rax)
callq 0x588d2
callq 0x58964
movl %eax, %ebx
callq 0x58964
callq 0x58964
movl %eax, %r15d
callq 0x58964
callq 0x58964
movl %eax, %r12d
callq 0x58964
leaq 0x27871d(%rip), %rcx    # 0x30d42c
movl %ebx, %edx
cvtsi2sd %rdx, %xmm2
movl %r15d, %edx
xorps %xmm0, %xmm0
cvtsi2sd %rdx, %xmm0
divsd 0x89a57(%rip), %xmm0    # 0x11e780
movl (%rcx), %edx
cvtsi2sd %r12d, %xmm1
testb %r14b, %r14b
je 0x94d87
orl $0x2, %edx
movl %edx, (%rcx)
leaq 0x278fff(%rip), %rcx    # 0x30dd40
movsd %xmm2, (%rcx)
leaq 0x278ffc(%rip), %rcx    # 0x30dd48
movsd %xmm0, (%rcx)
leaq 0x279089(%rip), %rcx    # 0x30dde0
movsd %xmm1, (%rcx)
leaq 0x278fee(%rip), %rcx    # 0x30dd50
movl %eax, (%rcx)
leaq 0x278ff9(%rip), %rax    # 0x30dd64
orb $0x2, (%rax)
leaq 0x278feb(%rip), %rax    # 0x30dd60
orb $0x2, (%rax)
leaq 0x278539(%rip), %rax    # 0x30d2b8
orb $0x2, (%rax)
jmp 0x94e3f
orl $0x1, %edx
movl %edx, (%rcx)
leaq 0x278f95(%rip), %rcx    # 0x30dd28
movsd %xmm2, (%rcx)
leaq 0x278f92(%rip), %rcx    # 0x30dd30
movsd %xmm0, (%rcx)
leaq 0x27902f(%rip), %rcx    # 0x30ddd8
movsd %xmm1, (%rcx)
leaq 0x278f84(%rip), %rcx    # 0x30dd38
leaq 0x278fa9(%rip), %rdx    # 0x30dd64
orb $0x1, (%rdx)
leaq 0x278f9b(%rip), %rdx    # 0x30dd60
orb $0x1, (%rdx)
leaq 0x2784e9(%rip), %rdx    # 0x30d2b8
orb $0x1, (%rdx)
movl %eax, (%rcx)
movl %eax, %ecx
andb $0x1, %cl
leaq 0x278f40(%rip), %rdx    # 0x30dd20
movb %cl, (%rdx)
leaq 0x2784f3(%rip), %rcx    # 0x30d2dc
movl $0x3, %edx
movl %edx, (%rcx)
xorl %ecx, %ecx
testb $0x40, %al
sete %cl
leaq 0x278f1a(%rip), %rax    # 0x30dd18
movl %ecx, (%rax)
leaq 0x2784d9(%rip), %rax    # 0x30d2e0
movl %edx, (%rax)
cmpl $0x1, %ebx
je 0x94e23
cmpl $0x64, %ebx
je 0x94e1f
cmpl $0x3e8, %ebx            # imm = 0x3E8
jne 0x94e27
movb $-0x7d, %al
jmp 0x94e29
movb $-0x7e, %al
jmp 0x94e29
movb $0x2, %al
jmp 0x94e29
xorl %eax, %eax
leaq 0x278ef3(%rip), %rcx    # 0x30dd23
movb %al, (%rcx)
leaq 0x278497(%rip), %rax    # 0x30d2d0
movl $0x4, (%rax)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x75326