// File: 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
subq $0x10, %rsp
movl $0xa, %edi
callq 0xcad0
cmpl $0x0, %eax
jne 0xcc2c6
movl $0xa, %edi
callq 0x2b610
jmp 0xcc767
movl $0xa, %edi
callq 0x2bd30
callq 0x79fc0
movb %al, -0x1(%rbp)
leaq 0x2a11e1(%rip), %rax    # 0x36d4c0
cmpb $0x0, 0x17a12(%rax)
je 0xcc2f6
leaq 0x2a11d1(%rip), %rax    # 0x36d4c0
movb $0x0, 0x17a12(%rax)
leaq 0x2cb139(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x0, %eax
jne 0xcc357
movzbl -0x1(%rbp), %eax
cmpl $0xb5, %eax
jne 0xcc323
leaq 0x2cb11f(%rip), %rax    # 0x397436
movw $0x1, (%rax)
callq 0x7a1d0
jmp 0xcc33a
movzbl -0x1(%rbp), %eax
cmpl $0x24, %eax
jne 0xcc338
leaq 0x2cb103(%rip), %rax    # 0x397436
movw $0x64, (%rax)
jmp 0xcc33a
leaq 0x2cb0f1(%rip), %rax    # 0x397432
movw $0x0, (%rax)
leaq 0x2cb0e7(%rip), %rax    # 0x397434
movw $0x0, (%rax)
jmp 0xcc767
leaq 0x2cb0d8(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x64, %eax
jne 0xcc38a
movzbl -0x1(%rbp), %eax
cmpl $0xa, %eax
jne 0xcc385
leaq 0x2cb0c0(%rip), %rax    # 0x397436
movw $0x0, (%rax)
movl $0x1, 0x2feaef(%rip)    # 0x3cae74
jmp 0xcc765
leaq 0x2cb0a5(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x1, %eax
jne 0xcc3d2
movzbl -0x1(%rbp), %eax
cmpl $0x62, %eax
je 0xcc3a7
jmp 0xcc72f
leaq 0x2cb088(%rip), %rax    # 0x397436
movw (%rax), %cx
addw $0x1, %cx
leaq 0x2cb07a(%rip), %rax    # 0x397436
movw %cx, (%rax)
movb $0x0, 0x2ff895(%rip)    # 0x3cbc5b
movb $0x0, 0x2ff88d(%rip)    # 0x3cbc5a
jmp 0xcc763
leaq 0x2cb05d(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x2, %eax
jne 0xcc440
movb -0x1(%rbp), %al
movb %al, 0x2ff874(%rip)     # 0x3cbc5e
movzbl -0x1(%rbp), %eax
andl $0xff, %eax
movw %ax, 0x2ff866(%rip)     # 0x3cbc60
movzbl -0x1(%rbp), %ecx
movzbl 0x2ff855(%rip), %eax    # 0x3cbc5a
addl %ecx, %eax
movb %al, 0x2ff84d(%rip)     # 0x3cbc5a
movzbl 0x2ff846(%rip), %ecx    # 0x3cbc5a
movzbl 0x2ff840(%rip), %eax    # 0x3cbc5b
addl %ecx, %eax
movb %al, 0x2ff838(%rip)     # 0x3cbc5b
leaq 0x2cb00c(%rip), %rax    # 0x397436
movw (%rax), %cx
addw $0x1, %cx
leaq 0x2caffe(%rip), %rax    # 0x397436
movw %cx, (%rax)
jmp 0xcc761
leaq 0x2cafef(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x3, %eax
jne 0xcc4bb
movb -0x1(%rbp), %al
movb %al, 0x2ff807(%rip)     # 0x3cbc5f
movzwl 0x2ff801(%rip), %eax    # 0x3cbc60
shll $0x8, %eax
movzbl -0x1(%rbp), %ecx
andl $0xff, %ecx
addl %ecx, %eax
movw %ax, 0x2ff7eb(%rip)     # 0x3cbc60
movzbl -0x1(%rbp), %ecx
movzbl 0x2ff7da(%rip), %eax    # 0x3cbc5a
addl %ecx, %eax
movb %al, 0x2ff7d2(%rip)     # 0x3cbc5a
movzbl 0x2ff7cb(%rip), %ecx    # 0x3cbc5a
movzbl 0x2ff7c5(%rip), %eax    # 0x3cbc5b
addl %ecx, %eax
movb %al, 0x2ff7bd(%rip)     # 0x3cbc5b
leaq 0x2caf91(%rip), %rax    # 0x397436
movw (%rax), %cx
addw $0x1, %cx
leaq 0x2caf83(%rip), %rax    # 0x397436
movw %cx, (%rax)
jmp 0xcc75f
leaq 0x2caf74(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x4, %eax
jne 0xcc51a
movzbl -0x1(%rbp), %eax
movl %eax, 0x2ff790(%rip)    # 0x3cbc64
movzbl -0x1(%rbp), %ecx
movzbl 0x2ff77b(%rip), %eax    # 0x3cbc5a
addl %ecx, %eax
movb %al, 0x2ff773(%rip)     # 0x3cbc5a
movzbl 0x2ff76c(%rip), %ecx    # 0x3cbc5a
movzbl 0x2ff766(%rip), %eax    # 0x3cbc5b
addl %ecx, %eax
movb %al, 0x2ff75e(%rip)     # 0x3cbc5b
leaq 0x2caf32(%rip), %rax    # 0x397436
movw (%rax), %cx
addw $0x1, %cx
leaq 0x2caf24(%rip), %rax    # 0x397436
movw %cx, (%rax)
jmp 0xcc75d
leaq 0x2caf15(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x5, %eax
jne 0xcc5b3
movzbl -0x1(%rbp), %eax
shll $0x8, %eax
addl 0x2ff72a(%rip), %eax    # 0x3cbc64
movl %eax, 0x2ff724(%rip)    # 0x3cbc64
movl 0x2ff71e(%rip), %eax    # 0x3cbc64
movl %eax, 0x2ff71c(%rip)    # 0x3cbc68
movzbl -0x1(%rbp), %ecx
movzbl 0x2ff703(%rip), %eax    # 0x3cbc5a
addl %ecx, %eax
movb %al, 0x2ff6fb(%rip)     # 0x3cbc5a
movzbl 0x2ff6f4(%rip), %ecx    # 0x3cbc5a
movzbl 0x2ff6ee(%rip), %eax    # 0x3cbc5b
addl %ecx, %eax
movb %al, 0x2ff6e6(%rip)     # 0x3cbc5b
leaq 0x2caeba(%rip), %rax    # 0x397436
movw (%rax), %cx
addw $0x1, %cx
leaq 0x2caeac(%rip), %rax    # 0x397436
movw %cx, (%rax)
cmpl $0x0, 0x2ff6d0(%rip)    # 0x3cbc64
jne 0xcc5ae
leaq 0x2cae99(%rip), %rax    # 0x397436
movw (%rax), %cx
addw $0x1, %cx
leaq 0x2cae8b(%rip), %rax    # 0x397436
movw %cx, (%rax)
jmp 0xcc75b
leaq 0x2cae7c(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x6, %eax
jne 0xcc685
leaq 0x2cae65(%rip), %rax    # 0x397432
movzwl (%rax), %eax
cmpl $0x1000, %eax           # imm = 0x1000
jge 0xcc663
movb -0x1(%rbp), %dl
leaq 0x2cae4d(%rip), %rax    # 0x397432
movw (%rax), %ax
movw %ax, %si
addw $0x1, %si
leaq 0x2cae3c(%rip), %rcx    # 0x397432
movw %si, (%rcx)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0x2c9e2b(%rip), %rax    # 0x396430
movb %dl, (%rax,%rcx)
movzbl -0x1(%rbp), %ecx
movzbl 0x2ff647(%rip), %eax    # 0x3cbc5a
addl %ecx, %eax
movb %al, 0x2ff63f(%rip)     # 0x3cbc5a
movzbl 0x2ff638(%rip), %ecx    # 0x3cbc5a
movzbl 0x2ff632(%rip), %eax    # 0x3cbc5b
addl %ecx, %eax
movb %al, 0x2ff62a(%rip)     # 0x3cbc5b
movl 0x2ff62d(%rip), %eax    # 0x3cbc64
addl $-0x1, %eax
movl %eax, 0x2ff624(%rip)    # 0x3cbc64
cmpl $0x0, 0x2ff61d(%rip)    # 0x3cbc64
jne 0xcc661
leaq 0x2cade6(%rip), %rax    # 0x397436
movw (%rax), %cx
addw $0x1, %cx
leaq 0x2cadd8(%rip), %rax    # 0x397436
movw %cx, (%rax)
jmp 0xcc680
leaq 0x1d1ae6(%rip), %rax    # 0x29e150
movl (%rax), %ecx
orl $0x8000, %ecx           # imm = 0x8000
leaq 0x1d1ad7(%rip), %rax    # 0x29e150
movl %ecx, (%rax)
jmp 0xcc72f
jmp 0xcc759
leaq 0x2cadaa(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x7, %eax
jne 0xcc6ba
leaq 0x2cad9b(%rip), %rax    # 0x397436
movw (%rax), %cx
addw $0x1, %cx
leaq 0x2cad8d(%rip), %rax    # 0x397436
movw %cx, (%rax)
movb -0x1(%rbp), %al
movb %al, 0x2ff5a7(%rip)     # 0x3cbc5c
jmp 0xcc757
leaq 0x2cad75(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x8, %eax
jne 0xcc72d
leaq 0x2cad66(%rip), %rax    # 0x397436
movw $0x0, (%rax)
movb -0x1(%rbp), %al
movb %al, 0x2ff57f(%rip)     # 0x3cbc5d
movzbl 0x2ff577(%rip), %eax    # 0x3cbc5c
movzbl 0x2ff56e(%rip), %ecx    # 0x3cbc5a
cmpl %ecx, %eax
jne 0xcc702
movzbl 0x2ff566(%rip), %eax    # 0x3cbc5d
movzbl 0x2ff55d(%rip), %ecx    # 0x3cbc5b
cmpl %ecx, %eax
je 0xcc71c
leaq 0x1d1a47(%rip), %rax    # 0x29e150
movl (%rax), %ecx
orl $0x4000, %ecx           # imm = 0x4000
leaq 0x1d1a38(%rip), %rax    # 0x29e150
movl %ecx, (%rax)
jmp 0xcc72f
callq 0xcbe40
movl $0x1, 0x2fe749(%rip)    # 0x3cae74
jmp 0xcc755
jmp 0xcc72f
leaq 0x2cacfc(%rip), %rax    # 0x397432
movw $0x0, (%rax)
leaq 0x2cacf4(%rip), %rax    # 0x397436
movw $0x0, (%rax)
movb $0x0, 0x2ff50d(%rip)    # 0x3cbc5b
movb $0x0, 0x2ff505(%rip)    # 0x3cbc5a
jmp 0xcc757
jmp 0xcc759
jmp 0xcc75b
jmp 0xcc75d
jmp 0xcc75f
jmp 0xcc761
jmp 0xcc763
jmp 0xcc765
jmp 0xcc767
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax)