// File: 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
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0x9638b
jmp 0x96aa4
movl $0x0, 0x334c1b(%rip)    # 0x3cafb0
leaq 0x1e1714(%rip), %rax    # 0x277ab0
cmpq $0x40000, (%rax)        # imm = 0x40000
jne 0x963f8
cmpl $0x196, -0xc(%rbp)      # imm = 0x196
jne 0x963b8
movl $0xa, %edi
callq 0x79900
movq -0x8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x24, %eax
jne 0x963d3
movq -0x8(%rbp), %rdi
addq $0x1, %rdi
callq 0xbc470
jmp 0x963f3
movq -0x8(%rbp), %rax
movzbl (%rax), %edi
callq 0x96330
movl $0xd, %edi
callq 0x96330
movl $0xa, %edi
callq 0x96330
jmp 0x966dc
movq -0x8(%rbp), %rdi
callq 0x9120
movl %eax, -0x14(%rbp)
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x96460
leaq 0x1e1696(%rip), %rax    # 0x277ab0
cmpq $0x1000, (%rax)         # imm = 0x1000
jne 0x96442
leaq 0x1e3d9e(%rip), %rax    # 0x27a1c8
cmpl $0x4f, (%rax)
jne 0x96442
movq -0x8(%rbp), %rax
movslq -0x10(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3b, %eax
jne 0x96442
jmp 0x96453
movq -0x8(%rbp), %rax
movslq -0x10(%rbp), %rcx
movzbl (%rax,%rcx), %edi
callq 0x7b210
jmp 0x96455
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x9640b
leaq 0x1e1649(%rip), %rax    # 0x277ab0
cmpq $0x1000, (%rax)         # imm = 0x1000
jne 0x96494
movl $0xd, %edi
callq 0x7b210
leaq 0x1e3d57(%rip), %rax    # 0x27a1d8
movl $0x0, (%rax)
leaq 0x1e3d4e(%rip), %rax    # 0x27a1dc
movl $0x0, (%rax)
movl $0x1, 0x334b52(%rip)    # 0x3caff0
leaq 0x1e160b(%rip), %rax    # 0x277ab0
cmpq $0x20000, (%rax)        # imm = 0x20000
jne 0x964d7
leaq 0x1e3d67(%rip), %rax    # 0x27a21c
movl $0xd, (%rax)
leaq 0x1e3d5e(%rip), %rax    # 0x27a220
movl $0xa, (%rax)
movl $0xa, %edi
callq 0x7b210
jmp 0x9667c
leaq 0x1e15d2(%rip), %rax    # 0x277ab0
cmpq $0x10000000, (%rax)     # imm = 0x10000000
jne 0x96503
leaq 0x1e3d2e(%rip), %rax    # 0x27a21c
movl $0xd, (%rax)
movl $0xd, %edi
callq 0x7b210
jmp 0x9667a
leaq 0x1e15a6(%rip), %rax    # 0x277ab0
cmpq $0x1000000, (%rax)      # imm = 0x1000000
jne 0x9652f
leaq 0x1e3d02(%rip), %rax    # 0x27a21c
movl $0xd, (%rax)
movl $0xd, %edi
callq 0x7b210
jmp 0x96678
movabsq $0x1000000000, %rcx     # imm = 0x1000000000
leaq 0x1e1570(%rip), %rax    # 0x277ab0
cmpq %rcx, (%rax)
jne 0x96564
leaq 0x1e3cd0(%rip), %rax    # 0x27a21c
movl $0xd, (%rax)
leaq 0x1e3cc7(%rip), %rax    # 0x27a220
movl $0xa, (%rax)
jmp 0x96676
leaq 0x1e1545(%rip), %rax    # 0x277ab0
cmpq $0x8000000, (%rax)      # imm = 0x8000000
jne 0x965a8
leaq 0x1e3ca1(%rip), %rax    # 0x27a21c
movl $0xd, (%rax)
movl $0xd, %edi
callq 0x7b210
cmpl $0x323, -0xc(%rbp)      # imm = 0x323
jne 0x965a3
movl $0x1388, %edi           # imm = 0x1388
callq 0xb8b0
callq 0xbe120
jmp 0x96674
leaq 0x1e1501(%rip), %rax    # 0x277ab0
cmpq $0x1000, (%rax)         # imm = 0x1000
jne 0x965d4
leaq 0x1e3c5d(%rip), %rax    # 0x27a21c
movl $0xa, (%rax)
movl $0xa, %edi
callq 0x7b210
jmp 0x96672
leaq 0x1e14d5(%rip), %rax    # 0x277ab0
cmpq $0x8, (%rax)
jne 0x965fa
leaq 0x1e3c34(%rip), %rax    # 0x27a21c
movl $0xd, (%rax)
movl $0xd, %edi
callq 0x7b210
jmp 0x96670
leaq 0x1e14af(%rip), %rax    # 0x277ab0
cmpq $0x2000000, (%rax)      # imm = 0x2000000
jne 0x96630
leaq 0x1e3c0b(%rip), %rax    # 0x27a21c
movl $0xd, (%rax)
leaq 0x1e3c02(%rip), %rax    # 0x27a220
movl $0xa, (%rax)
movl $0xd, %edi
callq 0x7b210
jmp 0x9666e
leaq 0x1e3b89(%rip), %rax    # 0x27a1c0
cmpl $0x4e, (%rax)
jne 0x96655
leaq 0x1e3bd9(%rip), %rax    # 0x27a21c
movl $0xd, (%rax)
movl $0xd, %edi
callq 0x7b210
jmp 0x9666c
leaq 0x1e3bc0(%rip), %rax    # 0x27a21c
movl $0xa, (%rax)
movl $0xa, %edi
callq 0x7b210
jmp 0x9666e
jmp 0x96670
jmp 0x96672
jmp 0x96674
jmp 0x96676
jmp 0x96678
jmp 0x9667a
jmp 0x9667c
movl $0x0, 0x33496a(%rip)    # 0x3caff0
leaq 0x1e1423(%rip), %rax    # 0x277ab0
cmpq $0x1000, (%rax)         # imm = 0x1000
jne 0x96698
jmp 0x966da
cmpl $0x26, -0xc(%rbp)
jne 0x966b7
leaq 0x206efb(%rip), %rax    # 0x29d5a0
cmpq $0x0, (%rax)
jne 0x966b5
movl $0x1388, %edi           # imm = 0x1388
callq 0xb8b0
jmp 0x966d8
cmpl $0x35, -0xc(%rbp)
jne 0x966d6
leaq 0x206edc(%rip), %rax    # 0x29d5a0
cmpq $0x0, (%rax)
jne 0x966d4
movl $0x3e8, %edi            # imm = 0x3E8
callq 0xb8b0
jmp 0x966d6
jmp 0x966d8
jmp 0x966da
jmp 0x966dc
movl -0xc(%rbp), %eax
movl %eax, 0x3356eb(%rip)    # 0x3cbdd0
leaq 0x206eb4(%rip), %rax    # 0x29d5a0
cmpq $0x0, (%rax)
je 0x966f7
jmp 0x96a56
leaq 0x1e13b2(%rip), %rax    # 0x277ab0
cmpq $0x40000, (%rax)        # imm = 0x40000
jne 0x96716
movl $0xc8, %edi
callq 0xb8b0
jmp 0x96a54
leaq 0x1e1393(%rip), %rax    # 0x277ab0
cmpq $0x20000, (%rax)        # imm = 0x20000
jne 0x96735
movl $0x32, %edi
callq 0xb8b0
jmp 0x96a52
leaq 0x1e1374(%rip), %rax    # 0x277ab0
cmpq $0x10000000, (%rax)     # imm = 0x10000000
jne 0x9677c
movl $0x64, %edi
callq 0xb8b0
cmpl $0x389, -0xc(%rbp)      # imm = 0x389
jne 0x96763
movl -0xc(%rbp), %eax
movl %eax, 0x33484f(%rip)    # 0x3cafb0
jmp 0x96777
cmpl $0x38a, -0xc(%rbp)      # imm = 0x38A
jne 0x96775
movl -0xc(%rbp), %eax
movl %eax, 0x33483b(%rip)    # 0x3cafb0
jmp 0x96777
jmp 0x96a50
leaq 0x1e132d(%rip), %rax    # 0x277ab0
cmpq $0x1000000, (%rax)      # imm = 0x1000000
jne 0x96808
cmpl $0x0, -0xc(%rbp)
jge 0x96803
movq -0x8(%rbp), %rax
movb (%rax), %cl
leaq 0x1e3681(%rip), %rax    # 0x279e20
movb %cl, (%rax)
movq -0x8(%rbp), %rax
movb 0x1(%rax), %cl
leaq 0x1e3671(%rip), %rax    # 0x279e20
movb %cl, 0x1(%rax)
leaq 0x1e3667(%rip), %rax    # 0x279e20
movb $0x0, 0x2(%rax)
movl $0x0, 0x334829(%rip)    # 0x3caff0
movl $0x56, %edi
callq 0x7b210
movl $0x42, %edi
callq 0x7b210
movl $0x31, %edi
callq 0x7b210
movl $0x1, 0x334801(%rip)    # 0x3caff0
movl $0xd, %edi
callq 0x7b210
movl $0x64, %edi
callq 0xb8b0
jmp 0x96a4e
movabsq $0x1000000000, %rcx     # imm = 0x1000000000
leaq 0x1e1297(%rip), %rax    # 0x277ab0
cmpq %rcx, (%rax)
jne 0x9682d
movl $0x64, %edi
callq 0xb8b0
jmp 0x96a4c
leaq 0x1e127c(%rip), %rax    # 0x277ab0
cmpq $0x10, (%rax)
jne 0x96849
movl $0xc8, %edi
callq 0xb8b0
jmp 0x96a4a
leaq 0x1e1260(%rip), %rax    # 0x277ab0
cmpq $0x8000000, (%rax)      # imm = 0x8000000
jne 0x96868
movl $0x64, %edi
callq 0xb8b0
jmp 0x96a48
leaq 0x1e1241(%rip), %rax    # 0x277ab0
cmpq $0x1000, (%rax)         # imm = 0x1000
jne 0x96a0b
leaq 0x1e3945(%rip), %rax    # 0x27a1c8
cmpl $0x4f, (%rax)
jne 0x96a0b
movl $0xc8, %edi
callq 0xb8b0
movq -0x8(%rbp), %rdi
movl $0x3d, %esi
callq 0x9100
cmpq $0x0, %rax
je 0x969df
cmpl $0xc9, -0xc(%rbp)
jne 0x968c5
movl -0xc(%rbp), %eax
movl %eax, 0x3346f0(%rip)    # 0x3cafb0
jmp 0x969dd
cmpl $0xe2, -0xc(%rbp)
jne 0x968dc
movl -0xc(%rbp), %eax
movl %eax, 0x3346d9(%rip)    # 0x3cafb0
jmp 0x969db
cmpl $0xde, -0xc(%rbp)
jne 0x968f3
movl -0xc(%rbp), %eax
movl %eax, 0x3346c2(%rip)    # 0x3cafb0
jmp 0x969d9
cmpl $0xdf, -0xc(%rbp)
jne 0x9690a
movl -0xc(%rbp), %eax
movl %eax, 0x3346ab(%rip)    # 0x3cafb0
jmp 0x969d7
cmpl $0xfd, -0xc(%rbp)
jne 0x96921
movl -0xc(%rbp), %eax
movl %eax, 0x334694(%rip)    # 0x3cafb0
jmp 0x969d5
cmpl $0xcc, -0xc(%rbp)
jne 0x96938
movl -0xc(%rbp), %eax
movl %eax, 0x33467d(%rip)    # 0x3cafb0
jmp 0x969d3
cmpl $0xfc, -0xc(%rbp)
jne 0x9694f
movl -0xc(%rbp), %eax
movl %eax, 0x334666(%rip)    # 0x3cafb0
jmp 0x969d1
cmpl $0xfe, -0xc(%rbp)
jne 0x96963
movl -0xc(%rbp), %eax
movl %eax, 0x33464f(%rip)    # 0x3cafb0
jmp 0x969cf
cmpl $0xe0, -0xc(%rbp)
jne 0x96977
movl -0xc(%rbp), %eax
movl %eax, 0x33463b(%rip)    # 0x3cafb0
jmp 0x969cd
cmpl $0xe1, -0xc(%rbp)
jne 0x9698b
movl -0xc(%rbp), %eax
movl %eax, 0x334627(%rip)    # 0x3cafb0
jmp 0x969cb
cmpl $0xd9, -0xc(%rbp)
jne 0x9699f
movl -0xc(%rbp), %eax
movl %eax, 0x334613(%rip)    # 0x3cafb0
jmp 0x969c9
cmpl $0xfa, -0xc(%rbp)
jne 0x969b3
movl -0xc(%rbp), %eax
movl %eax, 0x3345ff(%rip)    # 0x3cafb0
jmp 0x969c7
cmpl $0xda, -0xc(%rbp)
jne 0x969c5
movl -0xc(%rbp), %eax
movl %eax, 0x3345eb(%rip)    # 0x3cafb0
jmp 0x969c7
jmp 0x969c9
jmp 0x969cb
jmp 0x969cd
jmp 0x969cf
jmp 0x969d1
jmp 0x969d3
jmp 0x969d5
jmp 0x969d7
jmp 0x969d9
jmp 0x969db
jmp 0x969dd
jmp 0x96a09
cmpl $0xdb, -0xc(%rbp)
jne 0x969f3
movl -0xc(%rbp), %eax
movl %eax, 0x3345bf(%rip)    # 0x3cafb0
jmp 0x96a07
cmpl $0xdc, -0xc(%rbp)
jne 0x96a05
movl -0xc(%rbp), %eax
movl %eax, 0x3345ab(%rip)    # 0x3cafb0
jmp 0x96a07
jmp 0x96a09
jmp 0x96a46
leaq 0x1e109e(%rip), %rax    # 0x277ab0
cmpq $0x1000, (%rax)         # imm = 0x1000
jne 0x96a1d
jmp 0x96a44
leaq 0x1e108c(%rip), %rax    # 0x277ab0
cmpq $0x2000000, (%rax)      # imm = 0x2000000
jne 0x96a38
movl -0xc(%rbp), %eax
movl %eax, 0x33537a(%rip)    # 0x3cbdb0
jmp 0x96a42
movl $0xc8, %edi
callq 0xb8b0
jmp 0x96a44
jmp 0x96a46
jmp 0x96a48
jmp 0x96a4a
jmp 0x96a4c
jmp 0x96a4e
jmp 0x96a50
jmp 0x96a52
jmp 0x96a54
jmp 0x96a56
movl $0xa, %edi
callq 0xc61e0
leaq 0x206b09(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0x96aa4
leaq 0x206afc(%rip), %rax    # 0x29d570
movq (%rax), %rdi
movl -0xc(%rbp), %edx
movl 0x338728(%rip), %ecx    # 0x3cf1a8
movl 0x338719(%rip), %r8d    # 0x3cf1a0
movl 0x338716(%rip), %r9d    # 0x3cf1a4
movq -0x8(%rbp), %rax
leaq 0xf1d2e(%rip), %rsi     # 0x1887c7
movq %rax, (%rsp)
movb $0x0, %al
callq 0x9550
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)