// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0x877d5(%rip), %rdi     # 0x124dd1
callq 0x58e77
leaq 0x27071a(%rip), %rax    # 0x30dd22
movb $0x1, %cl
movb %cl, (%rax)
leaq 0x27070d(%rip), %rax    # 0x30dd20
movb %cl, (%rax)
leaq 0x26fcc0(%rip), %rax    # 0x30d2dc
movl $0x8, %ecx
movl %ecx, (%rax)
leaq 0x26fcc2(%rip), %rax    # 0x30d2ec
movl %ecx, (%rax)
xorl %eax, %eax
movl %eax, 0x2cf594(%rip)    # 0x36cbc8
leaq 0x2700bd(%rip), %r14    # 0x30d6f8
movq $0x0, (%r14)
leaq 0x29e5fb(%rip), %rcx    # 0x33bc44
movl %eax, (%rcx)
movl $0x3, %edi
callq 0x83e83
leaq 0x1a0d34(%rip), %r15    # 0x23e390
movq (%r15), %rdi
testq %rdi, %rdi
je 0x9d679
leaq 0x87770(%rip), %rsi     # 0x124ddb
leaq 0x29e3ce(%rip), %rdx    # 0x33ba40
xorl %eax, %eax
callq 0x9560
leaq 0x29e3c0(%rip), %r12    # 0x33ba40
movl (%r12), %eax
cmpl $0x325420, %eax         # imm = 0x325420
je 0x9d773
cmpl $0x315420, %eax         # imm = 0x315420
jne 0x9d903
movl $0x2, %edi
callq 0x83e83
movl $0x4823, %eax           # imm = 0x4823
xorl (%r12), %eax
movzbl 0x2(%r12), %ecx
orw %ax, %cx
jne 0x9dabb
movl $0x8, %edi
callq 0x83e83
leaq 0x29e373(%rip), %rdi    # 0x33ba40
callq 0x98c6
movl %eax, %ebx
leaq 0x17d905(%rip), %r13    # 0x21afe0
cmpl $0x4e, (%r13)
jne 0x9d6f5
xorl %eax, %eax
cmpl 0x2d47e2(%rip), %ebx    # 0x371ecc
sete %al
addl %eax, %ebx
movl %ebx, 0x2d47d7(%rip)    # 0x371ecc
movq (%r15), %rdi
testq %rdi, %rdi
je 0x9d70f
leaq 0x876e8(%rip), %rsi     # 0x124dec
movl %ebx, %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x9560
movl %ebx, %eax
cvtsi2sd %rax, %xmm0
divsd 0x6b8fa(%rip), %xmm0    # 0x109018
addsd 0x6e162(%rip), %xmm0    # 0x10b888
callq 0x5c837
cmpl $0x4e, (%r13)
jne 0x9d868
leaq 0x26fd67(%rip), %rbx    # 0x30d4a4
testb $0x1, (%rbx)
je 0x9d868
leaq 0x26ffdb(%rip), %rax    # 0x30d728
cvtsi2sdl (%rax), %xmm1
xorpd %xmm0, %xmm0
subsd %xmm1, %xmm0
callq 0x5c907
orb $0x1, (%rbx)
leaq 0x26fc64(%rip), %rax    # 0x30d3cc
movl $0x1, (%rax)
jmp 0x9d868
movl $0x4, %edi
callq 0x83e83
leaq 0x29e2bc(%rip), %rbx    # 0x33ba40
movq %rbx, %rdi
callq 0x95e0
leaq 0x26fd49(%rip), %rcx    # 0x30d4dc
movl %eax, (%rcx)
leaq 0x26fd78(%rip), %rcx    # 0x30d514
movl %eax, (%rcx)
movl $0x2, %edi
callq 0x83e83
movq %rbx, %rdi
callq 0x95e0
leaq 0x26fd21(%rip), %rcx    # 0x30d4d8
movl %eax, (%rcx)
leaq 0x26fd50(%rip), %rcx    # 0x30d510
movl %eax, (%rcx)
movl $0x2, %edi
callq 0x83e83
movq %rbx, %rdi
callq 0x95e0
leaq 0x26fcf9(%rip), %rcx    # 0x30d4d4
movl %eax, (%rcx)
leaq 0x26fd28(%rip), %rcx    # 0x30d50c
movl %eax, (%rcx)
movl $0x2, %edi
callq 0x83e83
movq %rbx, %rdi
callq 0x95e0
leaq 0x26fcd1(%rip), %rcx    # 0x30d4d0
movl %eax, (%rcx)
leaq 0x26fd00(%rip), %rcx    # 0x30d508
movl %eax, (%rcx)
movl $0x2, %edi
callq 0x83e83
movq %rbx, %rdi
callq 0x95e0
leaq 0x26fca9(%rip), %rcx    # 0x30d4cc
movl %eax, (%rcx)
leaq 0x26fcd8(%rip), %rcx    # 0x30d504
movl %eax, (%rcx)
movl $0x2, %edi
callq 0x83e83
movq %rbx, %rdi
callq 0x95e0
leaq 0x26fc81(%rip), %rcx    # 0x30d4c8
movl %eax, (%rcx)
leaq 0x26fcb0(%rip), %rcx    # 0x30d500
movl %eax, (%rcx)
leaq 0x26fc87(%rip), %rax    # 0x30d4e0
xorl %ecx, %ecx
movq %rcx, (%rax)
leaq 0x26fcb3(%rip), %rax    # 0x30d518
movq %rcx, (%rax)
movl $0x1, %edi
callq 0x83e83
testl %eax, %eax
je 0x9d898
leaq 0x29e1c3(%rip), %rdi    # 0x33ba40
callq 0x95e0
leaq 0x26f3c7(%rip), %rcx    # 0x30cc50
movl %eax, (%rcx)
leaq 0x26f3c2(%rip), %rax    # 0x30cc54
movl $0x2, (%rax)
movl $0x1, %edi
callq 0x83e83
testl %eax, %eax
je 0x9d8c8
leaq 0x29e193(%rip), %rdi    # 0x33ba40
callq 0x95e0
leaq 0x26f39f(%rip), %rcx    # 0x30cc58
movl %eax, (%rcx)
leaq 0x26f39a(%rip), %rax    # 0x30cc5c
movl $0x2, (%rax)
movl $0x1, %edi
callq 0x83e83
movzbl (%r12), %eax
cmpl $0x30, %eax
je 0x9d962
cmpl $0x2d, %eax
je 0x9d94d
cmpl $0x2b, %eax
jne 0x9d987
leaq 0x26f8e3(%rip), %rcx    # 0x30d1d8
movl $0x80, %eax
orl (%rcx), %eax
movl $0x5, %ecx
jmp 0x9d975
movl $0x1fe, %edi            # imm = 0x1FE
callq 0x9d80
movq (%r15), %rdi
testq %rdi, %rdi
je 0x9d931
leaq 0x8750c(%rip), %rsi     # 0x124e28
leaq 0x29e11d(%rip), %rdx    # 0x33ba40
leaq 0x29df06(%rip), %rcx    # 0x33b830
xorl %eax, %eax
callq 0x9560
movl $0x1f4, %edi            # imm = 0x1F4
callq 0xaff7
leaq 0x17d6ee(%rip), %rax    # 0x21b030
movl $0x7b, (%rax)
jmp 0x9dabb
leaq 0x26f884(%rip), %rcx    # 0x30d1d8
movl $0x80, %eax
orl (%rcx), %eax
movl $0x6, %ecx
jmp 0x9d975
leaq 0x26f86f(%rip), %rcx    # 0x30d1d8
movl $0xffffff7f, %eax       # imm = 0xFFFFFF7F
andl (%rcx), %eax
movl $0x7, %ecx
leaq 0x26f85c(%rip), %rdx    # 0x30d1d8
movl %eax, (%rdx)
leaq 0x26f913(%rip), %rax    # 0x30d298
movl %ecx, (%rax)
movl $0x1, %edi
callq 0x83e83
movl $0x1, %edi
callq 0x83e83
movzbl (%r12), %eax
cmpl $0x30, %eax
je 0x9d9b8
cmpl $0x31, %eax
jne 0x9d9cd
leaq 0x26faf3(%rip), %rax    # 0x30d4a4
movl (%rax), %eax
orl $0x4, %eax
jmp 0x9d9c4
leaq 0x26fae5(%rip), %rax    # 0x30d4a4
movl (%rax), %eax
andl $-0x5, %eax
leaq 0x26fad9(%rip), %rcx    # 0x30d4a4
movl %eax, (%rcx)
movl $0x2, %edi
callq 0x83e83
movq (%r15), %rdi
testq %rdi, %rdi
je 0x9da2f
leaq 0x26fb2e(%rip), %rax    # 0x30d514
movl (%rax), %edx
leaq 0x26fb21(%rip), %rax    # 0x30d510
movl (%rax), %ecx
leaq 0x26fb14(%rip), %rax    # 0x30d50c
movl (%rax), %r8d
leaq 0x26fb06(%rip), %rax    # 0x30d508
movl (%rax), %r9d
leaq 0x26faf8(%rip), %rax    # 0x30d504
movl (%rax), %r10d
leaq 0x26faea(%rip), %rax    # 0x30d500
movl (%rax), %r11d
leaq 0x873de(%rip), %rsi     # 0x124dfe
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x9560
addq $0x10, %rsp
leaq 0x26fcba(%rip), %rax    # 0x30d6f0
movl $0x0, (%rax)
leaq 0x26fa85(%rip), %rax    # 0x30d4c8
movl (%rax), %eax
cmpl 0xcc925(%rip), %eax     # 0x16a370
je 0x9da52
callq 0x7327e
cmpl $0x0, 0x2cf16f(%rip)    # 0x36cbc8
jne 0x9dabb
leaq 0x17d57e(%rip), %rax    # 0x21afe0
cmpl $0x4e, (%rax)
je 0x9dabb
leaq 0x26fa92(%rip), %rax    # 0x30d500
cmpl $0x20, (%rax)
jne 0x9dabb
leaq 0x17ae56(%rip), %rax    # 0x2188d0
cmpq $0x8, (%rax)
jne 0x9da8e
leaq 0x86627(%rip), %rdi     # 0x1240ae
movl $0x65, %esi
jmp 0x9da9a
leaq 0x86618(%rip), %rdi     # 0x1240ad
movl $0x11, %esi
callq 0x5ee52
callq 0xaea1
addsd 0x6b58c(%rip), %xmm0    # 0x109038
movsd %xmm0, (%r14)
movl $0x0, 0x2d439d(%rip)    # 0x371e58
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq