chore: update files of project

This commit is contained in:
x-tools-author 2024-03-21 09:20:31 +08:00
parent 1318692d9c
commit 676afdd883
16 changed files with 171 additions and 179 deletions

View File

@ -21,24 +21,24 @@ function(sak_auto_execute_windeployqt target)
VERBATIM)
endif()
endif()
if(MSVC AND ${MSVC_VERSION} GREATER_EQUAL 1929)
cmake_path(GET CMAKE_CXX_COMPILER PARENT_PATH COMPILER_PATH)
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release" AND MSVC)
add_custom_command(
TARGET ${target}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${COMPILER_PATH}/VCRUNTIME140.dll"
$<TARGET_FILE_DIR:${target}>
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${COMPILER_PATH}/VCRUNTIME140_1.dll"
$<TARGET_FILE_DIR:${target}>
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${COMPILER_PATH}/MSVCP140.dll"
$<TARGET_FILE_DIR:${target}>
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${COMPILER_PATH}/MSVCP140_1.dll"
$<TARGET_FILE_DIR:${target}>
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${COMPILER_PATH}/MSVCP140_2.dll"
$<TARGET_FILE_DIR:${target}>
VERBATIM)
if(MSVC AND ${MSVC_VERSION} GREATER_EQUAL 1929)
cmake_path(GET CMAKE_CXX_COMPILER PARENT_PATH COMPILER_PATH)
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release" AND MSVC)
add_custom_command(
TARGET ${target}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${COMPILER_PATH}/VCRUNTIME140.dll"
$<TARGET_FILE_DIR:${target}>
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${COMPILER_PATH}/VCRUNTIME140_1.dll"
$<TARGET_FILE_DIR:${target}>
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${COMPILER_PATH}/MSVCP140.dll"
$<TARGET_FILE_DIR:${target}>
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${COMPILER_PATH}/MSVCP140_1.dll"
$<TARGET_FILE_DIR:${target}>
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${COMPILER_PATH}/MSVCP140_2.dll"
$<TARGET_FILE_DIR:${target}>
VERBATIM)
endif()
endif()
endif()
endfunction()

View File

@ -123,17 +123,23 @@ if(X_TOOLS_IMPORT_MODULE_CANBUS_STUDIO)
include_directories(${CMAKE_SOURCE_DIR}/Source/CANBusStudio/canbusstudioui)
endif()
option(X_TOOLS_IMPORT_MODULE_BLUETOOTH "Enable Bluetooth modbule" ON)
if(X_TOOLS_IMPORT_MODULE_BLUETOOTH)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Bluetooth)
file(GLOB X_TOOLS_BLUETOOTH_H "${CMAKE_SOURCE_DIR}/Source/Optional/bluetooth/*.h")
file(GLOB X_TOOLS_BLUETOOTH_UI "${CMAKE_SOURCE_DIR}/Source/Optional/bluetooth/*.ui")
file(GLOB X_TOOLS_BLUETOOTH_CPP "${CMAKE_SOURCE_DIR}/Source/Optional/bluetooth/*.cc")
add_compile_definitions(X_TOOLS_IMPORT_MODULE_BLUETOOTH)
list(APPEND X_TOOLS_SOURCE ${X_TOOLS_BLUETOOTH_H})
list(APPEND X_TOOLS_SOURCE ${X_TOOLS_BLUETOOTH_UI})
list(APPEND X_TOOLS_SOURCE ${X_TOOLS_BLUETOOTH_CPP})
include_directories(${CMAKE_SOURCE_DIR}/Source/Optional/bluetooth)
if(QT_VERSION_MAJOR GREATER 5)
if(NOT Qt${QT_VERSION_MAJOR}_VERSION VERSION_LESS "6.5.0")
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Bluetooth QUIET)
if(Qt${QT_VERSION_MAJOR}Bluetooth_FOUND)
option(X_TOOLS_IMPORT_MODULE_BLUETOOTH "Enable Bluetooth modbule" ON)
if(X_TOOLS_IMPORT_MODULE_BLUETOOTH)
file(GLOB X_TOOLS_BLUETOOTH_H "${CMAKE_SOURCE_DIR}/Source/Optional/Bluetooth/*.h")
file(GLOB X_TOOLS_BLUETOOTH_UI "${CMAKE_SOURCE_DIR}/Source/Optional/Bluetooth/*.ui")
file(GLOB X_TOOLS_BLUETOOTH_CPP "${CMAKE_SOURCE_DIR}/Source/Optional/Bluetooth/*.cpp")
add_compile_definitions(X_TOOLS_IMPORT_MODULE_BLUETOOTH)
list(APPEND X_TOOLS_SOURCE ${X_TOOLS_BLUETOOTH_H})
list(APPEND X_TOOLS_SOURCE ${X_TOOLS_BLUETOOTH_UI})
list(APPEND X_TOOLS_SOURCE ${X_TOOLS_BLUETOOTH_CPP})
include_directories(${CMAKE_SOURCE_DIR}/Source/Optional/Bluetooth)
endif()
endif()
endif()
endif()
set(WITH_GFLAGS OFF)

View File

@ -9,9 +9,9 @@ set(SAK_COMMON_SOURCES
${CMAKE_SOURCE_DIR}/Source/Common/Common/xToolsInterface.cpp
${CMAKE_SOURCE_DIR}/Source/Common/Common/xToolsTranslator.h
${CMAKE_SOURCE_DIR}/Source/Common/Common/xToolsTranslator.cpp
${CMAKE_SOURCE_DIR}/Source/Common/Commonui/xToolsUi.h
${CMAKE_SOURCE_DIR}/Source/Common/Commonui/xToolsMainWindow.h
${CMAKE_SOURCE_DIR}/Source/Common/Commonui/xToolsMainWindow.cpp
${CMAKE_SOURCE_DIR}/Source/Common/CommonUI/xToolsUi.h
${CMAKE_SOURCE_DIR}/Source/Common/CommonUI/xToolsMainWindow.h
${CMAKE_SOURCE_DIR}/Source/Common/CommonUI/xToolsMainWindow.cpp
${CMAKE_SOURCE_DIR}/xTools.qrc)
set(SAK_CANBUSSTUDIO_SOURCES ${SAK_CANBUSSTUDIO_SOURCES} ${SAK_COMMON_SOURCES})

View File

@ -9,9 +9,9 @@ set(SAK_COMMON_SOURCES
${CMAKE_SOURCE_DIR}/Source/Common/Common/xToolsInterface.cpp
${CMAKE_SOURCE_DIR}/Source/Common/Common/xToolsTranslator.h
${CMAKE_SOURCE_DIR}/Source/Common/Common/xToolsTranslator.cpp
${CMAKE_SOURCE_DIR}/Source/Common/Commonui/xToolsUi.h
${CMAKE_SOURCE_DIR}/Source/Common/Commonui/xToolsMainWindow.h
${CMAKE_SOURCE_DIR}/Source/Common/Commonui/xToolsMainWindow.cpp
${CMAKE_SOURCE_DIR}/Source/Common/CommonUI/xToolsUi.h
${CMAKE_SOURCE_DIR}/Source/Common/CommonUI/xToolsMainWindow.h
${CMAKE_SOURCE_DIR}/Source/Common/CommonUI/xToolsMainWindow.cpp
${CMAKE_SOURCE_DIR}/xTools.qrc)
set(SAK_MODBUSSTUDIO_SOURCES ${SAK_MODBUSSTUDIO_SOURCES} ${SAK_COMMON_SOURCES})

View File

