#ifndef SERIALPORT_H
#define SERIALPORT_H

#include <QObject>
#include <QSerialPort>
#include <QSerialPortInfo>

#include "protocol.h"

class SerialPort:public QObject
{
    Q_OBJECT
public:
    enum E_CMD_TYPE{
        e_zero,
        e_forward,
        e_back
    };

    SerialPort(QObject* parent=nullptr);
    static SerialPort *instance();
    ~SerialPort();

    void sendCmd(const E_CMD_TYPE e);
    static void parserTest();
public slots:
    void slotSendData(const QByteArray&);
signals:
    void sigSendSerialPortData(const CommonData&);
protected:
    void timerEvent(QTimerEvent *event);
private slots:
    void slotReadData();
private:
    void openSp();
    void to_hex(char* in_char, int char_length, char* out_char);
    void displayPortInfo();
private:
    QSerialPort *_sp;
};

#endif // SERIALPORT_H
