|
- #pragma once
-
- #include <QByteArray>
- #include <QMutex>
- #include <QMutexLocker>
- #include <QWaitCondition>
- #include "IBuffer.h"
-
- #define MIN_FRAME_LENGTH 28
-
- class VarBuffer : public IBuffer
- {
- public:
- explicit VarBuffer(unsigned long bufLength, bool readWait, bool writeWait);
- ~VarBuffer();
-
- unsigned short read(unsigned char* buf, unsigned short length) override;
- int write(unsigned char* buf, unsigned short length) override;
- unsigned short GetFrameLength() override;
-
- private:
- unsigned long m_iReadIndex;
- unsigned long m_iWriteIndex;
-
- unsigned char* m_pBuffer;
- unsigned long m_iBufferLength;
- unsigned short m_iFrameLength; // 帧长
-
- bool m_bReadWait;
- bool m_bWriteWait;
-
- QWaitCondition m_condRead;
- QWaitCondition m_condWrite;
-
- QMutex m_mutex;
- bool m_bIsOneCycle;
-
- private:
- bool IsFull(unsigned short length) override;
- bool IsEmpty(unsigned short length) override;
- bool verifyFrameLength(unsigned char* buf, unsigned short length);
- };
|