// File: /workspace/github_cpp_makefile_star2_O1/jkingan[P]ladyheather/heathui.cpp
// Function: set_serial_params(unsigned int, char*, int)
int set_serial_params(unsigned port, char *p, int open_port)
{
char *s;
int baud;
int data_bits;
int stop_bits;
int parity;

   // Set serial port parameters.
   // p is serial port parameter string
   // port is default port to config if no :P param seen in p string
   // if open_port is non-zero, com port is opened
   //
   // Returns port that was configed or negative number if error detected.
   //
   // If a serial port parameter is not specified it is not changed.

   if(p == 0) return (-1);  // null param string

   s = strstr(p, ":p");   // check for :P0 .. :P9 for forced port number
   if(s == 0) s = strstr(p, ":P");
   if(s == 0) s = strstr(p, ",p");
   if(s == 0) s = strstr(p, ",P");

   if(s && s[2]) {  // :Px value seen, override port arg
      if(isdigit(s[2])) port = (s[2]-'0');
      if     (toupper(s[2] == 'D')) port = DAC_PORT;       // :PD - external DAC port
      else if(toupper(s[2] == 'E')) port = ECHO_PORT;      // :PE - echo port
      else if(toupper(s[2] == 'F')) port = FAN_PORT;       // :PF - temperature control device port
      else if(toupper(s[2] == 'I')) port = TICC_PORT;      // :PI - TICC port
      else if(toupper(s[2] == 'K')) port = NMEA_PORT;      // :PK - echo in NMEA format port
      else if(toupper(s[2] == 'N')) port = THERMO_PORT;    // :PN - environmental sensor (thermometer) port
      else if(toupper(s[2] == 'R')) port = RCVR_PORT;      // :PR - receiver data port
      else if(toupper(s[2] == 'T')) port = TRACK_PORT;     // :PT - moon/sun position
   }

   if(port >= NUM_COM_PORTS) return (-2);  // port number out of range

   s = p;
   s = trim_whitespace(s);
   if(s == 0) return (-3);
   if(s[0] == 0) return (-3);  // null param string

   baud = com[port].baud_rate;
   data_bits = com[port].data_bits;
   stop_bits = com[port].stop_bits;
   parity = com[port].parity;

   if(isdigit(*s)) {
      baud = atoi(s);
//    if(baud >= 150) com[port].baud_rate = baud;
   }

   if     (strstr(s, ":8")) data_bits = 8;
   else if(strstr(s, ",8")) data_bits = 8;
   else if(strstr(s, ":7")) data_bits = 7;
   else if(strstr(s, ",7")) data_bits = 7;
   else if(strstr(s, ":6")) data_bits = 6;
   else if(strstr(s, ",6")) data_bits = 6;
   else if(strstr(s, ":5")) data_bits = 5;
   else if(strstr(s, ",5")) data_bits = 5;
// else                     data_bits = 8;

   if     (strstr(s, ":1")) stop_bits = 1;
   else if(strstr(s, ",1")) stop_bits = 1;
   else if(strstr(s, ":2")) stop_bits = 2;
   else if(strstr(s, ",2")) stop_bits = 2;
// else                     stop_bits = 1;

   if     (strstr(s, ":N")) parity = NO_PAR;
   else if(strstr(s, ":n")) parity = NO_PAR;
   else if(strstr(s, ":O")) parity = ODD_PAR;
   else if(strstr(s, ":0")) parity = ODD_PAR;
   else if(strstr(s, ":o")) parity = ODD_PAR;
   else if(strstr(s, ":E")) parity = EVEN_PAR;
   else if(strstr(s, ":e")) parity = EVEN_PAR;
   else if(strstr(s, ",N")) parity = NO_PAR;
   else if(strstr(s, ",n")) parity = NO_PAR;
   else if(strstr(s, ",O")) parity = ODD_PAR;
   else if(strstr(s, ",0")) parity = ODD_PAR;
   else if(strstr(s, ",o")) parity = ODD_PAR;
   else if(strstr(s, ",E")) parity = EVEN_PAR;
   else if(strstr(s, ",e")) parity = EVEN_PAR;
// else                     parity = NO_PAR;

   if(open_port == 2) {
      set_rcvr_baud(baud, data_bits, parity, stop_bits);
   }
   else {
      com[port].user_set_baud = 1;  //ppppp
      com[port].baud_rate = baud;
      com[port].data_bits = data_bits;
      com[port].parity = parity;
      com[port].stop_bits = stop_bits;
      if(open_port) init_com(port, 10);
   }
   return port;
}

