// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heathmsc.cpp
// Function: time_check(int, double, int, int, int, int, int, int, double)
int time_check(int reading_log, DATA_SIZE interval, int yy,int mon,int dd,  int hours,int minutes,int seconds,double frac)
{
double t;
int warn;
COORD row, col;
struct PLOT_Q q;
double nav_step;
double delta;

   // This routine verfies that time stamps are sequential
   // NEW_RCVR
   if(log_errors == 0) return 0;

   t = jdate(yy, mon, dd) - jdate(2012,0,0);
   t += jtime(hours,minutes,seconds,frac);
   t *= (24.0*60.0*60.0*1000.0);
   t = (double) (s64) (t+0.5);

   if(!have_last_stamp) {
      last_stamp = t;
      have_last_stamp = 1;
      return 0;
   }

   // see if we have a skip in the time stamp sequence
   warn = 0;   // assume properly consecutive time stamps

   nav_step = 1000.0;
   if(reading_log && interval) nav_step =  (double) (int) (((DATA_SIZE) 1000.0 * interval)+(DATA_SIZE) 0.50);
   else if(nav_rate) nav_step = (double) (int) ((1000.0 / nav_rate)+0.50);

   delta = fabs((t - last_stamp) - nav_step);

   if((rcvr_type == ACRON_RCVR) && status_second(seconds)) ;  // seconds value is when a long status message is being processed
   else if((rcvr_type == BRANDY_RCVR) && (delta < 800.0)) warn = 0;   // !!!! brandywine receiver can send multiple time stamps per second with millisecond fractions
   else if((rcvr_type == ESIP_RCVR) && (delta < 100.0)) warn = 0;
   else if((rcvr_type == LPFRS_RCVR) && (delta < 1400.0)) warn = 0;
   else if((rcvr_type == SA35_RCVR) && (delta < 1400.0)) warn = 0;
   else if((rcvr_type == RT17_RCVR) && (delta < 100.0)) warn = 0;  // toots
   else if((rcvr_type == SRO_RCVR) && (delta < 1400.0)) warn = 0;
   else if(STARLOC && starloc_skip_delay) --starloc_skip_delay;
   else if(STARLOC && bad_starloc_time && (delta == 1000.0)) warn = 0;
   else if((rcvr_type == TSIP_RCVR) && (tsip_type == SV6_TYPE) && (delta < 1100.0)) warn = 0;
   else if((rcvr_type == TSIP_RCVR) && (res_t == RES_T) && (raw_msg_rate >= 3) && (delta < 2100.0)) warn = 0;
   else if((rcvr_type == Z12_RCVR) && (delta < 750.0)) warn = 0;   // !!!! Z12 can send 0.5 sec backwards time stamps
//OSA   else if((rcvr_type == STAR_RCVR) && (star_type == OSA_TYPE) && (delta < 2200.0)) warn = 0;  // OSA
   else if(rcvr_type == TICC_RCVR) ;
   else if(lte_lite && (have_sawtooth == 0)) ;
   else if(time_checked == 0) warn = 0;   // it's the first time 
   else if((t-last_stamp) == 0.0) {  // duplicate time stamp
      warn = 1;
       if((rcvr_type == STAR_RCVR) && (star_type == OSA_TYPE)) warn = 0;  // OSA
   }
   else if(HIGH_TS_THRESH && (delta < TS_CHECK_THRESHOLD)) { // allow larger time stamp differences
      warn = 0;
   }
   else if(nav_rate && (reading_log == 0) && (delta > 1.0)) {  // more than 1msec err in time stamp sequence
      warn = 2;  // checking live readings
   }
   else if(reading_log && (delta > 1.0)) {  // time stamp sequence error > 1 msec
      warn = 3;   // checking log readings
   }
   bad_starloc_time = 0;

   if(0 && warn) {
      sprintf(debug_text2, "unt:%f step:%f last_stamp:%f  t:%f  delta:%f nav:%f warn:%d", 
      interval, nav_step, last_stamp, t, delta, 1.0/nav_rate, warn);
   }

//if(log_file) fprintf(log_file, "#! (%d) pri=%02d:%02d:%02d  adj:%02d:%02d:%02d\n", warn, pri_hours,pri_minutes,pri_seconds, hours,minutes,seconds);

   if(warn) {  // we have a duplicate or missing time stamp
      q = get_plot_q(plot_q_in);
      q.sat_flags |= TIME_SKIP;  
      put_plot_q(plot_q_in, q);

      if(log_errors && (reading_log == 0)) {
         if     (warn == 1) sprintf(log_text, "#! time stamp duplicated.  t=%.3f last=%.3f  delta=%.1f", t, last_stamp, delta);
         else if(warn == 2) sprintf(log_text, "#! time stamp skipped.  t=%.1f  last=%.1f  err:%.0f ms  %02d:%02d:%02d  delta=%.1f", t, last_stamp, t-last_stamp, hours,minutes,seconds, delta);
         else if(warn == 3) sprintf(log_text, "#! time stamp skipped in log file  delta=%.1f", delta);
         else               sprintf(log_text, "#! time stamp sequence error type: %d  delta=%.1f", warn, delta);
if(debug_file) fprintf(debug_file, "%s\n", log_text);
         write_log_comment(1);
      }

      if(log_comments && reading_log && log_errors) {
         if(text_mode) {
            row = EDIT_ROW;
            col = EDIT_COL;
         }
         else {
            row = PLOT_TEXT_ROW;
            col = PLOT_TEXT_COL;
         }
         sprintf(out, "#! time stamp skip %d in log.  interval=%.3f  step:%.1f  prev=%.3f this=%.3f  ", 
            warn, interval, nav_step, last_stamp, t);
         vidstr(row+4, col, RED, out);
         refresh_page();
      }
   }

   last_stamp = t;
   if(warn) time_checked = 0;
   else     time_checked = have_time;

   return warn;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
leaq 0x165afc(%rip), %r12    # 0x2283fb
xorl %r13d, %r13d
cmpb $0x0, (%r12)
je 0xc2ac5
movl %r9d, %r14d
movl %r8d, %r15d
movl %edi, %ebx
movsd %xmm0, -0x58(%rbp)
movl %esi, %edi
movl %edx, %esi
movl %ecx, %edx
movsd %xmm1, -0x30(%rbp)
callq 0xc2f07
addsd 0x52dce(%rip), %xmm0    # 0x115700
cvtsi2sd %r15d, %xmm1
cvtsi2sd %r14d, %xmm2
divsd 0x306c4(%rip), %xmm2    # 0xf3008
cvtsi2sdl 0x10(%rbp), %xmm3
addsd %xmm1, %xmm2
addsd -0x30(%rbp), %xmm3
divsd 0x306b6(%rip), %xmm3    # 0xf3010
addsd %xmm2, %xmm3
divsd 0x306da(%rip), %xmm3    # 0xf3040
addsd %xmm0, %xmm3
mulsd 0x4589e(%rip), %xmm3    # 0x108210
addsd 0x306ee(%rip), %xmm3    # 0xf3068
cvttsd2si %xmm3, %rax
cvtsi2sd %rax, %xmm2
leaq 0x14ac5e(%rip), %rax    # 0x20d5e9
cmpb $0x0, (%rax)
je 0xc29bf
testl %ebx, %ebx
movsd -0x58(%rbp), %xmm1
je 0xc29d2
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0xc29a5
jnp 0xc29d2
movsd 0x3068b(%rip), %xmm0    # 0xf3038
mulsd %xmm1, %xmm0
addsd 0x306af(%rip), %xmm0    # 0xf3068
cvttpd2dq %xmm0, %xmm0
jmp 0xc2a05
leaq 0x14ac1a(%rip), %rcx    # 0x20d5e0
movsd %xmm2, (%rcx)
movb $0x1, (%rax)
jmp 0xc2ac5
leaq 0x14297f(%rip), %rax    # 0x205358
movsd (%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xc29ed
jnp 0xc2ada
movsd 0x30643(%rip), %xmm1    # 0xf3038
divsd %xmm0, %xmm1
addsd 0x30667(%rip), %xmm1    # 0xf3068
cvttpd2dq %xmm1, %xmm0
cvtdq2pd %xmm0, %xmm3
leaq 0x14abd0(%rip), %r10    # 0x20d5e0
movapd %xmm2, %xmm4
subsd (%r10), %xmm4
leaq 0x13feb0(%rip), %r13    # 0x2028d0
movq (%r13), %rax
cmpq $0x4000, %rax           # imm = 0x4000
jne 0xc2a67
movl 0x10(%rbp), %edi
movsd %xmm2, -0x30(%rbp)
movq %r10, %r12
movapd %xmm3, -0x70(%rbp)
movapd %xmm4, -0x50(%rbp)
callq 0x43c47
movapd -0x50(%rbp), %xmm4
movapd -0x70(%rbp), %xmm3
movq %r12, %r10
leaq 0x1659a1(%rip), %r12    # 0x2283fb
movsd -0x30(%rbp), %xmm2
testl %eax, %eax
jne 0xc2aa1
movq (%r13), %rax
subsd %xmm3, %xmm4
andpd 0x3071d(%rip), %xmm4    # 0xf3190
cmpq $0x40000, %rax          # imm = 0x40000
jne 0xc2a89
movsd 0x52c85(%rip), %xmm0    # 0x115708
ucomisd %xmm4, %xmm0
ja 0xc2aa1
movl $0x80000000, %ecx       # imm = 0x80000000
cmpq %rcx, %rax
jne 0xc2ae7
movsd 0x305c5(%rip), %xmm0    # 0xf3060
ucomisd %xmm4, %xmm0
jbe 0xc2ae7
leaq 0x14ab48(%rip), %rax    # 0x20d5f0
andl $0x0, (%rax)
movsd %xmm2, (%r10)
leaq 0x166425(%rip), %rax    # 0x228edc
movb (%rax), %al
xorl %r13d, %r13d
leaq 0x14ab25(%rip), %rcx    # 0x20d5e8
movb %al, (%rcx)
movl %r13d, %eax
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsd 0x30556(%rip), %xmm3    # 0xf3038
jmp 0xc2a09
movsd 0x30571(%rip), %xmm0    # 0xf3060
ucomisd %xmm4, %xmm0
seta %dl
cmpq $0x10000000, %rax       # imm = 0x10000000
sete %dil
movsd 0x52c08(%rip), %xmm0    # 0x115710
ucomisd %xmm4, %xmm0
movabsq $0x1000000000, %rcx     # imm = 0x1000000000
seta %sil
cmpq %rcx, %rax
sete %r9b
orb %dil, %r9b
movabsq $0x200000000, %rdi      # imm = 0x200000000
cmpq %rdi, %rax
sete %r8b
cmpq $0x8000000, %rax        # imm = 0x8000000
sete %dil
testb %sil, %r9b
jne 0xc2aa1
andb %dl, %r8b
jne 0xc2aa1
andb %sil, %dil
jne 0xc2aa1
cmpq $0x1, %rax
sete %dl
leaq 0x14246c(%rip), %rsi    # 0x204fd4
movl (%rsi), %esi
cmpl $0x53, %esi
sete %dil
andb %dl, %dil
leaq 0x14aa71(%rip), %rdx    # 0x20d5ec
movl (%rdx), %r8d
testl %r8d, %r8d
setne %r9b
andb %dil, %r9b
cmpb $0x1, %r9b
jne 0xc2b99
decl %r8d
movl %r8d, (%rdx)
jmp 0xc2aa1
leaq 0x14aa50(%rip), %rdx    # 0x20d5f0
cmpl $0x0, (%rdx)
setne %r8b
andb %r8b, %dil
cmpb $0x1, %dil
jne 0xc2bc0
ucomisd 0x30480(%rip), %xmm4    # 0xf3038
jne 0xc2bc0
jnp 0xc2aa1
cmpq $0x1, %rax
jne 0xc2bdd
cmpl $0x36, %esi
jne 0xc2bdd
movsd 0x52b45(%rip), %xmm0    # 0x115718
ucomisd %xmm4, %xmm0
ja 0xc2aa1
cmpq $0x1, %rax
jne 0xc2c0d
leaq 0x13fd1a(%rip), %rsi    # 0x202904
cmpb $0x1, (%rsi)
jne 0xc2c0d
leaq 0x142782(%rip), %rsi    # 0x205378
cmpl $0x3, (%rsi)
jl 0xc2c0d
movsd 0x52b1d(%rip), %xmm0    # 0x115720
ucomisd %xmm4, %xmm0
ja 0xc2aa1
movabsq $0x100000000, %rsi      # imm = 0x100000000
cmpq %rsi, %rax
sete %sil
movsd 0x52b02(%rip), %xmm0    # 0x115728
ucomisd %xmm4, %xmm0
seta %dil
cmpq $0x10000, %rax          # imm = 0x10000
je 0xc2aa1
andb %dil, %sil
jne 0xc2aa1
leaq 0x142386(%rip), %rsi    # 0x204fd0
cmpl $0x0, (%rsi)
setne %sil
leaq 0x23476c(%rip), %rdi    # 0x2f73c4
cmpl $0x0, (%rdi)
sete %dil
testb %dil, %sil
jne 0xc2aa1
leaq 0x14a979(%rip), %rsi    # 0x20d5e8
cmpb $0x0, (%rsi)
je 0xc2aa1
movsd (%r10), %xmm1
ucomisd %xmm2, %xmm1
jne 0xc2ca6
jp 0xc2ca6
pushq $0x1
popq %r13
andl $0x0, (%rdx)
cmpq $0x1000, %rax           # imm = 0x1000
jne 0xc2d02
leaq 0x14234d(%rip), %rax    # 0x204fe8
cmpl $0x4f, (%rax)
je 0xc2aab
jmp 0xc2d02
addq $0x1b880400, %rcx       # imm = 0x1B880400
testq %rcx, %rax
je 0xc2cbc
ucomisd %xmm4, %xmm0
ja 0xc2aa1
testl %ebx, %ebx
jne 0xc2ce5
leaq 0x142691(%rip), %rax    # 0x205358
movsd (%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xc2cd7
jnp 0xc2ce5
ucomisd 0x30391(%rip), %xmm4    # 0xf3070
jbe 0xc2ce5
pushq $0x2
jmp 0xc2cfd
testl %ebx, %ebx
je 0xc2aa1
ucomisd 0x3037b(%rip), %xmm4    # 0xf3070
jbe 0xc2aa1
pushq $0x3
popq %r13
andl $0x0, (%rdx)
movapd %xmm4, -0x50(%rbp)
movapd %xmm3, -0x70(%rbp)
movsd %xmm2, -0x30(%rbp)
leaq 0x142610(%rip), %rax    # 0x205328
movq (%rax), %rsi
leaq -0x1d0(%rbp), %rdi
callq 0xf9c7
leaq -0x1ce(%rbp), %rsi
leaq -0x11e(%rbp), %rdi
movl $0x400, %eax            # imm = 0x400
orl -0x2(%rsi), %eax
movl %eax, -0x34(%rbp)
movl $0xae, %edx
callq 0x92a0
leaq 0x1425d7(%rip), %rax    # 0x205328
movq (%rax), %rax
movl -0x34(%rbp), %ecx
leaq -0x11e(%rbp), %rdx
movw %cx, -0x2(%rdx)
pushq $0x16
popq %rcx
leaq -0x120(%rbp), %rsi
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq %rax, %rdi
callq 0xfb93
movb (%r12), %al
testb %al, %al
sete %cl
testl %ebx, %ebx
setne %dl
orb %cl, %dl
jne 0xc2e50
cmpl $0x2, %r13d
je 0xc2dc8
cmpl $0x1, %r13d
jne 0xc2e06
leaq 0x14a83d(%rip), %rax    # 0x20d5e0
movsd (%rax), %xmm1
leaq 0x164bb2(%rip), %rdi    # 0x227960
leaq 0x59b04(%rip), %rsi     # 0x11c8b9
movsd -0x30(%rbp), %xmm0
movapd -0x50(%rbp), %xmm2
movb $0x3, %al
callq 0x9060
jmp 0xc2e20
leaq 0x14a811(%rip), %rax    # 0x20d5e0
movsd (%rax), %xmm1
movsd -0x30(%rbp), %xmm0
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
leaq 0x164b79(%rip), %rdi    # 0x227960
leaq 0x59b03(%rip), %rsi     # 0x11c8f1
movl %r15d, %edx
movl %r14d, %ecx
movl 0x10(%rbp), %r8d
movapd -0x50(%rbp), %xmm3
movb $0x4, %al
callq 0x9060
jmp 0xc2e20
leaq 0x164b53(%rip), %rdi    # 0x227960
leaq 0x59b30(%rip), %rsi     # 0x11c944
movapd -0x50(%rbp), %xmm0
movb $0x1, %al
callq 0x9060
leaq 0x165569(%rip), %rax    # 0x228390
movq (%rax), %rdi
testq %rdi, %rdi
je 0xc2e44
leaq 0x4cbe9(%rip), %rsi     # 0x10fa1f
leaq 0x164b23(%rip), %rdx    # 0x227960
xorl %eax, %eax
callq 0x9560
pushq $0x1
popq %rdi
callq 0xb25f5
movb (%r12), %al
testl %ebx, %ebx
movsd -0x30(%rbp), %xmm0
leaq 0x14a782(%rip), %rdx    # 0x20d5e0
je 0xc2efc
leaq 0x1655a9(%rip), %rcx    # 0x228414
cmpb $0x0, (%rcx)
je 0xc2efc
testb %al, %al
je 0xc2efc
leaq 0x13f955(%rip), %rax    # 0x2027d8
cmpl $0x0, (%rax)
leaq 0x266783(%rip), %rax    # 0x329610
cmoveq 0x7713b(%rip), %rax     # 0x139fd0
leaq 0x266770(%rip), %rcx    # 0x32960c
cmoveq 0x76fec(%rip), %rcx     # 0x139e90
movl (%rax), %ebx
movl (%rcx), %r14d
movsd (%rdx), %xmm2
leaq 0x26336c(%rip), %r15    # 0x326220
leaq 0x59ab7(%rip), %rsi     # 0x11c972
movq %r15, %rdi
movl %r13d, %edx
movsd -0x58(%rbp), %xmm0
movapd -0x70(%rbp), %xmm1
movsd -0x30(%rbp), %xmm3
movb $0x4, %al
callq 0x9060
addl $0x4, %r14d
pushq $0xc
popq %rdx
movl %r14d, %edi
movl %ebx, %esi
movq %r15, %rcx
callq 0xe2d2
callq 0xaa05
leaq 0x14a6e9(%rip), %rdx    # 0x20d5e0
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%rdx)
xorl %eax, %eax
jmp 0xc2abc