// File: /workspace/github_cpp_makefile_star2_O2/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 0x24760
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, %ebx
leaq 0xd3442(%rip), %rsi     # 0xf7b23
movq %r15, %rdi
callq 0x9090
testq %rax, %rax
jne 0x2472e
leaq 0xd3431(%rip), %rsi     # 0xf7b26
movq %r15, %rdi
callq 0x9090
testq %rax, %rax
jne 0x2472e
leaq 0xd3420(%rip), %rsi     # 0xf7b29
movq %r15, %rdi
callq 0x9090
testq %rax, %rax
jne 0x2472e
leaq 0xe7242(%rip), %rsi     # 0x10b95f
movq %r15, %rdi
callq 0x9090
testq %rax, %rax
je 0x24809
movsbl 0x2(%rax), %r14d
testl %r14d, %r14d
je 0x24809
leal -0x30(%r14), %eax
cmpl $0xa, %eax
cmovbl %eax, %ebx
xorl %edi, %edi
cmpb $0x44, %r14b
sete %dil
callq 0x9700
testl %eax, %eax
je 0x24764
pushq $0x10
jmp 0x24806
pushq $-0x1
popq %rax
retq
xorl %edi, %edi
cmpb $0x45, %r14b
sete %dil
callq 0x9700
testl %eax, %eax
je 0x2477e
pushq $0xb
jmp 0x24806
xorl %edi, %edi
cmpb $0x46, %r14b
sete %dil
callq 0x9700
testl %eax, %eax
je 0x24795
pushq $0x11
jmp 0x24806
xorl %edi, %edi
cmpb $0x49, %r14b
sete %dil
callq 0x9700
testl %eax, %eax
je 0x247ac
pushq $0xd
jmp 0x24806
xorl %edi, %edi
cmpb $0x4b, %r14b
sete %dil
callq 0x9700
testl %eax, %eax
je 0x247c3
pushq $0xc
jmp 0x24806
xorl %edi, %edi
cmpb $0x4e, %r14b
sete %dil
callq 0x9700
testl %eax, %eax
je 0x247da
pushq $0xf
jmp 0x24806
xorl %edi, %edi
cmpb $0x52, %r14b
sete %dil
callq 0x9700
testl %eax, %eax
je 0x247f1
pushq $0xa
jmp 0x24806
xorl %edi, %edi
cmpb $0x54, %r14b
sete %dil
callq 0x9700
testl %eax, %eax
je 0x24809
pushq $0x12
popq %rbx
jmp 0x24816
cmpl $0x12, %ebx
jbe 0x24816
pushq $-0x2
popq %rax
jmp 0x24a86
movq %r15, %rdi
callq 0x9f43
movq %rax, %r12
pushq $-0x3
popq %rax
testq %r12, %r12
je 0x24a86
movsbl (%r12), %ecx
testl %ecx, %ecx
je 0x24a86
movl %r13d, -0x3c(%rbp)
movl %ebx, %eax
imulq $0x2260, %rax, %r14     # imm = 0x2260
leaq 0x2d3a92(%rip), %r15    # 0x2f82e0
movl 0x214(%r15,%r14), %r13d
movl 0x218(%r15,%r14), %eax
movl %eax, -0x30(%rbp)
movl 0x21c(%r15,%r14), %eax
movl %eax, -0x38(%rbp)
addl $-0x30, %ecx
cmpl $0x9, %ecx
ja 0x2487e
movq %r12, %rdi
callq 0x95e0
jmp 0x24886
movl 0x210(%r15,%r14), %eax
movl %eax, -0x34(%rbp)
leaq 0xd329c(%rip), %rsi     # 0xf7b2c
movq %r12, %rdi
callq 0x9090
pushq $0x8
popq %rcx
movl %ecx, -0x2c(%rbp)
testq %rax, %rax
jne 0x24950
leaq 0xe67c4(%rip), %rsi     # 0x10b072
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x24950
leaq 0xd3269(%rip), %rsi     # 0xf7b2f
movq %r12, %rdi
callq 0x9090
pushq $0x7
popq %rcx
movl %ecx, -0x2c(%rbp)
testq %rax, %rax
jne 0x24950
leaq 0xe678c(%rip), %rsi     # 0x10b06c
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x24950
leaq 0xd323e(%rip), %rsi     # 0xf7b32
movq %r12, %rdi
callq 0x9090
pushq $0x6
popq %rcx
movl %ecx, -0x2c(%rbp)
testq %rax, %rax
jne 0x24950
leaq 0xd3227(%rip), %rsi     # 0xf7b35
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x24950
leaq 0xd3216(%rip), %rsi     # 0xf7b38
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
je 0x24934
pushq $0x5
popq %rax
jmp 0x2494d
leaq 0xd3200(%rip), %rsi     # 0xf7b3b
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
pushq $0x5
popq %rax
cmovel %r13d, %eax
movl %eax, -0x2c(%rbp)
leaq 0xd31e7(%rip), %rsi     # 0xf7b3e
movq %r12, %rdi
callq 0x9090
pushq $0x1
popq %r13
testq %rax, %rax
jne 0x249b1
leaq 0xe6531(%rip), %rsi     # 0x10aea0
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x249b1
leaq 0xd31be(%rip), %rsi     # 0xf7b41
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
je 0x24996
pushq $0x2
popq %r13
jmp 0x249b1
leaq 0xf9131(%rip), %rsi     # 0x11dace
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
pushq $0x2
popq %r13
cmovel -0x30(%rbp), %r13d
movl %r13d, -0x30(%rbp)
leaq 0xd3188(%rip), %rsi     # 0xf7b44
movq %r12, %rdi
callq 0x9090
xorl %r13d, %r13d
testq %rax, %rax
jne 0x24a28
leaq 0xd3174(%rip), %rsi     # 0xf7b47
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x24a28
leaq 0xd3163(%rip), %rsi     # 0xf7b4a
movq %r12, %rdi
callq 0x9090
pushq $0x1
popq %rcx
testq %rax, %rax
je 0x249fc
movl %ecx, %r13d
jmp 0x24a28
leaq 0xd314a(%rip), %rsi     # 0xf7b4d
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x24a24
leaq 0xd3139(%rip), %rsi     # 0xf7b50
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
je 0x24a95
pushq $0x1
popq %r13
movl -0x3c(%rbp), %eax
cmpl $0x2, %eax
jne 0x24a43
movl -0x34(%rbp), %edi
movl -0x2c(%rbp), %esi
movl %r13d, %edx
movl -0x30(%rbp), %ecx
callq 0x57f1e
jmp 0x24a84
addq %r14, %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 0x24a84
pushq $0xa
popq %rsi
movl %ebx, %edi
callq 0xb30a
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd30b7(%rip), %rsi     # 0xf7b53
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x24abd
leaq 0xd30a6(%rip), %rsi     # 0xf7b56
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
je 0x24ac4
pushq $0x2
jmp 0x24a26
leaq 0xe5e88(%rip), %rsi     # 0x10a953
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x24a28
leaq 0xd3076(%rip), %rsi     # 0xf7b59
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x24a28
leaq 0xd3061(%rip), %rsi     # 0xf7b5c
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x24a24
leaq 0xe62d0(%rip), %rsi     # 0x10ade3
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
jne 0x24a24
leaq 0xd3034(%rip), %rsi     # 0xf7b5f
movq %r12, %rdi
callq 0x9090
pushq $0x1
popq %r13
testq %rax, %rax
jne 0x24a28
leaq 0xd301b(%rip), %rsi     # 0xf7b62
movq %r12, %rdi
callq 0x9090
pushq $0x2
popq %r13
testq %rax, %rax
jne 0x24a28
leaq 0xd3002(%rip), %rsi     # 0xf7b65
movq %r12, %rdi
callq 0x9090
testq %rax, %rax
cmovel -0x38(%rbp), %r13d
jmp 0x24a28