#ifndef DEVICECONNECTION_H #define DEVICECONNECTION_H #include "DataStructure.h" #include #include #include #include #include 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; explicit DeviceConnection(QObject *parent = nullptr); void setH264FrameCallback(H264FrameCallback &&callback); void connect(const QString &address); void start(); void requestOpenDoorArea(); void updateOpenDoorAreaPoints(AreaWay way, const QList &points); void requestShieldedArea(); void updateShieldedAreaPoints(bool enabled, const QList &points); void requestAntiClipArea(); void updateAntiClipAreaPoints(bool enabled, const QList &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 &points); void currentShieldedAreaChanged(bool enabled, const QList &points); void currentAntiClipAreaChanged(bool enabled, const QList &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 m_uploadBuffer; H264FrameCallback m_frameCallback; std::queue> m_requests; }; #endif // DEVICECONNECTION_H