// File: jkingan[P]ladyheather/heathgps.cpp
// Function: get_scpi_message()
void get_scpi_message()
{
u08 c;
static int row = 0;

   // This routine buffers up an incomming SCPI message.  When the end of the
   // message is seen, the message is parsed and decoded with decode_scpi_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(scpi_status) {   // we are reading the SYST:STAT? results
      get_scpi_status(c);
      return;
   }

   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 '$'
      if(c == '>') {
         tsip_sync = 1;
         get_sync_time();
      }

      rst_msg:
      tsip_wptr = 0;
      tsip_rptr = 0;
      return;
   }
   else if(tsip_sync == 1) { // '>' has been seen, now build the message
      if(c == 0x0D) goto scpi_end; 
      else if(c == 0x0A) goto scpi_end; 
      else if(c == '>')  {  // null response to SCPI command
         decode_scpi_msg();
         packet_end = 1;
         tsip_sync = 1; 
         tsip_rptr = 0;
         tsip_wptr = 0;
         return;
      }

      if(tsip_wptr < MAX_TSIP) {  // so add it to the message buffer
         tsip_buf[tsip_wptr++] = c;
      }
      else {
         tsip_sync = 0;
         goto rst_msg;
      }
   }
   else {
      scpi_end:
      decode_scpi_msg();
      packet_end = 1;
      tsip_sync = 0;
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl $0xa, %edi
callq 0xcad0
cmpl $0x0, %eax
jne 0xd98e6
movl $0xa, %edi
callq 0x2b610
jmp 0xd9a58
movl $0xa, %edi
callq 0x2bd30
callq 0x79fc0
movb %al, -0x1(%rbp)
cmpl $0x0, 0x2f58b5(%rip)    # 0x3cf1b4
je 0xd990f
movzbl -0x1(%rbp), %edi
callq 0xd9720
jmp 0xd9a58
leaq 0x293baa(%rip), %rax    # 0x36d4c0
cmpb $0x0, 0x17a12(%rax)
je 0xd992d
leaq 0x293b9a(%rip), %rax    # 0x36d4c0
movb $0x0, 0x17a12(%rax)
leaq 0x2bdb02(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x0, %eax
jne 0xd9975
movzbl -0x1(%rbp), %eax
cmpl $0x3e, %eax
jne 0xd9956
leaq 0x2bdaea(%rip), %rax    # 0x397436
movw $0x1, (%rax)
callq 0x7a1d0
jmp 0xd9958
leaq 0x2bdad3(%rip), %rax    # 0x397432
movw $0x0, (%rax)
leaq 0x2bdac9(%rip), %rax    # 0x397434
movw $0x0, (%rax)
jmp 0xd9a58
leaq 0x2bdaba(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x1, %eax
jne 0xd9a39
movzbl -0x1(%rbp), %eax
cmpl $0xd, %eax
jne 0xd9996
jmp 0xd9a3b
movzbl -0x1(%rbp), %eax
cmpl $0xa, %eax
jne 0xd99a4
jmp 0xd9a3b
movzbl -0x1(%rbp), %eax
cmpl $0x3e, %eax
jne 0xd99e2
callq 0xd8a20
movl $0x1, 0x2f14b8(%rip)    # 0x3cae74
leaq 0x2bda73(%rip), %rax    # 0x397436
movw $0x1, (%rax)
leaq 0x2bda65(%rip), %rax    # 0x397434
movw $0x0, (%rax)
leaq 0x2bda57(%rip), %rax    # 0x397432
movw $0x0, (%rax)
jmp 0xd9a58
jmp 0xd99e4
jmp 0xd99e6
leaq 0x2bda45(%rip), %rax    # 0x397432
movzwl (%rax), %eax
cmpl $0x1000, %eax           # imm = 0x1000
jge 0xd9a26
movb -0x1(%rbp), %dl
leaq 0x2bda31(%rip), %rax    # 0x397432
movw (%rax), %ax
movw %ax, %si
addw $0x1, %si
leaq 0x2bda20(%rip), %rcx    # 0x397432
movw %si, (%rcx)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0x2bca0f(%rip), %rax    # 0x396430
movb %dl, (%rax,%rcx)
jmp 0xd9a37
leaq 0x2bda09(%rip), %rax    # 0x397436
movw $0x0, (%rax)
jmp 0xd9958
jmp 0xd9a56
jmp 0xd9a3b
callq 0xd8a20
movl $0x1, 0x2f142a(%rip)    # 0x3cae74
leaq 0x2bd9e5(%rip), %rax    # 0x397436
movw $0x0, (%rax)
jmp 0xd9a58
addq $0x10, %rsp
popq %rbp
retq
nop