// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathgps.cpp
// Function: start_self_survey(unsigned char, int)
void start_self_survey(u08 val, int why)
{
int hours;
   // val=0 - start survey
   // val=1 - save position (Tbolt-E)
   // val=2 - delete position (Tbolt-E)
   if(read_only) return;
   if(luxor) return;
stop_precision_survey(100);  // medsurv
if(0 && debug_file) fprintf(debug_file, "start self survey val:%d  why:%d\n", val,why); //plugh

   if(rcvr_type == ESIP_RCVR) { 
      sprintf(out, "PERDAPI,SURVEY,2,0,%ld", do_survey);
      send_esip_cmd(out);
   }
   else if(rcvr_type == FURUNO_RCVR) { 
      hours = do_survey;
      if(do_survey > 48) {  // assume time was in seconds
         hours = (do_survey+3599) / 3600;
         if(hours <= 0) hours = 1;
         else if(hours > 48) hours = 48;
         do_survey = hours;
      }
      survey_length = do_survey;
      sprintf(out, "GPset,Z3%02ld", do_survey);
      send_furuno_cmd(out);
      send_furuno_cmd("GPsrq");
   }
   else if(rcvr_type == MOTO_RCVR) {  //!!! moto_chans
      send_moto_start("Gd");
      send_byte(0x03);
      send_moto_end();
   }
   else if(rcvr_type == NVS_RCVR) {
      send_nvs_start(0x1D);
      send_byte(0x00);
      send_byte(0x02);
      send_nvs_end();
   }
   else if(rcvr_type == SCPI_RCVR) {
      extend_com_timeout(0.0);
      if(scpi_type == NORTEL_TYPE) {
         queue_scpi_cmd("GPS:POS:SURVEY:STAT ONCE", SCPI_SURVEY_MSG);
         queue_scpi_cmd("GPS:POS:SURVEY:PROGRESS?", SCPI_PROGRESS_MSG);
      }
      else {
         queue_scpi_cmd(":PTIM:GPS:POS:SURV:STAT ONCE", SCPI_SURVEY_MSG);
         queue_scpi_cmd(":PTIM:GPS:POS:SURV:STAT?", SCPI_SURVEY_MSG);
      }
if(debug_file) {
   fprintf(debug_file, "### start survey: why=%d  do_survey=%ld\n", why, do_survey);
   fflush(debug_file);
}
do_survey = 0;
do_median_survey = 0; //medsurv
survey_why = (-11);
   }
   else if(rcvr_type == TM4_RCVR) {
      send_tm4_cmd("#07,3");
   }
   else if(rcvr_type == TRUE_RCVR) {
      sprintf(out, "$SURVEY %ld", do_survey);
      send_true_cmd(out);  // $SURVEY %ld - do a self survey for %d hours
   }
   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(0xA6);
      send_byte(val);
      send_tsip_end();
   }
   else if(rcvr_type == UBX_RCVR) {  // zorky
      set_ubx_config(1, lat,lon,alt);  // go to survey mode
   }
   else if(rcvr_type == UCCM_RCVR) {
if(scpi_type == UCCMP_TYPE) {  // kkkkkk
      queue_uccm_cmd("GPS:POS:SURV:STAT ONCE", SCPI_SURVEY_MSG);
if(debug_file) {
   fprintf(debug_file, "### start survey: why=%d  do_survey=%ld\n", why, do_survey);
   fflush(debug_file);
}
do_survey = 0;
do_median_survey = 0;  // medsurv
survey_why = (-12);
      queue_uccm_cmd(":GPS:POS:SURV:STAT?", SCPI_SURVEY_MSG);
}
else {
      queue_uccm_cmd("SYST:PRES", SCPI_RESET_MSG);  // use factory reset to start survey mode
      queue_uccm_cmd("SYST:STAT?", UCCM_STATUS_MSG);
}
   }
   else if(rcvr_type == VENUS_RCVR) { // gggg
      set_venus_survey(1, lat,lon,alt);  // start self survey
   }
   else if(rcvr_type == ZODIAC_RCVR) {
      set_zod_config(3, 0.0,0.0,0.0, traim_threshold, 7);
   }
   else if(rcvr_type == ZYFER_RCVR) {
      send_zyfer_cmd("$TRMO,P");
   }

   if(val == 0) {
      surveying = 1;
   }
// plot_lla = 1;
// show_fixes = 1;
   if(trimble_save) ;
   else if(precision_survey) ;
   else if(lat || lon || alt) { // gggggggg
      precise_lat = lat;
      precise_lon = lon;
      precise_alt = alt;
      have_precise_lla = (-2);

      #ifdef BUFFER_LLA
         clear_lla_points(0);
      #endif
   }
   request_survey_params();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