// Assembly:
testq %rsi, %rsi
je 0x26789
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %ebx
movq %rsi, %r15
movl %edi, %r12d
leaq 0xe7441(%rip), %rsi     # 0x10da0f
movq %r15, %rdi
callq 0x9090
testq %rax, %rax
jne 0x265ea
leaq 0xe7430(%rip), %rsi     # 0x10da12
movq %r15, %rdi
callq 0x9090
testq %rax, %rax
jne 0x265fe
leaq 0xe741f(%rip), %rsi     # 0x10da15
movq %r15, %rdi
callq 0x9090
testq %rax, %rax
jne 0x26612
leaq 0xfb32d(%rip), %rsi     # 0x121937
movq %r15, %rdi
callq 0x9090
testq %rax, %rax
je 0x2670c
movsbl 0x2(%rax), %r13d
testl %r13d, %r13d
je 0x2670c
leal -0x30(%r13), %eax
cmpl $0xa, %eax
cmovbl %eax, %r12d
xorl %edi, %edi
cmpb $0x44, %r13b
sete %dil
callq 0x9700
movl $0x10, %r14d
testl %eax, %eax
jne 0x2670f
xorl %edi, %edi
cmpb $0x45, %r13b
sete %dil
callq 0x9700
movl $0xb, %r14d
testl %eax, %eax
jne 0x2670f
xorl %edi, %edi
cmpb $0x46, %r13b
sete %dil
callq 0x9700
movl $0x11, %r14d
testl %eax, %eax
jne 0x2670f
xorl %edi, %edi
cmpb $0x49, %r13b
sete %dil
callq 0x9700
movl $0xd, %r14d
testl %eax, %eax
jne 0x2670f
xorl %edi, %edi
cmpb $0x4b, %r13b
sete %dil
callq 0x9700
movl $0xc, %r14d
testl %eax, %eax
jne 0x2670f
xorl %edi, %edi
cmpb $0x4e, %r13b
sete %dil
callq 0x9700
movl $0xf, %r14d
testl %eax, %eax
jne 0x2670f
xorl %edi, %edi
cmpb $0x52, %r13b
sete %dil
callq 0x9700
movl $0xa, %r14d
testl %eax, %eax
jne 0x2670f
xorl %edi, %edi
cmpb $0x54, %r13b
sete %dil
callq 0x9700
testl %eax, %eax
movl $0x12, %r14d
cmovel %r12d, %r14d
jmp 0x2670f
movl %r12d, %r14d
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
cmpl $0x12, %r14d
ja 0x2699b
movq %r15, %rdi
callq 0x9fd5
movq %rax, %r12
movl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
testq %r12, %r12
je 0x2699b
movsbl (%r12), %ecx
testl %ecx, %ecx
je 0x2699b
movl %r14d, %eax
imulq $0x2260, %rax, %rax     # imm = 0x2260
leaq 0x2e7b8b(%rip), %r15    # 0x30e2e0
movl 0x214(%r15,%rax), %r13d
movl 0x218(%r15,%rax), %edx
movl %edx, -0x30(%rbp)
movl 0x21c(%r15,%rax), %edx
movl %edx, -0x38(%rbp)
addl $-0x30, %ecx
cmpl $0x9, %ecx
movq %rax, -0x40(%rbp)
ja 0x2678f
movq %r12, %rdi
callq 0x95e0
jmp 0x26797
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
retq
movl 0x210(%r15,%rax), %eax
movl %eax, -0x34(%rbp)
leaq 0xe7277(%rip), %rsi     # 0x10da18
movq %r12, %rdi
callq 0x9090
movl $0x8, -0x2c(%rbp)
testq %rax, %rax
jne 0x26868
leaq 0xfa88a(%rip), %rsi     # 0x12104a
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x26868
leaq 0xe7243(%rip), %rsi     # 0x10da1b
movq %r12, %rdi
callq 0x9090
movl $0x7, -0x2c(%rbp)
testq %rax, %rax
jne 0x26868
leaq 0xfa851(%rip), %rsi     # 0x121044
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x26868
leaq 0xe7217(%rip), %rsi     # 0x10da1e
movq %r12, %rdi
callq 0x9090
movl $0x6, -0x2c(%rbp)
testq %rax, %rax
jne 0x26868
leaq 0xe71ff(%rip), %rsi     # 0x10da21
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x26868
leaq 0xe71ee(%rip), %rsi     # 0x10da24
movq %r12, %rdi
callq 0x9090
movl $0x5, -0x2c(%rbp)
testq %rax, %rax
jne 0x26868
leaq 0xe71d6(%rip), %rsi     # 0x10da27
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
movl $0x5, %eax
cmovel %r13d, %eax
movl %eax, -0x2c(%rbp)
leaq 0xe71bb(%rip), %rsi     # 0x10da2a
movq %r12, %rdi
callq 0x9090
movl $0x1, %r13d
testq %rax, %rax
jne 0x268c7
leaq 0xfa5ef(%rip), %rsi     # 0x120e78
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x268c7
leaq 0xe7190(%rip), %rsi     # 0x10da2d
movq %r12, %rdi
callq 0x9090
movl $0x2, %r13d
testq %rax, %rax
jne 0x268c7
leaq 0x10d207(%rip), %rsi    # 0x133abe
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
cmovel -0x30(%rbp), %r13d
movl %r13d, -0x30(%rbp)
leaq 0xe715e(%rip), %rsi     # 0x10da30
movq %r12, %rdi
callq 0x9090
xorl %r13d, %r13d
testq %rax, %rax
jne 0x26938
leaq 0xe714a(%rip), %rsi     # 0x10da33
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x26938
leaq 0xe7139(%rip), %rsi     # 0x10da36
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x26932
leaq 0xe7128(%rip), %rsi     # 0x10da39
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x26932
leaq 0xe7117(%rip), %rsi     # 0x10da3c
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
je 0x269aa
movl $0x1, %r13d
cmpl $0x2, %ebx
movq -0x40(%rbp), %rax
jne 0x26954
movl -0x34(%rbp), %edi
movl -0x2c(%rbp), %esi
movl %r13d, %edx
movl -0x30(%rbp), %ecx
callq 0x5f797
jmp 0x26998
addq %rax, %r15
movl $0x1, 0x2258(%r15)
movl -0x34(%rbp), %eax
movl %eax, 0x210(%r15)
movl -0x2c(%rbp), %eax
movl %eax, 0x214(%r15)
movl %r13d, 0x21c(%r15)
movl -0x30(%rbp), %eax
movl %eax, 0x218(%r15)
testl %ebx, %ebx
je 0x26998
movl %r14d, %edi
movl $0xa, %esi
callq 0xb49f
movl %r14d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xe708e(%rip), %rsi     # 0x10da3f
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x269d2
leaq 0xe707d(%rip), %rsi     # 0x10da42
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
je 0x269dd
movl $0x2, %r13d
jmp 0x26938
leaq 0xf9f47(%rip), %rsi     # 0x12092b
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x26938
leaq 0xe7049(%rip), %rsi     # 0x10da45
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x26938
leaq 0xe7034(%rip), %rsi     # 0x10da48
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x26932
leaq 0xfa38f(%rip), %rsi     # 0x120dbb
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x26932
leaq 0xe7007(%rip), %rsi     # 0x10da4b
movq %r12, %rdi
callq 0x9090
movl $0x1, %r13d
testq %rax, %rax
jne 0x26938
leaq 0xe6fec(%rip), %rsi     # 0x10da4e
movq %r12, %rdi
callq 0x9090
movl $0x2, %r13d
testq %rax, %rax
jne 0x26938
leaq 0xe6fd1(%rip), %rsi     # 0x10da51
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
cmovel -0x38(%rbp), %r13d
jmp 0x26938