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

   // mode 0x02 - 1PPS
   // mode 0x82 - PP2S / 100 pps mode (Motorola)
   // mode 0x83 - 10000 PPS mode / 100 pps mode (Brandywine)

   if(read_only) return;    // !!! Resolution-T only
   if(luxor) return;

   if(rcvr_type == BRANDY_RCVR) {
      if(brandy_pps_width < 0) {  // negative polarity
         if     (mode == 0x82) sprintf(out, "$PRCCG,C,P2000,%d", brandy_pps_width);  // PP2S
         else if(mode == 0x83) sprintf(out, "$PRCCG,C,P10,%d",   brandy_pps_width);  // 100 PPS
         else                  sprintf(out, "$PRCCG,C,P1000,%d", brandy_pps_width);
      }
      else {  // positive polarity
         if     (mode == 0x82) sprintf(out, "$PRCCG,C,P2000,+%d", brandy_pps_width);  // PP2S
         else if(mode == 0x83) sprintf(out, "$PRCCG,C,P10,+%d",   brandy_pps_width);  // 100 PPS
         else                  sprintf(out, "$PRCCG,C,P1000,+%d", brandy_pps_width);
      }
      queue_brandy_cmd(out, BRANDY_PULSE_MSG);
   }
   else if(rcvr_type == ESIP_RCVR) {
       old_rate = pps_rate;
       pps_rate = mode;
       set_pps(user_pps_enable, pps_polarity,  cable_delay, pps1_delay,  pps_threshold, 10);
       pps_rate = old_rate;
       have_pps_rate = 1;
   }
   else if(rcvr_type == MOTO_RCVR) {
//sprintf(debug_text, "set pps mode:%d  oldr:%d  oldm:%d", mode, pps_rate,pps_mode);
      send_moto_start("AP");
      if(mode == RATE_100PPS) send_byte(1);  // 100 pps
      else                    send_byte(0);  // 1 PPS
      send_moto_end();
   }
   else if(rcvr_type == STAR_RCVR) {  // !!!!! we use this to toggle the TOD output
      if(star_type == OSA_TYPE) {
         if(mode == RATE_NO_TOD) {  // disable TOD message
            queue_star_cmd("TOD_STATE=D", STAR_TOD_MSG);
         }
         else {
            queue_star_cmd("TOD_STATE=E", STAR_TOD_MSG);
         }
         queue_star_cmd("TOD_STATE", STAR_TOD_MSG);
      }
      else {
         if(mode == RATE_NO_TOD) {  // disable TOD message
            queue_star_cmd("TOD_STATE=0;", STAR_TOD_MSG);
         }
         else {
            queue_star_cmd("TOD_STATE=1;", STAR_TOD_MSG);
         }
         queue_star_cmd("TOD_STATE;", STAR_TOD_MSG);
      }
   }
   else if(rcvr_type == TSIP_RCVR) {
      if(ACU_GG) ;
      else if(ACU_360) ;
      else if(ACUTIME) ;
      else if(PALISADE) return;
      else if(SV6_FAMILY) return;
      send_tsip_start(0x8E);
      send_byte(0x4E);
      mode &= 0xFE;
      send_byte(mode);
      send_tsip_end();
   }
   else if(rcvr_type == UBX_RCVR) {
       old_rate = pps_rate;
       pps_rate = mode;
       set_pps(user_pps_enable, pps_polarity,  delay_value, pps1_delay,  pps_threshold, 10);
       pps_rate = old_rate;
       have_pps_rate = 1;
   }
   else if(rcvr_type == UCCM_RCVR) {
      if(mode == RATE_PP2S) queue_uccm_cmd("OUTP:TP:SEL PP2S", UCCM_RATE_MSG);
      else                  queue_uccm_cmd("OUTP:TP:SEL PP1S", UCCM_RATE_MSG);
      queue_uccm_cmd("OUTP:TP:SEL?", UCCM_RATE_MSG);
   }
   else if(rcvr_type == ZYFER_RCVR) {
      if(mode == RATE_PP2S) send_zyfer_cmd("$PULR,2");      // PP2S
      else if(mode == RATE_1PPS) send_zyfer_cmd("$PULR,1"); // PPS
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
leaq 0x2bdd8c(%rip), %rax    # 0x32101a
leaq 0x1c5ca9(%rip), %rcx    # 0x228f3e
movb (%rcx), %cl
orb (%rax), %cl
jne 0x634d1
movl %edi, %ebx
leaq 0x19f628(%rip), %rax    # 0x2028d0
movq (%rax), %rax
cmpq $0x1, %rax
je 0x634b6
cmpq $0x4, %rax
je 0x63401
cmpq $0x8, %rax
je 0x63489
cmpq $0x20, %rax
je 0x6345d
cmpq $0x1000, %rax           # imm = 0x1000
je 0x63378
movl $0x80000000, %ecx       # imm = 0x80000000
cmpq %rcx, %rax
je 0x633d7
cmpq $0x100000, %rax         # imm = 0x100000
je 0x633b6
cmpq $0x40000, %rax          # imm = 0x40000
jne 0x634d1
cmpl $0x83, %ebx
leaq 0xa7e30(%rip), %rax     # 0x10b142
leaq 0xa7e39(%rip), %rcx     # 0x10b152
cmoveq %rax, %rcx
leaq 0xa7e53(%rip), %rax     # 0x10b177
leaq 0xa7e5d(%rip), %rdx     # 0x10b188
cmoveq %rax, %rdx
cmpl $0x82, %ebx
leaq 0xa7df4(%rip), %rax     # 0x10b130
cmovneq %rcx, %rax
leaq 0x2c2b11(%rip), %rcx    # 0x325e58
leaq 0xa7e16(%rip), %rsi     # 0x10b164
cmovneq %rdx, %rsi
movl (%rcx), %edx
testl %edx, %edx
cmovsq %rax, %rsi
leaq 0x2c2ebf(%rip), %rbx    # 0x326220
movq %rbx, %rdi
xorl %eax, %eax
callq 0x9060
movq %rbx, %rdi
movl $0x191, %esi            # imm = 0x191
jmp 0x6350a
leaq 0x1a1c69(%rip), %rax    # 0x204fe8
cmpl $0x4f, (%rax)
jne 0x634dc
cmpl $0x82, %ebx
leaq 0xa7e06(%rip), %rax     # 0x10b19b
leaq 0xa7e0b(%rip), %rdi     # 0x10b1a7
cmoveq %rax, %rdi
movl $0xd5, %esi
callq 0x576d4
leaq 0xa7e02(%rip), %rdi     # 0x10b1b3
jmp 0x63505
cmpl $0x2, %ebx
je 0x63519
cmpl $0x82, %ebx
jne 0x634d1
leaq 0xa7e40(%rip), %rdi     # 0x10b212
jmp 0x63520
leaq 0x294945(%rip), %r14    # 0x2f7d23
movb (%r14), %r15b
movb %bl, (%r14)
leaq 0x294936(%rip), %rax    # 0x2f7d21
movzbl (%rax), %edi
leaq 0x294923(%rip), %rax    # 0x2f7d18
movzbl (%rax), %esi
leaq 0x2949c9(%rip), %rax    # 0x2f7dc8
jmp 0x63429
leaq 0x29491b(%rip), %r14    # 0x2f7d23
movb (%r14), %r15b
movb %bl, (%r14)
leaq 0x29490c(%rip), %rax    # 0x2f7d21
movzbl (%rax), %edi
leaq 0x2948f9(%rip), %rax    # 0x2f7d18
movzbl (%rax), %esi
leaq 0x294997(%rip), %rax    # 0x2f7dc0
movsd (%rax), %xmm0
leaq 0x2949a4(%rip), %rax    # 0x2f7dd8
movsd (%rax), %xmm1
leaq 0x2948dd(%rip), %rax    # 0x2f7d1c
movss (%rax), %xmm2
pushq $0xa
popq %rdx
callq 0x61e97
movb %r15b, (%r14)
leaq 0x293e7b(%rip), %rax    # 0x2f72d0
movl $0x1, (%rax)
jmp 0x634d1
leaq 0x917e9(%rip), %rdi     # 0xf4c4d
callq 0x59a28
xorl %edi, %edi
cmpl $0x82, %ebx
sete %dil
callq 0x523f2
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x59aab
cmpl $0x82, %ebx
leaq 0xa7d4c(%rip), %rax     # 0x10b1e2
leaq 0xa7d56(%rip), %rdi     # 0x10b1f3
cmoveq %rax, %rdi
pushq $0x64
popq %rbx
movl %ebx, %esi
callq 0x576d4
leaq 0xa7d52(%rip), %rdi     # 0x10b204
movl %ebx, %esi
jmp 0x6350a
leaq 0x1a1b17(%rip), %rax    # 0x204fd4
movl (%rax), %eax
addl $-0x33, %eax
cmpl $0x1d, %eax
ja 0x6352f
movl $0x20000009, %ecx       # imm = 0x20000009
btl %eax, %ecx
jae 0x6352f
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x82, %ebx
leaq 0xa7cd4(%rip), %rax     # 0x10b1bd
leaq 0xa7cda(%rip), %rdi     # 0x10b1ca
cmoveq %rax, %rdi
movl $0xd5, %esi
callq 0x576d4
leaq 0xa7cd2(%rip), %rdi     # 0x10b1d7
movl $0xd5, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x576d4
leaq 0xa7cfa(%rip), %rdi     # 0x10b21a
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x579af
movl $0x8e, %edi
callq 0x5707f
pushq $0x4e
popq %rdi
callq 0x523f2
andl $0xfe, %ebx
movl %ebx, %edi
callq 0x523f2
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x570f8