// File: 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
subq $0x10, %rsp
leaq 0xcb4a1(%rip), %rdi     # 0x186a10
callq 0x7add0
movl $0x1, %edi
callq 0xae4a0
xorps %xmm0, %xmm0
movsd %xmm0, -0x10(%rbp)
leaq 0x2df483(%rip), %rax    # 0x39aa10
movb $0x0, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
leaq 0x2dbe91(%rip), %rcx    # 0x397432
movzwl (%rcx), %ecx
cmpl %ecx, %eax
jge 0xbb5ed
callq 0x7a510
movb %al, -0x5(%rbp)
movb -0x5(%rbp), %dl
movslq -0x4(%rbp), %rcx
leaq 0x2df452(%rip), %rax    # 0x39aa10
movb %dl, (%rax,%rcx)
movl -0x4(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0x2df43f(%rip), %rax    # 0x39aa10
movb $0x0, (%rax,%rcx)
cmpl $0x1f5, -0x4(%rbp)      # imm = 0x1F5
jl 0xbb5e0
jmp 0xbb5ed
jmp 0xbb5e2
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0xbb597
leaq 0x2df830(%rip), %rax    # 0x39ae24
movl $0x0, (%rax)
movl $0x1, %edi
callq 0xb4d60
cmpl $0x0, %eax
je 0xbb65b
leaq 0x2df610(%rip), %rdi    # 0x39ac20
callq 0x98d0
movl %eax, %ecx
leaq 0x2b1576(%rip), %rax    # 0x36cb94
movl %ecx, (%rax)
leaq 0x2b1571(%rip), %rax    # 0x36cb98
movl $0x1, (%rax)
leaq 0x2b1560(%rip), %rax    # 0x36cb94
cmpl $0x0, (%rax)
je 0xbb659
leaq 0x2b1a06(%rip), %rax    # 0x36d046
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0xbb659
leaq 0x1016d1(%rip), %rax    # 0x1bcd20
movl $0x1, 0x1150(%rax)
jmp 0xbb65b
movl $0x1, %edi
callq 0xb4d60
cmpl $0x0, %eax
je 0xbb6b3
leaq 0x2df5af(%rip), %rdi    # 0x39ac20
callq 0x98d0
movl %eax, -0x4(%rbp)
cmpl $0x0, -0x4(%rbp)
je 0xbb699
leaq 0x2b0d32(%rip), %rax    # 0x36c3b8
movl (%rax), %ecx
orl $0x800000, %ecx         # imm = 0x800000
leaq 0x2b0d23(%rip), %rax    # 0x36c3b8
movl %ecx, (%rax)
jmp 0xbb6b1
leaq 0x2b0d18(%rip), %rax    # 0x36c3b8
movl (%rax), %ecx
andl $0xff7fffff, %ecx       # imm = 0xFF7FFFFF
leaq 0x2b0d09(%rip), %rax    # 0x36c3b8
movl %ecx, (%rax)
jmp 0xbb6b3
movl $0x1, %edi
callq 0xb4d60
cmpl $0x0, %eax
je 0xbb6d1
leaq 0x2df557(%rip), %rdi    # 0x39ac20
callq 0x98d0
movl %eax, -0x4(%rbp)
movl $0x1, %edi
callq 0xb4d60
cmpl $0x0, %eax
je 0xbb751
leaq 0x2df539(%rip), %rdi    # 0x39ac20
callq 0x98d0
movl %eax, -0x4(%rbp)
cmpl $0x0, -0x4(%rbp)
jne 0xbb701
leaq 0x2b0f7b(%rip), %rax    # 0x36c677
movb $0xa, (%rax)
jmp 0xbb74f
cmpl $0x1, -0x4(%rbp)
jne 0xbb713
leaq 0x2b0f69(%rip), %rax    # 0x36c677
movb $0x0, (%rax)
jmp 0xbb74d
cmpl $0x2, -0x4(%rbp)
jne 0xbb725
leaq 0x2b0f57(%rip), %rax    # 0x36c677
movb $0x2, (%rax)
jmp 0xbb74b
cmpl $0x3, -0x4(%rbp)
jne 0xbb737
leaq 0x2b0f45(%rip), %rax    # 0x36c677
movb $0x19, (%rax)
jmp 0xbb749
cmpl $0x4, -0x4(%rbp)
jne 0xbb747
leaq 0x2b0f33(%rip), %rax    # 0x36c677
movb $-0x1, (%rax)
jmp 0xbb749
jmp 0xbb74b
jmp 0xbb74d
jmp 0xbb74f
jmp 0xbb751
movl $0x1, %edi
callq 0xb4d60
cmpl $0x0, %eax
je 0xbb824
leaq 0x2df4b5(%rip), %rdi    # 0x39ac20
callq 0x98d0
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0xbb78a
leaq 0x2b177b(%rip), %rax    # 0x36cf00
movb $0x0, (%rax)
jmp 0xbb794
leaq 0x2b176f(%rip), %rax    # 0x36cf00
movb $0x1, (%rax)
leaq 0x2b0d21(%rip), %rax    # 0x36c4bc
movl $0x1, (%rax)
movl -0x4(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0xbb7c3
leaq 0x2b0c05(%rip), %rax    # 0x36c3b8
movl (%rax), %ecx
orl $0x6, %ecx
leaq 0x2b0bf9(%rip), %rax    # 0x36c3b8
movl %ecx, (%rax)
jmp 0xbb7d8
leaq 0x2b0bee(%rip), %rax    # 0x36c3b8
movl (%rax), %ecx
andl $-0x7, %ecx
leaq 0x2b0be2(%rip), %rax    # 0x36c3b8
movl %ecx, (%rax)
leaq 0x2b0c2d(%rip), %rax    # 0x36c40c
movl $0x1, (%rax)
movl -0x4(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0xbb80a
leaq 0x2b0bc1(%rip), %rax    # 0x36c3b8
movl (%rax), %ecx
orl $0x400000, %ecx         # imm = 0x400000
leaq 0x2b0bb2(%rip), %rax    # 0x36c3b8
movl %ecx, (%rax)
jmp 0xbb822
leaq 0x2b0ba7(%rip), %rax    # 0x36c3b8
movl (%rax), %ecx
andl $0xffbfffff, %ecx       # imm = 0xFFBFFFFF
leaq 0x2b0b98(%rip), %rax    # 0x36c3b8
movl %ecx, (%rax)
jmp 0xbb824
leaq 0x2b0c5d(%rip), %rax    # 0x36c488
movl $0x1, (%rax)
leaq 0x2b0b78(%rip), %rax    # 0x36c3b0
movl (%rax), %ecx
andl $-0x11, %ecx
leaq 0x2b0b6c(%rip), %rax    # 0x36c3b0
movl %ecx, (%rax)
movl $0x1, %edi
callq 0xb4d60
cmpl $0x0, %eax
je 0xbb918
leaq 0x2df3c0(%rip), %rdi    # 0x39ac20
callq 0x98d0
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xbb888
leaq 0x2b0b36(%rip), %rax    # 0x36c3b0
movl (%rax), %ecx
orl $0x10, %ecx
leaq 0x2b0b2a(%rip), %rax    # 0x36c3b0
movl %ecx, (%rax)
movl -0x4(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0xbb8aa
leaq 0x2b0b16(%rip), %rax    # 0x36c3b0
movl (%rax), %ecx
orl $0x1, %ecx
leaq 0x2b0b0a(%rip), %rax    # 0x36c3b0
movl %ecx, (%rax)
jmp 0xbb8bf
leaq 0x2b0aff(%rip), %rax    # 0x36c3b0
movl (%rax), %ecx
andl $-0x2, %ecx
leaq 0x2b0af3(%rip), %rax    # 0x36c3b0
movl %ecx, (%rax)
movl -0x4(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0xbb8e1
leaq 0x2b0adf(%rip), %rax    # 0x36c3b0
movl (%rax), %ecx
orl $0x2, %ecx
leaq 0x2b0ad3(%rip), %rax    # 0x36c3b0
movl %ecx, (%rax)
jmp 0xbb8f6
leaq 0x2b0ac8(%rip), %rax    # 0x36c3b0
movl (%rax), %ecx
andl $-0x3, %ecx
leaq 0x2b0abc(%rip), %rax    # 0x36c3b0
movl %ecx, (%rax)
movl -0x4(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0xbb916
leaq 0x2b0aa8(%rip), %rax    # 0x36c3b0
movl (%rax), %ecx
orl $0x10, %ecx
leaq 0x2b0a9c(%rip), %rax    # 0x36c3b0
movl %ecx, (%rax)
jmp 0xbb918
movl $0x1, %edi
callq 0xb4d60
cmpl $0x0, %eax
je 0xbb9fa
leaq 0x2df2ee(%rip), %rdi    # 0x39ac20
callq 0x98d0
movl %eax, -0x4(%rbp)
leaq 0x2b0b47(%rip), %rax    # 0x36c488
movl $0x1, (%rax)
movl -0x4(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xbb96c
leaq 0x2b0a57(%rip), %rax    # 0x36c3b0
movl (%rax), %ecx
orl $0x1000000, %ecx        # imm = 0x1000000
leaq 0x2b0a48(%rip), %rax    # 0x36c3b0
movl %ecx, (%rax)
jmp 0xbb984
leaq 0x2b0a3d(%rip), %rax    # 0x36c3b0
movl (%rax), %ecx
andl $0xfeffffff, %ecx       # imm = 0xFEFFFFFF
leaq 0x2b0a2e(%rip), %rax    # 0x36c3b0
movl %ecx, (%rax)
movl -0x4(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0xbb9a9
leaq 0x2b0a22(%rip), %rax    # 0x36c3b8
movl (%rax), %ecx
orl $0x200000, %ecx         # imm = 0x200000
leaq 0x2b0a13(%rip), %rax    # 0x36c3b8
movl %ecx, (%rax)
jmp 0xbb9c1
leaq 0x2b0a08(%rip), %rax    # 0x36c3b8
movl (%rax), %ecx
andl $0xffdfffff, %ecx       # imm = 0xFFDFFFFF
leaq 0x2b09f9(%rip), %rax    # 0x36c3b8
movl %ecx, (%rax)
movl -0x4(%rbp), %eax
andl $0xa, %eax
cmpl $0x0, %eax
je 0xbb9e3
leaq 0x2b09dd(%rip), %rax    # 0x36c3b0
movl (%rax), %ecx
orl $0x8, %ecx
leaq 0x2b09d1(%rip), %rax    # 0x36c3b0
movl %ecx, (%rax)
jmp 0xbb9f8
leaq 0x2b09c6(%rip), %rax    # 0x36c3b0
movl (%rax), %ecx
andl $-0x9, %ecx
leaq 0x2b09ba(%rip), %rax    # 0x36c3b0
movl %ecx, (%rax)
jmp 0xbb9fa
movl $0x1, %edi
callq 0xb4d60
cmpl $0x0, %eax
je 0xbba88
leaq 0x2df210(%rip), %rdi    # 0x39ac20
callq 0x98d0
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xbba3a
leaq 0x2b0986(%rip), %rax    # 0x36c3b0
movl (%rax), %ecx
orl $0x8, %ecx
leaq 0x2b097a(%rip), %rax    # 0x36c3b0
movl %ecx, (%rax)
jmp 0xbba4f
leaq 0x2b096f(%rip), %rax    # 0x36c3b0
movl (%rax), %ecx
andl $-0x9, %ecx
leaq 0x2b0963(%rip), %rax    # 0x36c3b0
movl %ecx, (%rax)
movl -0x4(%rbp), %eax
andl $0xa, %eax
cmpl $0x0, %eax
je 0xbba71
leaq 0x2b0957(%rip), %rax    # 0x36c3b8
movl (%rax), %ecx
orl $0x10, %ecx
leaq 0x2b094b(%rip), %rax    # 0x36c3b8
movl %ecx, (%rax)
jmp 0xbba86
leaq 0x2b0940(%rip), %rax    # 0x36c3b8
movl (%rax), %ecx
andl $-0x11, %ecx
leaq 0x2b0934(%rip), %rax    # 0x36c3b8
movl %ecx, (%rax)
jmp 0xbba88
movl $0x2, %edi
callq 0xb4d60
cmpl $0x0, %eax
je 0xbba99
jmp 0xbba99
movl $0x8, %edi
callq 0xb4d60
cmpl $0x0, %eax
je 0xbbb2c
leaq 0x2b0bd1(%rip), %rax    # 0x36c684
movb (%rax), %cl
andb $-0x5, %cl
movb %cl, (%rax)
leaq 0x2df15f(%rip), %rdi    # 0x39ac20
callq 0x98d0
movl %eax, %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x10(%rbp)
movsd -0x10(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xbbb2a
jp 0xbbb2a
leaq 0x2b0b9b(%rip), %rax    # 0x36c684
movl (%rax), %ecx
orl $0x4, %ecx
leaq 0x2b0b8f(%rip), %rax    # 0x36c684
movl %ecx, (%rax)
callq 0xa750
leaq 0x2b0dbd(%rip), %rax    # 0x36c8c0
movsd (%rax), %xmm0
movsd 0xb5b09(%rip), %xmm1    # 0x171618
subsd %xmm1, %xmm0
movsd %xmm0, -0x10(%rbp)
movsd 0xb34e8(%rip), %xmm0    # 0x16f008
mulsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x10(%rbp)
jmp 0xbbb2c
movl $0x4, %edi
callq 0xb4d60
cmpl $0x0, %eax
je 0xbbb6e
leaq 0x2df0de(%rip), %rax    # 0x39ac20
movb $0x0, 0x4(%rax)
leaq 0x2b1053(%rip), %rdi    # 0x36cba0
leaq 0x2df0cc(%rip), %rsi    # 0x39ac20
callq 0x9350
leaq 0x2b0ff4(%rip), %rax    # 0x36cb54
movl (%rax), %ecx
orl $0x3, %ecx
leaq 0x2b0fe8(%rip), %rax    # 0x36cb54
movl %ecx, (%rax)
movsd -0x10(%rbp), %xmm0
movsd 0xb348d(%rip), %xmm1    # 0x16f008
divsd %xmm1, %xmm0
movsd %xmm0, -0x10(%rbp)
movsd 0xb5a8c(%rip), %xmm0    # 0x171618
addsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x10(%rbp)
movsd -0x10(%rbp), %xmm0
callq 0x7fb00
leaq 0x2b0add(%rip), %rax    # 0x36c684
movl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xbbbb6
callq 0x7fcb0
movl $0x1123, %edi           # imm = 0x1123
callq 0x9d790
callq 0x8b090
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax,%rax)