// File: /workspace/github_cpp_makefile_star2_O3/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 0x2cac62(%rip), %rax    # 0x33701a
leaq 0x1d2b7f(%rip), %rcx    # 0x23ef3e
movb (%rcx), %cl
orb (%rax), %cl
jne 0x6c646
movl %edi, %ebx
leaq 0x1ac4fe(%rip), %rax    # 0x2188d0
movq (%rax), %rax
cmpq $0xfff, %rax            # imm = 0xFFF
jg 0x6c428
cmpq $0x7, %rax
jg 0x6c4bf
cmpq $0x1, %rax
je 0x6c57a
cmpq $0x4, %rax
jne 0x6c646
leaq 0x2a1921(%rip), %r14    # 0x30dd23
movb (%r14), %r15b
movb %bl, (%r14)
leaq 0x2a1912(%rip), %rax    # 0x30dd21
movzbl (%rax), %edi
leaq 0x2a18ff(%rip), %rax    # 0x30dd18
movzbl (%rax), %esi
leaq 0x2a199d(%rip), %rax    # 0x30ddc0
jmp 0x6c541
cmpq $0xfffff, %rax          # imm = 0xFFFFF
jg 0x6c4ff
cmpq $0x1000, %rax           # imm = 0x1000
je 0x6c5c9
cmpq $0x40000, %rax          # imm = 0x40000
jne 0x6c646
cmpl $0x83, %ebx
leaq 0xb4da1(%rip), %rax     # 0x1211fa
leaq 0xb4daa(%rip), %rcx     # 0x12120a
cmoveq %rax, %rcx
leaq 0xb4dc4(%rip), %rax     # 0x12122f
leaq 0xb4dce(%rip), %rdx     # 0x121240
cmoveq %rax, %rdx
cmpl $0x82, %ebx
leaq 0xb4d65(%rip), %rax     # 0x1211e8
cmovneq %rcx, %rax
leaq 0x2cf9ca(%rip), %rcx    # 0x33be58
leaq 0xb4d87(%rip), %rsi     # 0x12121c
cmovneq %rdx, %rsi
movl (%rcx), %edx
testl %edx, %edx
cmovsq %rax, %rsi
leaq 0x2cfd78(%rip), %rbx    # 0x33c220
movq %rbx, %rdi
xorl %eax, %eax
callq 0x9060
movq %rbx, %rdi
movl $0x191, %esi            # imm = 0x191
jmp 0x6c67f
cmpq $0x8, %rax
je 0x6c600
cmpq $0x20, %rax
jne 0x6c646
leaq 0x9e6f8(%rip), %rdi     # 0x10abd2
callq 0x6160d
xorl %edi, %edi
cmpl $0x82, %ebx
sete %dil
callq 0x590f7
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x61688
cmpq $0x100000, %rax         # imm = 0x100000
je 0x6c630
movl $0x80000000, %ecx       # imm = 0x80000000
cmpq %rcx, %rax
jne 0x6c646
leaq 0x2a1803(%rip), %r14    # 0x30dd23
movb (%r14), %r15b
movb %bl, (%r14)
leaq 0x2a17f4(%rip), %rax    # 0x30dd21
movzbl (%rax), %edi
leaq 0x2a17e1(%rip), %rax    # 0x30dd18
movzbl (%rax), %esi
leaq 0x2a1887(%rip), %rax    # 0x30ddc8
movsd (%rax), %xmm0
leaq 0x2a188c(%rip), %rax    # 0x30ddd8
movsd (%rax), %xmm1
leaq 0x2a17c5(%rip), %rax    # 0x30dd1c
movss (%rax), %xmm2
movl $0xa, %edx
callq 0x6add8
movb %r15b, (%r14)
leaq 0x2a0d61(%rip), %rax    # 0x30d2d0
movl $0x1, (%rax)
jmp 0x6c646
leaq 0x1aea53(%rip), %rax    # 0x21afd4
movl (%rax), %eax
addl $-0x33, %eax
cmpl $0x1d, %eax
ja 0x6c599
movl $0x20000009, %ecx       # imm = 0x20000009
btl %eax, %ecx
jb 0x6c646
movl $0x8e, %edi
callq 0x5e6be
movl $0x4e, %edi
callq 0x590f7
andl $0xfe, %ebx
movl %ebx, %edi
callq 0x590f7
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x5e73c
leaq 0x1aea18(%rip), %rax    # 0x21afe8
cmpl $0x4f, (%rax)
jne 0x6c651
cmpl $0x82, %ebx
leaq 0xb4c71(%rip), %rax     # 0x121253
leaq 0xb4c76(%rip), %rdi     # 0x12125f
cmoveq %rax, %rdi
movl $0xd5, %esi
callq 0x5edda
leaq 0xb4c6d(%rip), %rdi     # 0x12126b
jmp 0x6c67a
cmpl $0x82, %ebx
leaq 0xb4c8d(%rip), %rax     # 0x12129a
leaq 0xb4c97(%rip), %rdi     # 0x1212ab
cmoveq %rax, %rdi
movl $0x64, %esi
callq 0x5edda
leaq 0xb4c93(%rip), %rdi     # 0x1212bc
movl $0x64, %esi
jmp 0x6c67f
cmpl $0x2, %ebx
je 0x6c68e
cmpl $0x82, %ebx
jne 0x6c646
leaq 0xb4c86(%rip), %rdi     # 0x1212ca
jmp 0x6c695
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x82, %ebx
leaq 0xb4c17(%rip), %rax     # 0x121275
leaq 0xb4c1d(%rip), %rdi     # 0x121282
cmoveq %rax, %rdi
movl $0xd5, %esi
callq 0x5edda
leaq 0xb4c15(%rip), %rdi     # 0x12128f
movl $0xd5, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x5edda
leaq 0xb4c3d(%rip), %rdi     # 0x1212d2
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x5f0e5