// File: /workspace/github_cpp_makefile_star2_O2/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 0x6530d
movl %esi, %ebx
movq %rdi, %r14
andl $0x0, 0x2f0ea9(%rip)    # 0x355dd0
leaq 0x19d9a2(%rip), %r13    # 0x2028d0
cmpq $0x40000, (%r13)        # imm = 0x40000
movabsq $0x1000000000, %r15     # imm = 0x1000000000
jne 0x64f6b
cmpl $0x196, %ebx            # imm = 0x196
jne 0x64f52
pushq $0xa
popq %rdi
callq 0x5142f
movb (%r14), %al
cmpb $0x24, %al
jne 0x6506b
leaq 0x1(%r14), %rdi
callq 0x7d28c
jmp 0x65180
movq %rbx, -0x30(%rbp)
movq %r14, %rdi
callq 0x9120
movq %rax, %r15
xorl %r12d, %r12d
testl %r15d, %r15d
cmovlel %r12d, %r15d
leaq 0x1a005d(%rip), %rbx    # 0x204fe8
movq (%r13), %rax
cmpq %r12, %r15
je 0x64fbf
cmpq $0x1000, %rax           # imm = 0x1000
sete %al
cmpl $0x4f, (%rbx)
sete %cl
andb %al, %cl
movb (%r14,%r12), %al
cmpb $0x3b, %al
sete %dl
testb %dl, %cl
jne 0x64fba
movzbl %al, %edi
callq 0x523f2
incq %r12
jmp 0x64f8b
cmpq $0x1000, %rax           # imm = 0x1000
jne 0x64fe7
pushq $0xd
popq %rdi
callq 0x523f2
leaq 0x1a0022(%rip), %rax    # 0x204ff8
andl $0x0, (%rax)
leaq 0x1a001c(%rip), %rax    # 0x204ffc
andl $0x0, (%rax)
movq (%r13), %rax
movl $0x1, 0x2f0e1f(%rip)    # 0x355e10
cmpq $0x8, %rax
movq -0x30(%rbp), %rbx
movabsq $0x1000000000, %r15     # imm = 0x1000000000
je 0x650de
cmpq $0x1000, %rax           # imm = 0x1000
je 0x650ef
cmpq %r15, %rax
je 0x6515a
cmpq $0x1000000, %rax        # imm = 0x1000000
je 0x650de
cmpq $0x2000000, %rax        # imm = 0x2000000
je 0x65088
cmpq $0x8000000, %rax        # imm = 0x8000000
je 0x650a4
cmpq $0x10000000, %rax       # imm = 0x10000000
je 0x650de
cmpq $0x20000, %rax          # imm = 0x20000
jne 0x650d2
leaq 0x19ffe3(%rip), %rax    # 0x20503c
movl $0xd, (%rax)
leaq 0x19ffda(%rip), %rax    # 0x205040
jmp 0x650f6
movzbl %al, %edi
callq 0x64edf
pushq $0xd
popq %rdi
callq 0x64edf
pushq $0xa
popq %rdi
callq 0x64edf
jmp 0x65180
leaq 0x19ffad(%rip), %rax    # 0x20503c
movl $0xd, (%rax)
leaq 0x19ffa4(%rip), %rax    # 0x205040
movl $0xa, (%rax)
jmp 0x650eb
leaq 0x19ff91(%rip), %rax    # 0x20503c
movl $0xd, (%rax)
pushq $0xd
popq %rdi
callq 0x523f2
cmpl $0x323, %ebx            # imm = 0x323
jne 0x65104
movl $0x1388, %edi           # imm = 0x1388
callq 0xae83
callq 0x7e67f
jmp 0x65104
leaq 0x19ff07(%rip), %rax    # 0x204fe0
cmpl $0x4e, (%rax)
jne 0x650ef
leaq 0x19ff57(%rip), %rax    # 0x20503c
movl $0xd, (%rax)
pushq $0xd
jmp 0x650fe
leaq 0x19ff46(%rip), %rax    # 0x20503c
movl $0xa, (%rax)
pushq $0xa
popq %rdi
callq 0x523f2
andl $0x0, 0x2f0d05(%rip)    # 0x355e10
cmpq $0x1000, (%r13)         # imm = 0x1000
je 0x65180
cmpl $0x26, %ebx
jne 0x65136
leaq 0x1c329f(%rip), %rax    # 0x2283c0
cmpq $0x0, (%rax)
je 0x65176
movl $0x26, 0x2f1acf(%rip)   # 0x356c00
jmp 0x652ce
cmpl $0x35, %ebx
sete %cl
leaq 0x1c327d(%rip), %rax    # 0x2283c0
movq (%rax), %rax
testq %rax, %rax
sete %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x6518a
movl $0x3e8, %edi            # imm = 0x3E8
jmp 0x6517b
leaq 0x19fedb(%rip), %rax    # 0x20503c
movl $0xd, (%rax)
leaq 0x19fed2(%rip), %rax    # 0x205040
movl $0xa, (%rax)
jmp 0x65104
movl $0x1388, %edi           # imm = 0x1388
callq 0xae83
leaq 0x1c3239(%rip), %rax    # 0x2283c0
movq (%rax), %rax
movl %ebx, 0x2f1a70(%rip)    # 0x356c00
testq %rax, %rax
jne 0x652ce
movq (%r13), %rax
cmpq $0x10, %rax
je 0x651d8
cmpq $0x20000, %rax          # imm = 0x20000
je 0x652c6
cmpq %r15, %rax
je 0x65232
cmpq $0x1000000, %rax        # imm = 0x1000000
je 0x651e2
cmpq $0x8000000, %rax        # imm = 0x8000000
je 0x65232
cmpq $0x10000000, %rax       # imm = 0x10000000
je 0x65239
cmpq $0x40000, %rax          # imm = 0x40000
jne 0x65261
movl $0xc8, %edi
jmp 0x652c9
testl %ebx, %ebx
jns 0x652ce
movb (%r14), %al
leaq 0x19fa4c(%rip), %rcx    # 0x204c40
movb %al, (%rcx)
movb 0x1(%r14), %al
movb %al, 0x1(%rcx)
movb $0x0, 0x2(%rcx)
andl $0x0, 0x2f0c08(%rip)    # 0x355e10
pushq $0x56
popq %rdi
callq 0x523f2
pushq $0x42
popq %rdi
callq 0x523f2
pushq $0x31
popq %rdi
callq 0x523f2
movl $0x1, 0x2f0be6(%rip)    # 0x355e10
pushq $0xd
popq %rdi
callq 0x523f2
pushq $0x64
jmp 0x652c8
pushq $0x64
popq %rdi
callq 0xae83
cmpl $0x38a, %ebx            # imm = 0x38A
je 0x65338
cmpl $0x389, %ebx            # imm = 0x389
jne 0x652ce
movl $0x389, 0x2f0b71(%rip)  # imm = 0x389
jmp 0x652ce
cmpq $0x1000, %rax           # imm = 0x1000
jne 0x6531c
leaq 0x19fd74(%rip), %rcx    # 0x204fe8
cmpl $0x4f, (%rcx)
jne 0x6531c
movl $0xc8, %edi
callq 0xae83
pushq $0x3d
popq %rsi
movq %r14, %rdi
callq 0x9100
testq %rax, %rax
je 0x65344
leal -0xd9(%rbx), %eax
cmpl $0x9, %eax
ja 0x65367
leaq 0xa3833(%rip), %rcx     # 0x108ae4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0xd9, 0x2f0b0c(%rip)   # 0x355dd0
jmp 0x652ce
pushq $0x32
popq %rdi
callq 0xae83
pushq $0xa
popq %rdi
callq 0x83d34
leaq 0x1c30b3(%rip), %rax    # 0x228390
movq (%rax), %rdi
testq %rdi, %rdi
je 0x6530d
movl 0x2f4ced(%rip), %ecx    # 0x359fd8
movl 0x2f4cde(%rip), %r8d    # 0x359fd0
movl 0x2f4cdb(%rip), %r9d    # 0x359fd4
movq %r14, (%rsp)
leaq 0xaa117(%rip), %rsi     # 0x10f41b
movl %ebx, %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 0x652ce
cmpq $0x2000000, %rax        # imm = 0x2000000
jne 0x651d8
movl %ebx, 0x2f18aa(%rip)    # 0x356be0
jmp 0x652ce
movl $0x38a, 0x2f0a8e(%rip)  # imm = 0x38A
jmp 0x652ce
cmpl $0xdc, %ebx
je 0x65391
cmpl $0xdb, %ebx
jne 0x652ce
movl $0xdb, 0x2f0a6e(%rip)   # 0x355dd0
jmp 0x652ce
leal -0xfa(%rbx), %eax
cmpl $0x4, %eax
ja 0x653a0
leaq 0xa3793(%rip), %rcx     # 0x108b0c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0xfa, 0x2f0a44(%rip)   # 0x355dd0
jmp 0x652ce
movl $0xdc, 0x2f0a35(%rip)   # 0x355dd0
jmp 0x652ce
cmpl $0xcc, %ebx
je 0x6544e
cmpl $0xc9, %ebx
jne 0x652ce
movl $0xc9, 0x2f0a0e(%rip)   # 0x355dd0
jmp 0x652ce
movl $0xde, 0x2f09ff(%rip)   # 0x355dd0
jmp 0x652ce
movl $0xe2, 0x2f09f0(%rip)   # 0x355dd0
jmp 0x652ce
movl $0xda, 0x2f09e1(%rip)   # 0x355dd0
jmp 0x652ce
movl $0xe1, 0x2f09d2(%rip)   # 0x355dd0
jmp 0x652ce
movl $0xdf, 0x2f09c3(%rip)   # 0x355dd0
jmp 0x652ce
movl $0xe0, 0x2f09b4(%rip)   # 0x355dd0
jmp 0x652ce
movl $0xfc, 0x2f09a5(%rip)   # 0x355dd0
jmp 0x652ce
movl $0xfe, 0x2f0996(%rip)   # 0x355dd0
jmp 0x652ce
movl $0xfd, 0x2f0987(%rip)   # 0x355dd0
jmp 0x652ce
movl $0xcc, 0x2f0978(%rip)   # 0x355dd0
jmp 0x652ce