// File: /workspace/github_cpp_makefile_star2_O1/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 %r12
pushq %rbx
subq $0x10, %rsp
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x7f47d
leaq 0x2a8cad(%rip), %r15    # 0x33b830
movb $0x0, (%r15)
leaq 0x2a56c4(%rip), %r14    # 0x338252
leaq 0x1ac3db(%rip), %r12    # 0x23ef70
movzwl (%r14), %eax
cmpq %rax, %rbx
jae 0x92bc5
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x92baf
orb $0x8, (%r12)
movb %al, (%rbx,%r15)
movb $0x0, 0x1(%rbx,%r15)
incq %rbx
cmpq $0x1f6, %rbx            # imm = 0x1F6
jne 0x92b95
leaq 0x2a5688(%rip), %rax    # 0x338254
xorl %ecx, %ecx
movw %cx, (%rax)
movw %cx, (%r14)
leaq 0x2a567a(%rip), %rax    # 0x338256
movw %cx, (%rax)
leaq 0x2a8c4a(%rip), %rdi    # 0x33b830
leaq 0x91857(%rip), %rsi     # 0x124444
callq 0x9090
testq %rax, %rax
je 0x92c50
callq 0xa495
leaq 0x27aac9(%rip), %rax    # 0x30d6cc
imull $0x2710, (%rax), %eax   # imm = 0x2710
leaq 0x27aac0(%rip), %rcx    # 0x30d6d0
imull $0x64, (%rcx), %edx
addl %eax, %edx
leaq 0x27aab8(%rip), %rax    # 0x30d6d4
addl (%rax), %edx
leaq 0x27aa9f(%rip), %rax    # 0x30d6c4
movl (%rax), %ecx
leaq 0x27aa92(%rip), %rax    # 0x30d6c0
movl (%rax), %r8d
leaq 0x27aa90(%rip), %rax    # 0x30d6c8
movl (%rax), %r9d
leaq 0x2a8bee(%rip), %rdi    # 0x33b830
leaq 0x9180c(%rip), %rsi     # 0x124455
xorl %eax, %eax
callq 0x9060
leaq 0x2a8bd9(%rip), %rbx    # 0x33b830
movq %rbx, %rdi
callq 0x9899
leaq 0x2a8fde(%rip), %rax    # 0x33bc44
movl $0x0, (%rax)
leaq 0x1ab71d(%rip), %rax    # 0x23e390
movq (%rax), %rdi
testq %rdi, %rdi
je 0x92cad
movl 0x2d9f7f(%rip), %edx    # 0x36cc00
leaq 0x188374(%rip), %rax    # 0x21affc
movl (%rax), %ecx
leaq 0x188367(%rip), %rax    # 0x21aff8
movl (%rax), %r8d
movl 0x2d9131(%rip), %r9d    # 0x36bdcc
movq %rbx, (%rsp)
leaq 0x917d1(%rip), %rsi     # 0x124477
xorl %eax, %eax
callq 0x9560
cmpl $0x0, 0x2d9118(%rip)    # 0x36bdcc
je 0x92cd0
leaq 0x18833f(%rip), %rax    # 0x21affc
xorl %ecx, %ecx
movl %ecx, (%rax)
leaq 0x188330(%rip), %rax    # 0x21aff8
movl %ecx, (%rax)
movl %ecx, 0x2d90fc(%rip)    # 0x36bdcc
leaq 0x188325(%rip), %r14    # 0x21affc
movl (%r14), %eax
leaq 0x188317(%rip), %rbx    # 0x21aff8
testl %eax, %eax
je 0x92d15
cmpl $0x0, (%rbx)
je 0x92d15
cmpl $0xd2, %eax
je 0x92d87
cmpl $0xce, %eax
je 0x92d80
cmpl $0xcd, %eax
jne 0x92d8e
callq 0x91879
jmp 0x92d95
xorl %eax, %eax
movl %eax, (%r14)
movl %eax, (%rbx)
callq 0x811da
testl %eax, %eax
je 0x92db0
leaq 0x2a8d10(%rip), %rax    # 0x33ba40
movl $0x52414c41, %ecx       # imm = 0x52414C41
xorl (%rax), %ecx
movzwl 0x4(%rax), %edx
xorl $0x4d, %edx
orl %ecx, %edx
je 0x92dab
movabsq $0x4b53414d5f4c41, %rcx # imm = 0x4B53414D5F4C41
movabsq $0x414d5f4d52414c41, %rdx # imm = 0x414D5F4D52414C41
xorq (%rax), %rdx
leaq 0x111(%rcx), %rsi
xorq 0x3(%rax), %rsi
orq %rdx, %rsi
je 0x92d72
cmpq %rcx, (%rax)
jne 0x92df9
leaq 0x91690(%rip), %rdi     # 0x124409
callq 0x58e77
jmp 0x92db0
callq 0x91d23
jmp 0x92d95
callq 0x92054
jmp 0x92d95
xorl %eax, %eax
movl %eax, (%r14)
movl %eax, (%rbx)
cmpl $0x0, (%rbx)
jne 0x92dec
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x6fae3
callq 0x8fdc9
callq 0x6fae3
leaq 0x1ab604(%rip), %rax    # 0x23e3c0
cmpq $0x0, (%rax)
setne %al
leaq 0x190836(%rip), %rcx    # 0x223600
movq (%rcx), %rdi
testq %rdi, %rdi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x92ddf
callq 0xaff7
leaq 0x1ac1ba(%rip), %rax    # 0x23efa0
movl $0x1, (%rax)
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl $0x464e4f43, %ecx       # imm = 0x464E4F43
xorl (%rax), %ecx
movzbl 0x4(%rax), %edx
orl %ecx, %edx
je 0x92e77
movabsq $0x454d49545f535047, %rcx # imm = 0x454D49545F535047
xorq (%rax), %rcx
movzbl 0x8(%rax), %edx
orq %rcx, %rdx
je 0x92e81
movabsq $0x59545f5455504e49, %rcx # imm = 0x59545F5455504E49
xorq (%rax), %rcx
movabsq $0x29312845505954, %rdx # imm = 0x29312845505954
xorq 0x6(%rax), %rdx
orq %rcx, %rdx
je 0x92e8b
movl $0x51534248, %ecx       # imm = 0x51534248
xorl (%rax), %ecx
movzbl 0x4(%rax), %edx
orl %ecx, %edx
je 0x92e95
movabsq $0x5350475f4f464e49, %rcx # imm = 0x5350475F4F464E49
xorq (%rax), %rcx
movzbl 0x8(%rax), %edx
orq %rcx, %rdx
je 0x92e9f
movl (%rax), %edx
cmpl $0x564e49, %edx         # imm = 0x564E49
jne 0x92ea9
callq 0x926d0
jmp 0x92db0
callq 0x901ab
jmp 0x92db0
callq 0x905a8
jmp 0x92db0
callq 0x92a7d
jmp 0x92db0
callq 0x904fb
jmp 0x92db0
callq 0x90b54
jmp 0x92db0
movl $0x54415453, %ecx       # imm = 0x54415453
xorl (%rax), %ecx
movl $0x535554, %esi         # imm = 0x535554
xorl 0x3(%rax), %esi
orl %ecx, %esi
je 0x92fb2
movabsq $0x54415245504d4554, %rcx # imm = 0x54415245504D4554
xorq (%rax), %rcx
movl 0x8(%rax), %esi
xorq $0x455255, %rsi         # imm = 0x455255
orq %rcx, %rsi
je 0x92fbc
movabsq $0x544154535f444f54, %rcx # imm = 0x544154535F444F54
movq (%rax), %rsi
xorq %rcx, %rsi
movzwl 0x8(%rax), %edi
xorq $0x45, %rdi
orq %rsi, %rdi
je 0x92fc6
movl $0x45505954, %esi       # imm = 0x45505954
xorl (%rax), %esi
movzbl 0x4(%rax), %edi
orl %esi, %edi
je 0x92fd0
movabsq $0x474e415f4b53414d, %rsi # imm = 0x474E415F4B53414D
xorq (%rax), %rsi
movabsq $0x454c474e415f4b, %rdi # imm = 0x454C474E415F4B
xorq 0x3(%rax), %rdi
orq %rsi, %rdi
je 0x92fda
movabsq $0x4154535f43445441, %rsi # imm = 0x4154535F43445441
xorq (%rax), %rsi
movl 0x8(%rax), %edi
xorq $0x535554, %rdi         # imm = 0x535554
orq %rsi, %rdi
je 0x92fe4
movabsq $0x5355544154535f46, %rsi # imm = 0x5355544154535F46
xorq 0x8(%rax), %rsi
movabsq $0x5245505f444c4f48, %rdi # imm = 0x5245505F444C4F48
xorq (%rax), %rdi
movzbl 0x10(%rax), %r8d
orq %rdi, %r8
orq %rsi, %r8
je 0x92fee
movabsq $0x5346464f5f435455, %rsi # imm = 0x5346464F5F435455
xorq (%rax), %rsi
movabsq $0x54455346464f5f, %rdi # imm = 0x54455346464F5F
xorq 0x3(%rax), %rdi
orq %rsi, %rdi
je 0x92ff8
cmpl $0x525457, %edx         # imm = 0x525457
jne 0x93004
callq 0x92188
jmp 0x92db0
callq 0x8fedb
jmp 0x92db0
callq 0x92555
jmp 0x92db0
callq 0x9259c
jmp 0x92db0
callq 0x92669
jmp 0x92db0
callq 0x92a25
jmp 0x92db0
callq 0x924f9
jmp 0x92db0
callq 0x9214e
jmp 0x92db0
leaq 0x91424(%rip), %rdi     # 0x124423
jmp 0x92d79
movabsq $0x41545f524f495250, %rdx # imm = 0x41545F524F495250
xorq (%rax), %rdx
movl 0x8(%rax), %esi
xorq $0x454c42, %rsi         # imm = 0x454C42
orq %rdx, %rsi
je 0x931c8
movabsq $0x545f54555054554f, %rdx # imm = 0x545F54555054554F
xorq (%rax), %rdx
movl 0x8(%rax), %esi
xorq $0x455059, %rsi         # imm = 0x455059
orq %rdx, %rsi
je 0x931d2
movabsq $0x55504e495f585541, %rdx # imm = 0x55504E495F585541
xorq (%rax), %rdx
movzwl 0x8(%rax), %esi
xorq $0x54, %rsi
orq %rdx, %rsi
je 0x931dc
addq $0x8f4ed, %rcx          # imm = 0x8F4ED
xorq (%rax), %rcx
movzwl 0x8(%rax), %edx
xorq $0x45, %rdx
orq %rcx, %rdx
je 0x931e6
movabsq $0x5441535f4b4341, %rcx # imm = 0x5441535F4B4341
movabsq $0x5349565f4f464e49, %rdx # imm = 0x5349565F4F464E49
xorq (%rax), %rdx
leaq 0x80615(%rcx), %rsi
xorq 0x5(%rax), %rsi
orq %rdx, %rsi
je 0x93201
movabsq $0x4152545f4f464e49, %rdx # imm = 0x4152545F4F464E49
xorq (%rax), %rdx
xorq 0x7(%rax), %rcx
orq %rdx, %rcx
je 0x931f0
movabsq $0x4148435f4f464e49, %rcx # imm = 0x4148435F4F464E49
xorq (%rax), %rcx
movzwl 0x8(%rax), %edx
xorq $0x4e, %rdx
orq %rcx, %rdx
je 0x931f0
movabsq $0x535f54555054554f, %rcx # imm = 0x535F54555054554F
xorq (%rax), %rcx
movabsq $0x45544154535f54, %rdx # imm = 0x45544154535F54
xorq 0x5(%rax), %rdx
orq %rcx, %rdx
je 0x93212
movl $0x5a504724, %ecx       # imm = 0x5A504724
xorl (%rax), %ecx
movl $0x41445a, %edx         # imm = 0x41445A
xorl 0x3(%rax), %edx
orl %ecx, %edx
je 0x93223
movl $0x45444f4d, %ecx       # imm = 0x45444F4D
xorl (%rax), %ecx
movzbl 0x4(%rax), %edx
orl %ecx, %edx
je 0x932d7
movabsq $0x52455f4d41524150, %rcx # imm = 0x52455F4D41524150
xorq (%rax), %rcx
movl 0x8(%rax), %edx
xorq $0x524f52, %rdx         # imm = 0x524F52
orq %rcx, %rdx
je 0x932bf
movabsq $0x455f5841544e5953, %rcx # imm = 0x455F5841544E5953
xorq (%rax), %rcx
movabsq $0x524f5252455f58, %rdx # imm = 0x524F5252455F58
xorq 0x5(%rax), %rdx
orq %rcx, %rdx
je 0x932bf
movabsq $0x5f4e574f4e4b4e55, %rcx # imm = 0x5F4E574F4E4B4E55
xorq (%rax), %rcx
movl 0x8(%rax), %edx
xorq $0x444d43, %rdx         # imm = 0x444D43
orq %rcx, %rdx
je 0x932bf
movl $0x4f525245, %ecx       # imm = 0x4F525245
xorl (%rax), %ecx
movl $0x2c524f, %edx         # imm = 0x2C524F
xorl 0x3(%rax), %edx
orl %ecx, %edx
je 0x932bf
cmpb $0x4f, (%rax)
jne 0x92db0
cmpb $0x4b, 0x1(%rax)
jne 0x92db0
leaq 0x9126e(%rip), %rdi     # 0x124431
jmp 0x932c6
callq 0x9178f
jmp 0x92db0
callq 0x91724
jmp 0x92db0
callq 0x917dd
jmp 0x92db0
callq 0x9182b
jmp 0x92db0
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x91d23
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x91879
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x92054
callq 0xaea1
addsd 0x75e08(%rip), %xmm0    # 0x109038
leaq 0x27a4c1(%rip), %rbx    # 0x30d6f8
movsd %xmm0, (%rbx)
xorl %r14d, %r14d
movl %r14d, 0x2dec13(%rip)   # 0x371e58
movl $0x1, %edi
callq 0x823b3
callq 0xaea1
addsd 0x75ddc(%rip), %xmm0    # 0x109038
movsd %xmm0, (%rbx)
movl %r14d, 0x2debf1(%rip)   # 0x371e58
leaq 0x27a292(%rip), %rax    # 0x30d500
cmpl $0x20, (%rax)
jne 0x92db0
leaq 0x187d6a(%rip), %rax    # 0x21afe8
cmpl $0x4f, (%rax)
jne 0x92db0
leaq 0x90cbb(%rip), %rdi     # 0x123f49
movl $0x12b, %esi            # imm = 0x12B
callq 0x5ee52
leaq 0x90f27(%rip), %rdi     # 0x1241c6
movl $0xce, %esi
callq 0x5ee52
leaq 0x90f08(%rip), %rdi     # 0x1241b8
movl $0xcd, %esi
callq 0x5ee52
jmp 0x92db0
leaq 0x91173(%rip), %rdi     # 0x124439
callq 0x58e77
xorl %eax, %eax
movl %eax, (%rbx)
movl %eax, (%r14)
jmp 0x92db0
leaq 0x9113b(%rip), %rdi     # 0x124419
jmp 0x92d79