// File: /workspace/github_cpp_makefile_star2_O3/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 0x2db69c(%rip), %rax    # 0x33701a
cmpb $0x0, (%rax)
jne 0x5bebc
movl %edi, %ebx
leaq 0x1bcf40(%rip), %rax    # 0x2188d0
movq (%rax), %rax
cmpq $0x7ffff, %rax          # imm = 0x7FFFF
jg 0x5ba3e
cmpq $0x3ff, %rax            # imm = 0x3FF
jg 0x5baa0
cmpq $0x1f, %rax
jg 0x5bb25
leaq -0x1(%rax), %rcx
cmpq $0x7, %rcx
ja 0x5bd70
leaq 0xc3146(%rip), %rax     # 0x11eb10
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
leaq 0x1bf5fa(%rip), %rax    # 0x21afd4
movl (%rax), %eax
leal -0x33(%rax), %ecx
cmpl $0x20, %ecx
ja 0x5ba0e
movl $0x20004009, %edx       # imm = 0x20004009
btq %rcx, %rdx
jae 0x5be58
leaq 0x1bcefe(%rip), %rcx    # 0x2188f8
movl (%rcx), %ecx
movl %eax, %edx
xorl $0x41, %edx
movl %ecx, %esi
xorl $0x47, %esi
orl %edx, %esi
jne 0x5be06
movl $0x8e, %edi
callq 0x5e6be
movl $0xa2, %edi
callq 0x590f7
movzbl %bl, %edi
callq 0x590f7
callq 0x5e73c
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x6d209
cmpq $0xfffffff, %rax        # imm = 0xFFFFFFF
jle 0x5bae1
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, %rax
jle 0x5bbcf
movabsq $0x3ffffffff, %rcx      # imm = 0x3FFFFFFFF
cmpq %rcx, %rax
jle 0x5bd0b
movabsq $0x400000000, %rcx      # imm = 0x400000000
cmpq %rcx, %rax
je 0x5be82
movabsq $0x800000000, %rcx      # imm = 0x800000000
cmpq %rcx, %rax
je 0x5be82
movabsq $0x1000000000, %rcx     # imm = 0x1000000000
jmp 0x5bd28
cmpq $0x3fff, %rax           # imm = 0x3FFF
jle 0x5bb48
cmpq $0xffff, %rax           # imm = 0xFFFF
jle 0x5bcee
cmpq $0x10000, %rax          # imm = 0x10000
je 0x5be82
cmpq $0x20000, %rax          # imm = 0x20000
je 0x5be82
cmpq $0x40000, %rax          # imm = 0x40000
je 0x5be82
jmp 0x5bebc
cmpq $0x7fffff, %rax         # imm = 0x7FFFFF
jg 0x5bbf8
cmpq $0x1fffff, %rax         # imm = 0x1FFFFF
jg 0x5bd36
cmpq $0x80000, %rax          # imm = 0x80000
je 0x5be82
cmpq $0x100000, %rax         # imm = 0x100000
jne 0x5bebc
testb %bl, %bl
je 0x5bdf0
leaq 0xc590f(%rip), %rdi     # 0x12142f
jmp 0x5bdf7
cmpq $0x7f, %rax
jg 0x5bc21
cmpq $0x20, %rax
je 0x5bdc8
cmpq $0x40, %rax
je 0x5be82
jmp 0x5bebc
cmpq $0xfff, %rax            # imm = 0xFFF
jg 0x5bc8c
cmpq $0x400, %rax            # imm = 0x400
je 0x5be82
cmpq $0x800, %rax            # imm = 0x800
jne 0x5bebc
leaq 0x2b1931(%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 0x2b2192(%rip), %rax    # 0x30dd21
movzbl (%rax), %edi
leaq 0x2b217f(%rip), %rax    # 0x30dd18
movzbl (%rax), %esi
leaq 0x2b221d(%rip), %rax    # 0x30ddc0
movsd (%rax), %xmm0
leaq 0x2b222a(%rip), %rax    # 0x30ddd8
movsd (%rax), %xmm1
leaq 0x2b2163(%rip), %rax    # 0x30dd1c
movss (%rax), %xmm2
movl $0x2c, %edx
callq 0x6add8
movl %r15d, (%r14)
jmp 0x5bebc
cmpq $0x3fffffff, %rax       # imm = 0x3FFFFFFF
jg 0x5bca9
cmpq $0x10000000, %rax       # imm = 0x10000000
je 0x5be82
cmpq $0x20000000, %rax       # imm = 0x20000000
je 0x5be82
jmp 0x5bebc
cmpq $0x1ffffff, %rax        # imm = 0x1FFFFFF
jg 0x5bd53
cmpq $0x800000, %rax         # imm = 0x800000
je 0x5be82
cmpq $0x1000000, %rax        # imm = 0x1000000
je 0x5be82
jmp 0x5bebc
cmpq $0x80, %rax
je 0x5be82
cmpq $0x100, %rax            # imm = 0x100
jne 0x5bebc
xorl %eax, %eax
testb %bl, %bl
setne %al
leaq 0x2b185d(%rip), %rcx    # 0x30d4a4
movl (%rcx), %edx
andl $-0x2, %edx
orl %eax, %edx
leal (%rax,%rax,2), %eax
movl %edx, (%rcx)
leaq 0x2b1863(%rip), %rcx    # 0x30d4bd
movb %al, (%rcx)
leaq 0x2b1769(%rip), %rax    # 0x30d3cc
movl $0x1, (%rax)
leaq 0x1bf454(%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 0x68563
cmpq $0x1000, %rax           # imm = 0x1000
je 0x5be82
cmpq $0x2000, %rax           # imm = 0x2000
je 0x5be82
jmp 0x5bebc
cmpq $0x40000000, %rax       # imm = 0x40000000
je 0x5be82
movl $0x80000000, %ecx       # imm = 0x80000000
cmpq %rcx, %rax
jne 0x5bebc
testb %bl, %bl
je 0x5bed0
movzbl %bl, %eax
cmpl $0x80, %eax
je 0x5bec7
cmpl $0x3, %eax
jne 0x5bedc
leaq 0xc56f1(%rip), %rdi     # 0x1213da
jmp 0x5bed7
cmpq $0x4000, %rax           # imm = 0x4000
je 0x5be82
cmpq $0x8000, %rax           # imm = 0x8000
je 0x5be82
jmp 0x5bebc
movabsq $0x100000000, %rcx      # imm = 0x100000000
cmpq %rcx, %rax
je 0x5be82
movabsq $0x200000000, %rcx      # imm = 0x200000000
cmpq %rcx, %rax
je 0x5be82
jmp 0x5bebc
cmpq $0x200000, %rax         # imm = 0x200000
je 0x5be82
cmpq $0x400000, %rax         # imm = 0x400000
je 0x5be82
jmp 0x5bebc
cmpq $0x2000000, %rax        # imm = 0x2000000
je 0x5be82
cmpq $0x8000000, %rax        # imm = 0x8000000
je 0x5be82
jmp 0x5bebc
cmpq $0x10, %rax
jne 0x5bebc
leaq 0x1bf25f(%rip), %rax    # 0x21afe0
cmpl $0x4e, (%rax)
je 0x5be82
testb %bl, %bl
leaq 0xc566f(%rip), %rax     # 0x121402
leaq 0xc5678(%rip), %rdi     # 0x121412
cmoveq %rax, %rdi
movl $0x17, %esi
callq 0x5edda
leaq 0xc4999(%rip), %rdi     # 0x120748
movl $0x19, %esi
callq 0x5edda
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x662ce
leaq 0xc55eb(%rip), %rdi     # 0x1213ba
callq 0x6160d
xorl %edi, %edi
testb %bl, %bl
setne %dil
callq 0x590f7
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x61688
leaq 0xc562c(%rip), %rdi     # 0x121423
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x5f0e5
cmpl $0x41, %eax
jne 0x5be1d
cmpl $0x33, %ecx
je 0x5ba0e
cmpl $0x47, %ecx
je 0x5ba0e
leaq 0x1bcae0(%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 0x687e1
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x687a7
cmpq $0x20, %rcx
jne 0x5ba0e
movl $0x8e, %edi
callq 0x5e6be
movl $0xa2, %edi
callq 0x590f7
xorl %edi, %edi
callq 0x590f7
callq 0x5e73c
leaq 0x2b161b(%rip), %rax    # 0x30d4a4
movl (%rax), %ecx
testb %bl, %bl
je 0x5bea0
orl $0x1, %ecx
movl %ecx, (%rax)
leaq 0x2b1622(%rip), %rax    # 0x30d4bd
movb $0x3, (%rax)
jmp 0x5beaf
andl $-0x2, %ecx
movl %ecx, (%rax)
leaq 0x2b1611(%rip), %rax    # 0x30d4bd
movb $0x0, (%rax)
leaq 0x2b1516(%rip), %rax    # 0x30d3cc
movl $0x1, (%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc5520(%rip), %rdi     # 0x1213ee
jmp 0x5bed7
leaq 0xc54ef(%rip), %rdi     # 0x1213c6
callq 0x5ee9b
movl $0x6, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x6a4ce