#ifndef COUNTERDEVICE_H
#define COUNTERDEVICE_H

#include <QObject>
#include <QUdpSocket>

#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/CounterProtocolXH.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;

    QMap<QString, qlonglong> bench;
    QList<CounterDataDto *> hisList;

    void afterFramePhase(CounterDataDto * counterData);

signals:
    void sendDataToDraw(CounterDataDto * counterData);

public slots:
    void dataReceivedHandler(QByteArray data);

};

#endif // COUNTERDEVICE_H
