// File: jkingan[P]ladyheather/heathgps.cpp
// Function: decode_scpi_msg()
void decode_scpi_msg()
{
char c;
int i;

   start_msg_decode(0);

   nmea_msg[0] = 0;
   for(i=0; i<tsip_wptr; i++) {  // copy message from tsip buffer to nmea buffer
      c = tsip_byte();
      nmea_msg[i] = c;
      nmea_msg[i+1] = 0;
      if(i >= ((int)sizeof(nmea_msg)-12)) break;
   }

   tsip_wptr = tsip_rptr = 0;
   tsip_sync = 0;

   // get the response from the reciver and pass it to (HOPEFULLY) the routine
   // that expects it...

   strupr(nmea_msg);

if(debug_file) fprintf(debug_file, "Decode msg %d:[%s]\n", polled_msg_id, nmea_msg);
   if((polled_msg_id == SCPI_CLS_MSG) && strstr(nmea_msg, "*CLS")) {  // receiver is echoing
      scpi_echo_mode = 1;
   }

if(1 && detect_rcvr_type && scpi_echo_mode && (com[RCVR_PORT].baud_rate == 9600)) {
   rcvr_type = CS_RCVR;
   polled_q_in = polled_q_out = 0;
   config_rcvr_type(0);
   need_msg_init = 2020;
   scpi_echo_mode = 1;
   scpi_type_changed = CS_RCVR;
   config_screen(8734);
   if(debug_file) fprintf(debug_file, "### switching to HP-5071A mode\n");
   return;
}

   if(nmea_msg[0] == ' ') {
      i = 1;
      if((nmea_msg[i] == 'E') && (nmea_msg[i+1] == '-')) {  // message returned error
         queue_scpi_cmd("*CLS", SCPI_CLS_MSG);  // reset the error
         scpi_msg_id = 0;
         poll_next_scpi();
         return;
      }
      else if((nmea_msg[i] == 'E') && (nmea_msg[i+1] == '+')) {  // message returned error
         queue_scpi_cmd("*CLS", SCPI_CLS_MSG);  // reset the error
         scpi_msg_id = 0;
         poll_next_scpi();
         return;
      }
      else if((nmea_msg[i] == 'S') && (nmea_msg[i+1] == 'C') && (nmea_msg[i+2] == 'P')) { // message with no data to return
         scpi_msg_id = 0;
         poll_next_scpi();
         return;
      }
   }

   scpi_msg_id = polled_msg_id;

   if     (scpi_msg_id == SCPI_TIME_MSG)      parse_scpi_time();
   else if(scpi_msg_id == SCPI_VIS_MSG)       parse_scpi_vis();
   else if(scpi_msg_id == SCPI_TRACK_MSG)     parse_scpi_track();
   else if(scpi_msg_id == SCPI_EFC_MSG)       parse_scpi_efc();
   else if(scpi_msg_id == SCPI_ELEV_MSG)      parse_scpi_elev();
   else if(scpi_msg_id == SCPI_GET_CABLE_MSG) parse_scpi_cable();
   else if(scpi_msg_id == SCPI_SET_CABLE_MSG) parse_scpi_cable();
   else if(scpi_msg_id == SCPI_UTC_OFS_MSG)   parse_scpi_utc_ofs();
   else if(scpi_msg_id == SCPI_TINT_MSG)      parse_scpi_tint();
   else if(scpi_msg_id == SCPI_STATUS_MSG)    parse_scpi_status();
   else if(scpi_msg_id == SCPI_PROGRESS_MSG)  parse_scpi_progress();
   else if(scpi_msg_id == SCPI_SURVEY_MSG)    parse_scpi_survey();
   else if(scpi_msg_id == SCPI_RESET_MSG)     parse_scpi_reset();
   else if(scpi_msg_id == SCPI_POSN_MSG)      parse_scpi_posn();
   else if(scpi_msg_id == SCPI_POS_MSG)       parse_scpi_pos();
   else if(scpi_msg_id == SCPI_HOLDOVER_MSG)  parse_scpi_holdover();
   else if(scpi_msg_id == SCPI_UTC_MSG)       parse_scpi_utc();
   else if(scpi_msg_id == SCPI_TUNC_MSG)      parse_scpi_tunc();
   else if(scpi_msg_id == SCPI_TEST_MSG)      parse_scpi_test();
   else if(scpi_msg_id == SCPI_HARDWARE_MSG)  parse_scpi_hardware();
   else if(scpi_msg_id == SCPI_LEAPTIME_MSG)  parse_scpi_leaptime();
   else if(scpi_msg_id == SCPI_ID_MSG)        parse_scpi_id();
   else if(scpi_msg_id == SCPI_IGNORE_MSG)    parse_scpi_ignore();
   else if(scpi_msg_id == SCPI_IGN_COUNT_MSG) parse_scpi_ign_count();
   else if(scpi_msg_id == SCPI_INCLUDE_MSG)   parse_scpi_include();
   else if(scpi_msg_id == SCPI_JAMSYNC_MSG)   parse_scpi_jamsync();
   else if(scpi_msg_id == SCPI_EDGE_MSG)      parse_scpi_edge();
   else if(scpi_msg_id == SCPI_LIFE_MSG)      parse_scpi_life();
   else if(scpi_msg_id == SCPI_POWER_MSG)     parse_scpi_power();
   else if(scpi_msg_id == SCPI_USER_MSG)      parse_scpi_user();
   else if(scpi_msg_id == SCPI_ANTENNA_MSG)   parse_scpi_antenna();
   else if(scpi_msg_id == SCPI_FFOM_MSG)      parse_scpi_ffom();
   else if(scpi_msg_id == SCPI_OPERATION_MSG) parse_scpi_operation();

if(scpi_msg_id == SCPI_STATUS_MSG) {  //;;;;;
   scpi_msg_id = 0;  // next message polled when status command completes
}
else {
   scpi_msg_id = 0;
   poll_next_scpi();
}

   if(sim_file && sim_delay) {  // throttle sim file messages
      Sleep(sim_delay);
   }
   saw_rcvr_msg = 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
xorl %edi, %edi
callq 0xae4a0
leaq 0x2c1fda(%rip), %rax    # 0x39aa10
movb $0x0, (%rax)
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
leaq 0x2be9e8(%rip), %rcx    # 0x397432
movzwl (%rcx), %ecx
cmpl %ecx, %eax
jge 0xd8a96
callq 0x7a510
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %dl
movslq -0x8(%rbp), %rcx
leaq 0x2c1fa9(%rip), %rax    # 0x39aa10
movb %dl, (%rax,%rcx)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0x2c1f96(%rip), %rax    # 0x39aa10
movb $0x0, (%rax,%rcx)
cmpl $0x1f5, -0x8(%rbp)      # imm = 0x1F5
jl 0xd8a89
jmp 0xd8a96
jmp 0xd8a8b
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0xd8a40
leaq 0x2be997(%rip), %rax    # 0x397434
movw $0x0, (%rax)
leaq 0x2be989(%rip), %rax    # 0x397432
movw $0x0, (%rax)
leaq 0x2be981(%rip), %rax    # 0x397436
movw $0x0, (%rax)
leaq 0x2c1f4f(%rip), %rdi    # 0x39aa10
callq 0x9890
leaq 0x1c4aa3(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0xd8af8
leaq 0x1c4a96(%rip), %rax    # 0x29d570
movq (%rax), %rdi
movl 0x2f32ed(%rip), %edx    # 0x3cbdd0
leaq 0xae203(%rip), %rsi     # 0x186ced
leaq 0x2c1f1f(%rip), %rcx    # 0x39aa10
movb $0x0, %al
callq 0x9550
cmpl $0x2, 0x2f32d1(%rip)    # 0x3cbdd0
jne 0xd8b27
leaq 0x2c1f08(%rip), %rdi    # 0x39aa10
leaq 0xabd9d(%rip), %rsi     # 0x1848ac
callq 0x9090
cmpq $0x0, %rax
je 0xd8b27
leaq 0x19efa3(%rip), %rax    # 0x277ac4
movl $0x1, (%rax)
leaq 0x1a167a(%rip), %rax    # 0x27a1a8
cmpl $0x0, (%rax)
je 0xd8be2
leaq 0x19ef86(%rip), %rax    # 0x277ac4
cmpl $0x0, (%rax)
je 0xd8be2
leaq 0x294972(%rip), %rax    # 0x36d4c0
cmpl $0x2580, 0x159d0(%rax)  # imm = 0x2580
jne 0xd8be2
leaq 0x19ef4b(%rip), %rax    # 0x277ab0
movq $0x20000, (%rax)        # imm = 0x20000
movl $0x0, 0x2f662e(%rip)    # 0x3cf1a4
movl $0x0, 0x2f6620(%rip)    # 0x3cf1a0
xorl %edi, %edi
callq 0x6a330
leaq 0x1a1682(%rip), %rax    # 0x27a210
movl $0x7e4, (%rax)          # imm = 0x7E4
leaq 0x19ef29(%rip), %rax    # 0x277ac4
movl $0x1, (%rax)
leaq 0x19ef20(%rip), %rax    # 0x277ac8
movl $0x20000, (%rax)        # imm = 0x20000
movl $0x221e, %edi           # imm = 0x221E
callq 0xeaf0
leaq 0x1c49b1(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0xd8bdd
leaq 0x1c49a4(%rip), %rax    # 0x29d570
movq (%rax), %rdi
leaq 0xafc1d(%rip), %rsi     # 0x1887f3
movb $0x0, %al
callq 0x9550
jmp 0xd9004
leaq 0x2c1e27(%rip), %rax    # 0x39aa10
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0xd8d00
movl $0x1, -0x8(%rbp)
movslq -0x8(%rbp), %rcx
leaq 0x2c1e09(%rip), %rax    # 0x39aa10
movsbl (%rax,%rcx), %eax
cmpl $0x45, %eax
jne 0xd8c4e
movl -0x8(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0x2c1df0(%rip), %rax    # 0x39aa10
movsbl (%rax,%rcx), %eax
cmpl $0x2d, %eax
jne 0xd8c4e
leaq 0xabc7c(%rip), %rdi     # 0x1848ac
movl $0x2, %esi
callq 0x82fd0
movl $0x0, 0x2f3198(%rip)    # 0x3cbddc
callq 0x97d50
jmp 0xd9004
movslq -0x8(%rbp), %rcx
leaq 0x2c1db7(%rip), %rax    # 0x39aa10
movsbl (%rax,%rcx), %eax
cmpl $0x45, %eax
jne 0xd8ca0
movl -0x8(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0x2c1d9e(%rip), %rax    # 0x39aa10
movsbl (%rax,%rcx), %eax
cmpl $0x2b, %eax
jne 0xd8ca0
leaq 0xabc2a(%rip), %rdi     # 0x1848ac
movl $0x2, %esi
callq 0x82fd0
movl $0x0, 0x2f3146(%rip)    # 0x3cbddc
callq 0x97d50
jmp 0xd9004
movslq -0x8(%rbp), %rcx
leaq 0x2c1d65(%rip), %rax    # 0x39aa10
movsbl (%rax,%rcx), %eax
cmpl $0x53, %eax
jne 0xd8cfa
movl -0x8(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0x2c1d4c(%rip), %rax    # 0x39aa10
movsbl (%rax,%rcx), %eax
cmpl $0x43, %eax
jne 0xd8cfa
movl -0x8(%rbp), %eax
addl $0x2, %eax
movslq %eax, %rcx
leaq 0x2c1d33(%rip), %rax    # 0x39aa10
movsbl (%rax,%rcx), %eax
cmpl $0x50, %eax
jne 0xd8cfa
movl $0x0, 0x2f30ec(%rip)    # 0x3cbddc
callq 0x97d50
jmp 0xd9004
jmp 0xd8cfc
jmp 0xd8cfe
jmp 0xd8d00
movl 0x2f30ca(%rip), %eax    # 0x3cbdd0
movl %eax, 0x2f30d0(%rip)    # 0x3cbddc
cmpl $0x3e7, 0x2f30c6(%rip)  # imm = 0x3E7
jne 0xd8d22
callq 0xd5e80
jmp 0xd8fa8
cmpl $0xc, 0x2f30b3(%rip)    # 0x3cbddc
jne 0xd8d35
callq 0xd6440
jmp 0xd8fa6
cmpl $0xd, 0x2f30a0(%rip)    # 0x3cbddc
jne 0xd8d48
callq 0xd6510
jmp 0xd8fa4
cmpl $0xb, 0x2f308d(%rip)    # 0x3cbddc
jne 0xd8d5b
callq 0xd6650
jmp 0xd8fa2
cmpl $0xa, 0x2f307a(%rip)    # 0x3cbddc
jne 0xd8d6e
callq 0xd6940
jmp 0xd8fa0
cmpl $0xe, 0x2f3067(%rip)    # 0x3cbddc
jne 0xd8d81
callq 0xd6890
jmp 0xd8f9e
cmpl $0x26, 0x2f3054(%rip)   # 0x3cbddc
jne 0xd8d94
callq 0xd6890
jmp 0xd8f9c
cmpl $0xf, 0x2f3041(%rip)    # 0x3cbddc
jne 0xd8da7
callq 0xd69a0
jmp 0xd8f9a
cmpl $0x10, 0x2f302e(%rip)   # 0x3cbddc
jne 0xd8dba
callq 0xd75e0
jmp 0xd8f98
cmpl $0x11, 0x2f301b(%rip)   # 0x3cbddc
jne 0xd8dcd
callq 0xd89c0
jmp 0xd8f96
cmpl $0x12, 0x2f3008(%rip)   # 0x3cbddc
jne 0xd8de0
callq 0xd7690
jmp 0xd8f94
cmpl $0x13, 0x2f2ff5(%rip)   # 0x3cbddc
jne 0xd8df3
callq 0xd7730
jmp 0xd8f92
cmpl $0x14, 0x2f2fe2(%rip)   # 0x3cbddc
jne 0xd8e06
callq 0xd8610
jmp 0xd8f90
cmpl $0x15, 0x2f2fcf(%rip)   # 0x3cbddc
jne 0xd8e19
callq 0xd8340
jmp 0xd8f8e
cmpl $0x1d, 0x2f2fbc(%rip)   # 0x3cbddc
jne 0xd8e2c
callq 0xd80b0
jmp 0xd8f8c
cmpl $0x16, 0x2f2fa9(%rip)   # 0x3cbddc
jne 0xd8e3f
callq 0xd77f0
jmp 0xd8f8a
cmpl $0x17, 0x2f2f96(%rip)   # 0x3cbddc
jne 0xd8e52
callq 0xd7960
jmp 0xd8f88
cmpl $0x18, 0x2f2f83(%rip)   # 0x3cbddc
jne 0xd8e65
callq 0xd7a20
jmp 0xd8f86
cmpl $0x19, 0x2f2f70(%rip)   # 0x3cbddc
jne 0xd8e78
callq 0xd7ba0
jmp 0xd8f84
cmpl $0x1a, 0x2f2f5d(%rip)   # 0x3cbddc
jne 0xd8e8b
callq 0xd7c20
jmp 0xd8f82
cmpl $0x1b, 0x2f2f4a(%rip)   # 0x3cbddc
jne 0xd8e9e
callq 0xd6a00
jmp 0xd8f80
cmpl $0x1c, 0x2f2f37(%rip)   # 0x3cbddc
jne 0xd8eb1
callq 0xd7090
jmp 0xd8f7e
cmpl $0x1e, 0x2f2f24(%rip)   # 0x3cbddc
jne 0xd8ec4
callq 0xd80d0
jmp 0xd8f7c
cmpl $0x1f, 0x2f2f11(%rip)   # 0x3cbddc
jne 0xd8ed7
callq 0xd81e0
jmp 0xd8f7a
cmpl $0x20, 0x2f2efe(%rip)   # 0x3cbddc
jne 0xd8eea
callq 0xd8260
jmp 0xd8f78
cmpl $0x21, 0x2f2eeb(%rip)   # 0x3cbddc
jne 0xd8efa
callq 0xd7940
jmp 0xd8f76
cmpl $0x22, 0x2f2edb(%rip)   # 0x3cbddc
jne 0xd8f0a
callq 0xd7aa0
jmp 0xd8f74
cmpl $0x23, 0x2f2ecb(%rip)   # 0x3cbddc
jne 0xd8f1a
callq 0xd7b50
jmp 0xd8f72
cmpl $0x24, 0x2f2ebb(%rip)   # 0x3cbddc
jne 0xd8f2a
callq 0xd8630
jmp 0xd8f70
cmpl $0x25, 0x2f2eab(%rip)   # 0x3cbddc
jne 0xd8f3a
callq 0xbf6d0
jmp 0xd8f6e
cmpl $0x33, 0x2f2e9b(%rip)   # 0x3cbddc
jne 0xd8f4a
callq 0xd8650
jmp 0xd8f6c
cmpl $0x32, 0x2f2e8b(%rip)   # 0x3cbddc
jne 0xd8f5a
callq 0xd8720
jmp 0xd8f6a
cmpl $0x34, 0x2f2e7b(%rip)   # 0x3cbddc
jne 0xd8f68
callq 0xd7f60
jmp 0xd8f6a
jmp 0xd8f6c
jmp 0xd8f6e
jmp 0xd8f70
jmp 0xd8f72
jmp 0xd8f74
jmp 0xd8f76
jmp 0xd8f78
jmp 0xd8f7a
jmp 0xd8f7c
jmp 0xd8f7e
jmp 0xd8f80
jmp 0xd8f82
jmp 0xd8f84
jmp 0xd8f86
jmp 0xd8f88
jmp 0xd8f8a
jmp 0xd8f8c
jmp 0xd8f8e
jmp 0xd8f90
jmp 0xd8f92
jmp 0xd8f94
jmp 0xd8f96
jmp 0xd8f98
jmp 0xd8f9a
jmp 0xd8f9c
jmp 0xd8f9e
jmp 0xd8fa0
jmp 0xd8fa2
jmp 0xd8fa4
jmp 0xd8fa6
jmp 0xd8fa8
cmpl $0x11, 0x2f2e2d(%rip)   # 0x3cbddc
jne 0xd8fbd
movl $0x0, 0x2f2e21(%rip)    # 0x3cbddc
jmp 0xd8fcc
movl $0x0, 0x2f2e15(%rip)    # 0x3cbddc
callq 0x97d50
leaq 0x1c45cd(%rip), %rax    # 0x29d5a0
cmpq $0x0, (%rax)
je 0xd8ff7
leaq 0x1a9800(%rip), %rax    # 0x2827e0
cmpq $0x0, (%rax)
je 0xd8ff7
leaq 0x1a97f3(%rip), %rax    # 0x2827e0
movq (%rax), %rax
movl %eax, %edi
callq 0xb8b0
leaq 0x1c5182(%rip), %rax    # 0x29e180
movl $0x1, (%rax)
addq $0x10, %rsp
popq %rbp
retq
nopw (%rax,%rax)