// File: jkingan[P]ladyheather/heathgps.cpp
// Function: parse_scpi_leaptime()
void parse_scpi_leaptime()
{
char *s;
u32 val;
int yy,mm,dd;
double leap_day;

   // calculates the date of the next leapsecond event
   log_packet_id("scpi leaptime");

   val = 0;

   msg_col = 0;
   if(get_msg_field()) { 
      strupr(msg_field);
      s = strstr(msg_field, "#H");
      if(scpi_type == NORTEL_TYPE) {
         s = "";
         val = atohex(&msg_field[0]);
         goto hex_time;
      }
      else if(s) {  // hex format
         if(s[2] == 0) return;
         val = atohex(s+2);

         hex_time:
         leap_day = (double) (u32) val;
         leap_day /= (24.0*60.0*60.0);
         leap_day += GPS_EPOCH;
         leap_day -= jtime(0,0,utc_offset, 0.0);  // convert GPS to UTC
         leap_day = ((double) (int) leap_day) + 0.50;  // removes time fraction
         leap_day -= jtime(0,0,0, 1.0);  // gets time of leap to 23:59:59
         have_scpi_hex_leap = 1;
//gregorian(0, leap_day);
//sprintf(debug_text2, "hexday:%f utcofs:%d  %04d/%02d/%02d %02d:%02d:%02d", leap_day, utc_offset, g_year,g_month,g_day, g_hours,g_minutes,g_seconds);
      }
      else if(0 && have_scpi_hex_leap) {  // we have leap date from the hex format message
         return;
      }
      else { // yyyy mm dd format  // this message can be wrong on devcices that send both formats
          yy = atoi(msg_field);   // ... might say 30 Sep if leap pending flag
          if(yy < 2016) return;    // ... was broadcast in July
          if(yy > 2100) return;

          if(get_msg_field() == 0) return;
          mm = atoi(msg_field);
          if(mm < 1) return;
          if(mm > 12) return;

          if(get_msg_field() == 0) return;
          dd = atoi(msg_field);
          if(dd < 1) return;
          if(dd > 31) return;

          leap_day = jdate(yy, mm, dd) + jtime(23,59,59,0.0);
          if(dd == 1) leap_day -= 1.0;
          sprintf(out, "%04d/%02d/%02d", yy,mm,dd);
//sprintf(debug_text3, "lday2:%f  %s", leap_day, out);
          s = &out[0];
      }

      leap_day += (double) (rolled * 1024*7);
      jd_leap = leap_day;
      calc_jd_leap(4);
///have_leap_days = 30;
///gregorian(0, leap_day);
//sprintf(plot_title, "rolled:%d  lday:%04d/%02d/%02d  %02d:%02d:%02d  today:%04d/%02d/%02d", rolled, g_year,g_month,g_day, g_hours,g_minutes,g_seconds, year,month,day);
///      today = jdate(year, month, day);
///      leap_days = (int) (leap_day - today);
///      have_leap_days = 3;
///sprintf(debug_text, "leap_day:%f today:%f leap_days:%d  rolled:%d", leap_day,today,leap_days, rolled);

if(debug_file) fprintf(debug_file, "### leaptime:%08X(%u)  leap_day:%f  leap_days:%d  s:%s", val, val, jd_leap, leap_days, s);
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
leaq 0xb1882(%rip), %rdi     # 0x188291
callq 0x7add0
movl $0x0, -0xc(%rbp)
leaq 0x2c4402(%rip), %rax    # 0x39ae24
movl $0x0, (%rax)
callq 0xb0bd0
cmpl $0x0, %eax
je 0xd6ce9
leaq 0x2c41e3(%rip), %rdi    # 0x39ac20
callq 0x9890
leaq 0x2c41d7(%rip), %rdi    # 0x39ac20
leaq 0xb1769(%rip), %rsi     # 0x1881b9
callq 0x9090
movq %rax, -0x8(%rbp)
leaq 0x1a3760(%rip), %rax    # 0x27a1c0
cmpl $0x4e, (%rax)
jne 0xd6a81
leaq 0xbdb26(%rip), %rax     # 0x194592
movq %rax, -0x8(%rbp)
leaq 0x2c41a9(%rip), %rdi    # 0x39ac20
callq 0x98d0
movl %eax, -0xc(%rbp)
jmp 0xd6aae
cmpq $0x0, -0x8(%rbp)
je 0xd6b59
movq -0x8(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x0, %eax
jne 0xd6a9e
jmp 0xd6ce9
movq -0x8(%rbp), %rdi
addq $0x2, %rdi
callq 0x98d0
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x20(%rbp)
movsd -0x20(%rbp), %xmm0
movsd 0x98540(%rip), %xmm1    # 0x16f008
divsd %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
movsd 0x9ab3f(%rip), %xmm0    # 0x171618
addsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
leaq 0x295e1e(%rip), %rax    # 0x36c908
movl (%rax), %edx
xorl %esi, %esi
xorps %xmm0, %xmm0
movl %esi, %edi
callq 0x122210
movaps %xmm0, %xmm1
movsd -0x20(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
cvttsd2si -0x20(%rbp), %eax
cvtsi2sd %eax, %xmm0
movsd 0x98576(%rip), %xmm1    # 0x16f090
addsd %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
xorl %edx, %edx
movsd 0x9853b(%rip), %xmm0    # 0x16f068
movl %edx, %edi
movl %edx, %esi
callq 0x122210
movaps %xmm0, %xmm1
movsd -0x20(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
leaq 0x2958b6(%rip), %rax    # 0x36c404
movl $0x1, (%rax)
jmp 0xd6c6a
leaq 0x2c40c0(%rip), %rdi    # 0x39ac20
callq 0x95c0
movl %eax, -0x10(%rbp)
cmpl $0x7e0, -0x10(%rbp)     # imm = 0x7E0
jge 0xd6b76
jmp 0xd6ce9
cmpl $0x834, -0x10(%rbp)     # imm = 0x834
jle 0xd6b84
jmp 0xd6ce9
callq 0xb0bd0
cmpl $0x0, %eax
jne 0xd6b93
jmp 0xd6ce9
leaq 0x2c4086(%rip), %rdi    # 0x39ac20
callq 0x95c0
movl %eax, -0x14(%rbp)
cmpl $0x1, -0x14(%rbp)
jge 0xd6bad
jmp 0xd6ce9
cmpl $0xc, -0x14(%rbp)
jle 0xd6bb8
jmp 0xd6ce9
callq 0xb0bd0
cmpl $0x0, %eax
jne 0xd6bc7
jmp 0xd6ce9
leaq 0x2c4052(%rip), %rdi    # 0x39ac20
callq 0x95c0
movl %eax, -0x18(%rbp)
cmpl $0x1, -0x18(%rbp)
jge 0xd6be1
jmp 0xd6ce9
cmpl $0x1f, -0x18(%rbp)
jle 0xd6bec
jmp 0xd6ce9
movl -0x10(%rbp), %edi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
callq 0x122140
movsd %xmm0, -0x28(%rbp)
movl $0x17, %edi
movl $0x3b, %edx
xorps %xmm0, %xmm0
movl %edx, %esi
callq 0x122210
movaps %xmm0, %xmm1
movsd -0x28(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
cmpl $0x1, -0x18(%rbp)
jne 0xd6c40
movsd -0x20(%rbp), %xmm0
movsd 0x98431(%rip), %xmm1    # 0x16f068
subsd %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
movl -0x10(%rbp), %edx
movl -0x14(%rbp), %ecx
movl -0x18(%rbp), %r8d
leaq 0x2c47af(%rip), %rdi    # 0x39b400
leaq 0xa531c(%rip), %rsi     # 0x17bf74
movb $0x0, %al
callq 0x9060
leaq 0x2c479a(%rip), %rax    # 0x39b400
movq %rax, -0x8(%rbp)
jmp 0xd6c6c
leaq 0x29597d(%rip), %rax    # 0x36c5f0
movl (%rax), %eax
shll $0xa, %eax
imull $0x7, %eax, %eax
cvtsi2sd %eax, %xmm0
addsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
movsd -0x20(%rbp), %xmm0
leaq 0x295aab(%rip), %rax    # 0x36c740
movsd %xmm0, (%rax)
movl $0x4, %edi
callq 0x80070
leaq 0x1c68c6(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0xd6ce7
leaq 0x1c68b9(%rip), %rax    # 0x29d570
movq (%rax), %rdi
movl -0xc(%rbp), %edx
movl -0xc(%rbp), %ecx
leaq 0x295a79(%rip), %rax    # 0x36c740
movsd (%rax), %xmm0
leaq 0x2956fa(%rip), %rax    # 0x36c3cc
movl (%rax), %r8d
movq -0x8(%rbp), %r9
leaq 0xb15bf(%rip), %rsi     # 0x18829f
movb $0x1, %al
callq 0x9550
jmp 0xd6ce9
addq $0x30, %rsp
popq %rbp
retq
nop