// File: 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
subq $0x20, %rsp
xorl %edi, %edi
callq 0xae4a0
leaq 0x2d1daa(%rip), %rax    # 0x39aa10
movb $0x0, (%rax)
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
leaq 0x2ce7b8(%rip), %rcx    # 0x397432
movzwl (%rcx), %ecx
cmpl %ecx, %eax
jge 0xc8cc6
callq 0x7a510
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %dl
movslq -0x8(%rbp), %rcx
leaq 0x2d1d79(%rip), %rax    # 0x39aa10
movb %dl, (%rax,%rcx)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0x2d1d66(%rip), %rax    # 0x39aa10
movb $0x0, (%rax,%rcx)
cmpl $0x1f5, -0x8(%rbp)      # imm = 0x1F5
jl 0xc8cb9
jmp 0xc8cc6
jmp 0xc8cbb
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0xc8c70
leaq 0x2ce767(%rip), %rax    # 0x397434
movw $0x0, (%rax)
leaq 0x2ce759(%rip), %rax    # 0x397432
movw $0x0, (%rax)
leaq 0x2ce751(%rip), %rax    # 0x397436
movw $0x0, (%rax)
leaq 0x2d1d1f(%rip), %rdi    # 0x39aa10
leaq 0xbeb14(%rip), %rsi     # 0x18780c
callq 0x9090
cmpq $0x0, %rax
je 0xc8d62
callq 0xa750
leaq 0x2a3b9d(%rip), %rax    # 0x36c8ac
imull $0x2710, (%rax), %eax   # imm = 0x2710
leaq 0x2a3b94(%rip), %rcx    # 0x36c8b0
imull $0x64, (%rcx), %ecx
addl %ecx, %eax
leaq 0x2a3b8c(%rip), %rcx    # 0x36c8b4
addl (%rcx), %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %edx
leaq 0x2a3b6d(%rip), %rax    # 0x36c8a4
movl (%rax), %ecx
leaq 0x2a3b60(%rip), %rax    # 0x36c8a0
movl (%rax), %r8d
leaq 0x2a3b5e(%rip), %rax    # 0x36c8a8
movl (%rax), %r9d
leaq 0x2d1cbc(%rip), %rdi    # 0x39aa10
leaq 0xbeac2(%rip), %rsi     # 0x18781d
movb $0x0, %al
callq 0x9060
leaq 0x2d1ca7(%rip), %rdi    # 0x39aa10
callq 0x9890
leaq 0x2d20af(%rip), %rax    # 0x39ae24
movl $0x0, (%rax)
leaq 0x1d47ee(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0xc8dcb
leaq 0x1d47e1(%rip), %rax    # 0x29d570
movq (%rax), %rdi
movl 0x303038(%rip), %edx    # 0x3cbdd0
leaq 0x1b143d(%rip), %rax    # 0x27a1dc
movl (%rax), %ecx
leaq 0x1b1430(%rip), %rax    # 0x27a1d8
movl (%rax), %r8d
movl 0x3021fa(%rip), %r9d    # 0x3cafac
leaq 0xbea86(%rip), %rsi     # 0x18783f
leaq 0x2d1c50(%rip), %rax    # 0x39aa10
movq %rax, (%rsp)
movb $0x0, %al
callq 0x9550
cmpl $0x0, 0x3021da(%rip)    # 0x3cafac
je 0xc8df8
leaq 0x1b1401(%rip), %rax    # 0x27a1dc
movl $0x0, (%rax)
leaq 0x1b13f0(%rip), %rax    # 0x27a1d8
movl $0x0, (%rax)
movl $0x0, 0x3021b4(%rip)    # 0x3cafac
leaq 0x1b13dd(%rip), %rax    # 0x27a1dc
cmpl $0x0, (%rax)
je 0xc8e8f
leaq 0x1b13c9(%rip), %rax    # 0x27a1d8
cmpl $0x0, (%rax)
je 0xc8e8f
leaq 0x1b13c1(%rip), %rax    # 0x27a1dc
cmpl $0xcd, (%rax)
jne 0xc8e2a
callq 0xc7270
jmp 0xc8e74
leaq 0x1b13ab(%rip), %rax    # 0x27a1dc
cmpl $0xce, (%rax)
jne 0xc8e40
callq 0xc78d0
jmp 0xc8e72
leaq 0x1b1395(%rip), %rax    # 0x27a1dc
cmpl $0xd2, (%rax)
jne 0xc8e56
callq 0xc7da0
jmp 0xc8e70
leaq 0x1b137f(%rip), %rax    # 0x27a1dc
movl $0x0, (%rax)
leaq 0x1b136e(%rip), %rax    # 0x27a1d8
movl $0x0, (%rax)
jmp 0xc8e72
jmp 0xc8e74
leaq 0x1b135d(%rip), %rax    # 0x27a1d8
cmpl $0x0, (%rax)
jne 0xc8e8a
movl $0x1, %edi
callq 0x987f0
jmp 0xc93fc
leaq 0x1b1346(%rip), %rax    # 0x27a1dc
movl $0x0, (%rax)
leaq 0x1b1335(%rip), %rax    # 0x27a1d8
movl $0x0, (%rax)
callq 0xb0bd0
cmpl $0x0, %eax
je 0xc93ba
leaq 0x2d1d62(%rip), %rdi    # 0x39ac20
leaq 0xc1a66(%rip), %rsi     # 0x18a92b
callq 0x9510
cmpl $0x0, %eax
jne 0xc8ed9
callq 0xc5060
jmp 0xc93b8
leaq 0x2d1d40(%rip), %rdi    # 0x39ac20
leaq 0xbe984(%rip), %rsi     # 0x18786b
callq 0x9510
cmpl $0x0, %eax
jne 0xc8efb
callq 0xc8b90
jmp 0xc93b6
leaq 0x2d1d1e(%rip), %rdi    # 0x39ac20
leaq 0xbe8a5(%rip), %rsi     # 0x1877ae
callq 0x9510
cmpl $0x0, %eax
jne 0xc8f1d
callq 0xc8b90
jmp 0xc93b4
leaq 0x2d1cfc(%rip), %rdi    # 0x39ac20
leaq 0xbe94b(%rip), %rsi     # 0x187876
callq 0x9510
cmpl $0x0, %eax
jne 0xc8f3f
callq 0xc5670
jmp 0xc93b2
leaq 0x2d1cda(%rip), %rdi    # 0x39ac20
leaq 0xbe92e(%rip), %rsi     # 0x18787b
callq 0x9510
cmpl $0x0, %eax
jne 0xc8f61
callq 0xc5bc0
jmp 0xc93b0
leaq 0x2d1cb8(%rip), %rdi    # 0x39ac20
leaq 0xbe915(%rip), %rsi     # 0x187884
callq 0x9510
cmpl $0x0, %eax
jne 0xc8f83
callq 0xc8b00
jmp 0xc93ae
leaq 0x2d1c96(%rip), %rdi    # 0x39ac20
leaq 0xbe4d6(%rip), %rsi     # 0x187467
callq 0x9510
cmpl $0x0, %eax
jne 0xc8fa5
callq 0xc5ab0
jmp 0xc93ac
leaq 0x2d1c74(%rip), %rdi    # 0x39ac20
leaq 0xbe363(%rip), %rsi     # 0x187316
callq 0x9510
cmpl $0x0, %eax
jne 0xc8fc7
callq 0xc62a0
jmp 0xc93aa
leaq 0x2d1c52(%rip), %rdi    # 0x39ac20
leaq 0xbe8bd(%rip), %rsi     # 0x187892
callq 0x9510
cmpl $0x0, %eax
jne 0xc8fe9
callq 0xc8670
jmp 0xc93a8
leaq 0x2d1c30(%rip), %rdi    # 0x39ac20
leaq 0xc060a(%rip), %rsi     # 0x189601
callq 0x9510
cmpl $0x0, %eax
jne 0xc900b
callq 0xc52b0
jmp 0xc93a6
leaq 0x2d1c0e(%rip), %rdi    # 0x39ac20
leaq 0xbe87d(%rip), %rsi     # 0x187896
callq 0x9510
cmpl $0x0, %eax
jne 0xc902d
callq 0xc84b0
jmp 0xc93a4
leaq 0x2d1bec(%rip), %rdi    # 0x39ac20
leaq 0xbb4c0(%rip), %rsi     # 0x1844fb
callq 0x9510
cmpl $0x0, %eax
jne 0xc904f
callq 0xc8500
jmp 0xc93a2
leaq 0x2d1bca(%rip), %rdi    # 0x39ac20
leaq 0xcd343(%rip), %rsi     # 0x1963a0
callq 0x9510
cmpl $0x0, %eax
jne 0xc9071
callq 0xc85f0
jmp 0xc93a0
leaq 0x2d1ba8(%rip), %rdi    # 0x39ac20
leaq 0xbe823(%rip), %rsi     # 0x1878a2
callq 0x9510
cmpl $0x0, %eax
jne 0xc9093
callq 0xc8a70
jmp 0xc939e
leaq 0x2d1b86(%rip), %rdi    # 0x39ac20
leaq 0xbe80c(%rip), %rsi     # 0x1878ad
callq 0x9510
cmpl $0x0, %eax
jne 0xc90b5
callq 0xc8430
jmp 0xc939c
leaq 0x2d1b64(%rip), %rdi    # 0x39ac20
leaq 0xbe7f6(%rip), %rsi     # 0x1878b9
callq 0x9510
cmpl $0x0, %eax
jne 0xc90d7
callq 0xc7fb0
jmp 0xc939a
leaq 0x2d1b42(%rip), %rdi    # 0x39ac20
leaq 0xbe7e5(%rip), %rsi     # 0x1878ca
callq 0x9510
cmpl $0x0, %eax
jne 0xc90f9
callq 0xc8bd0
jmp 0xc9398
leaq 0x2d1b20(%rip), %rdi    # 0x39ac20
leaq 0xbe5a2(%rip), %rsi     # 0x1876a9
callq 0x9510
cmpl $0x0, %eax
jne 0xc911b
callq 0xc7ff0
jmp 0xc9396
leaq 0x2d1afe(%rip), %rdi    # 0x39ac20
leaq 0xbe5cf(%rip), %rsi     # 0x1876f8
callq 0x9510
cmpl $0x0, %eax
jne 0xc913d
callq 0xc7150
jmp 0xc9394
leaq 0x2d1adc(%rip), %rdi    # 0x39ac20
leaq 0xbe590(%rip), %rsi     # 0x1876db
callq 0x9510
cmpl $0x0, %eax
jne 0xc915f
callq 0xc70c0
jmp 0xc9392
leaq 0x2d1aba(%rip), %rdi    # 0x39ac20
leaq 0xbe5a6(%rip), %rsi     # 0x187713
callq 0x9510
cmpl $0x0, %eax
jne 0xc9181
callq 0xc71b0
jmp 0xc9390
leaq 0x2d1a98(%rip), %rdi    # 0x39ac20
leaq 0xbe59d(%rip), %rsi     # 0x18772c
callq 0x9510
cmpl $0x0, %eax
jne 0xc91a3
callq 0xc7210
jmp 0xc938e
leaq 0x2d1a76(%rip), %rdi    # 0x39ac20
leaq 0xbe724(%rip), %rsi     # 0x1878d5
callq 0x9510
cmpl $0x0, %eax
jne 0xc91c5
callq 0xc7270
jmp 0xc93fc
leaq 0x2d1a54(%rip), %rdi    # 0x39ac20
leaq 0xbe70f(%rip), %rsi     # 0x1878e2
callq 0x9510
cmpl $0x0, %eax
jne 0xc91e7
callq 0xc78d0
jmp 0xc93fc
leaq 0x2d1a32(%rip), %rdi    # 0x39ac20
leaq 0xbe39e(%rip), %rsi     # 0x187593
callq 0x9510
cmpl $0x0, %eax
jne 0xc9209
callq 0xc78d0
jmp 0xc93fc
leaq 0x2d1a10(%rip), %rdi    # 0x39ac20
leaq 0xbe6da(%rip), %rsi     # 0x1878f1
callq 0x9510
cmpl $0x0, %eax
jne 0xc922b
callq 0xc7da0
jmp 0xc93fc
leaq 0x2d19ee(%rip), %rdi    # 0x39ac20
leaq 0xbe6c5(%rip), %rsi     # 0x1878fe
callq 0x9510
cmpl $0x0, %eax
jne 0xc92b3
movl $0x2d, %edi
callq 0xc5ec0
movl $0x1, %edi
callq 0xb2390
movl $0x2d, %edi
callq 0xc5ec0
leaq 0x2a3478(%rip), %rax    # 0x36c6e0
cmpl $0x20, (%rax)
jne 0xc92ae
leaq 0x1b0f54(%rip), %rax    # 0x27a1c8
cmpl $0x4f, (%rax)
jne 0xc92ac
leaq 0xbe096(%rip), %rdi     # 0x187316
movl $0x12b, %esi            # imm = 0x12B
callq 0x82fd0
leaq 0xbe302(%rip), %rdi     # 0x187593
movl $0xce, %esi
callq 0x82fd0
leaq 0xbe2e3(%rip), %rdi     # 0x187585
movl $0xcd, %esi
callq 0x82fd0
jmp 0xc92ae
jmp 0xc9384
leaq 0x2d1966(%rip), %rdi    # 0x39ac20
leaq 0xc1eda(%rip), %rsi     # 0x18b19b
callq 0x9510
cmpl $0x0, %eax
jne 0xc92d5
callq 0xc8bb0
jmp 0xc9382
leaq 0x2d1944(%rip), %rdi    # 0x39ac20
leaq 0xbe622(%rip), %rsi     # 0x187905
callq 0x9510
cmpl $0x0, %eax
jne 0xc92f7
callq 0xc8c20
jmp 0xc9380
leaq 0x2d1922(%rip), %rdi    # 0x39ac20
leaq 0xbe60c(%rip), %rsi     # 0x187911
callq 0x9510
cmpl $0x0, %eax
jne 0xc9316
callq 0xc8c20
jmp 0xc937e
leaq 0x2d1903(%rip), %rdi    # 0x39ac20
leaq 0xbe5fa(%rip), %rsi     # 0x18791e
callq 0x9510
cmpl $0x0, %eax
jne 0xc9335
callq 0xc8c20
jmp 0xc937c
leaq 0x2d18e4(%rip), %rdi    # 0x39ac20
leaq 0xbe5e7(%rip), %rsi     # 0x18792a
callq 0x9510
cmpl $0x0, %eax
jne 0xc9354
callq 0xc8c20
jmp 0xc937a
leaq 0x2d18c5(%rip), %rax    # 0x39ac20
movsbl (%rax), %eax
cmpl $0x4f, %eax
jne 0xc9378
leaq 0x2d18b6(%rip), %rax    # 0x39ac20
movsbl 0x1(%rax), %eax
cmpl $0x4b, %eax
jne 0xc9378
callq 0xc8bf0
jmp 0xc937a
jmp 0xc937c
jmp 0xc937e
jmp 0xc9380
jmp 0xc9382
jmp 0xc9384
jmp 0xc9386
jmp 0xc9388
jmp 0xc938a
jmp 0xc938c
jmp 0xc938e
jmp 0xc9390
jmp 0xc9392
jmp 0xc9394
jmp 0xc9396
jmp 0xc9398
jmp 0xc939a
jmp 0xc939c
jmp 0xc939e
jmp 0xc93a0
jmp 0xc93a2
jmp 0xc93a4
jmp 0xc93a6
jmp 0xc93a8
jmp 0xc93aa
jmp 0xc93ac
jmp 0xc93ae
jmp 0xc93b0
jmp 0xc93b2
jmp 0xc93b4
jmp 0xc93b6
jmp 0xc93b8
jmp 0xc93ba
movl $0x2, %edi
callq 0x987f0
leaq 0x1d41d5(%rip), %rax    # 0x29d5a0
cmpq $0x0, (%rax)
je 0xc93ef
leaq 0x1b9408(%rip), %rax    # 0x2827e0
cmpq $0x0, (%rax)
je 0xc93ef
leaq 0x1b93fb(%rip), %rax    # 0x2827e0
movq (%rax), %rax
movl %eax, %edi
callq 0xb8b0
leaq 0x1d4d8a(%rip), %rax    # 0x29e180
movl $0x1, (%rax)
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)