#ifndef RFID_H
#define RFID_H
#include <QObject>
#include <QThread>
#include <QDebug>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QHash>
#include <QMutex>
#include <QVariant>
#include "define.h"

enum class readerWorkStat {
    init,
    setpower,
    setant,
    startreadtid,
    readid,
    sleep,
};

class rfid : public QThread
{
    Q_OBJECT
public:
    explicit rfid(QObject *parent = nullptr);

public slots:
    void slot_set_thread_stop(void);
    void slot_uartinfo_change(void);
    void slot_start_read_tid(void);
    void slot_start_read_tid_Ex(const QVariant &user);

private:
    bool threadstatus = true;
    QSerialPort *devserial;
    bool openPort = false;
    readerWorkStat workstat = readerWorkStat::init;

    bool openSerial(void);
    void sendData(QByteArray &sendData);
    bool readData(QByteArray *data, quint16 timeout);
    quint16 uiCrc16Cal(QByteArray &data, quint8 count);
    void getReadType(void);
    void setPower(void);
    void setAnt(void);
    void setStartreadtid(void);
    void readTid(void);
    quint32 tidCount;
    QList<QString> tidList;

signals:
    // 返回rfid列表
    void signal_tid_update(quint16 count, QList<QString> tidList);
    void signal_reader_run(bool stat);

    void signal_tid_update_Ex(quint16 count, QList<QString> tidList, const QVariant &user);

protected:
    void run() override;

private:
    QVariant m_user;    // 用户自定义数据
};

#endif // RFID_H
