// File: /workspace/github_cpp_makefile_star2_O3/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 0x16a1cd(%rip), %rax    # 0x23e3fb
xorl %r13d, %r13d
cmpb $0x0, (%rax)
je 0xd43fd
movl %r9d, %ebx
movl %r8d, %r14d
movl %edi, %r12d
movsd %xmm0, -0x58(%rbp)
movl 0x10(%rbp), %r15d
movl %esi, %edi
movl %edx, %esi
movl %ecx, %edx
movsd %xmm1, -0x30(%rbp)
callq 0xd485e
addsd 0x57554(%rip), %xmm0    # 0x12b7b8
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
cvtsi2sd %ebx, %xmm2
divsd 0x34d90(%rip), %xmm2    # 0x109008
cvtsi2sd %r15d, %xmm3
addsd %xmm1, %xmm2
addsd -0x30(%rbp), %xmm3
divsd 0x34d82(%rip), %xmm3    # 0x109010
addsd %xmm2, %xmm3
divsd 0x34da6(%rip), %xmm3    # 0x109040
addsd %xmm0, %xmm3
mulsd 0x49ef2(%rip), %xmm3    # 0x11e198
addsd 0x34dba(%rip), %xmm3    # 0x109068
cvttsd2si %xmm3, %rax
xorps %xmm2, %xmm2
cvtsi2sd %rax, %xmm2
leaq 0x14f327(%rip), %rax    # 0x2235e9
cmpb $0x0, (%rax)
je 0xd42f7
testl %r12d, %r12d
movsd -0x58(%rbp), %xmm1
je 0xd430a
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0xd42dd
jnp 0xd430a
movsd 0x34d53(%rip), %xmm0    # 0x109038
mulsd %xmm1, %xmm0
addsd 0x34d77(%rip), %xmm0    # 0x109068
cvttpd2dq %xmm0, %xmm0
jmp 0xd433d
leaq 0x14f2e2(%rip), %rcx    # 0x2235e0
movsd %xmm2, (%rcx)
movb $0x1, (%rax)
jmp 0xd43fd
leaq 0x147047(%rip), %rax    # 0x21b358
movsd (%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xd4325
jnp 0xd4412
movsd 0x34d0b(%rip), %xmm1    # 0x109038
divsd %xmm0, %xmm1
addsd 0x34d2f(%rip), %xmm1    # 0x109068
cvttpd2dq %xmm1, %xmm0
cvtdq2pd %xmm0, %xmm3
leaq 0x14f298(%rip), %r10    # 0x2235e0
movapd %xmm2, %xmm4
subsd (%r10), %xmm4
leaq 0x144578(%rip), %r13    # 0x2188d0
movq (%r13), %rax
cmpq $0x4000, %rax           # imm = 0x4000
jne 0xd439c
movl %r15d, %edi
movsd %xmm2, -0x30(%rbp)
movq %r10, %r15
movapd %xmm3, -0x70(%rbp)
movapd %xmm4, -0x50(%rbp)
callq 0x47b01
movapd -0x50(%rbp), %xmm4
movapd -0x70(%rbp), %xmm3
movq %r15, %r10
movl 0x10(%rbp), %r15d
movsd -0x30(%rbp), %xmm2
testl %eax, %eax
jne 0xd43d6
movq (%r13), %rax
subsd %xmm3, %xmm4
andpd 0x34de8(%rip), %xmm4    # 0x109190
cmpq $0x40000, %rax          # imm = 0x40000
jne 0xd43be
movsd 0x57408(%rip), %xmm0    # 0x12b7c0
ucomisd %xmm4, %xmm0
ja 0xd43d6
movl $0x80000000, %ecx       # imm = 0x80000000
cmpq %rcx, %rax
jne 0xd441f
movsd 0x34c90(%rip), %xmm0    # 0x109060
ucomisd %xmm4, %xmm0
jbe 0xd441f
leaq 0x14f213(%rip), %rax    # 0x2235f0
movl $0x0, (%rax)
movsd %xmm2, (%r10)
leaq 0x16aaed(%rip), %rax    # 0x23eedc
movb (%rax), %al
xorl %r13d, %r13d
leaq 0x14f1ed(%rip), %rcx    # 0x2235e8
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 0x34c1e(%rip), %xmm3    # 0x109038
jmp 0xd4341
movsd 0x34c39(%rip), %xmm0    # 0x109060
ucomisd %xmm4, %xmm0
seta %dl
cmpq $0x10000000, %rax       # imm = 0x10000000
sete %dil
movsd 0x57388(%rip), %xmm0    # 0x12b7c8
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 0xd43d6
andb %dl, %r8b
jne 0xd43d6
andb %sil, %dil
jne 0xd43d6
cmpq $0x1, %rax
sete %dl
leaq 0x146b34(%rip), %rsi    # 0x21afd4
movl (%rsi), %esi
cmpl $0x53, %esi
sete %dil
andb %dl, %dil
leaq 0x14f139(%rip), %rdx    # 0x2235ec
movl (%rdx), %r8d
testl %r8d, %r8d
setne %r9b
andb %dil, %r9b
cmpb $0x1, %r9b
jne 0xd44d1
decl %r8d
movl %r8d, (%rdx)
jmp 0xd43d6
leaq 0x14f118(%rip), %rdx    # 0x2235f0
cmpl $0x0, (%rdx)
setne %r8b
andb %r8b, %dil
cmpb $0x1, %dil
jne 0xd44f8
ucomisd 0x34b48(%rip), %xmm4    # 0x109038
jne 0xd44f8
jnp 0xd43d6
cmpq $0x1, %rax
jne 0xd4515
cmpl $0x36, %esi
jne 0xd4515
movsd 0x572c5(%rip), %xmm0    # 0x12b7d0
ucomisd %xmm4, %xmm0
ja 0xd43d6
cmpq $0x1, %rax
jne 0xd4545
leaq 0x1443e2(%rip), %rsi    # 0x218904
cmpb $0x1, (%rsi)
jne 0xd4545
leaq 0x146e4a(%rip), %rsi    # 0x21b378
cmpl $0x3, (%rsi)
jl 0xd4545
movsd 0x5729d(%rip), %xmm0    # 0x12b7d8
ucomisd %xmm4, %xmm0
ja 0xd43d6
movabsq $0x100000000, %rsi      # imm = 0x100000000
cmpq %rsi, %rax
sete %sil
movsd 0x57282(%rip), %xmm0    # 0x12b7e0
ucomisd %xmm4, %xmm0
seta %dil
cmpq $0x10000, %rax          # imm = 0x10000
je 0xd43d6
andb %dil, %sil
jne 0xd43d6
leaq 0x146a4e(%rip), %rsi    # 0x21afd0
cmpl $0x0, (%rsi)
setne %sil
leaq 0x238e34(%rip), %rdi    # 0x30d3c4
cmpl $0x0, (%rdi)
sete %dil
testb %dil, %sil
jne 0xd43d6
leaq 0x14f041(%rip), %rsi    # 0x2235e8
cmpb $0x0, (%rsi)
je 0xd43d6
movsd (%r10), %xmm1
ucomisd %xmm2, %xmm1
jne 0xd45e5
jp 0xd45e5
leaq 0x146a24(%rip), %rcx    # 0x21afe8
movl (%rcx), %ecx
movl $0x0, (%rdx)
movl $0x1, %r13d
cmpq $0x1000, %rax           # imm = 0x1000
jne 0xd464a
cmpl $0x4f, %ecx
je 0xd43e3
jmp 0xd464a
addq $0x1b880400, %rcx       # imm = 0x1B880400
testq %rcx, %rax
je 0xd45fb
ucomisd %xmm4, %xmm0
ja 0xd43d6
testl %r12d, %r12d
jne 0xd4627
leaq 0x146d51(%rip), %rax    # 0x21b358
movsd (%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xd4617
jnp 0xd4627
movl $0x2, %r13d
ucomisd 0x34a4b(%rip), %xmm4    # 0x109070
ja 0xd4644
testl %r12d, %r12d
je 0xd43d6
movl $0x3, %r13d
ucomisd 0x34a32(%rip), %xmm4    # 0x109070
jbe 0xd43d6
movl $0x0, (%rdx)
movapd %xmm4, -0x50(%rbp)
movapd %xmm3, -0x70(%rbp)
movsd %xmm2, -0x30(%rbp)
leaq 0x146cc8(%rip), %rax    # 0x21b328
movq (%rax), %rsi
leaq -0x1d0(%rbp), %rdi
callq 0x100be
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 0x92b0
leaq 0x146c8f(%rip), %rax    # 0x21b328
movq (%rax), %rax
movl -0x34(%rbp), %ecx
leaq -0x11e(%rbp), %rdx
movw %cx, -0x2(%rdx)
leaq -0x120(%rbp), %rsi
movl $0x16, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq %rax, %rdi
callq 0x1028a
leaq 0x169d30(%rip), %rax    # 0x23e3fb
movb (%rax), %al
testb %al, %al
sete %cl
testl %r12d, %r12d
setne %dl
orb %cl, %dl
jne 0xd471f
cmpl $0x2, %r13d
je 0xd47c3
cmpl $0x1, %r13d
jne 0xd47ff
leaq 0x14eee9(%rip), %rax    # 0x2235e0
movsd (%rax), %xmm1
leaq 0x16925e(%rip), %rdi    # 0x23d960
leaq 0x5e290(%rip), %rsi     # 0x132999
movsd -0x30(%rbp), %xmm0
movapd -0x50(%rbp), %xmm2
movb $0x3, %al
callq 0x9060
jmp 0xd4819
testb %al, %al
sete %al
testl %r12d, %r12d
sete %cl
leaq 0x169ce3(%rip), %rdx    # 0x23e414
cmpb $0x0, (%rdx)
sete %dl
orb %cl, %dl
orb %al, %dl
jne 0xd4847
leaq 0x144090(%rip), %rax    # 0x2187d8
cmpl $0x0, (%rax)
leaq 0x26aebe(%rip), %rax    # 0x33f610
cmoveq 0x7b876(%rip), %rax     # 0x14ffd0
leaq 0x26aeab(%rip), %rcx    # 0x33f60c
cmoveq 0x7b71f(%rip), %rcx     # 0x14fe88
movl (%rax), %ebx
movl (%rcx), %r14d
leaq 0x14ee6b(%rip), %rax    # 0x2235e0
movsd (%rax), %xmm2
leaq 0x267aa0(%rip), %r15    # 0x33c220
leaq 0x5e2cb(%rip), %rsi     # 0x132a52
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
movl %r14d, %edi
movl %ebx, %esi
movl $0xc, %edx
movq %r15, %rcx
callq 0xe787
callq 0xab54
jmp 0xd4847
leaq 0x14ee16(%rip), %rax    # 0x2235e0
movsd (%rax), %xmm1
movsd -0x30(%rbp), %xmm0
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
leaq 0x16917e(%rip), %rdi    # 0x23d960
leaq 0x5e1e8(%rip), %rsi     # 0x1329d1
movl %r14d, %edx
movl %ebx, %ecx
movl %r15d, %r8d
movapd -0x50(%rbp), %xmm3
movb $0x4, %al
callq 0x9060
jmp 0xd4819
leaq 0x16915a(%rip), %rdi    # 0x23d960
leaq 0x5e217(%rip), %rsi     # 0x132a24
movapd -0x50(%rbp), %xmm0
movb $0x1, %al
callq 0x9060
leaq 0x169b70(%rip), %rax    # 0x23e390
movq (%rax), %rdi
testq %rdi, %rdi
je 0xd483d
leaq 0x512a8(%rip), %rsi     # 0x125ad7
leaq 0x16912a(%rip), %rdx    # 0x23d960
xorl %eax, %eax
callq 0x9560
movl $0x1, %edi
callq 0xc36e2
movsd -0x30(%rbp), %xmm0
leaq 0x14ed8d(%rip), %rax    # 0x2235e0
movsd %xmm0, (%rax)
xorl %eax, %eax
jmp 0xd43f4