// File: 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
subq $0x10, %rsp
movb %dil, %al
movb %al, -0x1(%rbp)
movl %esi, -0x8(%rbp)
leaq 0x302682(%rip), %rax    # 0x3961fa
cmpb $0x0, (%rax)
je 0x93b82
jmp 0x941f3
leaq 0x20a595(%rip), %rax    # 0x29e11e
cmpb $0x0, (%rax)
je 0x93b93
jmp 0x941f3
movl $0x64, %edi
callq 0x15a050
movl $0x80000000, %ecx       # imm = 0x80000000
leaq 0x1e3f07(%rip), %rax    # 0x277ab0
cmpq %rcx, (%rax)
jne 0x93bde
leaq 0x2d94a3(%rip), %rax    # 0x36d058
movq (%rax), %rdx
leaq 0x307841(%rip), %rdi    # 0x39b400
leaq 0xf102d(%rip), %rsi     # 0x184bf3
movb $0x0, %al
callq 0x9060
leaq 0x30782c(%rip), %rdi    # 0x39b400
callq 0x830d0
jmp 0x9411b
leaq 0x1e3ecb(%rip), %rax    # 0x277ab0
cmpq $0x20000000, (%rax)     # imm = 0x20000000
jne 0x93ca6
leaq 0x2d945f(%rip), %rax    # 0x36d058
movq (%rax), %rax
movl %eax, -0xc(%rbp)
leaq 0x2d9452(%rip), %rax    # 0x36d058
cmpq $0x30, (%rax)
jle 0x93c55
leaq 0x2d9445(%rip), %rax    # 0x36d058
movq (%rax), %rax
addq $0xe0f, %rax            # imm = 0xE0F
movl $0xe10, %ecx            # imm = 0xE10
cqto
idivq %rcx
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jg 0x93c38
movl $0x1, -0xc(%rbp)
jmp 0x93c47
cmpl $0x30, -0xc(%rbp)
jle 0x93c45
movl $0x30, -0xc(%rbp)
jmp 0x93c47
movslq -0xc(%rbp), %rcx
leaq 0x2d9406(%rip), %rax    # 0x36d058
movq %rcx, (%rax)
leaq 0x2d93fc(%rip), %rax    # 0x36d058
movq (%rax), %rax
movl %eax, %ecx
leaq 0x2d93e8(%rip), %rax    # 0x36d050
movl %ecx, (%rax)
leaq 0x2d93e7(%rip), %rax    # 0x36d058
movq (%rax), %rdx
leaq 0x307785(%rip), %rdi    # 0x39b400
leaq 0xf0f88(%rip), %rsi     # 0x184c0a
movb $0x0, %al
callq 0x9060
leaq 0x307770(%rip), %rdi    # 0x39b400
callq 0x83270
leaq 0xf00b5(%rip), %rdi     # 0x183d51
callq 0x83270
jmp 0x94119
leaq 0x1e3e03(%rip), %rax    # 0x277ab0
cmpq $0x20, (%rax)
jne 0x93cd3
leaq 0xf0498(%rip), %rdi     # 0x184152
callq 0x86190
movl $0x3, %edi
callq 0x7b210
callq 0x86230
jmp 0x94117
leaq 0x1e3dd6(%rip), %rax    # 0x277ab0
cmpq $0x800, (%rax)          # imm = 0x800
jne 0x93d08
movl $0x1d, %edi
callq 0x824f0
xorl %edi, %edi
callq 0x7b210
movl $0x2, %edi
callq 0x7b210
callq 0x82630
jmp 0x94115
leaq 0x1e3da1(%rip), %rax    # 0x277ab0
cmpq $0x10, (%rax)
jne 0x93de2
xorps %xmm0, %xmm0
callq 0x88f10
leaq 0x1e6498(%rip), %rax    # 0x27a1c0
cmpl $0x4e, (%rax)
jne 0x93d51
leaq 0xf0ee4(%rip), %rdi     # 0x184c18
movl $0x13, %esi
callq 0x82fd0
leaq 0xf0eec(%rip), %rdi     # 0x184c31
movl $0x12, %esi
callq 0x82fd0
jmp 0x93d73
leaq 0xf0ef2(%rip), %rdi     # 0x184c4a
movl $0x13, %esi
callq 0x82fd0
leaq 0xf0c47(%rip), %rdi     # 0x1849b0
movl $0x13, %esi
callq 0x82fd0
leaq 0x2097f6(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0x93db4
leaq 0x2097e9(%rip), %rax    # 0x29d570
movq (%rax), %rdi
movl -0x8(%rbp), %edx
leaq 0x2d92c4(%rip), %rax    # 0x36d058
movq (%rax), %rcx
leaq 0xf0ec9(%rip), %rsi     # 0x184c67
movb $0x0, %al
callq 0x9550
leaq 0x2097c4(%rip), %rax    # 0x29d570
movq (%rax), %rdi
callq 0x9430
leaq 0x2d929d(%rip), %rax    # 0x36d058
movq $0x0, (%rax)
leaq 0x2d9297(%rip), %rax    # 0x36d060
movq $0x0, (%rax)
leaq 0x2d9291(%rip), %rax    # 0x36d068
movl $0xfffffff5, (%rax)     # imm = 0xFFFFFFF5
jmp 0x94113
movabsq $0x400000000, %rcx      # imm = 0x400000000
leaq 0x1e3cbd(%rip), %rax    # 0x277ab0
cmpq %rcx, (%rax)
jne 0x93e09
leaq 0xf0e91(%rip), %rdi     # 0x184c90
callq 0x83490
jmp 0x94111
leaq 0x1e3ca0(%rip), %rax    # 0x277ab0
cmpq $0x200000, (%rax)       # imm = 0x200000
jne 0x93e49
leaq 0x2d9238(%rip), %rax    # 0x36d058
movq (%rax), %rdx
leaq 0x3075d6(%rip), %rdi    # 0x39b400
leaq 0xf0e65(%rip), %rsi     # 0x184c96
movb $0x0, %al
callq 0x9060
leaq 0x3075c1(%rip), %rdi    # 0x39b400
callq 0x83580
jmp 0x9410f
leaq 0x1e3c60(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x93f64
leaq 0x1e3c4f(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x93e84
leaq 0x1e6346(%rip), %rax    # 0x27a1b4
cmpl $0x41, (%rax)
jne 0x93e84
leaq 0x1e3c5e(%rip), %rax    # 0x277ad8
cmpl $0x47, (%rax)
jne 0x93e84
jmp 0x93f3d
leaq 0x1e3c25(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x93eba
leaq 0x1e631c(%rip), %rax    # 0x27a1b4
cmpl $0x41, (%rax)
jne 0x93eba
leaq 0x1e3c34(%rip), %rax    # 0x277ad8
cmpl $0x33, (%rax)
je 0x93eb5
leaq 0x1e3c28(%rip), %rax    # 0x277ad8
cmpl $0x47, (%rax)
jne 0x93eba
jmp 0x93f3b
leaq 0x1e3bef(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x93ed5
leaq 0x1e62e6(%rip), %rax    # 0x27a1b4
cmpl $0x41, (%rax)
jne 0x93ed5
jmp 0x93f39
leaq 0x1e3bd4(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x93ef3
leaq 0x1e62cb(%rip), %rax    # 0x27a1b4
cmpl $0x50, (%rax)
jne 0x93ef3
jmp 0x941f3
leaq 0x1e3bb6(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x93f35
leaq 0x1e62ad(%rip), %rax    # 0x27a1b4
cmpl $0x36, (%rax)
je 0x93f30
leaq 0x1e62a1(%rip), %rax    # 0x27a1b4
cmpl $0x33, (%rax)
je 0x93f30
leaq 0x1e6295(%rip), %rax    # 0x27a1b4
cmpl $0x50, (%rax)
je 0x93f30
leaq 0x1e6289(%rip), %rax    # 0x27a1b4
cmpl $0x41, (%rax)
jne 0x93f35
jmp 0x941f3
jmp 0x93f37
jmp 0x93f39
jmp 0x93f3b
jmp 0x93f3d
movl $0x8e, %edi
callq 0x824f0
movl $0xa6, %edi
callq 0x7b210
movzbl -0x1(%rbp), %edi
callq 0x7b210
callq 0x82590
jmp 0x9410d
leaq 0x1e3b45(%rip), %rax    # 0x277ab0
cmpq $0x4, (%rax)
jne 0x93fa1
leaq 0x2d8238(%rip), %rax    # 0x36c1b0
movsd (%rax), %xmm0
leaq 0x2d8235(%rip), %rax    # 0x36c1b8
movsd (%rax), %xmm1
leaq 0x2d8232(%rip), %rax    # 0x36c1c0
movsd (%rax), %xmm2
movl $0x1, %edi
callq 0x8e2f0
jmp 0x9410b
leaq 0x1e3b08(%rip), %rax    # 0x277ab0
cmpq $0x8, (%rax)
jne 0x94077
leaq 0x1e6207(%rip), %rax    # 0x27a1c0
cmpl $0x50, (%rax)
jne 0x94050
leaq 0xf0c87(%rip), %rdi     # 0x184c50
movl $0x13, %esi
callq 0x82fd0
leaq 0x209596(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0x94014
leaq 0x209589(%rip), %rax    # 0x29d570
movq (%rax), %rdi
movl -0x8(%rbp), %edx
leaq 0x2d9064(%rip), %rax    # 0x36d058
movq (%rax), %rcx
leaq 0xf0c69(%rip), %rsi     # 0x184c67
movb $0x0, %al
callq 0x9550
leaq 0x209564(%rip), %rax    # 0x29d570
movq (%rax), %rdi
callq 0x9430
leaq 0x2d903d(%rip), %rax    # 0x36d058
movq $0x0, (%rax)
leaq 0x2d9037(%rip), %rax    # 0x36d060
movq $0x0, (%rax)
leaq 0x2d9031(%rip), %rax    # 0x36d068
movl $0xfffffff4, (%rax)     # imm = 0xFFFFFFF4
leaq 0xf0971(%rip), %rdi     # 0x1849b5
movl $0x13, %esi
callq 0x82fd0
jmp 0x94072
leaq 0xefa69(%rip), %rdi     # 0x183ac0
movl $0x14, %esi
callq 0x82fd0
leaq 0xf3413(%rip), %rdi     # 0x18747b
movl $0x65, %esi
callq 0x82fd0
jmp 0x94109
leaq 0x1e3a32(%rip), %rax    # 0x277ab0
cmpq $0x80, (%rax)
jne 0x940b4
leaq 0x2d8122(%rip), %rax    # 0x36c1b0
movsd (%rax), %xmm0
leaq 0x2d811f(%rip), %rax    # 0x36c1b8
movsd (%rax), %xmm1
leaq 0x2d811c(%rip), %rax    # 0x36c1c0
movsd (%rax), %xmm2
movl $0x1, %edi
callq 0x8c850
jmp 0x94107
leaq 0x1e39f5(%rip), %rax    # 0x277ab0
cmpq $0x100, (%rax)          # imm = 0x100
jne 0x940e7
leaq 0x1e61d9(%rip), %rax    # 0x27a2a4
movl (%rax), %esi
movl $0x3, %edi
xorps %xmm2, %xmm2
movl $0x7, %edx
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x8e4f0
jmp 0x94105
leaq 0x1e39c2(%rip), %rax    # 0x277ab0
cmpq $0x100000, (%rax)       # imm = 0x100000
jne 0x94103
leaq 0xf0ba4(%rip), %rdi     # 0x184ca2
callq 0x85d30
jmp 0x94105
jmp 0x94107
jmp 0x94109
jmp 0x9410b
jmp 0x9410d
jmp 0x9410f
jmp 0x94111
jmp 0x94113
jmp 0x94115
jmp 0x94117
jmp 0x94119
jmp 0x9411b
movzbl -0x1(%rbp), %eax
cmpl $0x0, %eax
jne 0x9412e
leaq 0x2d8f56(%rip), %rax    # 0x36d081
movb $0x1, (%rax)
leaq 0x2d8f47(%rip), %rax    # 0x36d07c
cmpl $0x0, (%rax)
je 0x9413f
jmp 0x941ee
leaq 0x2d8f32(%rip), %rax    # 0x36d078
cmpb $0x0, (%rax)
je 0x94150
jmp 0x941ec
leaq 0x2d8059(%rip), %rax    # 0x36c1b0
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x94194
jp 0x94194
leaq 0x2d804b(%rip), %rax    # 0x36c1b8
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x94194
jp 0x94194
leaq 0x2d803d(%rip), %rax    # 0x36c1c0
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x94194
jp 0x94194
jmp 0x941ea
leaq 0x2d8015(%rip), %rax    # 0x36c1b0
movsd (%rax), %xmm0
leaq 0x30632a(%rip), %rax    # 0x39a4d0
movsd %xmm0, (%rax)
leaq 0x2d8007(%rip), %rax    # 0x36c1b8
movsd (%rax), %xmm0
leaq 0x30631c(%rip), %rax    # 0x39a4d8
movsd %xmm0, (%rax)
leaq 0x2d7ff9(%rip), %rax    # 0x36c1c0
movsd (%rax), %xmm0
leaq 0x30630e(%rip), %rax    # 0x39a4e0
movsd %xmm0, (%rax)
leaq 0x30630b(%rip), %rax    # 0x39a4e8
movl $0xfffffffe, (%rax)     # imm = 0xFFFFFFFE
xorl %edi, %edi
callq 0x159b10
jmp 0x941ec
jmp 0x941ee
callq 0x9a9e0
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax)