// File: /workspace/github_cpp_makefile_star2_O1/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 0xa8240(%rip), %rdi     # 0x12222e
callq 0x58e77
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x7a009
leaq 0x1c4f6a(%rip), %rcx    # 0x23ef70
orb $0x8, (%rcx)
leaq 0x1c4f4e(%rip), %rcx    # 0x23ef5e
movb %al, (%rcx)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x7a028
leaq 0x1c4f4b(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x7a03e
leaq 0x1c4f35(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x7a054
leaq 0x1c4f1f(%rip), %rcx    # 0x23ef70
orb $0x8, (%rcx)
leaq 0x29306a(%rip), %rcx    # 0x30d0c5
movb %al, (%rcx)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x7a073
leaq 0x1c4f00(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x58aae
movss %xmm0, -0x2c(%rbp)
callq 0x58aae
movss %xmm0, -0x30(%rbp)
callq 0x58aae
leaq 0x293029(%rip), %rax    # 0x30d0bc
movss %xmm0, (%rax)
leaq 0x29302e(%rip), %rbx    # 0x30d0cc
orb $0x1, (%rbx)
callq 0x58aae
leaq 0x293013(%rip), %rax    # 0x30d0c0
movss %xmm0, (%rax)
orb $0x2, (%rbx)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x7a0ca
leaq 0x1c4ea9(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x7a0e0
leaq 0x1c4e93(%rip), %rcx    # 0x23ef70
orb $0x8, (%rcx)
leaq 0x292fdd(%rip), %rcx    # 0x30d0c4
movb %al, (%rcx)
leaq 0x19e7e0(%rip), %rax    # 0x2188d0
movq (%rax), %rax
cmpq $0x1, %rax
sete %sil
leaq 0x1a0ed2(%rip), %rcx    # 0x21afd4
movl (%rcx), %ecx
cmpl $0x41, %ecx
sete %dl
andb %sil, %dl
leaq 0x19e7e4(%rip), %rsi    # 0x2188f8
movl (%rsi), %esi
cmpl $0x47, %esi
sete %dil
movl $0x2b, %r12d
testb %dil, %dl
jne 0x7a168
testb %dl, %dl
je 0x7a13c
movl $0x28, %r12d
cmpl $0x33, %esi
je 0x7a168
cmpl $0x47, %esi
je 0x7a168
cmpl $0x31, %esi
sete %sil
movl $0x2b, %r12d
testb %sil, %dl
jne 0x7a168
cmpq $0x1, %rax
sete %al
cmpl $0x50, %ecx
sete %cl
andb %al, %cl
movzbl %cl, %eax
leal 0x28(,%rax,4), %r12d
addl $-0x17, %r12d
xorl %r13d, %r13d
leaq 0x1c4db7(%rip), %rbx    # 0x23ef2d
leaq 0xf6af7(%rip), %r15     # 0x170c74
leaq 0x1c4dec(%rip), %r14    # 0x23ef70
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x7a194
orb $0x8, (%r14)
cmpl $0x4, %r13d
jne 0x7a237
cmpb $0x0, (%rbx)
jne 0x7a1e1
leaq 0x19e75a(%rip), %rcx    # 0x218904
cmpb $0x4, (%rcx)
je 0x7a1e1
leaq 0x19e71a(%rip), %rcx    # 0x2188d0
cmpq $0x1, (%rcx)
sete %cl
leaq 0x1a0e10(%rip), %rdx    # 0x21afd4
cmpl $0x41, (%rdx)
sete %dl
andb %cl, %dl
leaq 0x19e725(%rip), %rcx    # 0x2188f8
movl (%rcx), %ecx
cmpl $0x47, %ecx
sete %sil
testb %sil, %dl
je 0x7a229
leal 0x1(%rax), %ecx
cmpb $0x2, %cl
jb 0x7a237
movl %eax, %ecx
andl $0x3, %ecx
movl %ecx, (%r15)
testb $0x8, %al
je 0x7a1f9
orb $0x8, (%r15)
testb $0x10, %al
je 0x7a201
orb $0x4, (%r15)
testb $0x20, %al
je 0x7a20a
orb $0x40, 0x1(%r15)
movl $0x4, %eax
cmpl $0x0, (%r15)
jne 0x7a21e
movl $0xc00f, (%r15)         # imm = 0xC00F
xorl %eax, %eax
leaq 0xf6a53(%rip), %rcx     # 0x170c78
movl %eax, (%rcx)
jmp 0x7a237
testb %dl, %dl
je 0x7a237
cmpl $0x47, %ecx
je 0x7a1e1
cmpl $0x33, %ecx
je 0x7a1e1
incl %r13d
cmpl %r13d, %r12d
jne 0x7a184
xorl %edi, %edi
callq 0x58f50
xorps %xmm0, %xmm0
cvtss2sd -0x2c(%rbp), %xmm0
mulsd 0x8eefe(%rip), %xmm0    # 0x109158
addsd 0x8ee06(%rip), %xmm0    # 0x109068
cvttsd2si %xmm0, %eax
cmpl $0x5a, %eax
ja 0x7a28a
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
leaq 0x292e3b(%rip), %rax    # 0x30d0b4
movss %xmm0, (%rax)
leaq 0x293178(%rip), %rax    # 0x30d3fc
movl $0x1, (%rax)
xorpd %xmm0, %xmm0
movss -0x30(%rbp), %xmm1
ucomiss %xmm0, %xmm1
jb 0x7a2bd
movss 0x92d48(%rip), %xmm0    # 0x10cfe8
ucomiss %xmm1, %xmm0
jbe 0x7a2bd
leaq 0x292e0c(%rip), %rax    # 0x30d0b8
movss %xmm1, (%rax)
leaq 0x293141(%rip), %rax    # 0x30d3f8
movl $0x1, (%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq