// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathgps.cpp
// Function: parse_rftg_time()
void parse_rftg_time()
{
int i;
char c;
double jd;

   log_packet_id("RFTG time code");

   start_msg_decode(1);
   jd = 0.0;

   nmea_msg[0] = 0;
   for(i=0; i<tsip_wptr; i++) {  // copy message from tsip buffer to nmea buffer
      c = tsip_byte();
      nmea_msg[i] = c;
      nmea_msg[i+1] = 0;
      if(i >= ((int)sizeof(nmea_msg)-12)) break;
   }

   msg_col = 0;     // index of next char to get from nmea buffer
   if(get_fixed_field(1)) {    // 0=ref0  1=ref1
      rftg_unit = atohex(msg_field);
      have_rftg_unit = 1;
      if((rftg_unit != 0) && (user_set_sat_plot == 0)) {  // enable sat plot unless user set it
         plot[SAT_PLOT].show_plot = 1;
      }
   }
   if(get_fixed_field(1)) {    // 0=active 1=inactive
      i = atohex(msg_field);
      if(i) minor_alarms |= MINOR_INACTIVE;
      else  minor_alarms &= (~MINOR_INACTIVE);
   }
   if(get_fixed_field(1)) {    // not used
      i = atohex(msg_field);
   }
   if(get_fixed_field(1)) {    // mode
      i = atohex(msg_field);
      if     (i == 0) discipline_mode = DIS_MODE_WARMUP;
      else if(i == 1) discipline_mode = DIS_MODE_NORMAL;
      else if(i == 2) discipline_mode = DIS_MODE_AUTO_HOLD;
      else if(i == 3) discipline_mode = DIS_MODE_FAILED;
      else if(i == 4) discipline_mode = DIS_MODE_UNKNOWN;
   }

   if(get_fixed_field(1)) {   // alarm char 1
      i = atohex(msg_field);
      if(i & 0x03) pps_enabled = 0;
      else         pps_enabled = 1;
      have_pps_enable = 1;

      if(i & 0x04) minor_alarms |= MINOR_ANT_NO_PWR;
      else         minor_alarms &= (~MINOR_ANT_NO_PWR);
      have_antenna = 1;

      if(i & 0x08) minor_alarms |= MINOR_WARMUP;   // warmup fail
      else         minor_alarms &= (~MINOR_WARMUP); // warmup ok
   }

   have_critical_alarms = 1;
   critical_alarms &= (~CRIT_OCXO);
   if(get_fixed_field(1)) {   // alarm char 2
      i = atohex(msg_field);
      if(i & 0x01) critical_alarms |= CRIT_OCXO;
      if(i & 0x02) critical_alarms |= CRIT_ROM;     // GPS ROM
      else         critical_alarms &= (~CRIT_ROM);
      if(i & 0x04) critical_alarms |= CRIT_RAM;     // GPS RAM
      else         critical_alarms &= (~CRIT_RAM);  
      if(i & 0x08) critical_alarms |= CRIT_OCXO;
   }

   if(get_fixed_field(1)) {   // alarm char 3
      i = atohex(msg_field);
      have_critical_alarms = 1;
      if(i & 0x01) critical_alarms |= MINOR_HOLDOVER;          
      else         critical_alarms &= (~MINOR_HOLDOVER);          
      if(i & 0x04) minor_alarms    |= MINOR_DISCIPLINE;   
      else         minor_alarms    &= (~MINOR_DISCIPLINE);
      if(i & 0x0A) critical_alarms |= CRIT_FPGA;          // temperature
      else         critical_alarms &= (~CRIT_FPGA);
   }

   if(get_fixed_field(1)) {   // alarm char 4
      i = atohex(msg_field);
      if(i & 0x01) critical_alarms |= CRIT_GPS;
      else         critical_alarms &= (~CRIT_GPS);
      if(i & 0x0A) minor_alarms    |= MINOR_OSC_CTRL;
      else         minor_alarms    &= (~MINOR_OSC_CTRL);
   }

   if(get_fixed_field(2)) {   // time in current mode
   }

   if(get_fixed_field(8)) {  // gps time
      time_flags &= (~TFLAGS_INVALID);
      jd = (double) atohex(msg_field);
      if(jd == 0.0) {  // no time, show system clock
         time_flags |= TFLAGS_INVALID;
         get_clock_time();
         jd = clk_jd - GPS_EPOCH;
         jd *= (24.0*60.0*60.0);
      }
   }

   if(get_fixed_field(4)) {   // firmware ID
      msg_field[4] = 0;
      strcpy(rftg_fw, msg_field);
      have_info |= (MANUF_PARAMS | PRODN_PARAMS);
   }

// sprintf(out, "%s -> unit %d  status:%04X  alarm:%06X  time:%.0f  mfg:%s", 
// nmea_msg, unit, status, alarm, jd, msg_field);

   jd /= (24.0*60.0*60.0);
   jd += GPS_EPOCH;

   set_gregorian_time(jd);
   if(time_flags & TFLAGS_UTC) {
      gps_to_utc();
   }

   update_gps_screen(4387);
   request_rftg_voltages();   // ask for group of status messages every second
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
leaq 0x9a4b4(%rip), %rdi     # 0x123729
callq 0x58dc2
movl $0x1, %edi
callq 0x7f2b8
leaq 0x2b25a5(%rip), %rbx    # 0x33b830
movb $0x0, (%rbx)
xorl %r14d, %r14d
leaq 0x2aefba(%rip), %r15    # 0x338252
leaq 0x1b5cd1(%rip), %r12    # 0x23ef70
movzwl (%r15), %eax
cmpq %rax, %r14
jae 0x892cf
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x892b9
orb $0x8, (%r12)
movb %al, (%r14,%rbx)
movb $0x0, 0x1(%r14,%rbx)
incq %r14
cmpq $0x1f6, %r14            # imm = 0x1F6
jne 0x8929f
leaq 0x2b296e(%rip), %rax    # 0x33bc44
movl $0x0, (%rax)
movl $0x1, %edi
callq 0x83d8c
testl %eax, %eax
je 0x8932d
leaq 0x2b274f(%rip), %rdi    # 0x33ba40
callq 0x98c6
leaq 0x2846b7(%rip), %rcx    # 0x30d9b4
movl %eax, (%rcx)
leaq 0x2846b2(%rip), %rcx    # 0x30d9b8
movl $0x1, (%rcx)
testl %eax, %eax
je 0x8932d
leaq 0x284b4f(%rip), %rax    # 0x30de66
cmpb $0x0, (%rax)
jne 0x8932d
leaq 0xd4a0d(%rip), %rax     # 0x15dd30
movl $0x1, 0x1150(%rax)
movl $0x1, %edi
callq 0x83d8c
testl %eax, %eax
je 0x89363
leaq 0x2b26fe(%rip), %rdi    # 0x33ba40
callq 0x98c6
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
leaq 0x283e83(%rip), %rax    # 0x30d1d8
movl $0xff7fffff, %edx       # imm = 0xFF7FFFFF
andl (%rax), %edx
shll $0x17, %ecx
orl %edx, %ecx
movl %ecx, (%rax)
movl $0x1, %edi
callq 0x83d8c
testl %eax, %eax
je 0x8937d
leaq 0x2b26c8(%rip), %rdi    # 0x33ba40
callq 0x98c6
movl $0x1, %edi
callq 0x83d8c
testl %eax, %eax
je 0x893b7
leaq 0x2b26ae(%rip), %rdi    # 0x33ba40
callq 0x98c6
cmpl $0x4, %eax
ja 0x893b7
shll $0x3, %eax
movabsq $0xff1902000a, %rdx     # imm = 0xFF1902000A
movl %eax, %ecx
shrq %cl, %rdx
leaq 0x2840e2(%rip), %rax    # 0x30d497
movb %dl, (%rax)
movl $0x1, %ebx
movl $0x1, %edi
callq 0x83d8c
testl %eax, %eax
je 0x89419
leaq 0x2b266f(%rip), %rdi    # 0x33ba40
callq 0x98c6
testb $0x3, %al
leaq 0x284941(%rip), %rcx    # 0x30dd20
sete (%rcx)
leaq 0x283ef3(%rip), %rcx    # 0x30d2dc
movl %ebx, (%rcx)
movl %eax, %ecx
shll $0x1d, %ecx
sarl $0x1f, %ecx
leaq 0x283dde(%rip), %rdx    # 0x30d1d8
movl $0xffbffff9, %esi       # imm = 0xFFBFFFF9
andl (%rdx), %esi
andl $0x6, %ecx
orl %esi, %ecx
leaq 0x283e1f(%rip), %rsi    # 0x30d22c
movl %ebx, (%rsi)
andl $0x8, %eax
shll $0x13, %eax
orl %ecx, %eax
movl %eax, (%rdx)
leaq 0x283e88(%rip), %r14    # 0x30d2a8
movl $0x1, (%r14)
leaq 0x283da2(%rip), %rbx    # 0x30d1d0
andb $-0x11, (%rbx)
movl $0x1, %edi
callq 0x83d8c
testl %eax, %eax
je 0x8946e
leaq 0x2b25fa(%rip), %rdi    # 0x33ba40
callq 0x98c6
movl (%rbx), %edx
movl %eax, %ecx
shll $0x4, %ecx
andl $0x10, %ecx
andl $-0x4, %edx
orl %ecx, %edx
movl %eax, %ecx
shrl %ecx
andl $0x3, %ecx
orl %edx, %ecx
movl %ecx, (%rbx)
testb $0x8, %al
je 0x8946e
orl $0x10, %ecx
movl %ecx, (%rbx)
movl $0x1, %edi
callq 0x83d8c
testl %eax, %eax
je 0x894c6
leaq 0x2b25bd(%rip), %rdi    # 0x33ba40
callq 0x98c6
movl $0x1, (%r14)
movl $0xfefffff7, %ecx       # imm = 0xFEFFFFF7
andl (%rbx), %ecx
movl %eax, %edx
andl $0x1, %edx
shll $0x18, %edx
orl %ecx, %edx
leaq 0x283d31(%rip), %rcx    # 0x30d1d8
movl $0xffdfffff, %esi       # imm = 0xFFDFFFFF
andl (%rcx), %esi
movl %eax, %edi
andl $0x4, %edi
shll $0x13, %edi
orl %esi, %edi
movl %edi, (%rcx)
xorl %ecx, %ecx
testb $0xa, %al
setne %cl
leal (%rdx,%rcx,8), %eax
movl %eax, (%rbx)
movl $0x1, %edi
callq 0x83d8c
testl %eax, %eax
je 0x89509
leaq 0x2b2565(%rip), %rdi    # 0x33ba40
callq 0x98c6
movl (%rbx), %ecx
andl $-0x9, %ecx
movl %eax, %edx
andl $0x1, %edx
leal (%rcx,%rdx,8), %ecx
movl %ecx, (%rbx)
xorl %ecx, %ecx
testb $0xa, %al
setne %cl
leaq 0x283cdb(%rip), %rax    # 0x30d1d8
movl (%rax), %edx
andl $-0x11, %edx
shll $0x4, %ecx
orl %edx, %ecx
movl %ecx, (%rax)
movl $0x2, %edi
callq 0x83d8c
movl $0x8, %edi
callq 0x83d8c
testl %eax, %eax
je 0x89544
leaq 0x283f7c(%rip), %rbx    # 0x30d4a4
andb $-0x5, (%rbx)
leaq 0x2b250e(%rip), %rdi    # 0x33ba40
callq 0x98c6
testl %eax, %eax
je 0x8954a
movl %eax, %eax
cvtsi2sd %rax, %xmm0
jmp 0x8956d
xorpd %xmm0, %xmm0
jmp 0x8956d
orb $0x4, (%rbx)
callq 0xa477
leaq 0x284187(%rip), %rax    # 0x30d6e0
movsd (%rax), %xmm0
addsd 0x8232b(%rip), %xmm0    # 0x10b890
mulsd 0x7faab(%rip), %xmm0    # 0x109018
movsd %xmm0, -0x28(%rbp)
movl $0x4, %edi
callq 0x83d8c
testl %eax, %eax
je 0x895a1
leaq 0x2b24b9(%rip), %rsi    # 0x33ba40
movb $0x0, 0x4(%rsi)
leaq 0x28442e(%rip), %rdi    # 0x30d9c0
callq 0x9340
leaq 0x2843d6(%rip), %rax    # 0x30d974
orb $0x3, (%rax)
movsd -0x28(%rbp), %xmm0
divsd 0x7fa6a(%rip), %xmm0    # 0x109018
addsd 0x822e2(%rip), %xmm0    # 0x10b898
callq 0x5c71d
leaq 0x283ee2(%rip), %rbx    # 0x30d4a4
testb $0x1, (%rbx)
je 0x895ef
leaq 0x28415a(%rip), %rax    # 0x30d728
cvtsi2sdl (%rax), %xmm1
xorpd %xmm0, %xmm0
subsd %xmm1, %xmm0
callq 0x5c7ed
orb $0x1, (%rbx)
leaq 0x283de3(%rip), %rax    # 0x30d3cc
movl $0x1, (%rax)
callq 0x730e8
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x658db