// File: /workspace/github_cpp_makefile_star2_O1/jkingan[P]ladyheather/heathgps.cpp
// Function: set_timing_mode(unsigned char, int)
void set_timing_mode(u08 mode, int why)
{
int old_tf;

   // set the receiver to report time in either GPS or UTC
   // !!!!! should we always do manual_time if user set the UTC offset?
   // NEW_RCVR:

   if(read_only) return;

   if(rcvr_type == ACRON_RCVR) {
      goto manual_time;
   }
   else if(rcvr_type == BRANDY_RCVR) {
      goto manual_time;
   }
   else if(rcvr_type == CS_RCVR) {
      goto manual_time;
   }
   else if(rcvr_type == ESIP_RCVR) {
      if     (mode == TMODE_GPS) send_esip_cmd("PERDAPI,TIMEALIGN,1");  // gps time
      else if(mode == TMODE_UTC) send_esip_cmd("PERDAPI,TIMEALIGN,2");  // utc time
      else if(mode == TMODE_SU)  send_esip_cmd("PERDAPI,TIMEALIGN,3");  // utc(su) time
      save_segment(6, 87);  // we don't do this automatically
   }
   else if(rcvr_type == FURUNO_RCVR) {
      goto manual_time;
   }
   else if(rcvr_type == LPFRS_RCVR) {
      goto manual_time;
   }
   else if(rcvr_type == LUXOR_RCVR) {
      goto manual_time;
   }
   else if(rcvr_type == MOTO_RCVR) {
      send_moto_start("Aw");
      if(mode) send_byte(1);
      else     send_byte(0);
      send_moto_end();
   }
   else if(rcvr_type == NMEA_RCVR) {
      manual_time:     // receiver does not support output in GPS time, we do the conversion (if utc_offset is available)

      if(mode == 0) {  // GPS time
         time_flags &= (~TFLAGS_UTC);
         timing_mode = TMODE_GPS;
         have_timing_mode = 1;
      }
      else {  // UTC time
         time_flags |= (TFLAGS_UTC);
         timing_mode = TMODE_UTC;
         have_timing_mode = 1;
      }
   }
   else if(rcvr_type == NVS_RCVR) {
      old_tf = time_flags;
      if(mode == 0) {  // GPS time
         time_flags &= (~TFLAGS_UTC);
      }
      else {  // UTC time
         time_flags |= (TFLAGS_UTC);
      }
      set_pps(user_pps_enable, pps_polarity,  delay_value, pps1_delay,  pps_threshold, 44);
      time_flags = old_tf;
   }
   else if(rcvr_type == NO_RCVR) {
      goto manual_time;
   }
   else if(rcvr_type == PRS_RCVR) {
      goto manual_time;
   }
   else if(rcvr_type == RFTG_RCVR) {
      goto manual_time;
   }
   else if(1 && (rcvr_type == RT17_RCVR)) {
      goto manual_time;
   }
   else if(rcvr_type == SA35_RCVR) {
      goto manual_time;
   }
   else if(rcvr_type == SCPI_RCVR) {
      if(scpi_type == NORTEL_TYPE) {
         goto manual_time;
      }

      if(mode == 0) queue_scpi_cmd(":DIAG:GPS:UTC 0", SCPI_UTC_MSG);
      else          queue_scpi_cmd(":DIAG:GPS:UTC 1", SCPI_UTC_MSG);
      queue_scpi_cmd("*TST?", SCPI_TEST_MSG);  // cause a system reset
      show_test_warning();
//    queue_scpi_cmd(":DIAG:GPS:UTC?", SCPI_UTC_MSG);
   }
   else if(rcvr_type == SIRF_RCVR) {
      goto manual_time;
   }
   else if(rcvr_type == SRO_RCVR) {
      goto manual_time;
   }
   else if(rcvr_type == SS_RCVR) {
      goto manual_time;
   }
   else if(rcvr_type == STAR_RCVR) {
      goto manual_time;
   }
   else if(SV6_FAMILY || ACU_360 || ACU_GG || ACUTIME || PALISADE) {
      if(ACU_GG || ACU_360) {   // !!!!!! bork ACU_360
         goto tsip_tmode;
      }
      else if(mode) {  // utc
         set_io_options(0x32, 0x02, 0x03, BROADCAST_5A | DOPPLER_SMOOTH);  // LLA+DBL PRECISION, ENU vel,  UTC, PACKET 5A
      }
      else {
         set_io_options(0x32, 0x02, 0x02, BROADCAST_5A | DOPPLER_SMOOTH);  // LLA+DBL PRECISION, ENU vel,  GPS, PACKET 5A
      }
      request_io_options();
   }
   else if(rcvr_type == TAIP_RCVR) {
      goto manual_time;
   }
   else if(rcvr_type == THERMO_RCVR) {
      goto manual_time;
   }
   else if(rcvr_type == TICC_RCVR) {
      goto manual_time;
   }
   else if(rcvr_type == TIDE_RCVR) {
      goto manual_time;
   }
   else if(rcvr_type == TM4_RCVR) {
      goto manual_time;
   }
   else if(rcvr_type == TRUE_RCVR) {
      goto manual_time;
   }
   else if(rcvr_type == TSERVE_RCVR) {
      goto manual_time;
   }
   else if((rcvr_type == TSIP_RCVR) && (tsip_type == STARLOC_TYPE)) {
      send_tsip_start(0x8E);
      send_byte(0xA2);
      send_byte(TMODE_GPS);  // always set GPS mode, STARLOC always reports it is in GPS mode
      send_tsip_end();
      goto manual_time; // ... so we have to always manualy adjust the time
   }
   else if(rcvr_type == TSIP_RCVR) {
      tsip_tmode:
//sprintf(debug_text2, "set timing mode: %02X  why:%d", mode, why);
      send_tsip_start(0x8E);
      send_byte(0xA2);
      send_byte(mode);
      send_tsip_end();
      request_timing_mode();

      if(have_gnss_mask) {
      }
   }
   else if(rcvr_type == UBX_RCVR) {
      goto manual_time;
   }
   else if(rcvr_type == UCCM_RCVR) {
      goto manual_time;
   }
   else if(rcvr_type == VENUS_RCVR) {
      goto manual_time;
   }
   else if(rcvr_type == X72_RCVR) {
      goto manual_time;
   }
   else if(rcvr_type == Z12_RCVR) {
      goto manual_time;
   }
   else if(rcvr_type == ZODIAC_RCVR) {
      if(mode == 0) {  // GPS time
         time_flags &= (~TFLAGS_UTC);
         timing_mode = TMODE_GPS;
         have_timing_mode = 1;
      }
      else {  // utc time
         time_flags |= (TFLAGS_UTC);
         timing_mode = TMODE_UTC;
         have_timing_mode = 1;
      }
      set_zod_config(0, 0.0,0.0,0.0, traim_threshold, 5);  // timing mode alignment
   }
   else if(rcvr_type == ZYFER_RCVR) {
      if(mode == 0) send_zyfer_cmd("$TIMM,1,0,0");  // gps
      else          send_zyfer_cmd("$TIMM,2,0,0");  // utc
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
leaq 0x2db5b5(%rip), %rax    # 0x33701a
cmpb $0x0, (%rax)
jne 0x5bcc3
movl %edi, %ebx
leaq 0x1bce59(%rip), %rax    # 0x2188d0
movq (%rax), %rax
cmpq $0x1ffff, %rax          # imm = 0x1FFFF
jle 0x5baf2
cmpq $0xfffffff, %rax        # imm = 0xFFFFFFF
jle 0x5bb27
movabsq $0x1ffffffff, %rcx      # imm = 0x1FFFFFFFF
cmpq %rcx, %rax
jg 0x5bb91
cmpq $0x10000000, %rax       # imm = 0x10000000
je 0x5bc89
cmpq $0x20000000, %rax       # imm = 0x20000000
je 0x5bc89
movl $0x80000000, %ecx       # imm = 0x80000000
cmpq %rcx, %rax
jne 0x5bd11
testb %bl, %bl
je 0x5be77
movzbl %bl, %eax
cmpl $0x80, %eax
je 0x5be6e
cmpl $0x3, %eax
jne 0x5be83
leaq 0xc580d(%rip), %rdi     # 0x1212fa
jmp 0x5be7e
cmpq $0x3ff, %rax            # imm = 0x3FF
jg 0x5bb5c
cmpq $0xf, %rax
jle 0x5bbec
cmpq $0x10, %rax
je 0x5bc79
cmpq $0x20, %rax
je 0x5bcce
cmpq $0x40, %rax
je 0x5bc89
jmp 0x5bd11
cmpq $0x3fffff, %rax         # imm = 0x3FFFFF
jle 0x5bbcf
cmpq $0x400000, %rax         # imm = 0x400000
je 0x5bc89
cmpq $0x1000000, %rax        # imm = 0x1000000
je 0x5bc89
cmpq $0x8000000, %rax        # imm = 0x8000000
je 0x5bc89
jmp 0x5bd11
cmpq $0xfff, %rax            # imm = 0xFFF
jle 0x5bc05
cmpq $0x1000, %rax           # imm = 0x1000
je 0x5bc89
cmpq $0x2000, %rax           # imm = 0x2000
je 0x5bc89
cmpq $0x4000, %rax           # imm = 0x4000
je 0x5bc89
jmp 0x5bd11
movabsq $0x200000000, %rcx      # imm = 0x200000000
cmpq %rcx, %rax
je 0x5bc89
movabsq $0x800000000, %rcx      # imm = 0x800000000
cmpq %rcx, %rax
je 0x5bc89
movabsq $0x1000000000, %rcx     # imm = 0x1000000000
cmpq %rcx, %rax
je 0x5bc89
jmp 0x5bd11
cmpq $0x20000, %rax          # imm = 0x20000
je 0x5bc89
cmpq $0x40000, %rax          # imm = 0x40000
je 0x5bc89
jmp 0x5bd11
cmpq $0x1, %rax
je 0x5bcf6
cmpq $0x2, %rax
je 0x5bc89
jmp 0x5bd11
cmpq $0x400, %rax            # imm = 0x400
je 0x5bc89
cmpq $0x800, %rax            # imm = 0x800
jne 0x5bd11
leaq 0x2b1884(%rip), %r14    # 0x30d4a4
movl (%r14), %r15d
xorl %eax, %eax
testb %bl, %bl
setne %al
movl %r15d, %ecx
andl $-0x2, %ecx
orl %ecx, %eax
movl %eax, (%r14)
leaq 0x2b20e5(%rip), %rax    # 0x30dd21
movzbl (%rax), %edi
leaq 0x2b20d2(%rip), %rax    # 0x30dd18
movzbl (%rax), %esi
leaq 0x2b2170(%rip), %rax    # 0x30ddc0
movsd (%rax), %xmm0
leaq 0x2b217d(%rip), %rax    # 0x30ddd8
movsd (%rax), %xmm1
leaq 0x2b20b6(%rip), %rax    # 0x30dd1c
movss (%rax), %xmm2
movl $0x2c, %edx
callq 0x6ad1d
movl %r15d, (%r14)
jmp 0x5bcc3
leaq 0x1bf360(%rip), %rax    # 0x21afe0
cmpl $0x4e, (%rax)
jne 0x5be06
leaq 0x2b1814(%rip), %rax    # 0x30d4a4
movl (%rax), %ecx
testb %bl, %bl
je 0x5bca7
orl $0x1, %ecx
movl %ecx, (%rax)
leaq 0x2b181b(%rip), %rax    # 0x30d4bd
movb $0x3, (%rax)
jmp 0x5bcb6
andl $-0x2, %ecx
movl %ecx, (%rax)
leaq 0x2b180a(%rip), %rax    # 0x30d4bd
movb $0x0, (%rax)
leaq 0x2b170f(%rip), %rax    # 0x30d3cc
movl $0x1, (%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc5605(%rip), %rdi     # 0x1212da
callq 0x61694
xorl %edi, %edi
testb %bl, %bl
setne %dil
callq 0x591af
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x6170f
leaq 0x1bf2d7(%rip), %rcx    # 0x21afd4
movl (%rcx), %ecx
addl $-0x33, %ecx
cmpl $0x1d, %ecx
ja 0x5bd11
movl $0x20004009, %edx       # imm = 0x20004009
btl %ecx, %edx
jb 0x5bd64
cmpq $0x1, %rax
sete %dl
leaq 0x1bf2b5(%rip), %rcx    # 0x21afd4
movl (%rcx), %ecx
cmpl $0x41, %ecx
sete %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x5bd44
leaq 0x1bcbc0(%rip), %rdx    # 0x2188f8
movl (%rdx), %edx
cmpl $0x33, %edx
je 0x5bd64
cmpl $0x47, %edx
je 0x5bd64
cmpl $0x41, %ecx
sete %dl
cmpl $0x50, %ecx
sete %sil
cmpq $0x1, %rax
jne 0x5be44
orb %sil, %dl
je 0x5be44
cmpq $0x1, %rax
sete %al
leaq 0x1bf262(%rip), %rcx    # 0x21afd4
cmpl $0x41, (%rcx)
sete %cl
andb %al, %cl
leaq 0x1bcb77(%rip), %rax    # 0x2188f8
movl (%rax), %eax
cmpl $0x47, %eax
sete %dl
testb %dl, %cl
je 0x5bdbd
movl $0x8e, %edi
callq 0x5e740
movl $0xa2, %edi
callq 0x591af
movzbl %bl, %edi
callq 0x591af
callq 0x5e7c0
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x6d32a
testb %cl, %cl
je 0x5bdcb
cmpl $0x33, %eax
je 0x5bd8d
cmpl $0x47, %eax
je 0x5bd8d
leaq 0x1bcb32(%rip), %rax    # 0x218904
cmpb $0x1, (%rax)
sete %al
orb $0x2, %al
cmpb $0x1, %bl
movl $0x3, %edx
sbbl $0x0, %edx
movzbl %al, %ecx
movl $0x32, %edi
movl $0x2, %esi
callq 0x68554
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x6851a
testb %bl, %bl
leaq 0xc5513(%rip), %rax     # 0x121322
leaq 0xc551c(%rip), %rdi     # 0x121332
cmoveq %rax, %rdi
movl $0x17, %esi
callq 0x5ee52
leaq 0xc483d(%rip), %rdi     # 0x120668
movl $0x19, %esi
callq 0x5ee52
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x6605c
cmpq $0x1fffff, %rax         # imm = 0x1FFFFF
jle 0x5be97
cmpq $0x3fffffff, %rax       # imm = 0x3FFFFFFF
jg 0x5bebd
cmpq $0x200000, %rax         # imm = 0x200000
je 0x5bc89
cmpq $0x800000, %rax         # imm = 0x800000
je 0x5bc89
jmp 0x5bedc
leaq 0xc5499(%rip), %rdi     # 0x12130e
jmp 0x5be7e
leaq 0xc5468(%rip), %rdi     # 0x1212e6
callq 0x5ef13
movl $0x6, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x6a306
cmpq $0x8000, %rax           # imm = 0x8000
je 0x5bc89
cmpq $0x10000, %rax          # imm = 0x10000
je 0x5bc89
cmpq $0x80000, %rax          # imm = 0x80000
je 0x5bc89
jmp 0x5bedc
cmpq $0x40000000, %rax       # imm = 0x40000000
je 0x5bc89
movabsq $0x400000000, %rdx      # imm = 0x400000000
cmpq %rdx, %rax
je 0x5bc89
cmpq $0x1, %rax
sete %dl
cmpl $0x53, %ecx
sete %cl
andb %dl, %cl
cmpb $0x1, %cl
jne 0x5bf15
movl $0x8e, %edi
callq 0x5e740
movl $0xa2, %edi
callq 0x591af
xorl %edi, %edi
callq 0x591af
callq 0x5e7c0
jmp 0x5bc89
cmpq $0x1, %rax
je 0x5bd8d
cmpq $0xff, %rax
jle 0x5bf57
cmpq $0x1ffffff, %rax        # imm = 0x1FFFFFF
jg 0x5bf7c
cmpq $0x100, %rax            # imm = 0x100
je 0x5bfa0
cmpq $0x100000, %rax         # imm = 0x100000
jne 0x5bcc3
testb %bl, %bl
je 0x5bff3
leaq 0xc53fd(%rip), %rdi     # 0x12134f
jmp 0x5bffa
cmpq $0x4, %rax
je 0x5bc89
cmpq $0x8, %rax
je 0x5bc89
cmpq $0x80, %rax
je 0x5bc89
jmp 0x5bcc3
cmpq $0x2000000, %rax        # imm = 0x2000000
je 0x5bc89
movabsq $0x100000000, %rcx      # imm = 0x100000000
cmpq %rcx, %rax
je 0x5bc89
jmp 0x5bcc3
xorl %eax, %eax
testb %bl, %bl
setne %al
leaq 0x2b14f6(%rip), %rcx    # 0x30d4a4
movl (%rcx), %edx
andl $-0x2, %edx
orl %eax, %edx
leal (%rax,%rax,2), %eax
movl %edx, (%rcx)
leaq 0x2b14fc(%rip), %rcx    # 0x30d4bd
movb %al, (%rcx)
leaq 0x2b1402(%rip), %rax    # 0x30d3cc
movl $0x1, (%rax)
leaq 0x1bf0ed(%rip), %rax    # 0x21b0c4
movl (%rax), %esi
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
xorl %edi, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x683cd
leaq 0xc5349(%rip), %rdi     # 0x121343
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x5f15d