// File: /workspace/github_cpp_makefile_star2_O2/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
pushq $0xa
popq %rdi
callq 0xb771
pushq $0xa
popq %rdi
testl %eax, %eax
je 0x92818
callq 0x1d93f
movzbl 0x2c97f8(%rip), %eax    # 0x35bfe0
movl %eax, 0xc1e42(%rip)     # 0x154630
callq 0x51891
movb %al, 0x2c97e7(%rip)     # 0x35bfe0
movl 0x2c97e9(%rip), %ecx    # 0x35bfe8
cmpl $0x1, %ecx
jne 0x9282c
cmpl $0x35, %eax
jne 0x92823
movl $0x2, 0x2c97d5(%rip)    # 0x35bfe8
pushq $0x2
popq %rcx
jmp 0x92838
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x1d61b
andl $0x0, 0x2c97be(%rip)    # 0x35bfe8
xorl %ecx, %ecx
cmpl $0xd, %eax
jne 0x92838
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
cmpl $0x0, 0x2c77a5(%rip)    # 0x359fe4
je 0x9284f
movzbl %al, %edi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x91ea5
cmpl $0x0, 0x2c7796(%rip)    # 0x359fec
je 0x92866
movzbl %al, %edi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x9257f
leaq 0x265a73(%rip), %rdx    # 0x2f82e0
cmpb $0x0, 0x17a12(%rdx)
je 0x9287d
movb $0x0, 0x17a12(%rdx)
cmpb $0x1, 0x2c9760(%rip)    # 0x35bfe4
jne 0x928d3
movb $0x0, 0x2c9757(%rip)    # 0x35bfe4
cmpb $0xa, %al
je 0x928d3
movzbl %al, %edx
cmpl $0x20, %edx
je 0x92831
leaq 0x28f9b2(%rip), %rsi    # 0x322252
movzwl (%rsi), %edx
cmpq $0xffe, %rdx            # imm = 0xFFE
ja 0x928d3
leaq 0x1(%rdx), %rcx
movw %cx, (%rsi)
leaq 0x28e996(%rip), %rcx    # 0x321250
movb %al, (%rcx,%rdx)
movb $0x0, 0x1(%rcx,%rdx)
leaq 0x28f98d(%rip), %rax    # 0x322256
movw $0x1, (%rax)
jmp 0x92831
leaq 0x28f97c(%rip), %rbx    # 0x322256
movzwl (%rbx), %edx
cmpl $0x2, %edx
je 0x9295c
cmpl $0x1, %edx
je 0x92916
testl %edx, %edx
jne 0x92a58
cmpl $0x3e, %eax
je 0x92999
andb $-0x21, %al
cmpb $0x43, %al
jne 0x92999
movw $0x2, (%rbx)
movl $0x1, 0x2c96d7(%rip)    # 0x35bfe8
jmp 0x9299e
cmpb $0xa, %al
je 0x92a58
movzbl %al, %edx
cmpl $0x3e, %edx
jne 0x929fc
callq 0x91733
movl $0x1, 0x2c335b(%rip)    # 0x355c94
movb $0x1, 0x2c96a4(%rip)    # 0x35bfe4
movw $0x1, (%rbx)
leaq 0x28f908(%rip), %rax    # 0x322254
andw $0x0, (%rax)
leaq 0x28f8fb(%rip), %rax    # 0x322252
jmp 0x92a8d
cmpl $0x35, %eax
jne 0x929f3
leaq 0x28f8e6(%rip), %rcx    # 0x322252
movzwl (%rcx), %eax
cmpq $0xffd, %rax            # imm = 0xFFD
ja 0x92831
leaq 0x28e8ce(%rip), %rdx    # 0x321250
movb $0x43, (%rdx,%rax)
leaq 0x2(%rax), %rsi
movw %si, (%rcx)
movb $0x35, 0x1(%rax,%rdx)
movb $0x0, 0x2(%rdx,%rax)
jmp 0x929e9
movw $0x1, (%rbx)
callq 0x51a2f
movl 0xc1c87(%rip), %eax     # 0x154630
cmpl $0xd, %eax
je 0x929b7
cmpl $0xa, %eax
jne 0x92a7b
leaq 0x28f894(%rip), %rcx    # 0x322252
movzwl (%rcx), %eax
cmpq $0xffe, %rax            # imm = 0xFFE
ja 0x92831
movb 0x2c960d(%rip), %dl     # 0x35bfe0
leaq 0x1(%rax), %rsi
movw %si, (%rcx)
leaq 0x28e86f(%rip), %rcx    # 0x321250
movb %dl, (%rcx,%rax)
movb $0x0, 0x1(%rcx,%rax)
movw $0x1, (%rbx)
jmp 0x92831
andw $0x0, (%rbx)
jmp 0x92831
leaq 0x28f84f(%rip), %rsi    # 0x322252
movzwl (%rsi), %edx
cmpq $0xffe, %rdx            # imm = 0xFFE
ja 0x92a77
leaq 0x1(%rdx), %rdi
movw %di, (%rsi)
leaq 0x28e833(%rip), %rsi    # 0x321250
movb %al, (%rsi,%rdx)
movb $0x0, 0x1(%rsi,%rdx)
testl %ecx, %ecx
je 0x92831
movl $0x63, 0xc1bf9(%rip)    # 0x154630
cmpl $0x61, %eax
jne 0x92831
leaq 0x28e809(%rip), %rdi    # 0x321250
callq 0x9120
cmpq $0x82, %rax
jbe 0x92831
callq 0x91733
andw $0x0, (%rbx)
movl $0x1, 0x2c3229(%rip)    # 0x355c94
andl $0x0, 0x2c9576(%rip)    # 0x35bfe8
jmp 0x92831
andw $0x0, (%rbx)
leaq 0x28f7d0(%rip), %rax    # 0x322252
andw $0x0, (%rax)
leaq 0x28f7c7(%rip), %rax    # 0x322254
andw $0x0, (%rax)
jmp 0x92831