// File: /workspace/github_cpp_makefile_star2_O2/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 0x2bdaac(%rip), %rax    # 0x32101a
leaq 0x1c59c9(%rip), %rcx    # 0x228f3e
movb (%rcx), %cl
orb (%rax), %cl
jne 0x63837
movl %esi, %r14d
movl %edi, %ebx
pushq $0x64
popq %rdi
callq 0xe5811
leaq 0x19f33d(%rip), %rax    # 0x2028d0
movq (%rax), %rax
cmpq $0x1, %rax
je 0x63814
cmpq $0x4, %rax
je 0x63711
cmpq $0x8, %rax
je 0x63660
cmpq $0x10, %rax
je 0x63863
cmpq $0x20, %rax
je 0x6373f
cmpq $0x80, %rax
je 0x63893
cmpq $0x100, %rax            # imm = 0x100
je 0x637e1
cmpq $0x800, %rax            # imm = 0x800
je 0x63842
cmpq $0x100000, %rax         # imm = 0x100000
je 0x63803
cmpq $0x200000, %rax         # imm = 0x200000
je 0x636e2
cmpq $0x20000000, %rax       # imm = 0x20000000
je 0x6376e
movabsq $0x400000000, %rcx      # imm = 0x400000000
cmpq %rcx, %rax
je 0x6375d
movl $0x80000000, %ecx       # imm = 0x80000000
cmpq %rcx, %rax
jne 0x63958
leaq 0x294840(%rip), %rax    # 0x2f7e78
movq (%rax), %rdx
leaq 0x2c2bde(%rip), %r14    # 0x326220
leaq 0xa8262(%rip), %rsi     # 0x10b8ab
movq %r14, %rdi
xorl %eax, %eax
callq 0x9060
movq %r14, %rdi
callq 0x57791
jmp 0x63958
leaq 0x1a1979(%rip), %rax    # 0x204fe0
cmpl $0x50, (%rax)
jne 0x638c1
leaq 0xa8291(%rip), %rdi     # 0x10b908
pushq $0x13
popq %rsi
callq 0x576d4
leaq 0x1c4d0a(%rip), %r15    # 0x228390
movq (%r15), %rdi
testq %rdi, %rdi
je 0x636b1
leaq 0x2947e3(%rip), %rax    # 0x2f7e78
movq (%rax), %rcx
leaq 0xa8280(%rip), %rsi     # 0x10b91f
movl %r14d, %edx
xorl %eax, %eax
callq 0x9560
movq (%r15), %rdi
callq 0x9420
leaq 0x2947c0(%rip), %rax    # 0x2f7e78
andq $0x0, (%rax)
leaq 0x2947bd(%rip), %rax    # 0x2f7e80
andq $0x0, (%rax)
leaq 0x2947ba(%rip), %rax    # 0x2f7e88
movl $0xfffffff4, (%rax)     # imm = 0xFFFFFFF4
leaq 0xa7f92(%rip), %rdi     # 0x10b66d
pushq $0x13
jmp 0x638d9
leaq 0x29478f(%rip), %rax    # 0x2f7e78
movq (%rax), %rdx
leaq 0x2c2b2d(%rip), %r14    # 0x326220
leaq 0xa8254(%rip), %rsi     # 0x10b94e
movq %r14, %rdi
xorl %eax, %eax
callq 0x9060
movq %r14, %rdi
callq 0x57acc
jmp 0x63958
leaq 0x2938b8(%rip), %rax    # 0x2f6fd0
movsd (%rax), %xmm0
leaq 0x2938b5(%rip), %rax    # 0x2f6fd8
movsd (%rax), %xmm1
leaq 0x2938b2(%rip), %rax    # 0x2f6fe0
movsd (%rax), %xmm2
pushq $0x1
popq %rdi
callq 0x5f939
jmp 0x63958
leaq 0xa76d4(%rip), %rdi     # 0x10ae1a
callq 0x59a28
pushq $0x3
popq %rdi
callq 0x523f2
callq 0x59aab
jmp 0x63958
leaq 0xa81e4(%rip), %rdi     # 0x10b948
callq 0x57a21
jmp 0x63958
leaq 0x294703(%rip), %rcx    # 0x2f7e78
movq (%rcx), %rdx
cmpq $0x31, %rdx
jl 0x637a7
addq $0xe0f, %rdx            # imm = 0xE0F
movl $0xe10, %esi            # imm = 0xE10
movq %rdx, %rax
xorl %edx, %edx
divq %rsi
cmpl $0x30, %eax
pushq $0x30
popq %rsi
cmovll %eax, %esi
cmpl $0x2, %esi
pushq $0x1
popq %rdx
cmovgel %esi, %edx
movq %rdx, (%rcx)
leaq 0x2946c2(%rip), %rax    # 0x2f7e70
movl %edx, (%rax)
leaq 0x2c2a69(%rip), %r14    # 0x326220
leaq 0xa8104(%rip), %rsi     # 0x10b8c2
movq %r14, %rdi
xorl %eax, %eax
callq 0x9060
movq %r14, %rdi
callq 0x578d5
leaq 0xa7242(%rip), %rdi     # 0x10aa19
callq 0x578d5
jmp 0x63958
leaq 0x1a18dc(%rip), %rax    # 0x2050c4
movl (%rax), %esi
pushq $0x3
popq %rdi
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
callq 0x5faee
jmp 0x63958
leaq 0xa8151(%rip), %rdi     # 0x10b95b
callq 0x579af
jmp 0x63958
leaq 0x1a17b9(%rip), %rax    # 0x204fd4
movl (%rax), %eax
addl $-0x33, %eax
cmpl $0x1d, %eax
ja 0x639ff
movl $0x20000009, %ecx       # imm = 0x20000009
btl %eax, %ecx
jae 0x639ff
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1d
popq %rdi
callq 0x5707f
xorl %edi, %edi
callq 0x523f2
pushq $0x2
popq %rdi
callq 0x523f2
callq 0x57171
jmp 0x63958
xorpd %xmm0, %xmm0
callq 0x5bd83
leaq 0x1a176d(%rip), %rax    # 0x204fe0
cmpl $0x4e, (%rax)
jne 0x638e1
leaq 0xa8051(%rip), %rdi     # 0x10b8d0
pushq $0x13
popq %rsi
callq 0x576d4
leaq 0xa805b(%rip), %rdi     # 0x10b8e9
pushq $0x12
popq %rsi
jmp 0x638fe
leaq 0x293736(%rip), %rax    # 0x2f6fd0
movsd (%rax), %xmm0
leaq 0x293733(%rip), %rax    # 0x2f6fd8
movsd (%rax), %xmm1
leaq 0x293730(%rip), %rax    # 0x2f6fe0
movsd (%rax), %xmm2
pushq $0x1
popq %rdi
callq 0x5e5b2
jmp 0x63958
leaq 0xa6ec0(%rip), %rdi     # 0x10a788
pushq $0x14
popq %rsi
callq 0x576d4
leaq 0xaa7ff(%rip), %rdi     # 0x10e0d6
pushq $0x65
popq %rsi
callq 0x576d4
jmp 0x63958
leaq 0xa801a(%rip), %rdi     # 0x10b902
pushq $0x13
popq %r15
movl %r15d, %esi
callq 0x576d4
leaq 0xa7d6d(%rip), %rdi     # 0x10b668
movl %r15d, %esi
callq 0x576d4
leaq 0x1c4a86(%rip), %r15    # 0x228390
movq (%r15), %rdi
testq %rdi, %rdi
je 0x63935
leaq 0x29455f(%rip), %rax    # 0x2f7e78
movq (%rax), %rcx
leaq 0xa7ffc(%rip), %rsi     # 0x10b91f
movl %r14d, %edx
xorl %eax, %eax
callq 0x9560
movq (%r15), %rdi
callq 0x9420
leaq 0x29453c(%rip), %rax    # 0x2f7e78
andq $0x0, (%rax)
leaq 0x294539(%rip), %rax    # 0x2f7e80
andq $0x0, (%rax)
leaq 0x294536(%rip), %rax    # 0x2f7e88
movl $0xfffffff5, (%rax)     # imm = 0xFFFFFFF5
testb %bl, %bl
jne 0x63966
leaq 0x29453e(%rip), %rax    # 0x2f7ea1
movb $0x1, (%rax)
leaq 0x29452f(%rip), %rax    # 0x2f7e9c
cmpl $0x0, (%rax)
jne 0x639f0
leaq 0x29451f(%rip), %rax    # 0x2f7e98
cmpb $0x0, (%rax)
jne 0x639f0
leaq 0x29364b(%rip), %rax    # 0x2f6fd0
movsd (%rax), %xmm0
xorpd %xmm3, %xmm3
ucomisd %xmm3, %xmm0
leaq 0x293640(%rip), %rax    # 0x2f6fd8
movsd (%rax), %xmm1
leaq 0x29363d(%rip), %rax    # 0x2f6fe0
movsd (%rax), %xmm2
jne 0x639bb
jp 0x639bb
ucomisd %xmm3, %xmm1
jne 0x639bb
jp 0x639bb
ucomisd %xmm3, %xmm2
jne 0x639bb
jnp 0x639f0
leaq 0x2c192e(%rip), %rax    # 0x3252f0
movsd %xmm0, (%rax)
leaq 0x2c192b(%rip), %rax    # 0x3252f8
movsd %xmm1, (%rax)
leaq 0x2c1928(%rip), %rax    # 0x325300
movsd %xmm2, (%rax)
leaq 0x2c1925(%rip), %rax    # 0x325308
movl $0xfffffffe, (%rax)     # imm = 0xFFFFFFFE
xorl %edi, %edi
callq 0xe53f2
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x67b43
movl $0x8e, %edi
callq 0x5707f
movl $0xa6, %edi
callq 0x523f2
movzbl %bl, %edi
callq 0x523f2
callq 0x570f8
jmp 0x63958