// File: /workspace/github_cpp_makefile_star2_O1/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 0x2ca98e(%rip), %rax    # 0x33701a
leaq 0x1d28ab(%rip), %rcx    # 0x23ef3e
movb (%rcx), %cl
orb (%rax), %cl
jne 0x6cbe5
movl %esi, %r14d
movl %edi, %ebx
movl $0x64, %edi
callq 0xfaae1
leaq 0x1ac21d(%rip), %rax    # 0x2188d0
movq (%rax), %rax
cmpq $0xff, %rax
jle 0x6c773
cmpq $0x1fffff, %rax         # imm = 0x1FFFFF
jle 0x6c822
cmpq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
jg 0x6c8a7
cmpq $0x200000, %rax         # imm = 0x200000
je 0x6c8f3
cmpq $0x20000000, %rax       # imm = 0x20000000
jne 0x6cb07
leaq 0x2a177f(%rip), %rcx    # 0x30de78
movq (%rcx), %rax
cmpq $0x31, %rax
jl 0x6c736
addq $0xe0f, %rax            # imm = 0xE0F
shrq $0x4, %rax
movabsq $0x91a2b3c4d5e6f81, %rdx # imm = 0x91A2B3C4D5E6F81
mulq %rdx
shrq $0x3, %rdx
cmpl $0x30, %edx
movl $0x30, %eax
cmovll %edx, %eax
cmpl $0x2, %eax
movl $0x1, %edx
cmovgel %eax, %edx
movq %rdx, (%rcx)
movq (%rcx), %rdx
leaq 0x2a1730(%rip), %rax    # 0x30de70
movl %edx, (%rax)
leaq 0x2cfad7(%rip), %r14    # 0x33c220
leaq 0xb514a(%rip), %rsi     # 0x12189a
movq %r14, %rdi
xorl %eax, %eax
callq 0x9060
movq %r14, %rdi
callq 0x5f070
leaq 0xb4288(%rip), %rdi     # 0x1209f1
callq 0x5f070
jmp 0x6cb07
cmpq $0xf, %rax
jg 0x6c857
cmpq $0x1, %rax
je 0x6c97c
cmpq $0x4, %rax
je 0x6ca1c
cmpq $0x8, %rax
jne 0x6cb07
leaq 0x1ae83e(%rip), %rax    # 0x21afe0
cmpl $0x50, (%rax)
jne 0x6cae5
leaq 0xb512e(%rip), %rdi     # 0x1218e0
movl $0x13, %esi
callq 0x5ee52
leaq 0x1d1bcd(%rip), %r15    # 0x23e390
movq (%r15), %rdi
testq %rdi, %rdi
je 0x6c7ee
leaq 0x2a16a6(%rip), %rax    # 0x30de78
movq (%rax), %rcx
leaq 0xb511b(%rip), %rsi     # 0x1218f7
movl %r14d, %edx
xorl %eax, %eax
callq 0x9560
movq (%r15), %rdi
callq 0x9420
leaq 0x2a1683(%rip), %rax    # 0x30de78
xorl %ecx, %ecx
movq %rcx, (%rax)
leaq 0x2a167f(%rip), %rax    # 0x30de80
movq %rcx, (%rax)
leaq 0x2a167d(%rip), %rax    # 0x30de88
movl $0xfffffff4, (%rax)     # imm = 0xFFFFFFF4
leaq 0xb4e2d(%rip), %rdi     # 0x121645
movl $0x13, %esi
jmp 0x6cb02
cmpq $0x100, %rax            # imm = 0x100
je 0x6c933
cmpq $0x800, %rax            # imm = 0x800
je 0x6c957
cmpq $0x100000, %rax         # imm = 0x100000
jne 0x6cb07
leaq 0xb50e6(%rip), %rdi     # 0x121933
callq 0x5f15d
jmp 0x6cb07
cmpq $0x10, %rax
je 0x6c9e8
cmpq $0x20, %rax
je 0x6ca4c
cmpq $0x80, %rax
jne 0x6cb07
leaq 0x2a0752(%rip), %rax    # 0x30cfd0
movsd (%rax), %xmm0
leaq 0x2a074f(%rip), %rax    # 0x30cfd8
movsd (%rax), %xmm1
leaq 0x2a074c(%rip), %rax    # 0x30cfe0
movsd (%rax), %xmm2
movl $0x1, %edi
callq 0x66bf6
jmp 0x6cb07
movabsq $0x400000000, %rcx      # imm = 0x400000000
cmpq %rcx, %rax
je 0x6c922
movl $0x80000000, %ecx       # imm = 0x80000000
cmpq %rcx, %rax
jne 0x6cb07
leaq 0x2a15ad(%rip), %rax    # 0x30de78
movq (%rax), %rdx
leaq 0x2cf94b(%rip), %r14    # 0x33c220
leaq 0xb4fa7(%rip), %rsi     # 0x121883
movq %r14, %rdi
xorl %eax, %eax
callq 0x9060
movq %r14, %rdi
callq 0x5ef13
jmp 0x6cb07
leaq 0x2a157e(%rip), %rax    # 0x30de78
movq (%rax), %rdx
leaq 0x2cf91c(%rip), %r14    # 0x33c220
leaq 0xb501b(%rip), %rsi     # 0x121926
movq %r14, %rdi
xorl %eax, %eax
callq 0x9060
movq %r14, %rdi
callq 0x5f2a0
jmp 0x6cb07
leaq 0xb4ff7(%rip), %rdi     # 0x121920
callq 0x5f1e8
jmp 0x6cb07
leaq 0x1ae78a(%rip), %rax    # 0x21b0c4
movl (%rax), %esi
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
movl $0x3, %edi
callq 0x683cd
jmp 0x6cb07
movl $0x1d, %edi
callq 0x5e740
xorl %edi, %edi
callq 0x591af
movl $0x2, %edi
callq 0x591af
callq 0x5e844
jmp 0x6cb07
leaq 0x1ae651(%rip), %rcx    # 0x21afd4
movl (%rcx), %ecx
movl %ecx, %esi
xorl $0x41, %esi
leaq 0x1abf67(%rip), %rdx    # 0x2188f8
movl (%rdx), %edx
movl %edx, %edi
xorl $0x47, %edi
orl %esi, %edi
je 0x6c9c2
cmpl $0x41, %ecx
jne 0x6c9ab
cmpl $0x33, %edx
je 0x6c9c2
cmpl $0x47, %edx
je 0x6c9c2
cmpl $0x41, %ecx
sete %dl
cmpq $0x1, %rax
sete %sil
testb %dl, %sil
je 0x6cbae
movl $0x8e, %edi
callq 0x5e740
movl $0xa6, %edi
callq 0x591af
movzbl %bl, %edi
callq 0x591af
callq 0x5e7c0
jmp 0x6cb07
xorpd %xmm0, %xmm0
callq 0x63c5c
leaq 0x1ae5e8(%rip), %rax    # 0x21afe0
cmpl $0x4e, (%rax)
jne 0x6ca6c
leaq 0xb4ea4(%rip), %rdi     # 0x1218a8
movl $0x13, %esi
callq 0x5ee52
leaq 0xb4eac(%rip), %rdi     # 0x1218c1
movl $0x12, %esi
jmp 0x6ca89
leaq 0x2a05ad(%rip), %rax    # 0x30cfd0
movsd (%rax), %xmm0
leaq 0x2a05aa(%rip), %rax    # 0x30cfd8
movsd (%rax), %xmm1
leaq 0x2a05a7(%rip), %rax    # 0x30cfe0
movsd (%rax), %xmm2
movl $0x1, %edi
callq 0x6811b
jmp 0x6cb07
leaq 0xb439f(%rip), %rdi     # 0x120df2
callq 0x61694
movl $0x3, %edi
callq 0x591af
callq 0x6170f
jmp 0x6cb07
leaq 0xb4e67(%rip), %rdi     # 0x1218da
movl $0x13, %esi
callq 0x5ee52
leaq 0xb4bbc(%rip), %rdi     # 0x121640
movl $0x13, %esi
callq 0x5ee52
leaq 0x1d18fb(%rip), %r15    # 0x23e390
movq (%r15), %rdi
testq %rdi, %rdi
je 0x6cac0
leaq 0x2a13d4(%rip), %rax    # 0x30de78
movq (%rax), %rcx
leaq 0xb4e49(%rip), %rsi     # 0x1218f7
movl %r14d, %edx
xorl %eax, %eax
callq 0x9560
movq (%r15), %rdi
callq 0x9420
leaq 0x2a13b1(%rip), %rax    # 0x30de78
xorl %ecx, %ecx
movq %rcx, (%rax)
leaq 0x2a13ad(%rip), %rax    # 0x30de80
movq %rcx, (%rax)
leaq 0x2a13ab(%rip), %rax    # 0x30de88
movl $0xfffffff5, (%rax)     # imm = 0xFFFFFFF5
jmp 0x6cb07
leaq 0xb3c74(%rip), %rdi     # 0x120760
movl $0x14, %esi
callq 0x5ee52
leaq 0xb75b1(%rip), %rdi     # 0x1240ae
movl $0x65, %esi
callq 0x5ee52
testb %bl, %bl
jne 0x6cb15
leaq 0x2a138f(%rip), %rax    # 0x30dea1
movb $0x1, (%rax)
leaq 0x2a1380(%rip), %rax    # 0x30de9c
cmpl $0x0, (%rax)
jne 0x6cb9f
leaq 0x2a1370(%rip), %rax    # 0x30de98
cmpb $0x0, (%rax)
jne 0x6cb9f
leaq 0x2a049c(%rip), %rax    # 0x30cfd0
movsd (%rax), %xmm0
xorpd %xmm3, %xmm3
ucomisd %xmm3, %xmm0
leaq 0x2a0491(%rip), %rax    # 0x30cfd8
movsd (%rax), %xmm1
leaq 0x2a048e(%rip), %rax    # 0x30cfe0
movsd (%rax), %xmm2
jne 0x6cb6a
jp 0x6cb6a
ucomisd %xmm3, %xmm1
jne 0x6cb6a
jp 0x6cb6a
ucomisd %xmm3, %xmm2
jne 0x6cb6a
jnp 0x6cb9f
leaq 0x2ce77f(%rip), %rax    # 0x33b2f0
movsd %xmm0, (%rax)
leaq 0x2ce77c(%rip), %rax    # 0x33b2f8
movsd %xmm1, (%rax)
leaq 0x2ce779(%rip), %rax    # 0x33b300
movsd %xmm2, (%rax)
leaq 0x2ce776(%rip), %rax    # 0x33b308
movl $0xfffffffe, (%rax)     # imm = 0xFFFFFFFE
xorl %edi, %edi
callq 0xfa6ba
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x712d5
cmpq $0x1, %rax
sete %dl
cmpl $0x50, %ecx
sete %sil
testb %sil, %dl
jne 0x6cbe5
cmpq $0x1, %rax
jne 0x6c9c2
addl $-0x33, %ecx
cmpl $0x1d, %ecx
ja 0x6c9c2
movl $0x20004009, %eax       # imm = 0x20004009
btl %ecx, %eax
jae 0x6c9c2
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq