#ifndef USERLOCK_H
#define USERLOCK_H
#include <QObject>
#include <QThread>
#include <QDebug>
#include <QSerialPort>
#include <QSerialPortInfo>

enum class lockWorkStat {
    init,
    readstat,
    open,
    close,
    check,
};

class userlock : public QThread
{
    Q_OBJECT
public:
    explicit userlock(QSerialPort *serial, QObject *parent = nullptr);

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

    quint16 Modbus_Crc(QByteArray &data, quint8 count);
    void sendData(QByteArray &sendData);
    bool readData(QByteArray *data, quint16 timeout);
    bool readLockStat(void);
    bool openLock(void);
    bool closeLock(void);
    bool checkLock(void);
};

#endif // USERLOCK_H
