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

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

   test = 0;
   if(test && (polled_q_in != polled_q_out)) {  // we have a special message request queued
      send_queued_cmd(1);
   }
   else if(1) { // 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 {  // poll standard messages 
      if(polled_req < 0) polled_req = 0;

         if(0 && ((polled_seq % 8) == 0)) {       // get FC value every two seconds
            send_polled_cmd("FC?", PRS_FC_MSG);
         }
         else if(0 && ((polled_seq % 8) == 1)) {  // get TT value every two seconds
            send_polled_cmd("TT?", PRS_TT_MSG);
         }
         else if(0 && ((polled_seq % 8) == 2)) {  // get case temperature value every two seconds
            send_polled_cmd("AD10?", PRS_AD10_MSG);
         }
         else if(1 && prs_poll_tick) {
            if(prs_poll_tick == 1) {       // get FC value every two seconds
               send_polled_cmd("FC?", PRS_FC_MSG);
               ++prs_poll_tick;
            }
            else if(prs_poll_tick == 2) {  // get TT value every two seconds
               send_polled_cmd("TT?", PRS_TT_MSG);
               ++prs_poll_tick;
            }
            else {  // get case temperature value every two seconds
               send_polled_cmd("AD10?", PRS_AD10_MSG);
               prs_poll_tick = 0;
            }
         }
         else {
            // 52 message cycle repeats every 12 seconds -> 4.33 messages per second with PRS_SLEEP == 0
            // 52 message cycle repeats every 13 seconds -> 4.00 messages per second with PRS_SLEEP == 100

            if     (polled_req == 0)  send_polled_cmd("ID?",   PRS_ID_MSG);  // we get serial number from here, not from SN?
            else if(polled_req == 1)  send_polled_cmd("EP?",   PRS_EP_MSG);  // enable power
            else if(polled_req == 2)  send_polled_cmd("VB?",   PRS_VB_MSG);
            else if(polled_req == 3)  send_polled_cmd("ST?",   PRS_ST_MSG);
            else if(polled_req == 4)  send_polled_cmd("LM?",   PRS_LM_MSG);
            else if(polled_req == 5)  send_polled_cmd("LO?",   PRS_LO_MSG);
            else if(polled_req == 6)  send_polled_cmd("FC?",   PRS_FC_MSG);
            else if(polled_req == 7)  send_polled_cmd("DS?",   PRS_DS_MSG);
            else if(polled_req == 8)  send_polled_cmd("SF?",   PRS_SF_MSG);
            else if(polled_req == 9)  send_polled_cmd("SS?",   PRS_SS_MSG);
            else if(polled_req == 10) send_polled_cmd("GA?",   PRS_GA_MSG);
            else if(polled_req == 11) send_polled_cmd("PH?",   PRS_PH_MSG);
            else if(polled_req == 12) send_polled_cmd("SP?",   PRS_SP_MSG);
            else if(polled_req == 13) send_polled_cmd("MS?",   PRS_MS_MSG);
            else if(polled_req == 14) send_polled_cmd("MO?",   PRS_MO_MSG);
            else if(polled_req == 15) send_polled_cmd("MR?",   PRS_MR_MSG);
            else if(polled_req == 16) send_polled_cmd("FC!?",  PRS_FC2_MSG);  // was TT?
            else if(polled_req == 17) send_polled_cmd("TS?",   PRS_TS_MSG);
            else if(polled_req == 18) send_polled_cmd("TO?",   PRS_TO_MSG);
            else if(polled_req == 19) send_polled_cmd("PL?",   PRS_PL_MSG);
            else if(polled_req == 20) send_polled_cmd("PT?",   PRS_PT_MSG);
            else if(polled_req == 21) send_polled_cmd("PF?",   PRS_PF_MSG);
            else if(polled_req == 22) send_polled_cmd("PI?",   PRS_PI_MSG);

            else if(polled_req == 23) send_polled_cmd("SD0?",  PRS_SD0_MSG);
            else if(polled_req == 24) send_polled_cmd("SD1?",  PRS_SD1_MSG);
            else if(polled_req == 25) send_polled_cmd("SD2?",  PRS_SD2_MSG);
            else if(polled_req == 26) send_polled_cmd("SD3?",  PRS_SD3_MSG);
            else if(polled_req == 27) send_polled_cmd("SD4?",  PRS_SD4_MSG);
            else if(polled_req == 28) send_polled_cmd("SD5?",  PRS_SD5_MSG);
            else if(polled_req == 29) send_polled_cmd("SD6?",  PRS_SD6_MSG);
            else if(polled_req == 30) send_polled_cmd("SD7?",  PRS_SD7_MSG);

            else if(polled_req == 31) send_polled_cmd("AD0?",  PRS_AD0_MSG);
            else if(polled_req == 32) send_polled_cmd("AD1?",  PRS_AD1_MSG);
            else if(polled_req == 33) send_polled_cmd("AD2?",  PRS_AD2_MSG);
            else if(polled_req == 34) send_polled_cmd("AD3?",  PRS_AD3_MSG);
            else if(polled_req == 35) send_polled_cmd("AD4?",  PRS_AD4_MSG);
            else if(polled_req == 36) send_polled_cmd("AD5?",  PRS_AD5_MSG);
            else if(polled_req == 37) send_polled_cmd("AD6?",  PRS_AD6_MSG);
            else if(polled_req == 38) send_polled_cmd("AD7?",  PRS_AD7_MSG);
            else if(polled_req == 39) send_polled_cmd("AD8?",  PRS_AD8_MSG);
            else if(polled_req == 40) send_polled_cmd("AD9?",  PRS_AD9_MSG);
            else if(polled_req == 41) send_polled_cmd("AD10?", PRS_AD10_MSG);  // case temp
            else if(polled_req == 42) send_polled_cmd("AD11?", PRS_AD11_MSG);
            else if(polled_req == 43) send_polled_cmd("AD12?", PRS_AD12_MSG);
            else if(polled_req == 44) send_polled_cmd("AD13?", PRS_AD13_MSG);
            else if(polled_req == 45) send_polled_cmd("AD14?", PRS_AD14_MSG);
            else if(polled_req == 46) send_polled_cmd("AD15?", PRS_AD15_MSG);
            else if(polled_req == 47) send_polled_cmd("AD16?", PRS_AD16_MSG);
            else if(polled_req == 48) send_polled_cmd("AD17?", PRS_AD17_MSG);
            else if(polled_req == 49) send_polled_cmd("AD18?", PRS_AD18_MSG);
            else if(polled_req == 50) send_polled_cmd("AD19?", PRS_AD19_MSG);

            else if(polled_req == 51) send_polled_cmd("PS?",   PRS_PS_MSG);

            if(++polled_req > 51) {
               polled_req = 0;
               ++all_polled;
               if(all_polled == 1) {  // reset the queues the first time through
                  new_queue(RESET_ALL_QUEUES, 4598);
               }
            }
         }
         ++polled_seq;
      }
   }
}

