// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heathgps.cpp
// Function: exclude_sat(int)
void exclude_sat(int prn)
{
u32 val;
int i;
u32 old_gps;
u32 old_glonass;
u32 old_qzss;
u32 old_sbas;
u32 old_galileo;

   if(read_only) return;
   if(luxor) return;

   if(rcvr_type == ESIP_RCVR) {  
      old_gps = esip_deleted_gps;
      old_glonass = esip_deleted_glonass;  
      old_qzss = esip_deleted_qzss;  
      old_sbas = esip_deleted_sbas;  
      old_galileo = esip_deleted_galileo;  

      if(prn <= 0) {  // restore all sats
         esip_deleted_gps = 0;
         esip_deleted_glonass = 0;  
         esip_deleted_qzss = 0;  
         esip_deleted_sbas = 0;  
         esip_deleted_galileo = 0;  
      }
      else if((prn >= 1) && (prn <= 32)) {  // delete gps sat
         esip_deleted_gps |= (1U << (prn-1));
      }
      else if((prn >= 65) && (prn <= 92)) {  // delete glonass sat
         esip_deleted_glonass |= (1U << (prn-65));
      }
      else if((prn >= 93) && (prn <= 99)) {  // delete qzss sat
         esip_deleted_qzss |= (1U << (prn-93));
      }
      else if((prn >= 33) && (prn <= 51)) {  // delete sbas sat
         esip_deleted_sbas |= (1U << (prn-33));
      }
      else if(0 && (prn >= 211) && (prn <= 230)) {  // delete galileo sat !!!!!! what are galileo PRN's?
         esip_deleted_galileo |= (1U << (prn-211));
      }

      set_amu_mask(amu_mask);     // this will set the sat disable flags

      esip_deleted_gps = old_gps;
      esip_deleted_glonass = old_glonass;  
      esip_deleted_qzss = old_qzss;  
      esip_deleted_sbas = old_sbas;  
      esip_deleted_galileo = old_galileo;  

      request_rcvr_config(8799);
   }
   else if(rcvr_type == FURUNO_RCVR) {
      if((prn >= 120) && (prn < 120+32)) {  // !!!! handle disabling multiple sats
         i = (prn - 120);
         val = (1 << i);
         val |= excluded_sbas;
         sprintf(out,"GPmge,%05X", val);
         send_furuno_cmd(out);
      }
      else if(prn < 32) {
         if(prn) {
            val = 1 << (prn-1);   // val is bitmap of sats to exclude
            val = (~val);         // now it's bitmap of sats to include
            val &= sats_enabled;
         }
         else {  // enable all SBAS sats
            send_furuno_cmd("GPmge,00000");
            val = 0xFFFFFFFF;
         }

         val ^= 0xFFFFFFFF;
         sprintf(out, "GPset,U%08X", val);
         send_furuno_cmd(out);
      }

      reset_sat_tracking();
      send_furuno_cmd("GPsrq");
      send_furuno_cmd("GPmgq");
   }
   else if(rcvr_type == MOTO_RCVR) {
      if(prn > 32) return;
      send_moto_start("Am");
      send_byte(0);
      if(prn) {
         val = 1 << (prn-1);     // val = bitmask of sats to exclude
         val |= (~sats_enabled);
      }
      else {
         val = 0;
      }
      send_dword(val);
      send_moto_end();

      reset_sat_tracking();
      request_sat_health();
   }
   else if(rcvr_type == NVS_RCVR) {
      if(prn) {  // exclude sat
         send_nvs_start(0x12);
         if(prn >= NVS_GLONASS_PRN) {
            send_byte(0x02);  // GLONASS
            send_byte(prn-NVS_GLONASS_PRN);
         }
         else {
            send_byte(0x01);  // GPS
            send_byte((u08) prn);
         }
         send_byte(0x02);  // disable
         send_nvs_end();
      }
      else {  // enable all excluded sats
         for(i=1; i<=32; i++) {  // GPS sats
            if(sat[i].disabled) {
               send_nvs_start(0x12);
               send_byte(0x01);  // GPS
               send_byte(i);
               send_byte(0x01);  // enable
               send_nvs_end();
            }
         }
         for(i=NVS_GLONASS_PRN+1; i<=NVS_GLONASS_PRN+24; i++) { // GLONASS sats
            if(sat[i].disabled) {
               send_nvs_start(0x12);
               send_byte(0x02);  // GLONASS
               send_byte(i-NVS_GLONASS_PRN);
               send_byte(0x01);  // enable
               send_nvs_end();
            }
         }
      }
   }
   else if(rcvr_type == SCPI_RCVR) {
      if(prn > 32) return;
      if(prn) {
         if(scpi_type == NORTEL_TYPE) sprintf(out, "GPS:SAT:TRAC:IGNORE %d", prn);
         else                         sprintf(out, ":GPS:SAT:TRAC:IGN %d", prn);
         queue_scpi_cmd(out, SCPI_IGNORE_MSG);
      }
      else if(scpi_type == NORTEL_TYPE) {
         queue_scpi_cmd("GPS:SAT:TRAC:INCLUDE 1,2,3,4,5,6,7,8,9,10,11,12,13", SCPI_INCLUDE_MSG);
         queue_scpi_cmd("GPS:SAT:TRAC:INCLUDE 14,15,16,17,18,19,20,21,22,23", SCPI_INCLUDE_MSG);
         queue_scpi_cmd("GPS:SAT:TRAC:INCLUDE 24,25,26,27,28,29,30,31,32", SCPI_INCLUDE_MSG);
         queue_scpi_cmd("SYNC:IMMEDIATE", SCPI_JAMSYNC_MSG);
      }
      else {
         queue_scpi_cmd(":GPS:SAT:TRAC:IGN:NONE", SCPI_IGNORE_MSG);
         queue_scpi_cmd(":GPS:SAT:TRAC:INCL:ALL", SCPI_INCLUDE_MSG);
         queue_scpi_cmd(":SYNC:HOLD:REC:INIT", SCPI_HOLDOVER_MSG);
      }

      if(scpi_type == NORTEL_TYPE) {
         queue_scpi_cmd("GPS:SAT:TRAC:IGNORE?", SCPI_IGNORE_MSG);
         queue_scpi_cmd("GPS:SAT:TRAC:INCLUDE?", SCPI_INCLUDE_MSG);
      }
      else queue_scpi_cmd(":GPS:SAT:TRAC:IGN?", SCPI_IGNORE_MSG);
   }
   else if(rcvr_type == SS_RCVR) {
      old_gps = ss_deleted_gps;
      old_sbas = ss_deleted_sbas;  

      if(prn <= 0) {  // restore all sats
         ss_deleted_gps = 0;
         ss_deleted_sbas = 0;  
      }
      else if((prn >= 1) && (prn <= 32)) {  // delete gps sat
         ss_deleted_gps |= (1U << (prn-1));
         send_ss_start(90, 16);
         send_ss_string("UGPS-000");
         send_byte((ss_deleted_gps >> 0) & 0xFF);
         send_byte((ss_deleted_gps >> 8) & 0xFF);
         send_byte((ss_deleted_gps >> 16) & 0xFF);
         send_byte((ss_deleted_gps >> 24) & 0xFF);
         send_ss_end();
      }
      else if(0 && (prn >= 120) && (prn <= 138)) {  // !!!!! this needs work - delete sbas sat
         ss_deleted_sbas |= (1U << (prn-33));
         send_ss_start(90, 16);
         send_ss_string("UGPS-0G5");
         send_byte((ss_deleted_gps >> 0) & 0xFF);
         send_byte((ss_deleted_gps >> 8) & 0xFF);
         send_byte((ss_deleted_gps >> 16) & 0xFF);
         send_byte((ss_deleted_gps >> 24) & 0xFF);
         send_ss_end();
      }

      ss_deleted_gps = old_gps;
      ss_deleted_sbas = old_sbas;  
      request_rcvr_config(8799);
   }
   else if(rcvr_type == UCCM_RCVR) {
      if(prn > 32) return;
      if(prn) {
         queue_uccm_cmd("GPS:SAT:TRAC:INCL:ALL", SCPI_INCLUDE_MSG);
         sprintf(out, "GPS:SAT:TRAC:IGN %d", prn);
         queue_uccm_cmd(out, SCPI_IGNORE_MSG);
      }
      else {
         queue_uccm_cmd("GPS:SAT:TRAC:INCL:ALL", SCPI_INCLUDE_MSG);
// uuuu  queue_uccm_cmd("SYNC:HOLD:REC:INIT", SCPI_HOLDOVER_MSG);
      }
      queue_uccm_cmd("GPS:SAT:TRAC:IGN?", SCPI_IGNORE_MSG);
   }
   else if(rcvr_type == TSIP_RCVR) {
      if(prn) set_health_config(2, prn);
      else    set_health_config(1, 0);
      request_sat_health();  // request enable/disable and health status of all sats
   }
   else if(rcvr_type == ZODIAC_RCVR) {
      if(prn > 32) return;
      if(prn) {
         val = 1 << (prn-1);   // val is bitmap of sats to exclude
         val = (~val);         // now it's bitmap of sats to include
         val &= sats_enabled;
      }
      else {
         val = 0xFFFFFFFF;
      }

      set_zod_sat_mask(val);
   }
   else if(rcvr_type == ZYFER_RCVR) {
      if(prn > 32) return;
      if(prn) {
         sprintf(out, "$SSLT,%d,1", prn);
         send_zyfer_cmd(out);
      }
      else {
         for(prn=1; prn<=32; prn++) {
            send_zyfer_cmd("$SSLT,%d,0");
         }
      }
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0x2c0abc(%rip), %rax    # 0x32101a
leaq 0x1c89d9(%rip), %rcx    # 0x228f3e
movb (%rcx), %cl
orb (%rax), %cl
jne 0x60837
movl %edi, %ebx
leaq 0x1a2358(%rip), %rax    # 0x2028d0
movq (%rax), %rax
cmpq $0x1, %rax
je 0x60820
cmpq $0x8, %rax
je 0x6069b
cmpq $0x10, %rax
je 0x60832
cmpq $0x20, %rax
je 0x6078a
cmpq $0x100, %rax            # imm = 0x100
je 0x60800
cmpq $0x800, %rax            # imm = 0x800
je 0x607d7
cmpq $0x100000, %rax         # imm = 0x100000
je 0x60657
cmpq $0x20000000, %rax       # imm = 0x20000000
je 0x6075f
movabsq $0x800000000, %rcx      # imm = 0x800000000
cmpq %rcx, %rax
je 0x606e8
movl $0x80000000, %ecx       # imm = 0x80000000
cmpq %rcx, %rax
jne 0x60837
leaq 0x29778d(%rip), %rdx    # 0x2f7d88
movl (%rdx), %r8d
leaq 0x297787(%rip), %r12    # 0x2f7d8c
movl (%r12), %ecx
leaq 0x297784(%rip), %r13    # 0x2f7d94
movl (%r13), %r9d
leaq 0x29777d(%rip), %r10    # 0x2f7d98
movl (%r10), %r15d
leaq 0x29776b(%rip), %rax    # 0x2f7d90
movl (%rax), %r14d
testl %ebx, %ebx
movl %ecx, -0x38(%rbp)
movl %r9d, -0x34(%rbp)
movl %r8d, -0x30(%rbp)
movl %r14d, -0x2c(%rbp)
jle 0x608b1
cmpl $0x20, %ebx
ja 0x60996
decb %bl
movl %r8d, %eax
btsl %ebx, %eax
movl %eax, (%rdx)
jmp 0x60a68
cmpl $0x20, %ebx
jg 0x60837
testl %ebx, %ebx
je 0x609d9
leaq 0x2c5bb1(%rip), %r14    # 0x326220
leaq 0xaa642(%rip), %rsi     # 0x10acb8
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x9060
incq %r14
movq %r14, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x579af
cmpl $0x20, %ebx
jg 0x60837
leaq 0xaa575(%rip), %rdi     # 0x10ac20
pushq $0x20
popq %rsi
callq 0x576d4
testl %ebx, %ebx
je 0x606dc
leaq 0x2c5b62(%rip), %r14    # 0x326220
leaq 0xaa5b4(%rip), %rsi     # 0x10ac79
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x9060
pushq $0x1e
popq %rsi
movq %r14, %rdi
callq 0x576d4
leaq 0xaa4e7(%rip), %rdi     # 0x10abca
jmp 0x60b84
leaq 0x2976c1(%rip), %r14    # 0x2f7db0
movl (%r14), %r15d
leaq 0x2976bb(%rip), %r12    # 0x2f7db4
movl (%r12), %r13d
leal -0x1(%rbx), %eax
cmpl $0x1f, %eax
ja 0x60753
decb %bl
movl %r15d, %eax
btsl %ebx, %eax
movl %eax, (%r14)
pushq $0x5a
popq %rdi
pushq $0x10
popq %rsi
callq 0x5d27d
leaq 0xaa070(%rip), %rdi     # 0x10a792
callq 0x5d2c0
movzbl (%r14), %edi
callq 0x523f2
movzbl 0x1(%r14), %edi
callq 0x523f2
movzbl 0x2(%r14), %edi
callq 0x523f2
movzbl 0x3(%r14), %edi
callq 0x523f2
callq 0x5d2f6
movl %r15d, (%r14)
movl %r13d, (%r12)
jmp 0x60abe
leal -0x78(%rbx), %eax
cmpl $0x1f, %eax
ja 0x60846
leaq 0x296976(%rip), %rcx    # 0x2f70e8
movl (%rcx), %edx
btsl %eax, %edx
leaq 0x2c5aa2(%rip), %rdi    # 0x326220
leaq 0xaa4c5(%rip), %rsi     # 0x10ac4a
jmp 0x60af2
cmpl $0x20, %ebx
jg 0x60837
leaq 0xaa341(%rip), %rdi     # 0x10aadb
callq 0x59a28
xorl %r14d, %r14d
xorl %edi, %edi
callq 0x523f2
testl %ebx, %ebx
je 0x607c0
decb %bl
leaq 0x29692e(%rip), %rax    # 0x2f70e4
movl (%rax), %r14d
notl %r14d
btsl %ebx, %r14d
movl %r14d, %edi
callq 0x525e2
callq 0x59aab
callq 0x56b1c
jmp 0x60983
testl %ebx, %ebx
je 0x608ca
pushq $0x12
popq %rdi
callq 0x5707f
cmpl $0x40, %ebx
jl 0x609ae
pushq $0x2
popq %rdi
callq 0x523f2
addb $-0x40, %bl
jmp 0x609b6
cmpl $0x20, %ebx
jg 0x60837
testl %ebx, %ebx
je 0x609f8
decb %bl
leaq 0x2968ce(%rip), %rax    # 0x2f70e4
movl (%rax), %edi
btrl %ebx, %edi
jmp 0x609fb
testl %ebx, %ebx
je 0x60979
pushq $0x2
popq %rdi
movl %ebx, %esi
jmp 0x6097e
cmpl $0x20, %ebx
jle 0x6086c
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x1f, %ebx
jg 0x60b05
testl %ebx, %ebx
je 0x60ad6
decb %bl
leaq 0x296884(%rip), %rax    # 0x2f70e4
movl (%rax), %edx
notl %edx
btsl %ebx, %edx
jmp 0x60ae4
leaq 0x1a476d(%rip), %r15    # 0x204fe0
movl (%r15), %eax
testl %ebx, %ebx
je 0x60a0e
cmpl $0x4e, %eax
leaq 0xaa3d9(%rip), %rax     # 0x10ac61
leaq 0xaa3e9(%rip), %rsi     # 0x10ac78
cmoveq %rax, %rsi
leaq 0x2c5986(%rip), %r14    # 0x326220
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x9060
pushq $0x1e
popq %rsi
movq %r14, %rdi
jmp 0x60b58
andl $0x0, (%rdx)
andl $0x0, (%r12)
andl $0x0, (%r13)
andl $0x0, (%r10)
andl $0x0, (%rax)
jmp 0x60a68
movb $0x1, %r15b
movl $0x349, %r13d           # imm = 0x349
leaq 0x1c86d6(%rip), %r12    # 0x228fb0
pushq $0x12
popq %rbx
pushq $0x1
popq %r14
cmpq $0x6c49, %r13           # imm = 0x6C49
je 0x60922
cmpb $0x0, (%r12,%r13)
je 0x60916
movl %ebx, %edi
callq 0x5707f
movl %r14d, %edi
callq 0x523f2
movzbl %r15b, %edi
callq 0x523f2
movl %r14d, %edi
callq 0x523f2
callq 0x57171
incb %r15b
addq $0x348, %r13            # imm = 0x348
jmp 0x608e1
movb $0x1, %r13b
xorl %ebx, %ebx
pushq $0x2
popq %r14
pushq $0x1
popq %r15
cmpq $0x4ec0, %rbx           # imm = 0x4EC0
je 0x60837
cmpb $0x0, 0xd549(%r12,%rbx)
je 0x6096d
pushq $0x12
popq %rdi
callq 0x5707f
movl %r14d, %edi
callq 0x523f2
movzbl %r13b, %edi
callq 0x523f2
movl %r15d, %edi
callq 0x523f2
callq 0x57171
incb %r13b
addq $0x348, %rbx            # imm = 0x348
jmp 0x6092f
pushq $0x1
popq %rdi
xorl %esi, %esi
callq 0x5fdea
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5fe46
leal -0x41(%rbx), %eax
cmpl $0x1b, %eax
ja 0x60a52
btsl %eax, %ecx
movl %ecx, (%r12)
jmp 0x60a68
pushq $0x1
popq %rdi
callq 0x523f2
movzbl %bl, %edi
callq 0x523f2
pushq $0x2
popq %rdi
callq 0x523f2
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x57171
pushq $0x20
popq %r14
leaq 0xaa2e0(%rip), %rbx     # 0x10acc4
subl $0x1, %r14d
jb 0x60837
movq %rbx, %rdi
callq 0x579af
jmp 0x609e4
pushq $-0x1
popq %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x60bb7
cmpl $0x4e, %eax
jne 0x60b30
leaq 0xaa106(%rip), %rdi     # 0x10ab24
pushq $0x20
popq %rbx
movl %ebx, %esi
callq 0x576d4
leaq 0xaa128(%rip), %rdi     # 0x10ab57
movl %ebx, %esi
callq 0x576d4
leaq 0xaa14d(%rip), %rdi     # 0x10ab8a
movl %ebx, %esi
callq 0x576d4
leaq 0xaa16f(%rip), %rdi     # 0x10abba
pushq $0x21
jmp 0x60b57
leal -0x5d(%rbx), %eax
cmpl $0x6, %eax
ja 0x60b9a
movl %r9d, %ecx
btsl %eax, %ecx
movl %ecx, (%r13)
movq %rdx, %r14
leaq 0x296646(%rip), %rax    # 0x2f70b8
movss (%rax), %xmm1
movss 0x9666a(%rip), %xmm0    # 0xf70e8
movl $0xff, %edi
movl $0xff, %esi
movaps %xmm0, %xmm2
movaps %xmm0, %xmm3
movl $0xff, %edx
movq %r10, %rbx
callq 0x55b65
movl -0x30(%rbp), %eax
movl %eax, (%r14)
movl -0x38(%rbp), %eax
movl %eax, (%r12)
movl -0x34(%rbp), %eax
movl %eax, (%r13)
movl %r15d, (%rbx)
leaq 0x2972d7(%rip), %rax    # 0x2f7d90
movl -0x2c(%rbp), %ecx
movl %ecx, (%rax)
movl $0x225f, %edi           # imm = 0x225F
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5e18e
leaq 0xaa178(%rip), %rdi     # 0x10ac55
callq 0x578d5
xorl %edx, %edx
leaq 0x2c5735(%rip), %rdi    # 0x326220
leaq 0xa9ff8(%rip), %rsi     # 0x10aaea
xorl %eax, %eax
callq 0x9060
leaq 0x2c5720(%rip), %rdi    # 0x326220
callq 0x578d5
callq 0x56b1c
leaq 0xa9f08(%rip), %rdi     # 0x10aa19
callq 0x578d5
leaq 0xa9d8f(%rip), %rdi     # 0x10a8ac
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x578d5
leaq 0xaa0d1(%rip), %rdi     # 0x10ac08
pushq $0x1e
popq %rsi
callq 0x576d4
leaq 0xaa0d9(%rip), %rdi     # 0x10ac1f
pushq $0x20
popq %rsi
callq 0x576d4
leaq 0xaa0e1(%rip), %rdi     # 0x10ac36
pushq $0x16
popq %rsi
callq 0x576d4
cmpl $0x4e, (%r15)
jne 0x60b7d
leaq 0xaa123(%rip), %rdi     # 0x10ac8d
pushq $0x1e
popq %rsi
callq 0x576d4
leaq 0xaa129(%rip), %rdi     # 0x10aca2
pushq $0x20
jmp 0x60b86
leaq 0xaa045(%rip), %rdi     # 0x10abc9
pushq $0x1e
popq %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x576d4
cmpl $0x33, %ebx
movq %rdx, %r14
ja 0x60a6b
addb $-0x21, %bl
movl %r15d, %eax
btsl %ebx, %eax
movl %eax, (%r10)
jmp 0x60a6b