// File: /workspace/github_cpp_makefile_star2_O2/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 0x1c220a(%rip), %rax    # 0x228f3e
leaq 0x2ba2df(%rip), %rcx    # 0x32101a
movb (%rcx), %cl
orb (%rax), %cl
jne 0x66dcc
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edi, %ebx
leaq 0x19bb74(%rip), %rax    # 0x2028d0
movq (%rax), %rax
cmpq $0x1, %rax
je 0x66ef1
cmpq $0x4, %rax
je 0x66dcd
cmpq $0x80, %rax
je 0x66e3a
cmpq $0x800, %rax            # imm = 0x800
je 0x66ddb
movl $0x80000000, %ecx       # imm = 0x80000000
cmpq %rcx, %rax
jne 0x67092
movups 0xa4ad4(%rip), %xmm0    # 0x10b86c
leaq 0x2bf481(%rip), %r14    # 0x326220
movaps %xmm0, (%r14)
movw $0x4f, 0x10(%r14)
movq %r14, %rdi
callq 0x9120
addq %r14, %rax
testb $0x1, %bl
jne 0x66fa3
movb $0x0, 0x2(%rax)
movw $0x302c, (%rax)         # imm = 0x302C
jmp 0x66fac
retq
movl %ebx, %edi
xorl %esi, %esi
callq 0x66b7b
jmp 0x67092
pushq $0xd
popq %rdi
callq 0x5707f
pushq $0x2
popq %r14
movl %r14d, %edi
callq 0x523f2
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 0x523f2
callq 0x57171
jmp 0x67092
pushq $0x64
popq %rdi
pushq $0x5
popq %r15
movl %r15d, %esi
callq 0x582b6
pushq $0x19
popq %rdi
callq 0x523f2
movl %ebx, %edi
andl $0xf, %edi
callq 0x52599
pushq $0x1
popq %r14
movl %r14d, %edi
callq 0x58354
pushq $0x62
popq %r12
movl %r12d, %edi
movl %r15d, %esi
callq 0x582b6
pushq $0x3
popq %rdi
callq 0x523f2
movl %ebx, %edi
shrl $0xe, %edi
andl $0x1, %edi
callq 0x523f2
movl %r14d, %edi
callq 0x523f2
movl %r14d, %edi
callq 0x58354
pushq $0x9
popq %rsi
movl %r12d, %edi
callq 0x582b6
movl %r14d, %edi
callq 0x523f2
shrl $0xf, %ebx
andl $0x1, %ebx
movl %ebx, %edi
callq 0x523f2
pushq $0x2
popq %rbx
movl %ebx, %edi
callq 0x523f2
pushq $0x8
popq %rdi
callq 0x523f2
movl %r14d, %edi
callq 0x523f2
movl %ebx, %edi
callq 0x523f2
pushq $0xf
popq %rdi
callq 0x523f2
movl %r14d, %edi
callq 0x58354
jmp 0x67092
leaq 0x1c2035(%rip), %rax    # 0x228f2d
cmpb $0x0, (%rax)
jne 0x66f2d
leaq 0x19ba00(%rip), %rax    # 0x202904
cmpb $0x4, (%rax)
je 0x66f2d
leaq 0x19e0c4(%rip), %rax    # 0x204fd4
movl (%rax), %ecx
movl %ecx, %edx
xorl $0x41, %edx
leaq 0x19b9da(%rip), %rax    # 0x2028f8
movl (%rax), %eax
movl %eax, %esi
xorl $0x47, %esi
orl %edx, %esi
jne 0x6701b
leaq 0xf3d40(%rip), %r14     # 0x15ac74
movl (%r14), %r15d
leaq 0xf3d3a(%rip), %r12     # 0x15ac78
movl (%r12), %r13d
movl $0x29a, (%r12)          # imm = 0x29A
movl %ebx, (%r14)
movss 0x90193(%rip), %xmm0    # 0xf70e8
movl $0xff, %edi
movl $0xff, %esi
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
movaps %xmm0, %xmm3
movl $0xff, %edx
callq 0x55b65
movl $0x1f4, %edi            # imm = 0x1F4
callq 0xae83
movl (%r14), %eax
xorl %ecx, %ecx
testb $0x2, %al
setne %cl
testb $0x1, %al
leal 0x3(%rcx,%rcx,4), %eax
pushq $0x3
popq %rdi
cmovel %eax, %edi
callq 0x546d8
movl %r15d, (%r14)
movl %r13d, (%r12)
jmp 0x67092
movb $0x0, 0x2(%rax)
movw $0x322c, (%rax)         # imm = 0x322C
movq %r14, %rdi
callq 0x9120
addq %r14, %rax
testb $0x2, %bl
jne 0x66fc7
movb $0x0, 0x2(%rax)
movw $0x302c, (%rax)         # imm = 0x302C
jmp 0x66fd0
movb $0x0, 0x2(%rax)
movw $0x322c, (%rax)         # imm = 0x322C
testb $0x4, %bl
jne 0x66fec
movq %r14, %rdi
callq 0x9120
movw $0x302c, (%r14,%rax)    # imm = 0x302C
movb $0x0, 0x2(%r14,%rax)
jmp 0x6703d
leaq 0x290dad(%rip), %rax    # 0x2f7da0
movl (%rax), %r15d
movq %r14, %rdi
callq 0x9120
addq %r14, %rax
cmpl $0x2220, %r15d          # imm = 0x2220
je 0x67010
cmpl $0x57, %r15d
jne 0x67034
movb $0x0, 0x2(%rax)
movw $0x302c, (%rax)         # imm = 0x302C
jmp 0x6703d
cmpl $0x41, %ecx
jne 0x67092
cmpl $0x47, %eax
je 0x66f2d
cmpl $0x33, %eax
je 0x66f2d
jmp 0x67092
movb $0x0, 0x2(%rax)
movw $0x322c, (%rax)         # imm = 0x322C
movq %r14, %rdi
callq 0x9120
addq %r14, %rax
btl $0xe, %ebx
jb 0x67059
movb $0x0, 0x2(%rax)
movw $0x302c, (%rax)         # imm = 0x302C
jmp 0x67062
movb $0x0, 0x2(%rax)
movw $0x322c, (%rax)         # imm = 0x322C
movq %r14, %rdi
callq 0x9120
addq %r14, %rax
testw %bx, %bx
js 0x6707d
movb $0x0, 0x2(%rax)
movw $0x302c, (%rax)         # imm = 0x302C
jmp 0x67086
movb $0x0, 0x2(%rax)
movw $0x322c, (%rax)         # imm = 0x322C
leaq 0x2bf193(%rip), %rdi    # 0x326220
callq 0x57791
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6147d