// File: 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
subq $0x330, %rsp            # imm = 0x330
movl 0x10(%rbp), %eax
movl %edi, -0x8(%rbp)
movsd %xmm0, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
movsd %xmm1, -0x30(%rbp)
leaq 0x17bcc8(%rip), %rax    # 0x29d5db
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x121927
movl $0x0, -0x4(%rbp)
jmp 0x122131
movl -0x14(%rbp), %edi
movl -0x18(%rbp), %esi
movl -0x1c(%rbp), %edx
callq 0x122140
movsd %xmm0, -0x270(%rbp)
movl $0x7dc, %edi            # imm = 0x7DC
xorl %edx, %edx
movl %edx, %esi
callq 0x122140
movaps %xmm0, %xmm1
movsd -0x270(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movl -0x20(%rbp), %edi
movl -0x24(%rbp), %esi
movl 0x10(%rbp), %edx
movsd -0x30(%rbp), %xmm0
callq 0x122210
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd 0x61214(%rip), %xmm0    # 0x182b98
mulsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd 0x4d6fa(%rip), %xmm0    # 0x16f090
addsd -0x38(%rbp), %xmm0
cvttsd2si %xmm0, %rax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x38(%rbp)
leaq 0x160e18(%rip), %rax    # 0x2827c9
cmpb $0x0, (%rax)
jne 0x1219dc
movsd -0x38(%rbp), %xmm0
leaq 0x160dfe(%rip), %rax    # 0x2827c0
movsd %xmm0, (%rax)
leaq 0x160dfc(%rip), %rax    # 0x2827c9
movb $0x1, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x122131
movl $0x0, -0x3c(%rbp)
movsd 0x4d645(%rip), %xmm0    # 0x16f030
movsd %xmm0, -0x100(%rbp)
cmpl $0x0, -0x8(%rbp)
je 0x121a3a
movsd -0x10(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x121a0b
jp 0x121a0b
jmp 0x121a3a
movsd -0x10(%rbp), %xmm0
movsd 0x4d618(%rip), %xmm1    # 0x16f030
mulsd %xmm1, %xmm0
movsd 0x4d66c(%rip), %xmm1    # 0x16f090
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x100(%rbp)
jmp 0x121a83
leaq 0x158af7(%rip), %rax    # 0x27a538
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x121a52
jp 0x121a52
jmp 0x121a81
movsd 0x4d5d6(%rip), %xmm0    # 0x16f030
leaq 0x158ad7(%rip), %rax    # 0x27a538
divsd (%rax), %xmm0
movsd 0x4d623(%rip), %xmm1    # 0x16f090
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x100(%rbp)
jmp 0x121a83
movsd -0x38(%rbp), %xmm0
leaq 0x160d31(%rip), %rax    # 0x2827c0
subsd (%rax), %xmm0
subsd -0x100(%rbp), %xmm0
movaps 0x4d7ee(%rip), %xmm1    # 0x16f290
pand %xmm1, %xmm0
movsd %xmm0, -0x108(%rbp)
leaq 0x155ffb(%rip), %rax    # 0x277ab0
cmpq $0x4000, (%rax)         # imm = 0x4000
jne 0x121ad0
movl 0x10(%rbp), %edi
callq 0x642b0
cmpl $0x0, %eax
je 0x121ad0
jmp 0x121e7a
leaq 0x155fd9(%rip), %rax    # 0x277ab0
cmpq $0x40000, (%rax)        # imm = 0x40000
jne 0x121afe
movsd 0x6c828(%rip), %xmm0    # 0x18e310
ucomisd -0x108(%rbp), %xmm0
jbe 0x121afe
movl $0x0, -0x3c(%rbp)
jmp 0x121e78
movl $0x80000000, %ecx       # imm = 0x80000000
leaq 0x155fa6(%rip), %rax    # 0x277ab0
cmpq %rcx, (%rax)
jne 0x121b2d
movsd 0x4d539(%rip), %xmm0    # 0x16f050
ucomisd -0x108(%rbp), %xmm0
jbe 0x121b2d
movl $0x0, -0x3c(%rbp)
jmp 0x121e76
leaq 0x155f7c(%rip), %rax    # 0x277ab0
cmpq $0x10000000, (%rax)     # imm = 0x10000000
jne 0x121b5b
movsd 0x6c7d3(%rip), %xmm0    # 0x18e318
ucomisd -0x108(%rbp), %xmm0
jbe 0x121b5b
movl $0x0, -0x3c(%rbp)
jmp 0x121e74
movabsq $0x1000000000, %rcx     # imm = 0x1000000000
leaq 0x155f44(%rip), %rax    # 0x277ab0
cmpq %rcx, (%rax)
jne 0x121b8f
movsd 0x6c79f(%rip), %xmm0    # 0x18e318
ucomisd -0x108(%rbp), %xmm0
jbe 0x121b8f
movl $0x0, -0x3c(%rbp)
jmp 0x121e72
movabsq $0x200000000, %rcx      # imm = 0x200000000
leaq 0x155f10(%rip), %rax    # 0x277ab0
cmpq %rcx, (%rax)
jne 0x121bc3
movsd 0x4d4a3(%rip), %xmm0    # 0x16f050
ucomisd -0x108(%rbp), %xmm0
jbe 0x121bc3
movl $0x0, -0x3c(%rbp)
jmp 0x121e70
leaq 0x155ee6(%rip), %rax    # 0x277ab0
cmpq $0x8000000, (%rax)      # imm = 0x8000000
jne 0x121bf1
movsd 0x6c73d(%rip), %xmm0    # 0x18e318
ucomisd -0x108(%rbp), %xmm0
jbe 0x121bf1
movl $0x0, -0x3c(%rbp)
jmp 0x121e6e
leaq 0x155eb8(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x121c30
leaq 0x1585af(%rip), %rax    # 0x27a1b4
cmpl $0x53, (%rax)
jne 0x121c30
leaq 0x160bbb(%rip), %rax    # 0x2827cc
cmpl $0x0, (%rax)
je 0x121c30
leaq 0x160baf(%rip), %rax    # 0x2827cc
movl (%rax), %ecx
addl $-0x1, %ecx
leaq 0x160ba3(%rip), %rax    # 0x2827cc
movl %ecx, (%rax)
jmp 0x121e6c
leaq 0x155e79(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x121c79
leaq 0x158570(%rip), %rax    # 0x27a1b4
cmpl $0x53, (%rax)
jne 0x121c79
leaq 0x160b80(%rip), %rax    # 0x2827d0
cmpl $0x0, (%rax)
je 0x121c79
movsd -0x108(%rbp), %xmm0
movsd 0x4d3cb(%rip), %xmm1    # 0x16f030
ucomisd %xmm1, %xmm0
jne 0x121c79
jp 0x121c79
movl $0x0, -0x3c(%rbp)
jmp 0x121e6a
leaq 0x155e30(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x121cb0
leaq 0x158527(%rip), %rax    # 0x27a1b4
cmpl $0x36, (%rax)
jne 0x121cb0
movsd 0x6c686(%rip), %xmm0    # 0x18e320
ucomisd -0x108(%rbp), %xmm0
jbe 0x121cb0
movl $0x0, -0x3c(%rbp)
jmp 0x121e68
leaq 0x155df9(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x121cf6
leaq 0x155e20(%rip), %rax    # 0x277ae4
movzbl (%rax), %eax
cmpl $0x1, %eax
jne 0x121cf6
leaq 0x158885(%rip), %rax    # 0x27a558
cmpl $0x3, (%rax)
jl 0x121cf6
movsd 0x6c648(%rip), %xmm0    # 0x18e328
ucomisd -0x108(%rbp), %xmm0
jbe 0x121cf6
movl $0x0, -0x3c(%rbp)
jmp 0x121e66
movabsq $0x100000000, %rcx      # imm = 0x100000000
leaq 0x155da9(%rip), %rax    # 0x277ab0
cmpq %rcx, (%rax)
jne 0x121d2a
movsd 0x6c61c(%rip), %xmm0    # 0x18e330
ucomisd -0x108(%rbp), %xmm0
jbe 0x121d2a
movl $0x0, -0x3c(%rbp)
jmp 0x121e64
leaq 0x155d7f(%rip), %rax    # 0x277ab0
cmpq $0x10000, (%rax)        # imm = 0x10000
jne 0x121d3f
jmp 0x121e62
leaq 0x15846a(%rip), %rax    # 0x27a1b0
cmpl $0x0, (%rax)
je 0x121d5c
leaq 0x24a852(%rip), %rax    # 0x36c5a4
cmpl $0x0, (%rax)
jne 0x121d5c
jmp 0x121e60
leaq 0x160a65(%rip), %rax    # 0x2827c8
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x121d77
movl $0x0, -0x3c(%rbp)
jmp 0x121e5e
movsd -0x38(%rbp), %xmm0
leaq 0x160a3d(%rip), %rax    # 0x2827c0
subsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x121dc1
jp 0x121dc1
movl $0x1, -0x3c(%rbp)
leaq 0x155d10(%rip), %rax    # 0x277ab0
cmpq $0x1000, (%rax)         # imm = 0x1000
jne 0x121dbc
leaq 0x158418(%rip), %rax    # 0x27a1c8
cmpl $0x4f, (%rax)
jne 0x121dbc
movl $0x0, -0x3c(%rbp)
jmp 0x121e5c
leaq 0x155ce8(%rip), %rcx    # 0x277ab0
movabsq $0x101b880400, %rax     # imm = 0x101B880400
andq (%rcx), %rax
cmpq $0x0, %rax
je 0x121df6
movsd 0x6c54d(%rip), %xmm0    # 0x18e330
ucomisd -0x108(%rbp), %xmm0
jbe 0x121df6
movl $0x0, -0x3c(%rbp)
jmp 0x121e5a
leaq 0x15873b(%rip), %rax    # 0x27a538
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x121e0e
jp 0x121e0e
jmp 0x121e33
cmpl $0x0, -0x8(%rbp)
jne 0x121e33
movsd -0x108(%rbp), %xmm0
movsd 0x4d244(%rip), %xmm1    # 0x16f068
ucomisd %xmm1, %xmm0
jbe 0x121e33
movl $0x2, -0x3c(%rbp)
jmp 0x121e58
cmpl $0x0, -0x8(%rbp)
je 0x121e56
movsd -0x108(%rbp), %xmm0
movsd 0x4d21f(%rip), %xmm1    # 0x16f068
ucomisd %xmm1, %xmm0
jbe 0x121e56
movl $0x3, -0x3c(%rbp)
jmp 0x121e58
jmp 0x121e5a
jmp 0x121e5c
jmp 0x121e5e
jmp 0x121e60
jmp 0x121e62
jmp 0x121e64
jmp 0x121e66
jmp 0x121e68
jmp 0x121e6a
jmp 0x121e6c
jmp 0x121e6e
jmp 0x121e70
jmp 0x121e72
jmp 0x121e74
jmp 0x121e76
jmp 0x121e78
jmp 0x121e7a
leaq 0x16094f(%rip), %rax    # 0x2827d0
movl $0x0, (%rax)
cmpl $0x0, -0x3c(%rbp)
je 0x1220f7
leaq 0x158670(%rip), %rax    # 0x27a508
movq (%rax), %rsi
leaq -0x1b8(%rbp), %rdi
callq 0x133f0
leaq -0xf8(%rbp), %rdi
leaq -0x1b8(%rbp), %rsi
movl $0xb0, %edx
callq 0x92c0
movzwl -0xf8(%rbp), %eax
orl $0x400, %eax            # imm = 0x400
movw %ax, -0xf8(%rbp)
leaq 0x15862f(%rip), %rax    # 0x27a508
movq (%rax), %rax
movq %rax, -0x278(%rbp)
leaq -0x268(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
movl $0xb0, %edx
callq 0x92c0
movq %rsp, %rdi
movl $0x16, %ecx
leaq -0x268(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq -0x278(%rbp), %rdi
callq 0x13680
leaq 0x17b6bb(%rip), %rax    # 0x29d5db
cmpb $0x0, (%rax)
je 0x122039
cmpl $0x0, -0x8(%rbp)
jne 0x122039
cmpl $0x1, -0x3c(%rbp)
jne 0x121f6b
movsd -0x38(%rbp), %xmm0
leaq 0x16087b(%rip), %rax    # 0x2827c0
movsd (%rax), %xmm1
movsd -0x108(%rbp), %xmm2
leaq 0x17abe8(%rip), %rdi    # 0x29cb40
leaq 0x7356c(%rip), %rsi     # 0x1954cb
movb $0x3, %al
callq 0x9060
jmp 0x122003
cmpl $0x2, -0x3c(%rbp)
jne 0x121fba
movsd -0x38(%rbp), %xmm0
leaq 0x160843(%rip), %rax    # 0x2827c0
movsd (%rax), %xmm1
movsd -0x38(%rbp), %xmm2
leaq 0x160833(%rip), %rax    # 0x2827c0
subsd (%rax), %xmm2
movl -0x20(%rbp), %edx
movl -0x24(%rbp), %ecx
movl 0x10(%rbp), %r8d
movsd -0x108(%rbp), %xmm3
leaq 0x17ab96(%rip), %rdi    # 0x29cb40
leaq 0x73552(%rip), %rsi     # 0x195503
movb $0x4, %al
callq 0x9060
jmp 0x122001
cmpl $0x3, -0x3c(%rbp)
jne 0x121fdf
movsd -0x108(%rbp), %xmm0
leaq 0x17ab71(%rip), %rdi    # 0x29cb40
leaq 0x73580(%rip), %rsi     # 0x195556
movb $0x1, %al
callq 0x9060
jmp 0x121fff
movl -0x3c(%rbp), %edx
movsd -0x108(%rbp), %xmm0
leaq 0x17ab4f(%rip), %rdi    # 0x29cb40
leaq 0x7358c(%rip), %rsi     # 0x195584
movb $0x1, %al
callq 0x9060
jmp 0x122001
jmp 0x122003
leaq 0x17b566(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0x12202f
leaq 0x17b559(%rip), %rax    # 0x29d570
movq (%rax), %rdi
leaq 0x66dde(%rip), %rsi     # 0x188dff
leaq 0x17ab18(%rip), %rdx    # 0x29cb40
movb $0x0, %al
callq 0x9550
movl $0x1, %edi
callq 0x10cbe0
leaq 0x17b5b4(%rip), %rax    # 0x29d5f4
cmpb $0x0, (%rax)
je 0x1220f5
cmpl $0x0, -0x8(%rbp)
je 0x1220f5
leaq 0x17b581(%rip), %rax    # 0x29d5db
cmpb $0x0, (%rax)
je 0x1220f5
leaq 0x15594e(%rip), %rax    # 0x2779b8
cmpl $0x0, (%rax)
je 0x122089
leaq 0x27c776(%rip), %rax    # 0x39e7ec
movl (%rax), %eax
movl %eax, -0x40(%rbp)
leaq 0x27c76e(%rip), %rax    # 0x39e7f0
movl (%rax), %eax
movl %eax, -0x44(%rbp)
jmp 0x1220a1
leaq 0x1559e0(%rip), %rax    # 0x277a70
movl (%rax), %eax
movl %eax, -0x40(%rbp)
leaq 0x1559d0(%rip), %rax    # 0x277a6c
movl (%rax), %eax
movl %eax, -0x44(%rbp)
movl -0x3c(%rbp), %edx
movsd -0x10(%rbp), %xmm0
movsd -0x100(%rbp), %xmm1
leaq 0x160708(%rip), %rax    # 0x2827c0
movsd (%rax), %xmm2
movsd -0x38(%rbp), %xmm3
leaq 0x279338(%rip), %rdi    # 0x39b400
leaq 0x734e7(%rip), %rsi     # 0x1955b6
movb $0x4, %al
callq 0x9060
movl -0x40(%rbp), %edi
addl $0x4, %edi
movl -0x44(%rbp), %esi
movl $0xc, %edx
leaq 0x279315(%rip), %rcx    # 0x39b400
callq 0x10ee0
callq 0xb0d0
jmp 0x1220f7
movsd -0x38(%rbp), %xmm0
leaq 0x1606bd(%rip), %rax    # 0x2827c0
movsd %xmm0, (%rax)
cmpl $0x0, -0x3c(%rbp)
je 0x122119
leaq 0x1606b4(%rip), %rax    # 0x2827c8
movb $0x0, (%rax)
jmp 0x12212b
leaq 0x17bf9c(%rip), %rax    # 0x29e0bc
movb (%rax), %cl
leaq 0x16069f(%rip), %rax    # 0x2827c8
movb %cl, (%rax)
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x330, %rsp            # imm = 0x330
popq %rbp
retq
nopl (%rax)