// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathgps.cpp
// Function: get_uccm_message()
void get_uccm_message()
{
static u08 c = 0;   // samsung
static int row = 0;
static int last_uccm_c = 0x0D;
static int null_decode = 0;
static int time_msg = 0;

   // This routine buffers up an incoming UCCM message.  When the end of the
   // message is seen, the message is parsed and decoded with decode_uccm_msg()

   if(SERIAL_DATA_AVAILABLE(RCVR_PORT) == 0) {
      check_com_timer(RCVR_PORT);
      return;
   }
   else {
      reset_com_timer(RCVR_PORT);
   }

   last_uccm_c = c;
   c = get_com_char();
   if(time_msg == 1) {
      if(c != '5') time_msg = 0;
      else time_msg = 2;
   }
   if(c == 0x0D) return; // samsung

   if(scpi_status) {    // we are reading the SYST:STAT? results
      get_uccm_status(c);
      return;
   }
   else if(uccm_loop) {  // we are reading the UCCM LOOP results
      get_uccm_loop(c);
      return;
   }

   if(com[RCVR_PORT].rcv_error) {      // parity/framing/overrun errors
      com[RCVR_PORT].rcv_error = 0;
//!!!!!qqqq    goto rst_msg;
   }

if(null_decode) {
   null_decode = 0;
   if(c == 0x0A) ;
   else if(c == 0x0D) ;
   else if(c == ' ') return;
   else if(tsip_wptr < (MAX_TSIP-1)) {  // so add it to the message buffer
      tsip_buf[tsip_wptr++] = c;
      tsip_buf[tsip_wptr] = 0;
      tsip_sync = 1;
      return;
   }
}

   if(tsip_sync == 0) {    // syncing to start of message, search for a '>'
      if(c == '>') {
         tsip_sync = 1;
         get_sync_time();
      }
      else if((c == 'C') || (c == 'c')) {
         tsip_sync = 2; // maybe the time field?
         time_msg = 1;
         get_sync_time();
      }
      else {
         tsip_sync = 1;
         get_sync_time();
      }
if((last_uccm_c == 0x0A) || (last_uccm_c == 0x0D)) {   // samsung
   if(tsip_wptr < (MAX_TSIP-1)) {  // so add it to the message buffer
      tsip_buf[tsip_wptr++] = c;
      tsip_buf[tsip_wptr] = 0;
      tsip_sync = 1;
   }
   return;
}

      rst_msg:
      tsip_wptr = 0;
      tsip_rptr = 0;
      return;
   }
   else if(tsip_sync == 1) { // '>' has been seen, now build the message
      if(c == 0x0A) goto uccm_end; 
      else if(c == 0x0D)  goto uccm_end; 
      else if(c == '>')  {  // null response to UCCM command
         decode_uccm_msg(1);
         packet_end = 1;
         null_decode = 1;  // put next char in tsip_bug
         tsip_sync = 1;
         tsip_rptr = 0;
         tsip_wptr = 0;
         return;
      }


      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_sync = 0;
         goto rst_msg;
      }
if(time_msg && (last_uccm_c = 'c') && (c == 'a')) {  // samsung does not end time message with 0x0D 0x0A
   if(strlen((char *) tsip_buf) > 130) {
      goto uccm_end;
   }
}
   }
   else if(tsip_sync == 2) {  // C5 timecode message
      if(c == '5') {
         if(tsip_wptr < (MAX_TSIP-2)) {  // so add it to the message buffer
            tsip_buf[tsip_wptr++] = 'C';
            tsip_buf[tsip_wptr++] = '5';
            tsip_buf[tsip_wptr] = 0;
            tsip_sync = 1;
         }
      }
      else tsip_sync = 0;
   }
   else {
      uccm_end:
//if(debug_file) fprintf(debug_file, "Got:: {%s}\n", tsip_buf);
      decode_uccm_msg(2);
      packet_end = 1;
      tsip_sync = 0;
      time_msg = 0;
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movl $0xa, %edi
callq 0xb9ad
movl $0xa, %edi
testl %eax, %eax
je 0xa19cd
callq 0x1ea0b
movzbl 0x2d0645(%rip), %eax    # 0x371fe0
movl %eax, 0xc8c8f(%rip)     # 0x16a630
callq 0x584bd
movb %al, 0x2d0634(%rip)     # 0x371fe0
movl 0x2d0636(%rip), %ecx    # 0x371fe8
cmpl $0x1, %ecx
jne 0xa19e4
cmpl $0x35, %eax
jne 0xa19d8
movl $0x2, 0x2d0622(%rip)    # 0x371fe8
movl $0x2, %ecx
jmp 0xa19f0
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x1e66a
movl $0x0, 0x2d0606(%rip)    # 0x371fe8
xorl %ecx, %ecx
cmpl $0xd, %eax
jne 0xa19f0
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
cmpl $0x0, 0x2ce5ed(%rip)    # 0x36ffe4
je 0xa1a07
movzbl %al, %edi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0xa1005
cmpl $0x0, 0x2ce5de(%rip)    # 0x36ffec
je 0xa1a1e
movzbl %al, %edi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0xa1723
leaq 0x26c8bb(%rip), %rdx    # 0x30e2e0
cmpb $0x0, 0x17a12(%rdx)
je 0xa1a35
movb $0x0, 0x17a12(%rdx)
cmpb $0x1, 0x2d05a8(%rip)    # 0x371fe4
jne 0xa1a8b
movb $0x0, 0x2d059f(%rip)    # 0x371fe4
cmpb $0xa, %al
je 0xa1a8b
movzbl %al, %edx
cmpl $0x20, %edx
je 0xa19e9
leaq 0x2967fa(%rip), %rsi    # 0x338252
movzwl (%rsi), %edx
cmpq $0xffe, %rdx            # imm = 0xFFE
ja 0xa1a8b
leaq 0x1(%rdx), %rcx
movw %cx, (%rsi)
leaq 0x2957de(%rip), %rcx    # 0x337250
movb %al, (%rcx,%rdx)
movb $0x0, 0x1(%rcx,%rdx)
leaq 0x2967d5(%rip), %rax    # 0x338256
movw $0x1, (%rax)
jmp 0xa19e9
leaq 0x2967c4(%rip), %rbx    # 0x338256
movzwl (%rbx), %edx
cmpl $0x2, %edx
je 0xa1b15
cmpl $0x1, %edx
je 0xa1ace
testl %edx, %edx
jne 0xa1c12
cmpl $0x3e, %eax
je 0xa1b52
andb $-0x21, %al
cmpb $0x43, %al
jne 0xa1b52
movw $0x2, (%rbx)
movl $0x1, 0x2d051f(%rip)    # 0x371fe8
jmp 0xa1b57
cmpb $0xa, %al
je 0xa1c12
movzbl %al, %edx
cmpl $0x3e, %edx
jne 0xa1bb6
callq 0xa07d1
movl $0x1, 0x2ca1a3(%rip)    # 0x36bc94
movb $0x1, 0x2d04ec(%rip)    # 0x371fe4
movw $0x1, (%rbx)
leaq 0x296750(%rip), %rax    # 0x338254
xorl %ecx, %ecx
movw %cx, (%rax)
leaq 0x296742(%rip), %rax    # 0x338252
jmp 0xa1c4d
cmpl $0x35, %eax
jne 0xa1bac
leaq 0x29672d(%rip), %rcx    # 0x338252
movzwl (%rcx), %eax
cmpq $0xffd, %rax            # imm = 0xFFD
ja 0xa19e9
leaq 0x295715(%rip), %rdx    # 0x337250
movb $0x43, (%rdx,%rax)
leaq 0x2(%rax), %rsi
movw %si, (%rcx)
movb $0x35, 0x1(%rax,%rdx)
movb $0x0, 0x2(%rdx,%rax)
jmp 0xa1ba2
movw $0x1, (%rbx)
callq 0x58672
movl 0xc8ace(%rip), %eax     # 0x16a630
cmpl $0xd, %eax
je 0xa1b70
cmpl $0xa, %eax
jne 0xa1c3a
leaq 0x2966db(%rip), %rcx    # 0x338252
movzwl (%rcx), %eax
cmpq $0xffe, %rax            # imm = 0xFFE
ja 0xa19e9
movb 0x2d0454(%rip), %dl     # 0x371fe0
leaq 0x1(%rax), %rsi
movw %si, (%rcx)
leaq 0x2956b6(%rip), %rcx    # 0x337250
movb %dl, (%rcx,%rax)
movb $0x0, 0x1(%rcx,%rax)
movw $0x1, (%rbx)
jmp 0xa19e9
movw $0x0, (%rbx)
jmp 0xa19e9
leaq 0x296695(%rip), %rsi    # 0x338252
movzwl (%rsi), %edx
cmpq $0xffe, %rdx            # imm = 0xFFE
ja 0xa1c35
leaq 0x1(%rdx), %rdi
movw %di, (%rsi)
leaq 0x295679(%rip), %rsi    # 0x337250
movb %al, (%rsi,%rdx)
movb $0x0, 0x1(%rsi,%rdx)
testl %ecx, %ecx
je 0xa19e9
movl $0x63, 0xc8a3f(%rip)    # 0x16a630
cmpl $0x61, %eax
jne 0xa19e9
leaq 0x29564f(%rip), %rdi    # 0x337250
callq 0x9120
cmpq $0x82, %rax
jbe 0xa19e9
callq 0xa07d1
movl $0x1, 0x2ca073(%rip)    # 0x36bc94
movw $0x0, (%rbx)
movl $0x0, 0x2d03b8(%rip)    # 0x371fe8
jmp 0xa19e9
movw $0x0, (%rbx)
leaq 0x296611(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
leaq 0x296607(%rip), %rax    # 0x338254
movw %cx, (%rax)
jmp 0xa19e9