// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathgps.cpp
// Function: set_discipline_mode(unsigned char)
void set_discipline_mode(u08 mode)
{
   if(read_only) return;
   if(luxor) return;

   // mode 0: jam sync
   // mode 1: enter recovery
   // mode 2: manual holdover
   // mode 3: exit manual holdover
   // mode 4: disable disciplining
   // mode 5: enable disciplining

   if(rcvr_type == CS_RCVR) {
      set_cs_remote(1);
      if     (mode == SET_DIS_MODE_DISABLE) queue_cs_cmd(":PTIM:STAN 0", CS_STANDBY_MSG);
      else if(mode == SET_DIS_MODE_ENABLE)  queue_cs_cmd(":PTIM:STAN 1", CS_STANDBY_MSG);
      restore_cs_remote();
      queue_cs_cmd(":PTIM:STAN?", CS_STANDBY_MSG);
   }
   else if(rcvr_type == PRS_RCVR) {
      // !!!!! LO command does not respond with "OK" in verbose mode... use -PRS_LO_MSG kludge
      if     (mode == SET_DIS_MODE_HOLDOVER) queue_prs_cmd("LO0", -PRS_LO_MSG);
      else if(mode == SET_DIS_MODE_DISABLE)  queue_prs_cmd("LO0", -PRS_LO_MSG);
      else if(mode == SET_DIS_MODE_NORMAL)   queue_prs_cmd("LO1", -PRS_LO_MSG);
      else if(mode == SET_DIS_MODE_ENABLE)   queue_prs_cmd("LO1", -PRS_LO_MSG);
      queue_prs_cmd("LO?", PRS_LO_MSG);
      queue_prs_cmd("ST?", PRS_ST_MSG);
   }
   else if(rcvr_type == SRO_RCVR) {
      if(mode == SET_DIS_MODE_JAMSYNC) {      // sync now
         set_sro_sy(1);
      }
      else if(mode == SET_DIS_MODE_DISABLE) { // free run
         set_sro_tr(0);
      }
      else if(mode == SET_DIS_MODE_ENABLE) {  // track now+always
         set_sro_tr(3);
      }
   }
   else if(rcvr_type == STAR_RCVR) {
      if(star_type == OSA_TYPE) {
         if     (mode == SET_DIS_MODE_HOLDOVER) queue_star_cmd("MODE=HOLDOVER", STAR_HOLD_MSG);
         else if(mode == SET_DIS_MODE_NORMAL)   queue_star_cmd("MODE=AUTOMATIC", STAR_HOLD_MSG);
      }
      else {
         if     (mode == SET_DIS_MODE_HOLDOVER) queue_star_cmd("MODE=H;", STAR_HOLD_MSG);
         else if(mode == SET_DIS_MODE_NORMAL)   queue_star_cmd("MODE=A;", STAR_HOLD_MSG);
      }
      request_rcvr_config(8855);
   }
   else if(rcvr_type == SCPI_RCVR) {  // 2=exit holdover  3=force holdover
      z_rcvr:
if(debug_file) fprintf(debug_file, "set_dmode(%d)\n", mode);
      extend_com_timeout(0.0);
      if(scpi_type == NORTEL_TYPE) {
         if     (mode == SET_DIS_MODE_NORMAL)   queue_scpi_cmd("ROSC:HOLD:REC:INIT", SCPI_HOLDOVER_MSG);
         else if(mode == SET_DIS_MODE_HOLDOVER) queue_scpi_cmd("ROSC:HOLD:INIT", SCPI_HOLDOVER_MSG);
         else if(mode == SET_DIS_MODE_JAMSYNC)  queue_scpi_cmd("SYNC:IMMEDIATE", SCPI_JAMSYNC_MSG);
         queue_scpi_cmd("ROSC:HOLD:DUR?", SCPI_HOLDOVER_MSG);
      }
      else {
         if     (mode == SET_DIS_MODE_NORMAL)   queue_scpi_cmd(":SYNC:HOLD:REC:INIT", SCPI_HOLDOVER_MSG);
         else if(mode == SET_DIS_MODE_HOLDOVER) queue_scpi_cmd(":SYNC:HOLD:INIT", SCPI_HOLDOVER_MSG);
         else if(mode == SET_DIS_MODE_JAMSYNC)  queue_scpi_cmd(":SYNC:IMM", SCPI_JAMSYNC_MSG);
         queue_scpi_cmd(":ROSC:HOLD:DUR?", SCPI_HOLDOVER_MSG);
      }
   }
   else if(rcvr_type == UCCM_RCVR) { 
      if(scpi_type == UCCMP_TYPE) goto z_rcvr;
      else if(scpi_type == SAMSUNG_TYPE) {  // samsung
         if     (mode == SET_DIS_MODE_NORMAL)   queue_scpi_cmd("SYNC:HOLD:REC:INIT", SCPI_HOLDOVER_MSG);
         else if(mode == SET_DIS_MODE_HOLDOVER) queue_scpi_cmd("SYNC:HOLD:INIT", SCPI_HOLDOVER_MSG);
         else if(mode == SET_DIS_MODE_DISABLE)  queue_scpi_cmd("SYNC:HOLD:INIT", SCPI_HOLDOVER_MSG);
         else if(mode == SET_DIS_MODE_ENABLE)   queue_scpi_cmd("SYNC:HOLD:REC:INIT", SCPI_HOLDOVER_MSG);
      }
      else if((mode == SET_DIS_MODE_HOLDOVER) || (mode == SET_DIS_MODE_DISABLE)) {  // disable disciplining at current EFC
         set_dac_voltage(uccm_voltage, 20);
      }
      else if((mode == SET_DIS_MODE_RECOVER) || (mode == SET_DIS_MODE_NORMAL) || (mode == SET_DIS_MODE_ENABLE)) {  // enable disciplining
         queue_uccm_cmd("DIAG:ROSC:EFC:DATA GPS", UCCM_SETDAC_MSG);
         queue_uccm_cmd("DIAG:ROSC:EFC:DATA?", UCCM_EFC_MSG);
         discipline_mode = DIS_MODE_RECOVERY;  // recovery
      }
   }
   else if(rcvr_type == TSIP_RCVR) {
      if(ACU_GG) return;
      if(ACU_360) return;
      if(ACUTIME) return;
      if(PALISADE) return;
      if(SV6_FAMILY) return;
      send_tsip_start(0x8E);
      send_byte(0xA3);
      send_byte(mode);
      send_tsip_end();
   }
   else if(rcvr_type == X72_RCVR) {
      if     (mode == SET_DIS_MODE_HOLDOVER) set_x72_discipline(0);
      else if(mode == SET_DIS_MODE_DISABLE)  set_x72_discipline(0);
      else if(mode == SET_DIS_MODE_NORMAL)   set_x72_discipline(1);
      else if(mode == SET_DIS_MODE_ENABLE)   set_x72_discipline(1);
      else if(mode == SET_DIS_MODE_JAMSYNC) {
         update_x72_tic(x72_pps, 4);
      }
   }

   if(mode == SET_DIS_MODE_JAMSYNC) {
      osc_integral = 0.0;
      have_osc = 0;
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
leaq 0x2c9a09(%rip), %rax    # 0x33701a
leaq 0x1d1926(%rip), %rcx    # 0x23ef3e
movb (%rcx), %cl
orb (%rax), %cl
jne 0x6da06
movl %edi, %ebx
leaq 0x1ab2a5(%rip), %rax    # 0x2188d0
movq (%rax), %rax
cmpq $0x1ffff, %rax          # imm = 0x1FFFF
jg 0x6d697
cmpq $0xf, %rax
jg 0x6d6ff
cmpq $0x1, %rax
je 0x6d7eb
cmpq $0x8, %rax
jne 0x6d9e7
leaq 0x1ad985(%rip), %rax    # 0x21afe0
movl (%rax), %eax
cmpl $0x50, %eax
je 0x6d78a
cmpl $0x53, %eax
jne 0x6d90a
cmpb $0x5, %bl
ja 0x6da06
movzbl %bl, %eax
leaq 0xb150a(%rip), %rcx     # 0x11eb8c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xb365d(%rip), %rdi     # 0x120cef
jmp 0x6da59
cmpq $0x1ffffff, %rax        # imm = 0x1FFFFFF
jg 0x6d746
cmpq $0x20000, %rax          # imm = 0x20000
je 0x6d830
cmpq $0x1000000, %rax        # imm = 0x1000000
jne 0x6d9e7
leal -0x2(%rbx), %eax
cmpb $0x3, %al
ja 0x6d6dd
movzbl %al, %eax
leaq 0xb2940(%rip), %rcx     # 0x12000c
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
movl $0xfffffe05, %esi       # imm = 0xFFFFFE05
callq 0x5edda
leaq 0xb3d8d(%rip), %rdi     # 0x121471
movl $0x1fb, %esi            # imm = 0x1FB
callq 0x5edda
leaq 0xb8283(%rip), %rdi     # 0x125978
movl $0x1f9, %esi            # imm = 0x1F9
jmp 0x6d9bc
cmpq $0x10, %rax
je 0x6d78a
cmpq $0x1000, %rax           # imm = 0x1000
jne 0x6d9e7
leaq 0x1ad8cc(%rip), %rax    # 0x21afe8
cmpl $0x4f, (%rax)
jne 0x6d8a4
cmpb $0x2, %bl
je 0x6d9c3
movzbl %bl, %eax
cmpl $0x3, %eax
jne 0x6d9dd
leaq 0xb3d42(%rip), %rdi     # 0x121483
jmp 0x6d9d3
cmpq $0x2000000, %rax        # imm = 0x2000000
je 0x6d858
cmpq $0x8000000, %rax        # imm = 0x8000000
jne 0x6d9e7
cmpb $0x5, %bl
je 0x6d959
movzbl %bl, %eax
cmpl $0x4, %eax
je 0x6d955
testl %eax, %eax
jne 0x6da06
movl $0x1, %edi
callq 0x6da69
jmp 0x6d9eb
leaq 0x1d0bff(%rip), %rax    # 0x23e390
movq (%rax), %rdi
testq %rdi, %rdi
je 0x6d7aa
movzbl %bl, %edx
leaq 0xb3cff(%rip), %rsi     # 0x1214a2
xorl %eax, %eax
callq 0x9560
xorps %xmm0, %xmm0
callq 0x63ce2
leaq 0x1ad827(%rip), %rax    # 0x21afe0
cmpl $0x4e, (%rax)
jne 0x6d87b
testb %bl, %bl
je 0x6d985
movzbl %bl, %eax
cmpl $0x2, %eax
je 0x6d969
cmpl $0x3, %eax
jne 0x6d996
leaq 0xb3ccb(%rip), %rdi     # 0x1214b1
jmp 0x6d970
leaq 0x1ad7e2(%rip), %rax    # 0x21afd4
movl (%rax), %eax
addl $-0x33, %eax
cmpl $0x1d, %eax
ja 0x6d80a
movl $0x20004009, %ecx       # imm = 0x20004009
btl %eax, %ecx
jb 0x6da06
movl $0x8e, %edi
callq 0x5e6be
movl $0xa3, %edi
callq 0x590f7
movzbl %bl, %edi
callq 0x590f7
callq 0x5e73c
jmp 0x6d9e7
movl $0x1, %edi
callq 0x63e3b
cmpb $0x4, %bl
je 0x6d8c5
movzbl %bl, %eax
cmpl $0x5, %eax
jne 0x6d8d6
leaq 0xb30a2(%rip), %rdi     # 0x1208f8
jmp 0x6d8cc
cmpb $0x5, %bl
ja 0x6da06
movzbl %bl, %eax
leaq 0xb1309(%rip), %rcx     # 0x11eb74
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorl %edi, %edi
jmp 0x6d8ff
testb %bl, %bl
je 0x6d99f
movzbl %bl, %eax
cmpl $0x2, %eax
je 0x6d977
cmpl $0x3, %eax
jne 0x6d9b0
leaq 0xb344f(%rip), %rdi     # 0x120cee
jmp 0x6d97e
cmpb $0x2, %bl
je 0x6d9cc
movzbl %bl, %eax
cmpl $0x3, %eax
jne 0x6d9dd
leaq 0xb3bda(%rip), %rdi     # 0x12149a
jmp 0x6d9d3
leaq 0xb3b84(%rip), %rdi     # 0x121450
movl $0x143, %esi            # imm = 0x143
callq 0x5edda
leaq 0x1ad10f(%rip), %rax    # 0x21a9ec
cmpl $0x0, (%rax)
jne 0x6d8e9
xorl %edi, %edi
callq 0x63e3b
leaq 0xb3b6d(%rip), %rdi     # 0x12145d
movl $0x143, %esi            # imm = 0x143
jmp 0x6d9bc
movl $0x1, %edi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x6db23
cmpb $0x5, %bl
ja 0x6da06
movzbl %bl, %eax
movl $0x2a, %ecx
btl %eax, %ecx
jae 0x6da2d
leaq 0xb3bd2(%rip), %rdi     # 0x1214fd
movl $0x68, %esi
callq 0x5edda
leaq 0xb3a40(%rip), %rdi     # 0x12137c
movl $0x67, %esi
callq 0x5edda
leaq 0x29fb4a(%rip), %rax    # 0x30d497
movb $0x4, (%rax)
jmp 0x6da06
xorl %edi, %edi
jmp 0x6d95e
movl $0x3, %edi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x6dac6
leaq 0xb3b54(%rip), %rdi     # 0x1214c4
movl $0x16, %esi
jmp 0x6d991
leaq 0xb3b55(%rip), %rdi     # 0x1214d3
movl $0x16, %esi
jmp 0x6d9ab
leaq 0xb32e6(%rip), %rdi     # 0x120c72
movl $0x21, %esi
callq 0x5edda
leaq 0xb3b51(%rip), %rdi     # 0x1214ee
jmp 0x6d9b7
leaq 0xb3b3d(%rip), %rdi     # 0x1214e3
movl $0x21, %esi
callq 0x5edda
leaq 0xb3b36(%rip), %rdi     # 0x1214ed
movl $0x16, %esi
callq 0x5edda
jmp 0x6d9e7
leaq 0xb3aab(%rip), %rdi     # 0x121475
jmp 0x6d9d3
leaq 0xb3abf(%rip), %rdi     # 0x121492
movl $0xfc, %esi
callq 0x5edda
movl $0x2297, %edi           # imm = 0x2297
callq 0x667f2
testb %bl, %bl
jne 0x6da06
leaq 0x1ad81e(%rip), %rax    # 0x21b210
movq $0x0, (%rax)
leaq 0x1d14e4(%rip), %rax    # 0x23eee4
movl $0x0, (%rax)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
leaq 0x1ad3e8(%rip), %rax    # 0x21adfc
movl (%rax), %edi
incl 0x30c324(%rip)          # 0x379d40
callq 0x8fbce
movl $0x0, 0x308c31(%rip)    # 0x37665c
jmp 0x6d9eb
movl $0x14, %ecx
btl %eax, %ecx
jae 0x6d9eb
leaq 0x29efca(%rip), %rax    # 0x30ca08
movsd (%rax), %xmm0
movl $0x14, %edi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x6ce5e
leaq 0xb3a7b(%rip), %rdi     # 0x1214d4
movl $0x16, %esi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x5edda