// File: jkingan[P]ladyheather/heathgps.cpp
// Function: poll_next_scpi()
void poll_next_scpi()
{
int test;

   // request an item from a SCPI receiver.  Requests are alternated between
   // a time message and some receiver parameter.  The parameter requests are 
   // alternated between one of three important parameters and then the lesser
   // important ones.

   test = 1;
   if(test && (polled_q_in != polled_q_out)) {  // we have a special message request queued
      send_queued_cmd(1);
   }
   else if(polled_msg_id == SCPI_TIME_MSG) { // request next misc message every time
      if((test == 0) && (polled_q_in != polled_q_out)) {  // we have a special message request queued
         send_queued_cmd(2);
      }
      else if(scpi_type == NORTEL_TYPE) {
         if(polled_req < 0) polled_req = 0;

         if((polled_seq % 10) == 0) send_polled_cmd("PTIME:INTERVAL?",       SCPI_TINT_MSG);    
         else if((polled_seq % 10) == 1) send_polled_cmd("ROSC:CONT?",       SCPI_EFC_MSG);
         else {
            if     (polled_req ==  0) send_polled_cmd("PTIME:LEAPSECOND?",           SCPI_LEAPTIME_MSG);
            else if(polled_req ==  1) send_polled_cmd("PTIME:ACC:LEAPSECOND?",       SCPI_UTC_OFS_MSG);
            else if(polled_req ==  2) send_polled_cmd("*IDN?",                       SCPI_ID_MSG);
            else if(polled_req ==  3) send_polled_cmd("GPS:POSITION?",               SCPI_POSN_MSG);
            else if(polled_req ==  4) send_polled_cmd("GPS:REF:ADELAY?",             SCPI_GET_CABLE_MSG);
            else if(polled_req ==  5) send_polled_cmd("GPS:SAT:TRAC:EMANGLE?",       SCPI_ELEV_MSG);
            else if(polled_req ==  6) send_polled_cmd("ANTENNA:CONDITION?",          SCPI_ANTENNA_MSG);
            else if(polled_req ==  7) send_polled_cmd("STATUS:OPERATION:CONDITION?", SCPI_OPERATION_MSG);
            else if(polled_req ==  8) send_polled_cmd("STATUS:HARDWARE:CONDITION?",  SCPI_HARDWARE_MSG);
            else if(polled_req ==  9) send_polled_cmd("GPS:POS:SURVEY:PROGRESS?",    SCPI_PROGRESS_MSG);
            else if(polled_req == 10) send_polled_cmd("GPS:SAT:TRACKING?",           SCPI_TRACK_MSG);
            else if(polled_req == 11) send_polled_cmd("GPS:SAT:VIS:PRED?",           SCPI_VIS_MSG);
            else if(polled_req == 12) send_polled_cmd("ROSC:HOLD:DUR?",              SCPI_HOLDOVER_MSG);
            else if(polled_req == 13) send_polled_cmd("GPS:SAT:TRAC:IGNORE?",        SCPI_IGNORE_MSG);
            else if(polled_req == 14) send_polled_cmd("GPS:SAT:TRAC:INCLUDE?",       SCPI_INCLUDE_MSG);
            else if(polled_req == 15) send_polled_cmd("DIAG:LIFETIME:COUNT?",        SCPI_LIFE_MSG);
            else if(polled_req == 16) send_polled_cmd("SYNC:FFOM?",                  SCPI_FFOM_MSG);

            if(++polled_req > 16) {
               polled_req = 0;
               ++all_polled;
            }
         }
         ++polled_seq;
      }
      else {
//       queue_scpi_cmd(":DIAG:ROSC:EFC?", SCPI_EFC_MSG);     // we want these as often as possible
//       queue_scpi_cmd(":PTIM:TINT?",     SCPI_TINT_MSG);
//       queue_scpi_cmd(":ROSC:HOLD:TUNC:PRED?",    SCPI_TUNC_MSG);

         if(polled_req < 0) polled_req = 0;

         if(     (polled_seq % 10) == 0) send_polled_cmd(":PTIM:TINT?",           SCPI_TINT_MSG);
         else if((polled_seq % 10) == 1) send_polled_cmd(":DIAG:ROSC:EFC?",       SCPI_EFC_MSG);
         else {
            if     (polled_req == 0)  send_polled_cmd(":PTIM:LEAP:ACC?",          SCPI_UTC_OFS_MSG);
            else if(polled_req == 1)  {
               if(scpi_type == HP_TYPE) {
                  send_polled_cmd(":GPS:POS?", SCPI_POSN_MSG);
               }
               else {
                  send_polled_cmd(":GPS:POS:ACT?",            SCPI_POSN_MSG);
               }
            }
            else if(polled_req == 2)  send_polled_cmd("*IDN?",                    SCPI_ID_MSG);
            else if(polled_req == 3)  send_polled_cmd(":PTIM:GPS:SAT:VIS:PRED?",  SCPI_VIS_MSG);
            else if(polled_req == 4)  send_polled_cmd(":PTIM:GPS:SAT:TRAC?",      SCPI_TRACK_MSG);
            else if(polled_req == 5)  send_polled_cmd(":GPS:SAT:TRAC:IGN?"      , SCPI_IGNORE_MSG);
            else if(polled_req == 6)  send_polled_cmd(":STATUS:OPER:HARD:COND?",  SCPI_HARDWARE_MSG);
            else if(polled_req == 7)  send_polled_cmd(":ROSC:HOLD:DUR?",          SCPI_HOLDOVER_MSG);
            else if(polled_req == 8)  send_polled_cmd(":DIAG:GPS:UTC?",           SCPI_UTC_MSG);

            else if(polled_req == 9)  send_polled_cmd(":PTIM:GPS:EMAN?",          SCPI_ELEV_MSG);
            else if(polled_req == 10) send_polled_cmd(":PTIM:GPS:ADEL?",          SCPI_GET_CABLE_MSG);
            else if(polled_req == 11) send_polled_cmd(":PTIM:GPS:POS:SURV:STAT?", SCPI_SURVEY_MSG);
            else if(polled_req == 12) send_polled_cmd(":PTIM:GPS:POS:SURV:PROG?", SCPI_PROGRESS_MSG);
            else if(polled_req == 13) send_polled_cmd(":PTIM:LEAP:GPST?",         SCPI_LEAPTIME_MSG);
            else if(polled_req == 14) send_polled_cmd(":PTIM:LEAP:DATE?",         SCPI_LEAPTIME_MSG);
            else if(polled_req == 15) send_polled_cmd(":PTIM:PPS:EDGE?",          SCPI_EDGE_MSG);
            else if(polled_req == 16) send_polled_cmd(":DIAG:LIF:COUNT?",         SCPI_LIFE_MSG);
            else if(polled_req == 17) send_polled_cmd(":ROSC:HOLD:TUNC:PRED?", SCPI_TUNC_MSG);

            if(++polled_req > 17) {
               polled_req = 0;
               ++all_polled;
            }
         }
         ++polled_seq;
      }
   }
   else {
      send_polled_cmd(":PTIME:TCODE?", SCPI_TIME_MSG);  // request time message
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl $0x1, -0x4(%rbp)
cmpl $0x0, -0x4(%rbp)
je 0x97d82
movl 0x337435(%rip), %eax    # 0x3cf1a0
cmpl 0x337433(%rip), %eax    # 0x3cf1a4
je 0x97d82
movl $0x1, %edi
callq 0xbd7c0
jmp 0x983ab
cmpl $0x3e7, 0x334044(%rip)  # imm = 0x3E7
jne 0x98398
cmpl $0x0, -0x4(%rbp)
jne 0x97db5
movl 0x337402(%rip), %eax    # 0x3cf1a0
cmpl 0x337400(%rip), %eax    # 0x3cf1a4
je 0x97db5
movl $0x2, %edi
callq 0xbd7c0
jmp 0x98396
leaq 0x1e2404(%rip), %rax    # 0x27a1c0
cmpl $0x4e, (%rax)
jne 0x9808f
cmpl $0x0, 0x3373e0(%rip)    # 0x3cf1ac
jge 0x97dd8
movl $0x0, 0x3373d4(%rip)    # 0x3cf1ac
movl 0x3373d2(%rip), %eax    # 0x3cf1b0
movl $0xa, %ecx
xorl %edx, %edx
divl %ecx
cmpl $0x0, %edx
jne 0x97e02
leaq 0xf07fb(%rip), %rdi     # 0x1885ee
movl $0x10, %esi
callq 0x96370
jmp 0x9807b
movl 0x3373a8(%rip), %eax    # 0x3cf1b0
movl $0xa, %ecx
xorl %edx, %edx
divl %ecx
cmpl $0x1, %edx
jne 0x97e2c
leaq 0xec7c6(%rip), %rdi     # 0x1845e3
movl $0xb, %esi
callq 0x96370
jmp 0x98079
cmpl $0x0, 0x337379(%rip)    # 0x3cf1ac
jne 0x97e4b
leaq 0xf07c2(%rip), %rdi     # 0x1885fe
movl $0x1b, %esi
callq 0x96370
jmp 0x9804a
cmpl $0x1, 0x33735a(%rip)    # 0x3cf1ac
jne 0x97e6a
leaq 0xf07b5(%rip), %rdi     # 0x188610
movl $0xf, %esi
callq 0x96370
jmp 0x98048
cmpl $0x2, 0x33733b(%rip)    # 0x3cf1ac
jne 0x97e89
leaq 0xecadd(%rip), %rdi     # 0x184957
movl $0x1c, %esi
callq 0x96370
jmp 0x98046
cmpl $0x3, 0x33731c(%rip)    # 0x3cf1ac
jne 0x97ea8
leaq 0xf078d(%rip), %rdi     # 0x188626
movl $0x15, %esi
callq 0x96370
jmp 0x98044
cmpl $0x4, 0x3372fd(%rip)    # 0x3cf1ac
jne 0x97ec7
leaq 0xec463(%rip), %rdi     # 0x18431b
movl $0xe, %esi
callq 0x96370
jmp 0x98042
cmpl $0x5, 0x3372de(%rip)    # 0x3cf1ac
jne 0x97ee6
leaq 0xec299(%rip), %rdi     # 0x184170
movl $0xa, %esi
callq 0x96370
jmp 0x98040
cmpl $0x6, 0x3372bf(%rip)    # 0x3cf1ac
jne 0x97f05
leaq 0xf073e(%rip), %rdi     # 0x188634
movl $0x33, %esi
callq 0x96370
jmp 0x9803e
cmpl $0x7, 0x3372a0(%rip)    # 0x3cf1ac
jne 0x97f24
leaq 0xf0732(%rip), %rdi     # 0x188647
movl $0x34, %esi
callq 0x96370
jmp 0x9803c
cmpl $0x8, 0x337281(%rip)    # 0x3cf1ac
jne 0x97f43
leaq 0xf072f(%rip), %rdi     # 0x188663
movl $0x1a, %esi
callq 0x96370
jmp 0x9803a
cmpl $0x9, 0x337262(%rip)    # 0x3cf1ac
jne 0x97f62
leaq 0xeccde(%rip), %rdi     # 0x184c31
movl $0x12, %esi
callq 0x96370
jmp 0x98038
cmpl $0xa, 0x337243(%rip)    # 0x3cf1ac
jne 0x97f81
leaq 0xf070c(%rip), %rdi     # 0x18867e
movl $0xd, %esi
callq 0x96370
jmp 0x98036
cmpl $0xb, 0x337224(%rip)    # 0x3cf1ac
jne 0x97fa0
leaq 0xf0769(%rip), %rdi     # 0x1886fa
movl $0xc, %esi
callq 0x96370
jmp 0x98034
cmpl $0xc, 0x337205(%rip)    # 0x3cf1ac
jne 0x97fbc
leaq 0xec7ce(%rip), %rdi     # 0x18477e
movl $0x16, %esi
callq 0x96370
jmp 0x98032
cmpl $0xd, 0x3371e9(%rip)    # 0x3cf1ac
jne 0x97fd8
leaq 0xebff9(%rip), %rdi     # 0x183fc5
movl $0x1e, %esi
callq 0x96370
jmp 0x98030
cmpl $0xe, 0x3371cd(%rip)    # 0x3cf1ac
jne 0x97ff4
leaq 0xebff2(%rip), %rdi     # 0x183fda
movl $0x20, %esi
callq 0x96370
jmp 0x9802e
cmpl $0xf, 0x3371b1(%rip)    # 0x3cf1ac
jne 0x98010
leaq 0xf068c(%rip), %rdi     # 0x188690
movl $0x23, %esi
callq 0x96370
jmp 0x9802c
cmpl $0x10, 0x337195(%rip)   # 0x3cf1ac
jne 0x9802a
leaq 0xf0685(%rip), %rdi     # 0x1886a5
movl $0x32, %esi
callq 0x96370
jmp 0x9802c
jmp 0x9802e
jmp 0x98030
jmp 0x98032
jmp 0x98034
jmp 0x98036
jmp 0x98038
jmp 0x9803a
jmp 0x9803c
jmp 0x9803e
jmp 0x98040
jmp 0x98042
jmp 0x98044
jmp 0x98046
jmp 0x98048
jmp 0x9804a
movl 0x33715c(%rip), %eax    # 0x3cf1ac
addl $0x1, %eax
movl %eax, 0x337153(%rip)    # 0x3cf1ac
cmpl $0x10, %eax
jle 0x98077
movl $0x0, 0x337144(%rip)    # 0x3cf1ac
movl 0x332f3a(%rip), %eax    # 0x3cafa8
addl $0x1, %eax
movl %eax, 0x332f31(%rip)    # 0x3cafa8
jmp 0x98079
jmp 0x9807b
movl 0x33712f(%rip), %eax    # 0x3cf1b0
addl $0x1, %eax
movl %eax, 0x337126(%rip)    # 0x3cf1b0
jmp 0x98394
cmpl $0x0, 0x337116(%rip)    # 0x3cf1ac
jge 0x980a2
movl $0x0, 0x33710a(%rip)    # 0x3cf1ac
movl 0x337108(%rip), %eax    # 0x3cf1b0
movl $0xa, %ecx
xorl %edx, %edx
divl %ecx
cmpl $0x0, %edx
jne 0x980cc
leaq 0xf05f3(%rip), %rdi     # 0x1886b0
movl $0x10, %esi
callq 0x96370
jmp 0x98385
movl 0x3370de(%rip), %eax    # 0x3cf1b0
movl $0xa, %ecx
xorl %edx, %edx
divl %ecx
cmpl $0x1, %edx
jne 0x980f6
leaq 0xf05d5(%rip), %rdi     # 0x1886bc
movl $0xb, %esi
callq 0x96370
jmp 0x98383
cmpl $0x0, 0x3370af(%rip)    # 0x3cf1ac
jne 0x98115
leaq 0xf05c6(%rip), %rdi     # 0x1886cc
movl $0xf, %esi
callq 0x96370
jmp 0x98354
cmpl $0x1, 0x337090(%rip)    # 0x3cf1ac
jne 0x98153
leaq 0x1e209b(%rip), %rax    # 0x27a1c0
cmpl $0x38, (%rax)
jne 0x9813d
leaq 0xf05ab(%rip), %rdi     # 0x1886dc
movl $0x15, %esi
callq 0x96370
jmp 0x9814e
leaq 0xf05a2(%rip), %rdi     # 0x1886e6
movl $0x15, %esi
callq 0x96370
jmp 0x98352
cmpl $0x2, 0x337052(%rip)    # 0x3cf1ac
jne 0x98172
leaq 0xec7f4(%rip), %rdi     # 0x184957
movl $0x1c, %esi
callq 0x96370
jmp 0x98350
cmpl $0x3, 0x337033(%rip)    # 0x3cf1ac
jne 0x98191
leaq 0xf0572(%rip), %rdi     # 0x1886f4
movl $0xc, %esi
callq 0x96370
jmp 0x9834e
cmpl $0x4, 0x337014(%rip)    # 0x3cf1ac
jne 0x981b0
leaq 0xf056b(%rip), %rdi     # 0x18870c
movl $0xd, %esi
callq 0x96370
jmp 0x9834c
cmpl $0x5, 0x336ff5(%rip)    # 0x3cf1ac
jne 0x981cf
leaq 0xebd41(%rip), %rdi     # 0x183f01
movl $0x1e, %esi
callq 0x96370
jmp 0x9834a
cmpl $0x6, 0x336fd6(%rip)    # 0x3cf1ac
jne 0x981ee
leaq 0xf0541(%rip), %rdi     # 0x188720
movl $0x1a, %esi
callq 0x96370
jmp 0x98348
cmpl $0x7, 0x336fb7(%rip)    # 0x3cf1ac
jne 0x9820d
leaq 0xec57f(%rip), %rdi     # 0x18477d
movl $0x16, %esi
callq 0x96370
jmp 0x98346
cmpl $0x8, 0x336f98(%rip)    # 0x3cf1ac
jne 0x9822c
leaq 0xf051b(%rip), %rdi     # 0x188738
movl $0x17, %esi
callq 0x96370
jmp 0x98344
cmpl $0x9, 0x336f79(%rip)    # 0x3cf1ac
jne 0x9824b
leaq 0xebf5c(%rip), %rdi     # 0x184198
movl $0xa, %esi
callq 0x96370
jmp 0x98342
cmpl $0xa, 0x336f5a(%rip)    # 0x3cf1ac
jne 0x9826a
leaq 0xf04ec(%rip), %rdi     # 0x188747
movl $0xe, %esi
callq 0x96370
jmp 0x98340
cmpl $0xb, 0x336f3b(%rip)    # 0x3cf1ac
jne 0x98289
leaq 0xec736(%rip), %rdi     # 0x1849b0
movl $0x13, %esi
callq 0x96370
jmp 0x9833e
cmpl $0xc, 0x336f1c(%rip)    # 0x3cf1ac
jne 0x982a8
leaq 0xf04be(%rip), %rdi     # 0x188757
movl $0x12, %esi
callq 0x96370
jmp 0x9833c
cmpl $0xd, 0x336efd(%rip)    # 0x3cf1ac
jne 0x982c4
leaq 0xf04b8(%rip), %rdi     # 0x188770
movl $0x1b, %esi
callq 0x96370
jmp 0x9833a
cmpl $0xe, 0x336ee1(%rip)    # 0x3cf1ac
jne 0x982e0
leaq 0xf04ad(%rip), %rdi     # 0x188781
movl $0x1b, %esi
callq 0x96370
jmp 0x98338
cmpl $0xf, 0x336ec5(%rip)    # 0x3cf1ac
jne 0x982fc
leaq 0xec076(%rip), %rdi     # 0x184366
movl $0x22, %esi
callq 0x96370
jmp 0x98336
cmpl $0x10, 0x336ea9(%rip)   # 0x3cf1ac
jne 0x98318
leaq 0xf0486(%rip), %rdi     # 0x188792
movl $0x23, %esi
callq 0x96370
jmp 0x98334
cmpl $0x11, 0x336e8d(%rip)   # 0x3cf1ac
jne 0x98332
leaq 0xf047b(%rip), %rdi     # 0x1887a3
movl $0x18, %esi
callq 0x96370
jmp 0x98334
jmp 0x98336
jmp 0x98338
jmp 0x9833a
jmp 0x9833c
jmp 0x9833e
jmp 0x98340
jmp 0x98342
jmp 0x98344
jmp 0x98346
jmp 0x98348
jmp 0x9834a
jmp 0x9834c
jmp 0x9834e
jmp 0x98350
jmp 0x98352
jmp 0x98354
movl 0x336e52(%rip), %eax    # 0x3cf1ac
addl $0x1, %eax
movl %eax, 0x336e49(%rip)    # 0x3cf1ac
cmpl $0x11, %eax
jle 0x98381
movl $0x0, 0x336e3a(%rip)    # 0x3cf1ac
movl 0x332c30(%rip), %eax    # 0x3cafa8
addl $0x1, %eax
movl %eax, 0x332c27(%rip)    # 0x3cafa8
jmp 0x98383
jmp 0x98385
movl 0x336e25(%rip), %eax    # 0x3cf1b0
addl $0x1, %eax
movl %eax, 0x336e1c(%rip)    # 0x3cf1b0
jmp 0x98396
jmp 0x983a9
leaq 0xf041a(%rip), %rdi     # 0x1887b9
movl $0x3e7, %esi            # imm = 0x3E7
callq 0x96370
jmp 0x983ab
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)