// File: /workspace/github_cpp_makefile_star2_O3/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 0x7f2b8
leaq 0x2a8c31(%rip), %r15    # 0x33b830
movb $0x0, (%r15)
leaq 0x2a5648(%rip), %r14    # 0x338252
leaq 0x1ac35f(%rip), %r12    # 0x23ef70
movzwl (%r14), %eax
cmpq %rax, %rbx
jae 0x92c41
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x92c2b
orb $0x8, (%r12)
movb %al, (%rbx,%r15)
movb $0x0, 0x1(%rbx,%r15)
incq %rbx
cmpq $0x1f6, %rbx            # imm = 0x1F6
jne 0x92c11
leaq 0x2a560c(%rip), %rax    # 0x338254
xorl %ecx, %ecx
movw %cx, (%rax)
movw %cx, (%r14)
leaq 0x2a55fe(%rip), %rax    # 0x338256
movw %cx, (%rax)
leaq 0x2a8bce(%rip), %rdi    # 0x33b830
leaq 0x918bb(%rip), %rsi     # 0x124524
callq 0x9090
testq %rax, %rax
je 0x92ccc
callq 0xa477
leaq 0x27aa4d(%rip), %rax    # 0x30d6cc
imull $0x2710, (%rax), %eax   # imm = 0x2710
leaq 0x27aa44(%rip), %rcx    # 0x30d6d0
imull $0x64, (%rcx), %edx
addl %eax, %edx
leaq 0x27aa3c(%rip), %rax    # 0x30d6d4
addl (%rax), %edx
leaq 0x27aa23(%rip), %rax    # 0x30d6c4
movl (%rax), %ecx
leaq 0x27aa16(%rip), %rax    # 0x30d6c0
movl (%rax), %r8d
leaq 0x27aa14(%rip), %rax    # 0x30d6c8
movl (%rax), %r9d
leaq 0x2a8b72(%rip), %rdi    # 0x33b830
leaq 0x91870(%rip), %rsi     # 0x124535
xorl %eax, %eax
callq 0x9060
leaq 0x2a8b5d(%rip), %rbx    # 0x33b830
movq %rbx, %rdi
callq 0x9899
leaq 0x2a8f62(%rip), %rax    # 0x33bc44
movl $0x0, (%rax)
leaq 0x1ab6a1(%rip), %rax    # 0x23e390
movq (%rax), %rdi
testq %rdi, %rdi
je 0x92d29
movl 0x2d9f03(%rip), %edx    # 0x36cc00
leaq 0x1882f8(%rip), %rax    # 0x21affc
movl (%rax), %ecx
leaq 0x1882eb(%rip), %rax    # 0x21aff8
movl (%rax), %r8d
movl 0x2d90b5(%rip), %r9d    # 0x36bdcc
movq %rbx, (%rsp)
leaq 0x91835(%rip), %rsi     # 0x124557
xorl %eax, %eax
callq 0x9560
cmpl $0x0, 0x2d909c(%rip)    # 0x36bdcc
je 0x92dc0
movl $0x0, 0x2d908c(%rip)    # 0x36bdcc
leaq 0x1882b5(%rip), %rbx    # 0x21affc
xorl %eax, %eax
movl %eax, (%rbx)
leaq 0x1882a6(%rip), %r14    # 0x21aff8
movl %eax, (%r14)
callq 0x810b1
testl %eax, %eax
je 0x92e14
leaq 0x2a8cd7(%rip), %rax    # 0x33ba40
movl $0x52414c41, %ecx       # imm = 0x52414C41
xorl (%rax), %ecx
movzwl 0x4(%rax), %edx
xorl $0x4d, %edx
orl %ecx, %edx
je 0x92e0f
movabsq $0x4b53414d5f4c41, %rdx # imm = 0x4B53414D5F4C41
movabsq $0x414d5f4d52414c41, %rcx # imm = 0x414D5F4D52414C41
xorq (%rax), %rcx
leaq 0x111(%rdx), %rsi
xorq 0x3(%rax), %rsi
orq %rcx, %rsi
je 0x92db2
movq (%rax), %rcx
cmpq %rdx, %rcx
jne 0x92e5d
leaq 0x91730(%rip), %rdi     # 0x1244e9
callq 0x58dc2
jmp 0x92e14
leaq 0x188235(%rip), %rax    # 0x21affc
movl (%rax), %ecx
testl %ecx, %ecx
je 0x92d40
leaq 0x188220(%rip), %rbx    # 0x21aff8
cmpl $0x0, (%rbx)
je 0x92d40
cmpl $0xd2, %ecx
je 0x92ee8
cmpl $0xce, %ecx
je 0x92ee1
cmpl $0xcd, %ecx
jne 0x92ef8
callq 0x918f8
jmp 0x92eed
callq 0x8fe3d
callq 0x6fa59
leaq 0x1ab5a0(%rip), %rax    # 0x23e3c0
cmpq $0x0, (%rax)
setne %al
leaq 0x1907d2(%rip), %rcx    # 0x223600
movq (%rcx), %rdi
testq %rdi, %rdi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x92e43
callq 0xafe8
leaq 0x1ac156(%rip), %rax    # 0x23efa0
movl $0x1, (%rax)
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl $0x464e4f43, %edx       # imm = 0x464E4F43
xorl (%rax), %edx
movzbl 0x4(%rax), %esi
orl %edx, %esi
je 0x92f0f
movabsq $0x454d49545f535047, %rdx # imm = 0x454D49545F535047
xorq (%rax), %rdx
movzbl 0x8(%rax), %esi
orq %rdx, %rsi
je 0x92f19
movabsq $0x59545f5455504e49, %rdx # imm = 0x59545F5455504E49
xorq (%rax), %rdx
movabsq $0x29312845505954, %rsi # imm = 0x29312845505954
xorq 0x6(%rax), %rsi
orq %rdx, %rsi
je 0x92f23
movl $0x51534248, %edx       # imm = 0x51534248
xorl (%rax), %edx
movzbl 0x4(%rax), %esi
orl %edx, %esi
je 0x92f2d
movabsq $0x5350475f4f464e49, %rdx # imm = 0x5350475F4F464E49
xorq (%rax), %rdx
movzbl 0x8(%rax), %esi
orq %rdx, %rsi
je 0x92f37
cmpl $0x564e49, %ecx         # imm = 0x564E49
jne 0x92f41
callq 0x9274c
jmp 0x92e14
callq 0x91d9f
jmp 0x92eed
callq 0x920d0
cmpl $0x0, (%rbx)
jne 0x92e50
jmp 0x92efe
xorl %ecx, %ecx
movl %ecx, (%rax)
movl %ecx, (%rbx)
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x6fa59
callq 0x9021f
jmp 0x92e14
callq 0x9061c
jmp 0x92e14
callq 0x92af9
jmp 0x92e14
callq 0x9056f
jmp 0x92e14
callq 0x90bc4
jmp 0x92e14
movl $0x54415453, %edx       # imm = 0x54415453
xorl (%rax), %edx
movl $0x535554, %esi         # imm = 0x535554
xorl 0x3(%rax), %esi
orl %edx, %esi
je 0x9304a
movabsq $0x54415245504d4554, %rdx # imm = 0x54415245504D4554
xorq (%rax), %rdx
movl 0x8(%rax), %esi
xorq $0x455255, %rsi         # imm = 0x455255
orq %rdx, %rsi
je 0x93054
movabsq $0x544154535f444f54, %rdx # imm = 0x544154535F444F54
movq (%rax), %rsi
xorq %rdx, %rsi
movzwl 0x8(%rax), %edi
xorq $0x45, %rdi
orq %rsi, %rdi
je 0x9305e
movl $0x45505954, %esi       # imm = 0x45505954
xorl (%rax), %esi
movzbl 0x4(%rax), %edi
orl %esi, %edi
je 0x93068
movabsq $0x474e415f4b53414d, %rsi # imm = 0x474E415F4B53414D
xorq (%rax), %rsi
movabsq $0x454c474e415f4b, %rdi # imm = 0x454C474E415F4B
xorq 0x3(%rax), %rdi
orq %rsi, %rdi
je 0x93072
movabsq $0x4154535f43445441, %rsi # imm = 0x4154535F43445441
xorq (%rax), %rsi
movl 0x8(%rax), %edi
xorq $0x535554, %rdi         # imm = 0x535554
orq %rsi, %rdi
je 0x9307c
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 0x93086
movabsq $0x5346464f5f435455, %rsi # imm = 0x5346464F5F435455
xorq (%rax), %rsi
movabsq $0x54455346464f5f, %rdi # imm = 0x54455346464F5F
xorq 0x3(%rax), %rdi
orq %rsi, %rdi
je 0x93090
cmpl $0x525457, %ecx         # imm = 0x525457
jne 0x9309c
callq 0x92204
jmp 0x92e14
callq 0x8ff4f
jmp 0x92e14
callq 0x925d1
jmp 0x92e14
callq 0x92618
jmp 0x92e14
callq 0x926e5
jmp 0x92e14
callq 0x92aa1
jmp 0x92e14
callq 0x92575
jmp 0x92e14
callq 0x921ca
jmp 0x92e14
leaq 0x9146c(%rip), %rdi     # 0x124503
jmp 0x92db9
movabsq $0x41545f524f495250, %rsi # imm = 0x41545F524F495250
xorq (%rax), %rsi
movl 0x8(%rax), %edi
xorq $0x454c42, %rdi         # imm = 0x454C42
orq %rsi, %rdi
je 0x9325b
movabsq $0x545f54555054554f, %rsi # imm = 0x545F54555054554F
xorq (%rax), %rsi
movl 0x8(%rax), %edi
xorq $0x455059, %rdi         # imm = 0x455059
orq %rsi, %rdi
je 0x93265
movabsq $0x55504e495f585541, %rsi # imm = 0x55504E495F585541
xorq (%rax), %rsi
movzwl 0x8(%rax), %edi
xorq $0x54, %rdi
orq %rsi, %rdi
je 0x9326f
addq $0x8f4ed, %rdx          # imm = 0x8F4ED
xorq (%rax), %rdx
movzwl 0x8(%rax), %esi
xorq $0x45, %rsi
orq %rdx, %rsi
je 0x93279
movabsq $0x5441535f4b4341, %rdx # imm = 0x5441535F4B4341
movabsq $0x5349565f4f464e49, %rsi # imm = 0x5349565F4F464E49
xorq (%rax), %rsi
leaq 0x80615(%rdx), %rdi
xorq 0x5(%rax), %rdi
orq %rsi, %rdi
je 0x93294
movabsq $0x4152545f4f464e49, %rsi # imm = 0x4152545F4F464E49
xorq (%rax), %rsi
xorq 0x7(%rax), %rdx
orq %rsi, %rdx
je 0x93283
movabsq $0x4148435f4f464e49, %rdx # imm = 0x4148435F4F464E49
xorq (%rax), %rdx
movzwl 0x8(%rax), %esi
xorq $0x4e, %rsi
orq %rdx, %rsi
je 0x93283
movabsq $0x535f54555054554f, %rdx # imm = 0x535F54555054554F
xorq (%rax), %rdx
movabsq $0x45544154535f54, %rsi # imm = 0x45544154535F54
xorq 0x5(%rax), %rsi
orq %rdx, %rsi
je 0x932a5
movl $0x5a504724, %edx       # imm = 0x5A504724
xorl (%rax), %edx
movl $0x41445a, %esi         # imm = 0x41445A
xorl 0x3(%rax), %esi
orl %edx, %esi
je 0x932b6
movl $0x45444f4d, %edx       # imm = 0x45444F4D
xorl (%rax), %edx
movzbl 0x4(%rax), %esi
orl %edx, %esi
je 0x9336a
movabsq $0x52455f4d41524150, %rdx # imm = 0x52455F4D41524150
xorq (%rax), %rdx
movl 0x8(%rax), %esi
xorq $0x524f52, %rsi         # imm = 0x524F52
orq %rdx, %rsi
je 0x93352
movabsq $0x455f5841544e5953, %rdx # imm = 0x455F5841544E5953
xorq (%rax), %rdx
movabsq $0x524f5252455f58, %rsi # imm = 0x524F5252455F58
xorq 0x5(%rax), %rsi
orq %rdx, %rsi
je 0x93352
movabsq $0x5f4e574f4e4b4e55, %rdx # imm = 0x5F4E574F4E4B4E55
xorq (%rax), %rdx
movl 0x8(%rax), %esi
xorq $0x444d43, %rsi         # imm = 0x444D43
orq %rdx, %rsi
je 0x93352
movl $0x4f525245, %edx       # imm = 0x4F525245
xorl (%rax), %edx
movl $0x2c524f, %esi         # imm = 0x2C524F
xorl 0x3(%rax), %esi
orl %edx, %esi
je 0x93352
movzwl %cx, %eax
cmpl $0x4b4f, %eax           # imm = 0x4B4F
jne 0x92e14
leaq 0x912bb(%rip), %rdi     # 0x124511
jmp 0x93359
callq 0x9180e
jmp 0x92e14
callq 0x917a3
jmp 0x92e14
callq 0x9185c
jmp 0x92e14
callq 0x918aa
jmp 0x92e14
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x91d9f
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x918f8
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x920d0
callq 0xae92
addsd 0x75d75(%rip), %xmm0    # 0x109038
leaq 0x27a42e(%rip), %rbx    # 0x30d6f8
movsd %xmm0, (%rbx)
xorl %r14d, %r14d
movl %r14d, 0x2deb80(%rip)   # 0x371e58
movl $0x1, %edi
callq 0x822b5
callq 0xae92
addsd 0x75d49(%rip), %xmm0    # 0x109038
movsd %xmm0, (%rbx)
movl %r14d, 0x2deb5e(%rip)   # 0x371e58
leaq 0x27a1ff(%rip), %rax    # 0x30d500
cmpl $0x20, (%rax)
jne 0x92e14
leaq 0x187cd7(%rip), %rax    # 0x21afe8
cmpl $0x4f, (%rax)
jne 0x92e14
leaq 0x90d08(%rip), %rdi     # 0x124029
movl $0x12b, %esi            # imm = 0x12B
callq 0x5edda
leaq 0x90f74(%rip), %rdi     # 0x1242a6
movl $0xce, %esi
callq 0x5edda
leaq 0x90f55(%rip), %rdi     # 0x124298
movl $0xcd, %esi
callq 0x5edda
jmp 0x92e14
leaq 0x911c0(%rip), %rdi     # 0x124519
callq 0x58dc2
xorl %eax, %eax
movl %eax, (%r14)
movl %eax, (%rbx)
jmp 0x92e14
leaq 0x91188(%rip), %rdi     # 0x1244f9
jmp 0x92db9