// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heathui.cpp
// Function: edit_pps_freq(int)
void edit_pps_freq(int chan)
{
double freq;
double duty;
int old_width;

   // set lat/lon/altitude
   if(edit_buffer[0] == 0) return;

   freq = 1.0;
   duty = 0.50;
   if     (rcvr_type == NVS_RCVR)   sscanf(edit_buffer, "%lf", &duty);
   else if(rcvr_type == CS_RCVR)    sscanf(edit_buffer, "%lf", &freq);
   else if((rcvr_type == ESIP_RCVR) && (chan == 0)) sscanf(edit_buffer, "%lf", &duty);
   else if((rcvr_type == SS_RCVR) && (chan == 0))   sscanf(edit_buffer, "%lf", &duty);
   else if(rcvr_type == TM4_RCVR)   sscanf(edit_buffer, "%lf", &freq);
   else if(rcvr_type == ZYFER_RCVR) sscanf(edit_buffer, "%lf", &duty);
   else sscanf(edit_buffer, "%lf %lf", &freq, &duty);


   if(rcvr_type == CS_RCVR) {
   }
   else if((rcvr_type == ESIP_RCVR) && (chan == 0)) { // PPS pulse width
      if((duty < 1.0) || (duty > 500.0)) {
         edit_error("PPS width must be 1..500 msecs");
      }
      else {
         old_width = esip_pps_width;
         esip_pps_width = (int) duty;
         set_pps(user_pps_enable, pps_polarity,  cable_delay, pps1_delay,  pps_threshold, 4);
         esip_pps_width = old_width;
         request_pps_info();
      }
      return;
   }
   else if(rcvr_type == SS_RCVR) {
      old_width = (int) ss_pps_width;
      ss_pps_width = (int) (duty*1000.0);
      set_pps(user_pps_enable, pps_polarity,  cable_delay, pps1_delay,  pps_threshold, 4);
      ss_pps_width = (double) old_width;
      request_pps_info();
   }
   else if(rcvr_type == TM4_RCVR) {
   }
   else if(rcvr_type == ZYFER_RCVR) {
   }
   else if((chan == 1) && ((rcvr_type == NVS_RCVR) || ((rcvr_type == VENUS_RCVR) && !saw_timing_msg)) ) {
      edit_error("Receiver does not support PPS2");
      return;
   }
   else if(freq < 0.0) {
      edit_error("Frequency must be >= 0.0");
      return;
   }
   else if(duty <= 0.0) {
      edit_error("Duty cycle / pulse width must be > 0.0");
      return;
   }
   else if(duty >= 1.0) {  // duty is a pulse width in microseconds (or nanoseconds)
      if(rcvr_type == ESIP_RCVR) duty = freq * (duty/1.0E9);  // convert nanoeconds to duty cycle
      else if(rcvr_type == NVS_RCVR) duty = freq * (duty/1.0E9);  // convert nanoeconds to duty cycle
      else duty = freq * (duty/1.0E6);  // convert microseconds to duty cycle
      if(duty >= 1.0) {
         edit_error("Pulse width too long for specified frequency");
         return;
      }
   }

   if(chan == 0) set_pps_freq(chan, freq, duty, pps_polarity, cable_delay, pps1_delay, 1);
   else          set_pps_freq(chan, freq, duty, 0,            cable_delay, pps2_delay, 1); // rising edge gggg
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
leaq 0x2f9d90(%rip), %rax    # 0x3292e0
cmpb $0x0, (%rax)
je 0x2f7b4
movl %edi, %ebx
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, -0x30(%rbp)
movabsq $0x3fe0000000000000, %rax # imm = 0x3FE0000000000000
movq %rax, -0x28(%rbp)
leaq 0x1d3352(%rip), %r12    # 0x2028d0
movq (%r12), %rax
movabsq $0x400000000, %r15      # imm = 0x400000000
movabsq $0x800000000, %r14      # imm = 0x800000000
cmpq $0x20000, %rax          # imm = 0x20000
je 0x2f5da
cmpq $0x800, %rax            # imm = 0x800
je 0x2f5ee
movl $0x80000000, %ecx       # imm = 0x80000000
cmpq %rcx, %rax
setne %cl
testl %ebx, %ebx
setne %dl
orb %cl, %dl
je 0x2f5ee
testl %ebx, %ebx
setne %cl
cmpq %r14, %rax
setne %dl
orb %cl, %dl
je 0x2f5ee
cmpq $0x100000, %rax         # imm = 0x100000
je 0x2f5ee
cmpq %r15, %rax
jne 0x2f803
leaq 0x2f9cff(%rip), %rdi    # 0x3292e0
leaq 0xedba8(%rip), %rsi     # 0x11d190
leaq -0x30(%rbp), %rdx
jmp 0x2f600
leaq 0x2f9ceb(%rip), %rdi    # 0x3292e0
leaq 0xedb94(%rip), %rsi     # 0x11d190
leaq -0x28(%rbp), %rdx
xorl %eax, %eax
callq 0x9350
movq (%r12), %rax
cmpq $0x20000, %rax          # imm = 0x20000
jne 0x2f647
movsd -0x30(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
testl %ebx, %ebx
je 0x2f6de
leaq 0x2c879c(%rip), %rax    # 0x2f7dc8
movsd (%rax), %xmm2
leaq 0x2c87a9(%rip), %rax    # 0x2f7de0
movsd (%rax), %xmm3
pushq $0x1
popq %rdx
movl %ebx, %edi
xorl %esi, %esi
jmp 0x2f702
movl $0x80000000, %ecx       # imm = 0x80000000
cmpq %rcx, %rax
setne %cl
testl %ebx, %ebx
setne %dl
orb %cl, %dl
jne 0x2f70c
movsd -0x28(%rbp), %xmm0
movsd 0xc3a04(%rip), %xmm1    # 0xf3070
ucomisd %xmm0, %xmm1
ja 0x2f7a8
ucomisd 0xc6342(%rip), %xmm0    # 0xf59c0
ja 0x2f7a8
leaq 0x2c86e5(%rip), %rbx    # 0x2f7d70
cvttsd2si %xmm0, %eax
movl (%rbx), %r14d
movl %eax, (%rbx)
leaq 0x2c8686(%rip), %rax    # 0x2f7d21
movzbl (%rax), %edi
leaq 0x2c8673(%rip), %rax    # 0x2f7d18
movzbl (%rax), %esi
leaq 0x2c8719(%rip), %rax    # 0x2f7dc8
movsd (%rax), %xmm0
leaq 0x2c871e(%rip), %rax    # 0x2f7dd8
movsd (%rax), %xmm1
leaq 0x2c8657(%rip), %rax    # 0x2f7d1c
movss (%rax), %xmm2
pushq $0x4
popq %rdx
callq 0x61e97
movl %r14d, (%rbx)
callq 0x61bf1
jmp 0x2f7b4
leaq 0x2c8633(%rip), %rax    # 0x2f7d18
movl (%rax), %esi
leaq 0x2c86da(%rip), %rax    # 0x2f7dc8
movsd (%rax), %xmm2
leaq 0x2c86df(%rip), %rax    # 0x2f7dd8
movsd (%rax), %xmm3
pushq $0x1
popq %rdx
xorl %edi, %edi
callq 0x8793a
jmp 0x2f7b4
cmpq $0x100000, %rax         # imm = 0x100000
je 0x2f613
cmpq %r15, %rax
je 0x2f613
cmpq %r14, %rax
jne 0x2f7c1
leaq 0x2c8677(%rip), %r14    # 0x2f7da8
movsd -0x28(%rbp), %xmm0
mulsd 0xc38fa(%rip), %xmm0    # 0xf3038
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
movsd (%r14), %xmm1
movaps %xmm1, -0x40(%rbp)
movlps %xmm0, (%r14)
leaq 0x2c85c7(%rip), %rax    # 0x2f7d21
movzbl (%rax), %edi
leaq 0x2c85b4(%rip), %rax    # 0x2f7d18
movzbl (%rax), %esi
leaq 0x2c865a(%rip), %rax    # 0x2f7dc8
movsd (%rax), %xmm0
leaq 0x2c865f(%rip), %rax    # 0x2f7dd8
movsd (%rax), %xmm1
leaq 0x2c8598(%rip), %rax    # 0x2f7d1c
movss (%rax), %xmm2
pushq $0x4
popq %rdx
callq 0x61e97
cvttpd2dq -0x40(%rbp), %xmm0
cvtdq2pd %xmm0, %xmm0
movlpd %xmm0, (%r14)
callq 0x61bf1
jmp 0x2f613
leaq 0xcfa4c(%rip), %rdi     # 0xff1fb
callq 0x214df
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x1, %ebx
jne 0x2f7eb
cmpq $0x800, %rax            # imm = 0x800
je 0x2f7e2
cmpq $0x80, %rax
jne 0x2f7eb
leaq 0x2c7c4b(%rip), %rcx    # 0x2f7428
cmpl $0x0, (%rcx)
jne 0x2f7eb
leaq 0xcfa31(%rip), %rdi     # 0xff21a
jmp 0x2f7af
movsd -0x30(%rbp), %xmm0
xorpd %xmm2, %xmm2
ucomisd %xmm0, %xmm2
jbe 0x2f825
leaq 0xcfa38(%rip), %rdi     # 0xff239
jmp 0x2f7af
leaq 0x2f9ad6(%rip), %rdi    # 0x3292e0
leaq 0xed97b(%rip), %rsi     # 0x11d18c
leaq -0x30(%rbp), %rdx
leaq -0x28(%rbp), %rcx
xorl %eax, %eax
callq 0x9350
jmp 0x2f607
movsd -0x28(%rbp), %xmm1
ucomisd %xmm1, %xmm2
jae 0x2f85a
ucomisd 0xc3838(%rip), %xmm1    # 0xf3070
jb 0x2f613
cmpq $0x800, %rax            # imm = 0x800
je 0x2f850
movl $0x80000000, %ecx       # imm = 0x80000000
cmpq %rcx, %rax
jne 0x2f866
divsd 0xc37d0(%rip), %xmm1    # 0xf3028
jmp 0x2f86e
leaq 0xcf9f1(%rip), %rdi     # 0xff252
jmp 0x2f7af
divsd 0xc37e2(%rip), %xmm1    # 0xf3050
mulsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
ucomisd 0xc37f1(%rip), %xmm0    # 0xf3070
jb 0x2f613
leaq 0xcf9ed(%rip), %rdi     # 0xff279
jmp 0x2f7af