// File: /workspace/github_cpp_makefile_star2_O2/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 %rbx
pushq %rax
leaq 0x90bd7(%rip), %rdi     # 0x10d671
callq 0x520bf
pushq $0x1
popq %rdi
callq 0x73dcb
leaq 0x2a8d82(%rip), %rbx    # 0x325830
movb $0x0, (%rbx)
xorl %r14d, %r14d
leaq 0x2a5797(%rip), %r15    # 0x322252
movzwl (%r15), %eax
cmpq %rax, %r14
jae 0x7cadf
callq 0x51c47
movb %al, (%r14,%rbx)
movb $0x0, 0x1(%r14,%rbx)
incq %r14
cmpq $0x1f6, %r14            # imm = 0x1F6
jne 0x7cabb
leaq 0x2a915e(%rip), %rax    # 0x325c44
andl $0x0, (%rax)
pushq $0x1
popq %rdi
callq 0x78198
testl %eax, %eax
je 0x7cb38
leaq 0x2a8f44(%rip), %rdi    # 0x325a40
callq 0x98b2
leaq 0x27aeac(%rip), %rcx    # 0x2f79b4
movl %eax, (%rcx)
leaq 0x27aea7(%rip), %rcx    # 0x2f79b8
movl $0x1, (%rcx)
testl %eax, %eax
je 0x7cb38
leaq 0x27b344(%rip), %rax    # 0x2f7e66
cmpb $0x0, (%rax)
jne 0x7cb38
leaq 0xcb202(%rip), %rax     # 0x147d30
movl $0x1, 0x1150(%rax)
pushq $0x1
popq %rdi
callq 0x78198
testl %eax, %eax
je 0x7cb6c
leaq 0x2a8ef5(%rip), %rdi    # 0x325a40
callq 0x98b2
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
leaq 0x27a67a(%rip), %rax    # 0x2f71d8
movl $0xff7fffff, %edx       # imm = 0xFF7FFFFF
andl (%rax), %edx
shll $0x17, %ecx
orl %edx, %ecx
movl %ecx, (%rax)
pushq $0x1
popq %rdi
callq 0x78198
testl %eax, %eax
je 0x7cb84
leaq 0x2a8ec1(%rip), %rdi    # 0x325a40
callq 0x98b2
pushq $0x1
popq %rdi
callq 0x78198
testl %eax, %eax
je 0x7cbbc
leaq 0x2a8ea9(%rip), %rdi    # 0x325a40
callq 0x98b2
cmpl $0x4, %eax
ja 0x7cbbc
shll $0x3, %eax
movabsq $0xff1902000a, %rdx     # imm = 0xFF1902000A
movl %eax, %ecx
shrq %cl, %rdx
leaq 0x27a8dd(%rip), %rax    # 0x2f7497
movb %dl, (%rax)
pushq $0x1
popq %rbx
movl %ebx, %edi
callq 0x78198
testl %eax, %eax
je 0x7cc19
leaq 0x2a8e6f(%rip), %rdi    # 0x325a40
callq 0x98b2
testb $0x3, %al
leaq 0x27b141(%rip), %rcx    # 0x2f7d20
sete (%rcx)
leaq 0x27a6f3(%rip), %rcx    # 0x2f72dc
movl %ebx, (%rcx)
movl %eax, %ecx
shll $0x1d, %ecx
sarl $0x1f, %ecx
leaq 0x27a5de(%rip), %rdx    # 0x2f71d8
movl $0xffbffff9, %esi       # imm = 0xFFBFFFF9
andl (%rdx), %esi
andl $0x6, %ecx
orl %esi, %ecx
leaq 0x27a61f(%rip), %rsi    # 0x2f722c
movl %ebx, (%rsi)
andl $0x8, %eax
shll $0x13, %eax
orl %ecx, %eax
movl %eax, (%rdx)
leaq 0x27a688(%rip), %r14    # 0x2f72a8
movl $0x1, (%r14)
leaq 0x27a5a2(%rip), %rbx    # 0x2f71d0
andb $-0x11, (%rbx)
pushq $0x1
popq %rdi
callq 0x78198
testl %eax, %eax
je 0x7cc6c
leaq 0x2a8dfc(%rip), %rdi    # 0x325a40
callq 0x98b2
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 0x7cc6c
orl $0x10, %ecx
movl %ecx, (%rbx)
pushq $0x1
popq %rdi
callq 0x78198
testl %eax, %eax
je 0x7ccc2
leaq 0x2a8dc1(%rip), %rdi    # 0x325a40
callq 0x98b2
movl $0x1, (%r14)
movl $0xfefffff7, %ecx       # imm = 0xFEFFFFF7
andl (%rbx), %ecx
movl %eax, %edx
andl $0x1, %edx
shll $0x18, %edx
orl %ecx, %edx
leaq 0x27a535(%rip), %rcx    # 0x2f71d8
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)
pushq $0x1
popq %rdi
callq 0x78198
testl %eax, %eax
je 0x7cd03
leaq 0x2a8d6b(%rip), %rdi    # 0x325a40
callq 0x98b2
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 0x27a4e1(%rip), %rax    # 0x2f71d8
movl (%rax), %edx
andl $-0x11, %edx
shll $0x4, %ecx
orl %edx, %ecx
movl %ecx, (%rax)
pushq $0x2
popq %rdi
callq 0x78198
pushq $0x8
popq %rdi
callq 0x78198
testl %eax, %eax
je 0x7cd3a
leaq 0x27a786(%rip), %rbx    # 0x2f74a4
andb $-0x5, (%rbx)
leaq 0x2a8d18(%rip), %rdi    # 0x325a40
callq 0x98b2
testl %eax, %eax
je 0x7cd40
movl %eax, %eax
cvtsi2sd %rax, %xmm0
jmp 0x7cd63
xorpd %xmm0, %xmm0
jmp 0x7cd63
orb $0x4, (%rbx)
callq 0xa386
leaq 0x27a991(%rip), %rax    # 0x2f76e0
movsd (%rax), %xmm0
addsd 0x78bad(%rip), %xmm0    # 0xf5908
mulsd 0x762b5(%rip), %xmm0    # 0xf3018
movsd %xmm0, -0x20(%rbp)
pushq $0x4
popq %rdi
callq 0x78198
testl %eax, %eax
je 0x7cd95
leaq 0x2a8cc5(%rip), %rsi    # 0x325a40
movb $0x0, 0x4(%rsi)
leaq 0x27ac3a(%rip), %rdi    # 0x2f79c0
callq 0x9330
leaq 0x27abe2(%rip), %rax    # 0x2f7974
orb $0x3, (%rax)
movsd -0x20(%rbp), %xmm0
divsd 0x76276(%rip), %xmm0    # 0xf3018
addsd 0x78b66(%rip), %xmm0    # 0xf5910
callq 0x55392
leaq 0x27a6ee(%rip), %rax    # 0x2f74a4
testb $0x1, (%rax)
je 0x7cdc0
callq 0x55500
callq 0x694f6
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x5d535