// File: /workspace/github_cpp_makefile_star2_O1/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 0x6e85e
movl %esi, %r15d
movq %rdi, %r14
movl $0x0, 0x2fd9ea(%rip)    # 0x36bdd0
leaq 0x1aa4e3(%rip), %r12    # 0x2188d0
cmpq $0x40000, (%r12)        # imm = 0x40000
jne 0x6e424
cmpl $0x196, %r15d           # imm = 0x196
jne 0x6e40a
movl $0xa, %edi
callq 0x5804f
movb (%r14), %bl
cmpb $0x24, %bl
jne 0x6e4da
leaq 0x1(%r14), %rdi
callq 0x89cf7
jmp 0x6e682
movq %r15, -0x30(%rbp)
movq %r14, %rdi
callq 0x9120
movq %rax, %r15
testl %r15d, %r15d
jle 0x6e471
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
xorl %r13d, %r13d
leaq 0x1acb9f(%rip), %rbx    # 0x21afe8
cmpq $0x1000, (%r12)         # imm = 0x1000
jne 0x6e45f
cmpl $0x4f, (%rbx)
jne 0x6e45f
cmpb $0x3b, (%r14,%r13)
je 0x6e469
movzbl (%r14,%r13), %edi
callq 0x591af
incq %r13
cmpq %r13, %r15
jne 0x6e449
cmpq $0x1000, (%r12)         # imm = 0x1000
jne 0x6e499
movl $0xd, %edi
callq 0x591af
leaq 0x1acb6c(%rip), %rax    # 0x21aff8
xorl %ecx, %ecx
movl %ecx, (%rax)
leaq 0x1acb65(%rip), %rax    # 0x21affc
movl %ecx, (%rax)
movl $0x1, 0x2fd96d(%rip)    # 0x36be10
movq (%r12), %rax
cmpq $0x1ffffff, %rax        # imm = 0x1FFFFFF
jg 0x6e52d
cmpq $0x1ffff, %rax          # imm = 0x1FFFF
movq -0x30(%rbp), %r15
jg 0x6e589
cmpq $0x8, %rax
je 0x6e60c
cmpq $0x1000, %rax           # imm = 0x1000
je 0x6e620
jmp 0x6e600
movzbl %bl, %esi
movl $0xa, %edi
movl $0x1, %edx
callq 0xbcc0
xorb %bl, 0x2fe5c4(%rip)     # 0x36cab6
movl $0xa, %edi
movl $0xd, %esi
movl $0x1, %edx
callq 0xbcc0
xorb $0xd, 0x2fe5a9(%rip)    # 0x36cab6
movl $0xa, %edi
movl $0xa, %esi
movl $0x1, %edx
callq 0xbcc0
xorb $0xa, 0x2fe58e(%rip)    # 0x36cab6
jmp 0x6e682
cmpq $0xfffffff, %rax        # imm = 0xFFFFFFF
movq -0x30(%rbp), %r15
jg 0x6e59b
cmpq $0x2000000, %rax        # imm = 0x2000000
je 0x6e5ce
cmpq $0x8000000, %rax        # imm = 0x8000000
jne 0x6e600
leaq 0x1acae4(%rip), %rax    # 0x21b03c
movl $0xd, (%rax)
movl $0xd, %edi
callq 0x591af
cmpl $0x323, %r15d           # imm = 0x323
jne 0x6e637
movl $0x1388, %edi           # imm = 0x1388
callq 0xaff7
callq 0x8b1d0
jmp 0x6e637
cmpq $0x20000, %rax          # imm = 0x20000
je 0x6e5ea
cmpq $0x1000000, %rax        # imm = 0x1000000
je 0x6e60c
jmp 0x6e600
cmpq $0x10000000, %rax       # imm = 0x10000000
je 0x6e60c
movabsq $0x1000000000, %rcx     # imm = 0x1000000000
cmpq %rcx, %rax
jne 0x6e600
leaq 0x1aca83(%rip), %rax    # 0x21b03c
movl $0xd, (%rax)
leaq 0x1aca7a(%rip), %rax    # 0x21b040
movl $0xa, (%rax)
jmp 0x6e637
leaq 0x1aca67(%rip), %rax    # 0x21b03c
movl $0xd, (%rax)
leaq 0x1aca5e(%rip), %rax    # 0x21b040
movl $0xa, (%rax)
jmp 0x6e619
leaq 0x1aca4b(%rip), %rax    # 0x21b03c
movl $0xd, (%rax)
leaq 0x1aca42(%rip), %rax    # 0x21b040
jmp 0x6e627
leaq 0x1ac9d9(%rip), %rax    # 0x21afe0
cmpl $0x4e, (%rax)
jne 0x6e620
leaq 0x1aca29(%rip), %rax    # 0x21b03c
movl $0xd, (%rax)
movl $0xd, %edi
jmp 0x6e632
leaq 0x1aca15(%rip), %rax    # 0x21b03c
movl $0xa, (%rax)
movl $0xa, %edi
callq 0x591af
movl $0x0, 0x2fd7cf(%rip)    # 0x36be10
cmpq $0x1000, (%r12)         # imm = 0x1000
je 0x6e682
cmpl $0x26, %r15d
jne 0x6e665
leaq 0x1cfd68(%rip), %rax    # 0x23e3c0
cmpq $0x0, (%rax)
jne 0x6e682
movl $0x1388, %edi           # imm = 0x1388
jmp 0x6e67d
cmpl $0x35, %r15d
jne 0x6e682
leaq 0x1cfd4e(%rip), %rax    # 0x23e3c0
cmpq $0x0, (%rax)
jne 0x6e682
movl $0x3e8, %edi            # imm = 0x3E8
callq 0xaff7
movl %r15d, 0x2fe577(%rip)   # 0x36cc00
leaq 0x1cfd30(%rip), %rax    # 0x23e3c0
cmpq $0x0, (%rax)
jne 0x6e81c
movq (%r12), %rax
cmpq $0xffffff, %rax         # imm = 0xFFFFFF
jle 0x6e6c8
cmpq $0xfffffff, %rax        # imm = 0xFFFFFFF
jg 0x6e6ec
cmpq $0x1000000, %rax        # imm = 0x1000000
je 0x6e783
cmpq $0x8000000, %rax        # imm = 0x8000000
je 0x6e7df
jmp 0x6e70b
cmpq $0x10, %rax
je 0x6e6e2
cmpq $0x20000, %rax          # imm = 0x20000
je 0x6e812
cmpq $0x40000, %rax          # imm = 0x40000
jne 0x6e70b
movl $0xc8, %edi
jmp 0x6e817
cmpq $0x10000000, %rax       # imm = 0x10000000
je 0x6e7e6
movabsq $0x1000000000, %rcx     # imm = 0x1000000000
cmpq %rcx, %rax
je 0x6e7df
cmpq $0x1000, %rax           # imm = 0x1000
jne 0x6e86d
leaq 0x1ac8ca(%rip), %rcx    # 0x21afe8
cmpl $0x4f, (%rcx)
jne 0x6e86d
movl $0xc8, %edi
callq 0xaff7
movq %r14, %rdi
movl $0x3d, %esi
callq 0x9100
testq %rax, %rax
je 0x6e896
cmpl $0xf9, %r15d
jg 0x6e8bb
leal -0xd9(%r15), %eax
cmpl $0x9, %eax
ja 0x6e8f9
leaq 0xb0379(%rip), %rcx     # 0x11eae4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0xd9, 0x2fd652(%rip)   # 0x36bdd0
jmp 0x6e81c
testl %r15d, %r15d
jns 0x6e81c
movb (%r14), %al
leaq 0x1ac4aa(%rip), %rcx    # 0x21ac40
movb %al, (%rcx)
movb 0x1(%r14), %al
movb %al, 0x1(%rcx)
movb $0x0, 0x2(%rcx)
movl $0x0, 0x2fd663(%rip)    # 0x36be10
movl $0x56, %edi
callq 0x591af
movl $0x42, %edi
callq 0x591af
movl $0x31, %edi
callq 0x591af
movl $0x1, 0x2fd63b(%rip)    # 0x36be10
movl $0xd, %edi
callq 0x591af
movl $0x64, %edi
jmp 0x6e817
movl $0x64, %edi
callq 0xaff7
cmpl $0x38a, %r15d           # imm = 0x38A
je 0x6e88a
cmpl $0x389, %r15d           # imm = 0x389
jne 0x6e81c
movl $0x389, 0x2fd5c0(%rip)  # imm = 0x389
jmp 0x6e81c
movl $0x32, %edi
callq 0xaff7
movl $0xa, %edi
callq 0x90ac8
leaq 0x1cfb63(%rip), %rax    # 0x23e390
movq (%rax), %rdi
testq %rdi, %rdi
je 0x6e85e
movl 0x30179d(%rip), %ecx    # 0x36ffd8
movl 0x30178e(%rip), %r8d    # 0x36ffd0
movl 0x30178b(%rip), %r9d    # 0x36ffd4
movq %r14, (%rsp)
leaq 0xb6b9f(%rip), %rsi     # 0x1253f3
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 0x6e81c
cmpq $0x2000000, %rax        # imm = 0x2000000
jne 0x6e6e2
movl %r15d, 0x2fe358(%rip)   # 0x36cbe0
jmp 0x6e81c
movl $0x38a, 0x2fd53c(%rip)  # imm = 0x38A
jmp 0x6e81c
cmpl $0xdc, %r15d
je 0x6e8ea
cmpl $0xdb, %r15d
jne 0x6e81c
movl $0xdb, 0x2fd51a(%rip)   # 0x36bdd0
jmp 0x6e81c
leal -0xfa(%r15), %eax
cmpl $0x4, %eax
ja 0x6e81c
leaq 0xb023a(%rip), %rcx     # 0x11eb0c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0xfa, 0x2fd4eb(%rip)   # 0x36bdd0
jmp 0x6e81c
movl $0xdc, 0x2fd4dc(%rip)   # 0x36bdd0
jmp 0x6e81c
cmpl $0xc9, %r15d
je 0x6e9a9
cmpl $0xcc, %r15d
jne 0x6e81c
movl $0xcc, 0x2fd4b3(%rip)   # 0x36bdd0
jmp 0x6e81c
movl $0xfe, 0x2fd4a4(%rip)   # 0x36bdd0
jmp 0x6e81c
movl $0xfd, 0x2fd495(%rip)   # 0x36bdd0
jmp 0x6e81c
movl $0xfc, 0x2fd486(%rip)   # 0x36bdd0
jmp 0x6e81c
movl $0xe2, 0x2fd477(%rip)   # 0x36bdd0
jmp 0x6e81c
movl $0xde, 0x2fd468(%rip)   # 0x36bdd0
jmp 0x6e81c
movl $0xe0, 0x2fd459(%rip)   # 0x36bdd0
jmp 0x6e81c
movl $0xdf, 0x2fd44a(%rip)   # 0x36bdd0
jmp 0x6e81c
movl $0xda, 0x2fd43b(%rip)   # 0x36bdd0
jmp 0x6e81c
movl $0xe1, 0x2fd42c(%rip)   # 0x36bdd0
jmp 0x6e81c
movl $0xc9, 0x2fd41d(%rip)   # 0x36bdd0
jmp 0x6e81c