// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathgps.cpp
// Function: send_polled_cmd(char*, int)
void send_polled_cmd(char *s, int id)
{
int i, j;

   if(s == 0) return;
   no_response_msg = 0;

   if(rcvr_type == BRANDY_RCVR) {
      if(id == BRANDY_SATINFO_MSG) {  // prevent time codes processing from falling behind
         drain_port(RCVR_PORT);
      }

      if(s[0] == '$') {  // NMEA formatted command
         send_brandy_cmd(&s[1]);
      }
      else {  // query command
         send_brandy_char(s[0]);
         send_brandy_char(0x0D);
         send_brandy_char(0x0A);
      }
      goto msg_done;
   }

   j = strlen(s);
   for(i=0; i<j; i++) {
      if((rcvr_type == STAR_RCVR) && (star_type == OSA_TYPE) && (s[i] == ';')) ;
      else send_byte((u08) s[i]);
   }

   if(rcvr_type == STAR_RCVR) {
      send_byte(0x0D);
      star_line = 0;
      star_msg = 0;
   }

   eom_flag = EOM;
   if(rcvr_type == CS_RCVR) {
      pkt_end1 = 0x0D;
      pkt_end2 = 0x0A;
      send_byte(0x0A);
   }
   else if(rcvr_type == LPFRS_RCVR) {
      pkt_end1 = 0x0D;
      send_byte(0x0D);
   }
   else if(rcvr_type == PRS_RCVR) {
      pkt_end1 = 0x0D;
      send_byte(0x0D);
   }
   else if(rcvr_type == SA35_RCVR) {
      pkt_end1 = 0x0D;
      pkt_end2 = 0x0A;
//    send_byte(0x0A);
   }
   else if(rcvr_type == SRO_RCVR) {
      pkt_end1 = 0x0D;
      send_byte(0x0D);
      if(id == SRO_RESET_MSG) {
         Sleep(5000);
         restart_prs_polling();
      }
   }
   else if(rcvr_type == STAR_RCVR) {
      pkt_end1 = 0x0A;
      send_byte(0x0A);
   }
   else if(rcvr_type == UCCM_RCVR) {
      pkt_end1 = 0x0D;
      send_byte(0x0D);
   }
   else if(rcvr_type == X72_RCVR) {
      pkt_end1 = 0x0D;
      pkt_end2 = 0x0A;
//eom_flag = FLUSH_COM;
      send_byte(0x0D);
   }
   else if(scpi_type == NORTEL_TYPE) {
      pkt_end1 = 0x0D;
      send_byte(0x0D);
   }
   else {
      pkt_end1 = 0x0A;
      send_byte(0x0A);
   }

   eom_flag = ADD_CHAR;

   if(rcvr_type == STAR_RCVR) {
////      saw_star_etx = 0;
   }
   else if(id == SCPI_SET_CABLE_MSG) {  // setting cable delay ties up receiver for several seconds
      if(sim_file == 0) Sleep(5000);
   }
else if(id == SCPI_FDUP_MSG) {  // setting fdup mode takes a while
   if(sim_file == 0) Sleep(1000);
}

   msg_done:
   polled_msg_id = id;

   if(sim_file) ; 
   else if(rcvr_type == BRANDY_RCVR) {
      if(BRANDY_SLEEP) Sleep(BRANDY_SLEEP); 
   }
   else if(rcvr_type == CS_RCVR) {
      if(CS_SLEEP) Sleep(CS_SLEEP); 
   }
   else if(rcvr_type == LPFRS_RCVR) {
      if(LPFRS_SLEEP) Sleep(LPFRS_SLEEP); 
      if     (id == LPFRS_C_WRITE_MSG) no_response_msg = id;
      else if(id == LPFRS_F_WRITE_MSG) no_response_msg = id;
   }
   else if(rcvr_type == PRS_RCVR) {
////  if(PRS_SLEEP) Sleep(PRS_SLEEP);   // if no sleep, message cycle lasts 11 seconds

      if(id < 0) {        // we just sent a command that changes a param
         last_prs_set[0] = s[0];  // remember the last param set command
         last_prs_set[1] = s[1];
         last_prs_set[2] = 0;

         eom_flag = ADD_CHAR; // ... these don't send a response back
         send_byte('V');      // ... so force a response from the unit
         send_byte('B');      // ... so that the message polling does not timeout
         send_byte('1');
         eom_flag = EOM;
         send_byte(0x0D);
         Sleep(PRS_SLEEP);
      }
   }
   else if(rcvr_type == SA35_RCVR) {
      if(SA35_SLEEP) Sleep(SA35_SLEEP); 
   }
   else if(rcvr_type == SCPI_RCVR) {
      if(SCPI_SLEEP) Sleep(SCPI_SLEEP); 
   }
   else if(rcvr_type == SRO_RCVR) {
      if(SRO_SLEEP) Sleep(SRO_SLEEP); 
   }
   else if((rcvr_type == STAR_RCVR) && (star_type == OSA_TYPE)) {
      if(OSA_SLEEP) Sleep(OSA_SLEEP);   // allow time for receiver to digest the command
      if(strchr(s, '=')) {  // !!!!! commands that do not send a resposnse
         if     (id == STAR_ALMASK_MSG)    no_response_msg = id;
         else if(id == STAR_ADM_MSG)       no_response_msg = id;
         else if(id == STAR_AUX_MSG)       no_response_msg = id;
         else if(id == STAR_BAUD_MSG)      no_response_msg = id;
         else if(id == STAR_CABLE_MSG)     no_response_msg = id;
         else if(id == STAR_HBSQ_MSG)      no_response_msg = id;
         else if(id == STAR_HOLD_MSG)      no_response_msg = id;
         else if(id == STAR_OFFSET_MSG)    no_response_msg = id;
         else if(id == STAR_OUTPUT_MSG)    no_response_msg = id;
         else if(id == STAR_PRIOR_MSG)     no_response_msg = id;
         else if(id == STAR_TZONE_MSG)     no_response_msg = id;
         else if(id == STAR_TAU_MSG)       no_response_msg = id;
         else if(id == STAR_WTR_MSG)       no_response_msg = id;
      }
      else if(id == STAR_CLEAR_GPS_MSG)    no_response_msg = id;
      else if(id == STAR_CLEAR_AUX_MSG)    no_response_msg = id;
   }
   else if(rcvr_type == STAR_RCVR) {
      if(STAR_SLEEP) Sleep(STAR_SLEEP);
   }
   else if(rcvr_type == X72_RCVR) {
////  if(X72_SLEEP) Sleep(X72_SLEEP); 
x72_msg_id = id;
   }
   else {
      if(DEFAULT_SLEEP) Sleep(DEFAULT_SLEEP);   // allow time for receiver to digest the command
   }
fake_second_check(10);  // see if time to simulate the missing second
if(debug_file) fprintf(debug_file,   "\nSEND SCPI id:%d  sqe:%d  in:%d out:%d: %s\n", id, polled_q_entries, polled_q_in,polled_q_out, s);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
testq %rdi, %rdi
je 0x6e7d8
movl %esi, %r15d
movq %rdi, %r14
movl $0x0, 0x2fdad5(%rip)    # 0x36bdd0
leaq 0x1aa5ce(%rip), %rax    # 0x2188d0
movq (%rax), %r13
cmpq $0x40000, %r13          # imm = 0x40000
jne 0x6e33b
cmpl $0x196, %r15d           # imm = 0x196
jne 0x6e321
movl $0xa, %edi
callq 0x5802f
movb (%r14), %bl
cmpb $0x24, %bl
jne 0x6e420
leaq 0x1(%r14), %rdi
callq 0x89cc6
jmp 0x6e5f4
movq %r15, -0x30(%rbp)
movq %r14, %rdi
callq 0x9120
movq %rax, %r15
testl %r15d, %r15d
jle 0x6e3af
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
leaq 0x1acc8b(%rip), %rbx    # 0x21afe8
movl (%rbx), %eax
xorl %r12d, %r12d
movq %r13, %rcx
cmpq $0x1000, %rcx           # imm = 0x1000
sete %cl
cmpl $0x4f, %eax
sete %dl
andb %cl, %dl
movb (%r14,%r12), %al
cmpb $0x3b, %al
sete %cl
testb %cl, %dl
je 0x6e390
movl $0x1000, %ecx           # imm = 0x1000
movl $0x4f, %eax
jmp 0x6e3a7
movzbl %al, %edi
callq 0x590f7
leaq 0x1aa531(%rip), %rax    # 0x2188d0
movq (%rax), %r13
movl (%rbx), %eax
movq %r13, %rcx
incq %r12
cmpq %r12, %r15
jne 0x6e365
cmpq $0x1000, %r13           # imm = 0x1000
jne 0x6e3e0
movl $0xd, %edi
callq 0x590f7
leaq 0x1acc2f(%rip), %rax    # 0x21aff8
xorl %ecx, %ecx
movl %ecx, (%rax)
leaq 0x1acc28(%rip), %rax    # 0x21affc
movl %ecx, (%rax)
leaq 0x1aa4f3(%rip), %rax    # 0x2188d0
movq (%rax), %r13
movl $0x1, 0x2fda26(%rip)    # 0x36be10
cmpq $0x1ffffff, %r13        # imm = 0x1FFFFFF
movq -0x30(%rbp), %r15
jg 0x6e473
cmpq $0x1ffff, %r13          # imm = 0x1FFFF
jg 0x6e4d8
cmpq $0x8, %r13
je 0x6e55e
cmpq $0x1000, %r13           # imm = 0x1000
je 0x6e572
jmp 0x6e552
movzbl %bl, %esi
movl $0xa, %edi
movl $0x1, %edx
callq 0xbcaa
xorb %bl, 0x2fe67e(%rip)     # 0x36cab6
movl $0xa, %edi
movl $0xd, %esi
movl $0x1, %edx
callq 0xbcaa
xorb $0xd, 0x2fe663(%rip)    # 0x36cab6
movl $0xa, %edi
movl $0xa, %esi
movl $0x1, %edx
callq 0xbcaa
xorb $0xa, 0x2fe648(%rip)    # 0x36cab6
jmp 0x6e5f4
cmpq $0xfffffff, %r13        # imm = 0xFFFFFFF
jg 0x6e4ec
cmpq $0x2000000, %r13        # imm = 0x2000000
je 0x6e520
cmpq $0x8000000, %r13        # imm = 0x8000000
jne 0x6e552
leaq 0x1acb9f(%rip), %rax    # 0x21b03c
movl $0xd, (%rax)
movl $0xd, %edi
callq 0x590f7
cmpl $0x323, %r15d           # imm = 0x323
jne 0x6e589
movl $0x1388, %edi           # imm = 0x1388
callq 0xafe8
callq 0x8b1d2
movl $0x0, 0x2fd93d(%rip)    # 0x36be10
jmp 0x6e5f4
cmpq $0x20000, %r13          # imm = 0x20000
je 0x6e53c
cmpq $0x1000000, %r13        # imm = 0x1000000
je 0x6e55e
jmp 0x6e552
cmpq $0x10000000, %r13       # imm = 0x10000000
je 0x6e55e
movabsq $0x1000000000, %rax     # imm = 0x1000000000
cmpq %rax, %r13
jne 0x6e552
leaq 0x1acb31(%rip), %rax    # 0x21b03c
movl $0xd, (%rax)
leaq 0x1acb28(%rip), %rax    # 0x21b040
movl $0xa, (%rax)
jmp 0x6e589
leaq 0x1acb15(%rip), %rax    # 0x21b03c
movl $0xd, (%rax)
leaq 0x1acb0c(%rip), %rax    # 0x21b040
movl $0xa, (%rax)
jmp 0x6e56b
leaq 0x1acaf9(%rip), %rax    # 0x21b03c
movl $0xd, (%rax)
leaq 0x1acaf0(%rip), %rax    # 0x21b040
jmp 0x6e579
leaq 0x1aca87(%rip), %rax    # 0x21afe0
cmpl $0x4e, (%rax)
jne 0x6e572
leaq 0x1acad7(%rip), %rax    # 0x21b03c
movl $0xd, (%rax)
movl $0xd, %edi
jmp 0x6e584
leaq 0x1acac3(%rip), %rax    # 0x21b03c
movl $0xa, (%rax)
movl $0xa, %edi
callq 0x590f7
movl $0x0, 0x2fd87d(%rip)    # 0x36be10
leaq 0x1aa336(%rip), %rax    # 0x2188d0
cmpq $0x1000, (%rax)         # imm = 0x1000
je 0x6e5f4
cmpl $0x26, %r15d
jne 0x6e5c5
leaq 0x1cfe10(%rip), %rax    # 0x23e3c0
cmpq $0x0, (%rax)
je 0x6e5ea
movl $0x26, 0x2fe640(%rip)   # 0x36cc00
jmp 0x6e796
cmpl $0x35, %r15d
sete %cl
leaq 0x1cfded(%rip), %rax    # 0x23e3c0
movq (%rax), %rax
testq %rax, %rax
sete %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x6e5fe
movl $0x3e8, %edi            # imm = 0x3E8
jmp 0x6e5ef
movl $0x1388, %edi           # imm = 0x1388
callq 0xafe8
leaq 0x1cfdc5(%rip), %rax    # 0x23e3c0
movq (%rax), %rax
movl %r15d, 0x2fe5fb(%rip)   # 0x36cc00
testq %rax, %rax
jne 0x6e796
leaq 0x1aa2bb(%rip), %rax    # 0x2188d0
movq (%rax), %rax
cmpq $0xffffff, %rax         # imm = 0xFFFFFF
jle 0x6e642
cmpq $0xfffffff, %rax        # imm = 0xFFFFFFF
jg 0x6e666
cmpq $0x1000000, %rax        # imm = 0x1000000
je 0x6e6fd
cmpq $0x8000000, %rax        # imm = 0x8000000
je 0x6e759
jmp 0x6e685
cmpq $0x10, %rax
je 0x6e65c
cmpq $0x20000, %rax          # imm = 0x20000
je 0x6e78c
cmpq $0x40000, %rax          # imm = 0x40000
jne 0x6e685
movl $0xc8, %edi
jmp 0x6e791
cmpq $0x10000000, %rax       # imm = 0x10000000
je 0x6e760
movabsq $0x1000000000, %rcx     # imm = 0x1000000000
cmpq %rcx, %rax
je 0x6e759
cmpq $0x1000, %rax           # imm = 0x1000
jne 0x6e7e7
leaq 0x1ac950(%rip), %rcx    # 0x21afe8
cmpl $0x4f, (%rcx)
jne 0x6e7e7
movl $0xc8, %edi
callq 0xafe8
movq %r14, %rdi
movl $0x3d, %esi
callq 0x9100
testq %rax, %rax
je 0x6e810
cmpl $0xf9, %r15d
jg 0x6e835
leal -0xd9(%r15), %eax
cmpl $0x9, %eax
ja 0x6e873
leaq 0xb04bf(%rip), %rcx     # 0x11eba4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0xd9, 0x2fd6d8(%rip)   # 0x36bdd0
jmp 0x6e796
testl %r15d, %r15d
jns 0x6e796
movb (%r14), %al
leaq 0x1ac530(%rip), %rcx    # 0x21ac40
movb %al, (%rcx)
movb 0x1(%r14), %al
movb %al, 0x1(%rcx)
movb $0x0, 0x2(%rcx)
movl $0x0, 0x2fd6e9(%rip)    # 0x36be10
movl $0x56, %edi
callq 0x590f7
movl $0x42, %edi
callq 0x590f7
movl $0x31, %edi
callq 0x590f7
movl $0x1, 0x2fd6c1(%rip)    # 0x36be10
movl $0xd, %edi
callq 0x590f7
movl $0x64, %edi
jmp 0x6e791
movl $0x64, %edi
callq 0xafe8
cmpl $0x38a, %r15d           # imm = 0x38A
je 0x6e804
cmpl $0x389, %r15d           # imm = 0x389
jne 0x6e796
movl $0x389, 0x2fd646(%rip)  # imm = 0x389
jmp 0x6e796
movl $0x32, %edi
callq 0xafe8
movl $0xa, %edi
callq 0x90b38
leaq 0x1cfbe9(%rip), %rax    # 0x23e390
movq (%rax), %rdi
testq %rdi, %rdi
je 0x6e7d8
movl 0x301823(%rip), %ecx    # 0x36ffd8
movl 0x301814(%rip), %r8d    # 0x36ffd0
movl 0x301811(%rip), %r9d    # 0x36ffd4
movq %r14, (%rsp)
leaq 0xb6d05(%rip), %rsi     # 0x1254d3
movl %r15d, %edx
xorl %eax, %eax
callq 0x9560
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x1000, %rax           # imm = 0x1000
je 0x6e796
cmpq $0x2000000, %rax        # imm = 0x2000000
jne 0x6e65c
movl %r15d, 0x2fe3de(%rip)   # 0x36cbe0
jmp 0x6e796
movl $0x38a, 0x2fd5c2(%rip)  # imm = 0x38A
jmp 0x6e796
cmpl $0xdc, %r15d
je 0x6e864
cmpl $0xdb, %r15d
jne 0x6e796
movl $0xdb, 0x2fd5a0(%rip)   # 0x36bdd0
jmp 0x6e796
leal -0xfa(%r15), %eax
cmpl $0x4, %eax
ja 0x6e796
leaq 0xb0380(%rip), %rcx     # 0x11ebcc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0xfa, 0x2fd571(%rip)   # 0x36bdd0
jmp 0x6e796
movl $0xdc, 0x2fd562(%rip)   # 0x36bdd0
jmp 0x6e796
cmpl $0xc9, %r15d
je 0x6e923
cmpl $0xcc, %r15d
jne 0x6e796
movl $0xcc, 0x2fd539(%rip)   # 0x36bdd0
jmp 0x6e796
movl $0xfe, 0x2fd52a(%rip)   # 0x36bdd0
jmp 0x6e796
movl $0xfd, 0x2fd51b(%rip)   # 0x36bdd0
jmp 0x6e796
movl $0xfc, 0x2fd50c(%rip)   # 0x36bdd0
jmp 0x6e796
movl $0xe2, 0x2fd4fd(%rip)   # 0x36bdd0
jmp 0x6e796
movl $0xde, 0x2fd4ee(%rip)   # 0x36bdd0
jmp 0x6e796
movl $0xe0, 0x2fd4df(%rip)   # 0x36bdd0
jmp 0x6e796
movl $0xdf, 0x2fd4d0(%rip)   # 0x36bdd0
jmp 0x6e796
movl $0xda, 0x2fd4c1(%rip)   # 0x36bdd0
jmp 0x6e796
movl $0xe1, 0x2fd4b2(%rip)   # 0x36bdd0
jmp 0x6e796
movl $0xc9, 0x2fd4a3(%rip)   # 0x36bdd0
jmp 0x6e796