// File: /workspace/github_c_makefile_star2_O0/patriciogonzalezvivo[P]tprint/src/thermalPrinter.cpp
// Function: ThermalPrinter::open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
bool ThermalPrinter::open(const std::string& _portName){
    try {
        port = new serial::Serial( _portName,
                                   BAUDRATE,
                                   serial::Timeout::simpleTimeout(1000),
                                   serial::eightbits,
                                   serial::parity_none,
                                   serial::stopbits_one,
                                   serial::flowcontrol_none );
    }
    
    catch (const std::exception& exc){
        std::cout << "ThermalPrinter:: Fail to open" << exc.what() << std::endl;
        bConnected = false;
        return bConnected;
    }
    
    bConnected = true;
    usleep(50000);
    reset();
    usleep(50000);
    
    setControlParameter(7, 100, 2);
    // Set “max heating dots”,”heating time”, “heating interval”
    // n1 = 0-255 Max printing dots,Unit(8dots),Default:7(64 dots)
    // n2 = 3-255 Heating time,Unit(10us),Default:80(800us)
    // n3 = 0-255 Heating interval,Unit(10us),Default:2(20us)
    // The more max heting dots, the more peak current will cost
    // whenprinting, the faster printing speed. The max heating dots is 8*(n1+1)
    // The more heating time, the more density , but the slower printing speed. If heating time is too short, blank page may occur.
    // The more heating interval, the more clear, but the slower
    
    // printDensity (def. 14) / printBreakTime (def.40)
    // setPrintDensity(14,40);
    setStatus(true);

    port->flushOutput();
    
    feed();

    return bConnected;
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x78(%rsp)
movq %rsi, 0x70(%rsp)
movq 0x78(%rsp), %rax
movq %rax, 0x38(%rsp)
movl $0x10, %edi
callq 0xd3c0
movq %rax, 0x40(%rsp)
jmp 0x1b50c
movq 0x70(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x50(%rsp), %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x2caf0
jmp 0x1b527
movq 0x30(%rsp), %rsi
movq 0x40(%rsp), %rdi
movl 0x60(%rsp), %ecx
movq %rsp, %rax
movl %ecx, 0x10(%rax)
movups 0x50(%rsp), %xmm0
movups %xmm0, (%rax)
movl $0x0, 0x18(%rax)
movl $0x4b00, %edx           # imm = 0x4B00
movl $0x8, %ecx
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0x11560
jmp 0x1b564
movq 0x38(%rsp), %rax
movq 0x40(%rsp), %rcx
movq %rcx, 0x8(%rax)
jmp 0x1b64c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
jmp 0x1b5a4
movq 0x40(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
movl $0x10, %esi
callq 0xd3d0
movl 0x64(%rsp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x1b6d5
movq 0x68(%rsp), %rdi
callq 0xd160
movq %rax, 0x48(%rsp)
movq 0x1a9f5(%rip), %rdi     # 0x35fc0
leaq 0x12469(%rip), %rsi     # 0x2da3b
callq 0xd3a0
movq %rax, 0x28(%rsp)
jmp 0x1b5de
movq 0x48(%rsp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq 0x28(%rsp), %rdi
movq %rax, %rsi
callq 0xd3a0
movq %rax, 0x20(%rsp)
jmp 0x1b600
movq 0x20(%rsp), %rdi
movq 0x1a99c(%rip), %rsi     # 0x35fa8
callq 0xd3f0
jmp 0x1b613
movq 0x38(%rsp), %rax
movb $0x0, 0x10(%rax)
movb 0x10(%rax), %al
andb $0x1, %al
movb %al, 0x87(%rsp)
callq 0xd6d0
jmp 0x1b6c4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
callq 0xd6d0
jmp 0x1b647
jmp 0x1b6d5
movq 0x38(%rsp), %rax
movb $0x1, 0x10(%rax)
movl $0xc350, %edi           # imm = 0xC350
callq 0xd5f0
movq 0x38(%rsp), %rdi
callq 0x1b6f0
movl $0xc350, %edi           # imm = 0xC350
callq 0xd5f0
movq 0x38(%rsp), %rdi
movl $0x7, %esi
movl $0x64, %edx
movl $0x2, %ecx
callq 0x1b720
movq 0x38(%rsp), %rdi
movl $0x1, %esi
callq 0x1b790
movq 0x38(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x12780
movq 0x38(%rsp), %rdi
callq 0x1b7e0
movq 0x38(%rsp), %rax
movb 0x10(%rax), %al
andb $0x1, %al
movb %al, 0x87(%rsp)
movb 0x87(%rsp), %al
andb $0x1, %al
addq $0x88, %rsp
retq
movq 0x68(%rsp), %rdi
callq 0xd750
movq %rax, %rdi
callq 0xff20
nopw (%rax,%rax)