#ifndef COUNTERPROTOCOLXH_H
#define COUNTERPROTOCOLXH_H

#include <QObject>

#include "dto/CounterDataDto.h"

static const QString COUNTER_FRAME_HEAD = "$XHTS"; // 帧头
static const QString COUNTER_FRAME_TAIL = "\r\n";
static const QString COUNTER_FRAME_CONTENT_SEP = "|"; // 帧内分隔符

static const int COUNTER_FRAME_DEVCODE_LENGTH = 8;
static const int COUNTER_FRAME_TIME_LENGTH = 12;
static const int COUNTER_FRAME_DTLEN_LENGTH = 3;
static const int COUNTER_FRAME_SUM_LENGTH = 1;
static const int COUNTER_MESSURE_CHANNEL = 16;
static const int COUNTER_FRAME_DATA_LENGTH = 16 * 16 + 20;

static const int COUNTER_FRAME_MIN_LENGTH = COUNTER_FRAME_HEAD.length() +
        COUNTER_FRAME_DEVCODE_LENGTH +
        COUNTER_FRAME_TIME_LENGTH +
        COUNTER_FRAME_DTLEN_LENGTH +
        COUNTER_FRAME_SUM_LENGTH +
        COUNTER_FRAME_DATA_LENGTH;

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

    // 解析计数器测量数据
    static bool parseMessureData(QByteArray rawData, CounterDataDto * counterData);
    static QList<QByteArray> extractFrameList(QByteArray rawData);

    // 检测帧格式，帧头帧尾
    static bool checkFrame(QByteArray rawData);
signals:

};

#endif // COUNTERPROTOCOLXH_H
