// File: /workspace/github_cpp_makefile_star2_O1/jkingan[P]ladyheather/heathgps.cpp
// Function: set_rcvr_baud(int, int, int, int)
int set_rcvr_baud(int baud, int data_bits, int parity, int stop_bits)
{
int i;

   // future command to set receiver serial port settings
   // !!!!! data_bits, parity, stop_bits not currently implemented
   //       We currentlu always set 8:N:1
   // returns: 0=baud set  1=improper rate   2=baud change not supported

   if(read_only) return 2;

   i = (-1);
   if     (baud == 150) return 1;   // don't allow non-standard values
   else if(baud == 300)    i = 0;   
   else if(baud == 600)    i = 1;   
   else if(baud == 1200)   i = 2;  
   else if(baud == 2400)   i = 3;  
   else if(baud == 4800)   i = 4;  
   else if(baud == 9600)   i = 5;  
   else if(baud == 19200)  i = 6; 
   else if(baud == 38400)  i = 7; 
   else if(baud == 57600)  i = 8; 
   else if(baud == 115200) i = 9; 
   else if(baud == 230400) {
      if(0 && (rcvr_type == VENUS_RCVR)) i = 10;
      else return 1;
   }
   else return 1;

   if(rcvr_type == ESIP_RCVR) {
      sprintf(out, "PERDCFG,UART1,%d", baud);
      send_esip_cmd(out);
      com[RCVR_PORT].baud_rate = baud;
   }
   else if(0 && (rcvr_type == NVS_RCVR)) {
      if(i < 4) return 1;
      send_nvs_start(0x0B);
      send_byte(0);    // current port
      send_dword(baud);
      send_byte(0);    // current protocol
      send_nvs_end();
      com[RCVR_PORT].baud_rate = baud;
   }
   else if(1 && (rcvr_type == SIRF_RCVR)) {
      if(i < 2) return 1;
      send_sirf_start(SET_SIRF_BINARY, 8+1);
      send_dword(baud);
      send_byte(8);
      send_byte(1);
      send_byte(0);
      send_byte(0);
      send_sirf_end();
      com[RCVR_PORT].baud_rate = baud;
   }
   else if(rcvr_type == TM4_RCVR) {  // time port baud rate
      i -= 2;
      if(i < 0) return 1;
      sprintf(out, "#10,%d", i);
      send_tm4_cmd(out);
      return 0;   // does not change control serial port baud rate !!!
   }
   else if(0 && (rcvr_type == TSIP_RCVR)) {
      if((baud >= 9600) && (baud <= 115200)) {
         set_trimble_protocol(baud, 8, NO_PAR, 1, 2,2);
         com[RCVR_PORT].baud_rate = baud;
      }
      else return 1;
   }
   else if(rcvr_type == UBX_RCVR) {
      rcvr_type = NMEA_RCVR;
      sprintf(out, "PUBX,41,1,0003,0001,%d,0", com[RCVR_PORT].baud_rate);  // 9600 bps ublox binary output mode (port 1)
      send_nmea_cmd(out);
      rcvr_type = UBX_RCVR;
      com[RCVR_PORT].baud_rate = baud;
   }
   else if(rcvr_type == VENUS_RCVR) {
      i -= 4;
      if(i < 0) return 1;
      send_venus_start(SET_VENUS_BAUD);
      send_byte(0);  // com1
      send_byte(i); 
      send_venus_save(1);
      com[RCVR_PORT].baud_rate = baud;
   }
   else if(rcvr_type == Z12_RCVR) {
      com[RCVR_PORT].baud_rate = baud;
      sprintf(out, "PASHS,SPD,A,%d", i);
      send_z12_cmd(out);
      com[RCVR_PORT].baud_rate = baud;
   }
   else if(0 && (rcvr_type == ZODIAC_RCVR)) {
      if(i == 9) i += 2;
      else       i += 1;
      if(i == 10) return 1;   // we don't allow 76800 baud

      send_zod_start(ZOD_SET_BAUD, 20, 0);
      send_zod_seq();

      send_word(0x0001);  // port 1

      send_word(1);       // 8 bits
      send_word(0);       // 1 stop
      send_word(0);       // no parity
      send_word(i);       // baud
      send_word(0);
      send_word(0);

      send_word(1);       // 8 bits
      send_word(0);       // 1 stop
      send_word(0);       // no parity
      send_word(i);       // baud
      send_word(0);
      send_word(0);

      send_zod_end();

      com[RCVR_PORT].baud_rate = baud;
   }
   else return 2;

   Sleep(COM_INIT_SLEEP);
   init_com(RCVR_PORT, 150);
   return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
leaq 0x2d7871(%rip), %rax    # 0x33701a
movl $0x2, %r14d
cmpb $0x0, (%rax)
jne 0x5fa83
movl %edi, %ebx
cmpl $0x257f, %edi           # imm = 0x257F
jg 0x5f7fb
movb $0x1, %al
cmpl $0x4af, %ebx            # imm = 0x4AF
jle 0x5f827
cmpl $0x4b0, %ebx            # imm = 0x4B0
je 0x5f86c
cmpl $0x960, %ebx            # imm = 0x960
je 0x5f87c
cmpl $0x12c0, %ebx           # imm = 0x12C0
jne 0x5fa8f
movl $0x4, %r15d
jmp 0x5f88a
cmpl $0x95ff, %ebx           # imm = 0x95FF
jle 0x5f848
cmpl $0x9600, %ebx           # imm = 0x9600
je 0x5f874
cmpl $0xe100, %ebx           # imm = 0xE100
je 0x5f884
cmpl $0x1c200, %ebx          # imm = 0x1C200
jne 0x5fa8f
movl $0x9, %r15d
jmp 0x5f88a
xorl %r15d, %r15d
cmpl $0x12c, %ebx            # imm = 0x12C
je 0x5f844
cmpl $0x258, %ebx            # imm = 0x258
jne 0x5fa8f
movl $0x1, %r15d
movb $0x1, %cl
jmp 0x5f88e
cmpl $0x2580, %ebx           # imm = 0x2580
je 0x5f864
cmpl $0x4b00, %ebx           # imm = 0x4B00
jne 0x5fa8f
movl $0x6, %r15d
jmp 0x5f88a
movl $0x5, %r15d
jmp 0x5f88a
movl $0x2, %r15d
jmp 0x5f88c
movl $0x7, %r15d
jmp 0x5f88a
movl $0x3, %r15d
jmp 0x5f88c
movl $0x8, %r15d
xorl %eax, %eax
xorl %ecx, %ecx
leaq 0x1b903b(%rip), %r12    # 0x2188d0
movq (%r12), %rdx
cmpq $0x7fffffff, %rdx       # imm = 0x7FFFFFFF
jg 0x5f903
cmpq $0x4, %rdx
je 0x5f95e
cmpq $0x40, %rdx
je 0x5f9dd
cmpq $0x80, %rdx
jne 0x5fa83
movl $0x1, %r14d
testb %al, %al
jne 0x5fa83
movl $0x5, %edi
movl $0x4, %esi
callq 0x5fbb4
xorl %edi, %edi
callq 0x591af
addb $-0x4, %r15b
movzbl %r15b, %edi
callq 0x591af
movl $0x1, %edi
callq 0x5fc43
jmp 0x5fa5a
movabsq $0x400000000, %rax      # imm = 0x400000000
cmpq %rax, %rdx
je 0x5f9a0
movabsq $0x100000000, %rax      # imm = 0x100000000
cmpq %rax, %rdx
je 0x5fa2a
movl $0x80000000, %eax       # imm = 0x80000000
cmpq %rax, %rdx
jne 0x5fa83
leaq 0x2dc8e2(%rip), %r14    # 0x33c220
leaq 0xc0afc(%rip), %rsi     # 0x120441
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x9060
movq %r14, %rdi
callq 0x5ef13
jmp 0x5fa5a
movq $0x2, (%r12)
leaq 0x2ae973(%rip), %rax    # 0x30e2e0
movl 0x159d0(%rax), %edx
leaq 0x2dc8a6(%rip), %r14    # 0x33c220
leaq 0xc0ad8(%rip), %rsi     # 0x120459
movq %r14, %rdi
xorl %eax, %eax
callq 0x9060
movq %r14, %rdi
callq 0x5f15d
movq $0x4, (%r12)
jmp 0x5fa5a
movl $0x1, %r14d
testb %cl, %cl
jne 0x5fa83
addl $-0x2, %r15d
leaq 0x2dc867(%rip), %rbx    # 0x33c220
leaq 0xc0a92(%rip), %rsi     # 0x120452
xorl %r14d, %r14d
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0x9060
movq %rbx, %rdi
callq 0x5f1e8
jmp 0x5fa83
movl $0x1, %r14d
testb %cl, %cl
jne 0x5fa83
movl $0x86, %edi
movl $0x9, %esi
callq 0x5fa97
movl %ebx, %edi
callq 0x593b5
movl $0x8, %edi
callq 0x591af
movl $0x1, %edi
callq 0x591af
xorl %edi, %edi
callq 0x591af
xorl %edi, %edi
callq 0x591af
callq 0x5fb3b
jmp 0x5fa5a
leaq 0x2ae8af(%rip), %rax    # 0x30e2e0
movl %ebx, 0x159d0(%rax)
leaq 0x2dc7e2(%rip), %r14    # 0x33c220
leaq 0xc0a2d(%rip), %rsi     # 0x120472
movq %r14, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0x9060
movq %r14, %rdi
callq 0x5f340
leaq 0x2ae87f(%rip), %rax    # 0x30e2e0
movl %ebx, 0x159d0(%rax)
movl $0xc8, %edi
callq 0xaff7
movl $0xa, %edi
movl $0x96, %esi
callq 0xb49f
xorl %r14d, %r14d
movl %r14d, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %r14d
jmp 0x5fa83