#ifndef MODBUSREPOSITORY_H
#define MODBUSREPOSITORY_H
#include "GlobalDefine.h"
#include <QList>
#include <QReadWriteLock>

class CHRDataMap    ///Holding Register data map.
{
public:
    CHRDataMap(quint16 StartAddress, quint16 Length);
    quint16 mStartAddress,mEndAddress;
    quint16 mLength;
    QList<qint16> mRegistersData;

};

class CModbusRepository : public QObject
{
    Q_OBJECT
public:
    CModbusRepository();

    //Holding Registers
    int AddHRDataMap(quint16 StartAddress, quint16 Length);
    bool IsHRValid(quint16 StartAddress, quint16 Length, int *index = 0);
    QByteArray GetHRData(quint16 StartAddress, quint16 Length, bool *OK = 0);
    quint16 GetSingleReg(quint16 Address, bool *OK = 0);
    QList<qint16> GetRegs(quint16 StartAddress, quint16 Length, bool *OK = 0);
    int WriteHRData(quint16 StartAddress, quint16 Length, QByteArray Data);
    int WriteSingleReg(quint16 Address, quint16 Value);
    int WriteMultipleRegs(quint16 StartAddress, QList<qint16> Data);
    const QList<CHRDataMap> *GetRepo(){return &mHoldingRegisters;}


private:
    QList<CHRDataMap> mHoldingRegisters;
    QReadWriteLock mMutex;

signals:
    void RepoChanged(quint16 StartAddress, quint16 Length);

};

#endif // MODBUSREPOSITORY_H
