// File: /workspace/github_cpp_makefile_star2_O2/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 0x73dcb
leaq 0x294ff2(%rip), %r15    # 0x325830
movb $0x0, (%r15)
leaq 0x291a09(%rip), %r14    # 0x322252
movzwl (%r14), %eax
cmpq %rax, %rbx
jae 0x9086d
callq 0x51c47
movb %al, (%rbx,%r15)
movb $0x0, 0x1(%rbx,%r15)
incq %rbx
cmpq $0x1f6, %rbx            # imm = 0x1F6
jne 0x90849
leaq 0x2919e0(%rip), %rax    # 0x322254
andw $0x0, (%rax)
andw $0x0, (%r14)
leaq 0x2919d2(%rip), %rax    # 0x322256
andw $0x0, (%rax)
leaq 0x294fa1(%rip), %rbx    # 0x325830
movq %rbx, %rdi
callq 0x988f
leaq 0x197af2(%rip), %r15    # 0x228390
movq (%r15), %rdi
testq %rdi, %rdi
je 0x908c1
movl 0x2c6354(%rip), %edx    # 0x356c00
leaq 0x7d09b(%rip), %rsi     # 0x10d94e
leaq 0x294f76(%rip), %rcx    # 0x325830
xorl %eax, %eax
callq 0x9560
movl 0x2c6338(%rip), %r14d   # 0x356c00
cmpl $0x2, %r14d
jne 0x908f3
leaq 0x294f5b(%rip), %rdi    # 0x325830
leaq 0x7ac88(%rip), %rsi     # 0x10b564
callq 0x9090
testq %rax, %rax
je 0x908f3
leaq 0x171ff7(%rip), %rax    # 0x2028e4
movl $0x1, (%rax)
leaq 0x1746ce(%rip), %rax    # 0x204fc8
cmpl $0x0, (%rax)
je 0x9099d
leaq 0x171fda(%rip), %r12    # 0x2028e4
cmpl $0x0, (%r12)
je 0x9099d
leaq 0x2679c4(%rip), %rax    # 0x2f82e0
cmpl $0x2580, 0x159d0(%rax)  # imm = 0x2580
jne 0x9099d
leaq 0x171fa1(%rip), %rax    # 0x2028d0
andl $0x0, 0x2c969e(%rip)    # 0x359fd4
movq $0x20000, (%rax)        # imm = 0x20000
andl $0x0, 0x2c968c(%rip)    # 0x359fd0
xorl %edi, %edi
callq 0x473fa
leaq 0x1746de(%rip), %rax    # 0x205030
movl $0x7e4, (%rax)          # imm = 0x7E4
movl $0x1, (%r12)
leaq 0x171f81(%rip), %rax    # 0x2028e8
movl $0x20000, (%rax)        # imm = 0x20000
movl $0x221e, %edi           # imm = 0x221E
callq 0xcc4f
movq (%r15), %rcx
testq %rcx, %rcx
je 0x90b7c
leaq 0x7eabd(%rip), %rdi     # 0x10f447
pushq $0x1f
popq %rsi
pushq $0x1
popq %rdx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x9750
cmpb $0x20, (%rbx)
jne 0x909f5
movb 0x1(%rbx), %cl
movb 0x2(%rbx), %al
movl %ecx, %edx
xorb $0x45, %dl
movl %eax, %esi
xorb $0x2d, %sil
orb %dl, %sil
je 0x909c3
movl %eax, %esi
xorb $0x2b, %sil
orb %sil, %dl
jne 0x909e6
leaq 0x7ab9a(%rip), %rdi     # 0x10b564
pushq $0x2
popq %rsi
callq 0x576d4
andl $0x0, 0x2c6233(%rip)    # 0x356c0c
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x65f5a
cmpb $0x53, %cl
jne 0x909f5
cmpb $0x43, %al
jne 0x909f5
cmpb $0x50, 0x3(%rbx)
je 0x909d2
movl %r14d, 0x2c6210(%rip)   # 0x356c0c
leal -0xa(%r14), %eax
cmpl $0x2a, %eax
ja 0x90a1f
leaq 0x78e74(%rip), %rcx     # 0x109880
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
callq 0x8f1b6
jmp 0x90b27
cmpl $0x3e7, %r14d           # imm = 0x3E7
jne 0x90b39
callq 0x8ea3a
jmp 0x90b27
callq 0x90201
jmp 0x90b27
callq 0x9013c
jmp 0x90b27
callq 0x8f2c7
jmp 0x90b27
callq 0x90606
jmp 0x90b27
callq 0x8fdc4
jmp 0x90b27
callq 0x90544
jmp 0x90b27
callq 0x8fcf6
jmp 0x90b27
callq 0x8ef4d
jmp 0x90b27
callq 0x907da
jmp 0x90b27
callq 0x8fe46
jmp 0x90b27
callq 0x8fb4d
jmp 0x90b27
callq 0x8f227
jmp 0x90b27
callq 0x90253
jmp 0x90b27
callq 0x8fadb
jmp 0x90b27
callq 0x8eeb2
jmp 0x90b27
callq 0x8f006
jmp 0x90b27
callq 0x8fbd5
jmp 0x90b27
callq 0x8fe90
jmp 0x90b27
callq 0x8fce5
jmp 0x90b27
callq 0x9014d
jmp 0x90b27
callq 0x8f274
jmp 0x90b27
callq 0x90319
jmp 0x90b27
callq 0x8fd63
jmp 0x90b27
callq 0x8fa65
jmp 0x90b27
callq 0x8f71f
jmp 0x90b27
callq 0x8fef7
jmp 0x90b27
callq 0x90566
jmp 0x90b27
callq 0x7f628
jmp 0x90b27
callq 0x9006d
jmp 0x90b27
callq 0x90555
cmpl $0x11, 0x2c60de(%rip)   # 0x356c0c
jne 0x90b39
andl $0x0, 0x2c60d5(%rip)    # 0x356c0c
jmp 0x90b45
andl $0x0, 0x2c60cc(%rip)    # 0x356c0c
callq 0x65f5a
leaq 0x197874(%rip), %rax    # 0x2283c0
cmpq $0x0, (%rax)
setne %al
leaq 0x17caa6(%rip), %rcx    # 0x20d600
movq (%rcx), %rdi
testq %rdi, %rdi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x90b6f
callq 0xae83
leaq 0x19842a(%rip), %rax    # 0x228fa0
movl $0x1, (%rax)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq