// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heathui.cpp
// Function: set_jitter_config()
void set_jitter_config()
{
int i;
int ndx;
int max_bin;
double max_val;
double val;
double peak_div;
double avg;
double sdev;
double sum_y, sum_yy;
struct PLOT_Q q;

   // set up the machine to measure and display receiver message timing

   if(measure_jitter) {  // jitter measurements just enabled
      old_idle = idle_sleep;       // save current settings
      old_jit_adev = jitter_adev;
      old_poll = no_poll;

      old_plot_watch = plot_watch;
      old_plot_azel = plot_azel;
      for(i=0; i<NUM_PLOTS+DERIVED_PLOTS; i++) {  // disable all plots
         old_show_plots[i] = plot[i].show_plot;
         plot[i].show_plot = 0;
      }

      plot[MSGJIT].show_plot = 1;
      plot[MSGOFS].show_plot = 1;
      plot_watch = 0;
      plot_azel = 0;
                                   // set optimum values for jitter measurement
      idle_sleep = 0;
      jitter_adev = 1;
//    no_poll = 1;                 // rrrrr messes up things like SCPI that must be polled
      new_queue(RESET_ALL_QUEUES, 63); // flush the queues
   }
   else {  // jitter measurements disabled, restore old settings, calculate histogram
      sprintf(log_text, "#");
      write_log_comment(1);
      sprintf(log_text, "#  Jitter measurement ADEVs");
      write_log_comment(1);
      sprintf(log_text, "#");
      write_log_comment(1);
      log_adevs();
      log_stats();

      idle_sleep = old_idle;
      jitter_adev = old_jit_adev;
      no_poll = old_poll;

      plot_watch = old_plot_watch;
      plot_azel = old_plot_azel;
      for(i=0; i<NUM_PLOTS+DERIVED_PLOTS; i++) {  // disable all plots
         plot[i].show_plot = old_show_plots[i];
      }


      // calculate histogram of message arrival times (+/- 2000 msecs, 0.1 msec res
      if(plot_q_count == 0) return;
      if(hist_file) {
         fclose(hist_file);
         hist_file = 0;
      }
      sprintf(out, "%s.jit", unit_file_name);
      hist_file = topen(out, "w");
      if(hist_file == 0) return;

      for(i=0; i<HIST_BINS; i++) hist[i] = 0;

      avg = 0.0;
      sum_y = sum_yy = 0.0;
      for(i=0; i<plot_q_count; i++) {  // calculate histogram of message offset times
         q = plot_q[i];
         if(queue_interval) val = ((double) q.data[MSGOFS] / (double) queue_interval);
         else val = 0.0;

         sum_y += val;
         sum_yy += (val * val);

         ndx = (int) (val*HIST_SCALE+0.50);
         ndx += (HIST_BINS/2);
         if((ndx < 0) || (ndx >= HIST_BINS)) continue;
         ++hist[ndx];
      }
      if(plot_q_count) avg = sum_y / (double) plot_q_count;
      sdev = sqrt(fabs((sum_yy / (double) plot_q_count) - (avg*avg)));


fprintf(hist_file, "# bin   count\n");
      max_bin = 0;
      max_val = 0.0;
      peak_div = 1.0;
      for(i=0; i<HIST_BINS; i++) {  // write histogram data
         if(HIST_SCALE) val = (double) (i - (HIST_BINS/2)) / (double) HIST_SCALE;
         else val = 0.0;
         if(hist[i]) {
            fprintf(hist_file, "%.2f %d\n", val, hist[i]);
            if(hist[i] > max_bin) {  // a new peak
               max_bin = hist[i];
               max_val = val;
               peak_div = 1.0;
            }
            else if(hist[i] == max_bin) {  // broad peak, average the values
               max_val += val;
               ++peak_div;
            }
         }
      }

      sprintf(plot_title, "# msg offset time: /tsx=%.2f msec   max hits:%d points:%ld   avg:%.2f sdev:%.2f", max_val/peak_div,  max_bin, plot_q_count, avg,sdev);
      fprintf(hist_file,  "# msg offset time: /tsx=%.2f msec   max hits:%d points:%ld   avg:%.2f sdev:%.2f", max_val/peak_div,  max_bin, plot_q_count, avg,sdev);
      fclose(hist_file);
      hist_file = 0;
   }

   dont_reset_queues = 0;
   new_queue(RESET_ADEV_Q, 12);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
leaq 0x1eeff7(%rip), %rax    # 0x226cc8
cmpl $0x0, (%rax)
je 0x37db4
leaq 0x1d5917(%rip), %rax    # 0x20d5f8
movl (%rax), %ecx
leaq 0x1eefe2(%rip), %rdx    # 0x226ccc
movl %ecx, (%rdx)
leaq 0x1eefd1(%rip), %rcx    # 0x226cc4
movl (%rcx), %edx
leaq 0x1eefd8(%rip), %rsi    # 0x226cd4
movl %edx, (%rsi)
leaq 0x2e931b(%rip), %rdx    # 0x321020
movzbl (%rdx), %edx
leaq 0x1eefc1(%rip), %rsi    # 0x226cd0
movl %edx, (%rsi)
leaq 0x1cd6f0(%rip), %rdx    # 0x205408
movb (%rdx), %sil
movb %sil, 0x2f4c33(%rip)    # 0x32c955
leaq 0x1cd6ea(%rip), %rsi    # 0x205413
movb (%rsi), %dil
movb %dil, 0x2f4c21(%rip)    # 0x32c954
leaq 0x10fff6(%rip), %rdi    # 0x147d30
leaq 0x18(%rdi), %r8
xorl %r9d, %r9d
leaq 0x2f4bf8(%rip), %r10    # 0x32c940
cmpq $0x14, %r9
je 0x37d65
movb (%r8), %r11b
andl $0x0, (%r8)
movb %r11b, (%r9,%r10)
incq %r9
addq $0xe8, %r8
jmp 0x37d48
pushq $0x1
popq %r8
movl %r8d, 0xbe0(%rdi)
movl %r8d, 0xaf8(%rdi)
xorl %edi, %edi
movb %dil, (%rdx)
movb %dil, (%rsi)
andq $0x0, (%rax)
movl %r8d, (%rcx)
pushq $0x7
popq %rdi
pushq $0x3f
popq %rsi
callq 0x10a99
leaq 0x122ec8(%rip), %rax    # 0x15ac60
andl $0x0, (%rax)
pushq $0x1
popq %rdi
pushq $0xc
popq %rsi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x10a99
leaq 0x1efba5(%rip), %r14    # 0x227960
movw $0x23, %r15w
movw %r15w, (%r14)
pushq $0x1
popq %rbx
movl %ebx, %edi
callq 0xb25f5
movups 0xc9193(%rip), %xmm0    # 0x100f68
movups %xmm0, 0xc(%r14)
movupd 0xc917a(%rip), %xmm0    # 0x100f5c
movapd %xmm0, (%r14)
movl %ebx, %edi
callq 0xb25f5
movw %r15w, (%r14)
movl %ebx, %edi
callq 0xb25f5
callq 0xc0849
callq 0xbfd20
leaq 0x1eeec2(%rip), %rax    # 0x226ccc
movslq (%rax), %rax
leaq 0x1d57e4(%rip), %rcx    # 0x20d5f8
movq %rax, (%rcx)
leaq 0x1eeeb6(%rip), %rax    # 0x226cd4
movl (%rax), %eax
leaq 0x1eee9d(%rip), %rcx    # 0x226cc4
movl %eax, (%rcx)
leaq 0x1eeea0(%rip), %rax    # 0x226cd0
movb (%rax), %al
leaq 0x2e91e7(%rip), %rcx    # 0x321020
movb %al, (%rcx)
movb 0x2f4b14(%rip), %al     # 0x32c955
leaq 0x1cd5c0(%rip), %rcx    # 0x205408
movb %al, (%rcx)
movb 0x2f4b04(%rip), %al     # 0x32c954
leaq 0x1cd5bc(%rip), %rcx    # 0x205413
movb %al, (%rcx)
leaq 0x10fed0(%rip), %rax    # 0x147d30
addq $0x18, %rax
xorl %ecx, %ecx
leaq 0x2f4ad3(%rip), %rdx    # 0x32c940
cmpq $0x14, %rcx
je 0x37e84
movzbl (%rcx,%rdx), %esi
movl %esi, (%rax)
incq %rcx
addq $0xe8, %rax
jmp 0x37e6d
leaq 0x1cd4ad(%rip), %r15    # 0x205338
cmpq $0x0, (%r15)
je 0x37eff
leaq 0x1f0510(%rip), %r14    # 0x2283a8
movq (%r14), %rdi
testq %rdi, %rdi
je 0x37ea9
callq 0x9360
andq $0x0, (%r14)
leaq 0x122dd8(%rip), %rax    # 0x15ac88
movq (%rax), %rdx
leaq 0x2ee366(%rip), %rbx    # 0x326220
leaq 0xc90b7(%rip), %rsi     # 0x100f78
movq %rbx, %rdi
xorl %eax, %eax
callq 0x9060
leaq 0xd3431(%rip), %rsi     # 0x10b303
movq %rbx, %rdi
callq 0x9a22
movq %rax, (%r14)
testq %rax, %rax
je 0x37eff
xorl %ecx, %ecx
leaq 0x2f6875(%rip), %r13    # 0x32e760
cmpq $0x27100, %rcx          # imm = 0x27100
je 0x37f0e
andl $0x0, (%rcx,%r13)
addq $0x4, %rcx
jmp 0x37eeb
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r15), %rcx
leaq 0x1cd480(%rip), %rdx    # 0x205398
movq (%rdx), %rdx
leaq 0x1cd3ee(%rip), %rsi    # 0x205310
movq (%rsi), %rsi
cvtsi2sd %rdx, %xmm1
xorl %edi, %edi
testq %rcx, %rcx
cmovgq %rcx, %rdi
addq $0x70, %rsi
xorpd %xmm0, %xmm0
movsd 0xbb125(%rip), %xmm2    # 0xf3068
xorpd %xmm5, %xmm5
subq $0x1, %rdi
jb 0x37fa6
testq %rdx, %rdx
je 0x37f5c
movsd (%rsi), %xmm3
divsd %xmm1, %xmm3
jmp 0x37f60
xorpd %xmm3, %xmm3
movapd %xmm3, %xmm4
mulsd 0xbb13c(%rip), %xmm4    # 0xf30a8
addsd %xmm2, %xmm4
cvttsd2si %xmm4, %r8d
leal -0x4e20(%r8), %r9d
cmpl $0xffff63c0, %r9d       # imm = 0xFFFF63C0
jb 0x37f91
addl $0x4e20, %r8d           # imm = 0x4E20
incl (%r13,%r8,4)
addsd %xmm3, %xmm0
mulsd %xmm3, %xmm3
addsd %xmm3, %xmm5
addq $0xb0, %rsi
jmp 0x37f47
cvtsi2sd %rcx, %xmm1
xorpd %xmm2, %xmm2
movsd %xmm2, -0x30(%rbp)
testq %rcx, %rcx
je 0x37fc1
divsd %xmm1, %xmm0
movapd %xmm0, %xmm2
divsd %xmm1, %xmm5
movsd %xmm2, -0x48(%rbp)
movapd %xmm2, %xmm0
mulsd %xmm2, %xmm0
subsd %xmm0, %xmm5
andpd 0xbb1b2(%rip), %xmm5    # 0xf3190
movapd %xmm5, -0x60(%rbp)
leaq 0xc8f95(%rip), %rdi     # 0x100f7f
pushq $0xe
popq %rsi
pushq $0x1
popq %rdx
movq %rax, %rcx
callq 0x9750
movsd 0xbb070(%rip), %xmm0    # 0xf3070
xorl %r12d, %r12d
movl $0xffffb1e0, %r15d      # imm = 0xFFFFB1E0
leaq 0xc8f7e(%rip), %r14     # 0x100f8e
xorl %ebx, %ebx
movsd %xmm0, -0x38(%rbp)
movsd 0xbb089(%rip), %xmm1    # 0xf30a8
cmpq $0x27100, %r12          # imm = 0x27100
je 0x380af
cvtsi2sd %r15d, %xmm0
divsd %xmm1, %xmm0
movl (%r12,%r13), %edx
testl %edx, %edx
je 0x380a3
leaq 0x1f0364(%rip), %rax    # 0x2283a8
movq (%rax), %rdi
movq %r14, %rsi
movb $0x1, %al
movsd %xmm0, -0x40(%rbp)
callq 0x9560
movl (%r12,%r13), %eax
cmpl %ebx, %eax
jle 0x38074
movl %eax, %ebx
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd 0xbaffe(%rip), %xmm0    # 0xf3070
jmp 0x38096
movsd -0x40(%rbp), %xmm1
jne 0x3809b
movsd -0x30(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x38(%rbp), %xmm0
addsd 0xbafda(%rip), %xmm0    # 0xf3070
movsd %xmm0, -0x38(%rbp)
movsd 0xbb005(%rip), %xmm1    # 0xf30a8
incl %r15d
addq $0x4, %r12
jmp 0x3801f
sqrtsd -0x60(%rbp), %xmm2
movsd %xmm2, -0x40(%rbp)
movsd -0x30(%rbp), %xmm0
divsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq 0x1cd269(%rip), %r12    # 0x205338
movq (%r12), %rcx
leaq 0x2f0776(%rip), %rdi    # 0x328850
leaq 0xc8eb6(%rip), %r14     # 0x100f97
movq %r14, %rsi
movl %ebx, %edx
movsd -0x48(%rbp), %xmm1
movb $0x3, %al
callq 0x9060
leaq 0x1f02af(%rip), %r15    # 0x2283a8
movq (%r15), %rdi
movq (%r12), %rcx
movq %r14, %rsi
movsd -0x30(%rbp), %xmm0
movl %ebx, %edx
movsd -0x48(%rbp), %xmm1
movsd -0x40(%rbp), %xmm2
movb $0x3, %al
callq 0x9560
movq (%r15), %rdi
callq 0x9360
andq $0x0, (%r15)
jmp 0x37d91