// File: /workspace/github_cpp_makefile_star2_O2/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 0x2cc931(%rip), %rax    # 0x32101a
cmpb $0x0, (%rax)
jne 0x54a2c
movl %edi, %ebx
leaq 0x1ae1d5(%rip), %rax    # 0x2028d0
movq (%rax), %rax
cmpq $0x1, %rax
je 0x5494a
cmpq $0x2, %rax
je 0x549f2
cmpq $0x10, %rax
je 0x549e2
cmpq $0x20, %rax
je 0x549ba
cmpq $0x40, %rax
je 0x549f2
cmpq $0x400, %rax            # imm = 0x400
je 0x549f2
cmpq $0x800, %rax            # imm = 0x800
je 0x548e9
cmpq $0x1000, %rax           # imm = 0x1000
je 0x549f2
cmpq $0x2000, %rax           # imm = 0x2000
je 0x549f2
cmpq $0x4000, %rax           # imm = 0x4000
je 0x549f2
cmpq $0x20000, %rax          # imm = 0x20000
je 0x549f2
cmpq $0x40000, %rax          # imm = 0x40000
je 0x549f2
cmpq $0x400000, %rax         # imm = 0x400000
je 0x549f2
cmpq $0x1000000, %rax        # imm = 0x1000000
je 0x549f2
cmpq $0x8000000, %rax        # imm = 0x8000000
je 0x549f2
cmpq $0x10000000, %rax       # imm = 0x10000000
je 0x549f2
cmpq $0x20000000, %rax       # imm = 0x20000000
je 0x549f2
movl $0x80000000, %ecx       # imm = 0x80000000
cmpq %rcx, %rax
je 0x548be
movabsq $0x200000000, %rcx      # imm = 0x200000000
cmpq %rcx, %rax
je 0x549f2
movabsq $0x800000000, %rcx      # imm = 0x800000000
cmpq %rcx, %rax
je 0x549f2
movabsq $0x1000000000, %rcx     # imm = 0x1000000000
cmpq %rcx, %rax
je 0x549f2
leaq 0x1b07c6(%rip), %rcx    # 0x204fd4
movl (%rcx), %edx
cmpl $0x41, %edx
sete %sil
xorl %ecx, %ecx
cmpl $0x50, %edx
sete %dil
testb %cl, %cl
je 0x5482d
orb %dil, %sil
jne 0x5496d
cmpq $0x8000, %rax           # imm = 0x8000
je 0x549f2
cmpq $0x10000, %rax          # imm = 0x10000
je 0x549f2
cmpq $0x80000, %rax          # imm = 0x80000
je 0x549f2
cmpq $0x200000, %rax         # imm = 0x200000
je 0x549f2
cmpq $0x800000, %rax         # imm = 0x800000
je 0x549f2
cmpq $0x40000000, %rax       # imm = 0x40000000
je 0x549f2
movabsq $0x400000000, %rsi      # imm = 0x400000000
cmpq %rsi, %rax
je 0x549f2
cmpl $0x53, %edx
sete %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x54b17
movl $0x8e, %edi
callq 0x5707f
movl $0xa2, %edi
callq 0x523f2
xorl %edi, %edi
callq 0x523f2
callq 0x570f8
jmp 0x549f2
testb %bl, %bl
je 0x54ac5
movzbl %bl, %eax
cmpl $0x80, %eax
je 0x54abc
cmpl $0x3, %eax
jne 0x54ad1
leaq 0xb6a3e(%rip), %rdi     # 0x10b322
jmp 0x54acc
leaq 0x2a2bb4(%rip), %r14    # 0x2f74a4
movl (%r14), %r15d
xorl %eax, %eax
testb %bl, %bl
setne %al
movl %r15d, %ecx
andl $-0x2, %ecx
orl %ecx, %eax
movl %eax, (%r14)
leaq 0x2a3415(%rip), %rax    # 0x2f7d21
movzbl (%rax), %edi
leaq 0x2a3402(%rip), %rax    # 0x2f7d18
movzbl (%rax), %esi
leaq 0x2a34a0(%rip), %rax    # 0x2f7dc0
movsd (%rax), %xmm0
leaq 0x2a34ad(%rip), %rax    # 0x2f7dd8
movsd (%rax), %xmm1
leaq 0x2a33e6(%rip), %rax    # 0x2f7d1c
movss (%rax), %xmm2
pushq $0x2c
popq %rdx
callq 0x61e97
movl %r15d, (%r14)
jmp 0x54a2c
leaq 0x1b0683(%rip), %rcx    # 0x204fd4
movl (%rcx), %edx
leal -0x33(%rdx), %ecx
cmpl $0x1d, %ecx
ja 0x54ae3
movl $0x20004009, %esi       # imm = 0x20004009
btl %ecx, %esi
jae 0x54ae3
leaq 0x1adf84(%rip), %rax    # 0x2028f8
movl (%rax), %edi
cmpl $0x41, %edx
sete %cl
cmpl $0x47, %edi
sete %al
testb %al, %cl
je 0x54a37
movl $0x8e, %edi
callq 0x5707f
movl $0xa2, %edi
callq 0x523f2
movzbl %bl, %edi
callq 0x523f2
callq 0x570f8
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x63fdb
leaq 0xb6941(%rip), %rdi     # 0x10b302
callq 0x59a28
xorl %edi, %edi
testb %bl, %bl
setne %dil
callq 0x523f2
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x59aab
leaq 0x1b05f7(%rip), %rax    # 0x204fe0
cmpl $0x4e, (%rax)
jne 0x54a82
leaq 0x2a2aab(%rip), %rax    # 0x2f74a4
movl (%rax), %ecx
testb %bl, %bl
je 0x54a10
orl $0x1, %ecx
movl %ecx, (%rax)
leaq 0x2a2ab2(%rip), %rax    # 0x2f74bd
movb $0x3, (%rax)
jmp 0x54a1f
andl $-0x2, %ecx
movl %ecx, (%rax)
leaq 0x2a2aa1(%rip), %rax    # 0x2f74bd
movb $0x0, (%rax)
leaq 0x2a29a6(%rip), %rax    # 0x2f73cc
movl $0x1, (%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
testb %cl, %cl
je 0x54a4d
cmpl $0x33, %edi
je 0x5498a
cmpl $0x47, %edi
je 0x5498a
leaq 0x1adeb0(%rip), %rax    # 0x202904
cmpb $0x1, (%rax)
sete %al
orb $0x2, %al
cmpb $0x1, %bl
pushq $0x3
popq %rdx
sbbl $0x0, %edx
movzbl %al, %ecx
pushq $0x32
popq %rdi
pushq $0x2
popq %rsi
callq 0x5fc56
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x5fc1e
testb %bl, %bl
leaq 0xb68bf(%rip), %rax     # 0x10b34a
leaq 0xb68c8(%rip), %rdi     # 0x10b35a
cmoveq %rax, %rdi
pushq $0x17
popq %rsi
callq 0x576d4
leaq 0xb5beb(%rip), %rdi     # 0x10a690
pushq $0x19
popq %rsi
callq 0x576d4
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x5dcf3
leaq 0xb6873(%rip), %rdi     # 0x10b336
jmp 0x54acc
leaq 0xb6842(%rip), %rdi     # 0x10b30e
callq 0x57791
pushq $0x6
popq %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x6166c
movb $0x1, %cl
cmpl $0x41, %edx
sete %sil
jne 0x54819
leaq 0x1addff(%rip), %rcx    # 0x2028f8
movl (%rcx), %edi
movb $0x1, %cl
cmpl $0x33, %edi
je 0x5497c
cmpl $0x47, %edi
je 0x5497c
pushq $0x41
popq %rdx
jmp 0x54819
testb %cl, %cl
jne 0x5498a
cmpq $0x4, %rax
je 0x549f2
cmpq $0x8, %rax
je 0x549f2
cmpq $0x80, %rax
je 0x549f2
movabsq $0x100000000, %rcx      # imm = 0x100000000
cmpq %rcx, %rax
je 0x549f2
cmpq $0x100000, %rax         # imm = 0x100000
je 0x54bc5
cmpq $0x2000000, %rax        # imm = 0x2000000
je 0x549f2
cmpq $0x100, %rax            # imm = 0x100
jne 0x54a2c
xorl %eax, %eax
testb %bl, %bl
setne %al
leaq 0x2a2924(%rip), %rcx    # 0x2f74a4
movl (%rcx), %edx
andl $-0x2, %edx
orl %eax, %edx
leal (%rax,%rax,2), %eax
movl %edx, (%rcx)
leaq 0x2a292a(%rip), %rcx    # 0x2f74bd
movb %al, (%rcx)
leaq 0x2a2830(%rip), %rax    # 0x2f73cc
movl $0x1, (%rax)
leaq 0x1b051b(%rip), %rax    # 0x2050c4
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 0x5faee
testb %bl, %bl
je 0x54bd2
leaq 0xb67a7(%rip), %rdi     # 0x10b377
jmp 0x54bd9
leaq 0xb6792(%rip), %rdi     # 0x10b36b
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x579af