// File: /workspace/github_cpp_makefile_star2_O3/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 0xa8593(%rip), %rdi     # 0x12230e
callq 0x58dc2
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x79d96
leaq 0x1c51dd(%rip), %rcx    # 0x23ef70
orb $0x8, (%rcx)
leaq 0x1c51c1(%rip), %rcx    # 0x23ef5e
movb %al, (%rcx)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x79db5
leaq 0x1c51be(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x79dcb
leaq 0x1c51a8(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x79de1
leaq 0x1c5192(%rip), %rcx    # 0x23ef70
orb $0x8, (%rcx)
leaq 0x2932dd(%rip), %rcx    # 0x30d0c5
movb %al, (%rcx)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x79e00
leaq 0x1c5173(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x58a30
movss %xmm0, -0x2c(%rbp)
callq 0x58a30
movss %xmm0, -0x30(%rbp)
callq 0x58a30
leaq 0x29329c(%rip), %rax    # 0x30d0bc
movss %xmm0, (%rax)
leaq 0x2932a1(%rip), %rbx    # 0x30d0cc
orb $0x1, (%rbx)
callq 0x58a30
leaq 0x293286(%rip), %rax    # 0x30d0c0
movss %xmm0, (%rax)
orb $0x2, (%rbx)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x79e57
leaq 0x1c511c(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x79e6d
leaq 0x1c5106(%rip), %rcx    # 0x23ef70
orb $0x8, (%rcx)
leaq 0x293250(%rip), %rcx    # 0x30d0c4
movb %al, (%rcx)
leaq 0x19ea53(%rip), %rax    # 0x2188d0
movq (%rax), %rax
cmpq $0x1, %rax
sete %dl
leaq 0x1a1146(%rip), %rcx    # 0x21afd4
movl (%rcx), %ecx
cmpl $0x41, %ecx
sete %sil
andb %dl, %sil
leaq 0x19ea57(%rip), %rdx    # 0x2188f8
movl (%rdx), %edx
cmpl $0x47, %edx
sete %dil
movl $0x2b, %r12d
testb %dil, %sil
jne 0x79ee9
testb %sil, %sil
je 0x79ecf
cmpl $0x31, %edx
je 0x79ee9
movl $0x28, %r12d
cmpl $0x33, %edx
je 0x79ee9
cmpl $0x47, %edx
je 0x79ee9
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 0x1c5036(%rip), %rbx    # 0x23ef2d
leaq 0x19ea06(%rip), %r14    # 0x218904
leaq 0x1c506b(%rip), %r15    # 0x23ef70
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x79f15
orb $0x8, (%r15)
cmpl $0x4, %r13d
jne 0x79fbf
cmpb $0x0, (%rbx)
jne 0x79f5c
cmpb $0x4, (%r14)
je 0x79f5c
leaq 0x19e99f(%rip), %rcx    # 0x2188d0
cmpq $0x1, (%rcx)
sete %cl
leaq 0x1a1095(%rip), %rdx    # 0x21afd4
cmpl $0x41, (%rdx)
sete %dl
andb %cl, %dl
leaq 0x19e9aa(%rip), %rcx    # 0x2188f8
movl (%rcx), %ecx
cmpl $0x47, %ecx
sete %sil
testb %sil, %dl
je 0x79f92
leal 0x1(%rax), %ecx
cmpb $0x2, %cl
jb 0x79fbf
movl %eax, %edx
andl $0xb, %edx
movl %eax, %ecx
shrl $0x2, %ecx
andl $0x4, %ecx
orl %edx, %ecx
leaq 0xf6cfa(%rip), %rdx     # 0x170c74
movl %ecx, (%rdx)
testb $0x20, %al
jne 0x79fa2
movl $0x4, %eax
testl %ecx, %ecx
jne 0x79fb6
xorl %eax, %eax
movl $0xc00f, %ecx           # imm = 0xC00F
jmp 0x79fad
testb %dl, %dl
je 0x79fbf
cmpl $0x47, %ecx
je 0x79f5c
cmpl $0x33, %ecx
je 0x79f5c
jmp 0x79fbf
orl $0x4000, %ecx           # imm = 0x4000
movl $0x4, %eax
leaq 0xf6cc0(%rip), %rdx     # 0x170c74
movl %ecx, (%rdx)
leaq 0xf6cbb(%rip), %rcx     # 0x170c78
movl %eax, (%rcx)
incl %r13d
cmpl %r13d, %r12d
jne 0x79f05
xorl %edi, %edi
callq 0x58e9b
xorps %xmm0, %xmm0
cvtss2sd -0x2c(%rbp), %xmm0
mulsd 0x8f17e(%rip), %xmm0    # 0x109160
addsd 0x8f07e(%rip), %xmm0    # 0x109068
cvttsd2si %xmm0, %eax
cmpl $0x5a, %eax
ja 0x7a012
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
leaq 0x2930b3(%rip), %rax    # 0x30d0b4
movss %xmm0, (%rax)
leaq 0x2933f0(%rip), %rax    # 0x30d3fc
movl $0x1, (%rax)
xorpd %xmm0, %xmm0
movss -0x30(%rbp), %xmm1
ucomiss %xmm0, %xmm1
jb 0x7a045
movss 0x93054(%rip), %xmm0    # 0x10d07c
ucomiss %xmm1, %xmm0
jbe 0x7a045
leaq 0x293084(%rip), %rax    # 0x30d0b8
movss %xmm1, (%rax)
leaq 0x2933b9(%rip), %rax    # 0x30d3f8
movl $0x1, (%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq