// File: /workspace/github_cpp_makefile_star2_O2/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 %r12
pushq %rbx
leaq 0x803ad(%rip), %rdi     # 0x10edf9
callq 0x520bf
leaq 0x2692ca(%rip), %rax    # 0x2f7d22
movb $0x1, %cl
movb %cl, (%rax)
leaq 0x2692bd(%rip), %rax    # 0x2f7d20
movb %cl, (%rax)
leaq 0x268870(%rip), %rax    # 0x2f72dc
pushq $0x8
popq %rcx
movl %ecx, (%rax)
leaq 0x268874(%rip), %rax    # 0x2f72ec
movl %ecx, (%rax)
andl $0x0, 0x2c8147(%rip)    # 0x356bc8
leaq 0x268c70(%rip), %rax    # 0x2f76f8
andq $0x0, (%rax)
leaq 0x2971b1(%rip), %rax    # 0x325c44
andl $0x0, (%rax)
pushq $0x3
popq %rdi
callq 0x78198
leaq 0x1998eb(%rip), %r15    # 0x228390
movq (%r15), %rdi
testq %rdi, %rdi
je 0x8eac2
leaq 0x8034f(%rip), %rsi     # 0x10ee03
leaq 0x296f85(%rip), %rdx    # 0x325a40
xorl %eax, %eax
callq 0x9560
leaq 0x296f77(%rip), %r12    # 0x325a40
movl (%r12), %eax
cmpl $0x325420, %eax         # imm = 0x325420
je 0x8eb99
cmpl $0x315420, %eax         # imm = 0x315420
jne 0x8ed14
pushq $0x2
popq %rdi
callq 0x78198
leaq 0x296f4e(%rip), %rdi    # 0x325a40
leaq 0x80318(%rip), %rsi     # 0x10ee11
pushq $0x3
popq %rdx
callq 0x9380
testl %eax, %eax
jne 0x8ee8d
pushq $0x8
popq %rdi
callq 0x78198
leaq 0x296f28(%rip), %rdi    # 0x325a40
callq 0x98b2
movl %eax, %ebx
leaq 0x1764ba(%rip), %r14    # 0x204fe0
cmpl $0x4e, (%r14)
jne 0x8eb3f
xorl %eax, %eax
cmpl 0x2cd398(%rip), %ebx    # 0x35becc
sete %al
addl %eax, %ebx
movl %ebx, 0x2cd38d(%rip)    # 0x35becc
movq (%r15), %rdi
testq %rdi, %rdi
je 0x8eb59
leaq 0x802c6(%rip), %rsi     # 0x10ee14
movl %ebx, %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x9560
movl %ebx, %eax
cvtsi2sd %rax, %xmm0
divsd 0x644b0(%rip), %xmm0    # 0xf3018
addsd 0x66da0(%rip), %xmm0    # 0xf5910
callq 0x55392
cmpl $0x4e, (%r14)
jne 0x8ec86
leaq 0x26891e(%rip), %rax    # 0x2f74a4
testb $0x1, (%rax)
je 0x8ec86
callq 0x55500
jmp 0x8ec86
pushq $0x4
popq %rdi
callq 0x78198
leaq 0x296e98(%rip), %rbx    # 0x325a40
movq %rbx, %rdi
callq 0x95e0
leaq 0x268925(%rip), %rcx    # 0x2f74dc
movl %eax, (%rcx)
leaq 0x268954(%rip), %rcx    # 0x2f7514
movl %eax, (%rcx)
pushq $0x2
popq %r14
movl %r14d, %edi
callq 0x78198
movq %rbx, %rdi
callq 0x95e0
leaq 0x2688fb(%rip), %rcx    # 0x2f74d8
movl %eax, (%rcx)
leaq 0x26892a(%rip), %rcx    # 0x2f7510
movl %eax, (%rcx)
movl %r14d, %edi
callq 0x78198
movq %rbx, %rdi
callq 0x95e0
leaq 0x2688d5(%rip), %rcx    # 0x2f74d4
movl %eax, (%rcx)
leaq 0x268904(%rip), %rcx    # 0x2f750c
movl %eax, (%rcx)
movl %r14d, %edi
callq 0x78198
movq %rbx, %rdi
callq 0x95e0
leaq 0x2688af(%rip), %rcx    # 0x2f74d0
movl %eax, (%rcx)
leaq 0x2688de(%rip), %rcx    # 0x2f7508
movl %eax, (%rcx)
movl %r14d, %edi
callq 0x78198
movq %rbx, %rdi
callq 0x95e0
leaq 0x268889(%rip), %rcx    # 0x2f74cc
movl %eax, (%rcx)
leaq 0x2688b8(%rip), %rcx    # 0x2f7504
movl %eax, (%rcx)
movl %r14d, %edi
callq 0x78198
movq %rbx, %rdi
callq 0x95e0
leaq 0x268863(%rip), %rcx    # 0x2f74c8
movl %eax, (%rcx)
leaq 0x268892(%rip), %rcx    # 0x2f7500
movl %eax, (%rcx)
leaq 0x268869(%rip), %rax    # 0x2f74e0
andq $0x0, (%rax)
leaq 0x268896(%rip), %rax    # 0x2f7518
andq $0x0, (%rax)
pushq $0x1
popq %rdi
callq 0x78198
testl %eax, %eax
je 0x8ecb4
leaq 0x296da7(%rip), %rdi    # 0x325a40
callq 0x95e0
leaq 0x267fab(%rip), %rcx    # 0x2f6c50
movl %eax, (%rcx)
leaq 0x267fa6(%rip), %rax    # 0x2f6c54
movl $0x2, (%rax)
pushq $0x1
popq %rdi
callq 0x78198
testl %eax, %eax
je 0x8ece2
leaq 0x296d79(%rip), %rdi    # 0x325a40
callq 0x95e0
leaq 0x267f85(%rip), %rcx    # 0x2f6c58
movl %eax, (%rcx)
leaq 0x267f80(%rip), %rax    # 0x2f6c5c
movl $0x2, (%rax)
pushq $0x1
popq %rdi
callq 0x78198
movzbl (%r12), %eax
cmpl $0x30, %eax
je 0x8ed70
cmpl $0x2d, %eax
je 0x8ed5e
cmpl $0x2b, %eax
jne 0x8ed93
leaq 0x2684cf(%rip), %rcx    # 0x2f71d8
movl $0x80, %eax
orl (%rcx), %eax
pushq $0x5
jmp 0x8ed80
movl $0x1fe, %edi            # imm = 0x1FE
callq 0x9d23
movq (%r15), %rdi
testq %rdi, %rdi
je 0x8ed42
leaq 0x80123(%rip), %rsi     # 0x10ee50
leaq 0x296d0c(%rip), %rdx    # 0x325a40
leaq 0x296af5(%rip), %rcx    # 0x325830
xorl %eax, %eax
callq 0x9560
movl $0x1f4, %edi            # imm = 0x1F4
callq 0xae83
leaq 0x1762dd(%rip), %rax    # 0x205030
movl $0x7b, (%rax)
jmp 0x8ee8d
leaq 0x268473(%rip), %rcx    # 0x2f71d8
movl $0x80, %eax
orl (%rcx), %eax
pushq $0x6
jmp 0x8ed80
leaq 0x268461(%rip), %rcx    # 0x2f71d8
movl $0xffffff7f, %eax       # imm = 0xFFFFFF7F
andl (%rcx), %eax
pushq $0x7
popq %rcx
leaq 0x268450(%rip), %rdx    # 0x2f71d8
movl %eax, (%rdx)
leaq 0x268507(%rip), %rax    # 0x2f7298
movl %ecx, (%rax)
pushq $0x1
popq %rbx
movl %ebx, %edi
callq 0x78198
movl %ebx, %edi
callq 0x78198
movzbl (%r12), %eax
cmpl $0x30, %eax
je 0x8edc1
cmpl $0x31, %eax
jne 0x8edd6
leaq 0x2686ea(%rip), %rax    # 0x2f74a4
movl (%rax), %eax
orl $0x4, %eax
jmp 0x8edcd
leaq 0x2686dc(%rip), %rax    # 0x2f74a4
movl (%rax), %eax
andl $-0x5, %eax
leaq 0x2686d0(%rip), %rcx    # 0x2f74a4
movl %eax, (%rcx)
pushq $0x2
popq %rdi
callq 0x78198
movq (%r15), %rdi
testq %rdi, %rdi
je 0x8ee34
leaq 0x268727(%rip), %rax    # 0x2f7514
movl (%rax), %edx
leaq 0x26871a(%rip), %rax    # 0x2f7510
movl (%rax), %ecx
leaq 0x26870d(%rip), %rax    # 0x2f750c
movl (%rax), %r8d
leaq 0x2686ff(%rip), %rax    # 0x2f7508
movl (%rax), %r9d
leaq 0x2686f1(%rip), %rax    # 0x2f7504
movl (%rax), %r10d
leaq 0x2686e3(%rip), %rax    # 0x2f7500
movl (%rax), %r11d
leaq 0x7ffff(%rip), %rsi     # 0x10ee26
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x9560
popq %rcx
popq %rdx
leaq 0x2688b5(%rip), %rax    # 0x2f76f0
andl $0x0, (%rax)
leaq 0x268683(%rip), %rax    # 0x2f74c8
movl (%rax), %eax
cmpl 0xc5523(%rip), %eax     # 0x154370
je 0x8ee54
callq 0x694f6
cmpl $0x0, 0x2c7d6d(%rip)    # 0x356bc8
jne 0x8ee8d
leaq 0x17617c(%rip), %rax    # 0x204fe0
cmpl $0x4e, (%rax)
je 0x8ee8d
leaq 0x268690(%rip), %rax    # 0x2f7500
cmpl $0x20, (%rax)
jne 0x8ee8d
leaq 0x173a54(%rip), %rax    # 0x2028d0
cmpq $0x8, (%rax)
jne 0x8ee96
leaq 0x7f24d(%rip), %rdi     # 0x10e0d6
pushq $0x65
jmp 0x8ee9f
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7f238(%rip), %rdi     # 0x10e0d5
pushq $0x11
popq %rsi
callq 0x576d4
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x83b1e