// File: /workspace/github_cpp_makefile_star2_O3/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 0xb9ad
movl $0xa, %edi
testl %eax, %eax
je 0x95bfb
callq 0x1ea0b
callq 0x584bd
leaq 0x27873a(%rip), %rcx    # 0x30e2e0
cmpb $0x0, 0x17a12(%rcx)
je 0x95bb6
movb $0x0, 0x17a12(%rcx)
leaq 0x2a2699(%rip), %rcx    # 0x338256
movzwl (%rcx), %edx
cmpq $0x8, %rdx
ja 0x95c01
leaq 0x89bcb(%rip), %rsi     # 0x11f798
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
cmpb $0x24, %al
je 0x95dc4
movzbl %al, %eax
cmpl $0xb5, %eax
jne 0x95dc9
movw $0x1, (%rcx)
callq 0x58672
jmp 0x95dc9
popq %rbp
jmp 0x1e66a
cmpl $0x64, %edx
jne 0x95da7
cmpl $0xa, %eax
jne 0x95ddf
movw $0x0, (%rcx)
jmp 0x95d92
movl %eax, 0x2d6e61(%rip)    # 0x36ca84
movb 0x2d6e51(%rip), %dl     # 0x36ca7a
addb %al, %dl
movb %dl, 0x2d6e49(%rip)     # 0x36ca7a
addb %dl, 0x2d6e44(%rip)     # 0x36ca7b
movw $0x5, (%rcx)
jmp 0x95ddf
movb %al, 0x2d6e37(%rip)     # 0x36ca7e
movw %ax, 0x2d6e32(%rip)     # 0x36ca80
movb 0x2d6e26(%rip), %dl     # 0x36ca7a
addb %al, %dl
movb %dl, 0x2d6e1e(%rip)     # 0x36ca7a
addb %dl, 0x2d6e19(%rip)     # 0x36ca7b
movw $0x3, (%rcx)
jmp 0x95ddf
movb %al, 0x2d6e0d(%rip)     # 0x36ca7f
movzwl 0x2d6e07(%rip), %edx    # 0x36ca80
shll $0x8, %edx
orl %eax, %edx
movw %dx, 0x2d6dfb(%rip)     # 0x36ca80
movb 0x2d6def(%rip), %dl     # 0x36ca7a
addb %al, %dl
movb %dl, 0x2d6de7(%rip)     # 0x36ca7a
addb %dl, 0x2d6de2(%rip)     # 0x36ca7b
movw $0x4, (%rcx)
jmp 0x95ddf
movw $0x8, (%rcx)
movb %al, 0x2d6dce(%rip)     # 0x36ca7c
jmp 0x95ddf
cmpl $0x62, %eax
jne 0x95da7
movw $0x2, (%rcx)
xorl %eax, %eax
movb %al, 0x2d6db2(%rip)     # 0x36ca7b
movb %al, 0x2d6dab(%rip)     # 0x36ca7a
jmp 0x95ddf
movl %eax, %edx
shll $0x8, %edx
movb 0x2d6d9a(%rip), %sil    # 0x36ca7a
addb %al, %sil
addb %sil, 0x2d6d91(%rip)    # 0x36ca7b
xorl %eax, %eax
addl 0x2d6d92(%rip), %edx    # 0x36ca84
movl %edx, 0x2d6d8c(%rip)    # 0x36ca84
movl %edx, 0x2d6d8a(%rip)    # 0x36ca88
movb %sil, 0x2d6d75(%rip)    # 0x36ca7a
sete %al
orl $0x6, %eax
movw %ax, (%rcx)
jmp 0x95ddf
leaq 0x2a2538(%rip), %rdi    # 0x338252
movzwl (%rdi), %esi
movl $0x8000, %edx           # imm = 0x8000
cmpq $0xfff, %rsi            # imm = 0xFFF
ja 0x95d9e
leal 0x1(%rsi), %edx
movw %dx, (%rdi)
leaq 0x2a1518(%rip), %rdx    # 0x337250
movb %al, (%rdx,%rsi)
movb 0x2d6d39(%rip), %dl     # 0x36ca7a
addb %al, %dl
addb %dl, 0x2d6d32(%rip)     # 0x36ca7b
movb %dl, 0x2d6d2b(%rip)     # 0x36ca7a
decl 0x2d6d2f(%rip)          # 0x36ca84
jne 0x95ddf
movw $0x7, (%rcx)
jmp 0x95ddf
movw $0x0, (%rcx)
movb %al, 0x2d6d10(%rip)     # 0x36ca7d
movb 0x2d6d08(%rip), %sil    # 0x36ca7c
movl $0x4000, %edx           # imm = 0x4000
cmpb 0x2d6cfa(%rip), %sil    # 0x36ca7a
jne 0x95d9e
movzbl 0x2d6cf2(%rip), %esi    # 0x36ca7b
cmpl %esi, %eax
jne 0x95d9e
callq 0x95714
movl $0x1, 0x2d5ef8(%rip)    # 0x36bc94
jmp 0x95ddf
leaq 0x1a91cb(%rip), %rax    # 0x23ef70
orl %edx, (%rax)
leaq 0x2a24a4(%rip), %rax    # 0x338252
xorl %edx, %edx
movw %dx, (%rax)
movw %dx, (%rcx)
movb %dl, 0x2d6cbf(%rip)     # 0x36ca7b
movb %dl, 0x2d6cb8(%rip)     # 0x36ca7a
jmp 0x95ddf
movw $0x64, (%rcx)
leaq 0x2a2482(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
leaq 0x2a2478(%rip), %rax    # 0x338254
movw %cx, (%rax)
popq %rbp
retq