AntiClipSettings/DeviceConnection.h

70 lines
2.2 KiB
C
Raw Normal View History

2024-08-13 20:06:10 +08:00
#ifndef DEVICECONNECTION_H
#define DEVICECONNECTION_H
2024-08-16 16:24:15 +08:00
#include "DataStructure.h"
2024-08-13 20:06:10 +08:00
#include <QObject>
2024-08-14 20:01:38 +08:00
#include <QQmlEngine>
2024-08-16 16:24:15 +08:00
#include <QTcpSocket>
2024-08-14 20:01:38 +08:00
#include <queue>
2024-08-13 20:06:10 +08:00
#include <string_view>
2024-08-16 16:24:15 +08:00
class NetworkInfomation;
2024-08-13 20:06:10 +08:00
class DeviceConnection : public QObject {
Q_OBJECT
2024-08-14 20:01:38 +08:00
QML_ELEMENT
2024-08-16 16:24:15 +08:00
QML_UNCREATABLE("Only created in C++...")
2024-08-14 20:01:38 +08:00
2024-08-13 20:06:10 +08:00
public:
2024-08-14 20:01:38 +08:00
enum Resolution {
Video_360P = 0,
Video_720P,
};
enum AreaWay {
Diabled = 0,
2024-08-16 16:24:15 +08:00
FullArea,
2024-08-14 20:01:38 +08:00
Quadrangle, // 四边形
};
Q_ENUM(AreaWay)
2024-08-13 20:06:10 +08:00
using H264FrameCallback = std::function<void(const char *data, uint32_t size)>;
explicit DeviceConnection(QObject *parent = nullptr);
void setH264FrameCallback(H264FrameCallback &&callback);
2024-08-16 16:24:15 +08:00
void connect(const QString &address);
2024-08-13 20:06:10 +08:00
void start();
void requestOpenDoorArea();
2024-08-16 16:24:15 +08:00
void updateOpenDoorAreaPoints(AreaWay way, const QList<QPointF> &points);
2024-08-14 20:01:38 +08:00
void requestShieldedArea();
void updateShieldedAreaPoints(bool enabled, const QList<QPointF> &points);
void requestAntiClipArea();
void updateAntiClipAreaPoints(bool enabled, const QList<QPointF> &points);
void requestResolution(Resolution resolution);
2024-08-16 16:24:15 +08:00
void requestNetworkInfomation();
void updateNetworkInfomation(bool dhcp, const QString &ip, const QString &netmask, const QString &gateway);
2024-08-13 20:06:10 +08:00
signals:
2024-08-16 16:24:15 +08:00
void currentOpenDoorAreaChanged(AreaWay way, const QList<QPointF> &points);
2024-08-14 20:01:38 +08:00
void currentShieldedAreaChanged(bool enabled, const QList<QPointF> &points);
void currentAntiClipAreaChanged(bool enabled, const QList<QPointF> &points);
2024-08-16 16:24:15 +08:00
void currentNetworkInfomationChanged(const NetworkInfomation &info);
2024-08-13 20:06:10 +08:00
protected:
void onConnected();
void onH264ReadyRead();
void onCommandReadyRead();
void handleCommand(const std::string_view &replyText);
2024-08-16 16:24:15 +08:00
void onErrorOccurred(QAbstractSocket::SocketError socketError);
2024-08-13 20:06:10 +08:00
private:
QTcpSocket *m_commandSocket = nullptr;
QTcpSocket *m_h264Socket = nullptr;
bool m_receivedFirstJsonReply = false;
QByteArray m_commandBuffer;
QByteArray m_h264Buffer;
H264FrameCallback m_frameCallback;
2024-08-14 20:01:38 +08:00
std::queue<std::function<void()>> m_requests;
2024-08-13 20:06:10 +08:00
};
#endif // DEVICECONNECTION_H