实现向设备发起防夹灵敏度设置,恢复出厂设置请求。

This commit is contained in:
luocai 2024-12-04 15:23:42 +08:00
parent 77dd027ff7
commit fb27b0fa57
7 changed files with 165 additions and 36 deletions

View File

@ -127,7 +127,24 @@ void Application::setCurrentAntiClipAreaEnabled(bool enabled) {
emit currentAntiClipAreaEnabledChanged(); emit currentAntiClipAreaEnabledChanged();
if (!m_device.expired()) { if (!m_device.expired()) {
auto device = m_device.lock(); auto device = m_device.lock();
device->updateAntiClipAreaPoints(m_currentAntiClipAreaEnabled, m_currentAntiClipAreaPoints); device->updateAntiClipAreaPoints(m_currentAntiClipAreaEnabled, m_currentAntiClipAreaPoints,
m_currentAntiClipSensitivity);
}
}
}
int Application::currentAntiClipSensitivity() const {
return m_currentAntiClipSensitivity;
}
void Application::setCurrentAntiClipSensitivity(int sensitivity) {
if (m_currentAntiClipSensitivity != sensitivity) {
m_currentAntiClipSensitivity = sensitivity;
emit currentAntiClipSensitivityChanged();
if (!m_device.expired()) {
auto device = m_device.lock();
device->updateAntiClipAreaPoints(m_currentAntiClipAreaEnabled, m_currentAntiClipAreaPoints,
m_currentAntiClipSensitivity);
} }
} }
} }
@ -153,7 +170,7 @@ void Application::updateOpenDoorAreaPoints(const QList<QPointF> &points) {
void Application::updateAntiClipAreaPoints(const QList<QPointF> &points) { void Application::updateAntiClipAreaPoints(const QList<QPointF> &points) {
if (!m_device.expired()) { if (!m_device.expired()) {
auto device = m_device.lock(); auto device = m_device.lock();
device->updateAntiClipAreaPoints(m_currentAntiClipAreaEnabled, points); device->updateAntiClipAreaPoints(m_currentAntiClipAreaEnabled, points, m_currentAntiClipSensitivity);
} }
} }
@ -260,6 +277,7 @@ void Application::connectToDevice(int index) {
m_currentShieldedAreaPoints = info.shieldedArea; m_currentShieldedAreaPoints = info.shieldedArea;
m_currentAntiClipAreaEnabled = info.antiClipAreaEnabled; m_currentAntiClipAreaEnabled = info.antiClipAreaEnabled;
m_currentAntiClipAreaPoints = info.antiClipArea; m_currentAntiClipAreaPoints = info.antiClipArea;
m_currentAntiClipSensitivity = info.antiClipSensitivity;
m_currentNetworkInfomation = device->networkInfomation(); m_currentNetworkInfomation = device->networkInfomation();
m_currentFirmware = device->infomation().firmwareVersion; m_currentFirmware = device->infomation().firmwareVersion;
m_currentDeviceConnected = device->isConnected(); m_currentDeviceConnected = device->isConnected();
@ -273,6 +291,7 @@ void Application::connectToDevice(int index) {
emit currentOpenDoorAreaWayChanged(); emit currentOpenDoorAreaWayChanged();
emit currentShieldedAreaEnabledChanged(); emit currentShieldedAreaEnabledChanged();
emit currentAntiClipAreaEnabledChanged(); emit currentAntiClipAreaEnabledChanged();
emit currentAntiClipSensitivityChanged();
emit currentNetworkInfomationChanged(); emit currentNetworkInfomationChanged();
} }
emit currentFirmwareChanged(); emit currentFirmwareChanged();
@ -306,6 +325,16 @@ void Application::upgradeDevice(const QString &file) {
} }
} }
void Application::resetDevice() {
if (m_device.expired()) return;
auto device = m_device.lock();
if (device->isConnected()) {
device->requestReset();
} else {
emit newMessage(2, "恢复出厂设置", "设备已离线,请重新连接设备!");
}
}
void Application::onDeviceOpenDoorArea(DeviceConnection::AreaWay way, const QList<QPointF> &points) { void Application::onDeviceOpenDoorArea(DeviceConnection::AreaWay way, const QList<QPointF> &points) {
setCurrentOpenDoorAreaWay(way); setCurrentOpenDoorAreaWay(way);
setCurrentOpenDoorAreaPoints(points); setCurrentOpenDoorAreaPoints(points);
@ -323,9 +352,10 @@ void Application::onDeviceShieldedArea(bool enabled, const QList<QPointF> &point
setCurrentShieldedAreaPoints(points); setCurrentShieldedAreaPoints(points);
} }
void Application::onDeviceAntiClipArea(bool enabled, const QList<QPointF> &points) { void Application::onDeviceAntiClipArea(bool enabled, const QList<QPointF> &points, int sensitivity) {
setCurrentAntiClipAreaEnabled(enabled); setCurrentAntiClipAreaEnabled(enabled);
setCurrentAntiClipAreaPoints(points); setCurrentAntiClipAreaPoints(points);
setCurrentAntiClipSensitivity(sensitivity);
} }
void Application::onDeviceNetworkInfomation(const NetworkInfomation &info) { void Application::onDeviceNetworkInfomation(const NetworkInfomation &info) {

View File

@ -34,6 +34,7 @@ class Application : public QObject {
setCurrentShieldedAreaPoints NOTIFY currentShieldedAreaPointsChanged) setCurrentShieldedAreaPoints NOTIFY currentShieldedAreaPointsChanged)
Q_PROPERTY(bool currentAntiClipAreaEnabled READ currentAntiClipAreaEnabled WRITE setCurrentAntiClipAreaEnabled Q_PROPERTY(bool currentAntiClipAreaEnabled READ currentAntiClipAreaEnabled WRITE setCurrentAntiClipAreaEnabled
NOTIFY currentAntiClipAreaEnabledChanged) NOTIFY currentAntiClipAreaEnabledChanged)
Q_PROPERTY(int currentAntiClipSensitivity READ currentAntiClipSensitivity WRITE setCurrentAntiClipSensitivity NOTIFY currentAntiClipSensitivityChanged)
Q_PROPERTY(QList<QPointF> currentAntiClipAreaPoints READ currentAntiClipAreaPoints WRITE Q_PROPERTY(QList<QPointF> currentAntiClipAreaPoints READ currentAntiClipAreaPoints WRITE
setCurrentAntiClipAreaPoints NOTIFY currentAntiClipAreaPointsChanged) setCurrentAntiClipAreaPoints NOTIFY currentAntiClipAreaPointsChanged)
Q_PROPERTY( Q_PROPERTY(
@ -65,6 +66,8 @@ public:
bool currentAntiClipAreaEnabled() const; bool currentAntiClipAreaEnabled() const;
void setCurrentAntiClipAreaEnabled(bool enabled); void setCurrentAntiClipAreaEnabled(bool enabled);
int currentAntiClipSensitivity() const;
void setCurrentAntiClipSensitivity(int sensitivity);
QList<QPointF> currentAntiClipAreaPoints() const; QList<QPointF> currentAntiClipAreaPoints() const;
void setCurrentAntiClipAreaPoints(const QList<QPointF> &points); void setCurrentAntiClipAreaPoints(const QList<QPointF> &points);
@ -81,6 +84,7 @@ public:
const QString &gateway, const QString &dns); const QString &gateway, const QString &dns);
Q_INVOKABLE void connectToDevice(int index); Q_INVOKABLE void connectToDevice(int index);
Q_INVOKABLE void upgradeDevice(const QString &file); Q_INVOKABLE void upgradeDevice(const QString &file);
Q_INVOKABLE void resetDevice();
Q_INVOKABLE void startSearchDevice(); Q_INVOKABLE void startSearchDevice();
int exec(); int exec();
@ -94,6 +98,7 @@ signals:
void currentOpenDoorAreaWayChanged(); void currentOpenDoorAreaWayChanged();
void currentShieldedAreaEnabledChanged(); void currentShieldedAreaEnabledChanged();
void currentAntiClipAreaEnabledChanged(); void currentAntiClipAreaEnabledChanged();
void currentAntiClipSensitivityChanged();
void currentNetworkInfomationChanged(); void currentNetworkInfomationChanged();
void currentFirmwareChanged(); void currentFirmwareChanged();
void currentDeviceConnectedChanged(); void currentDeviceConnectedChanged();
@ -108,7 +113,7 @@ protected:
void onDeviceFlipChanged(bool flip); void onDeviceFlipChanged(bool flip);
void onDeviceOpenDoorArea(DeviceConnection::AreaWay way, const QList<QPointF> &points); void onDeviceOpenDoorArea(DeviceConnection::AreaWay way, const QList<QPointF> &points);
void onDeviceShieldedArea(bool enabled, const QList<QPointF> &points); void onDeviceShieldedArea(bool enabled, const QList<QPointF> &points);
void onDeviceAntiClipArea(bool enabled, const QList<QPointF> &points); void onDeviceAntiClipArea(bool enabled, const QList<QPointF> &points, int sensitivity);
void onDeviceNetworkInfomation(const NetworkInfomation &info); void onDeviceNetworkInfomation(const NetworkInfomation &info);
void onDeviceFirmware(const QString &firmware); void onDeviceFirmware(const QString &firmware);
void onDeviceConnected(); void onDeviceConnected();
@ -128,6 +133,7 @@ private:
bool m_currentShieldedAreaEnabled = false; bool m_currentShieldedAreaEnabled = false;
QList<QPointF> m_currentShieldedAreaPoints; QList<QPointF> m_currentShieldedAreaPoints;
bool m_currentAntiClipAreaEnabled = false; bool m_currentAntiClipAreaEnabled = false;
int m_currentAntiClipSensitivity = 1;
QList<QPointF> m_currentAntiClipAreaPoints; QList<QPointF> m_currentAntiClipAreaPoints;
NetworkInfomation m_currentNetworkInfomation; NetworkInfomation m_currentNetworkInfomation;
QString m_currentFirmware; QString m_currentFirmware;

View File

@ -210,15 +210,16 @@ void DeviceConnection::requestAntiClipArea() {
m_requests.push(task); m_requests.push(task);
} }
void DeviceConnection::updateAntiClipAreaPoints(bool enabled, const QList<QPointF> &points) { void DeviceConnection::updateAntiClipAreaPoints(bool enabled, const QList<QPointF> &points, int sensitivity) {
Task task; Task task;
task.command = "a03opendoor5_setdata"; task.command = "a03opendoor5_setdata";
task.task = [this, enabled, points]() { task.task = [this, enabled, points, sensitivity]() {
boost::json::object request; boost::json::object request;
request["func"] = "a03opendoor5_setdata"; request["func"] = "a03opendoor5_setdata";
request["deviceid"] = "0"; request["deviceid"] = "0";
boost::json::object data; boost::json::object data;
data["value"] = enabled ? "1" : "0"; data["value"] = enabled ? "1" : "0";
data["sensitivity"] = std::to_string(sensitivity);
boost::json::array pointArray; boost::json::array pointArray;
for (auto &p : points) { for (auto &p : points) {
boost::json::object point; boost::json::object point;
@ -433,6 +434,28 @@ void DeviceConnection::requestOta(const QString &firmware, const QString &file)
m_requests.push(task); m_requests.push(task);
} }
void DeviceConnection::requestReset() {
Task task;
task.command = "a12factory_setdata";
task.task = [this]() {
boost::json::object request;
request["func"] = "a12factory_setdata";
request["deviceid"] = "0";
boost::json::object data;
data["value"] = "1";
request["data"] = std::move(data);
auto text = boost::json::serialize(request);
m_commandSocket->write(text.data(), text.size());
};
task.future = std::make_shared<QFutureInterface<bool>>();
if (m_requests.empty()) {
task.task();
}
auto ret = task.future->future();
m_requests.push(task);
}
void DeviceConnection::transferBinContent() { void DeviceConnection::transferBinContent() {
constexpr int SliceSize = 1024; constexpr int SliceSize = 1024;
constexpr int WaitMd5CheckTime = 3000; // ms constexpr int WaitMd5CheckTime = 3000; // ms
@ -545,7 +568,10 @@ QString DeviceConnection::handleCommand(const std::string_view &replyText, const
} }
m_infomation.antiClipAreaEnabled = value == "1"; m_infomation.antiClipAreaEnabled = value == "1";
m_infomation.antiClipArea = points; m_infomation.antiClipArea = points;
emit antiClipAreaChanged(value == "1", points); if (data.contains("sensitivity")) {
m_infomation.antiClipSensitivity = std::stoi(static_cast<std::string>(data.at("sensitivity").as_string()));
}
emit antiClipAreaChanged(value == "1", points, m_infomation.antiClipSensitivity);
} else if (function == "netconfig_getdata") { } else if (function == "netconfig_getdata") {
auto &data = reply.at("data").as_object(); auto &data = reply.at("data").as_object();
m_networkInfomation.dhcp = data.at("type").as_string() == "dhcp"; m_networkInfomation.dhcp = data.at("type").as_string() == "dhcp";
@ -669,6 +695,8 @@ QString DeviceConnection::handleCommand(const std::string_view &replyText, const
} }
} }
requestVideoInformation(); requestVideoInformation();
} else if (function == "a12factory_setdata") {
LOG(info) << "device factory reset";
} else { } else {
LOG(warning) << "unknown reply: " << replyText; LOG(warning) << "unknown reply: " << replyText;
} }

View File

@ -47,6 +47,7 @@ public:
QList<QPointF> antiClipArea; QList<QPointF> antiClipArea;
bool antiClipAreaEnabled; bool antiClipAreaEnabled;
int antiClipSensitivity = 1;
}; };
Q_ENUM(AreaWay) Q_ENUM(AreaWay)
@ -67,7 +68,7 @@ public:
void requestShieldedArea(); void requestShieldedArea();
void updateShieldedAreaPoints(bool enabled, const QList<QPointF> &points); void updateShieldedAreaPoints(bool enabled, const QList<QPointF> &points);
void requestAntiClipArea(); void requestAntiClipArea();
void updateAntiClipAreaPoints(bool enabled, const QList<QPointF> &points); void updateAntiClipAreaPoints(bool enabled, const QList<QPointF> &points, int sensitivity);
void requestResolution(Resolution resolution); void requestResolution(Resolution resolution);
void requestNetworkInfomation(); void requestNetworkInfomation();
QFuture<bool> updateNetworkInfomation(bool dhcp, const QString &ip, const QString &netmask, const QString &gateway, QFuture<bool> updateNetworkInfomation(bool dhcp, const QString &ip, const QString &netmask, const QString &gateway,
@ -87,13 +88,14 @@ public:
* @param file * @param file
*/ */
void requestOta(const QString &firmware, const QString &file); void requestOta(const QString &firmware, const QString &file);
void requestReset();
signals: signals:
void connected(); void connected();
void disconnected(); void disconnected();
void openDoorAreaChanged(AreaWay way, const QList<QPointF> &points); void openDoorAreaChanged(AreaWay way, const QList<QPointF> &points);
void shieldedAreaChanged(bool enabled, const QList<QPointF> &points); void shieldedAreaChanged(bool enabled, const QList<QPointF> &points);
void antiClipAreaChanged(bool enabled, const QList<QPointF> &points); void antiClipAreaChanged(bool enabled, const QList<QPointF> &points, int sensitivity);
void rotationChanged(int rotation); void rotationChanged(int rotation);
void flipChanged(bool flip); void flipChanged(bool flip);
void networkInfomationChanged(const NetworkInfomation &info); void networkInfomationChanged(const NetworkInfomation &info);

View File

@ -16,6 +16,7 @@ Item {
property color antiClipAreaColor: "blue" property color antiClipAreaColor: "blue"
property var antiClipAreaPoints: [] property var antiClipAreaPoints: []
property bool antiClipAreaEnabled: false property bool antiClipAreaEnabled: false
property int antiClipSensitivity: 1
property alias flip: flipSwitch.checked property alias flip: flipSwitch.checked
property alias videoRotation: rotateComboBox.currentIndex property alias videoRotation: rotateComboBox.currentIndex
@ -241,19 +242,18 @@ Item {
} }
} }
} }
Grid { GridLayout {
id: controlBar id: controlBar
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
columns: 2 columns: 4
spacing: 10
verticalItemAlignment: Qt.AlignVCenter
Label { text: qsTr("图像: ") } Label { text: qsTr("图像: ") }
Row { Row {
enabled: root.enabled enabled: root.enabled
Layout.columnSpan: 3
Label { Label {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
text: qsTr("旋转") text: qsTr("旋转")
@ -283,6 +283,7 @@ Item {
} }
Row { Row {
enabled: root.enabled enabled: root.enabled
Layout.columnSpan: 3
RadioButton { RadioButton {
text: "关闭" text: "关闭"
checked: App.currentOpenDoorAreaWay ==DeviceConnection.Diabled checked: App.currentOpenDoorAreaWay ==DeviceConnection.Diabled
@ -310,6 +311,7 @@ Item {
Label {text: qsTr("防夹区域: ")} Label {text: qsTr("防夹区域: ")}
Row { Row {
enabled: root.enabled enabled: root.enabled
Layout.columnSpan: 1
RadioButton { RadioButton {
text: "关闭" text: "关闭"
checked: !App.currentAntiClipAreaEnabled checked: !App.currentAntiClipAreaEnabled
@ -327,6 +329,19 @@ Item {
} }
} }
Label { text: qsTr("灵敏度: ")
Layout.alignment: Qt.AlignRight
}
ComboBox {
id: antiClipSensitivityComboBox
enabled: root.enabled
Layout.alignment: Qt.AlignLeft
model: [1,2,3,4,5]
currentIndex: root.antiClipSensitivity-1
onCurrentIndexChanged: {
App.currentAntiClipSensitivity = antiClipSensitivityComboBox.currentIndex+1
}
}
Label {text: qsTr("屏蔽区域: ")} Label {text: qsTr("屏蔽区域: ")}
Row { Row {

View File

@ -118,6 +118,7 @@ ApplicationWindow {
shieldedAreaEnabled: App.currentShieldedAreaEnabled shieldedAreaEnabled: App.currentShieldedAreaEnabled
shieldedAreaPoints: App.currentShieldedAreaPoints shieldedAreaPoints: App.currentShieldedAreaPoints
antiClipAreaEnabled: App.currentAntiClipAreaEnabled antiClipAreaEnabled: App.currentAntiClipAreaEnabled
antiClipSensitivity: App.currentAntiClipSensitivity
antiClipAreaPoints: App.currentAntiClipAreaPoints antiClipAreaPoints: App.currentAntiClipAreaPoints
flip: App.currentDeviceFlip flip: App.currentDeviceFlip
videoRotation: App.currentDeviceRotation videoRotation: App.currentDeviceRotation
@ -163,6 +164,7 @@ ApplicationWindow {
} }
Item {} Item {}
Button { Button {
Layout.alignment: Qt.AlignRight
text: "升级" text: "升级"
onClicked: { onClicked: {
if (deviceList.currentIndex < 0) { if (deviceList.currentIndex < 0) {
@ -175,17 +177,32 @@ ApplicationWindow {
otaPopup.open() otaPopup.open()
} }
} }
Item {} Button {
Layout.alignment: Qt.AlignRight
Layout.rightMargin: 5
text: "重置"
onClicked: {
if (deviceList.currentIndex < 0) {
showMessageDialog(2, "恢复出厂设置", "请先选择设备")
return
} else {
showMessageDialog(2, "恢复出厂设置", "设备将会重启,重启后配置恢复默认",()=>{
App.resetDevice();
})
}
}
}
spacing: (parent.width - (2 * 100)) / 3 spacing: (parent.width - (2 * 100)) / 3
} }
function showMessageDialog(type, title, message) { function showMessageDialog(type, title, message, callback) {
let component = Qt.createComponent("MessageDialog.qml") let component = Qt.createComponent("MessageDialog.qml")
if (component.status === Component.Ready) { if (component.status === Component.Ready) {
let dialog = component.createObject(window, { let dialog = component.createObject(window, {
"type": type, "type": type,
"titleText": title, "titleText": title,
"text": message "text": message,
"callback": callback
}) })
dialog.open() dialog.open()
} }

View File

@ -13,6 +13,7 @@ Dialog {
property alias text: textLabel.text property alias text: textLabel.text
property alias textFontSize: textLabel.font.pixelSize property alias textFontSize: textLabel.font.pixelSize
property int type: MessageDialog.Type.Successful property int type: MessageDialog.Type.Successful
property var callback
closePolicy: Popup.CloseOnEscap | Popup.NoAutoClose closePolicy: Popup.CloseOnEscap | Popup.NoAutoClose
background: Rectangle { background: Rectangle {
radius: 8 radius: 8
@ -62,14 +63,44 @@ Dialog {
wrapMode: Text.WordWrap wrapMode: Text.WordWrap
} }
Button { Row {
id: cancelButton
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
Layout.rightMargin: 6 Layout.rightMargin: 6
Layout.preferredWidth: 72 spacing: 10
Layout.preferredHeight: 40 Button {
id: okButton
width: 72
height: 40
font.family: control.font.family font.family: control.font.family
text: "关闭" text: "好的"
font.pixelSize: 14
contentItem: Text {
text: parent.text
font: parent.font
color: parent.down ? "#FFFFFF" : "#53627C"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
background: Rectangle {
border.color: "#E1E4E8"
border.width: 1
color: parent.down ? "#F25959" : "#FFFFFF"
radius: 2
}
onClicked: {
if(callback !== undefined){
callback()
}
control.accept()
}
}
Button {
id: cancelButton
visible: callback !== undefined
width: 72
height: 40
font.family: control.font.family
text: "取消"
font.pixelSize: 14 font.pixelSize: 14
contentItem: Text { contentItem: Text {
text: parent.text text: parent.text
@ -78,7 +109,6 @@ Dialog {
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
} }
background: Rectangle { background: Rectangle {
border.color: "#E1E4E8" border.color: "#E1E4E8"
border.width: 1 border.width: 1
@ -88,6 +118,7 @@ Dialog {
onClicked: control.reject() onClicked: control.reject()
} }
} }
}
onTypeChanged: { onTypeChanged: {
if (type === MessageDialog.Type.Successful || type === MessageDialog.Type.Ok) { if (type === MessageDialog.Type.Successful || type === MessageDialog.Type.Ok) {
image.source = "qrc:/qt/qml/AntiClipSettings/resources/successfull.svg" image.source = "qrc:/qt/qml/AntiClipSettings/resources/successfull.svg"