// File: jkingan[P]ladyheather/heathgps.cpp
// Function: parse_scpi_time()
void parse_scpi_time()
{
u32 val;
static u32 last_tval = 0;
double jd;

   log_packet_id("scpi time");

pps_enabled = pps_mode = 1; // zzzzz
   have_pps_enable = 8;
   have_pps_mode = 8;
   sent_uccm_status = 0;

   fake_msec = 0.0;

   msg_col = 0;
   get_fixed_field(3);  // get " T#"
if(debug_file) fprintf(debug_file, "scpi time:%s\n", msg_field);

   if(!strcmp(msg_field, " T1")) {  // hex format time
      get_fixed_field(2);
      if(strcmp(msg_field, "#H")) return;
      get_fixed_field(8);
      val = atohex(msg_field);

      if(scpi_type == NORTEL_TYPE) {
         if(val == last_tval) ++val;
         last_tval = val;
      }

if(debug_file) fprintf(debug_file, "time val:%08X(%u)", val,val);

      jd = (double) (u32) val;
      jd /= (24.0*60.0*60.0);
      jd += GPS_EPOCH;
      
      set_gregorian_time(jd); 

      if((scpi_type == NORTEL_TYPE) && (time_flags & TFLAGS_UTC)) {
         gps_to_utc();
      }

      goto time_info;
   }
   else if(!strcmp(msg_field, " T2")) {
      get_fixed_field(4);
      pri_year = year = atoi(msg_field);
      get_fixed_field(2);
      pri_month = month = atoi(msg_field);
      get_fixed_field(2);
      pri_day = day = atoi(msg_field);

      get_fixed_field(2);
      pri_hours = hours = atoi(msg_field);
      get_fixed_field(2);
      pri_minutes = minutes = atoi(msg_field);
      get_fixed_field(2);
      pri_seconds = seconds = atoi(msg_field);
      pri_frac = raw_frac = 0.0;

      time_info:
      if(get_fixed_field(1)) {  // TFOM
         tfom = atoi(msg_field);
         have_tfom = 2;
      }
      if(get_fixed_field(1)) {  // FFOM
         ffom = atoi(msg_field);
         have_ffom = 2;
      }

      get_fixed_field(1);  // leap pending
      if(msg_field[0] == '+') {
         minor_alarms |= (MINOR_LEAP_PEND);
         have_leap_info = 5;
      }
      else if(msg_field[0] == '-') {
         minor_alarms |= (MINOR_LEAP_PEND);
         have_leap_info = 6;
      }
      else if(msg_field[0] == '0') {
         minor_alarms &= (~MINOR_LEAP_PEND);
         have_leap_info = 7;
      }

      get_fixed_field(1);  // request for service

      get_fixed_field(1);  // time validity
      if(msg_field[0] == '1') {       // time invalid
         time_flags |= TFLAGS_INVALID;
      }
      else if(msg_field[0] == '0') {  // time valid
         time_flags &= (~TFLAGS_INVALID);
      }

      get_fixed_field(2);  // checksum
if(debug_file) fprintf(debug_file, "time code: %04d/%02d/%02d %02d:%02d:%02d\n", pri_year,pri_month,pri_day, pri_hours,pri_minutes,pri_seconds);

      fake_time_stamp = 0;

      if(seconds != last_misc_second) {
         update_gps_screen(1006);
      }

      if(sent_uccm_status) ;
      else if(scpi_type == NORTEL_TYPE) ;
      else if(pri_seconds == SCPI_STATUS_SECOND) {
         if(rcvr_type == UCCM_RCVR) queue_uccm_cmd("SYST:STAT?", UCCM_STATUS_MSG);
         else                       queue_scpi_cmd(":SYST:STAT?", SCPI_STATUS_MSG);
         start_fake_seconds(4);
      }
   }
   else {  // message requests/responses out of sync?
      BEEP(510);  // gggg
      if(debug_file) fprintf(debug_file, "Message sync error (%s): %s\n", msg_field, nmea_msg);
      Sleep(500);
      need_msg_init = 123;
      return;
drain_port(RCVR_PORT);
tsip_sync = 0;
tsip_wptr = 0;
tsip_rptr = 0;
init_messages(123, 0);   // setup the receiver
redraw_screen();
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
leaq 0xb230e(%rip), %rdi     # 0x18819d
callq 0x7add0
leaq 0x297067(%rip), %rax    # 0x36cf02
movb $0x1, (%rax)
leaq 0x29705b(%rip), %rax    # 0x36cf00
movb $0x1, (%rax)
leaq 0x29660d(%rip), %rax    # 0x36c4bc
movl $0x8, (%rax)
leaq 0x296610(%rip), %rax    # 0x36c4cc
movl $0x8, (%rax)
movl $0x0, 0x2f5ecc(%rip)    # 0x3cbd98
leaq 0x296a05(%rip), %rax    # 0x36c8d8
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
leaq 0x2c4f43(%rip), %rax    # 0x39ae24
movl $0x0, (%rax)
movl $0x3, %edi
callq 0xb4d60
leaq 0x1c7678(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0xd5f1d
leaq 0x1c766b(%rip), %rax    # 0x29d570
movq (%rax), %rdi
leaq 0xb2298(%rip), %rsi     # 0x1881a7
leaq 0x2c4d0a(%rip), %rdx    # 0x39ac20
movb $0x0, %al
callq 0x9550
leaq 0x2c4cfc(%rip), %rdi    # 0x39ac20
leaq 0xb228a(%rip), %rsi     # 0x1881b5
callq 0x9510
cmpl $0x0, %eax
jne 0xd6033
movl $0x2, %edi
callq 0xb4d60
leaq 0x2c4cd6(%rip), %rdi    # 0x39ac20
leaq 0xb2268(%rip), %rsi     # 0x1881b9
callq 0x9510
cmpl $0x0, %eax
je 0xd5f60
jmp 0xd6431
movl $0x8, %edi
callq 0xb4d60
leaq 0x2c4caf(%rip), %rdi    # 0x39ac20
callq 0x98d0
movl %eax, -0x4(%rbp)
leaq 0x1a4240(%rip), %rax    # 0x27a1c0
cmpl $0x4e, (%rax)
jne 0xd5fa2
movl -0x4(%rbp), %eax
cmpl 0x2fb132(%rip), %eax    # 0x3d10c0
jne 0xd5f99
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
movl %eax, 0x2fb11e(%rip)    # 0x3d10c0
leaq 0x1c75c7(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0xd5fcd
leaq 0x1c75ba(%rip), %rax    # 0x29d570
movq (%rax), %rdi
movl -0x4(%rbp), %edx
movl -0x4(%rbp), %ecx
leaq 0xb21f6(%rip), %rsi     # 0x1881bc
movb $0x0, %al
callq 0x9550
movl -0x4(%rbp), %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x10(%rbp)
movsd -0x10(%rbp), %xmm0
movsd 0x99021(%rip), %xmm1    # 0x16f008
divsd %xmm1, %xmm0
movsd %xmm0, -0x10(%rbp)
movsd 0x9b620(%rip), %xmm0    # 0x171618
addsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x10(%rbp)
movsd -0x10(%rbp), %xmm0
callq 0x7fb00
leaq 0x1a41ad(%rip), %rax    # 0x27a1c0
cmpl $0x4e, (%rax)
jne 0xd602e
leaq 0x296665(%rip), %rax    # 0x36c684
movl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xd602e
callq 0x7fcb0
jmp 0xd6167
leaq 0x2c4be6(%rip), %rdi    # 0x39ac20
leaq 0xb218d(%rip), %rsi     # 0x1881ce
callq 0x9510
cmpl $0x0, %eax
jne 0xd63d9
movl $0x4, %edi
callq 0xb4d60
leaq 0x2c4bc0(%rip), %rdi    # 0x39ac20
callq 0x95c0
movl %eax, %ecx
leaq 0x29664e(%rip), %rax    # 0x36c6bc
movl %ecx, (%rax)
leaq 0x29667d(%rip), %rax    # 0x36c6f4
movl %ecx, (%rax)
movl $0x2, %edi
callq 0xb4d60
leaq 0x2c4b96(%rip), %rdi    # 0x39ac20
callq 0x95c0
movl %eax, %ecx
leaq 0x296620(%rip), %rax    # 0x36c6b8
movl %ecx, (%rax)
leaq 0x29664f(%rip), %rax    # 0x36c6f0
movl %ecx, (%rax)
movl $0x2, %edi
callq 0xb4d60
leaq 0x2c4b6c(%rip), %rdi    # 0x39ac20
callq 0x95c0
movl %eax, %ecx
leaq 0x2965f2(%rip), %rax    # 0x36c6b4
movl %ecx, (%rax)
leaq 0x296621(%rip), %rax    # 0x36c6ec
movl %ecx, (%rax)
movl $0x2, %edi
callq 0xb4d60
leaq 0x2c4b42(%rip), %rdi    # 0x39ac20
callq 0x95c0
movl %eax, %ecx
leaq 0x2965c4(%rip), %rax    # 0x36c6b0
movl %ecx, (%rax)
leaq 0x2965f3(%rip), %rax    # 0x36c6e8
movl %ecx, (%rax)
movl $0x2, %edi
callq 0xb4d60
leaq 0x2c4b18(%rip), %rdi    # 0x39ac20
callq 0x95c0
movl %eax, %ecx
leaq 0x296596(%rip), %rax    # 0x36c6ac
movl %ecx, (%rax)
leaq 0x2965c5(%rip), %rax    # 0x36c6e4
movl %ecx, (%rax)
movl $0x2, %edi
callq 0xb4d60
leaq 0x2c4aee(%rip), %rdi    # 0x39ac20
callq 0x95c0
movl %eax, %ecx
leaq 0x296568(%rip), %rax    # 0x36c6a8
movl %ecx, (%rax)
leaq 0x296597(%rip), %rax    # 0x36c6e0
movl %ecx, (%rax)
leaq 0x29656e(%rip), %rax    # 0x36c6c0
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
leaq 0x296598(%rip), %rax    # 0x36c6f8
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movl $0x1, %edi
callq 0xb4d60
cmpl $0x0, %eax
je 0xd619a
leaq 0x2c4aa3(%rip), %rdi    # 0x39ac20
callq 0x95c0
movl %eax, %ecx
leaq 0x295ca5(%rip), %rax    # 0x36be30
movl %ecx, (%rax)
leaq 0x295ca0(%rip), %rax    # 0x36be34
movl $0x2, (%rax)
movl $0x1, %edi
callq 0xb4d60
cmpl $0x0, %eax
je 0xd61cd
leaq 0x2c4a70(%rip), %rdi    # 0x39ac20
callq 0x95c0
movl %eax, %ecx
leaq 0x295c7a(%rip), %rax    # 0x36be38
movl %ecx, (%rax)
leaq 0x295c75(%rip), %rax    # 0x36be3c
movl $0x2, (%rax)
movl $0x1, %edi
callq 0xb4d60
leaq 0x2c4a42(%rip), %rax    # 0x39ac20
movsbl (%rax), %eax
cmpl $0x2b, %eax
jne 0xd620d
leaq 0x2961cb(%rip), %rax    # 0x36c3b8
movl (%rax), %ecx
orl $0x80, %ecx
leaq 0x2961bc(%rip), %rax    # 0x36c3b8
movl %ecx, (%rax)
leaq 0x296273(%rip), %rax    # 0x36c478
movl $0x5, (%rax)
jmp 0xd627b
leaq 0x2c4a0c(%rip), %rax    # 0x39ac20
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0xd6243
leaq 0x296195(%rip), %rax    # 0x36c3b8
movl (%rax), %ecx
orl $0x80, %ecx
leaq 0x296186(%rip), %rax    # 0x36c3b8
movl %ecx, (%rax)
leaq 0x29623d(%rip), %rax    # 0x36c478
movl $0x6, (%rax)
jmp 0xd6279
leaq 0x2c49d6(%rip), %rax    # 0x39ac20
movsbl (%rax), %eax
cmpl $0x30, %eax
jne 0xd6277
leaq 0x29615f(%rip), %rax    # 0x36c3b8
movl (%rax), %ecx
andl $0xffffff7f, %ecx       # imm = 0xFFFFFF7F
leaq 0x296150(%rip), %rax    # 0x36c3b8
movl %ecx, (%rax)
leaq 0x296207(%rip), %rax    # 0x36c478
movl $0x7, (%rax)
jmp 0xd6279
jmp 0xd627b
movl $0x1, %edi
callq 0xb4d60
movl $0x1, %edi
callq 0xb4d60
leaq 0x2c498a(%rip), %rax    # 0x39ac20
movsbl (%rax), %eax
cmpl $0x31, %eax
jne 0xd62b5
leaq 0x2963df(%rip), %rax    # 0x36c684
movl (%rax), %ecx
orl $0x4, %ecx
leaq 0x2963d3(%rip), %rax    # 0x36c684
movl %ecx, (%rax)
jmp 0xd62db
leaq 0x2c4964(%rip), %rax    # 0x39ac20
movsbl (%rax), %eax
cmpl $0x30, %eax
jne 0xd62d9
leaq 0x2963b9(%rip), %rax    # 0x36c684
movl (%rax), %ecx
andl $-0x5, %ecx
leaq 0x2963ad(%rip), %rax    # 0x36c684
movl %ecx, (%rax)
jmp 0xd62db
movl $0x2, %edi
callq 0xb4d60
leaq 0x1c7284(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0xd634b
leaq 0x1c7277(%rip), %rax    # 0x29d570
movq (%rax), %rdi
leaq 0x2963f1(%rip), %rax    # 0x36c6f4
movl (%rax), %edx
leaq 0x2963e4(%rip), %rax    # 0x36c6f0
movl (%rax), %ecx
leaq 0x2963d7(%rip), %rax    # 0x36c6ec
movl (%rax), %r8d
leaq 0x2963c9(%rip), %rax    # 0x36c6e8
movl (%rax), %r9d
leaq 0x2963bb(%rip), %rax    # 0x36c6e4
movl (%rax), %r10d
leaq 0x2963ad(%rip), %rax    # 0x36c6e0
movl (%rax), %eax
leaq 0xb1e96(%rip), %rsi     # 0x1881d2
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0x9550
leaq 0x29657e(%rip), %rax    # 0x36c8d0
movl $0x0, (%rax)
leaq 0x296349(%rip), %rax    # 0x36c6a8
movl (%rax), %eax
cmpl 0xf2ff9(%rip), %eax     # 0x1c9360
je 0xd6373
movl $0x3ee, %edi            # imm = 0x3EE
callq 0x9d790
cmpl $0x0, 0x2f5a1e(%rip)    # 0x3cbd98
je 0xd637e
jmp 0xd63d7
leaq 0x1a3e3b(%rip), %rax    # 0x27a1c0
cmpl $0x4e, (%rax)
jne 0xd638c
jmp 0xd63d5
leaq 0x29634d(%rip), %rax    # 0x36c6e0
cmpl $0x20, (%rax)
jne 0xd63d3
leaq 0x1a1711(%rip), %rax    # 0x277ab0
cmpq $0x8, (%rax)
jne 0xd63b8
leaq 0xb10cf(%rip), %rdi     # 0x18747b
movl $0x65, %esi
callq 0x82fd0
jmp 0xd63c9
leaq 0xb10bb(%rip), %rdi     # 0x18747a
movl $0x11, %esi
callq 0x82fd0
movl $0x4, %edi
callq 0xc5ec0
jmp 0xd63d5
jmp 0xd63d7
jmp 0xd642f
movl $0x1fe, %edi            # imm = 0x1FE
callq 0x9ec0
leaq 0x1c7186(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0xd6416
leaq 0x1c7179(%rip), %rax    # 0x29d570
movq (%rax), %rdi
leaq 0xb1dfb(%rip), %rsi     # 0x1881fc
leaq 0x2c4818(%rip), %rdx    # 0x39ac20
leaq 0x2c4601(%rip), %rcx    # 0x39aa10
movb $0x0, %al
callq 0x9550
movl $0x1f4, %edi            # imm = 0x1F4
callq 0xb8b0
leaq 0x1a3de9(%rip), %rax    # 0x27a210
movl $0x7b, (%rax)
jmp 0xd6431
jmp 0xd6431
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)