// File: /workspace/github_cpp_makefile_star2_O1/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 0x2ce004(%rip), %rax    # 0x33701a
leaq 0x1d5f21(%rip), %rcx    # 0x23ef3e
movb (%rcx), %cl
orb (%rax), %cl
jne 0x69505
movl %edi, %ebx
leaq 0x1af8a0(%rip), %rax    # 0x2188d0
movq (%rax), %rax
cmpq $0x7ff, %rax            # imm = 0x7FF
jg 0x69089
cmpq $0xf, %rax
jle 0x69125
cmpq $0x10, %rax
je 0x69223
cmpq $0x20, %rax
je 0x6929e
cmpq $0x100, %rax            # imm = 0x100
jne 0x69505
cmpl $0x20, %ebx
jg 0x69505
testl %ebx, %ebx
je 0x69561
decb %bl
leaq 0x2a4065(%rip), %rax    # 0x30d0e4
movl (%rax), %edi
btrl %ebx, %edi
jmp 0x69566
cmpq $0x1fffffff, %rax       # imm = 0x1FFFFFFF
jle 0x6918a
cmpq $0x20000000, %rax       # imm = 0x20000000
je 0x69273
movabsq $0x800000000, %rcx      # imm = 0x800000000
cmpq %rcx, %rax
je 0x6930b
movl $0x80000000, %ecx       # imm = 0x80000000
cmpq %rcx, %rax
jne 0x69505
leaq 0x2a4cbf(%rip), %rdx    # 0x30dd88
movl (%rdx), %r8d
leaq 0x2a4cb9(%rip), %r12    # 0x30dd8c
movl (%r12), %ecx
leaq 0x2a4cb6(%rip), %r13    # 0x30dd94
movl (%r13), %r9d
leaq 0x2a4caf(%rip), %r10    # 0x30dd98
movl (%r10), %r11d
leaq 0x2a4c9d(%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 0x69478
cmpl $0x20, %ebx
jg 0x694d3
decb %bl
movl %r8d, %eax
btsl %ebx, %eax
movl %eax, (%rdx)
jmp 0x6958f
cmpq $0x1, %rax
je 0x691e2
cmpq $0x8, %rax
jne 0x69505
cmpl $0x20, %ebx
jg 0x69505
leaq 0xb7aaf(%rip), %rdi     # 0x120bf8
movl $0x20, %esi
callq 0x5ee52
testl %ebx, %ebx
je 0x6917e
leaq 0x2d30c2(%rip), %r14    # 0x33c220
leaq 0xb7aec(%rip), %rsi     # 0x120c51
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x9060
movq %r14, %rdi
movl $0x1e, %esi
callq 0x5ee52
leaq 0xb7a1d(%rip), %rdi     # 0x120ba2
jmp 0x696da
cmpq $0x800, %rax            # imm = 0x800
je 0x691f6
cmpq $0x100000, %rax         # imm = 0x100000
jne 0x69505
cmpl $0x20, %ebx
jg 0x69505
testl %ebx, %ebx
je 0x694eb
leaq 0x2d306a(%rip), %r14    # 0x33c220
leaq 0xb7ad3(%rip), %rsi     # 0x120c90
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 0x5f15d
testl %ebx, %ebx
je 0x693ae
movl $0x2, %edi
movl %ebx, %esi
jmp 0x693b5
testl %ebx, %ebx
je 0x693cd
movl $0x12, %edi
callq 0x5e740
cmpl $0x40, %ebx
jl 0x694a4
movl $0x2, %edi
callq 0x591af
addb $-0x40, %bl
jmp 0x694ae
cmpl $0x20, %ebx
jg 0x69505
leaq 0x1b1dad(%rip), %r15    # 0x21afe0
movl (%r15), %eax
testl %ebx, %ebx
je 0x69514
cmpl $0x4e, %eax
leaq 0xb79f1(%rip), %rax     # 0x120c39
leaq 0xb7a01(%rip), %rsi     # 0x120c50
cmoveq %rax, %rsi
leaq 0x2d2fc6(%rip), %r14    # 0x33c220
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x9060
movq %r14, %rdi
movl $0x1e, %esi
jmp 0x696a9
leal -0x78(%rbx), %eax
cmpl $0x1f, %eax
ja 0x69388
leaq 0x2a3e62(%rip), %rcx    # 0x30d0e8
movl (%rcx), %edx
btsl %eax, %edx
leaq 0x2d2f8e(%rip), %rdi    # 0x33c220
leaq 0xb7989(%rip), %rsi     # 0x120c22
jmp 0x6961c
cmpl $0x20, %ebx
jg 0x69505
leaq 0xb7805(%rip), %rdi     # 0x120ab3
callq 0x61694
xorl %r14d, %r14d
xorl %edi, %edi
callq 0x591af
movl $0x0, %edi
testl %ebx, %ebx
je 0x692d6
decb %bl
leaq 0x2a3e15(%rip), %rax    # 0x30d0e4
movl (%rax), %edi
notl %edi
btsl %ebx, %edi
callq 0x593b5
callq 0x6170f
movl $0x218, %eax            # imm = 0x218
leaq 0x1d5cc4(%rip), %rcx    # 0x23efb0
movl %r14d, (%rcx,%rax)
movl %r14d, -0x1fc(%rcx,%rax)
addq $0x348, %rax            # imm = 0x348
cmpq $0xcd358, %rax          # imm = 0xCD358
jne 0x692ec
jmp 0x693ba
leaq 0x2a4a9e(%rip), %r14    # 0x30ddb0
movl (%r14), %r15d
leaq 0x2a4a98(%rip), %r12    # 0x30ddb4
movl (%r12), %r13d
testl %ebx, %ebx
jle 0x6948f
cmpl $0x20, %ebx
jg 0x69498
decb %bl
movl %r15d, %eax
btsl %ebx, %eax
movl %eax, (%r14)
movl $0x5a, %edi
movl $0x10, %esi
callq 0x653a5
leaq 0xb7418(%rip), %rdi     # 0x12076a
callq 0x653eb
movzbl (%r14), %edi
callq 0x591af
movzbl 0x1(%r14), %edi
callq 0x591af
movzbl 0x2(%r14), %edi
callq 0x591af
movzbl 0x3(%r14), %edi
callq 0x591af
callq 0x65433
jmp 0x69498
cmpl $0x1f, %ebx
jg 0x6962f
testl %ebx, %ebx
je 0x69600
decb %bl
leaq 0x2a3d42(%rip), %rax    # 0x30d0e4
movl (%rax), %edx
notl %edx
btsl %ebx, %edx
jmp 0x6960e
movl $0x1, %edi
xorl %esi, %esi
callq 0x6873c
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6879a
movb $0x1, %r14b
movl $0x349, %r15d           # imm = 0x349
leaq 0x1d5bd3(%rip), %rbx    # 0x23efb0
cmpb $0x0, (%rbx,%r15)
je 0x69410
movl $0x12, %edi
callq 0x5e740
movl $0x1, %edi
callq 0x591af
movzbl %r14b, %edi
callq 0x591af
movl $0x1, %edi
callq 0x591af
callq 0x5e844
incb %r14b
addq $0x348, %r15            # imm = 0x348
cmpq $0x6c49, %r15           # imm = 0x6C49
jne 0x693dd
movb $0x1, %r14b
xorl %r15d, %r15d
cmpb $0x0, 0xd549(%rbx,%r15)
je 0x69460
movl $0x12, %edi
callq 0x5e740
movl $0x2, %edi
callq 0x591af
movzbl %r14b, %edi
callq 0x591af
movl $0x1, %edi
callq 0x591af
callq 0x5e844
incb %r14b
addq $0x348, %r15            # imm = 0x348
cmpq $0x4ec0, %r15           # imm = 0x4EC0
jne 0x69429
jmp 0x69505
xorl %eax, %eax
movl %eax, (%rdx)
movl %eax, (%r12)
movl %eax, (%r13)
movl %eax, (%r10)
movl %eax, (%r14)
jmp 0x6958f
xorl %eax, %eax
movl %eax, (%r14)
movl %eax, (%r12)
movl %r15d, (%r14)
movl %r13d, (%r12)
jmp 0x695e8
movl $0x1, %edi
callq 0x591af
movzbl %bl, %edi
callq 0x591af
movl $0x2, %edi
callq 0x591af
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5e844
leal -0x41(%rbx), %eax
cmpl $0x1b, %eax
ja 0x69579
btsl %eax, %ecx
movl %ecx, (%r12)
jmp 0x6958f
movl $0x20, %r14d
leaq 0xb77a4(%rip), %rbx     # 0x120c9c
movq %rbx, %rdi
callq 0x5f15d
decl %r14d
jne 0x694f8
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x4e, %eax
jne 0x6967b
leaq 0xb75d8(%rip), %rdi     # 0x120afc
movl $0x20, %esi
callq 0x5ee52
leaq 0xb75fa(%rip), %rdi     # 0x120b2f
movl $0x20, %esi
callq 0x5ee52
leaq 0xb761c(%rip), %rdi     # 0x120b62
movl $0x20, %esi
callq 0x5ee52
leaq 0xb763b(%rip), %rdi     # 0x120b92
movl $0x21, %esi
jmp 0x696a9
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6970f
leal -0x5d(%rbx), %eax
cmpl $0x6, %eax
ja 0x696f2
movl %r9d, %ecx
btsl %eax, %ecx
movl %ecx, (%r13)
movq %rdx, %r14
leaq 0x2a3b1f(%rip), %rax    # 0x30d0b8
movss (%rax), %xmm1
movss 0xa3a2b(%rip), %xmm0    # 0x10cfd0
movl $0xff, %edi
movl $0xff, %esi
movaps %xmm0, %xmm2
movaps %xmm0, %xmm3
movl $0xff, %edx
movq %r10, %rbx
movl %r11d, %r15d
callq 0x5d081
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 0x2a47ad(%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 0x66617
leaq 0xb7626(%rip), %rdi     # 0x120c2d
callq 0x5f070
xorl %edx, %edx
leaq 0x2d2c0b(%rip), %rdi    # 0x33c220
leaq 0xb74a6(%rip), %rsi     # 0x120ac2
xorl %eax, %eax
callq 0x9060
leaq 0x2d2bf6(%rip), %rdi    # 0x33c220
callq 0x5f070
movl $0x218, %eax            # imm = 0x218
leaq 0x1d5975(%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 0x6963d
leaq 0xb7395(%rip), %rdi     # 0x1209f1
callq 0x5f070
leaq 0xb721c(%rip), %rdi     # 0x120884
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5f070
leaq 0xb755e(%rip), %rdi     # 0x120be0
movl $0x1e, %esi
callq 0x5ee52
leaq 0xb7564(%rip), %rdi     # 0x120bf7
movl $0x20, %esi
callq 0x5ee52
leaq 0xb756a(%rip), %rdi     # 0x120c0e
movl $0x16, %esi
callq 0x5ee52
cmpl $0x4e, (%r15)
jne 0x696d3
leaq 0xb75aa(%rip), %rdi     # 0x120c65
movl $0x1e, %esi
callq 0x5ee52
leaq 0xb75ae(%rip), %rdi     # 0x120c7a
movl $0x20, %esi
jmp 0x696df
leaq 0xb74c7(%rip), %rdi     # 0x120ba1
movl $0x1e, %esi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5ee52
cmpl $0x33, %ebx
movq %rdx, %r14
jg 0x69592
addb $-0x21, %bl
movl %r11d, %eax
btsl %ebx, %eax
movl %eax, (%r10)
jmp 0x69592