// File: /workspace/github_cpp_makefile_star2_O2/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:
movl 0x2f4070(%rip), %eax    # 0x359fd0
cmpl 0x2f406e(%rip), %eax    # 0x359fd4
jne 0x65fb8
cmpl $0x3e7, 0x2f0c8e(%rip)  # imm = 0x3E7
jne 0x65fc0
pushq %rbp
movq %rsp, %rbp
leaq 0x19f061(%rip), %rax    # 0x204fe0
movl (%rax), %esi
movl 0x2f4055(%rip), %ecx    # 0x359fdc
cmpl $0x4e, %esi
jne 0x65fd1
testl %ecx, %ecx
jns 0x65f99
andl $0x0, 0x2f4045(%rip)    # 0x359fdc
xorl %ecx, %ecx
movl 0x2f4041(%rip), %eax    # 0x359fe0
pushq $0xa
popq %rsi
xorl %edx, %edx
divl %esi
cmpl $0x1, %edx
je 0x65fff
testl %edx, %edx
jne 0x6601c
leaq 0xa928c(%rip), %rdi     # 0x10f242
jmp 0x65ffb
pushq $0x1
popq %rdi
jmp 0x7dfa9
leaq 0xa9446(%rip), %rdi     # 0x10f40d
movl $0x3e7, %esi            # imm = 0x3E7
jmp 0x64f01
testl %ecx, %ecx
jns 0x65fde
andl $0x0, 0x2f4000(%rip)    # 0x359fdc
xorl %ecx, %ecx
movl 0x2f3ffc(%rip), %eax    # 0x359fe0
pushq $0xa
popq %rdi
xorl %edx, %edx
divl %edi
cmpl $0x1, %edx
je 0x66008
testl %edx, %edx
jne 0x66045
leaq 0xa9309(%rip), %rdi     # 0x10f304
pushq $0x10
jmp 0x66011
leaq 0xa5295(%rip), %rdi     # 0x10b29b
jmp 0x6600f
leaq 0xa9301(%rip), %rdi     # 0x10f310
pushq $0xb
popq %rsi
callq 0x64f01
jmp 0x66247
cmpl $0x10, %ecx
ja 0x6623a
movl %ecx, %eax
leaq 0xa2c82(%rip), %rcx     # 0x108cb0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xa9214(%rip), %rdi     # 0x10f252
pushq $0x1b
jmp 0x66126
cmpl $0x11, %ecx
ja 0x6623a
movl %ecx, %eax
leaq 0xa2c11(%rip), %rcx     # 0x108c68
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xa92b9(%rip), %rdi     # 0x10f320
pushq $0xf
jmp 0x66220
leaq 0xa9284(%rip), %rdi     # 0x10f2f9
pushq $0x32
jmp 0x66126
leaq 0xa4c1f(%rip), %rdi     # 0x10aca2
pushq $0x20
jmp 0x66126
leaq 0xa92bd(%rip), %rdi     # 0x10f34e
pushq $0xc
jmp 0x66126
leaq 0xa4f34(%rip), %rdi     # 0x10afd3
pushq $0xe
jmp 0x66126
leaq 0xa5389(%rip), %rdi     # 0x10b436
pushq $0x16
jmp 0x66126
leaq 0xa5831(%rip), %rdi     # 0x10b8e9
pushq $0x12
jmp 0x66126
leaq 0xa554c(%rip), %rdi     # 0x10b60f
pushq $0x1c
jmp 0x66126
leaq 0xa9216(%rip), %rdi     # 0x10f2e4
pushq $0x23
jmp 0x66126
leaq 0xa91a1(%rip), %rdi     # 0x10f27a
pushq $0x15
jmp 0x66126
leaq 0xa91b7(%rip), %rdi     # 0x10f29b
pushq $0x34
jmp 0x66126
leaq 0xa9175(%rip), %rdi     # 0x10f264
pushq $0xf
jmp 0x66126
leaq 0xa4d3e(%rip), %rdi     # 0x10ae38
jmp 0x66127
leaq 0xa4b8a(%rip), %rdi     # 0x10ac8d
pushq $0x1e
jmp 0x66126
leaq 0xa917a(%rip), %rdi     # 0x10f288
pushq $0x33
jmp 0x66126
leaq 0xa91b9(%rip), %rdi     # 0x10f2d2
pushq $0xd
jmp 0x66126
leaq 0xa9193(%rip), %rdi     # 0x10f2b7
pushq $0x1a
popq %rsi
callq 0x64f01
movl 0x2f3eaa(%rip), %eax    # 0x359fdc
leal 0x1(%rax), %ecx
movl %ecx, 0x2f3ea1(%rip)    # 0x359fdc
cmpl $0x10, %eax
jge 0x6623a
jmp 0x66247
leaq 0xa9296(%rip), %rdi     # 0x10f3e6
pushq $0x23
jmp 0x66220
leaq 0xa9277(%rip), %rdi     # 0x10f3d5
jmp 0x661f2
leaq 0xa54fe(%rip), %rdi     # 0x10b668
pushq $0x13
jmp 0x66220
leaq 0xa91e8(%rip), %rdi     # 0x10f360
pushq $0xd
jmp 0x66220
leaq 0xa9225(%rip), %rdi     # 0x10f3ab
pushq $0x12
jmp 0x66220
leaq 0xa4ccc(%rip), %rdi     # 0x10ae60
pushq $0xa
jmp 0x66220
leaq 0xa546d(%rip), %rdi     # 0x10b60f
pushq $0x1c
jmp 0x66220
leaq 0xa4e71(%rip), %rdi     # 0x10b01e
pushq $0x22
jmp 0x66220
leaq 0xa9190(%rip), %rdi     # 0x10f348
pushq $0xc
jmp 0x66220
leaq 0xa5272(%rip), %rdi     # 0x10b435
pushq $0x16
jmp 0x66220
cmpl $0x38, %esi
jne 0x66217
leaq 0xa915d(%rip), %rdi     # 0x10f330
jmp 0x6621e
leaq 0xa921b(%rip), %rdi     # 0x10f3f7
pushq $0x18
jmp 0x66220
leaq 0xa49e2(%rip), %rdi     # 0x10abc9
pushq $0x1e
jmp 0x66220
leaq 0xa91d2(%rip), %rdi     # 0x10f3c4
pushq $0x1b
jmp 0x66220
leaq 0xa9177(%rip), %rdi     # 0x10f374
pushq $0x1a
jmp 0x66220
leaq 0xa9193(%rip), %rdi     # 0x10f39b
pushq $0xe
jmp 0x66220
leaq 0xa9179(%rip), %rdi     # 0x10f38c
pushq $0x17
jmp 0x66220
leaq 0xa911c(%rip), %rdi     # 0x10f33a
pushq $0x15
popq %rsi
callq 0x64f01
movl 0x2f3db0(%rip), %eax    # 0x359fdc
leal 0x1(%rax), %ecx
movl %ecx, 0x2f3da7(%rip)    # 0x359fdc
cmpl $0x11, %eax
jl 0x66247
andl $0x0, 0x2f3d9b(%rip)    # 0x359fdc
incl 0x2efb81(%rip)          # 0x355dc8
incl 0x2f3d93(%rip)          # 0x359fe0
popq %rbp
retq