// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heathgps.cpp
// Function: get_tsip_config()
void get_tsip_config()
{
u08 rcvr_mode;
u08 rsvd1;
u08 rsvd2;
u08 rsvd3;
u08 rsvd4[32]; 
u08 sat_types;
u08 i, last;
float el_val;
float amu_val;

   log_packet_id("Packet 0xBB (Receiver config)");

   subcode = tsip_byte();       // 0
   rcvr_mode = tsip_byte();     // 1
   rsvd1 = tsip_byte();         // 2
   dynamics_code = tsip_byte(); // 3
   rsvd2 = tsip_byte();         // 4
   el_val = tsip_single();      // 5
   amu_val = tsip_single();     // 9
   pdop_mask = tsip_single();   // 13
   have_pdop_mask |= 0x01;
   pdop_switch = tsip_single(); // 17
   have_pdop_mask |= 0x02;
   rsvd3 = tsip_byte();         // 21  (DGPS age)
   foliage_mode = tsip_byte();  // 22 saw_icm: anti-jam mode

   // byte 23: low power mode
   // byte 24: clock hold mode
   // byte 25: measurement rate
   // byte 26: fix rate
   // byte 27: sat type mask for OD clock mode saw_icm
   //          0x01 GPS
   //          0x02 GLONASS
   //          0x08 Beidou
   //          0x10 Galileo
   //          0x20 QZSS 
   last = 40;
   if(ACU_GG) last = 43;  // !!!!! should be 40, but this causes a packet read error!
   else if(ACU_360) last = 40;
   else if(ACUTIME && (acu_type == '1')) last = 43;  // !!!! 40 for newer models?
   else if(PALISADE) last = 44;

   for(i=23; i<last; i++) {   
      rsvd4[i-23] = tsip_byte();
      if((i == 27) && (saw_icm || (res_t == RES_T_360) || ACU_GG || ACU_360)) { // saw_icm: byte 28 = OD clock mode sat type bit mask
         sat_types = rsvd4[i-23];
         if(sat_types == 0) ;
         else if(sat_types == 0xFF) ;
         else {
            gnss_mask = 0;
            if(sat_types & 0x01) gnss_mask |= GPS;
            if(sat_types & 0x02) gnss_mask |= GLONASS;
            if(sat_types & 0x08) gnss_mask |= BEIDOU;
            if(sat_types & 0x10) gnss_mask |= GALILEO;
            if(sat_types & 0x20) gnss_mask |= QZSS;
            if(gnss_mask == 0) {
               gnss_mask = MIXED;
               have_gnss_mask = 0;
            }
            else have_gnss_mask = 4;
         }
      }
   }

   check_tsip_end(1);

   // stupid filtering required for STARLOC II devices
   el_val = (float) (int) ((el_val*RAD_TO_DEG) + 0.50F);
   if(0 && STARLOC) ;
   else if((el_val >= 0.0) && (el_val <= 90.0)) {
      el_mask = el_val;
      have_el_mask = 1;
   }

   if(0 && STARLOC) ;
   else if((amu_val >= 0.0) && (amu_val < 60.0)) {
      amu_mask = amu_val;
      have_amu = 1;
   }
   if(tsip_error) return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0x9cbbe(%rip), %rdi     # 0x10c256
callq 0x520bf
callq 0x51c47
leaq 0x1b98b5(%rip), %rcx    # 0x228f5e
movb %al, (%rcx)
callq 0x51c47
callq 0x51c47
callq 0x51c47
leaq 0x287a04(%rip), %rcx    # 0x2f70c5
movb %al, (%rcx)
callq 0x51c47
callq 0x51dc3
movss %xmm0, -0x2c(%rbp)
callq 0x51dc3
movss %xmm0, -0x30(%rbp)
callq 0x51dc3
leaq 0x2879d4(%rip), %rax    # 0x2f70bc
movss %xmm0, (%rax)
leaq 0x2879d9(%rip), %rbx    # 0x2f70cc
orb $0x1, (%rbx)
callq 0x51dc3
leaq 0x2879be(%rip), %rax    # 0x2f70c0
movss %xmm0, (%rax)
orb $0x2, (%rbx)
callq 0x51c47
callq 0x51c47
leaq 0x2879aa(%rip), %rcx    # 0x2f70c4
movb %al, (%rcx)
leaq 0x1931ad(%rip), %rax    # 0x2028d0
movq (%rax), %rax
cmpq $0x1, %rax
sete %dl
leaq 0x1958a0(%rip), %rcx    # 0x204fd4
movl (%rcx), %ecx
cmpl $0x41, %ecx
sete %sil
andb %dl, %sil
leaq 0x1931b1(%rip), %rdx    # 0x2028f8
movl (%rdx), %edx
cmpl $0x47, %edx
sete %dil
movb $0x2b, %r12b
testb %dil, %sil
jne 0x6f788
testb %sil, %sil
je 0x6f76f
cmpl $0x31, %edx
je 0x6f788
movb $0x28, %r12b
cmpl $0x33, %edx
je 0x6f788
cmpl $0x47, %edx
je 0x6f788
cmpq $0x1, %rax
sete %al
cmpl $0x50, %ecx
sete %r12b
andb %al, %r12b
shlb $0x2, %r12b
orb $0x28, %r12b
movb $0x17, %r13b
leaq 0x1b979b(%rip), %rbx    # 0x228f2d
leaq 0x19316b(%rip), %r14    # 0x202904
leaq 0xeb4d4(%rip), %r15     # 0x15ac74
cmpb %r13b, %r12b
jbe 0x6f851
callq 0x51c47
cmpb $0x1b, %r13b
jne 0x6f849
cmpb $0x0, (%rbx)
jne 0x6f7f5
cmpb $0x4, (%r14)
je 0x6f7f5
leaq 0x193106(%rip), %rcx    # 0x2028d0
cmpq $0x1, (%rcx)
sete %cl
leaq 0x1957fc(%rip), %rdx    # 0x204fd4
cmpl $0x41, (%rdx)
sete %dl
andb %cl, %dl
leaq 0x193111(%rip), %rcx    # 0x2028f8
movl (%rcx), %ecx
cmpl $0x47, %ecx
sete %sil
testb %sil, %dl
je 0x6f824
leal 0x1(%rax), %ecx
cmpb $0x2, %cl
jb 0x6f849
movzbl %al, %ecx
movl %ecx, %edx
andl $0xb, %edx
shrl $0x2, %ecx
andl $0x4, %ecx
orl %edx, %ecx
movl %ecx, (%r15)
testb $0x20, %al
jne 0x6f834
pushq $0x4
popq %rax
testl %ecx, %ecx
jne 0x6f840
xorl %eax, %eax
movl $0xc00f, %ecx           # imm = 0xC00F
jmp 0x6f83d
testb %dl, %dl
je 0x6f849
cmpl $0x47, %ecx
je 0x6f7f5
cmpl $0x33, %ecx
je 0x6f7f5
jmp 0x6f849
orl $0x4000, %ecx           # imm = 0x4000
pushq $0x4
popq %rax
movl %ecx, (%r15)
leaq 0xeb431(%rip), %rcx     # 0x15ac78
movl %eax, (%rcx)
incb %r13b
jmp 0x6f7a0
xorl %edi, %edi
callq 0x52194
cvtss2sd -0x2c(%rbp), %xmm0
mulsd 0x838fb(%rip), %xmm0    # 0xf3160
addsd 0x837fb(%rip), %xmm0    # 0xf3068
cvttsd2si %xmm0, %eax
cmpl $0x5a, %eax
ja 0x6f892
cvtsi2ss %eax, %xmm0
leaq 0x287833(%rip), %rax    # 0x2f70b4
movss %xmm0, (%rax)
leaq 0x287b70(%rip), %rax    # 0x2f73fc
movl $0x1, (%rax)
xorpd %xmm0, %xmm0
movss -0x30(%rbp), %xmm1
ucomiss %xmm0, %xmm1
jb 0x6f8c5
movss 0x87854(%rip), %xmm0    # 0xf70fc
ucomiss %xmm1, %xmm0
jbe 0x6f8c5
leaq 0x287804(%rip), %rax    # 0x2f70b8
movss %xmm1, (%rax)
leaq 0x287b39(%rip), %rax    # 0x2f73f8
movl $0x1, (%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq