#ifndef COUNTERPROTOCOLBM_H
#define COUNTERPROTOCOLBM_H

#include <QObject>

#include "dto/CounterDataDto.h"

static const QString COUNTER_FRAME_HEAD = "$GL"; // 帧头
static const QString COUNTER_FRAME_TAIL = "\r\n"; // 帧尾
static const QString COUNTER_FRAME_CONTENT_SEP = ","; // 帧内分隔符
static const QString COUNTER_FRAME_SUM_SEP = "*"; // 异或和字段的分隔符

static const int COUNTER_FRAME_SUM_LENGTH = 2;
static const int COUNTER_FRAME_SUB_COUNT = 8;
static const int COUNTER_FRAME_SUB_MIN_SIZE = 2;
static const int COUNTER_FRAME_MIN_LENGTH = COUNTER_FRAME_HEAD.length() +
                                            COUNTER_FRAME_TAIL.length() +
                                            COUNTER_FRAME_SUB_COUNT * COUNTER_FRAME_SUB_MIN_SIZE +
                                            1 + COUNTER_FRAME_SUM_LENGTH;

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

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

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

#endif // COUNTERPROTOCOLBM_H
