// File: /workspace/github_cpp_makefile_star2_O2/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
pushq $0xa
popq %rdi
callq 0xb771
pushq $0xa
popq %rdi
testl %eax, %eax
je 0x88416
callq 0x1d93f
callq 0x51891
leaq 0x26ff1f(%rip), %rcx    # 0x2f82e0
cmpb $0x0, 0x17a12(%rcx)
je 0x883d1
movb $0x0, 0x17a12(%rcx)
leaq 0x299e7e(%rip), %rcx    # 0x322256
movzwl (%rcx), %edx
cmpq $0x8, %rdx
ja 0x8841c
leaq 0x812f4(%rip), %rsi     # 0x1096dc
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
cmpb $0x24, %al
je 0x885d1
movzbl %al, %eax
cmpl $0xb5, %eax
jne 0x885d6
movw $0x1, (%rcx)
callq 0x51a2f
jmp 0x885d6
popq %rbp
jmp 0x1d61b
cmpl $0x64, %edx
jne 0x885b2
cmpl $0xa, %eax
jne 0x885ec
andw $0x0, (%rcx)
jmp 0x8859d
movl %eax, 0x2ce647(%rip)    # 0x356a84
movb 0x2ce637(%rip), %dl     # 0x356a7a
addb %al, %dl
movb %dl, 0x2ce62f(%rip)     # 0x356a7a
addb %dl, 0x2ce62a(%rip)     # 0x356a7b
movw $0x5, (%rcx)
jmp 0x885ec
movb %al, 0x2ce61d(%rip)     # 0x356a7e
movw %ax, 0x2ce618(%rip)     # 0x356a80
movb 0x2ce60c(%rip), %dl     # 0x356a7a
addb %al, %dl
movb %dl, 0x2ce604(%rip)     # 0x356a7a
addb %dl, 0x2ce5ff(%rip)     # 0x356a7b
movw $0x3, (%rcx)
jmp 0x885ec
movb %al, 0x2ce5f3(%rip)     # 0x356a7f
movzwl 0x2ce5ed(%rip), %edx    # 0x356a80
shll $0x8, %edx
orl %eax, %edx
movw %dx, 0x2ce5e1(%rip)     # 0x356a80
movb 0x2ce5d5(%rip), %dl     # 0x356a7a
addb %al, %dl
movb %dl, 0x2ce5cd(%rip)     # 0x356a7a
addb %dl, 0x2ce5c8(%rip)     # 0x356a7b
movw $0x4, (%rcx)
jmp 0x885ec
movw $0x8, (%rcx)
movb %al, 0x2ce5b4(%rip)     # 0x356a7c
jmp 0x885ec
cmpl $0x62, %eax
jne 0x885b2
movw $0x2, (%rcx)
jmp 0x885c1
movl %eax, %edx
shll $0x8, %edx
movb 0x2ce58e(%rip), %sil    # 0x356a7a
addb %al, %sil
addb %sil, 0x2ce585(%rip)    # 0x356a7b
xorl %eax, %eax
addl 0x2ce586(%rip), %edx    # 0x356a84
movl %edx, 0x2ce580(%rip)    # 0x356a84
movl %edx, 0x2ce57e(%rip)    # 0x356a88
movb %sil, 0x2ce569(%rip)    # 0x356a7a
sete %al
orl $0x6, %eax
movw %ax, (%rcx)
jmp 0x885ec
leaq 0x299d2c(%rip), %rdi    # 0x322252
movzwl (%rdi), %esi
movl $0x8000, %edx           # imm = 0x8000
cmpq $0xfff, %rsi            # imm = 0xFFF
ja 0x885a9
leal 0x1(%rsi), %edx
movw %dx, (%rdi)
leaq 0x298d0c(%rip), %rdx    # 0x321250
movb %al, (%rdx,%rsi)
movb 0x2ce52d(%rip), %dl     # 0x356a7a
addb %al, %dl
addb %dl, 0x2ce526(%rip)     # 0x356a7b
movb %dl, 0x2ce51f(%rip)     # 0x356a7a
decl 0x2ce523(%rip)          # 0x356a84
jne 0x885ec
movw $0x7, (%rcx)
jmp 0x885ec
andw $0x0, (%rcx)
movb %al, 0x2ce505(%rip)     # 0x356a7d
movb 0x2ce4fd(%rip), %sil    # 0x356a7c
movl $0x4000, %edx           # imm = 0x4000
cmpb 0x2ce4ef(%rip), %sil    # 0x356a7a
jne 0x885a9
movzbl 0x2ce4e7(%rip), %esi    # 0x356a7b
cmpl %esi, %eax
jne 0x885a9
callq 0x88056
movl $0x1, 0x2cd6ed(%rip)    # 0x355c94
jmp 0x885ec
leaq 0x1a09c0(%rip), %rax    # 0x228f70
orl %edx, (%rax)
leaq 0x299c99(%rip), %rax    # 0x322252
andw $0x0, (%rax)
andw $0x0, (%rcx)
xorl %eax, %eax
movb %al, 0x2ce4b2(%rip)     # 0x356a7b
movb %al, 0x2ce4ab(%rip)     # 0x356a7a
jmp 0x885ec
movw $0x64, (%rcx)
leaq 0x299c75(%rip), %rax    # 0x322252
andw $0x0, (%rax)
leaq 0x299c6c(%rip), %rax    # 0x322254
andw $0x0, (%rax)
popq %rbp
retq