leaq 0x2ca965(%rip), %rax    # 0x33701a
leaq 0x1d2882(%rip), %rcx    # 0x23ef3e
movb (%rcx), %cl
orb (%rax), %cl
jne 0x6c9c9
movl %esi, %r14d
movl %edi, %ebx
movl $0x64, %edi
callq 0xfb285
leaq 0x1ac1f4(%rip), %rax    # 0x2188d0
movq (%rax), %rax
cmpq $0xff, %rax
jle 0x6c79d
cmpq $0x1fffff, %rax         # imm = 0x1FFFFF
jle 0x6c84c
cmpq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
jg 0x6c8d1
cmpq $0x200000, %rax         # imm = 0x200000
je 0x6c91d
cmpq $0x20000000, %rax       # imm = 0x20000000
jne 0x6caf3
leaq 0x2a1756(%rip), %rcx    # 0x30de78
movq (%rcx), %rdx
cmpq $0x31, %rdx
jl 0x6c763
addq $0xe0f, %rdx            # imm = 0xE0F
shrq $0x4, %rdx
movabsq $0x91a2b3c4d5e6f81, %rsi # imm = 0x91A2B3C4D5E6F81
movq %rdx, %rax
mulq %rsi
shrq $0x3, %rdx
cmpl $0x30, %edx
movl $0x30, %eax
cmovll %edx, %eax
cmpl $0x2, %eax
movl $0x1, %edx
cmovgel %eax, %edx
movq %rdx, (%rcx)
leaq 0x2a1706(%rip), %rax    # 0x30de70
movl %edx, (%rax)
leaq 0x2cfaad(%rip), %r14    # 0x33c220
leaq 0xb5200(%rip), %rsi     # 0x12197a
movq %r14, %rdi
xorl %eax, %eax
callq 0x9060
movq %r14, %rdi
callq 0x5eff8
leaq 0xb433e(%rip), %rdi     # 0x120ad1
callq 0x5eff8
jmp 0x6caf3
cmpq $0xf, %rax
jg 0x6c881
cmpq $0x1, %rax
je 0x6c9a6
cmpq $0x4, %rax
je 0x6ca08
cmpq $0x8, %rax
jne 0x6caf3
leaq 0x1ae814(%rip), %rax    # 0x21afe0
cmpl $0x50, (%rax)
jne 0x6cad1
leaq 0xb51e4(%rip), %rdi     # 0x1219c0
movl $0x13, %esi
callq 0x5edda
leaq 0x1d1ba3(%rip), %r15    # 0x23e390
movq (%r15), %rdi
testq %rdi, %rdi
je 0x6c818
leaq 0x2a167c(%rip), %rax    # 0x30de78
movq (%rax), %rcx
leaq 0xb51d1(%rip), %rsi     # 0x1219d7
movl %r14d, %edx
xorl %eax, %eax
callq 0x9560
movq (%r15), %rdi
callq 0x9420
leaq 0x2a1659(%rip), %rax    # 0x30de78
xorl %ecx, %ecx
movq %rcx, (%rax)
leaq 0x2a1655(%rip), %rax    # 0x30de80
movq %rcx, (%rax)
leaq 0x2a1653(%rip), %rax    # 0x30de88
movl $0xfffffff4, (%rax)     # imm = 0xFFFFFFF4
leaq 0xb4ee3(%rip), %rdi     # 0x121725
movl $0x13, %esi
jmp 0x6caee
cmpq $0x100, %rax            # imm = 0x100
je 0x6c95d
cmpq $0x800, %rax            # imm = 0x800
je 0x6c981
cmpq $0x100000, %rax         # imm = 0x100000
jne 0x6caf3
leaq 0xb519c(%rip), %rdi     # 0x121a13
callq 0x5f0e5
jmp 0x6caf3
cmpq $0x10, %rax
je 0x6c9d4
cmpq $0x20, %rax
je 0x6ca38
cmpq $0x80, %rax
jne 0x6caf3
leaq 0x2a0728(%rip), %rax    # 0x30cfd0
movsd (%rax), %xmm0
leaq 0x2a0725(%rip), %rax    # 0x30cfd8
movsd (%rax), %xmm1
leaq 0x2a0722(%rip), %rax    # 0x30cfe0
movsd (%rax), %xmm2
movl $0x1, %edi
callq 0x66d89
jmp 0x6caf3
movabsq $0x400000000, %rcx      # imm = 0x400000000
cmpq %rcx, %rax
je 0x6c94c
movl $0x80000000, %ecx       # imm = 0x80000000
cmpq %rcx, %rax
jne 0x6caf3
leaq 0x2a1583(%rip), %rax    # 0x30de78
movq (%rax), %rdx
leaq 0x2cf921(%rip), %r14    # 0x33c220
leaq 0xb505d(%rip), %rsi     # 0x121963
movq %r14, %rdi
xorl %eax, %eax
callq 0x9060
movq %r14, %rdi
callq 0x5ee9b
jmp 0x6caf3
leaq 0x2a1554(%rip), %rax    # 0x30de78
movq (%rax), %rdx
leaq 0x2cf8f2(%rip), %r14    # 0x33c220
leaq 0xb50d1(%rip), %rsi     # 0x121a06
movq %r14, %rdi
xorl %eax, %eax
callq 0x9060
movq %r14, %rdi
callq 0x5f228
jmp 0x6caf3
leaq 0xb50ad(%rip), %rdi     # 0x121a00
callq 0x5f170
jmp 0x6caf3
leaq 0x1ae760(%rip), %rax    # 0x21b0c4
movl (%rax), %esi
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
movl $0x3, %edi
callq 0x68563
jmp 0x6caf3
movl $0x1d, %edi
callq 0x5e6be
xorl %edi, %edi
callq 0x590f7
movl $0x2, %edi
callq 0x590f7
callq 0x5e7c0
jmp 0x6caf3
leaq 0x1ae627(%rip), %rax    # 0x21afd4
movl (%rax), %eax
addl $-0x33, %eax
cmpl $0x1d, %eax
ja 0x6cb9a
movl $0x20000009, %ecx       # imm = 0x20000009
btl %eax, %ecx
jae 0x6cb9a
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
xorpd %xmm0, %xmm0
callq 0x63ce2
leaq 0x1ae5fc(%rip), %rax    # 0x21afe0
cmpl $0x4e, (%rax)
jne 0x6ca58
leaq 0xb4f98(%rip), %rdi     # 0x121988
movl $0x13, %esi
callq 0x5edda
leaq 0xb4fa0(%rip), %rdi     # 0x1219a1
movl $0x12, %esi
jmp 0x6ca75
leaq 0x2a05c1(%rip), %rax    # 0x30cfd0
movsd (%rax), %xmm0
leaq 0x2a05be(%rip), %rax    # 0x30cfd8
movsd (%rax), %xmm1
leaq 0x2a05bb(%rip), %rax    # 0x30cfe0
movsd (%rax), %xmm2
movl $0x1, %edi
callq 0x682ae
jmp 0x6caf3
leaq 0xb4493(%rip), %rdi     # 0x120ed2
callq 0x6160d
movl $0x3, %edi
callq 0x590f7
callq 0x61688
jmp 0x6caf3
leaq 0xb4f5b(%rip), %rdi     # 0x1219ba
movl $0x13, %esi
callq 0x5edda
leaq 0xb4cb0(%rip), %rdi     # 0x121720
movl $0x13, %esi
callq 0x5edda
leaq 0x1d190f(%rip), %r15    # 0x23e390
movq (%r15), %rdi
testq %rdi, %rdi
je 0x6caac
leaq 0x2a13e8(%rip), %rax    # 0x30de78
movq (%rax), %rcx
leaq 0xb4f3d(%rip), %rsi     # 0x1219d7
movl %r14d, %edx
xorl %eax, %eax
callq 0x9560
movq (%r15), %rdi
callq 0x9420
leaq 0x2a13c5(%rip), %rax    # 0x30de78
xorl %ecx, %ecx
movq %rcx, (%rax)
leaq 0x2a13c1(%rip), %rax    # 0x30de80
movq %rcx, (%rax)
leaq 0x2a13bf(%rip), %rax    # 0x30de88
movl $0xfffffff5, (%rax)     # imm = 0xFFFFFFF5
jmp 0x6caf3
leaq 0xb3d68(%rip), %rdi     # 0x120840
movl $0x14, %esi
callq 0x5edda
leaq 0xb76a5(%rip), %rdi     # 0x12418e
movl $0x65, %esi
callq 0x5edda
testb %bl, %bl
jne 0x6cb01
leaq 0x2a13a3(%rip), %rax    # 0x30dea1
movb $0x1, (%rax)
leaq 0x2a1394(%rip), %rax    # 0x30de9c
cmpl $0x0, (%rax)
jne 0x6cb8b
leaq 0x2a1384(%rip), %rax    # 0x30de98
cmpb $0x0, (%rax)
jne 0x6cb8b
leaq 0x2a04b0(%rip), %rax    # 0x30cfd0
movsd (%rax), %xmm0
xorpd %xmm3, %xmm3
ucomisd %xmm3, %xmm0
leaq 0x2a04a5(%rip), %rax    # 0x30cfd8
movsd (%rax), %xmm1
leaq 0x2a04a2(%rip), %rax    # 0x30cfe0
movsd (%rax), %xmm2
jne 0x6cb56
jp 0x6cb56
ucomisd %xmm3, %xmm1
jne 0x6cb56
jp 0x6cb56
ucomisd %xmm3, %xmm2
jne 0x6cb56
jnp 0x6cb8b
leaq 0x2ce793(%rip), %rax    # 0x33b2f0
movsd %xmm0, (%rax)
leaq 0x2ce790(%rip), %rax    # 0x33b2f8
movsd %xmm1, (%rax)
leaq 0x2ce78d(%rip), %rax    # 0x33b300
movsd %xmm2, (%rax)
leaq 0x2ce78a(%rip), %rax    # 0x33b308
movl $0xfffffffe, (%rax)     # imm = 0xFFFFFFFE
xorl %edi, %edi
callq 0xfae0d
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x7135e
movl $0x8e, %edi
callq 0x5e6be
movl $0xa6, %edi
callq 0x590f7
movzbl %bl, %edi
callq 0x590f7
callq 0x5e73c
jmp 0x6caf3