// File: jkingan[P]ladyheather/heathgps.cpp
// Function: get_ss_message()
void get_ss_message()
{
u08 c;
static u08 id;
static u08 cid;
static int msg_len;

   // This routine buffers up an incoming Novatel message.  When the end of the
   // message is seen, the message is parsed and decoded with decode_ss_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 SOH
      if(c == 0x01) {      // SOH seen
         tsip_sync = 1;
         get_sync_time();
      }
      tsip_wptr = 0;
      tsip_rptr = 0;
      ss_vfy_cksum = 0;  // the calculated message checksum
      ss_msg_cksum = 0;  // the checksum in the message
      id = 0;
      cid = 0;
      msg_len = 0;
      return;
   }
   else if(tsip_sync == 1) { // SOH has been seen, get message id
      if(tsip_wptr < MAX_TSIP) {   // add char to the message buffer
         ss_vfy_cksum += c;
         tsip_buf[tsip_wptr++] = c;
      }
      else {
         tsip_error |= OVFL_ERROR;
         goto rst_msg;
      }
      id = c;
      ++tsip_sync;
   }
   else if(tsip_sync == 2) { // message id inverted
      if(tsip_wptr < MAX_TSIP) {   // add char to the message buffer
         ss_vfy_cksum += c;
         tsip_buf[tsip_wptr++] = c;
      }
      else {
         tsip_error |= OVFL_ERROR;
         goto rst_msg;
      }
      cid = c ^ 0xFF;
//BEEP(5555);  // piss3
//sprintf(out, "id:%02X(%d)  c:%02X  cinv:%02x    ", id,id, c, cid);
//DEBUGSTR(out);
//refresh_page();
      if(id != cid) goto rst_msg;
      ++tsip_sync;
   }
   else if(tsip_sync == 3) { // message len
      if(tsip_wptr < MAX_TSIP) {   // add char to the message buffer
         ss_vfy_cksum += c;
         tsip_buf[tsip_wptr++] = c;
      }
      else {
         tsip_error |= OVFL_ERROR;
         goto rst_msg;
      }
      msg_len = c;
      ++tsip_sync;
      if(msg_len == 0) ++tsip_sync;
   }
   else if(tsip_sync == 4) { // message body
      if(tsip_wptr < MAX_TSIP) {   // add char to the message buffer
         ss_vfy_cksum += c;
         tsip_buf[tsip_wptr++] = c;
      }
      --msg_len;
      if(msg_len <= 0) ++tsip_sync;
   }
   else if(tsip_sync == 5) {  // low byte of checksum
      ss_msg_cksum = c;
      ++tsip_sync;
   }
   else if(tsip_sync == 6) {  // high byte of checksum
      ss_msg_cksum += ((int) c) * 256;
      if(ss_msg_cksum == ss_vfy_cksum) decode_ss_msg();
      packet_end = 1;
      tsip_sync = 0;
      tsip_wptr = 0;
      tsip_sync = 0;
   }
   else {     // should never happen, prepare for next message
      rst_msg:
      tsip_wptr = 0;
      tsip_sync = 0;
      nmea_vfy_cksum = nmea_msg_cksum = 0; // init received message checksum
      venus_nmea = 0;
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl $0xa, %edi
callq 0xcad0
cmpl $0x0, %eax
jne 0xba566
movl $0xa, %edi
callq 0x2b610
jmp 0xba9bf
movl $0xa, %edi
callq 0x2bd30
callq 0x79fc0
movb %al, -0x1(%rbp)
leaq 0x2b2f41(%rip), %rax    # 0x36d4c0
cmpb $0x0, 0x17a12(%rax)
je 0xba596
leaq 0x2b2f31(%rip), %rax    # 0x36d4c0
movb $0x0, 0x17a12(%rax)
leaq 0x2dce99(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x0, %eax
jne 0xba606
movzbl -0x1(%rbp), %eax
cmpl $0x1, %eax
jne 0xba5bf
leaq 0x2dce81(%rip), %rax    # 0x397436
movw $0x1, (%rax)
callq 0x7a1d0
leaq 0x2dce6c(%rip), %rax    # 0x397432
movw $0x0, (%rax)
leaq 0x2dce62(%rip), %rax    # 0x397434
movw $0x0, (%rax)
movw $0x0, 0x3116b8(%rip)    # 0x3cbc98
movw $0x0, 0x3116b1(%rip)    # 0x3cbc9a
movb $0x0, 0x316a70(%rip)    # 0x3d1060
movb $0x0, 0x316a6a(%rip)    # 0x3d1061
movl $0x0, 0x316a63(%rip)    # 0x3d1064
jmp 0xba9bf
leaq 0x2dce29(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x1, %eax
jne 0xba6b0
leaq 0x2dce12(%rip), %rax    # 0x397432
movzwl (%rax), %eax
cmpl $0x1000, %eax           # imm = 0x1000
jge 0xba66d
movzbl -0x1(%rbp), %ecx
movswl 0x311663(%rip), %eax    # 0x3cbc98
addl %ecx, %eax
movw %ax, 0x31165a(%rip)     # 0x3cbc98
movb -0x1(%rbp), %dl
leaq 0x2dcdea(%rip), %rax    # 0x397432
movw (%rax), %ax
movw %ax, %si
addw $0x1, %si
leaq 0x2dcdd9(%rip), %rcx    # 0x397432
movw %si, (%rcx)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0x2dbdc8(%rip), %rax    # 0x396430
movb %dl, (%rax,%rcx)
jmp 0xba68a
leaq 0x1e3adc(%rip), %rax    # 0x29e150
movl (%rax), %ecx
orl $0x8000, %ecx           # imm = 0x8000
leaq 0x1e3acd(%rip), %rax    # 0x29e150
movl %ecx, (%rax)
jmp 0xba983
movb -0x1(%rbp), %al
movb %al, 0x3169cd(%rip)     # 0x3d1060
leaq 0x2dcd9c(%rip), %rax    # 0x397436
movw (%rax), %cx
addw $0x1, %cx
leaq 0x2dcd8e(%rip), %rax    # 0x397436
movw %cx, (%rax)
jmp 0xba9bd
leaq 0x2dcd7f(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x2, %eax
jne 0xba777
leaq 0x2dcd68(%rip), %rax    # 0x397432
movzwl (%rax), %eax
cmpl $0x1000, %eax           # imm = 0x1000
jge 0xba717
movzbl -0x1(%rbp), %ecx
movswl 0x3115b9(%rip), %eax    # 0x3cbc98
addl %ecx, %eax
movw %ax, 0x3115b0(%rip)     # 0x3cbc98
movb -0x1(%rbp), %dl
leaq 0x2dcd40(%rip), %rax    # 0x397432
movw (%rax), %ax
movw %ax, %si
addw $0x1, %si
leaq 0x2dcd2f(%rip), %rcx    # 0x397432
movw %si, (%rcx)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0x2dbd1e(%rip), %rax    # 0x396430
movb %dl, (%rax,%rcx)
jmp 0xba734
leaq 0x1e3a32(%rip), %rax    # 0x29e150
movl (%rax), %ecx
orl $0x8000, %ecx           # imm = 0x8000
leaq 0x1e3a23(%rip), %rax    # 0x29e150
movl %ecx, (%rax)
jmp 0xba983
movzbl -0x1(%rbp), %eax
xorl $0xff, %eax
movb %al, 0x31691e(%rip)     # 0x3d1061
movzbl 0x316916(%rip), %eax    # 0x3d1060
movzbl 0x316910(%rip), %ecx    # 0x3d1061
cmpl %ecx, %eax
je 0xba75a
jmp 0xba983
leaq 0x2dccd5(%rip), %rax    # 0x397436
movw (%rax), %cx
addw $0x1, %cx
leaq 0x2dccc7(%rip), %rax    # 0x397436
movw %cx, (%rax)
jmp 0xba9bb
leaq 0x2dccb8(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x3, %eax
jne 0xba843
leaq 0x2dcca1(%rip), %rax    # 0x397432
movzwl (%rax), %eax
cmpl $0x1000, %eax           # imm = 0x1000
jge 0xba7de
movzbl -0x1(%rbp), %ecx
movswl 0x3114f2(%rip), %eax    # 0x3cbc98
addl %ecx, %eax
movw %ax, 0x3114e9(%rip)     # 0x3cbc98
movb -0x1(%rbp), %dl
leaq 0x2dcc79(%rip), %rax    # 0x397432
movw (%rax), %ax
movw %ax, %si
addw $0x1, %si
leaq 0x2dcc68(%rip), %rcx    # 0x397432
movw %si, (%rcx)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0x2dbc57(%rip), %rax    # 0x396430
movb %dl, (%rax,%rcx)
jmp 0xba7fb
leaq 0x1e396b(%rip), %rax    # 0x29e150
movl (%rax), %ecx
orl $0x8000, %ecx           # imm = 0x8000
leaq 0x1e395c(%rip), %rax    # 0x29e150
movl %ecx, (%rax)
jmp 0xba983
movzbl -0x1(%rbp), %eax
movl %eax, 0x31685f(%rip)    # 0x3d1064
leaq 0x2dcc2a(%rip), %rax    # 0x397436
movw (%rax), %cx
addw $0x1, %cx
leaq 0x2dcc1c(%rip), %rax    # 0x397436
movw %cx, (%rax)
cmpl $0x0, 0x316840(%rip)    # 0x3d1064
jne 0xba83e
leaq 0x2dcc09(%rip), %rax    # 0x397436
movw (%rax), %cx
addw $0x1, %cx
leaq 0x2dcbfb(%rip), %rax    # 0x397436
movw %cx, (%rax)
jmp 0xba9b9
leaq 0x2dcbec(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x4, %eax
jne 0xba8dd
leaq 0x2dcbd5(%rip), %rax    # 0x397432
movzwl (%rax), %eax
cmpl $0x1000, %eax           # imm = 0x1000
jge 0xba8a8
movzbl -0x1(%rbp), %ecx
movswl 0x311426(%rip), %eax    # 0x3cbc98
addl %ecx, %eax
movw %ax, 0x31141d(%rip)     # 0x3cbc98
movb -0x1(%rbp), %dl
leaq 0x2dcbad(%rip), %rax    # 0x397432
movw (%rax), %ax
movw %ax, %si
addw $0x1, %si
leaq 0x2dcb9c(%rip), %rcx    # 0x397432
movw %si, (%rcx)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0x2dbb8b(%rip), %rax    # 0x396430
movb %dl, (%rax,%rcx)
movl 0x3167b6(%rip), %eax    # 0x3d1064
addl $-0x1, %eax
movl %eax, 0x3167ad(%rip)    # 0x3d1064
cmpl $0x0, 0x3167a6(%rip)    # 0x3d1064
jg 0xba8d8
leaq 0x2dcb6f(%rip), %rax    # 0x397436
movw (%rax), %cx
addw $0x1, %cx
leaq 0x2dcb61(%rip), %rax    # 0x397436
movw %cx, (%rax)
jmp 0xba9b7
leaq 0x2dcb52(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x5, %eax
jne 0xba914
movzbl -0x1(%rbp), %eax
movw %ax, 0x3113a3(%rip)     # 0x3cbc9a
leaq 0x2dcb38(%rip), %rax    # 0x397436
movw (%rax), %cx
addw $0x1, %cx
leaq 0x2dcb2a(%rip), %rax    # 0x397436
movw %cx, (%rax)
jmp 0xba9b5
leaq 0x2dcb1b(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x6, %eax
jne 0xba981
movzbl -0x1(%rbp), %ecx
shll $0x8, %ecx
movswl 0x311369(%rip), %eax    # 0x3cbc9a
addl %ecx, %eax
movw %ax, 0x311360(%rip)     # 0x3cbc9a
movswl 0x311359(%rip), %eax    # 0x3cbc9a
movswl 0x311350(%rip), %ecx    # 0x3cbc98
cmpl %ecx, %eax
jne 0xba951
callq 0xba250
movl $0x1, 0x310519(%rip)    # 0x3cae74
leaq 0x2dcad4(%rip), %rax    # 0x397436
movw $0x0, (%rax)
leaq 0x2dcac4(%rip), %rax    # 0x397432
movw $0x0, (%rax)
leaq 0x2dcabc(%rip), %rax    # 0x397436
movw $0x0, (%rax)
jmp 0xba9b3
jmp 0xba983
leaq 0x2dcaa8(%rip), %rax    # 0x397432
movw $0x0, (%rax)
leaq 0x2dcaa0(%rip), %rax    # 0x397436
movw $0x0, (%rax)
movb $0x0, 0x3112f3(%rip)    # 0x3cbc95
movb $0x0, 0x3112eb(%rip)    # 0x3cbc94
movl $0x0, 0x311311(%rip)    # 0x3cbcc4
jmp 0xba9b5
jmp 0xba9b7
jmp 0xba9b9
jmp 0xba9bb
jmp 0xba9bd
jmp 0xba9bf
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)