// File: /workspace/github_cpp_makefile_star2_O1/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 0xb9c3
movl $0xa, %edi
testl %eax, %eax
je 0xa17bf
callq 0x1ea2c
movzbl 0x2d0857(%rip), %eax    # 0x371fe0
movl %eax, 0xc8ea1(%rip)     # 0x16a630
callq 0x584d5
movb %al, 0x2d0846(%rip)     # 0x371fe0
cmpl $0x1, 0x2d0847(%rip)    # 0x371fe8
jne 0xa17b3
xorl %ecx, %ecx
cmpl $0x35, %eax
sete %cl
addl %ecx, %ecx
movl %ecx, 0x2d0835(%rip)    # 0x371fe8
cmpl $0xd, %eax
jne 0xa17ca
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x1e6a0
cmpl $0x0, 0x2ce813(%rip)    # 0x36ffe4
je 0xa17e1
movzbl %al, %edi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0xa0df2
cmpl $0x0, 0x2ce804(%rip)    # 0x36ffec
je 0xa17f8
movzbl %al, %edi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0xa1518
leaq 0x26cae1(%rip), %rcx    # 0x30e2e0
cmpb $0x0, 0x17a12(%rcx)
je 0xa180f
movb $0x0, 0x17a12(%rcx)
cmpb $0x1, 0x2d07ce(%rip)    # 0x371fe4
jne 0xa186a
movb $0x0, 0x2d07c5(%rip)    # 0x371fe4
cmpb $0xa, %al
je 0xa186a
movzbl %al, %ecx
cmpl $0xd, %ecx
je 0xa186a
cmpl $0x20, %ecx
je 0xa17b8
leaq 0x296a1b(%rip), %rdx    # 0x338252
movzwl (%rdx), %ecx
cmpq $0xffe, %rcx            # imm = 0xFFE
ja 0xa186a
leaq 0x1(%rcx), %rsi
movw %si, (%rdx)
leaq 0x2959ff(%rip), %rdx    # 0x337250
movb %al, (%rdx,%rcx)
movb $0x0, 0x1(%rdx,%rcx)
leaq 0x2969f6(%rip), %rax    # 0x338256
movw $0x1, (%rax)
jmp 0xa17b8
leaq 0x2969e5(%rip), %rbx    # 0x338256
movzwl (%rbx), %ecx
cmpl $0x2, %ecx
je 0xa1901
cmpl $0x1, %ecx
je 0xa18b1
testl %ecx, %ecx
jne 0xa1a0a
cmpl $0x3e, %eax
je 0xa1945
andb $-0x21, %al
cmpb $0x43, %al
jne 0xa1945
movw $0x2, (%rbx)
movl $0x1, 0x2d073c(%rip)    # 0x371fe8
jmp 0xa194a
cmpb $0xa, %al
je 0xa1a0a
movzbl %al, %ecx
cmpl $0xd, %ecx
je 0xa1a0a
cmpl $0x3e, %ecx
jne 0xa19a9
callq 0xa05bf
movl $0x1, 0x2ca3b7(%rip)    # 0x36bc94
movb $0x1, 0x2d0700(%rip)    # 0x371fe4
movw $0x1, (%rbx)
leaq 0x296964(%rip), %rax    # 0x338254
xorl %ecx, %ecx
movw %cx, (%rax)
leaq 0x296956(%rip), %rax    # 0x338252
jmp 0xa1a45
cmpl $0x35, %eax
jne 0xa199f
leaq 0x296941(%rip), %rcx    # 0x338252
movzwl (%rcx), %eax
cmpq $0xffd, %rax            # imm = 0xFFD
ja 0xa17b8
leaq 0x1(%rax), %rdx
movw %dx, (%rcx)
leaq 0x295922(%rip), %rdx    # 0x337250
movb $0x43, (%rdx,%rax)
leaq 0x2(%rax), %rsi
movw %si, (%rcx)
movb $0x35, 0x1(%rdx,%rax)
movb $0x0, 0x2(%rdx,%rax)
jmp 0xa1995
movw $0x1, (%rbx)
callq 0x58682
movl 0xc8cdb(%rip), %eax     # 0x16a630
cmpl $0xd, %eax
je 0xa1963
cmpl $0xa, %eax
jne 0xa1a32
leaq 0x2968e8(%rip), %rcx    # 0x338252
movzwl (%rcx), %eax
cmpq $0xffe, %rax            # imm = 0xFFE
ja 0xa17b8
movb 0x2d0661(%rip), %dl     # 0x371fe0
leaq 0x1(%rax), %rsi
movw %si, (%rcx)
leaq 0x2958c3(%rip), %rcx    # 0x337250
movb %dl, (%rcx,%rax)
movb $0x0, 0x1(%rcx,%rax)
movw $0x1, (%rbx)
jmp 0xa17b8
movw $0x0, (%rbx)
jmp 0xa17b8
leaq 0x2968a2(%rip), %rdx    # 0x338252
movzwl (%rdx), %ecx
cmpq $0xffe, %rcx            # imm = 0xFFE
ja 0xa1a2d
leaq 0x1(%rcx), %rsi
movw %si, (%rdx)
leaq 0x295886(%rip), %rdx    # 0x337250
movb %al, (%rdx,%rcx)
movb $0x0, 0x1(%rdx,%rcx)
cmpl $0x0, 0x2d060f(%rip)    # 0x371fe8
je 0xa17b8
movl $0x63, 0xc8c47(%rip)    # 0x16a630
cmpl $0x61, %eax
jne 0xa17b8
leaq 0x295857(%rip), %rdi    # 0x337250
callq 0x9120
cmpq $0x82, %rax
jbe 0xa17b8
callq 0xa05bf
movl $0x1, 0x2ca27b(%rip)    # 0x36bc94
movw $0x0, (%rbx)
movl $0x0, 0x2d05c0(%rip)    # 0x371fe8
jmp 0xa17b8
movw $0x0, (%rbx)
leaq 0x296819(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
leaq 0x29680f(%rip), %rax    # 0x338254
movw %cx, (%rax)
jmp 0xa17b8