// File: /workspace/github_cpp_makefile_star2_O3/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 0x7f2b8
leaq 0x29c07d(%rip), %r15    # 0x33b830
movb $0x0, (%r15)
leaq 0x298a94(%rip), %r14    # 0x338252
leaq 0x19f7ab(%rip), %r12    # 0x23ef70
movzwl (%r14), %eax
cmpq %rax, %rbx
jae 0x9f7f5
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x9f7df
orb $0x8, (%r12)
movb %al, (%rbx,%r15)
movb $0x0, 0x1(%rbx,%r15)
incq %rbx
cmpq $0x1f6, %rbx            # imm = 0x1F6
jne 0x9f7c5
leaq 0x298a58(%rip), %rax    # 0x338254
xorl %ecx, %ecx
movw %cx, (%rax)
movw %cx, (%r14)
leaq 0x298a4a(%rip), %rax    # 0x338256
movw %cx, (%rax)
leaq 0x29c01a(%rip), %rbx    # 0x33b830
movq %rbx, %rdi
callq 0x9899
leaq 0x19eb6b(%rip), %r15    # 0x23e390
movq (%r15), %rdi
testq %rdi, %rdi
je 0x9f848
movl 0x2cd3cd(%rip), %edx    # 0x36cc00
leaq 0x841cc(%rip), %rsi     # 0x123a06
leaq 0x29bfef(%rip), %rcx    # 0x33b830
xorl %eax, %eax
callq 0x9560
movl 0x2cd3b1(%rip), %r14d   # 0x36cc00
cmpl $0x2, %r14d
jne 0x9f87a
leaq 0x29bfd4(%rip), %rdi    # 0x33b830
leaq 0x81db9(%rip), %rsi     # 0x12161c
callq 0x9090
testq %rax, %rax
je 0x9f87a
leaq 0x179070(%rip), %rax    # 0x2188e4
movl $0x1, (%rax)
leaq 0x17b747(%rip), %rax    # 0x21afc8
cmpl $0x0, (%rax)
je 0x9f928
leaq 0x179053(%rip), %r12    # 0x2188e4
cmpl $0x0, (%r12)
je 0x9f928
leaq 0x26ea3d(%rip), %rax    # 0x30e2e0
cmpl $0x2580, 0x159d0(%rax)  # imm = 0x2580
jne 0x9f928
leaq 0x17901a(%rip), %rax    # 0x2188d0
movq $0x20000, (%rax)        # imm = 0x20000
xorl %eax, %eax
movl %eax, 0x2d070f(%rip)    # 0x36ffd4
movl %eax, 0x2d0705(%rip)    # 0x36ffd0
xorl %edi, %edi
callq 0x4b2af
leaq 0x17b757(%rip), %rax    # 0x21b030
movl $0x7e4, (%rax)          # imm = 0x7E4
movl $0x1, (%r12)
leaq 0x178ffa(%rip), %rax    # 0x2188e8
movl $0x20000, (%rax)        # imm = 0x20000
movl $0x221e, %edi           # imm = 0x221E
callq 0xcf89
movq (%r15), %rcx
testq %rcx, %rcx
je 0x9fb5f
leaq 0x85bee(%rip), %rdi     # 0x1254ff
movl $0x1f, %esi
movl $0x1, %edx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x9750
cmpb $0x20, (%rbx)
jne 0x9f985
movb 0x1(%rbx), %cl
movb 0x2(%rbx), %al
movl %ecx, %edx
xorb $0x45, %dl
movl %eax, %esi
xorb $0x2d, %sil
orb %dl, %sil
je 0x9f94e
movl %eax, %esi
xorb $0x2b, %sil
orb %sil, %dl
jne 0x9f976
leaq 0x81cc7(%rip), %rdi     # 0x12161c
movl $0x2, %esi
callq 0x5edda
movl $0x0, 0x2cd2a3(%rip)    # 0x36cc0c
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x6f476
cmpb $0x53, %cl
jne 0x9f985
cmpb $0x43, %al
jne 0x9f985
cmpb $0x50, 0x3(%rbx)
je 0x9f95f
movl %r14d, 0x2cd280(%rip)   # 0x36cc0c
leal -0xa(%r14), %eax
cmpl $0x2a, %eax
ja 0x9f9af
leaq 0x7ffa0(%rip), %rcx     # 0x11f93c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
callq 0x9dfde
jmp 0x9fb04
cmpl $0x3e7, %r14d           # imm = 0x3E7
jne 0x9fb19
callq 0x9d7c1
jmp 0x9fb04
callq 0x9f13b
jmp 0x9fb04
leaq 0x857b8(%rip), %rdi     # 0x12518f
jmp 0x9faff
callq 0x9e135
jmp 0x9fb04
leaq 0x8581f(%rip), %rdi     # 0x12520c
jmp 0x9faff
callq 0x9eca2
jmp 0x9fb04
leaq 0x857db(%rip), %rdi     # 0x1251de
jmp 0x9faff
callq 0x9ebca
jmp 0x9fb04
callq 0x9dd4d
jmp 0x9fb04
leaq 0x85848(%rip), %rdi     # 0x12526b
callq 0x58dc2
movl $0x1, 0x2d05b2(%rip)    # 0x36ffe4
leaq 0x17b5df(%rip), %rax    # 0x21b018
xorl %ecx, %ecx
movl %ecx, (%rax)
movl %ecx, 0x2d2491(%rip)    # 0x371ed4
movl %ecx, 0x2d2487(%rip)    # 0x371ed0
movl %ecx, 0x2cd175(%rip)    # 0x36cbc4
movb $0x0, 0x2cd0ea(%rip)    # 0x36cb40
movl %ecx, 0x2d058c(%rip)    # 0x36ffe8
jmp 0x9fb04
callq 0x9ed29
jmp 0x9fb04
callq 0x9ea19
jmp 0x9fb04
callq 0x9e052
jmp 0x9fb04
callq 0x9f193
jmp 0x9fb04
callq 0x9e9a4
jmp 0x9fb04
callq 0x9dca4
jmp 0x9fb04
callq 0x9de10
jmp 0x9fb04
callq 0x9eaa6
jmp 0x9fb04
callq 0x9ed76
jmp 0x9fb04
leaq 0x85613(%rip), %rdi     # 0x1250c3
jmp 0x9faff
callq 0x9f042
jmp 0x9fb04
callq 0x9e0a2
jmp 0x9fb04
callq 0x9f27d
jmp 0x9fb04
callq 0x9ec3c
jmp 0x9fb04
callq 0x9e929
jmp 0x9fb04
callq 0x9e5de
jmp 0x9fb04
callq 0x9ede0
jmp 0x9fb04
callq 0x9f4cd
jmp 0x9fb04
callq 0x8c1c5
jmp 0x9fb04
callq 0x9ef5d
jmp 0x9fb04
leaq 0x856ea(%rip), %rdi     # 0x1251e9
callq 0x58dc2
cmpl $0x11, 0x2cd101(%rip)   # 0x36cc0c
jne 0x9fb19
movl $0x0, 0x2cd0f5(%rip)    # 0x36cc0c
jmp 0x9fb28
movl $0x0, 0x2cd0e9(%rip)    # 0x36cc0c
callq 0x6f476
leaq 0x19e891(%rip), %rax    # 0x23e3c0
cmpq $0x0, (%rax)
setne %al
leaq 0x183ac3(%rip), %rcx    # 0x223600
movq (%rcx), %rdi
testq %rdi, %rdi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x9fb52
callq 0xafe8
leaq 0x19f447(%rip), %rax    # 0x23efa0
movl $0x1, (%rax)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq