// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x7f47d
leaq 0x29c275(%rip), %r15    # 0x33b830
movb $0x0, (%r15)
leaq 0x298c8c(%rip), %r14    # 0x338252
leaq 0x19f9a3(%rip), %r12    # 0x23ef70
movzwl (%r14), %eax
cmpq %rax, %rbx
jae 0x9f5fd
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x9f5e7
orb $0x8, (%r12)
movb %al, (%rbx,%r15)
movb $0x0, 0x1(%rbx,%r15)
incq %rbx
cmpq $0x1f6, %rbx            # imm = 0x1F6
jne 0x9f5cd
leaq 0x298c50(%rip), %rax    # 0x338254
xorl %ecx, %ecx
movw %cx, (%rax)
movw %cx, (%r14)
leaq 0x298c42(%rip), %rax    # 0x338256
movw %cx, (%rax)
leaq 0x29c212(%rip), %rbx    # 0x33b830
movq %rbx, %rdi
callq 0x9899
leaq 0x19ed63(%rip), %r15    # 0x23e390
movq (%r15), %rdi
testq %rdi, %rdi
je 0x9f650
movl 0x2cd5c5(%rip), %edx    # 0x36cc00
leaq 0x842e4(%rip), %rsi     # 0x123926
leaq 0x29c1e7(%rip), %rcx    # 0x33b830
xorl %eax, %eax
callq 0x9560
movl 0x2cd5a9(%rip), %r14d   # 0x36cc00
cmpl $0x2, %r14d
jne 0x9f682
leaq 0x29c1cc(%rip), %rdi    # 0x33b830
leaq 0x81ed1(%rip), %rsi     # 0x12153c
callq 0x9090
testq %rax, %rax
je 0x9f682
leaq 0x179268(%rip), %rax    # 0x2188e4
movl $0x1, (%rax)
leaq 0x17b93f(%rip), %rax    # 0x21afc8
cmpl $0x0, (%rax)
je 0x9f730
leaq 0x17924b(%rip), %r12    # 0x2188e4
cmpl $0x0, (%r12)
je 0x9f730
leaq 0x26ec35(%rip), %rax    # 0x30e2e0
cmpl $0x2580, 0x159d0(%rax)  # imm = 0x2580
jne 0x9f730
leaq 0x179212(%rip), %rax    # 0x2188d0
movq $0x20000, (%rax)        # imm = 0x20000
xorl %eax, %eax
movl %eax, 0x2d0907(%rip)    # 0x36ffd4
movl %eax, 0x2d08fd(%rip)    # 0x36ffd0
xorl %edi, %edi
callq 0x4b25a
leaq 0x17b94f(%rip), %rax    # 0x21b030
movl $0x7e4, (%rax)          # imm = 0x7E4
movl $0x1, (%r12)
leaq 0x1791f2(%rip), %rax    # 0x2188e8
movl $0x20000, (%rax)        # imm = 0x20000
movl $0x221e, %edi           # imm = 0x221E
callq 0xcf81
movq (%r15), %rcx
testq %rcx, %rcx
je 0x9f95b
leaq 0x85d06(%rip), %rdi     # 0x12541f
movl $0x1f, %esi
movl $0x1, %edx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x9750
cmpb $0x20, (%rbx)
jne 0x9f78d
movb 0x1(%rbx), %cl
movb 0x2(%rbx), %al
movl %ecx, %edx
xorb $0x45, %dl
movl %eax, %esi
xorb $0x2d, %sil
orb %dl, %sil
je 0x9f756
movl %eax, %esi
xorb $0x2b, %sil
orb %sil, %dl
jne 0x9f77e
leaq 0x81ddf(%rip), %rdi     # 0x12153c
movl $0x2, %esi
callq 0x5ee52
movl $0x0, 0x2cd49b(%rip)    # 0x36cc0c
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x6f4fd
cmpb $0x53, %cl
jne 0x9f78d
cmpb $0x43, %al
jne 0x9f78d
cmpb $0x50, 0x3(%rbx)
je 0x9f767
movl %r14d, 0x2cd478(%rip)   # 0x36cc0c
leal -0xa(%r14), %eax
cmpl $0x2a, %eax
ja 0x9f7b7
leaq 0x800c0(%rip), %rcx     # 0x11f864
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
callq 0x9de04
jmp 0x9f90c
cmpl $0x3e7, %r14d           # imm = 0x3E7
jne 0x9f90c
callq 0x9d5e7
jmp 0x9f90c
callq 0x9ef53
jmp 0x9f90c
leaq 0x858d0(%rip), %rdi     # 0x1250af
jmp 0x9f907
callq 0x9df5b
jmp 0x9f90c
leaq 0x85937(%rip), %rdi     # 0x12512c
jmp 0x9f907
callq 0x9eac8
jmp 0x9f90c
leaq 0x858f3(%rip), %rdi     # 0x1250fe
jmp 0x9f907
callq 0x9e9f0
jmp 0x9f90c
callq 0x9db73
jmp 0x9f90c
leaq 0x85960(%rip), %rdi     # 0x12518b
callq 0x58e77
movl $0x1, 0x2d07aa(%rip)    # 0x36ffe4
leaq 0x17b7d7(%rip), %rax    # 0x21b018
xorl %ecx, %ecx
movl %ecx, (%rax)
movl %ecx, 0x2d2689(%rip)    # 0x371ed4
movl %ecx, 0x2d267f(%rip)    # 0x371ed0
movl %ecx, 0x2cd36d(%rip)    # 0x36cbc4
movb $0x0, 0x2cd2e2(%rip)    # 0x36cb40
movl %ecx, 0x2d0784(%rip)    # 0x36ffe8
jmp 0x9f90c
callq 0x9eb4f
jmp 0x9f90c
callq 0x9e83f
jmp 0x9f90c
callq 0x9de78
jmp 0x9f90c
callq 0x9efab
jmp 0x9f90c
callq 0x9e7ca
jmp 0x9f90c
callq 0x9daca
jmp 0x9f90c
callq 0x9dc36
jmp 0x9f90c
callq 0x9e8cc
jmp 0x9f90c
callq 0x9eb9c
jmp 0x9f90c
leaq 0x8572b(%rip), %rdi     # 0x124fe3
jmp 0x9f907
callq 0x9ee67
jmp 0x9f90c
callq 0x9dec8
jmp 0x9f90c
callq 0x9f095
jmp 0x9f90c
callq 0x9ea62
jmp 0x9f90c
callq 0x9e74f
jmp 0x9f90c
callq 0x9e404
jmp 0x9f90c
callq 0x9ec06
jmp 0x9f90c
callq 0x9f2d5
jmp 0x9f90c
callq 0x8c1c3
jmp 0x9f90c
callq 0x9ed82
jmp 0x9f90c
leaq 0x85802(%rip), %rdi     # 0x125109
callq 0x58e77
cmpl $0x11, 0x2cd2f9(%rip)   # 0x36cc0c
movl $0x0, 0x2cd2ef(%rip)    # 0x36cc0c
je 0x9f924
callq 0x6f4fd
leaq 0x19ea95(%rip), %rax    # 0x23e3c0
cmpq $0x0, (%rax)
setne %al
leaq 0x183cc7(%rip), %rcx    # 0x223600
movq (%rcx), %rdi
testq %rdi, %rdi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x9f94e
callq 0xaff7
leaq 0x19f64b(%rip), %rax    # 0x23efa0
movl $0x1, (%rax)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq