// File: /workspace/github_cpp_makefile_star2_O3/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 0x2cde40(%rip), %rax    # 0x33701a
leaq 0x1d5d5d(%rip), %rcx    # 0x23ef3e
movb (%rcx), %cl
orb (%rax), %cl
jne 0x696af
movl %edi, %ebx
leaq 0x1af6dc(%rip), %rax    # 0x2188d0
movq (%rax), %rax
cmpq $0x7ff, %rax            # imm = 0x7FF
jg 0x6924d
cmpq $0xf, %rax
jle 0x692e9
cmpq $0x10, %rax
je 0x693e7
cmpq $0x20, %rax
je 0x69462
cmpq $0x100, %rax            # imm = 0x100
jne 0x696af
cmpl $0x20, %ebx
jg 0x696af
testl %ebx, %ebx
je 0x6970b
decb %bl
leaq 0x2a3ea1(%rip), %rax    # 0x30d0e4
movl (%rax), %edi
btrl %ebx, %edi
jmp 0x69710
cmpq $0x1fffffff, %rax       # imm = 0x1FFFFFFF
jle 0x6934e
cmpq $0x20000000, %rax       # imm = 0x20000000
je 0x69437
movabsq $0x800000000, %rcx      # imm = 0x800000000
cmpq %rcx, %rax
je 0x694cf
movl $0x80000000, %ecx       # imm = 0x80000000
cmpq %rcx, %rax
jne 0x696af
leaq 0x2a4afb(%rip), %rdx    # 0x30dd88
movl (%rdx), %r8d
leaq 0x2a4af5(%rip), %r12    # 0x30dd8c
movl (%r12), %ecx
leaq 0x2a4af2(%rip), %r13    # 0x30dd94
movl (%r13), %r9d
leaq 0x2a4aeb(%rip), %r10    # 0x30dd98
movl (%r10), %r11d
leaq 0x2a4ad9(%rip), %r14    # 0x30dd90
movl (%r14), %r15d
testl %ebx, %ebx
movl %ecx, -0x38(%rbp)
movl %r9d, -0x34(%rbp)
movl %r8d, -0x30(%rbp)
movl %r15d, -0x2c(%rbp)
jle 0x69637
cmpl $0x20, %ebx
ja 0x6967d
decb %bl
movl %r8d, %eax
btsl %ebx, %eax
movl %eax, (%rdx)
jmp 0x69739
cmpq $0x1, %rax
je 0x693a6
cmpq $0x8, %rax
jne 0x696af
cmpl $0x20, %ebx
jg 0x696af
leaq 0xb79cb(%rip), %rdi     # 0x120cd8
movl $0x20, %esi
callq 0x5edda
testl %ebx, %ebx
je 0x69342
leaq 0x2d2efe(%rip), %r14    # 0x33c220
leaq 0xb7a08(%rip), %rsi     # 0x120d31
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x9060
movq %r14, %rdi
movl $0x1e, %esi
callq 0x5edda
leaq 0xb7939(%rip), %rdi     # 0x120c82
jmp 0x69884
cmpq $0x800, %rax            # imm = 0x800
je 0x693ba
cmpq $0x100000, %rax         # imm = 0x100000
jne 0x696af
cmpl $0x20, %ebx
jg 0x696af
testl %ebx, %ebx
je 0x69695
leaq 0x2d2ea6(%rip), %r14    # 0x33c220
leaq 0xb79ef(%rip), %rsi     # 0x120d70
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 0x5f0e5
testl %ebx, %ebx
je 0x69570
movl $0x2, %edi
movl %ebx, %esi
jmp 0x69577
testl %ebx, %ebx
je 0x6958f
movl $0x12, %edi
callq 0x5e6be
cmpl $0x40, %ebx
jl 0x6964e
movl $0x2, %edi
callq 0x590f7
addb $-0x40, %bl
jmp 0x69658
cmpl $0x20, %ebx
jg 0x696af
leaq 0x1b1be9(%rip), %r15    # 0x21afe0
movl (%r15), %eax
testl %ebx, %ebx
je 0x696be
cmpl $0x4e, %eax
leaq 0xb790d(%rip), %rax     # 0x120d19
leaq 0xb791d(%rip), %rsi     # 0x120d30
cmoveq %rax, %rsi
leaq 0x2d2e02(%rip), %r14    # 0x33c220
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x9060
movq %r14, %rdi
movl $0x1e, %esi
jmp 0x69853
leal -0x78(%rbx), %eax
cmpl $0x1f, %eax
ja 0x6954a
leaq 0x2a3c9e(%rip), %rcx    # 0x30d0e8
movl (%rcx), %edx
btsl %eax, %edx
leaq 0x2d2dca(%rip), %rdi    # 0x33c220
leaq 0xb78a5(%rip), %rsi     # 0x120d02
jmp 0x697c6
cmpl $0x20, %ebx
jg 0x696af
leaq 0xb7721(%rip), %rdi     # 0x120b93
callq 0x6160d
xorl %r14d, %r14d
xorl %edi, %edi
callq 0x590f7
movl $0x0, %edi
testl %ebx, %ebx
je 0x6949a
decb %bl
leaq 0x2a3c51(%rip), %rax    # 0x30d0e4
movl (%rax), %edi
notl %edi
btsl %ebx, %edi
callq 0x592eb
callq 0x61688
movl $0x218, %eax            # imm = 0x218
leaq 0x1d5b00(%rip), %rcx    # 0x23efb0
movl %r14d, (%rcx,%rax)
movl %r14d, -0x1fc(%rcx,%rax)
addq $0x348, %rax            # imm = 0x348
cmpq $0xcd358, %rax          # imm = 0xCD358
jne 0x694b0
jmp 0x6957c
leaq 0x2a48da(%rip), %r14    # 0x30ddb0
movl (%r14), %r15d
leaq 0x2a48d4(%rip), %r12    # 0x30ddb4
movl (%r12), %r13d
leal -0x1(%rbx), %eax
cmpl $0x1f, %eax
ja 0x6953e
decb %bl
movl %r15d, %eax
btsl %ebx, %eax
movl %eax, (%r14)
movl $0x5a, %edi
movl $0x10, %esi
callq 0x65608
leaq 0xb733d(%rip), %rdi     # 0x12084a
callq 0x6564e
movzbl (%r14), %edi
callq 0x590f7
movzbl 0x1(%r14), %edi
callq 0x590f7
movzbl 0x2(%r14), %edi
callq 0x590f7
movzbl 0x3(%r14), %edi
callq 0x590f7
callq 0x65696
movl %r15d, (%r14)
movl %r13d, (%r12)
jmp 0x69792
cmpl $0x1f, %ebx
jg 0x697d9
testl %ebx, %ebx
je 0x697aa
decb %bl
leaq 0x2a3b80(%rip), %rax    # 0x30d0e4
movl (%rax), %edx
notl %edx
btsl %ebx, %edx
jmp 0x697b8
movl $0x1, %edi
xorl %esi, %esi
callq 0x68981
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x689df
movb $0x1, %r14b
movl $0x349, %r15d           # imm = 0x349
leaq 0x1d5a11(%rip), %rbx    # 0x23efb0
cmpb $0x0, (%rbx,%r15)
je 0x695d2
movl $0x12, %edi
callq 0x5e6be
movl $0x1, %edi
callq 0x590f7
movzbl %r14b, %edi
callq 0x590f7
movl $0x1, %edi
callq 0x590f7
callq 0x5e7c0
incb %r14b
addq $0x348, %r15            # imm = 0x348
cmpq $0x6c49, %r15           # imm = 0x6C49
jne 0x6959f
movb $0x1, %r14b
xorl %r15d, %r15d
cmpb $0x0, 0xd549(%rbx,%r15)
je 0x69622
movl $0x12, %edi
callq 0x5e6be
movl $0x2, %edi
callq 0x590f7
movzbl %r14b, %edi
callq 0x590f7
movl $0x1, %edi
callq 0x590f7
callq 0x5e7c0
incb %r14b
addq $0x348, %r15            # imm = 0x348
cmpq $0x4ec0, %r15           # imm = 0x4EC0
jne 0x695eb
jmp 0x696af
xorl %eax, %eax
movl %eax, (%rdx)
movl %eax, (%r12)
movl %eax, (%r13)
movl %eax, (%r10)
movl %eax, (%r14)
jmp 0x69739
movl $0x1, %edi
callq 0x590f7
movzbl %bl, %edi
callq 0x590f7
movl $0x2, %edi
callq 0x590f7
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5e7c0
leal -0x41(%rbx), %eax
cmpl $0x1b, %eax
ja 0x69723
btsl %eax, %ecx
movl %ecx, (%r12)
jmp 0x69739
movl $0x20, %r14d
leaq 0xb76da(%rip), %rbx     # 0x120d7c
movq %rbx, %rdi
callq 0x5f0e5
decl %r14d
jne 0x696a2
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x4e, %eax
jne 0x69825
leaq 0xb750e(%rip), %rdi     # 0x120bdc
movl $0x20, %esi
callq 0x5edda
leaq 0xb7530(%rip), %rdi     # 0x120c0f
movl $0x20, %esi
callq 0x5edda
leaq 0xb7552(%rip), %rdi     # 0x120c42
movl $0x20, %esi
callq 0x5edda
leaq 0xb7571(%rip), %rdi     # 0x120c72
movl $0x21, %esi
jmp 0x69853
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x698b9
leal -0x5d(%rbx), %eax
cmpl $0x6, %eax
ja 0x6989c
movl %r9d, %ecx
btsl %eax, %ecx
movl %ecx, (%r13)
movq %rdx, %r14
leaq 0x2a3975(%rip), %rax    # 0x30d0b8
movss (%rax), %xmm1
movss 0xa3919(%rip), %xmm0    # 0x10d068
movl $0xff, %edi
movl $0xff, %esi
movaps %xmm0, %xmm2
movaps %xmm0, %xmm3
movl $0xff, %edx
movq %r10, %rbx
movl %r11d, %r15d
callq 0x5cf59
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 0x2a4603(%rip), %rax    # 0x30dd90
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 0x667f2
leaq 0xb755c(%rip), %rdi     # 0x120d0d
callq 0x5eff8
xorl %edx, %edx
leaq 0x2d2a61(%rip), %rdi    # 0x33c220
leaq 0xb73dc(%rip), %rsi     # 0x120ba2
xorl %eax, %eax
callq 0x9060
leaq 0x2d2a4c(%rip), %rdi    # 0x33c220
callq 0x5eff8
movl $0x218, %eax            # imm = 0x218
leaq 0x1d57cb(%rip), %rcx    # 0x23efb0
xorl %edx, %edx
movl %edx, (%rcx,%rax)
movl %edx, -0x1fc(%rcx,%rax)
addq $0x348, %rax            # imm = 0x348
cmpq $0xcd358, %rax          # imm = 0xCD358
jne 0x697e7
leaq 0xb72cb(%rip), %rdi     # 0x120ad1
callq 0x5eff8
leaq 0xb7152(%rip), %rdi     # 0x120964
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5eff8
leaq 0xb7494(%rip), %rdi     # 0x120cc0
movl $0x1e, %esi
callq 0x5edda
leaq 0xb749a(%rip), %rdi     # 0x120cd7
movl $0x20, %esi
callq 0x5edda
leaq 0xb74a0(%rip), %rdi     # 0x120cee
movl $0x16, %esi
callq 0x5edda
cmpl $0x4e, (%r15)
jne 0x6987d
leaq 0xb74e0(%rip), %rdi     # 0x120d45
movl $0x1e, %esi
callq 0x5edda
leaq 0xb74e4(%rip), %rdi     # 0x120d5a
movl $0x20, %esi
jmp 0x69889
leaq 0xb73fd(%rip), %rdi     # 0x120c81
movl $0x1e, %esi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5edda
cmpl $0x33, %ebx
movq %rdx, %r14
ja 0x6973c
addb $-0x21, %bl
movl %r11d, %eax
btsl %ebx, %eax
movl %eax, (%r10)
jmp 0x6973c