// File: /workspace/github_cpp_makefile_star2_O1/jkingan[P]ladyheather/heathgps.cpp
// Function: get_ubx_message()
void get_ubx_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 decode_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 0xB5
      if(c == 0xB5) {
         tsip_sync = 1;
         get_sync_time();
      }
      else if(c == '$') {  // ignore NMEA msg
         tsip_sync = 100;
      }
      tsip_wptr = 0;
      tsip_rptr = 0;
      return;
   }
   else if(tsip_sync == 100) {  // skipping NMEA message
      if(c == 0x0A) {
         tsip_sync = 0;
         packet_end = 1;
      }
   }
   else if(tsip_sync == 1) { // 0xB5 has been seen, now checking next byte
      if(c != 0x62) goto rst_msg;
      ++tsip_sync;           // 0xB5 0x62 seen... so accumulate the message
      ubx_rxa = ubx_rxb = 0; // init received message checksum
   }
   else if(tsip_sync == 2) {    // get ubx message class
      ubx_rx_class = c;
      ubx_msg_id = (c & 0xFF);
      ubx_rxa += c;
      ubx_rxb += ubx_rxa;
      ++tsip_sync;
   }
   else if(tsip_sync == 3) {    // get ubx message id
      ubx_rx_id = c;
      ubx_msg_id = (ubx_msg_id * 256) + (c & 0xFF);
      ubx_rxa += c;
      ubx_rxb += ubx_rxa;
      ++tsip_sync;
   }
   else if(tsip_sync == 4) {    // low byte of payload length
      ubx_rx_len = c;
      ubx_rxa += c;
      ubx_rxb += ubx_rxa;
      ++tsip_sync;
   }
   else if(tsip_sync == 5) {    // high byte of payload length
      ubx_rx_len += (((u32) c) * 256);
      ubx_msg_len = ubx_rx_len;
      ubx_rxa += c;
      ubx_rxb += ubx_rxa;
      ++tsip_sync;
      if(ubx_rx_len == 0) ++tsip_sync;  // message has no payload
   }
   else if(tsip_sync == 6) {   // get ubx message payload
      if(tsip_wptr < MAX_TSIP) {  // so add it to the message buffer
         tsip_buf[tsip_wptr++] = c;
         ubx_rxa += c;
         ubx_rxb += ubx_rxa;
         --ubx_rx_len;
         if(ubx_rx_len == 0) ++tsip_sync;  // message payload processed, now get checksums
      }
      else {
         tsip_error |= OVFL_ERROR;
         goto rst_msg;
      }
   }
   else if(tsip_sync == 7) {  // first byte of message checksum
      ++tsip_sync;
      ubx_msg_rxa = c;
//packet_end = 0;
   }
   else if(tsip_sync == 8) {  // last byte of message checksum, end of ubx message
      tsip_sync = 0;
      ubx_msg_rxb = c;
      if((ubx_msg_rxa != ubx_rxa) || (ubx_msg_rxb != ubx_rxb)) { // checksum error
         tsip_error |= CKSUM_ERROR;
         goto rst_msg;
      }

      decode_ubx_msg();  // message checksum matches, process the message
      packet_end = 1;
   }
   else {     // should never happen
      rst_msg:
      tsip_wptr = 0;
      tsip_sync = 0;
      ubx_rxa = ubx_rxb = 0; // init received message checksum
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl $0xa, %edi
callq 0xb9c3
movl $0xa, %edi
testl %eax, %eax
je 0x95b04
callq 0x1ea2c
callq 0x584d5
leaq 0x27882f(%rip), %rcx    # 0x30e2e0
cmpb $0x0, 0x17a12(%rcx)
je 0x95ac1
movb $0x0, 0x17a12(%rcx)
leaq 0x2a278e(%rip), %rcx    # 0x338256
movzwl (%rcx), %edx
cmpq $0x8, %rdx
ja 0x95b0a
leaq 0x89be8(%rip), %rsi     # 0x11f6c0
movslq (%rsi,%rdx,4), %rdi
addq %rsi, %rdi
jmpq *%rdi
cmpl $0x24, %eax
je 0x95cc7
cmpl $0xb5, %eax
jne 0x95ccc
movw $0x1, (%rcx)
callq 0x58682
jmp 0x95ccc
popq %rbp
jmp 0x1e6a0
cmpl $0x64, %edx
jne 0x95caa
cmpl $0xa, %eax
jne 0x95ce2
movw $0x0, (%rcx)
jmp 0x95c95
movb 0x2d6f4d(%rip), %sil    # 0x36ca7a
addb %al, %sil
addb %sil, 0x2d6f44(%rip)    # 0x36ca7b
movl %eax, 0x2d6f47(%rip)    # 0x36ca84
jmp 0x95b5d
movb %al, 0x2d6f39(%rip)     # 0x36ca7e
movb 0x2d6f2e(%rip), %sil    # 0x36ca7a
addb %al, %sil
addb %sil, 0x2d6f25(%rip)    # 0x36ca7b
movw %ax, 0x2d6f23(%rip)     # 0x36ca80
movb %sil, 0x2d6f16(%rip)    # 0x36ca7a
jmp 0x95b97
movb %al, 0x2d6f13(%rip)     # 0x36ca7f
movzwl 0x2d6f0d(%rip), %esi    # 0x36ca80
shll $0x8, %esi
orl %eax, %esi
movb 0x2d6efb(%rip), %dil    # 0x36ca7a
addb %al, %dil
addb %dil, 0x2d6ef2(%rip)    # 0x36ca7b
movw %si, 0x2d6ef0(%rip)     # 0x36ca80
movb %dil, 0x2d6ee3(%rip)    # 0x36ca7a
leal 0x1(%rdx), %eax
movw %ax, (%rcx)
jmp 0x95ce2
incl %edx
movw %dx, (%rcx)
movb %al, 0x2d6ecf(%rip)     # 0x36ca7c
jmp 0x95ce2
cmpl $0x62, %eax
jne 0x95caa
leal 0x1(%rdx), %eax
movw %ax, (%rcx)
xorl %eax, %eax
movb %al, 0x2d6eb2(%rip)     # 0x36ca7b
movb %al, 0x2d6eab(%rip)     # 0x36ca7a
jmp 0x95ce2
movl %eax, %esi
movb 0x2d6e9d(%rip), %dil    # 0x36ca7a
addb %al, %dil
addb %dil, 0x2d6e94(%rip)    # 0x36ca7b
shll $0x8, %esi
leal 0x1(%rdx), %eax
movb %dil, 0x2d6e86(%rip)    # 0x36ca7a
movw %ax, (%rcx)
addl 0x2d6e87(%rip), %esi    # 0x36ca84
movl %esi, 0x2d6e81(%rip)    # 0x36ca84
movl %esi, 0x2d6e7f(%rip)    # 0x36ca88
jne 0x95ce2
leal 0x2(%rdx), %eax
jmp 0x95b9a
leaq 0x2a2637(%rip), %r8     # 0x338252
movzwl (%r8), %edi
movl $0x8000, %esi           # imm = 0x8000
cmpq $0xfff, %rdi            # imm = 0xFFF
ja 0x95ca1
leal 0x1(%rdi), %esi
movw %si, (%r8)
leaq 0x2a1615(%rip), %rsi    # 0x337250
movb %al, (%rsi,%rdi)
movb 0x2d6e35(%rip), %sil    # 0x36ca7a
addb %al, %sil
addb %sil, 0x2d6e2c(%rip)    # 0x36ca7b
movb %sil, 0x2d6e24(%rip)    # 0x36ca7a
decl 0x2d6e28(%rip)          # 0x36ca84
jne 0x95ce2
jmp 0x95b97
movw $0x0, (%rcx)
movb %al, 0x2d6e0b(%rip)     # 0x36ca7d
movb 0x2d6e04(%rip), %dl     # 0x36ca7c
movl $0x4000, %esi           # imm = 0x4000
cmpb 0x2d6df7(%rip), %dl     # 0x36ca7a
jne 0x95ca1
movzbl 0x2d6def(%rip), %edx    # 0x36ca7b
cmpl %edx, %eax
jne 0x95ca1
callq 0x9561e
movl $0x1, 0x2d5ff5(%rip)    # 0x36bc94
jmp 0x95ce2
leaq 0x1a92c8(%rip), %rax    # 0x23ef70
orl %esi, (%rax)
leaq 0x2a25a1(%rip), %rax    # 0x338252
xorl %edx, %edx
movw %dx, (%rax)
movw %dx, (%rcx)
movb %dl, 0x2d6dbc(%rip)     # 0x36ca7b
movb %dl, 0x2d6db5(%rip)     # 0x36ca7a
jmp 0x95ce2
movw $0x64, (%rcx)
leaq 0x2a257f(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
leaq 0x2a2575(%rip), %rax    # 0x338254
movw %cx, (%rax)
popq %rbp
retq