147 lines
3.5 KiB
C++
147 lines
3.5 KiB
C++
#ifndef GVSPPARSER_H
|
|
#define GVSPPARSER_H
|
|
|
|
#include <QObject>
|
|
#include <QByteArray>
|
|
#include <QImage>
|
|
#include <QAtomicInt>
|
|
#include <cstdint>
|
|
|
|
// GVSP packet types (GigE Vision 2.1 standard)
|
|
#define GVSP_LEADER_PACKET 0x01
|
|
#define GVSP_TRAILER_PACKET 0x02
|
|
#define GVSP_PAYLOAD_PACKET 0x03
|
|
|
|
// Payload types
|
|
#define PAYLOAD_TYPE_IMAGE 0x0001
|
|
#define PAYLOAD_TYPE_BINARY 0x0003
|
|
#define PAYLOAD_TYPE_POINTCLOUD 0x8000 // Vendor-specific for point cloud data
|
|
|
|
// 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 (GigE Vision 2.1 standard - 8 bytes)
|
|
struct GVSPPacketHeader {
|
|
uint16_t status; // Status flags
|
|
uint16_t block_id; // Block ID (frame number)
|
|
uint8_t packet_format; // Packet type: 0x01=Leader, 0x02=Trailer, 0x03=Payload
|
|
uint8_t reserved; // Reserved byte
|
|
uint16_t packet_id; // Packet ID within block
|
|
};
|
|
|
|
// 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;
|
|
};
|
|
|
|
// Point cloud data leader (vendor-specific, payload_type = 0x8000)
|
|
struct GVSPPointCloudDataLeader {
|
|
uint16_t reserved;
|
|
uint16_t payload_type; // 0x8000
|
|
uint32_t timestamp_high;
|
|
uint32_t timestamp_low;
|
|
uint32_t data_size; // Total size of point cloud data
|
|
};
|
|
|
|
// Point cloud data trailer
|
|
struct GVSPPointCloudDataTrailer {
|
|
uint32_t reserved;
|
|
uint16_t payload_type; // 0x8000
|
|
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 pointCloudDataReceived(const QByteArray &cloudData, 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();
|
|
void processPointCloudData();
|
|
|
|
private:
|
|
// Reception state
|
|
bool m_isReceiving;
|
|
int m_dataType; // 0=unknown, 1=image, 3=depth, 4=pointcloud
|
|
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;
|
|
|
|
// Async processing control
|
|
QAtomicInt m_imageProcessingCount;
|
|
};
|
|
|
|
#endif // GVSPPARSER_H
|