// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heathgps.cpp
// Function: get_sirf_message()
void get_sirf_message()
{
u08 c;

   // This routine buffers up an incoming UBX message.  When the end of the
   // message is seen, the message is parsed and decoded with parse_ubx_msg()

   if(SERIAL_DATA_AVAILABLE(RCVR_PORT) == 0) {
      check_com_timer(RCVR_PORT);
      return;
   }
   else {
      reset_com_timer(RCVR_PORT);
   }

   c = get_com_char();
   if(com[RCVR_PORT].rcv_error) {      // parity/framing/overrun errors
      com[RCVR_PORT].rcv_error = 0;
//!!!!!qqqq    goto rst_msg;
   }


   if(tsip_sync == 0) {      // syncing to start of message, search for a 0xA0
      if(c == 0xA0) {
         tsip_sync = 1;
         get_sync_time();
      }
      tsip_wptr = 0;
      tsip_rptr = 0;
      return;
   }
   else if(tsip_sync == 1) { // 0xA0 has been seen, now checking next byte
      if(c != 0xA2) goto rst_msg;
      ++tsip_sync;           // 0xA2 seen... so accumulate the message
      sirf_rx_cksum = 0;     // init received message checksum
   }
   else if(tsip_sync == 2) { // high byte of payload length
      sirf_rx_len = ((u32) c);
      sirf_msg_len = sirf_rx_len;
      ++tsip_sync;
   }
   else if(tsip_sync == 3) {    // low byte of payload length
      sirf_rx_len *= 256;
      sirf_rx_len += (((u32) c) & 0xFF);
      sirf_msg_len = sirf_rx_len;
      ++tsip_sync;
      if(sirf_rx_len == 0) ++tsip_sync;  // message has no payload
   }
   else if(tsip_sync == 4) {   // get sirf message payload
      if(tsip_wptr < MAX_TSIP) {  // so add it to the message buffer
         sirf_rx_cksum += c;
         tsip_buf[tsip_wptr++] = c;
         --sirf_rx_len;
         if((int) sirf_rx_len <= 0) ++tsip_sync;  // message payload processed, now get checksums
      }
      else {
         tsip_error |= OVFL_ERROR;
         goto rst_msg;
      }
   }
   else if(tsip_sync == 5) {  // first (high) byte of message checksum
      sirf_msg_cksum = c;
      ++tsip_sync;
   }
   else if(tsip_sync == 6) {  // last byte of message checksum, end of sirf message
      sirf_msg_cksum = (sirf_msg_cksum * 256) + (((u16) c) & 0xFF);
      sirf_msg_cksum &= 0x7FFF;
      sirf_rx_cksum &= 0x7FFF;

      if(sirf_msg_cksum != sirf_rx_cksum) { // checksum error
         tsip_error |= CKSUM_ERROR;
         goto rst_msg;
      }
      tsip_sync = 7;
//    tsip_sync = 0;
//    decode_sirf_msg();  // message checksum matches, process the message
//    packet_end = 1;
   }
   else if(tsip_sync == 7) {  // end-of-message bytes
      tsip_sync = 8;
   }
   else if(tsip_sync == 8) {  // end-of-message bytes 
      decode_sirf_msg();  // message checksum matches, process the message
      packet_end = 1;
      tsip_sync = 0;
   }
   else {     // should never happen
      rst_msg:
      tsip_wptr = 0;
      tsip_sync = 0;
      sirf_rx_cksum = 0; // init received message checksum
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
pushq $0xa
popq %rdi
callq 0xb771
pushq $0xa
popq %rdi
testl %eax, %eax
je 0x8905c
callq 0x1d93f
callq 0x51891
leaq 0x26f2e4(%rip), %rcx    # 0x2f82e0
cmpb $0x0, 0x17a12(%rcx)
je 0x8900c
movb $0x0, 0x17a12(%rcx)
leaq 0x299243(%rip), %rbx    # 0x322256
movzwl (%rbx), %ecx
cmpq $0x8, %rcx
ja 0x8915f
leaq 0x80721(%rip), %rdx     # 0x109748
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
cmpl $0xa0, %eax
jne 0x89041
movw $0x1, (%rbx)
callq 0x51a2f
leaq 0x29920a(%rip), %rax    # 0x322252
andw $0x0, (%rax)
leaq 0x299201(%rip), %rax    # 0x322254
andw $0x0, (%rax)
jmp 0x8918b
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x1d61b
leaq 0x2991e4(%rip), %rdx    # 0x322252
movzwl (%rdx), %ecx
movl $0x8000, %esi           # imm = 0x8000
cmpq $0xfff, %rcx            # imm = 0xFFF
ja 0x89156
addw %ax, 0x2cda66(%rip)     # 0x356af0
leal 0x1(%rcx), %esi
movw %si, (%rdx)
leaq 0x2981b9(%rip), %rdx    # 0x321250
movb %al, (%rdx,%rcx)
movl 0x2cda58(%rip), %eax    # 0x356af8
decl %eax
movl %eax, 0x2cda50(%rip)    # 0x356af8
testl %eax, %eax
jg 0x8918b
movw $0x5, (%rbx)
jmp 0x8918b
movl %eax, 0x2cda38(%rip)    # 0x356af8
movl %eax, 0x2cda36(%rip)    # 0x356afc
movw $0x3, (%rbx)
jmp 0x8918b
movl 0x2cda22(%rip), %ecx    # 0x356af8
shll $0x8, %ecx
xorl %edx, %edx
orl %eax, %ecx
movl %ecx, 0x2cda15(%rip)    # 0x356af8
movl %ecx, 0x2cda13(%rip)    # 0x356afc
sete %dl
orl $0x4, %edx
movw %dx, (%rbx)
jmp 0x8918b
movw $0x8, (%rbx)
jmp 0x8918b
cmpl $0xa2, %eax
jne 0x8915f
movw $0x2, (%rbx)
jmp 0x8916e
movw %ax, 0x2cd9dc(%rip)     # 0x356af2
movw $0x6, (%rbx)
jmp 0x8918b
movzwl 0x2cd9ce(%rip), %ecx    # 0x356af2
andl $0x7f, %ecx
shll $0x8, %ecx
orl %eax, %ecx
movw %cx, 0x2cd9bf(%rip)     # 0x356af2
movzwl 0x2cd9b6(%rip), %eax    # 0x356af0
andl $0x7fff, %eax           # imm = 0x7FFF
movw %ax, 0x2cd9aa(%rip)     # 0x356af0
movl $0x4000, %esi           # imm = 0x4000
cmpl %eax, %ecx
jne 0x89156
movw $0x7, (%rbx)
jmp 0x8918b
leaq 0x19fe13(%rip), %rax    # 0x228f70
orl %esi, (%rax)
leaq 0x2990ec(%rip), %rax    # 0x322252
andw $0x0, (%rax)
andw $0x0, (%rbx)
andw $0x0, 0x2cd97a(%rip)    # 0x356af0
jmp 0x8918b
callq 0x88f09
movl $0x1, 0x2ccb0d(%rip)    # 0x355c94
andw $0x0, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq