// File: /workspace/github_cpp_makefile_star2_O1/jkingan[P]ladyheather/heathgps.cpp
// Function: set_gnss_system(int)
void set_gnss_system(int system)
{
u08 val;
int old_gnss_mask;
int old_have_gnss;

   // set the GNSS system/systems to use
   if(luxor) return;
   if(read_only) return;
//sprintf(plot_title, "GNSS set rcvr:%04X gnss:%04X", rcvr_type, system);

   if(rcvr_type == ESIP_RCVR) {
      sprintf(out, "PERDAPI,GNSS,AUTO");
      if(system & GPS) strcat(out, ",2");
      else             strcat(out, ",0");
      if(system & GLONASS) strcat(out, ",2");
      else                 strcat(out, ",0");
      if(system & GALILEO) {
         if(furuno_type == 87)        strcat(out, ",0");
         else if(furuno_type == 8736) strcat(out, ",0");
         else                         strcat(out, ",2");
      }
      else                 strcat(out, ",0");
      if(system & QZSS) strcat(out, ",2");
      else              strcat(out, ",0");
      if(system & SBAS) strcat(out, ",2");
      else              strcat(out, ",0");
      send_esip_cmd(out);
   }
   else if(rcvr_type == NVS_RCVR) {
      system &= (~BEIDOU);
      send_nvs_start(0x0D);
      send_byte(0x02);
      val = 0;
      if((system & GPS) && (system & GLONASS)) val = 0;
      else if(system & GPS) val = 1;
      else if(system & GLONASS) val = 2;
      else if(system & GALILEO) val = 3;
      if(system & GALILEO) ;            // can't do SBAS
      else if(system & SBAS) val += 10; // include SBAS 
      send_byte(val);
      send_nvs_end();
   }
   else if(rcvr_type == UBX_RCVR) {
      set_ubx_gnss(system, 0);
   }
   else if(rcvr_type == VENUS_RCVR) {
      send_venus_start(SET_VENUS_GNSS);
      send_byte(0x19);
      send_word((u16) (system & (GPS | GLONASS | BEIDOU | GALILEO)));
      send_venus_save(1);

      send_venus_start(SET_VENUS_QZSS);
      send_byte(0x03);
      if(system & QZSS) send_byte(1);
      else              send_byte(0);
      send_byte(1);       // channels
      send_venus_save(1);

if(1) {
      send_venus_start(SET_VENUS_SBAS);
      send_byte(0x01);
      if(system & SBAS) send_byte(1);
      else              send_byte(0);
      send_byte(2);     // auto select mode
      send_byte(8);     // URA
      send_byte(1);     // apply corrections
      send_byte(2);     // channels
      send_byte(0x0F);  // WAAS + EGNOS + MSAS + GAGAN
      send_venus_save(1);
}
   }
   else if(rcvr_type == TSIP_RCVR) {
      if(saw_icm || (res_t == RES_T_360) || ACU_GG || ACU_360) {
         old_gnss_mask = gnss_mask;
         old_have_gnss = have_gnss_mask;
         have_gnss_mask = 666;
         gnss_mask = system;

         set_config(0xFF, 0xFF, -1.0F, -1.0F, -1.0F, -1.0F, 0xFF);
Sleep(500);
if(gnss_mask & GPS)          set_timing_mode(TMODE_UTC, 14);
else if(gnss_mask & GLONASS) set_timing_mode(TMODE_GLONASS, 15);
else                         set_timing_mode(TMODE_UTC, 16);

         gnss_mask = old_gnss_mask;
         have_gnss_mask = old_have_gnss;
      }
   }

   request_gnss_system();
}

