// File: /workspace/github_cpp_makefile_star2_O1/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 0x9a3a2(%rip), %rdi     # 0x123649
callq 0x58e77
movl $0x1, %edi
callq 0x7f47d
leaq 0x2b2573(%rip), %rbx    # 0x33b830
movb $0x0, (%rbx)
xorl %r14d, %r14d
leaq 0x2aef88(%rip), %r15    # 0x338252
leaq 0x1b5c9f(%rip), %r12    # 0x23ef70
movzwl (%r15), %eax
cmpq %rax, %r14
jae 0x89301
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x892eb
orb $0x8, (%r12)
movb %al, (%r14,%rbx)
movb $0x0, 0x1(%r14,%rbx)
incq %r14
cmpq $0x1f6, %r14            # imm = 0x1F6
jne 0x892d1
leaq 0x2b293c(%rip), %rax    # 0x33bc44
movl $0x0, (%rax)
movl $0x1, %edi
callq 0x83e83
testl %eax, %eax
je 0x8935f
leaq 0x2b271d(%rip), %rdi    # 0x33ba40
callq 0x98c6
leaq 0x284685(%rip), %rcx    # 0x30d9b4
movl %eax, (%rcx)
leaq 0x284680(%rip), %rcx    # 0x30d9b8
movl $0x1, (%rcx)
testl %eax, %eax
je 0x8935f
leaq 0x284b1d(%rip), %rax    # 0x30de66
cmpb $0x0, (%rax)
jne 0x8935f
leaq 0xd49db(%rip), %rax     # 0x15dd30
movl $0x1, 0x1150(%rax)
movl $0x1, %edi
callq 0x83e83
testl %eax, %eax
je 0x89395
leaq 0x2b26cc(%rip), %rdi    # 0x33ba40
callq 0x98c6
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
leaq 0x283e51(%rip), %rax    # 0x30d1d8
movl $0xff7fffff, %edx       # imm = 0xFF7FFFFF
andl (%rax), %edx
shll $0x17, %ecx
orl %edx, %ecx
movl %ecx, (%rax)
movl $0x1, %edi
callq 0x83e83
testl %eax, %eax
je 0x893af
leaq 0x2b2696(%rip), %rdi    # 0x33ba40
callq 0x98c6
movl $0x1, %edi
callq 0x83e83
testl %eax, %eax
je 0x893e9
leaq 0x2b267c(%rip), %rdi    # 0x33ba40
callq 0x98c6
cmpl $0x4, %eax
ja 0x893e9
shll $0x3, %eax
movabsq $0xff1902000a, %rdx     # imm = 0xFF1902000A
movl %eax, %ecx
shrq %cl, %rdx
leaq 0x2840b0(%rip), %rax    # 0x30d497
movb %dl, (%rax)
movl $0x1, %ebx
movl $0x1, %edi
callq 0x83e83
testl %eax, %eax
je 0x8944b
leaq 0x2b263d(%rip), %rdi    # 0x33ba40
callq 0x98c6
testb $0x3, %al
leaq 0x28490f(%rip), %rcx    # 0x30dd20
sete (%rcx)
leaq 0x283ec1(%rip), %rcx    # 0x30d2dc
movl %ebx, (%rcx)
movl %eax, %ecx
shll $0x1d, %ecx
sarl $0x1f, %ecx
leaq 0x283dac(%rip), %rdx    # 0x30d1d8
movl $0xffbffff9, %esi       # imm = 0xFFBFFFF9
andl (%rdx), %esi
andl $0x6, %ecx
orl %esi, %ecx
leaq 0x283ded(%rip), %rsi    # 0x30d22c
movl %ebx, (%rsi)
andl $0x8, %eax
shll $0x13, %eax
orl %ecx, %eax
movl %eax, (%rdx)
leaq 0x283e56(%rip), %r14    # 0x30d2a8
movl $0x1, (%r14)
leaq 0x283d70(%rip), %rbx    # 0x30d1d0
andb $-0x11, (%rbx)
movl $0x1, %edi
callq 0x83e83
testl %eax, %eax
je 0x8949d
leaq 0x2b25c8(%rip), %rdi    # 0x33ba40
callq 0x98c6
testb $0x1, %al
je 0x89484
orb $0x10, (%rbx)
movl (%rbx), %edx
andl $-0x4, %edx
movl %eax, %ecx
shrl %ecx
andl $0x3, %ecx
orl %edx, %ecx
movl %ecx, (%rbx)
testb $0x8, %al
je 0x8949d
orl $0x10, %ecx
movl %ecx, (%rbx)
movl $0x1, %edi
callq 0x83e83
testl %eax, %eax
je 0x894f5
leaq 0x2b258e(%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 0x283d02(%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 0x83e83
testl %eax, %eax
je 0x89538
leaq 0x2b2536(%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 0x283cac(%rip), %rax    # 0x30d1d8
movl (%rax), %edx
andl $-0x11, %edx
shll $0x4, %ecx
orl %edx, %ecx
movl %ecx, (%rax)
movl $0x2, %edi
callq 0x83e83
movl $0x8, %edi
callq 0x83e83
testl %eax, %eax
je 0x89573
leaq 0x283f4d(%rip), %rbx    # 0x30d4a4
andb $-0x5, (%rbx)
leaq 0x2b24df(%rip), %rdi    # 0x33ba40
callq 0x98c6
testl %eax, %eax
je 0x89579
movl %eax, %eax
cvtsi2sd %rax, %xmm0
jmp 0x8959c
xorpd %xmm0, %xmm0
jmp 0x8959c
orb $0x4, (%rbx)
callq 0xa495
leaq 0x284158(%rip), %rax    # 0x30d6e0
movsd (%rax), %xmm0
addsd 0x822ec(%rip), %xmm0    # 0x10b880
mulsd 0x7fa7c(%rip), %xmm0    # 0x109018
movsd %xmm0, -0x28(%rbp)
movl $0x4, %edi
callq 0x83e83
testl %eax, %eax
je 0x895d0
leaq 0x2b248a(%rip), %rsi    # 0x33ba40
movb $0x0, 0x4(%rsi)
leaq 0x2843ff(%rip), %rdi    # 0x30d9c0
callq 0x9340
leaq 0x2843a7(%rip), %rax    # 0x30d974
orb $0x3, (%rax)
movsd -0x28(%rbp), %xmm0
divsd 0x7fa3b(%rip), %xmm0    # 0x109018
addsd 0x822a3(%rip), %xmm0    # 0x10b888
callq 0x5c837
leaq 0x283eb3(%rip), %rbx    # 0x30d4a4
testb $0x1, (%rbx)
je 0x8961e
leaq 0x28412b(%rip), %rax    # 0x30d728
cvtsi2sdl (%rax), %xmm1
xorpd %xmm0, %xmm0
subsd %xmm1, %xmm0
callq 0x5c907
orb $0x1, (%rbx)
leaq 0x283db4(%rip), %rax    # 0x30d3cc
movl $0x1, (%rax)
callq 0x7327e
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x65712