// File: /workspace/github_cpp_makefile_star2_O3/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 0x876db(%rip), %rdi     # 0x124eb1
callq 0x58dc2
leaq 0x270540(%rip), %rax    # 0x30dd22
movb $0x1, %cl
movb %cl, (%rax)
leaq 0x270533(%rip), %rax    # 0x30dd20
movb %cl, (%rax)
leaq 0x26fae6(%rip), %rax    # 0x30d2dc
movl $0x8, %ecx
movl %ecx, (%rax)
leaq 0x26fae8(%rip), %rax    # 0x30d2ec
movl %ecx, (%rax)
xorl %eax, %eax
movl %eax, 0x2cf3ba(%rip)    # 0x36cbc8
leaq 0x26fee3(%rip), %r14    # 0x30d6f8
movq $0x0, (%r14)
leaq 0x29e421(%rip), %rcx    # 0x33bc44
movl %eax, (%rcx)
movl $0x3, %edi
callq 0x83d8c
leaq 0x1a0b5a(%rip), %r15    # 0x23e390
movq (%r15), %rdi
testq %rdi, %rdi
je 0x9d853
leaq 0x87676(%rip), %rsi     # 0x124ebb
leaq 0x29e1f4(%rip), %rdx    # 0x33ba40
xorl %eax, %eax
callq 0x9560
leaq 0x29e1e6(%rip), %r12    # 0x33ba40
movl (%r12), %eax
cmpl $0x325420, %eax         # imm = 0x325420
je 0x9d94d
cmpl $0x315420, %eax         # imm = 0x315420
jne 0x9dadd
movl $0x2, %edi
callq 0x83d8c
movl $0x4823, %eax           # imm = 0x4823
xorl (%r12), %eax
movzbl 0x2(%r12), %ecx
orw %ax, %cx
jne 0x9dc95
movl $0x8, %edi
callq 0x83d8c
leaq 0x29e199(%rip), %rdi    # 0x33ba40
callq 0x98c6
movl %eax, %ebx
leaq 0x17d72b(%rip), %r13    # 0x21afe0
cmpl $0x4e, (%r13)
jne 0x9d8cf
xorl %eax, %eax
cmpl 0x2d4608(%rip), %ebx    # 0x371ecc
sete %al
addl %eax, %ebx
movl %ebx, 0x2d45fd(%rip)    # 0x371ecc
movq (%r15), %rdi
testq %rdi, %rdi
je 0x9d8e9
leaq 0x875ee(%rip), %rsi     # 0x124ecc
movl %ebx, %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x9560
movl %ebx, %eax
cvtsi2sd %rax, %xmm0
divsd 0x6b720(%rip), %xmm0    # 0x109018
addsd 0x6df98(%rip), %xmm0    # 0x10b898
callq 0x5c71d
cmpl $0x4e, (%r13)
jne 0x9da42
leaq 0x26fb8d(%rip), %rbx    # 0x30d4a4
testb $0x1, (%rbx)
je 0x9da42
leaq 0x26fe01(%rip), %rax    # 0x30d728
cvtsi2sdl (%rax), %xmm1
xorpd %xmm0, %xmm0
subsd %xmm1, %xmm0
callq 0x5c7ed
orb $0x1, (%rbx)
leaq 0x26fa8a(%rip), %rax    # 0x30d3cc
movl $0x1, (%rax)
jmp 0x9da42
movl $0x4, %edi
callq 0x83d8c
leaq 0x29e0e2(%rip), %rbx    # 0x33ba40
movq %rbx, %rdi
callq 0x95e0
leaq 0x26fb6f(%rip), %rcx    # 0x30d4dc
movl %eax, (%rcx)
leaq 0x26fb9e(%rip), %rcx    # 0x30d514
movl %eax, (%rcx)
movl $0x2, %edi
callq 0x83d8c
movq %rbx, %rdi
callq 0x95e0
leaq 0x26fb47(%rip), %rcx    # 0x30d4d8
movl %eax, (%rcx)
leaq 0x26fb76(%rip), %rcx    # 0x30d510
movl %eax, (%rcx)
movl $0x2, %edi
callq 0x83d8c
movq %rbx, %rdi
callq 0x95e0
leaq 0x26fb1f(%rip), %rcx    # 0x30d4d4
movl %eax, (%rcx)
leaq 0x26fb4e(%rip), %rcx    # 0x30d50c
movl %eax, (%rcx)
movl $0x2, %edi
callq 0x83d8c
movq %rbx, %rdi
callq 0x95e0
leaq 0x26faf7(%rip), %rcx    # 0x30d4d0
movl %eax, (%rcx)
leaq 0x26fb26(%rip), %rcx    # 0x30d508
movl %eax, (%rcx)
movl $0x2, %edi
callq 0x83d8c
movq %rbx, %rdi
callq 0x95e0
leaq 0x26facf(%rip), %rcx    # 0x30d4cc
movl %eax, (%rcx)
leaq 0x26fafe(%rip), %rcx    # 0x30d504
movl %eax, (%rcx)
movl $0x2, %edi
callq 0x83d8c
movq %rbx, %rdi
callq 0x95e0
leaq 0x26faa7(%rip), %rcx    # 0x30d4c8
movl %eax, (%rcx)
leaq 0x26fad6(%rip), %rcx    # 0x30d500
movl %eax, (%rcx)
leaq 0x26faad(%rip), %rax    # 0x30d4e0
xorl %ecx, %ecx
movq %rcx, (%rax)
leaq 0x26fad9(%rip), %rax    # 0x30d518
movq %rcx, (%rax)
movl $0x1, %edi
callq 0x83d8c
testl %eax, %eax
je 0x9da72
leaq 0x29dfe9(%rip), %rdi    # 0x33ba40
callq 0x95e0
leaq 0x26f1ed(%rip), %rcx    # 0x30cc50
movl %eax, (%rcx)
leaq 0x26f1e8(%rip), %rax    # 0x30cc54
movl $0x2, (%rax)
movl $0x1, %edi
callq 0x83d8c
testl %eax, %eax
je 0x9daa2
leaq 0x29dfb9(%rip), %rdi    # 0x33ba40
callq 0x95e0
leaq 0x26f1c5(%rip), %rcx    # 0x30cc58
movl %eax, (%rcx)
leaq 0x26f1c0(%rip), %rax    # 0x30cc5c
movl $0x2, (%rax)
movl $0x1, %edi
callq 0x83d8c
movzbl (%r12), %eax
cmpl $0x30, %eax
je 0x9db3c
cmpl $0x2d, %eax
je 0x9db27
cmpl $0x2b, %eax
jne 0x9db61
leaq 0x26f709(%rip), %rcx    # 0x30d1d8
movl $0x80, %eax
orl (%rcx), %eax
movl $0x5, %ecx
jmp 0x9db4f
movl $0x1fe, %edi            # imm = 0x1FE
callq 0x9d78
movq (%r15), %rdi
testq %rdi, %rdi
je 0x9db0b
leaq 0x87412(%rip), %rsi     # 0x124f08
leaq 0x29df43(%rip), %rdx    # 0x33ba40
leaq 0x29dd2c(%rip), %rcx    # 0x33b830
xorl %eax, %eax
callq 0x9560
movl $0x1f4, %edi            # imm = 0x1F4
callq 0xafe8
leaq 0x17d514(%rip), %rax    # 0x21b030
movl $0x7b, (%rax)
jmp 0x9dc95
leaq 0x26f6aa(%rip), %rcx    # 0x30d1d8
movl $0x80, %eax
orl (%rcx), %eax
movl $0x6, %ecx
jmp 0x9db4f
leaq 0x26f695(%rip), %rcx    # 0x30d1d8
movl $0xffffff7f, %eax       # imm = 0xFFFFFF7F
andl (%rcx), %eax
movl $0x7, %ecx
leaq 0x26f682(%rip), %rdx    # 0x30d1d8
movl %eax, (%rdx)
leaq 0x26f739(%rip), %rax    # 0x30d298
movl %ecx, (%rax)
movl $0x1, %edi
callq 0x83d8c
movl $0x1, %edi
callq 0x83d8c
movzbl (%r12), %eax
cmpl $0x30, %eax
je 0x9db92
cmpl $0x31, %eax
jne 0x9dba7
leaq 0x26f919(%rip), %rax    # 0x30d4a4
movl (%rax), %eax
orl $0x4, %eax
jmp 0x9db9e
leaq 0x26f90b(%rip), %rax    # 0x30d4a4
movl (%rax), %eax
andl $-0x5, %eax
leaq 0x26f8ff(%rip), %rcx    # 0x30d4a4
movl %eax, (%rcx)
movl $0x2, %edi
callq 0x83d8c
movq (%r15), %rdi
testq %rdi, %rdi
je 0x9dc09
leaq 0x26f954(%rip), %rax    # 0x30d514
movl (%rax), %edx
leaq 0x26f947(%rip), %rax    # 0x30d510
movl (%rax), %ecx
leaq 0x26f93a(%rip), %rax    # 0x30d50c
movl (%rax), %r8d
leaq 0x26f92c(%rip), %rax    # 0x30d508
movl (%rax), %r9d
leaq 0x26f91e(%rip), %rax    # 0x30d504
movl (%rax), %r10d
leaq 0x26f910(%rip), %rax    # 0x30d500
movl (%rax), %r11d
leaq 0x872e4(%rip), %rsi     # 0x124ede
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x9560
addq $0x10, %rsp
leaq 0x26fae0(%rip), %rax    # 0x30d6f0
movl $0x0, (%rax)
leaq 0x26f8ab(%rip), %rax    # 0x30d4c8
movl (%rax), %eax
cmpl 0xcc74b(%rip), %eax     # 0x16a370
je 0x9dc2c
callq 0x730e8
cmpl $0x0, 0x2cef95(%rip)    # 0x36cbc8
jne 0x9dc95
leaq 0x17d3a4(%rip), %rax    # 0x21afe0
cmpl $0x4e, (%rax)
je 0x9dc95
leaq 0x26f8b8(%rip), %rax    # 0x30d500
cmpl $0x20, (%rax)
jne 0x9dc95
leaq 0x17ac7c(%rip), %rax    # 0x2188d0
cmpq $0x8, (%rax)
jne 0x9dc68
leaq 0x8652d(%rip), %rdi     # 0x12418e
movl $0x65, %esi
jmp 0x9dc74
leaq 0x8651e(%rip), %rdi     # 0x12418d
movl $0x11, %esi
callq 0x5edda
callq 0xae92
addsd 0x6b3b2(%rip), %xmm0    # 0x109038
movsd %xmm0, (%r14)
movl $0x0, 0x2d41c3(%rip)    # 0x371e58
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq