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