// Assembly:
movl 0x2f44c5(%rip), %eax    # 0x359fd0
cmpl 0x2f44c3(%rip), %eax    # 0x359fd4
jne 0x65b4c
movl 0x2f44c3(%rip), %eax    # 0x359fdc
testl %eax, %eax
jns 0x65b26
andl $0x0, 0x2f44b8(%rip)    # 0x359fdc
xorl %eax, %eax
pushq %rbp
movq %rsp, %rbp
movl 0x2f10c8(%rip), %ecx    # 0x356bf8
testl %ecx, %ecx
je 0x65b70
cmpl $0x2, %ecx
je 0x65b54
cmpl $0x1, %ecx
jne 0x65b9c
leaq 0xa97d7(%rip), %rdi     # 0x10f31c
movl $0x1fc, %esi            # imm = 0x1FC
jmp 0x65b60
pushq $0x2
popq %rdi
jmp 0x7dfa9
leaq 0xa7e85(%rip), %rdi     # 0x10d9e0
movl $0x206, %esi            # imm = 0x206
callq 0x64f01
incl 0x2f108d(%rip)          # 0x356bf8
jmp 0x65f3c
cmpl $0x33, %eax
ja 0x65f15
movl %eax, %eax
leaq 0xa3016(%rip), %rcx     # 0x108b98
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xa4c78(%rip), %rdi     # 0x10a80a
movl $0x1f6, %esi            # imm = 0x1F6
jmp 0x65efc
leaq 0xa7e41(%rip), %rdi     # 0x10d9e4
movl $0x262, %esi            # imm = 0x262
callq 0x64f01
andl $0x0, 0x2f1044(%rip)    # 0x356bf8
jmp 0x65f3c
leaq 0xa7ee1(%rip), %rdi     # 0x10daa1
movl $0x26b, %esi            # imm = 0x26B
jmp 0x65efc
leaq 0xa7ea6(%rip), %rdi     # 0x10da77
movl $0x264, %esi            # imm = 0x264
jmp 0x65efc
leaq 0xa7e7b(%rip), %rdi     # 0x10da5d
movl $0x25e, %esi            # imm = 0x25E
jmp 0x65efc
leaq 0xa7e9c(%rip), %rdi     # 0x10da8f
movl $0x268, %esi            # imm = 0x268
jmp 0x65efc
leaq 0xa7e4f(%rip), %rdi     # 0x10da53
movl $0x25c, %esi            # imm = 0x25C
jmp 0x65efc
leaq 0xa7e43(%rip), %rdi     # 0x10da58
movl $0x25d, %esi            # imm = 0x25D
jmp 0x65efc
leaq 0xa7e05(%rip), %rdi     # 0x10da2b
movl $0x216, %esi            # imm = 0x216
jmp 0x65efc
leaq 0xa7e17(%rip), %rdi     # 0x10da4e
movl $0x25b, %esi            # imm = 0x25B
jmp 0x65efc
leaq 0xa7dc2(%rip), %rdi     # 0x10da0a
movl $0x20f, %esi            # imm = 0x20F
jmp 0x65efc
leaq 0xa7e24(%rip), %rdi     # 0x10da7d
movl $0x265, %esi            # imm = 0x265
jmp 0x65efc
leaq 0xa7d98(%rip), %rdi     # 0x10da02
movl $0x204, %esi            # imm = 0x204
jmp 0x65efc
leaq 0xa7dce(%rip), %rdi     # 0x10da49
movl $0x25a, %esi            # imm = 0x25A
jmp 0x65efc
leaq 0xa7e09(%rip), %rdi     # 0x10da95
movl $0x269, %esi            # imm = 0x269
jmp 0x65efc
leaq 0xa7d5d(%rip), %rdi     # 0x10d9fa
movl $0x201, %esi            # imm = 0x201
jmp 0x65efc
leaq 0xa7ded(%rip), %rdi     # 0x10da9b
movl $0x26a, %esi            # imm = 0x26A
jmp 0x65efc
leaq 0xa5265(%rip), %rdi     # 0x10af24
movl $0x1fa, %esi            # imm = 0x1FA
jmp 0x65efc
leaq 0xa7d9c(%rip), %rdi     # 0x10da6c
movl $0x261, %esi            # imm = 0x261
jmp 0x65efc
leaq 0xa9b13(%rip), %rdi     # 0x10f7f4
movl $0x202, %esi            # imm = 0x202
jmp 0x65efc
leaq 0xa5c0c(%rip), %rdi     # 0x10b8fe
movl $0x1ff, %esi            # imm = 0x1FF
jmp 0x65efc
leaq 0xa7d1e(%rip), %rdi     # 0x10da21
movl $0x214, %esi            # imm = 0x214
jmp 0x65efc
leaq 0xa7d08(%rip), %rdi     # 0x10da1c
movl $0x213, %esi            # imm = 0x213
jmp 0x65efc
leaq 0xa7cc9(%rip), %rdi     # 0x10d9ee
movl $0x1f8, %esi            # imm = 0x1F8
jmp 0x65efc
leaq 0xa7cd0(%rip), %rdi     # 0x10da06
movl $0x205, %esi            # imm = 0x205
jmp 0x65efc
leaq 0xa9b79(%rip), %rdi     # 0x10f8c0
movl $0x1f9, %esi            # imm = 0x1F9
jmp 0x65efc
leaq 0xa7c9a(%rip), %rdi     # 0x10d9f2
movl $0x1fd, %esi            # imm = 0x1FD
jmp 0x65efc
leaq 0xa7c81(%rip), %rdi     # 0x10d9ea
movl $0x210, %esi            # imm = 0x210
jmp 0x65efc
leaq 0xa7cc5(%rip), %rdi     # 0x10da3f
movl $0x258, %esi            # imm = 0x258
jmp 0x65efc
leaq 0xa99c6(%rip), %rdi     # 0x10f751
movl $0x207, %esi            # imm = 0x207
jmp 0x65efc
leaq 0xa7c48(%rip), %rdi     # 0x10d9e4
movl $0x262, %esi            # imm = 0x262
jmp 0x65efc
leaq 0xa5ad1(%rip), %rdi     # 0x10b87e
movl $0x20b, %esi            # imm = 0x20B
jmp 0x65efc
leaq 0xa55fb(%rip), %rdi     # 0x10b3b9
movl $0x1fb, %esi            # imm = 0x1FB
jmp 0x65efc
leaq 0xa5ab7(%rip), %rdi     # 0x10b886
movl $0x20c, %esi            # imm = 0x20C
jmp 0x65efc
leaq 0xa7c1e(%rip), %rdi     # 0x10d9fe
movl $0x203, %esi            # imm = 0x203
jmp 0x65efc
leaq 0xa952b(%rip), %rdi     # 0x10f31c
movl $0x1fc, %esi            # imm = 0x1FC
jmp 0x65efc
leaq 0xa7c0d(%rip), %rdi     # 0x10da0f
movl $0x208, %esi            # imm = 0x208
jmp 0x65efc
leaq 0xa5a6f(%rip), %rdi     # 0x10b882
movl $0x200, %esi            # imm = 0x200
jmp 0x65efc
leaq 0xa7bd2(%rip), %rdi     # 0x10d9f6
movl $0x1fe, %esi            # imm = 0x1FE
jmp 0x65efc
leaq 0xa7c05(%rip), %rdi     # 0x10da3a
movl $0x219, %esi            # imm = 0x219
jmp 0x65efc
leaq 0xa7bfe(%rip), %rdi     # 0x10da44
movl $0x259, %esi            # imm = 0x259
jmp 0x65efc
leaq 0xa7c2c(%rip), %rdi     # 0x10da83
movl $0x266, %esi            # imm = 0x266
jmp 0x65efc
leaq 0xa5a22(%rip), %rdi     # 0x10b88a
movl $0x20d, %esi            # imm = 0x20D
jmp 0x65efc
leaq 0xa7bee(%rip), %rdi     # 0x10da67
movl $0x260, %esi            # imm = 0x260
jmp 0x65efc
leaq 0xa7b8c(%rip), %rdi     # 0x10da13
movl $0x20a, %esi            # imm = 0x20A
jmp 0x65efc
leaq 0xa7bdc(%rip), %rdi     # 0x10da71
movl $0x263, %esi            # imm = 0x263
jmp 0x65efc
leaq 0xa7b74(%rip), %rdi     # 0x10da17
movl $0x212, %esi            # imm = 0x212
jmp 0x65efc
leaq 0xa7b7f(%rip), %rdi     # 0x10da30
movl $0x217, %esi            # imm = 0x217
jmp 0x65efc
leaq 0xa7b76(%rip), %rdi     # 0x10da35
movl $0x218, %esi            # imm = 0x218
jmp 0x65efc
leaq 0xa7b95(%rip), %rdi     # 0x10da62
movl $0x25f, %esi            # imm = 0x25F
jmp 0x65efc
leaq 0xa7b4b(%rip), %rdi     # 0x10da26
movl $0x215, %esi            # imm = 0x215
jmp 0x65efc
leaq 0xa7ba0(%rip), %rdi     # 0x10da89
movl $0x267, %esi            # imm = 0x267
jmp 0x65efc
leaq 0xa7bb0(%rip), %rdi     # 0x10daa7
movl $0x209, %esi            # imm = 0x209
callq 0x64f01
movl 0x2f40d5(%rip), %eax    # 0x359fdc
leal 0x1(%rax), %ecx
movl %ecx, 0x2f40cc(%rip)    # 0x359fdc
cmpl $0x33, %eax
jl 0x65f3c
andl $0x0, 0x2f40c0(%rip)    # 0x359fdc
movl 0x2efea6(%rip), %eax    # 0x355dc8
leal 0x1(%rax), %ecx
movl %ecx, 0x2efe9d(%rip)    # 0x355dc8
testl %eax, %eax
jne 0x65f3c
pushq $0x7
popq %rdi
movl $0x11f6, %esi           # imm = 0x11F6
callq 0x10a99
incl 0x2f409e(%rip)          # 0x359fe0
popq %rbp
retq