// File: /workspace/github_cpp_makefile_star2_O2/msu-starx[P]starx/serial.cpp
// Function: SerialPort::setPort()
void SerialPort::setPort(void){
    tcgetattr(fileDescriptor, &portSettings); // Gets the current attributes

    switch(baudRate) {
    case 300:
        constBaud = B300;
        break;
    case 600:
        constBaud = B600;
        break;
    case 1200:
        constBaud = B1200;
        break;
    case 2400:
        constBaud = B2400;
        break;
    case 4800:
        constBaud = B4800;
        break;
    case 9600:
        constBaud = B9600;
        break;
    case 19200:
        constBaud = B19200;
        break;
    case 38400:
        constBaud = B38400;
        break;
    case 57600:
        constBaud = B57600;
        break;
    case 115200:
        constBaud = B115200;
        break;
    case 500000:
        constBaud = B500000;
        break;
    case 1000000:
        constBaud = B1000000;
        break;
    default:
        printf("Error! Undefined baud rate!\n");
        break;
    }

    cfsetispeed(&portSettings, constBaud); // Sets read speed
    cfsetospeed(&portSettings, constBaud); // Sets write speed

    portSettings.c_cflag &= ~PARENB; // Disables parity
    portSettings.c_cflag &= ~CSTOPB; // Sets the stop bits amount to 1
    portSettings.c_cflag &= ~CSIZE; // Clears the mask for setting the data size
    portSettings.c_cflag |= CS8; // Set the data bits amount to 8
    portSettings.c_cflag &= ~CRTSCTS; // Disables hardware flow control
    portSettings.c_cflag |= (CREAD | CLOCAL); // Enables receiver and sets local mode
    portSettings.c_iflag &= ~(IXON | IXOFF | IXANY); // Disables software flow control
    portSettings.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); // Selects raw input mode
    portSettings.c_oflag &= ~OPOST; // Selects raw output mode

    portSettings.c_cc[VMIN] = 0; // Minimum number of characters to read
    portSettings.c_cc[VTIME] = 0; // Time to wait for every character read
    // If VMIN = 0 and VTIME = 0, read() will be satisfied immediately

    if((tcsetattr(fileDescriptor, TCSANOW, &portSettings)) != 0) { // Sets the new attributes
        perror("\nSet_Port: Error in setting attributes - ");
    }
    else{
        printf("\n| Baud rate = %d bps | Stop bits = 1 | Parity = None |\n", baudRate);
    }

    this->flushPortAll();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
movl 0x4(%rdi), %edi
leaq 0x120(%rbx), %r14
movq %r14, %rsi
callq 0x21d0
movl 0x10(%rbx), %eax
cmpl $0xf4240, %eax          # imm = 0xF4240
je 0x561c
cmpl $0x258, %eax            # imm = 0x258
je 0x55ee
cmpl $0x4b0, %eax            # imm = 0x4B0
je 0x5647
cmpl $0x960, %eax            # imm = 0x960
je 0x5633
cmpl $0x12c0, %eax           # imm = 0x12C0
je 0x55d7
cmpl $0x2580, %eax           # imm = 0x2580
je 0x563d
cmpl $0x4b00, %eax           # imm = 0x4B00
je 0x55f8
cmpl $0x9600, %eax           # imm = 0x9600
je 0x5629
cmpl $0xe100, %eax           # imm = 0xE100
je 0x55e1
cmpl $0x1c200, %eax          # imm = 0x1C200
je 0x5602
cmpl $0x7a120, %eax          # imm = 0x7A120
je 0x560f
cmpl $0x12c, %eax            # imm = 0x12C
jne 0x56c3
movl $0x7, (%rbx)
pushq $0x7
jmp 0x564f
movl $0xc, (%rbx)
pushq $0xc
jmp 0x564f
movl $0x1001, (%rbx)         # imm = 0x1001
movl $0x1001, %esi           # imm = 0x1001
jmp 0x5650
movl $0x8, (%rbx)
pushq $0x8
jmp 0x564f
movl $0xe, (%rbx)
pushq $0xe
jmp 0x564f
movl $0x1002, (%rbx)         # imm = 0x1002
movl $0x1002, %esi           # imm = 0x1002
jmp 0x5650
movl $0x1005, (%rbx)         # imm = 0x1005
movl $0x1005, %esi           # imm = 0x1005
jmp 0x5650
movl $0x1008, (%rbx)         # imm = 0x1008
movl $0x1008, %esi           # imm = 0x1008
jmp 0x5650
movl $0xf, (%rbx)
pushq $0xf
jmp 0x564f
movl $0xb, (%rbx)
pushq $0xb
jmp 0x564f
movl $0xd, (%rbx)
pushq $0xd
jmp 0x564f
movl $0x9, (%rbx)
pushq $0x9
popq %rsi
movq %r14, %rdi
callq 0x20f0
movl (%rbx), %esi
movq %r14, %rdi
callq 0x21c0
movl $0x7ffff60f, %eax       # imm = 0x7FFFF60F
andl 0x128(%rbx), %eax
orl $0x8b0, %eax            # imm = 0x8B0
movl %eax, 0x128(%rbx)
andb $-0x1d, 0x121(%rbx)
andb $-0x1c, 0x12c(%rbx)
andb $-0x2, 0x124(%rbx)
andw $0x0, 0x136(%rbx)
movl 0x4(%rbx), %edi
xorl %esi, %esi
movq %r14, %rdx
callq 0x2200
testl %eax, %eax
jne 0x56d6
movl 0x10(%rbx), %esi
leaq 0xc0a(%rip), %rdi       # 0x62ba
xorl %eax, %eax
callq 0x2040
movq %rbx, %rdi
popq %rbx
popq %r14
popq %rbp
jmp 0x56e4
leaq 0xc59(%rip), %rdi       # 0x6323
callq 0x22a0
movl (%rbx), %esi
jmp 0x5650
leaq 0xbb3(%rip), %rdi       # 0x6290
callq 0x2170
jmp 0x56b7