@ -6,20 +6,20 @@
* xTools is licensed according to the terms in the file LICENCE(GPL V3) in the root of the source
* code directory.
**************************************************************************************************/
#include "xToolsBleCentralTool.h"
#include <QBluetoothDeviceInfo>
#include <QMetaObject>
#include "sakblecentraltool.h"
#define BLE_ERR_SIG QLowEnergyController::Error
SAKBleCentralTool::SAKBleCentralTool(QObject *parent)
xToolsBleCentralTool::xToolsBleCentralTool(QObject *parent)
: xToolsCommunicationTool(parent)
{}
SAKBleCentralTool::~SAKBleCentralTool() {}
xToolsBleCentralTool::~xToolsBleCentralTool() {}
QString SAKBleCentralTool::serviceName(QVariant service)
QString xToolsBleCentralTool::serviceName(QVariant service)
{
QObject *obj = service.value<QObject *>();
auto cookedService = qobject_cast<QLowEnergyService *>(obj);
@ -32,7 +32,7 @@ QString SAKBleCentralTool::serviceName(QVariant service)
return "Invalid";
}
QVariantList SAKBleCentralTool::characteristics(QVariant service)
QVariantList xToolsBleCentralTool::characteristics(QVariant service)
{
QVariantList list;
if (service.canConvert<QLowEnergyService *>()) {
@ -48,7 +48,7 @@ QVariantList SAKBleCentralTool::characteristics(QVariant service)
return list;
}
QString SAKBleCentralTool::characteristicName(QVariant characteristic)
QString xToolsBleCentralTool::characteristicName(QVariant characteristic)
{
if (characteristic.canConvert<QLowEnergyCharacteristic>()) {
auto c = characteristic.value<QLowEnergyCharacteristic>();
@ -58,7 +58,7 @@ QString SAKBleCentralTool::characteristicName(QVariant characteristic)
return "Invalid";
}
void SAKBleCentralTool::readCharacteristic()
void xToolsBleCentralTool::readCharacteristic()
{
if (!(m_serviceIndex >= 0 && m_serviceIndex < m_services.length())) {
qWarning() << "invalid service index";
@ -76,7 +76,7 @@ void SAKBleCentralTool::readCharacteristic()
service->readCharacteristic(c);
}
void SAKBleCentralTool::changeNotify()
void xToolsBleCentralTool::changeNotify()
{
if (!((m_serviceIndex >= 0) && (m_serviceIndex < m_services.length()))) {
return;
@ -110,7 +110,7 @@ void SAKBleCentralTool::changeNotify()
}
}
bool SAKBleCentralTool::hasFlag(QVariant characteristic, int flag)
bool xToolsBleCentralTool::hasFlag(QVariant characteristic, int flag)
{
auto ch = characteristic.value<QLowEnergyCharacteristic>();
auto properties = ch.properties();
@ -121,7 +121,7 @@ bool SAKBleCentralTool::hasFlag(QVariant characteristic, int flag)
return false;
}
bool SAKBleCentralTool::isNotified(QVariant characteristic)
bool xToolsBleCentralTool::isNotified(QVariant characteristic)
{
auto cookedCh = characteristic.value<QLowEnergyCharacteristic>();
auto desList = cookedCh.descriptors();
@ -136,7 +136,7 @@ bool SAKBleCentralTool::isNotified(QVariant characteristic)
return notified;
}
bool SAKBleCentralTool::initialize(QString &errStr)
bool xToolsBleCentralTool::initialize(QString &errStr)
{
if (!m_bluetoothDeviceInfo.isValid()) {
errStr = "invalid ble information.";
@ -168,7 +168,7 @@ bool SAKBleCentralTool::initialize(QString &errStr)
return true;
}
void SAKBleCentralTool::readBytes()
void xToolsBleCentralTool::readBytes()
{
if (!((m_serviceIndex >= 0) && (m_serviceIndex < m_services.length()))) {
return;
@ -180,7 +180,7 @@ void SAKBleCentralTool::readBytes()
service->readCharacteristic(characteristic);
}
void SAKBleCentralTool::writeBytes(const QByteArray &bytes)
void xToolsBleCentralTool::writeBytes(const QByteArray &bytes)
{
if (!((m_serviceIndex >= 0) && (m_serviceIndex < m_services.length()))) {
qWarning() << "invalid parameters.";
@ -214,19 +214,19 @@ void SAKBleCentralTool::writeBytes(const QByteArray &bytes)
}
}
void SAKBleCentralTool::uninitialize()
void xToolsBleCentralTool::uninitialize()
{
mBleCentral->disconnectFromDevice();
mBleCentral->deleteLater();
mBleCentral = nullptr;
}
void SAKBleCentralTool::onServiceDiscovered(const QBluetoothUuid &newService)
void xToolsBleCentralTool::onServiceDiscovered(const QBluetoothUuid &newService)
{
qInfo() << "new ble service discovered:" + newService.toString();
}
void SAKBleCentralTool::onServiceDiscoveryFinished()
void xToolsBleCentralTool::onServiceDiscoveryFinished()
{
qInfo() << "ble service discovery finished.";
QList<QBluetoothUuid> uuids = mBleCentral->services();
@ -267,7 +267,7 @@ void SAKBleCentralTool::onServiceDiscoveryFinished()
connect(service,
&QLowEnergyService::descriptorWritten,
this,
&SAKBleCentralTool::descriptorWritten);
&xToolsBleCentralTool::descriptorWritten);
m_services.append(service);
service->discoverDetails();
@ -276,7 +276,7 @@ void SAKBleCentralTool::onServiceDiscoveryFinished()
emit serviceDiscoveryFinished();
}
void SAKBleCentralTool::onBleCentralErrorOccuured(QLowEnergyController::Error err)
void xToolsBleCentralTool::onBleCentralErrorOccuured(QLowEnergyController::Error err)
{
if (err == QLowEnergyController::UnknownError) {
return;
@ -286,20 +286,20 @@ void SAKBleCentralTool::onBleCentralErrorOccuured(QLowEnergyController::Error er
exit();
}
void SAKBleCentralTool::onBleCentralConnected()
void xToolsBleCentralTool::onBleCentralConnected()
{
qWarning() << "connect to device successfully.";
mBleCentral->discoverServices();
}
void SAKBleCentralTool::onBleCentralDisconnected()
void xToolsBleCentralTool::onBleCentralDisconnected()
{
QString msg = "disconnect from device";
qWarning() << msg;
emit errorOccurred(msg);
}
void SAKBleCentralTool::onServiceObjectStateChanged(QLowEnergyService *service,
void xToolsBleCentralTool::onServiceObjectStateChanged(QLowEnergyService *service,
QLowEnergyService::ServiceState newState)
{
Q_UNUSED(service);
@ -309,18 +309,18 @@ void SAKBleCentralTool::onServiceObjectStateChanged(QLowEnergyService *service,
}
}
QVariant SAKBleCentralTool::info()
QVariant xToolsBleCentralTool::info()
{
return QVariant::fromValue(m_bluetoothDeviceInfo);
}
void SAKBleCentralTool::setInfo(QVariant info)
void xToolsBleCentralTool::setInfo(QVariant info)
{
m_bluetoothDeviceInfo = info.value<QBluetoothDeviceInfo>();
emit infoChanged();
}
QVariantList SAKBleCentralTool::services()
QVariantList xToolsBleCentralTool::services()
{
QVariantList varList;
for (auto &var : m_services) {
@ -329,34 +329,34 @@ QVariantList SAKBleCentralTool::services()
return varList;
}
int SAKBleCentralTool::serviceIndex()
int xToolsBleCentralTool::serviceIndex()
{
return m_serviceIndex;
}
void SAKBleCentralTool::setServiceIndex(int index)
void xToolsBleCentralTool::setServiceIndex(int index)
{
m_serviceIndex = index;
emit serviceIndexChanged();
}
int SAKBleCentralTool::characteristicIndex()
int xToolsBleCentralTool::characteristicIndex()
{
return m_characteristicIndex;
}
void SAKBleCentralTool::setCharacteristicIndex(int index)
void xToolsBleCentralTool::setCharacteristicIndex(int index)
{
m_characteristicIndex = index;
emit characteristicIndexChanged();
}
int SAKBleCentralTool::writeModel()
int xToolsBleCentralTool::writeModel()
{
return m_writeModel;
}
void SAKBleCentralTool::setWriteModel(int model)
void xToolsBleCentralTool::setWriteModel(int model)
{
m_writeModel = model;
emit writeModelChanged();

View File

@ -6,8 +6,7 @@
* xTools is licensed according to the terms in the file LICENCE(GPL V3) in the root of the source
* code directory.
**************************************************************************************************/
#ifndef EDBLECENTRAL_HH
#define EDBLECENTRAL_HH
#pragma once
#include <QBluetoothDeviceInfo>
#include <QBluetoothUuid>
@ -17,7 +16,7 @@
#include "xToolsCommunicationTool.h"
class SAKBleCentralTool : public xToolsCommunicationTool
class xToolsBleCentralTool : public xToolsCommunicationTool
{
Q_OBJECT
// clang-format off
@ -28,8 +27,8 @@ class SAKBleCentralTool : public xToolsCommunicationTool
Q_PROPERTY(int writeModel READ writeModel WRITE setWriteModel NOTIFY writeModelChanged)
// clang-format on
public:
SAKBleCentralTool(QObject *parent = nullptr);
~SAKBleCentralTool();
xToolsBleCentralTool(QObject *parent = nullptr);
~xToolsBleCentralTool();
public:
Q_INVOKABLE QString serviceName(QVariant service);
@ -89,5 +88,3 @@ private:
int m_characteristicIndex{-1};
int m_writeModel;
};
#endif // EDBLECENTRAL_HPP

View File

@ -6,8 +6,8 @@
* xTools is licensed according to the terms in the file LICENCE(GPL V3) in the root of the source
* code directory.
**************************************************************************************************/
#include "sakblecentraltoolui.h"
#include "ui_sakblecentraltoolui.h"
#include "xToolsBleCentralToolUi.h"
#include "ui_xToolsBleCentralToolUi.h"
#include <QGridLayout>
#include <QLabel>
@ -21,9 +21,9 @@
#define SAK_CB_I_C &QComboBox::currentIndexChanged
SAKBleCentralToolUi::SAKBleCentralToolUi(QWidget* parent)
xToolsBleCentralToolUi::xToolsBleCentralToolUi(QWidget* parent)
: xToolsCommunicationToolUi{parent}
, ui(new Ui::SAKBleCentralToolUi)
, ui(new Ui::xToolsBleCentralToolUi)
, mBleTool(Q_NULLPTR)
{
ui->setupUi(this);
@ -31,36 +31,36 @@ SAKBleCentralToolUi::SAKBleCentralToolUi(QWidget* parent)
connect(ui->pushButtonScan,
&QPushButton::clicked,
this,
&SAKBleCentralToolUi::onPushButtonScanClicked);
&xToolsBleCentralToolUi::onPushButtonScanClicked);
connect(ui->comboBoxDevices,
static_cast<void (QComboBox::*)(int)>(SAK_CB_I_C),
this,
&SAKBleCentralToolUi::onComboBoxDevicesActived);
&xToolsBleCentralToolUi::onComboBoxDevicesActived);
connect(ui->comboBoxServices,
static_cast<void (QComboBox::*)(int)>(SAK_CB_I_C),
this,
&SAKBleCentralToolUi::onComboBoxServicesCurrentIndexChanged);
&xToolsBleCentralToolUi::onComboBoxServicesCurrentIndexChanged);
connect(ui->comboBoxCharacteristics,
static_cast<void (QComboBox::*)(int)>(SAK_CB_I_C),
this,
&SAKBleCentralToolUi::onComboBoxCharacteristicsActived);
&xToolsBleCentralToolUi::onComboBoxCharacteristicsActived);
connect(ui->comboBoxWriteWay,
static_cast<void (QComboBox::*)(int)>(SAK_CB_I_C),
this,
&SAKBleCentralToolUi::onComboBoxWriteWayCurrentIndexChanged);
&xToolsBleCentralToolUi::onComboBoxWriteWayCurrentIndexChanged);
connect(ui->pushButtonNotify,
&QPushButton::clicked,
this,
&SAKBleCentralToolUi::onPushButtonNotifyClicked);
&xToolsBleCentralToolUi::onPushButtonNotifyClicked);
connect(ui->pushButtonRead,
&QPushButton::clicked,
this,
&SAKBleCentralToolUi::onPushButtonReadClicked);
connect(ui->comboBoxDevices, &SAKBluetoothDeviceInfoComboBox::finished, this, [=]() {
&xToolsBleCentralToolUi::onPushButtonReadClicked);
connect(ui->comboBoxDevices, &xToolsBluetoothDeviceInfoComboBox::finished, this, [=]() {
ui->pushButtonScan->setText(tr("Scan"));
ui->pushButtonScan->setEnabled(true);
});
connect(ui->comboBoxDevices, &SAKBluetoothDeviceInfoComboBox::started, this, [=]() {
connect(ui->comboBoxDevices, &xToolsBluetoothDeviceInfoComboBox::started, this, [=]() {
ui->pushButtonScan->setText(tr("Stop"));
ui->pushButtonScan->setEnabled(true);
});
@ -73,16 +73,16 @@ SAKBleCentralToolUi::SAKBleCentralToolUi(QWidget* parent)
ui->labelUnsupported->setStyleSheet("QLabel{color:red}");
}
SAKBleCentralToolUi::~SAKBleCentralToolUi()
xToolsBleCentralToolUi::~xToolsBleCentralToolUi()
{
delete ui;
}
void SAKBleCentralToolUi::onBaseToolUiInitialized(xToolsBaseTool* tool, const QString& settingsGroup)
void xToolsBleCentralToolUi::onBaseToolUiInitialized(xToolsBaseTool* tool, const QString& settingsGroup)
{
xToolsCommunicationToolUi::onBaseToolUiInitialized(tool, settingsGroup);
mBleTool = qobject_cast<SAKBleCentralTool*>(mTool);
mBleTool = qobject_cast<xToolsBleCentralTool*>(mTool);
if (!mBleTool) {
QByteArray msg("invalid SAKBleCentralTool tool");
qWarning() << QString::fromLatin1(msg);
@ -92,21 +92,21 @@ void SAKBleCentralToolUi::onBaseToolUiInitialized(xToolsBaseTool* tool, const QS
onComboBoxWriteWayCurrentIndexChanged();
connect(mBleTool,
&SAKBleCentralTool::descriptorWritten,
&xToolsBleCentralTool::descriptorWritten,
this,
&SAKBleCentralToolUi::onDescriptorWritten);
&xToolsBleCentralToolUi::onDescriptorWritten);
initSettingsMenu(settingsGroup);
}
void SAKBleCentralToolUi::onIsWorkingChanged(bool isWorking)
void xToolsBleCentralToolUi::onIsWorkingChanged(bool isWorking)
{
if (!isWorking) {
ui->progressBar->hide();
}
}
void SAKBleCentralToolUi::initSettingsMenu(const QString& settingsGroup)
void xToolsBleCentralToolUi::initSettingsMenu(const QString& settingsGroup)
{
QWidget* w = new QWidget(this);
QGridLayout* gl = new QGridLayout();
@ -151,13 +151,13 @@ void SAKBleCentralToolUi::initSettingsMenu(const QString& settingsGroup)
ui->pushButtonSettings->setMenu(menu);
connect(mBleTool,
&SAKBleCentralTool::serviceDiscoveryStarted,
&xToolsBleCentralTool::serviceDiscoveryStarted,
this,
&SAKBleCentralToolUi::onServiceDiscoveryStarted);
&xToolsBleCentralToolUi::onServiceDiscoveryStarted);
connect(mBleTool,
&SAKBleCentralTool::serviceDiscoveryFinished,
&xToolsBleCentralTool::serviceDiscoveryFinished,
this,
&SAKBleCentralToolUi::onServiceDiscoveryFinished);
&xToolsBleCentralToolUi::onServiceDiscoveryFinished);
int timeoutInterval = sp->value();
QString nameFiltter = le->text().trimmed();
@ -167,12 +167,12 @@ void SAKBleCentralToolUi::initSettingsMenu(const QString& settingsGroup)
onComboBoxDevicesActived();
}
void SAKBleCentralToolUi::onServiceDiscoveryStarted()
void xToolsBleCentralToolUi::onServiceDiscoveryStarted()
{
ui->progressBar->show();
}
void SAKBleCentralToolUi::onServiceDiscoveryFinished()
void xToolsBleCentralToolUi::onServiceDiscoveryFinished()
{
ui->comboBoxServices->clear();
auto services = mBleTool->services();
@ -193,7 +193,7 @@ void SAKBleCentralToolUi::onServiceDiscoveryFinished()
ui->progressBar->hide();
}
void SAKBleCentralToolUi::onDescriptorWritten(const QLowEnergyDescriptor& descriptor,
void xToolsBleCentralToolUi::onDescriptorWritten(const QLowEnergyDescriptor& descriptor,
const QByteArray& newValue)
{
Q_UNUSED(descriptor)
@ -201,7 +201,7 @@ void SAKBleCentralToolUi::onDescriptorWritten(const QLowEnergyDescriptor& descri
onComboBoxCharacteristicsActived();
}
void SAKBleCentralToolUi::onPushButtonScanClicked()
void xToolsBleCentralToolUi::onPushButtonScanClicked()
{
ui->pushButtonScan->setEnabled(false);
if (ui->comboBoxDevices->isActive()) {
@ -211,13 +211,13 @@ void SAKBleCentralToolUi::onPushButtonScanClicked()
}
}
void SAKBleCentralToolUi::onComboBoxDevicesActived()
void xToolsBleCentralToolUi::onComboBoxDevicesActived()
{
QVariant data = ui->comboBoxDevices->currentData();
mBleTool->setInfo(data);
}
void SAKBleCentralToolUi::onComboBoxServicesCurrentIndexChanged()
void xToolsBleCentralToolUi::onComboBoxServicesCurrentIndexChanged()
{
mBleTool->setServiceIndex(ui->comboBoxServices->currentIndex());
auto service = ui->comboBoxServices->currentData();
@ -233,7 +233,7 @@ void SAKBleCentralToolUi::onComboBoxServicesCurrentIndexChanged()
}
}
void SAKBleCentralToolUi::onComboBoxCharacteristicsActived()
void xToolsBleCentralToolUi::onComboBoxCharacteristicsActived()
{
int index = ui->comboBoxCharacteristics->currentIndex();
mBleTool->setCharacteristicIndex(index);
@ -259,19 +259,19 @@ void SAKBleCentralToolUi::onComboBoxCharacteristicsActived()
}
}
void SAKBleCentralToolUi::onComboBoxWriteWayCurrentIndexChanged()
void xToolsBleCentralToolUi::onComboBoxWriteWayCurrentIndexChanged()
{
int index = ui->comboBoxWriteWay->currentIndex();
mBleTool->setWriteModel(index);
qInfo() << "set write model to:" << index;
}
void SAKBleCentralToolUi::onPushButtonNotifyClicked()
void xToolsBleCentralToolUi::onPushButtonNotifyClicked()
{
mBleTool->changeNotify();
}
void SAKBleCentralToolUi::onPushButtonReadClicked()
void xToolsBleCentralToolUi::onPushButtonReadClicked()
{
mBleTool->readCharacteristic();
}

View File

@ -6,23 +6,20 @@
* xTools is licensed according to the terms in the file LICENCE(GPL V3) in the root of the source
* code directory.
**************************************************************************************************/
#ifndef SAKBLECENTRALTOOLUI_H
#define SAKBLECENTRALTOOLUI_H
#include <QLowEnergyDescriptor>
#include "sakblecentraltool.h"
#include "xToolsBleCentralTool.h"
#include "xToolsCommunicationToolUi.h"
namespace Ui {
class SAKBleCentralToolUi;
class xToolsBleCentralToolUi;
}
class SAKBleCentralToolUi : public xToolsCommunicationToolUi
class xToolsBleCentralToolUi : public xToolsCommunicationToolUi
{
Q_OBJECT
public:
explicit SAKBleCentralToolUi(QWidget *parent = nullptr);
~SAKBleCentralToolUi();
explicit xToolsBleCentralToolUi(QWidget *parent = nullptr);
~xToolsBleCentralToolUi();
protected:
virtual void onBaseToolUiInitialized(xToolsBaseTool *tool,
@ -31,8 +28,8 @@ protected:
virtual void onIsWorkingChanged(bool isWorking) final;
private:
Ui::SAKBleCentralToolUi *ui{nullptr};
SAKBleCentralTool *mBleTool;
Ui::xToolsBleCentralToolUi *ui{nullptr};
xToolsBleCentralTool *mBleTool;
const QLoggingCategory mLoggingCategory{"sak.blecentraltoolui"};
private:
@ -51,5 +48,3 @@ private slots:
void onPushButtonNotifyClicked();
void onPushButtonReadClicked();
};
#endif // SAKBLECENTRALTOOLUI_H

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SAKBleCentralToolUi</class>
<widget class="QWidget" name="SAKBleCentralToolUi">
<class>xToolsBleCentralToolUi</class>
<widget class="QWidget" name="xToolsBleCentralToolUi">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>248</width>
<width>256</width>
<height>256</height>
</rect>
</property>
@ -66,7 +66,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="SAKBluetoothDeviceInfoComboBox" name="comboBoxDevices"/>
<widget class="xToolsBluetoothDeviceInfoComboBox" name="comboBoxDevices"/>
</item>
<item row="7" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
@ -175,9 +175,9 @@
</widget>
<customwidgets>
<customwidget>
<class>SAKBluetoothDeviceInfoComboBox</class>
<class>xToolsBluetoothDeviceInfoComboBox</class>
<extends>QComboBox</extends>
<header location="global">sakbluetoothdeviceInfocombobox.h</header>
<header location="global">xToolsBluetoothDeviceInfoComboBox.h</header>
</customwidget>
</customwidgets>
<resources/>

View File

@ -6,7 +6,7 @@
* xTools is licensed according to the terms in the file LICENCE(GPL V3) in the root of the source
* code directory.
**************************************************************************************************/
#include "sakblescanner.h"
#include "xToolsBleScanner.h"
#include <QBluetoothDeviceInfo>
#include <QDebug>
@ -14,29 +14,29 @@
#define BLE_ERR_SIG void (QBluetoothDeviceDiscoveryAgent::*)(QBluetoothDeviceDiscoveryAgent::Error)
SAKBleScanner::SAKBleScanner(QObject* parent)
xToolsBleScanner::xToolsBleScanner(QObject* parent)
: QThread(parent)
, m_discover(Q_NULLPTR)
{}
SAKBleScanner::~SAKBleScanner() {}
xToolsBleScanner::~xToolsBleScanner() {}
void SAKBleScanner::startDiscover()
void xToolsBleScanner::startDiscover()
{
start();
}
void SAKBleScanner::stopDiscover()
void xToolsBleScanner::stopDiscover()
{
exit();
}
bool SAKBleScanner::isActive()
bool xToolsBleScanner::isActive()
{
return isRunning();
}
QVariant SAKBleScanner::deviceInfo(int index)
QVariant xToolsBleScanner::deviceInfo(int index)
{
m_deviceInfoListMutex.lock();
if (index >= 0 && index < m_deviceInfoList.length()) {
@ -48,27 +48,27 @@ QVariant SAKBleScanner::deviceInfo(int index)
return QVariant();
}
QString SAKBleScanner::deviceName(const QVariant& deviceInfo)
QString xToolsBleScanner::deviceName(const QVariant& deviceInfo)
{
auto cookedInfo = deviceInfo.value<QBluetoothDeviceInfo>();
return cookedInfo.name();
}
void SAKBleScanner::run()
void xToolsBleScanner::run()
{
m_discover = new QBluetoothDeviceDiscoveryAgent();
connect(m_discover,
&QBluetoothDeviceDiscoveryAgent::finished,
this,
&SAKBleScanner::onDiscoveryFinished);
&xToolsBleScanner::onDiscoveryFinished);
connect(m_discover,
&QBluetoothDeviceDiscoveryAgent::errorOccurred,
this,
&SAKBleScanner::onDiscoveryErrorOccurred);
&xToolsBleScanner::onDiscoveryErrorOccurred);
connect(m_discover,
&QBluetoothDeviceDiscoveryAgent::deviceDiscovered,
this,
&SAKBleScanner::onDiscoveryDeviceDiscovered);
&xToolsBleScanner::onDiscoveryDeviceDiscovered);
// 10s-1minute
int interval = m_timeoutInterval < 10 ? 10 : m_timeoutInterval;
@ -82,13 +82,13 @@ void SAKBleScanner::run()
exec();
}
void SAKBleScanner::onDiscoveryFinished()
void xToolsBleScanner::onDiscoveryFinished()
{
emit devicesInfoListChanged();
exit();
}
void SAKBleScanner::onDiscoveryErrorOccurred(QBluetoothDeviceDiscoveryAgent::Error error)
void xToolsBleScanner::onDiscoveryErrorOccurred(QBluetoothDeviceDiscoveryAgent::Error error)
{
Q_UNUSED(error);
qWarning() << "QBluetoothDeviceDiscoveryAgent error:" << m_discover->errorString();
@ -96,7 +96,7 @@ void SAKBleScanner::onDiscoveryErrorOccurred(QBluetoothDeviceDiscoveryAgent::Err
emit errorOccurred(m_discover->errorString());
}
void SAKBleScanner::onDiscoveryDeviceDiscovered(const QBluetoothDeviceInfo& info)
void xToolsBleScanner::onDiscoveryDeviceDiscovered(const QBluetoothDeviceInfo& info)
{
const QString name = info.name();
qInfo() << "new ble device:" << name;
@ -114,7 +114,7 @@ void SAKBleScanner::onDiscoveryDeviceDiscovered(const QBluetoothDeviceInfo& info
emit deviceDiscovered(info);
}
QVariantList SAKBleScanner::devicesInfoList()
QVariantList xToolsBleScanner::devicesInfoList()
{
QVariantList list;
m_deviceInfoListMutex.lock();
@ -126,23 +126,23 @@ QVariantList SAKBleScanner::devicesInfoList()
return list;
}
int SAKBleScanner::timeoutInterval()
int xToolsBleScanner::timeoutInterval()
{
return m_timeoutInterval;
}
void SAKBleScanner::setTimeoutInterval(int interval)
void xToolsBleScanner::setTimeoutInterval(int interval)
{
m_timeoutInterval = interval;
emit timeoutIntervalChanged();
}
QString SAKBleScanner::namefiltter()
QString xToolsBleScanner::namefiltter()
{
return m_nameFiltter;
}
void SAKBleScanner::setNameFiltter(const QString& flag)
void xToolsBleScanner::setNameFiltter(const QString& flag)
{
m_nameFiltter = flag;
emit filtterNameChanged();

View File

@ -6,8 +6,7 @@
* xTools is licensed according to the terms in the file LICENCE(GPL V3) in the root of the source
* code directory.
**************************************************************************************************/
#ifndef SAKBLESCANNER_H
#define SAKBLESCANNER_H
#pragma once
#include <QBluetoothDeviceDiscoveryAgent>
#include <QBluetoothDeviceInfo>
@ -16,7 +15,7 @@
#include <QThread>
#include <QVariant>
class SAKBleScanner : public QThread
class xToolsBleScanner : public QThread
{
Q_OBJECT
// clang-format off
@ -25,8 +24,8 @@ class SAKBleScanner : public QThread
Q_PROPERTY(QString namefiltter READ namefiltter WRITE setNameFiltter NOTIFY filtterNameChanged)
// clang-format on
public:
explicit SAKBleScanner(QObject *parent = nullptr);
~SAKBleScanner();
explicit xToolsBleScanner(QObject *parent = nullptr);
~xToolsBleScanner();
public:
Q_INVOKABLE void startDiscover();
@ -70,5 +69,3 @@ private:
int m_timeoutInterval{120};
QString m_nameFiltter{""};
};
#endif // SAKBLESCANNER_H

View File

@ -6,12 +6,12 @@
* xTools is licensed according to the terms in the file LICENCE(GPL V3) in the root of the source
* code directory.
**************************************************************************************************/
#include "sakbluetoothdeviceInfocombobox.h"
#include "xToolsBluetoothDeviceInfoComboBox.h"
#include <QBluetoothDeviceInfo>
#include <QMessageBox>
SAKBluetoothDeviceInfoComboBox::SAKBluetoothDeviceInfoComboBox(QWidget* parent)
xToolsBluetoothDeviceInfoComboBox::xToolsBluetoothDeviceInfoComboBox(QWidget* parent)
: xToolsComboBox(parent)
, mScanner(Q_NULLPTR)
{
@ -28,14 +28,14 @@ SAKBluetoothDeviceInfoComboBox::SAKBluetoothDeviceInfoComboBox(QWidget* parent)
#endif
}
SAKBluetoothDeviceInfoComboBox::~SAKBluetoothDeviceInfoComboBox()
xToolsBluetoothDeviceInfoComboBox::~xToolsBluetoothDeviceInfoComboBox()
{
#if 0
mScanner->stopDiscover();
#endif
}
void SAKBluetoothDeviceInfoComboBox::startDiscover()
void xToolsBluetoothDeviceInfoComboBox::startDiscover()
{
#if 0
clear();
@ -43,14 +43,14 @@ void SAKBluetoothDeviceInfoComboBox::startDiscover()
#endif
}
void SAKBluetoothDeviceInfoComboBox::stopDiscover()
void xToolsBluetoothDeviceInfoComboBox::stopDiscover()
{
#if 0
mScanner->stopDiscover();
#endif
}
bool SAKBluetoothDeviceInfoComboBox::isActive()
bool xToolsBluetoothDeviceInfoComboBox::isActive()
{
#if 0
return mScanner->isActive();
@ -58,19 +58,19 @@ bool SAKBluetoothDeviceInfoComboBox::isActive()
return false;
}
void SAKBluetoothDeviceInfoComboBox::setTimeoutInterval(int interval)
void xToolsBluetoothDeviceInfoComboBox::setTimeoutInterval(int interval)
{
#if 0
mScanner->setTimeoutInterval(interval);
#endif
}
void SAKBluetoothDeviceInfoComboBox::setNameFiltter(const QString& filtter)
void xToolsBluetoothDeviceInfoComboBox::setNameFiltter(const QString& filtter)
{
// mScanner->setNameFiltter(filtter);
}
void SAKBluetoothDeviceInfoComboBox::changeEvent(QEvent* event)
void xToolsBluetoothDeviceInfoComboBox::changeEvent(QEvent* event)
{
xToolsComboBox::changeEvent(event);
if ((event->type() == QEvent::EnabledChange) && isEnabled()) {
@ -78,7 +78,7 @@ void SAKBluetoothDeviceInfoComboBox::changeEvent(QEvent* event)
}
}
void SAKBluetoothDeviceInfoComboBox::onFinished()
void xToolsBluetoothDeviceInfoComboBox::onFinished()
{
// if (!isEnabled()) {
// return;
@ -94,7 +94,7 @@ void SAKBluetoothDeviceInfoComboBox::onFinished()
// emit finished();
}
void SAKBluetoothDeviceInfoComboBox::onDeviceDiscovered(const QBluetoothDeviceInfo& info)
void xToolsBluetoothDeviceInfoComboBox::onDeviceDiscovered(const QBluetoothDeviceInfo& info)
{
if (!isEnabled()) {
return;
@ -103,7 +103,7 @@ void SAKBluetoothDeviceInfoComboBox::onDeviceDiscovered(const QBluetoothDeviceIn
addItem(info.name(), QVariant::fromValue(info));
}
void SAKBluetoothDeviceInfoComboBox::onErrorOccurred(const QString& errStr)
void xToolsBluetoothDeviceInfoComboBox::onErrorOccurred(const QString& errStr)
{
QMessageBox::warning(this, tr("Error Occurred"), errStr);
}

View File

@ -6,20 +6,19 @@
* xTools is licensed according to the terms in the file LICENCE(GPL V3) in the root of the source
* code directory.
**************************************************************************************************/
#ifndef SAKBLUETOOTHDEVICEINFOCOMBOBOX_H
#define SAKBLUETOOTHDEVICEINFOCOMBOBOX_H
#pragma once
#include <QEvent>
#include "sakblescanner.h"
#include "xToolsBleScanner.h"
#include "xToolsComboBox.h"
class SAKBluetoothDeviceInfoComboBox : public xToolsComboBox
class xToolsBluetoothDeviceInfoComboBox : public xToolsComboBox
{
Q_OBJECT
public:
SAKBluetoothDeviceInfoComboBox(QWidget *parent = Q_NULLPTR);
~SAKBluetoothDeviceInfoComboBox();
xToolsBluetoothDeviceInfoComboBox(QWidget *parent = Q_NULLPTR);
~xToolsBluetoothDeviceInfoComboBox();
void startDiscover();
void stopDiscover();
bool isActive();
@ -34,12 +33,10 @@ protected:
virtual void changeEvent(QEvent *event) override;
private:
SAKBleScanner *mScanner;
xToolsBleScanner *mScanner;
private slots:
void onFinished();
void onDeviceDiscovered(const QBluetoothDeviceInfo &info);
void onErrorOccurred(const QString &errStr);
};
#endif // SAKBLUETOOTHDEVICEINFOCOMBOBOX_H

View File

@ -40,7 +40,7 @@
#include "xToolsWebSocketTransmitterToolUi.h"
#ifdef X_TOOLS_IMPORT_MODULE_BLUETOOTH
#include "sakblecentraltoolui.h"
#include "xToolsBleCentralToolUi.h"
#endif
xToolsToolBoxUi::xToolsToolBoxUi(QWidget* parent)
@ -171,7 +171,7 @@ xToolsCommunicationToolUi* xToolsToolBoxUi::communicationToolUi(int type)
}
#ifdef X_TOOLS_IMPORT_MODULE_BLUETOOTH
else if (type == xToolsToolFactory::BleCentralTool) {
w = new SAKBleCentralToolUi();
w = new xToolsBleCentralToolUi();
}
#endif
else {

View File

@ -32,7 +32,7 @@
#include "xToolsWebSocketTransmitterTool.h"
#ifdef X_TOOLS_IMPORT_MODULE_BLUETOOTH
#include "sakblecentraltool.h"
#include "xToolsBleCentralTool.h"
#endif
xToolsToolFactory::xToolsToolFactory(QObject *parent)
@ -79,7 +79,7 @@ xToolsBaseTool *xToolsToolFactory::createTool(int type)
}
#ifdef X_TOOLS_IMPORT_MODULE_BLUETOOTH
else if (BleCentralTool == type) {
tool = new SAKBleCentralTool();
tool = new xToolsBleCentralTool();
}
#endif
else if (StatistiticianTool == type) {

View File

@ -30,7 +30,7 @@
#include "xToolsWebSocketTransmitterToolUi.h"
#ifdef X_TOOLS_IMPORT_MODULE_BLUETOOTH
#include "sakblecentraltoolui.h"
#include "xToolsBleCentralToolUi.h"
#endif
xToolsToolUiFactory::xToolsToolUiFactory(QObject *parent)
@ -80,7 +80,7 @@ xToolsBaseToolUi *xToolsToolUiFactory::createToolUi(int type)
return new xToolsSocketServerToolUi();
#ifdef X_TOOLS_IMPORT_MODULE_BLUETOOTH
case xToolsToolFactory::BleCentralTool:
return new SAKBleCentralToolUi();
return new xToolsBleCentralToolUi();
#endif
case xToolsToolFactory::StatistiticianTool:
return new xToolsStatisticianToolUi();