#ifndef COUNTERDEVICE_H
#define COUNTERDEVICE_H

#include <QObject>

#include "common/utils/QSerialPortUtil.h"
#include "common/utils/QKafkaUtil.h"
#include "common/utils/QByteUtil.h"
#include "common/utils/QLogUtil.h"
#include "common/utils/SettingConfig.h"
#include "protocol/CounterProtocolBM.h"

class CounterDevice : public QObject
{
    Q_OBJECT
public:
    explicit CounterDevice(QObject *parent = nullptr);
    ~CounterDevice();

    void initSerialPort();

    void setComName(QString comName);
    void setBaudRate(int baudRate);
    QString getDevCode();
    void setDevCode(QString devCode);
    void setDeviceId(QString deviceId);

    bool isSerialOpen();

private:
    QString deviceId;
    QString devCode;
    QString comName;
    int baudRate;

    QSerialPortUtil serialUtil;
    QKafkaUtil kafkaUtil;
    QByteArray dataBuff;

    CounterDataDto bench;
    QList<CounterDataDto *> hisList;

    void pushChannelRawFrame(CounterDataDto * counterData);

signals:
    void sendDataToDraw(CounterDataDto * counterData);
    void successDataCalculate(CounterDataDto * counterData);

public slots:
    void dataReceivedHandler(QByteArray data);
    void afterFramePhase(CounterDataDto * counterData);
};

#endif // COUNTERDEVICE_H
