//
// Created by Ht on 2021/1/9.
//

#ifndef LIBDEVCPP_POSIXSERIALPORT_H
#define LIBDEVCPP_POSIXSERIALPORT_H

#if defined(LINUX) || defined(RESPI) || defined(ANDROID) || defined(MACOS) || defined(PRODUCT)

#include <serial/SerialPort.h>

namespace jedge {
    const static int8_t ival_comm_write_try_times_ = 3;

    class JE_API PosixSerialPort :
            public SerialPort {
    protected:
        int m_hCom;
        bool m_bThread_alive = false;
        bool m_hThr_shut_event = false;

    public:
        explicit PosixSerialPort(const std::string& portName);

        bool initSerialPort(unsigned int nBaud) override;

        bool writeData(uint8_t *buff, int32_t len) override;

    protected:
        void procSerialDataEvent() override;

        void readSerialData() override;

        bool closeSerialPort() override;


    };

}

#endif
#endif //LIBDEVCPP_POSIXSERIALPORT_H
