122 lines
2.5 KiB
C++
122 lines
2.5 KiB
C++
#ifndef GVSPPARSER_H
|
|
#define GVSPPARSER_H
|
|
|
|
#include <QObject>
|
|
#include <QByteArray>
|
|
#include <QImage>
|
|
#include <cstdint>
|
|
|
|
// GVSP packet types
|
|
#define GVSP_LEADER_PACKET 0x01
|
|
#define GVSP_PAYLOAD_PACKET 0x02
|
|
#define GVSP_TRAILER_PACKET 0x03
|
|
|
|
// Payload types
|
|
#define PAYLOAD_TYPE_IMAGE 0x0001
|
|
#define PAYLOAD_TYPE_BINARY 0x0003
|
|
|
|
// Image format
|
|
#define PIXEL_FORMAT_12BIT_GRAY 0x010C0001
|
|
|
|
// Image dimensions
|
|
#define IMAGE_WIDTH 1224
|
|
#define IMAGE_HEIGHT 1024
|
|
|
|
#pragma pack(push, 1)
|
|
|
|
// GVSP packet header
|
|
struct GVSPPacketHeader {
|
|
uint16_t status;
|
|
uint16_t block_id;
|
|
uint32_t packet_fmt_id;
|
|
};
|
|
|
|
// Image data leader
|
|
struct GVSPImageDataLeader {
|
|
uint16_t reserved;
|
|
uint16_t payload_type;
|
|
uint32_t timestamp_high;
|
|
uint32_t timestamp_low;
|
|
uint32_t pixel_format;
|
|
uint32_t size_x;
|
|
uint32_t size_y;
|
|
uint32_t offset_x;
|
|
uint32_t offset_y;
|
|
uint16_t padding_x;
|
|
uint16_t padding_y;
|
|
};
|
|
|
|
// Image data trailer
|
|
struct GVSPImageDataTrailer {
|
|
uint32_t reserved;
|
|
uint16_t payload_type;
|
|
uint32_t size_y;
|
|
};
|
|
|
|
// Binary data leader (for depth data)
|
|
struct GVSPBinaryDataLeader {
|
|
uint16_t reserved;
|
|
uint16_t payload_type;
|
|
uint32_t timestamp_high;
|
|
uint32_t timestamp_low;
|
|
uint32_t file_size;
|
|
uint32_t name_len;
|
|
char file_name[256];
|
|
};
|
|
|
|
// Binary data trailer
|
|
struct GVSPBinaryDataTrailer {
|
|
uint32_t reserved;
|
|
uint16_t payload_type;
|
|
uint32_t checksum;
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
class GVSPParser : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit GVSPParser(QObject *parent = nullptr);
|
|
~GVSPParser();
|
|
|
|
void parsePacket(const QByteArray &packet);
|
|
void reset();
|
|
|
|
signals:
|
|
void imageReceived(const QImage &image, uint32_t blockId);
|
|
void depthDataReceived(const QByteArray &depthData, uint32_t blockId);
|
|
void parseError(const QString &error);
|
|
|
|
private:
|
|
void handleLeaderPacket(const uint8_t *data, size_t size);
|
|
void handlePayloadPacket(const uint8_t *data, size_t size);
|
|
void handleTrailerPacket(const uint8_t *data, size_t size);
|
|
|
|
void processImageData();
|
|
void processDepthData();
|
|
|
|
private:
|
|
// Reception state
|
|
bool m_isReceiving;
|
|
int m_dataType; // 0=unknown, 1=image, 3=depth
|
|
uint32_t m_currentBlockId;
|
|
|
|
// Data buffer
|
|
QByteArray m_dataBuffer;
|
|
size_t m_expectedSize;
|
|
size_t m_receivedSize;
|
|
|
|
// Image info
|
|
uint32_t m_imageWidth;
|
|
uint32_t m_imageHeight;
|
|
uint32_t m_pixelFormat;
|
|
|
|
// Statistics
|
|
uint32_t m_lastBlockId;
|
|
int m_packetCount;
|
|
};
|
|
|
|
#endif // GVSPPARSER_H
|