// File: /workspace/github_cpp_makefile_star2_O3/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 0x264bd
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %r13d
movq %rsi, %r15
movl %edi, %r12d
leaq 0xe7792(%rip), %rsi     # 0x10daa3
movq %r15, %rdi
callq 0x9090
testq %rax, %rax
jne 0x2635e
leaq 0xe7781(%rip), %rsi     # 0x10daa6
movq %r15, %rdi
callq 0x9090
testq %rax, %rax
jne 0x2635e
leaq 0xe7770(%rip), %rsi     # 0x10daa9
movq %r15, %rdi
callq 0x9090
testq %rax, %rax
jne 0x2635e
leaq 0xfb6ca(%rip), %rsi     # 0x121a17
movq %r15, %rdi
callq 0x9090
testq %rax, %rax
je 0x26440
movsbl 0x2(%rax), %ebx
testl %ebx, %ebx
je 0x26440
leal -0x30(%rbx), %eax
cmpl $0xa, %eax
cmovbl %eax, %r12d
xorl %edi, %edi
cmpb $0x44, %bl
sete %dil
callq 0x9700
movl $0x10, %r14d
testl %eax, %eax
jne 0x26452
xorl %edi, %edi
cmpb $0x45, %bl
sete %dil
callq 0x9700
movl $0xb, %r14d
testl %eax, %eax
jne 0x26452
xorl %edi, %edi
cmpb $0x46, %bl
sete %dil
callq 0x9700
movl $0x11, %r14d
testl %eax, %eax
jne 0x26452
xorl %edi, %edi
cmpb $0x49, %bl
sete %dil
callq 0x9700
movl $0xd, %r14d
testl %eax, %eax
jne 0x26452
xorl %edi, %edi
cmpb $0x4b, %bl
sete %dil
callq 0x9700
movl $0xc, %r14d
testl %eax, %eax
jne 0x26452
xorl %edi, %edi
cmpb $0x4e, %bl
sete %dil
callq 0x9700
movl $0xf, %r14d
testl %eax, %eax
jne 0x26452
xorl %edi, %edi
cmpb $0x52, %bl
sete %dil
callq 0x9700
movl $0xa, %r14d
testl %eax, %eax
jne 0x26452
xorl %edi, %edi
cmpb $0x54, %bl
sete %dil
callq 0x9700
movl $0x12, %r14d
testl %eax, %eax
jne 0x26452
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
movl %r12d, %r14d
cmpl $0x12, %r12d
ja 0x266ce
movq %r15, %rdi
callq 0x9fcd
movq %rax, %r12
movl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
testq %r12, %r12
je 0x266ce
movsbl (%r12), %ecx
testl %ecx, %ecx
je 0x266ce
movl %r13d, -0x3c(%rbp)
movl %r14d, %eax
imulq $0x2260, %rax, %rbx     # imm = 0x2260
leaq 0x2e7e53(%rip), %r15    # 0x30e2e0
movl 0x214(%r15,%rbx), %r13d
movl 0x218(%r15,%rbx), %eax
movl %eax, -0x30(%rbp)
movl 0x21c(%r15,%rbx), %eax
movl %eax, -0x38(%rbp)
addl $-0x30, %ecx
cmpl $0x9, %ecx
ja 0x264c3
movq %r12, %rdi
callq 0x95e0
jmp 0x264cb
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
retq
movl 0x210(%r15,%rbx), %eax
movl %eax, -0x34(%rbp)
leaq 0xe75d7(%rip), %rsi     # 0x10daac
movq %r12, %rdi
callq 0x9090
movl $0x8, -0x2c(%rbp)
testq %rax, %rax
jne 0x2659c
leaq 0xfac36(%rip), %rsi     # 0x12112a
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x2659c
leaq 0xe75a3(%rip), %rsi     # 0x10daaf
movq %r12, %rdi
callq 0x9090
movl $0x7, -0x2c(%rbp)
testq %rax, %rax
jne 0x2659c
leaq 0xfabfd(%rip), %rsi     # 0x121124
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x2659c
leaq 0xe7577(%rip), %rsi     # 0x10dab2
movq %r12, %rdi
callq 0x9090
movl $0x6, -0x2c(%rbp)
testq %rax, %rax
jne 0x2659c
leaq 0xe755f(%rip), %rsi     # 0x10dab5
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x2659c
leaq 0xe754e(%rip), %rsi     # 0x10dab8
movq %r12, %rdi
callq 0x9090
movl $0x5, -0x2c(%rbp)
testq %rax, %rax
jne 0x2659c
leaq 0xe7536(%rip), %rsi     # 0x10dabb
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
movl $0x5, %eax
cmovel %r13d, %eax
movl %eax, -0x2c(%rbp)
leaq 0xe751b(%rip), %rsi     # 0x10dabe
movq %r12, %rdi
callq 0x9090
movl $0x1, %r13d
testq %rax, %rax
jne 0x265fb
leaq 0xfa99b(%rip), %rsi     # 0x120f58
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x265fb
leaq 0xe74f0(%rip), %rsi     # 0x10dac1
movq %r12, %rdi
callq 0x9090
movl $0x2, %r13d
testq %rax, %rax
jne 0x265fb
leaq 0x10d5c3(%rip), %rsi    # 0x133bae
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
cmovel -0x30(%rbp), %r13d
movl %r13d, -0x30(%rbp)
leaq 0xe74be(%rip), %rsi     # 0x10dac4
movq %r12, %rdi
callq 0x9090
xorl %r13d, %r13d
testq %rax, %rax
jne 0x2666c
leaq 0xe74aa(%rip), %rsi     # 0x10dac7
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x2666c
leaq 0xe7499(%rip), %rsi     # 0x10daca
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x26666
leaq 0xe7488(%rip), %rsi     # 0x10dacd
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x26666
leaq 0xe7477(%rip), %rsi     # 0x10dad0
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
je 0x266dd
movl $0x1, %r13d
movl -0x3c(%rbp), %eax
cmpl $0x2, %eax
jne 0x26687
movl -0x34(%rbp), %edi
movl -0x2c(%rbp), %esi
movl %r13d, %edx
movl -0x30(%rbp), %ecx
callq 0x5f71f
jmp 0x266cb
addq %rbx, %r15
movl $0x1, 0x2258(%r15)
movl -0x34(%rbp), %ecx
movl %ecx, 0x210(%r15)
movl -0x2c(%rbp), %ecx
movl %ecx, 0x214(%r15)
movl %r13d, 0x21c(%r15)
movl -0x30(%rbp), %ecx
movl %ecx, 0x218(%r15)
testl %eax, %eax
je 0x266cb
movl %r14d, %edi
movl $0xa, %esi
callq 0xb49e
movl %r14d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xe73ef(%rip), %rsi     # 0x10dad3
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x26705
leaq 0xe73de(%rip), %rsi     # 0x10dad6
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
je 0x26710
movl $0x2, %r13d
jmp 0x2666c
leaq 0xfa2f4(%rip), %rsi     # 0x120a0b
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x2666c
leaq 0xe73aa(%rip), %rsi     # 0x10dad9
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x2666c
leaq 0xe7395(%rip), %rsi     # 0x10dadc
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x26666
leaq 0xfa73c(%rip), %rsi     # 0x120e9b
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x26666
leaq 0xe7368(%rip), %rsi     # 0x10dadf
movq %r12, %rdi
callq 0x9090
movl $0x1, %r13d
testq %rax, %rax
jne 0x2666c
leaq 0xe734d(%rip), %rsi     # 0x10dae2
movq %r12, %rdi
callq 0x9090
movl $0x2, %r13d
testq %rax, %rax
jne 0x2666c
leaq 0xe7332(%rip), %rsi     # 0x10dae5
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
cmovel -0x38(%rbp), %r13d
jmp 0x2666c