// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heathgps.cpp
// Function: decode_star_msg()
void decode_star_msg()
{
char c;
int i;
static int row = 0;
int time;


   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;

   if(strstr(nmea_msg, "TOD IS NOT VALID")) {  // use system clock if no gps time
      get_clock_time();
      time = (clk_hours*10000) + (clk_minutes*100) + clk_seconds;
      sprintf(nmea_msg, "$GPZDA,%06d,%02d,%02d,%04d,+00,00", time,clk_day,clk_month,clk_year);
//sprintf(debug_text, "fake time %02d:%02d:%02d:  %s", clk_hours,clk_minutes,clk_seconds, nmea_msg);
   }


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

   strupr(nmea_msg);
   msg_col = 0;     // index of next char to get from nmea buffer

if(debug_file) fprintf(debug_file, "Decode STAR msg %d (m:%d l:%d etx:%d):[%s]\n", polled_msg_id, star_msg, star_line, saw_star_etx, nmea_msg);

if(saw_star_etx) {
   star_line = star_msg = 0;
   saw_star_etx = 0;
}
   if(star_msg && star_line) {  // getting multi-line response
      if     (star_msg == STAR_VIS_MSG) parse_star_vis();
      else if(star_msg == STAR_TRACK_MSG) parse_star_track();
      else if(star_msg == STAR_STATE_MSG) parse_star_state();
      else {
         star_line = star_msg = 0;
      }
      if(star_line == 0) {
         poll_next_star(1);
      }
      return;
   }
   else {
      star_line = star_msg = 0;
   }

   if(get_msg_field()) {  // get the STAR message type and parse it
      if     (!strcmp(msg_field, "ALARM"))            parse_star_alarm();
      else if(!strcmp(msg_field, "ALARM_MASK"))       parse_star_alarm_mask();
      else if(!strcmp(msg_field, "AL_MASK"))          parse_star_alarm_mask();
      else if(!strcmp(msg_field, "CONF"))             parse_star_conf();
      else if(!strcmp(msg_field, "GPS_TIME"))         parse_star_gps_time();
      else if(!strcmp(msg_field, "INPUT_TYPE(1)"))    parse_star_inp_type();
      else if(!strcmp(msg_field, "HBSQ"))             parse_star_hbsq();
      else if(!strcmp(msg_field, "INFO_GPS"))         parse_star_pos();
      else if(!strcmp(msg_field, "INV"))              parse_star_inv();
      else if(!strcmp(msg_field, "STATUS"))           parse_star_status();
      else if(!strcmp(msg_field, "TEMPERATURE"))      parse_star_temp();
      else if(!strcmp(msg_field, "TOD_STATE"))        parse_star_tod();
      else if(!strcmp(msg_field, "TYPE"))             parse_star_type();
      else if(!strcmp(msg_field, "MASK_ANGLE"))       parse_star_elmask(); 
      else if(!strcmp(msg_field, "ATDC_STATUS"))      parse_star_atdc(); 
      else if(!strcmp(msg_field, "HOLD_PERF_STATUS")) parse_star_perf(); 
      else if(!strcmp(msg_field, "UTC_OFFSET"))       parse_star_tzone(); 
      else if(!strcmp(msg_field, "WTR"))              parse_star_wtr(); 
      else if(!strcmp(msg_field, "PRIOR_TABLE"))      parse_star_prior();   // !!!! 4531
      else if(!strcmp(msg_field, "OUTPUT_TYPE"))      parse_star_output();  // !!!! 4531
      else if(!strcmp(msg_field, "AUX_INPUT"))        parse_star_aux_inp(); // !!!! 4531
      else if(!strcmp(msg_field, "ADM_STATE"))        parse_star_adm();     // !!!! 4531

      else if(!strcmp(msg_field, "INFO_VIS_SAT")) {    // multi-line response
         parse_star_vis();
         return;
      }
      else if(!strcmp(msg_field, "INFO_TRACK_SAT"))  { // multi-line response
         parse_star_track();
         return;
      }
      else if(!strcmp(msg_field, "INFO_CHAN"))  { // multi-line response
         parse_star_track();
         return;
      }
      else if(!strcmp(msg_field, "OUTPUT_STATE"))    { // multi-line response
         parse_star_state();
         return;
      }

      else if(!strcmp(msg_field, "$GPZDA")) {
start_fake_seconds(45);
         parse_gpzda(GPS); 
start_fake_seconds(45);
         if(pri_seconds == SCPI_STATUS_SECOND) {
            if(star_type == OSA_TYPE) { //OSA
               queue_star_cmd("INFO_GPS",      STAR_POS_MSG);   // !!! //OSA multi-line response
               queue_star_cmd("INFO_CHAN",     STAR_TRACK_MSG);   // !!! multi-line response
               queue_star_cmd("INFO_VIS_SAT;", STAR_VIS_MSG);     // !!! multi-line response
            }
         }
      }

      else if(!strcmp(msg_field, "MODE"))             parse_star_mode();   // !!!!!
      else if(!strcmp(msg_field, "PARAM_ERROR"))      parse_star_error();  // !!!!!
      else if(!strcmp(msg_field, "SYNTAX_ERROR"))     parse_star_error();  // !!!!!
      else if(!strcmp(msg_field, "UNKNOWN_CMD"))      parse_star_error();  // !!!!!
      else if(!strcmp(msg_field, "ERROR,"))           parse_star_error();  // !!!!!
      else if((msg_field[0] == 'O') && (msg_field[1] == 'K')) {
         parse_star_ok(); 
      }
   }

   poll_next_star(2);

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

   saw_rcvr_msg = 1;
   return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x73dcb
leaq 0x29fb80(%rip), %r15    # 0x325830
movb $0x0, (%r15)
leaq 0x29c597(%rip), %r14    # 0x322252
movzwl (%r14), %eax
cmpq %rax, %rbx
jae 0x85cdf
callq 0x51c47
movb %al, (%rbx,%r15)
movb $0x0, 0x1(%rbx,%r15)
incq %rbx
cmpq $0x1f6, %rbx            # imm = 0x1F6
jne 0x85cbb
leaq 0x29c56e(%rip), %rax    # 0x322254
andw $0x0, (%rax)
andw $0x0, (%r14)
leaq 0x29c560(%rip), %rax    # 0x322256
andw $0x0, (%rax)
leaq 0x29fb2f(%rip), %rdi    # 0x325830
leaq 0x88764(%rip), %rsi     # 0x10e46c
callq 0x9090
testq %rax, %rax
je 0x85d6b
callq 0xa386
leaq 0x2719ae(%rip), %rax    # 0x2f76cc
imull $0x2710, (%rax), %eax   # imm = 0x2710
leaq 0x2719a5(%rip), %rcx    # 0x2f76d0
imull $0x64, (%rcx), %edx
addl %eax, %edx
leaq 0x27199d(%rip), %rax    # 0x2f76d4
addl (%rax), %edx
leaq 0x271984(%rip), %rax    # 0x2f76c4
movl (%rax), %ecx
leaq 0x271977(%rip), %rax    # 0x2f76c0
movl (%rax), %r8d
leaq 0x271975(%rip), %rax    # 0x2f76c8
movl (%rax), %r9d
leaq 0x29fad3(%rip), %rdi    # 0x325830
leaq 0x88719(%rip), %rsi     # 0x10e47d
xorl %eax, %eax
callq 0x9060
leaq 0x29fabe(%rip), %rbx    # 0x325830
movq %rbx, %rdi
callq 0x988f
leaq 0x29fec3(%rip), %rax    # 0x325c44
andl $0x0, (%rax)
leaq 0x1a2605(%rip), %rax    # 0x228390
movq (%rax), %rdi
testq %rdi, %rdi
je 0x85dc5
movl 0x2d0e67(%rip), %edx    # 0x356c00
leaq 0x17f25c(%rip), %rax    # 0x204ffc
movl (%rax), %ecx
leaq 0x17f24f(%rip), %rax    # 0x204ff8
movl (%rax), %r8d
movl 0x2d0019(%rip), %r9d    # 0x355dcc
movq %rbx, (%rsp)
leaq 0x886e1(%rip), %rsi     # 0x10e49f
xorl %eax, %eax
callq 0x9560
cmpl $0x0, 0x2d0000(%rip)    # 0x355dcc
je 0x85e52
andl $0x0, 0x2cfff3(%rip)    # 0x355dcc
leaq 0x17f21c(%rip), %rax    # 0x204ffc
andl $0x0, (%rax)
leaq 0x17f20e(%rip), %rax    # 0x204ff8
andl $0x0, (%rax)
callq 0x75767
testl %eax, %eax
je 0x85ea6
leaq 0x29fc3f(%rip), %rdi    # 0x325a40
leaq 0x8b6ae(%rip), %rsi     # 0x1114b6
pushq $0x6
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x85ea1
leaq 0x29fc21(%rip), %rbx    # 0x325a40
leaq 0x886a5(%rip), %rsi     # 0x10e4cb
pushq $0xb
popq %rdx
movq %rbx, %rdi
callq 0x9380
testl %eax, %eax
je 0x85e4b
movq (%rbx), %rbx
movabsq $0x4b53414d5f4c41, %rax # imm = 0x4B53414D5F4C41
cmpq %rax, %rbx
jne 0x85eed
callq 0x85c17
jmp 0x85ea6
leaq 0x17f1a3(%rip), %rax    # 0x204ffc
movl (%rax), %ecx
testl %ecx, %ecx
je 0x85dd9
leaq 0x17f18e(%rip), %rbx    # 0x204ff8
cmpl $0x0, (%rbx)
je 0x85dd9
cmpl $0xd2, %ecx
je 0x85f94
cmpl $0xce, %ecx
je 0x85f8d
cmpl $0xcd, %ecx
jne 0x85fa4
callq 0x84a10
jmp 0x85f99
callq 0x83108
callq 0x66490
leaq 0x1a250e(%rip), %rax    # 0x2283c0
cmpq $0x0, (%rax)
setne %al
leaq 0x187740(%rip), %rcx    # 0x20d600
movq (%rcx), %rdi
testq %rdi, %rdi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x85ed5
callq 0xae83
leaq 0x1a30c4(%rip), %rax    # 0x228fa0
movl $0x1, (%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x29fb4c(%rip), %rdi    # 0x325a40
leaq 0x885db(%rip), %rsi     # 0x10e4d6
pushq $0x5
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x85fb9
leaq 0x29fb2e(%rip), %rdi    # 0x325a40
leaq 0x885c2(%rip), %rsi     # 0x10e4db
pushq $0x9
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x85fc3
leaq 0x29fb10(%rip), %rdi    # 0x325a40
leaq 0x885ad(%rip), %rsi     # 0x10e4e4
pushq $0xe
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x85fcd
leaq 0x29faf2(%rip), %rdi    # 0x325a40
leaq 0x8816d(%rip), %rsi     # 0x10e0c2
pushq $0x5
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x85fd7
leaq 0x29fad8(%rip), %rdi    # 0x325a40
leaq 0x88002(%rip), %rsi     # 0x10df71
pushq $0x9
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x85fe1
cmpl $0x564e49, %ebx         # imm = 0x564E49
jne 0x85feb
callq 0x8581f
jmp 0x85ea6
callq 0x84ea2
jmp 0x85f99
callq 0x851a6
cmpl $0x0, (%rbx)
jne 0x85ee2
jmp 0x85faa
andl $0x0, (%rax)
andl $0x0, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x66490
callq 0x834d1
jmp 0x85ea6
callq 0x838cc
jmp 0x85ea6
callq 0x85bb1
jmp 0x85ea6
callq 0x83826
jmp 0x85ea6
callq 0x83dba
jmp 0x85ea6
leaq 0x29fa4e(%rip), %rdi    # 0x325a40
leaq 0x8a1d6(%rip), %rsi     # 0x1101cf
pushq $0x7
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x860e1
leaq 0x29fa30(%rip), %rdi    # 0x325a40
leaq 0x884db(%rip), %rsi     # 0x10e4f2
pushq $0xc
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x860eb
leaq 0x29fa12(%rip), %rdi    # 0x325a40
leaq 0x8517e(%rip), %rsi     # 0x10b1b3
pushq $0xa
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x860f5
leaq 0x29f9f4(%rip), %rdi    # 0x325a40
leaq 0x97705(%rip), %rsi     # 0x11d758
pushq $0x5
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x860ff
leaq 0x29f9d6(%rip), %rdi    # 0x325a40
leaq 0x8848d(%rip), %rsi     # 0x10e4fe
pushq $0xb
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x86109
leaq 0x29f9b8(%rip), %rdi    # 0x325a40
leaq 0x8847a(%rip), %rsi     # 0x10e509
pushq $0xc
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x86113
leaq 0x29f99e(%rip), %rdi    # 0x325a40
leaq 0x8846c(%rip), %rsi     # 0x10e515
pushq $0x11
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x8611d
leaq 0x29f984(%rip), %rdi    # 0x325a40
leaq 0x88463(%rip), %rsi     # 0x10e526
pushq $0xb
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x86127
cmpl $0x525457, %ebx         # imm = 0x525457
jne 0x86131
callq 0x852e8
jmp 0x85ea6
callq 0x8320e
jmp 0x85ea6
callq 0x856a8
jmp 0x85ea6
callq 0x856ef
jmp 0x85ea6
callq 0x857b8
jmp 0x85ea6
callq 0x85b59
jmp 0x85ea6
callq 0x8564c
jmp 0x85ea6
callq 0x852ae
jmp 0x85ea6
callq 0x85c39
jmp 0x85ea6
leaq 0x29f908(%rip), %rdi    # 0x325a40
leaq 0x88219(%rip), %rsi     # 0x10e358
pushq $0xc
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x862ea
leaq 0x29f8ea(%rip), %rdi    # 0x325a40
leaq 0x881de(%rip), %rsi     # 0x10e33b
pushq $0xc
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x862f4
leaq 0x29f8cc(%rip), %rdi    # 0x325a40
leaq 0x881f8(%rip), %rsi     # 0x10e373
pushq $0xa
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x862fe
leaq 0x29f8ae(%rip), %rdi    # 0x325a40
leaq 0x881f3(%rip), %rsi     # 0x10e38c
pushq $0xa
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x86308
leaq 0x29f890(%rip), %rdi    # 0x325a40
leaq 0x8837a(%rip), %rsi     # 0x10e531
pushq $0xd
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x86321
leaq 0x29f872(%rip), %rdi    # 0x325a40
leaq 0x88369(%rip), %rsi     # 0x10e53e
pushq $0xf
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x86312
leaq 0x29f854(%rip), %rdi    # 0x325a40
leaq 0x87ffb(%rip), %rsi     # 0x10e1ee
pushq $0xa
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x86312
leaq 0x29f836(%rip), %rdi    # 0x325a40
leaq 0x8833c(%rip), %rsi     # 0x10e54d
pushq $0xd
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x86330
leaq 0x29f818(%rip), %rdi    # 0x325a40
leaq 0x8832b(%rip), %rsi     # 0x10e55a
pushq $0x7
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x8633f
leaq 0x29f7fa(%rip), %rdi    # 0x325a40
leaq 0x8bacf(%rip), %rsi     # 0x111d1c
pushq $0x5
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x863b3
leaq 0x29f7dc(%rip), %rdi    # 0x325a40
leaq 0x882f6(%rip), %rsi     # 0x10e561
pushq $0xc
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x863a9
leaq 0x29f7be(%rip), %rdi    # 0x325a40
leaq 0x882e4(%rip), %rsi     # 0x10e56d
pushq $0xd
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x863a9
leaq 0x29f7a0(%rip), %rdi    # 0x325a40
leaq 0x882d3(%rip), %rsi     # 0x10e57a
pushq $0xc
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x863a9
leaq 0x29f782(%rip), %rdi    # 0x325a40
leaq 0x882c1(%rip), %rsi     # 0x10e586
pushq $0x7
popq %rdx
callq 0x9380
testl %eax, %eax
je 0x863a9
cmpw $0x4b4f, %bx            # imm = 0x4B4F
jne 0x85ea6
callq 0x85c4a
jmp 0x85ea6
callq 0x84926
jmp 0x85ea6
callq 0x848be
jmp 0x85ea6
callq 0x84974
jmp 0x85ea6
callq 0x849c2
jmp 0x85ea6
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x84ea2
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x84a10
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x851a6
callq 0x83b1e
pushq $0x1
popq %rdi
callq 0x7687c
callq 0x83b1e
leaq 0x2711a8(%rip), %rax    # 0x2f7500
cmpl $0x20, (%rax)
jne 0x85ea6
leaq 0x17ec80(%rip), %rax    # 0x204fe8
cmpl $0x4f, (%rax)
jne 0x85ea6
leaq 0x87bf9(%rip), %rdi     # 0x10df71
movl $0x12b, %esi            # imm = 0x12B
callq 0x576d4
leaq 0x87e65(%rip), %rdi     # 0x10e1ee
movl $0xce, %esi
callq 0x576d4
leaq 0x87e46(%rip), %rdi     # 0x10e1e0
movl $0xcd, %esi
callq 0x576d4
jmp 0x85ea6
callq 0x85c70
jmp 0x85ea6
callq 0x85c28
jmp 0x85ea6