// Assembly:
leaq 0x1ceb7e(%rip), %rax    # 0x23ef3e
leaq 0x2c6c53(%rip), %rcx    # 0x33701a
movb (%rcx), %cl
orb (%rax), %cl
jne 0x7044a
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edi, %ebx
leaq 0x1a84ec(%rip), %rax    # 0x2188d0
movq (%rax), %rax
cmpq $0x7f, %rax
jle 0x7044b
cmpq $0x80, %rax
je 0x7046d
cmpq $0x800, %rax            # imm = 0x800
je 0x7053b
movl $0x80000000, %ecx       # imm = 0x80000000
cmpq %rcx, %rax
jne 0x70743
movups 0xb142e(%rip), %xmm0    # 0x121844
leaq 0x2cbe03(%rip), %r14    # 0x33c220
movaps %xmm0, (%r14)
movw $0x4f, 0x10(%r14)
movq %r14, %rdi
callq 0x9120
addq %r14, %rax
testb $0x1, %bl
jne 0x70654
movb $0x0, 0x2(%rax)
movw $0x302c, (%rax)         # imm = 0x302C
jmp 0x7065d
retq
cmpq $0x1, %rax
je 0x705a0
cmpq $0x4, %rax
jne 0x70743
movl %ebx, %edi
xorl %esi, %esi
callq 0x7022a
jmp 0x70743
movl $0x64, %edi
movl $0x5, %esi
callq 0x5fbb4
movl $0x19, %edi
callq 0x591af
movl %ebx, %edi
andl $0xf, %edi
callq 0x5936c
movl $0x1, %edi
callq 0x5fc43
movl $0x62, %edi
movl $0x5, %esi
callq 0x5fbb4
movl $0x3, %edi
callq 0x591af
movl %ebx, %edi
shrl $0xe, %edi
andl $0x1, %edi
callq 0x591af
movl $0x1, %edi
callq 0x591af
movl $0x1, %edi
callq 0x5fc43
movl $0x62, %edi
movl $0x9, %esi
callq 0x5fbb4
movl $0x1, %edi
callq 0x591af
shrl $0xf, %ebx
andl $0x1, %ebx
movl %ebx, %edi
callq 0x591af
movl $0x2, %edi
callq 0x591af
movl $0x8, %edi
callq 0x591af
movl $0x1, %edi
callq 0x591af
movl $0x2, %edi
callq 0x591af
movl $0xf, %edi
callq 0x591af
movl $0x1, %edi
callq 0x5fc43
jmp 0x70743
movl $0xd, %edi
callq 0x5e740
movl $0x2, %r14d
movl $0x2, %edi
callq 0x591af
movl %ebx, %eax
andl $0x3, %eax
xorl %ecx, %ecx
cmpl $0x3, %eax
setne %cl
testb $0x1, %bl
cmovel %r14d, %ecx
xorl %edx, %edx
testb $0x4, %bl
setne %dl
testl %eax, %eax
leal (%rdx,%rdx,2), %eax
cmovnel %ecx, %eax
andl $0x8004, %ebx           # imm = 0x8004
leal 0xa(%rax), %ecx
cmpl $0x8000, %ebx           # imm = 0x8000
movzbl %cl, %ecx
cmovnel %eax, %ecx
movzbl %cl, %edi
callq 0x591af
callq 0x5e844
jmp 0x70743
leaq 0x1ce986(%rip), %rax    # 0x23ef2d
cmpb $0x0, (%rax)
jne 0x705dc
leaq 0x1a8351(%rip), %rax    # 0x218904
cmpb $0x4, (%rax)
je 0x705dc
leaq 0x1aaa15(%rip), %rax    # 0x21afd4
movl (%rax), %ecx
movl %ecx, %edx
xorl $0x41, %edx
leaq 0x1a832b(%rip), %rax    # 0x2188f8
movl (%rax), %eax
movl %eax, %esi
xorl $0x47, %esi
orl %edx, %esi
jne 0x706cc
leaq 0x100691(%rip), %r14    # 0x170c74
movl (%r14), %r15d
leaq 0x10068b(%rip), %r12    # 0x170c78
movl (%r12), %r13d
movl $0x29a, (%r12)          # imm = 0x29A
movl %ebx, (%r14)
movss 0x9c9cc(%rip), %xmm0    # 0x10cfd0
movl $0xff, %edi
movl $0xff, %esi
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
movaps %xmm0, %xmm3
movl $0xff, %edx
callq 0x5d081
movl $0x1f4, %edi            # imm = 0x1F4
callq 0xaff7
movl (%r14), %eax
xorl %ecx, %ecx
testb $0x2, %al
setne %cl
testb $0x1, %al
leal 0x3(%rcx,%rcx,4), %eax
movl $0x3, %edi
cmovel %eax, %edi
callq 0x5ba54
movl %r15d, (%r14)
movl %r13d, (%r12)
jmp 0x70743
movb $0x0, 0x2(%rax)
movw $0x322c, (%rax)         # imm = 0x322C
movq %r14, %rdi
callq 0x9120
addq %r14, %rax
testb $0x2, %bl
jne 0x70678
movb $0x0, 0x2(%rax)
movw $0x302c, (%rax)         # imm = 0x302C
jmp 0x70681
movb $0x0, 0x2(%rax)
movw $0x322c, (%rax)         # imm = 0x322C
testb $0x4, %bl
jne 0x7069d
movq %r14, %rdi
callq 0x9120
movw $0x302c, (%r14,%rax)    # imm = 0x302C
movb $0x0, 0x2(%r14,%rax)
jmp 0x706ee
leaq 0x29d6fc(%rip), %rax    # 0x30dda0
movl (%rax), %r15d
movq %r14, %rdi
callq 0x9120
addq %r14, %rax
cmpl $0x2220, %r15d          # imm = 0x2220
je 0x706c1
cmpl $0x57, %r15d
jne 0x706e5
movb $0x0, 0x2(%rax)
movw $0x302c, (%rax)         # imm = 0x302C
jmp 0x706ee
cmpl $0x41, %ecx
jne 0x70743
cmpl $0x47, %eax
je 0x705dc
cmpl $0x33, %eax
je 0x705dc
jmp 0x70743
movb $0x0, 0x2(%rax)
movw $0x322c, (%rax)         # imm = 0x322C
movq %r14, %rdi
callq 0x9120
addq %r14, %rax
btl $0xe, %ebx
jb 0x7070a
movb $0x0, 0x2(%rax)
movw $0x302c, (%rax)         # imm = 0x302C
jmp 0x70713
movb $0x0, 0x2(%rax)
movw $0x322c, (%rax)         # imm = 0x322C
movq %r14, %rdi
callq 0x9120
addq %r14, %rax
testw %bx, %bx
js 0x7072e
movb $0x0, 0x2(%rax)
movw $0x302c, (%rax)         # imm = 0x302C
jmp 0x70737
movb $0x0, 0x2(%rax)
movw $0x322c, (%rax)         # imm = 0x322C
leaq 0x2cbae2(%rip), %rdi    # 0x33c220
callq 0x5ef13
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6a0d8