// File: /workspace/github_cpp_makefile_star2_O1/jkingan[P]ladyheather/heathgps.cpp
// Function: decode_x72_msg(int)
void decode_x72_msg(int why)
{
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;
tsip_error = 0;

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

   strupr(nmea_msg);

if(debug_file) fprintf(debug_file, "Decode x72 msg %d:(%s)  why:%d\n", x72_msg_id, nmea_msg, why);

   if(strstr(nmea_msg, "R>")) {  // >r prompt
      x72_msg_id = 0;
      return;
   }
   else if(nmea_msg[0] == 0) {  // empty line
      return;
   }
   else if(x72_msg_id == 0) {
if(debug_file) fprintf(debug_file, "response to:(%s) (status msg:%d) is next\n", nmea_msg, scpi_status);
      if     (strstr(nmea_msg, "A")) x72_msg_id = X72_SET_FC_MSG;
      else if(strstr(nmea_msg, "F")) x72_msg_id = X72_SET_DDS_MSG;
      else if(strstr(nmea_msg, "G")) x72_msg_id = X72_SET_DMODE_MSG;
      else if(strstr(nmea_msg, "H")) x72_msg_id = X72_HELP_MSG;
      else if(strstr(nmea_msg, "I")) x72_msg_id = X72_INFO_MSG;
      else if(strstr(nmea_msg, "J")) x72_msg_id = X72_GET_PPS_MSG;
      else if(strstr(nmea_msg, "K")) x72_msg_id = X72_SET_TIC_MSG;
      else if(strstr(nmea_msg, "L")) x72_msg_id = X72_SET_SRVC_MSG;
      else if(strstr(nmea_msg, "O")) x72_msg_id = X72_SET_FREQ_MSG;
      else if(strstr(nmea_msg, "P")) x72_msg_id = X72_GET_CREG_MSG;
      else if(strstr(nmea_msg, "Q")) x72_msg_id = X72_SET_CREG_MSG;
      else if(strstr(nmea_msg, "R")) x72_msg_id = X72_RUNR_MSG;
      else if(strstr(nmea_msg, "T")) x72_msg_id = X72_SAVE_TUNE_MSG;
      else if(strstr(nmea_msg, "W")) x72_msg_id = X72_HEALTH_MSG;
      else if(strstr(nmea_msg, "X")) x72_msg_id = X72_RUNX_MSG;
      else if(strstr(nmea_msg, "Y")) x72_msg_id = X72_TC_MSG;         // !!!! Y1
      else if(strstr(nmea_msg, "Y")) x72_msg_id = X72_DAMPING_MSG;    // !!!! Y2
      else if(strstr(nmea_msg, "Z")) x72_msg_id = X72_SAVE_DMODE_MSG; // !!!! Y2
      return;
   }

   if(x72_msg_id == X72_INFO_MSG) {  // multi-line response to the query
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_HEALTH_MSG) {  // multi-line response to the query 
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_GET_PPS_MSG) { // multi-line response to the query 
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_GET_CREG_MSG) { // multi-line response to the query 
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_HELP_MSG) { // multi-line response to the query 
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_SET_CREG_MSG) { // multi-line response to the query 
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_SET_TIC_MSG) { // multi-line response to the query 
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_SET_FREQ_MSG) { // multi-line response to the query 
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_SET_DMODE_MSG) { // multi-line response to the query 
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_SAVE_TUNE_MSG) { // multi-line response to the query 
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_SET_DDS_MSG) { // multi-line response to the query 
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_SET_SRVC_MSG) { // multi-line response to the query 
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_SET_FC_MSG) { // multi-line response to the query 
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_RUNR_MSG) { // multi-line response to the query 
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_RUNX_MSG) { // multi-line response to the query 
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_TC_MSG) {   // multi-line response to the query  
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_DAMPING_MSG) { // multi-line response to the query  
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == X72_SAVE_DMODE_MSG) { // multi-line response to the query  
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else if(x72_msg_id == SCPI_USER_MSG) {
      parse_x72_response(x72_msg_id);
      x72_msg_id = 0;
   }
   else {
      x72_msg_id = 0;
      poll_next_x72();
   }


// if(debug_file) fprintf(debug_file, "x72 %d response:%s\n", x72_msg_id, nmea_msg);
   update_x72_screen();

   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 %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edi, %ebx
xorl %r15d, %r15d
xorl %edi, %edi
callq 0x7f47d
leaq 0x2ac8c3(%rip), %r13    # 0x33b830
movb $0x0, (%r13)
leaq 0x2a92d9(%rip), %r12    # 0x338252
leaq 0x1afff0(%rip), %r14    # 0x23ef70
movzwl (%r12), %eax
cmpq %rax, %r15
jae 0x8efb0
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x8ef9a
orb $0x8, (%r14)
movb %al, (%r15,%r13)
movb $0x0, 0x1(%r15,%r13)
incq %r15
cmpq $0x1f6, %r15            # imm = 0x1F6
jne 0x8ef80
leaq 0x2a929d(%rip), %rax    # 0x338254
xorl %ecx, %ecx
movw %cx, (%rax)
movw %cx, (%r12)
leaq 0x2a928e(%rip), %rax    # 0x338256
movw %cx, (%rax)
movl $0x0, (%r14)
leaq 0x2ac857(%rip), %rdi    # 0x33b830
callq 0x9899
leaq 0x1af3ab(%rip), %r14    # 0x23e390
movq (%r14), %rdi
testq %rdi, %rdi
je 0x8f00b
movl 0x2ddbed(%rip), %edx    # 0x36cbe0
leaq 0x94c45(%rip), %rsi     # 0x123c3f
leaq 0x2ac82f(%rip), %rcx    # 0x33b830
movl %ebx, %r8d
xorl %eax, %eax
callq 0x9560
leaq 0x2ac81e(%rip), %rbx    # 0x33b830
leaq 0x94c46(%rip), %rsi     # 0x123c5f
movq %rbx, %rdi
callq 0x9090
testq %rax, %rax
je 0x8f035
movl $0x0, 0x2ddbb0(%rip)    # 0x36cbe0
jmp 0x8f197
cmpb $0x0, (%rbx)
je 0x8f197
movl 0x2ddb9c(%rip), %eax    # 0x36cbe0
leal -0x2bc(%rax), %ecx
cmpl $0x11, %ecx
ja 0x8f069
leaq 0x9056e(%rip), %rax     # 0x11f5c4
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movl $0x2bc, %edi            # imm = 0x2BC
jmp 0x8f14c
cmpl $0x25, %eax
je 0x8f10c
testl %eax, %eax
jne 0x8f121
movq (%r14), %rdi
testq %rdi, %rdi
je 0x8f09d
movl 0x2e0f5c(%rip), %ecx    # 0x36ffe4
leaq 0x94bd3(%rip), %rsi     # 0x123c62
leaq 0x2ac79a(%rip), %rdx    # 0x33b830
xorl %eax, %eax
callq 0x9560
leaq 0x2ac78c(%rip), %rdi    # 0x33b830
movl $0x41, %esi
callq 0x9100
testq %rax, %rax
je 0x8f1a6
movl $0x2bc, 0x2ddb1f(%rip)  # imm = 0x2BC
jmp 0x8f197
movl $0x2cc, %edi            # imm = 0x2CC
jmp 0x8f14c
movl $0x2ca, %edi            # imm = 0x2CA
jmp 0x8f14c
movl $0x2c7, %edi            # imm = 0x2C7
jmp 0x8f14c
movl $0x2c0, %edi            # imm = 0x2C0
jmp 0x8f14c
movl $0x2c8, %edi            # imm = 0x2C8
jmp 0x8f14c
movl $0x2c5, %edi            # imm = 0x2C5
jmp 0x8f14c
movl $0x2bd, %edi            # imm = 0x2BD
jmp 0x8f14c
movl $0x2cb, %edi            # imm = 0x2CB
jmp 0x8f14c
movl $0x2be, %edi            # imm = 0x2BE
jmp 0x8f14c
movl $0x2c3, %edi            # imm = 0x2C3
jmp 0x8f14c
movl $0x25, %edi
jmp 0x8f14c
movl $0x2cd, %edi            # imm = 0x2CD
jmp 0x8f14c
movl $0x2c1, %edi            # imm = 0x2C1
jmp 0x8f14c
movl $0x0, 0x2ddab5(%rip)    # 0x36cbe0
callq 0x70023
jmp 0x8f15b
movl $0x2c9, %edi            # imm = 0x2C9
jmp 0x8f14c
movl $0x2c2, %edi            # imm = 0x2C2
jmp 0x8f14c
movl $0x2c6, %edi            # imm = 0x2C6
jmp 0x8f14c
movl $0x2c4, %edi            # imm = 0x2C4
callq 0x8e079
movl $0x0, 0x2dda85(%rip)    # 0x36cbe0
callq 0x8df44
leaq 0x1af259(%rip), %rax    # 0x23e3c0
cmpq $0x0, (%rax)
setne %al
leaq 0x19448b(%rip), %rcx    # 0x223600
movq (%rcx), %rdi
testq %rdi, %rdi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x8f18a
callq 0xaff7
leaq 0x1afe0f(%rip), %rax    # 0x23efa0
movl $0x1, (%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2ac683(%rip), %rdi    # 0x33b830
movl $0x46, %esi
callq 0x9100
testq %rax, %rax
je 0x8f1c8
movl $0x2bd, 0x2dda1a(%rip)  # imm = 0x2BD
jmp 0x8f197
leaq 0x2ac661(%rip), %rdi    # 0x33b830
movl $0x47, %esi
callq 0x9100
testq %rax, %rax
je 0x8f1ea
movl $0x2be, 0x2dd9f8(%rip)  # imm = 0x2BE
jmp 0x8f197
leaq 0x2ac63f(%rip), %rdi    # 0x33b830
movl $0x48, %esi
callq 0x9100
testq %rax, %rax
je 0x8f20c
movl $0x2bf, 0x2dd9d6(%rip)  # imm = 0x2BF
jmp 0x8f197
leaq 0x2ac61d(%rip), %rdi    # 0x33b830
movl $0x49, %esi
callq 0x9100
testq %rax, %rax
je 0x8f231
movl $0x2c0, 0x2dd9b4(%rip)  # imm = 0x2C0
jmp 0x8f197
leaq 0x2ac5f8(%rip), %rdi    # 0x33b830
movl $0x4a, %esi
callq 0x9100
testq %rax, %rax
je 0x8f256
movl $0x2c1, 0x2dd98f(%rip)  # imm = 0x2C1
jmp 0x8f197
leaq 0x2ac5d3(%rip), %rdi    # 0x33b830
movl $0x4b, %esi
callq 0x9100
testq %rax, %rax
je 0x8f27b
movl $0x2c2, 0x2dd96a(%rip)  # imm = 0x2C2
jmp 0x8f197
leaq 0x2ac5ae(%rip), %rdi    # 0x33b830
movl $0x4c, %esi
callq 0x9100
testq %rax, %rax
je 0x8f2a0
movl $0x2c3, 0x2dd945(%rip)  # imm = 0x2C3
jmp 0x8f197
leaq 0x2ac589(%rip), %rdi    # 0x33b830
movl $0x4f, %esi
callq 0x9100
testq %rax, %rax
je 0x8f2c5
movl $0x2c4, 0x2dd920(%rip)  # imm = 0x2C4
jmp 0x8f197
leaq 0x2ac564(%rip), %rdi    # 0x33b830
movl $0x50, %esi
callq 0x9100
testq %rax, %rax
je 0x8f2ea
movl $0x2c5, 0x2dd8fb(%rip)  # imm = 0x2C5
jmp 0x8f197
leaq 0x2ac53f(%rip), %rdi    # 0x33b830
movl $0x51, %esi
callq 0x9100
testq %rax, %rax
je 0x8f30f
movl $0x2c6, 0x2dd8d6(%rip)  # imm = 0x2C6
jmp 0x8f197
leaq 0x2ac51a(%rip), %rdi    # 0x33b830
movl $0x52, %esi
callq 0x9100
testq %rax, %rax
je 0x8f334
movl $0x2c7, 0x2dd8b1(%rip)  # imm = 0x2C7
jmp 0x8f197
leaq 0x2ac4f5(%rip), %rdi    # 0x33b830
movl $0x54, %esi
callq 0x9100
testq %rax, %rax
je 0x8f359
movl $0x2c8, 0x2dd88c(%rip)  # imm = 0x2C8
jmp 0x8f197
leaq 0x2ac4d0(%rip), %rdi    # 0x33b830
movl $0x57, %esi
callq 0x9100
testq %rax, %rax
je 0x8f37e
movl $0x2c9, 0x2dd867(%rip)  # imm = 0x2C9
jmp 0x8f197
leaq 0x2ac4ab(%rip), %rdi    # 0x33b830
movl $0x58, %esi
callq 0x9100
testq %rax, %rax
je 0x8f3a3
movl $0x2ca, 0x2dd842(%rip)  # imm = 0x2CA
jmp 0x8f197
leaq 0x2ac486(%rip), %rdi    # 0x33b830
movl $0x59, %esi
callq 0x9100
testq %rax, %rax
je 0x8f3c8
movl $0x2cb, 0x2dd81d(%rip)  # imm = 0x2CB
jmp 0x8f197
leaq 0x2ac461(%rip), %rdi    # 0x33b830
movl $0x5a, %esi
callq 0x9100
testq %rax, %rax
je 0x8f197
movl $0x2cd, 0x2dd7f4(%rip)  # imm = 0x2CD
jmp 0x8f197