This commit is contained in:
Gary Talent 2024-10-29 00:45:42 -05:00
parent 4957bec1c6
commit 215f9b4d1d
2 changed files with 22 additions and 25 deletions

View File

@ -8,8 +8,8 @@
#include <QNetworkReply> #include <QNetworkReply>
#include <QSettings> #include <QSettings>
#include <string_view>
#include "consts.hpp"
#include "settingsdata.hpp" #include "settingsdata.hpp"
#include "cameraclient.hpp" #include "cameraclient.hpp"
@ -43,6 +43,16 @@ void CameraClient::setPreset(int preset) {
} }
} }
void CameraClient::reboot() {
post("/cgi-bin/param.cgi?post_reboot");
emit pollFailed();
}
void CameraClient::setBaseUrl() {
auto const [host, port] = getCameraConnectionData();
m_baseUrl = QString("http://%1:%2").arg(host, QString::number(port));
}
void CameraClient::setBrightness(int val) { void CameraClient::setBrightness(int val) {
if (val > -1) { if (val > -1) {
get(QString("/cgi-bin/ptzctrl.cgi?post_image_value&bright&%1").arg(val)); get(QString("/cgi-bin/ptzctrl.cgi?post_image_value&bright&%1").arg(val));
@ -73,33 +83,22 @@ void CameraClient::setHue(int val) {
} }
} }
void CameraClient::reboot() {
post("/cgi-bin/param.cgi?post_reboot");
emit pollFailed();
}
void CameraClient::setBaseUrl() {
auto const [host, port] = getCameraConnectionData();
m_baseUrl = QString("http://%1:%2").arg(host, QString::number(port));
}
void CameraClient::get(QString const&urlExt) { void CameraClient::get(QString const&urlExt) {
QUrl url(QString(m_baseUrl) + urlExt); QUrl const url{QString{m_baseUrl} + urlExt};
QNetworkRequest rqst(url); QNetworkRequest rqst{url};
auto const reply = m_nam->get(rqst); auto const reply = m_nam->get(rqst);
connect(reply, &QIODevice::readyRead, reply, &QObject::deleteLater); connect(reply, &QIODevice::readyRead, reply, &QObject::deleteLater);
} }
void CameraClient::post(QString const&urlExt) { void CameraClient::post(QString const&urlExt) {
QUrl url(QString(m_baseUrl) + urlExt); QNetworkRequest const rqst{QUrl{QString{m_baseUrl} + urlExt}};
QNetworkRequest rqst(url);
auto const reply = m_nam->post(rqst, QByteArray{}); auto const reply = m_nam->post(rqst, QByteArray{});
connect(reply, &QIODevice::readyRead, reply, &QObject::deleteLater); connect(reply, &QIODevice::readyRead, reply, &QObject::deleteLater);
} }
void CameraClient::poll() { void CameraClient::poll() {
QUrl url(QString(m_baseUrl) + "/cgi-bin/param.cgi?get_device_conf"); QUrl const url{QString{m_baseUrl} + "/cgi-bin/param.cgi?get_device_conf"};
QNetworkRequest rqst(url); QNetworkRequest const rqst{url};
m_pollingNam->get(rqst); m_pollingNam->get(rqst);
} }

View File

@ -12,8 +12,6 @@
#include <QObject> #include <QObject>
#include <QTimer> #include <QTimer>
#include "consts.hpp"
class CameraClient: public QObject { class CameraClient: public QObject {
Q_OBJECT Q_OBJECT
private: private:
@ -29,6 +27,12 @@ class CameraClient: public QObject {
void setPreset(int preset); void setPreset(int preset);
void reboot();
public slots:
void setBaseUrl();
private:
void setBrightness(int val); void setBrightness(int val);
void setSaturation(int val); void setSaturation(int val);
@ -39,12 +43,6 @@ class CameraClient: public QObject {
void setHue(int val); void setHue(int val);
void reboot();
public slots:
void setBaseUrl();
private:
void get(QString const&url); void get(QString const&url);
void post(QString const&url); void post(QString const&url);