// File: /workspace/github_cpp_makefile_star2_O3/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 0x300b54(%rip), %eax    # 0x36ffd0
cmpl 0x300b52(%rip), %eax    # 0x36ffd4
jne 0x6f4e8
cmpl $0x3e7, 0x2fd772(%rip)  # imm = 0x3E7
jne 0x6f4f2
pushq %rbp
movq %rsp, %rbp
leaq 0x1abb45(%rip), %rax    # 0x21afe0
movl (%rax), %ecx
movl 0x300b39(%rip), %eax    # 0x36ffdc
cmpl $0x4e, %ecx
jne 0x6f503
testl %eax, %eax
jns 0x6f4b8
movl $0x0, 0x300b26(%rip)    # 0x36ffdc
xorl %eax, %eax
movl 0x300b22(%rip), %ecx    # 0x36ffe0
movl $0xcccccccd, %edx       # imm = 0xCCCCCCCD
imulq %rcx, %rdx
shrq $0x23, %rdx
addl %edx, %edx
leal (%rdx,%rdx,4), %edx
subl %edx, %ecx
cmpl $0x1, %ecx
je 0x6f544
testl %ecx, %ecx
jne 0x6f563
leaq 0xb5e14(%rip), %rdi     # 0x1252fa
jmp 0x6f53d
movl $0x1, %edi
jmp 0x8aadd
leaq 0xb5fcc(%rip), %rdi     # 0x1254c5
movl $0x3e7, %esi            # imm = 0x3E7
jmp 0x6e2d1
testl %eax, %eax
jns 0x6f513
movl $0x0, 0x300acb(%rip)    # 0x36ffdc
xorl %eax, %eax
movl 0x300ac7(%rip), %edx    # 0x36ffe0
movl $0xcccccccd, %esi       # imm = 0xCCCCCCCD
imulq %rdx, %rsi
shrq $0x23, %rsi
addl %esi, %esi
leal (%rsi,%rsi,4), %esi
subl %esi, %edx
cmpl $0x1, %edx
je 0x6f54d
testl %edx, %edx
jne 0x6f58f
leaq 0xb5e7f(%rip), %rdi     # 0x1253bc
movl $0x10, %esi
jmp 0x6f559
leaq 0xb1e08(%rip), %rdi     # 0x121353
jmp 0x6f554
leaq 0xb5e74(%rip), %rdi     # 0x1253c8
movl $0xb, %esi
callq 0x6e2d1
jmp 0x6f803
cmpl $0x10, %eax
ja 0x6f7f3
movl %eax, %eax
leaq 0xaf7fb(%rip), %rcx     # 0x11ed70
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xb5d85(%rip), %rdi     # 0x12530a
movl $0x1b, %esi
jmp 0x6f6ab
cmpl $0x11, %eax
ja 0x6f7f3
movl %eax, %eax
leaq 0xaf787(%rip), %rdx     # 0x11ed28
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
jmpq *%rax
leaq 0xb5e27(%rip), %rdi     # 0x1253d8
movl $0xf, %esi
jmp 0x6f7da
leaq 0xb5def(%rip), %rdi     # 0x1253b1
movl $0x32, %esi
jmp 0x6f6ab
leaq 0xb1787(%rip), %rdi     # 0x120d5a
movl $0x20, %esi
jmp 0x6f6ab
leaq 0xb5e22(%rip), %rdi     # 0x125406
movl $0xc, %esi
jmp 0x6f6ab
leaq 0xb1a96(%rip), %rdi     # 0x12108b
movl $0xe, %esi
jmp 0x6f6ab
leaq 0xb1ee8(%rip), %rdi     # 0x1214ee
movl $0x16, %esi
jmp 0x6f6ab
leaq 0xb238a(%rip), %rdi     # 0x1219a1
movl $0x12, %esi
jmp 0x6f6ab
leaq 0xb209f(%rip), %rdi     # 0x1216c7
movl $0x1c, %esi
jmp 0x6f6ab
leaq 0xb5d66(%rip), %rdi     # 0x12539c
movl $0x23, %esi
jmp 0x6f6ab
leaq 0xb5cee(%rip), %rdi     # 0x125332
movl $0x15, %esi
jmp 0x6f6ab
leaq 0xb5d01(%rip), %rdi     # 0x125353
movl $0x34, %esi
jmp 0x6f6ab
leaq 0xb5cbc(%rip), %rdi     # 0x12531c
movl $0xf, %esi
jmp 0x6f6ab
leaq 0xb1882(%rip), %rdi     # 0x120ef0
movl $0xa, %esi
jmp 0x6f6ab
leaq 0xb16c9(%rip), %rdi     # 0x120d45
movl $0x1e, %esi
jmp 0x6f6ab
leaq 0xb5cb6(%rip), %rdi     # 0x125340
movl $0x33, %esi
jmp 0x6f6ab
leaq 0xb5cf2(%rip), %rdi     # 0x12538a
movl $0xd, %esi
jmp 0x6f6ab
leaq 0xb5cc9(%rip), %rdi     # 0x12536f
movl $0x1a, %esi
callq 0x6e2d1
movl 0x300926(%rip), %eax    # 0x36ffdc
leal 0x1(%rax), %ecx
movl %ecx, 0x30091d(%rip)    # 0x36ffdc
cmpl $0x10, %eax
jge 0x6f7f3
jmp 0x6f803
leaq 0xb5dca(%rip), %rdi     # 0x12549e
movl $0x23, %esi
jmp 0x6f7da
leaq 0xb5da8(%rip), %rdi     # 0x12548d
jmp 0x6f79d
leaq 0xb202f(%rip), %rdi     # 0x121720
movl $0x13, %esi
jmp 0x6f7da
leaq 0xb5d16(%rip), %rdi     # 0x125418
movl $0xd, %esi
jmp 0x6f7da
leaq 0xb5d50(%rip), %rdi     # 0x125463
movl $0x12, %esi
jmp 0x6f7da
leaq 0xb17f4(%rip), %rdi     # 0x120f18
movl $0xa, %esi
jmp 0x6f7da
leaq 0xb1f92(%rip), %rdi     # 0x1216c7
movl $0x1c, %esi
jmp 0x6f7da
leaq 0xb1990(%rip), %rdi     # 0x1210d6
movl $0x22, %esi
jmp 0x6f7da
leaq 0xb5ca9(%rip), %rdi     # 0x125400
movl $0xc, %esi
jmp 0x6f7da
leaq 0xb1d88(%rip), %rdi     # 0x1214ed
movl $0x16, %esi
jmp 0x6f7da
cmpl $0x38, %ecx
jne 0x6f7ce
leaq 0xb5c70(%rip), %rdi     # 0x1253e8
jmp 0x6f7d5
leaq 0xb5d2e(%rip), %rdi     # 0x1254af
movl $0x18, %esi
jmp 0x6f7da
leaq 0xb14f2(%rip), %rdi     # 0x120c81
movl $0x1e, %esi
jmp 0x6f7da
leaq 0xb5cdf(%rip), %rdi     # 0x12547c
movl $0x1b, %esi
jmp 0x6f7da
leaq 0xb5c81(%rip), %rdi     # 0x12542c
movl $0x1a, %esi
jmp 0x6f7da
leaq 0xb5c9a(%rip), %rdi     # 0x125453
movl $0xe, %esi
jmp 0x6f7da
leaq 0xb5c7d(%rip), %rdi     # 0x125444
movl $0x17, %esi
jmp 0x6f7da
leaq 0xb5c1d(%rip), %rdi     # 0x1253f2
movl $0x15, %esi
callq 0x6e2d1
movl 0x3007f7(%rip), %eax    # 0x36ffdc
leal 0x1(%rax), %ecx
movl %ecx, 0x3007ee(%rip)    # 0x36ffdc
cmpl $0x11, %eax
jl 0x6f803
movl $0x0, 0x3007df(%rip)    # 0x36ffdc
incl 0x2fc5c5(%rip)          # 0x36bdc8
incl 0x3007d7(%rip)          # 0x36ffe0
popq %rbp
retq