// File: /workspace/github_cpp_makefile_star2_O1/jkingan[P]ladyheather/heathgps.cpp
// Function: get_rftg_message()
void get_rftg_message()
{
u08 c;
int i;
static int colon = 0;
char s[3];  // used to calculate message cksum

   // this routine buffers up an incoming TSIP message and then parses it
   // when it is complete.

   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 DLE
      if(c == DLE) {
         tsip_sync = 1;
         get_sync_time();
         colon = 0;
      }
      else if(c == ':') {
         tsip_sync = 1;
         get_sync_time();
         colon = 1;
      }

      nmea_vfy_cksum = 0;
      nmea_msg_cksum = 0;
      tsip_wptr = 0;
      tsip_rptr = 0;
      return;
   }
   else if(tsip_sync == 1) {    // DLE had been seen, now checking next byte
      if(c == DLE) {            // DLE DLE is a 0x10 data byte
         goto rst_msg;
      }
      else if(c == ETX) {       // DLE ETX is end-of-message
         goto rst_msg;          // ... should never happen here
      }
      else if(colon) {
         if((c == '0') || (c == '1')) {
            goto get_msg;
         }
         else goto rst_msg;
      }
      else {                    // DLE xx is message start
         get_msg:
         tsip_sync = 2;         // ... so accumulate the message
         if(tsip_wptr < (MAX_TSIP-1)) {
            tsip_buf[tsip_wptr++] = c;
            tsip_buf[tsip_wptr] = 0;
         }
         else {                 // buffer overlow
            tsip_error |= OVFL_ERROR;
            goto rst_msg;
         }
      }
   }
   else if(tsip_sync == 2) {    // buffer up the message
      if(colon && (c == 0x0D)) {
         tsip_sync = 3;
         if(tsip_wptr < (MAX_TSIP-1)) {
            tsip_buf[tsip_wptr++] = 0;
            tsip_buf[tsip_wptr] = 0;
         }
         else {
            goto rst_msg;
         }
      }
      else if(c == DLE) {
         tsip_sync = 3;
      }
      else if(tsip_wptr < (MAX_TSIP-1)) {
         tsip_buf[tsip_wptr++] = c;
         tsip_buf[tsip_wptr] = 0;
      }
      else {
         tsip_error |= OVFL_ERROR;
         goto rst_msg;
      }
   }
   else if(tsip_sync == 3) {   // last char was a DLE
      if(colon) {
         nmea_vfy_cksum = 0;
         for(i=0; i<22; i+=2) {
            s[0] = tsip_buf[i];
            s[1] = tsip_buf[i+1];
            s[2] = 0;
            nmea_vfy_cksum += atohex(s);
         }
         nmea_vfy_cksum &= 0xFF;

         i = atohex((char *) &tsip_buf[22]) & 0xFF;
         if(nmea_vfy_cksum == i) {
            parse_rftg_time();
         }
         goto rst_msg;
      }
      else if(c == ETX) {           // DLE ETX is end-of-message
         decode_rftg_message(); // so process the buffered message
         packet_end = 1;

         rst_msg:
         tsip_wptr = 0;
         tsip_sync = 0;
      }
      else {                   // DLE DLE is a DLE data byte and DLE xx is message ID
         if(tsip_wptr < (MAX_TSIP-1)) {  // so add it to the message buffer
            tsip_buf[tsip_wptr++] = c;
            tsip_buf[tsip_wptr] = 0;
         }
         else {
            tsip_error |= OVFL_ERROR;
            goto rst_msg;
         }
         tsip_sync = 2;
      }
   }
   else {     // should never happen
      goto rst_msg;
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movl $0xa, %edi
callq 0xb9c3
movl $0xa, %edi
testl %eax, %eax
je 0x8999b
callq 0x1ea2c
callq 0x584d5
leaq 0x284993(%rip), %rcx    # 0x30e2e0
cmpb $0x0, 0x17a12(%rcx)
je 0x8995d
movb $0x0, 0x17a12(%rcx)
leaq 0x2ae8f2(%rip), %r15    # 0x338256
movzwl (%r15), %ecx
cmpq $0x3, %rcx
ja 0x89b63
leaq 0x9589f(%rip), %rdx     # 0x11f218
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
cmpl $0x10, %eax
je 0x89af0
cmpl $0x3a, %eax
jne 0x89b03
movb $0x1, %bl
jmp 0x89af2
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x1e6a0
cmpl $0xd, %eax
jne 0x89a95
testb $0x1, 0x2e84cc(%rip)    # 0x371e88
je 0x89a95
movw $0x3, (%r15)
leaq 0x2ae883(%rip), %rcx    # 0x338252
movzwl (%rcx), %eax
cmpq $0xffe, %rax            # imm = 0xFFE
ja 0x89b63
leal 0x1(%rax), %edx
movw %dx, (%rcx)
leaq 0x2ad865(%rip), %rcx    # 0x337250
movw $0x0, (%rcx,%rax)
jmp 0x89b73
cmpb $0x1, 0x2e848b(%rip)    # 0x371e88
jne 0x89aa5
movb $0x0, 0x2e30aa(%rip)    # 0x36cab4
movq $-0x2, %r12
leaq 0x2ad838(%rip), %rbx    # 0x337250
leaq -0x23(%rbp), %r14
movzwl 0x2(%rbx,%r12), %eax
movw %ax, -0x23(%rbp)
movb $0x0, -0x21(%rbp)
movq %r14, %rdi
callq 0x98c6
addb %al, 0x2e307c(%rip)     # 0x36cab4
addq $0x2, %r12
cmpq $0x14, %r12
jb 0x89a1c
addq $0x16, %rbx
movq %rbx, %rdi
callq 0x98c6
cmpb %al, 0x2e3060(%rip)     # 0x36cab4
jne 0x89b63
callq 0x89291
jmp 0x89b63
cmpl $0x3, %eax
je 0x89b63
cmpl $0x10, %eax
je 0x89b63
movl %eax, %ecx
andl $-0x2, %ecx
cmpl $0x30, %ecx
je 0x89a8d
testb $0x1, 0x2e8401(%rip)    # 0x371e88
jne 0x89b63
movw $0x2, (%r15)
jmp 0x89abe
cmpl $0x10, %eax
jne 0x89abe
movw $0x3, (%r15)
jmp 0x89b73
cmpl $0x3, %eax
jne 0x89b27
callq 0x89634
movl $0x1, 0x2e21db(%rip)    # 0x36bc94
jmp 0x89b63
leaq 0x2ae78d(%rip), %rdx    # 0x338252
movzwl (%rdx), %ecx
cmpq $0xffe, %rcx            # imm = 0xFFE
ja 0x89b58
leaq 0x1(%rcx), %rsi
movw %si, (%rdx)
leaq 0x2ad76d(%rip), %rdx    # 0x337250
movb %al, (%rdx,%rcx)
movb $0x0, 0x1(%rdx,%rcx)
jmp 0x89b73
xorl %ebx, %ebx
movw $0x1, (%r15)
callq 0x58682
movb %bl, 0x2e8385(%rip)     # 0x371e88
xorl %eax, %eax
movb %al, 0x2e2fa9(%rip)     # 0x36cab4
movb %al, 0x2e2fa4(%rip)     # 0x36cab5
leaq 0x2ae73a(%rip), %rcx    # 0x338252
movw %ax, (%rcx)
leaq 0x2ae732(%rip), %rcx    # 0x338254
movw %ax, (%rcx)
jmp 0x89b73
leaq 0x2ae724(%rip), %rdx    # 0x338252
movzwl (%rdx), %ecx
cmpq $0xffe, %rcx            # imm = 0xFFE
ja 0x89b58
leaq 0x1(%rcx), %rsi
movw %si, (%rdx)
leaq 0x2ad708(%rip), %rdx    # 0x337250
movb %al, (%rdx,%rcx)
movb $0x0, 0x1(%rdx,%rcx)
movw $0x2, (%r15)
jmp 0x89b73
leaq 0x1b5411(%rip), %rax    # 0x23ef70
orb $-0x80, 0x1(%rax)
leaq 0x2ae6e8(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
movw %cx, (%r15)
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq