mirror of
https://github.com/x-tools-author/x-tools.git
synced 2025-09-15 15:28:40 +08:00
chore: update signals and slots
This commit is contained in:
parent
6699e6b8a3
commit
6019ba0518
@ -194,9 +194,8 @@ void SAKBleCentralTool::readBytes()
|
||||
service->readCharacteristic(characteristic);
|
||||
}
|
||||
|
||||
void SAKBleCentralTool::writeBytes(const QByteArray &bytes, const QVariant &context)
|
||||
void SAKBleCentralTool::writeBytes(const QByteArray &bytes)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
if (!((mServiceIndex >= 0) && (mServiceIndex < mServices.length()))) {
|
||||
qWarning() << "invalid parameters.";
|
||||
return;
|
||||
@ -257,22 +256,21 @@ void SAKBleCentralTool::onServiceDiscoveryFinished()
|
||||
&QLowEnergyService::characteristicChanged,
|
||||
service,
|
||||
[=](const QLowEnergyCharacteristic &info, const QByteArray &value) {
|
||||
emit bytesOutputted(value, QVariant());
|
||||
Q_UNUSED(info);
|
||||
emit bytesOutput(value);
|
||||
emit bytesRead(value, info.name());
|
||||
});
|
||||
connect(service,
|
||||
&QLowEnergyService::characteristicRead,
|
||||
service,
|
||||
[=](const QLowEnergyCharacteristic &info, const QByteArray &value) {
|
||||
emit bytesOutputted(value, QVariant());
|
||||
Q_UNUSED(info);
|
||||
emit bytesOutput(value);
|
||||
emit bytesRead(value, info.name());
|
||||
});
|
||||
connect(service,
|
||||
&QLowEnergyService::characteristicWritten,
|
||||
service,
|
||||
[=](const QLowEnergyCharacteristic &info, const QByteArray &value) {
|
||||
emit bytesInputted(value, QVariant());
|
||||
Q_UNUSED(info);
|
||||
emit bytesWritten(value, info.name());
|
||||
});
|
||||
connect(service,
|
||||
&QLowEnergyService::stateChanged,
|
||||
|
||||
@ -45,10 +45,10 @@ signals:
|
||||
void serviceDiscoveryFinished();
|
||||
|
||||
protected:
|
||||
virtual bool initialize(QString &errStr) final;
|
||||
virtual void writeBytes(const QByteArray &bytes, const QVariant &context = QJsonObject()) final;
|
||||
virtual void readBytes() final;
|
||||
virtual void uninitialize() final;
|
||||
bool initialize(QString &errStr) override;
|
||||
void writeBytes(const QByteArray &bytes) override;
|
||||
void readBytes();
|
||||
void uninitialize() override;
|
||||
|
||||
private:
|
||||
QLowEnergyController *mBleCentral{nullptr};
|
||||
|
||||
@ -90,36 +90,36 @@ void SAKToolBox::initialize(int type)
|
||||
|
||||
// clang-format off
|
||||
// rx->output_masker->output_analyzer->responser
|
||||
connect(mComunicationTool, &SAKBaseTool::bytesOutputted, mRxMaskerTool, &SAKBaseTool::inputBytes);
|
||||
connect(mRxMaskerTool, &SAKBaseTool::bytesOutputted, mRxAnalyzerTool, &SAKBaseTool::inputBytes);
|
||||
connect(mRxAnalyzerTool, &SAKBaseTool::bytesOutputted, mResponserTool, &SAKBaseTool::inputBytes);
|
||||
connect(mComunicationTool, &SAKBaseTool::bytesOutput, mRxMaskerTool, &SAKBaseTool::inputBytes);
|
||||
connect(mRxMaskerTool, &SAKBaseTool::bytesOutput, mRxAnalyzerTool, &SAKBaseTool::inputBytes);
|
||||
connect(mRxAnalyzerTool, &SAKBaseTool::bytesOutput, mResponserTool, &SAKBaseTool::inputBytes);
|
||||
// emiiter,responser,prestorer->input_analyzer->input_masker->tx
|
||||
connect(mEmitterTool, &SAKBaseTool::bytesOutputted, mTxAnalyzerTool, &SAKBaseTool::inputBytes);
|
||||
connect(mResponserTool, &SAKBaseTool::bytesOutputted, mTxAnalyzerTool, &SAKBaseTool::inputBytes);
|
||||
connect(mPrestorerTool, &SAKBaseTool::bytesOutputted, mTxAnalyzerTool, &SAKBaseTool::inputBytes);
|
||||
connect(mTxAnalyzerTool, &SAKBaseTool::bytesOutputted, mTxMaskerTool, &SAKBaseTool::inputBytes);
|
||||
connect(mTxMaskerTool, &SAKBaseTool::bytesOutputted, mComunicationTool, &SAKBaseTool::inputBytes);
|
||||
connect(mEmitterTool, &SAKBaseTool::bytesOutput, mTxAnalyzerTool, &SAKBaseTool::inputBytes);
|
||||
connect(mResponserTool, &SAKBaseTool::bytesOutput, mTxAnalyzerTool, &SAKBaseTool::inputBytes);
|
||||
connect(mPrestorerTool, &SAKBaseTool::bytesOutput, mTxAnalyzerTool, &SAKBaseTool::inputBytes);
|
||||
connect(mTxAnalyzerTool, &SAKBaseTool::bytesOutput, mTxMaskerTool, &SAKBaseTool::inputBytes);
|
||||
connect(mTxMaskerTool, &SAKBaseTool::bytesOutput, mComunicationTool, &SAKBaseTool::inputBytes);
|
||||
// rx->storer; tx->storer
|
||||
connect(mRxAnalyzerTool, &SAKBaseTool::bytesOutputted, mStorerTool, &SAKBaseTool::inputBytes);
|
||||
connect(mTxMaskerTool, &SAKBaseTool::bytesInputted, mStorerTool, &SAKBaseTool::inputBytes);
|
||||
connect(mRxAnalyzerTool, &SAKBaseTool::bytesOutput, mStorerTool, &SAKBaseTool::inputBytes);
|
||||
connect(mTxMaskerTool, &SAKBaseTool::bytesOutput, mStorerTool, &SAKBaseTool::inputBytes);
|
||||
// rx->velometer; tx->velometer
|
||||
connect(mComunicationTool, &SAKBaseTool::bytesOutputted, mRxVelometerTool, &SAKBaseTool::inputBytes);
|
||||
connect(mComunicationTool, &SAKBaseTool::bytesInputted, mTxVelometerTool, &SAKBaseTool::inputBytes);
|
||||
connect(mComunicationTool, &SAKBaseTool::bytesOutput, mRxVelometerTool, &SAKBaseTool::inputBytes);
|
||||
connect(mComunicationTool, &SAKBaseTool::bytesOutput, mTxVelometerTool, &SAKBaseTool::inputBytes);
|
||||
// rx->statistician; tx->statistician
|
||||
connect(mRxAnalyzerTool, &SAKBaseTool::bytesOutputted, mRxStatisticianTool, &SAKBaseTool::inputBytes);
|
||||
connect(mComunicationTool, &SAKBaseTool::bytesInputted, mTxStatisticianTool, &SAKBaseTool::inputBytes);
|
||||
connect(mRxAnalyzerTool, &SAKBaseTool::bytesOutput, mRxStatisticianTool, &SAKBaseTool::inputBytes);
|
||||
connect(mComunicationTool, &SAKBaseTool::bytesOutput, mTxStatisticianTool, &SAKBaseTool::inputBytes);
|
||||
// rx->serialport transmition; serialport transmition->Tx analyzer
|
||||
connect(mRxAnalyzerTool, &SAKBaseTool::bytesOutputted, mSerialPortTransmitterTool, &SAKBaseTool::inputBytes);
|
||||
connect(mSerialPortTransmitterTool, &SAKBaseTool::bytesOutputted, mTxAnalyzerTool, &SAKBaseTool::inputBytes);
|
||||
connect(mRxAnalyzerTool, &SAKBaseTool::bytesOutput, mSerialPortTransmitterTool, &SAKBaseTool::inputBytes);
|
||||
connect(mSerialPortTransmitterTool, &SAKBaseTool::bytesOutput, mTxAnalyzerTool, &SAKBaseTool::inputBytes);
|
||||
// rx->udp transmition; udp transmition->Tx analyzer
|
||||
connect(mRxAnalyzerTool, &SAKBaseTool::bytesOutputted, mUdpTransmitterTool, &SAKBaseTool::inputBytes);
|
||||
connect(mUdpTransmitterTool, &SAKBaseTool::bytesOutputted, mTxAnalyzerTool, &SAKBaseTool::inputBytes);
|
||||
connect(mRxAnalyzerTool, &SAKBaseTool::bytesOutput, mUdpTransmitterTool, &SAKBaseTool::inputBytes);
|
||||
connect(mUdpTransmitterTool, &SAKBaseTool::bytesOutput, mTxAnalyzerTool, &SAKBaseTool::inputBytes);
|
||||
// rx->tcp transmition; tcp transmition->Tx analyzer
|
||||
connect(mRxAnalyzerTool, &SAKBaseTool::bytesOutputted, mTcpTransmitterTool, &SAKBaseTool::inputBytes);
|
||||
connect(mTcpTransmitterTool, &SAKBaseTool::bytesOutputted, mTxAnalyzerTool, &SAKBaseTool::inputBytes);
|
||||
connect(mRxAnalyzerTool, &SAKBaseTool::bytesOutput, mTcpTransmitterTool, &SAKBaseTool::inputBytes);
|
||||
connect(mTcpTransmitterTool, &SAKBaseTool::bytesOutput, mTxAnalyzerTool, &SAKBaseTool::inputBytes);
|
||||
// rx->websocket transmition; websocket transmition->Tx analyzer
|
||||
connect(mRxAnalyzerTool, &SAKBaseTool::bytesOutputted, mWebSocketTransmitterTool, &SAKBaseTool::inputBytes);
|
||||
connect(mWebSocketTransmitterTool, &SAKBaseTool::bytesOutputted, mTxAnalyzerTool, &SAKBaseTool::inputBytes);
|
||||
connect(mRxAnalyzerTool, &SAKBaseTool::bytesOutput, mWebSocketTransmitterTool, &SAKBaseTool::inputBytes);
|
||||
connect(mWebSocketTransmitterTool, &SAKBaseTool::bytesOutput, mTxAnalyzerTool, &SAKBaseTool::inputBytes);
|
||||
|
||||
connect(mComunicationTool, &SAKCommunicationTool::errorOccured, this, &SAKToolBox::errorOccurred);
|
||||
// clang-format on
|
||||
@ -160,9 +160,9 @@ void SAKToolBox::close()
|
||||
}
|
||||
}
|
||||
|
||||
void SAKToolBox::send(const QByteArray& bytes, const QVariant& context)
|
||||
void SAKToolBox::send(const QByteArray& bytes)
|
||||
{
|
||||
mTxAnalyzerTool->inputBytes(bytes, context);
|
||||
mTxAnalyzerTool->inputBytes(bytes);
|
||||
}
|
||||
|
||||
bool SAKToolBox::isWorking()
|
||||
|
||||
@ -59,7 +59,7 @@ public:
|
||||
|
||||
Q_INVOKABLE void open();
|
||||
Q_INVOKABLE void close();
|
||||
Q_INVOKABLE void send(const QByteArray& bytes, const QVariant& context = QJsonObject());
|
||||
Q_INVOKABLE void send(const QByteArray& bytes);
|
||||
bool isWorking();
|
||||
|
||||
SAKCommunicationTool* getCommunicationTool();
|
||||
|
||||
@ -202,7 +202,7 @@ void SAKToolBoxUi::try2send()
|
||||
|
||||
bytes.prepend(prefixData);
|
||||
bytes.append(suffixData);
|
||||
mToolBox->getTxAnalyzerTool()->inputBytes(bytes, QJsonObject());
|
||||
mToolBox->getTxAnalyzerTool()->inputBytes(bytes);
|
||||
}
|
||||
|
||||
QString SAKToolBoxUi::dateTimeFormat()
|
||||
@ -237,9 +237,8 @@ QString SAKToolBoxUi::dateTimeFormat()
|
||||
return QDateTime::currentDateTime().toString(dateTimeFormat);
|
||||
}
|
||||
|
||||
void SAKToolBoxUi::output2ui(const QByteArray& bytes, const QVariant& context, bool isRx)
|
||||
void SAKToolBoxUi::output2ui(const QByteArray& bytes, const QString& flag, bool isRx)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
int format = ui->comboBoxOutputFormat->currentData().toInt();
|
||||
QString str = SAKInterface::arrayToString(bytes, format);
|
||||
|
||||
@ -248,10 +247,10 @@ void SAKToolBoxUi::output2ui(const QByteArray& bytes, const QVariant& context, b
|
||||
}
|
||||
|
||||
QString dt = dateTimeFormat();
|
||||
QString flag = isRx ? "Rx" : "Tx";
|
||||
QString flags = isRx ? "Rx" : "Tx";
|
||||
QString color = isRx ? "red" : "blue";
|
||||
|
||||
flag = QString("<font color=%1>%2</font>").arg(color, flag);
|
||||
flags = QString("<font color=%1>%2</font>").arg(color, flags);
|
||||
QString info;
|
||||
if (dt.isEmpty()) {
|
||||
info = QString("[%1]").arg(flag);
|
||||
@ -338,22 +337,22 @@ void SAKToolBoxUi::onIsWorkingChanged()
|
||||
}
|
||||
}
|
||||
|
||||
void SAKToolBoxUi::onBytesWritten(const QByteArray& bytes, const QVariant& context)
|
||||
void SAKToolBoxUi::onBytesWritten(const QByteArray& bytes, const QString& to)
|
||||
{
|
||||
if (!ui->checkBoxOutputTx->isChecked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
output2ui(bytes, context, false);
|
||||
output2ui(bytes, to, false);
|
||||
}
|
||||
|
||||
void SAKToolBoxUi::onBytesRead(const QByteArray& bytes, const QVariant& context)
|
||||
void SAKToolBoxUi::onBytesRead(const QByteArray& bytes, const QString& from)
|
||||
{
|
||||
if (!ui->checkBoxOutputRx->isChecked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
output2ui(bytes, context, true);
|
||||
output2ui(bytes, from, true);
|
||||
}
|
||||
|
||||
void SAKToolBoxUi::onInputTextChanged()
|
||||
@ -630,12 +629,12 @@ void SAKToolBoxUi::initTools()
|
||||
});
|
||||
|
||||
connect(mCommunicationTool,
|
||||
&SAKCommunicationTool::bytesInputted,
|
||||
&SAKCommunicationTool::bytesWritten,
|
||||
this,
|
||||
&SAKToolBoxUi::onBytesWritten);
|
||||
|
||||
auto outputAnalyzer = mToolBox->getRxAnalyzerTool();
|
||||
connect(outputAnalyzer, &SAKAnalyzerTool::bytesOutputted, this, &::SAKToolBoxUi::onBytesRead);
|
||||
//connect(outputAnalyzer, &SAKAnalyzerTool::bytesOutput, this, &::SAKToolBoxUi::onBytesRead);
|
||||
|
||||
ui->pushButtonPrestorer->setMenu(mPrestorerToolUi->menu());
|
||||
}
|
||||
|
||||
@ -76,15 +76,15 @@ private:
|
||||
SAKCommunicationToolUi *communicationToolUi(int type);
|
||||
void try2send();
|
||||
QString dateTimeFormat();
|
||||
void output2ui(const QByteArray &bytes, const QVariant &context, bool isRx);
|
||||
void output2ui(const QByteArray &bytes, const QString &flag, bool isRx);
|
||||
QString settingsGroup();
|
||||
QByteArray calculateCrc(const QByteArray &bytes = QByteArray(), bool fixedOriginOrder = false);
|
||||
void setDefaultText();
|
||||
|
||||
private slots:
|
||||
void onIsWorkingChanged();
|
||||
void onBytesWritten(const QByteArray &bytes, const QVariant &context);
|
||||
void onBytesRead(const QByteArray &bytes, const QVariant &context);
|
||||
void onBytesWritten(const QByteArray &bytes, const QString &to);
|
||||
void onBytesRead(const QByteArray &bytes, const QString &from);
|
||||
void onInputTextChanged();
|
||||
|
||||
private:
|
||||
|
||||
@ -43,7 +43,7 @@ void SAKAnalyzerTool::setMaxTempBytes(int maxBytes)
|
||||
mParametersMutex.unlock();
|
||||
}
|
||||
|
||||
void SAKAnalyzerTool::inputBytes(const QByteArray &bytes, const QVariant &context)
|
||||
void SAKAnalyzerTool::inputBytes(const QByteArray &bytes)
|
||||
{
|
||||
if (bytes.isEmpty()) {
|
||||
outputMessage(QtInfoMsg,
|
||||
@ -54,12 +54,8 @@ void SAKAnalyzerTool::inputBytes(const QByteArray &bytes, const QVariant &contex
|
||||
|
||||
QString hex = QString::fromLatin1(SAKInterface::arrayToHex(bytes, ' '));
|
||||
outputMessage(QtInfoMsg, QString("%1<-%2").arg(mToolName, hex));
|
||||
emit bytesInputted(bytes, context);
|
||||
|
||||
if (enable()) {
|
||||
if (mContext != context) {
|
||||
mContext = context;
|
||||
}
|
||||
mInputtedBytesMutex.lock();
|
||||
mInputtedBytes.append(bytes);
|
||||
mInputtedBytesMutex.unlock();
|
||||
@ -67,7 +63,7 @@ void SAKAnalyzerTool::inputBytes(const QByteArray &bytes, const QVariant &contex
|
||||
QByteArray ba = SAKInterface::arrayToHex(bytes, ' ');
|
||||
QString hex = QString::fromLatin1(ba);
|
||||
outputMessage(QtInfoMsg, QString("%1->%2").arg(mToolName, hex));
|
||||
emit bytesOutputted(bytes, context);
|
||||
emit bytesOutput(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,7 +109,7 @@ void SAKAnalyzerTool::analyze()
|
||||
if (mInputtedBytes.length() > ctx.maxTempBytes) {
|
||||
QByteArray ba = SAKInterface::arrayToHex(mInputtedBytes, ' ');
|
||||
outputMessage(QtInfoMsg, "clear bytes: " + QString::fromLatin1(ba));
|
||||
emit bytesOutputted(mInputtedBytes, mContext);
|
||||
emit bytesOutput(mInputtedBytes);
|
||||
mInputtedBytes.clear();
|
||||
}
|
||||
}
|
||||
@ -131,7 +127,7 @@ void SAKAnalyzerTool::analyzeFixed()
|
||||
QByteArray ba = SAKInterface::arrayToHex(frame, ' ');
|
||||
QString hex = QString::fromLatin1(ba);
|
||||
outputMessage(QtInfoMsg, QString("Analyzer->%1").arg(hex));
|
||||
emit bytesOutputted(frame, mContext);
|
||||
emit bytesOutput(frame);
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,7 +145,7 @@ void SAKAnalyzerTool::analyzeSeparationMark()
|
||||
QString hex = QString::fromLatin1(ba);
|
||||
QString msg = QString("Analyzer->%1").arg(hex);
|
||||
outputMessage(QtInfoMsg, msg);
|
||||
emit bytesOutputted(mInputtedBytes, mContext);
|
||||
emit bytesOutput(mInputtedBytes);
|
||||
mInputtedBytes.clear();
|
||||
return;
|
||||
}
|
||||
@ -167,5 +163,5 @@ void SAKAnalyzerTool::analyzeSeparationMark()
|
||||
QString hex = QString::fromLatin1(ba);
|
||||
QString msg = QString("Analyzer->%1").arg(hex);
|
||||
outputMessage(QtInfoMsg, msg);
|
||||
emit bytesOutputted(frame, mContext);
|
||||
emit bytesOutput(frame);
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ public:
|
||||
Q_INVOKABLE void setSeparationMark(const QByteArray &mark);
|
||||
Q_INVOKABLE void setMaxTempBytes(int maxBytes);
|
||||
|
||||
virtual void inputBytes(const QByteArray &bytes, const QVariant &context = QJsonObject()) final;
|
||||
void inputBytes(const QByteArray &bytes) override;
|
||||
|
||||
protected:
|
||||
virtual void run() final;
|
||||
|
||||
@ -38,9 +38,9 @@ SAKBaseTool::~SAKBaseTool()
|
||||
}
|
||||
}
|
||||
|
||||
void SAKBaseTool::inputBytes(const QByteArray &bytes, const QVariant &context)
|
||||
void SAKBaseTool::inputBytes(const QByteArray &bytes)
|
||||
{
|
||||
emit bytesInputted(bytes, context);
|
||||
emit bytesOutput(bytes);
|
||||
}
|
||||
|
||||
void SAKBaseTool::outputMessage(int type, const QString &info) const
|
||||
|
||||
@ -32,11 +32,10 @@ public:
|
||||
* @param bytes: The bytes input.
|
||||
* @param context: The extension parameters.
|
||||
*/
|
||||
virtual void inputBytes(const QByteArray &bytes, const QVariant &context = QJsonObject());
|
||||
virtual void inputBytes(const QByteArray &bytes);
|
||||
|
||||
signals:
|
||||
void bytesInputted(const QByteArray &bytes, const QVariant &context);
|
||||
void bytesOutputted(const QByteArray &bytes, const QVariant &context);
|
||||
void bytesOutput(const QByteArray &bytes);
|
||||
void errorOccured(const QString &errorString);
|
||||
|
||||
protected:
|
||||
|
||||
@ -13,19 +13,17 @@ SAKCommunicationTool::SAKCommunicationTool(QObject *parent)
|
||||
: SAKBaseTool{parent}
|
||||
{}
|
||||
|
||||
void SAKCommunicationTool::inputBytes(const QByteArray &bytes, const QVariant &context)
|
||||
SAKCommunicationTool::~SAKCommunicationTool() {}
|
||||
|
||||
void SAKCommunicationTool::inputBytes(const QByteArray &bytes)
|
||||
{
|
||||
if (!enable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
mInputDataMutex.lock();
|
||||
QJsonObject jsonObj = context.toJsonObject();
|
||||
jsonObj.insert("flag", "tx");
|
||||
QVariant cookedContext = QVariant::fromValue(jsonObj);
|
||||
InputDataContext dataCtx{bytes, cookedContext};
|
||||
mInputDataList.append(dataCtx);
|
||||
mInputDataMutex.unlock();
|
||||
m_inputBytesMutex.lock();
|
||||
m_inputBytesList.append(bytes);
|
||||
m_inputBytesMutex.unlock();
|
||||
}
|
||||
|
||||
QJsonObject SAKCommunicationTool::rxJsonObject() const
|
||||
@ -55,12 +53,12 @@ void SAKCommunicationTool::run()
|
||||
txTimer->setInterval(5);
|
||||
txTimer->setSingleShot(true);
|
||||
connect(txTimer, &QTimer::timeout, txTimer, [=]() {
|
||||
this->mInputDataMutex.lock();
|
||||
if (!mInputDataList.isEmpty()) {
|
||||
InputDataContext dataCtx = mInputDataList.takeFirst();
|
||||
writeBytes(dataCtx.bytes, dataCtx.context);
|
||||
this->m_inputBytesMutex.lock();
|
||||
if (!m_inputBytesList.isEmpty()) {
|
||||
auto bytes = m_inputBytesList.takeFirst();
|
||||
writeBytes(bytes);
|
||||
}
|
||||
this->mInputDataMutex.unlock();
|
||||
this->m_inputBytesMutex.unlock();
|
||||
txTimer->start();
|
||||
});
|
||||
txTimer->start();
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
#define SAKCOMMUNICATIONTOOL_H
|
||||
|
||||
#include "sakbasetool.h"
|
||||
|
||||
#include <QMutex>
|
||||
|
||||
class SAKCommunicationTool : public SAKBaseTool
|
||||
@ -17,32 +18,26 @@ class SAKCommunicationTool : public SAKBaseTool
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SAKCommunicationTool(QObject *parent = nullptr);
|
||||
virtual void inputBytes(const QByteArray &bytes, const QVariant &context = QJsonObject()) final;
|
||||
~SAKCommunicationTool() override;
|
||||
void inputBytes(const QByteArray &bytes) override;
|
||||
|
||||
signals:
|
||||
void bytesRead(const QByteArray &bytes, const QString &from);
|
||||
void bytesWritten(const QByteArray &bytes, const QString &to);
|
||||
|
||||
protected:
|
||||
struct InputDataContext
|
||||
{
|
||||
QByteArray bytes;
|
||||
QVariant context;
|
||||
};
|
||||
|
||||
protected:
|
||||
virtual void run() final;
|
||||
virtual void run() override;
|
||||
|
||||
virtual bool initialize(QString &errStr) = 0;
|
||||
virtual void writeBytes(const QByteArray &bytes, const QVariant &context = QJsonObject()) = 0;
|
||||
virtual void writeBytes(const QByteArray &bytes) = 0;
|
||||
virtual void uninitialize() = 0;
|
||||
|
||||
QJsonObject rxJsonObject() const;
|
||||
QJsonObject txJsonObject() const;
|
||||
|
||||
private:
|
||||
QList<InputDataContext> mInputDataList;
|
||||
QMutex mInputDataMutex;
|
||||
QList<QByteArray> m_inputBytesList;
|
||||
QMutex m_inputBytesMutex;
|
||||
};
|
||||
|
||||
#endif // SAKCOMMUNICATIONTOOL_H
|
||||
|
||||
@ -62,7 +62,7 @@ void SAKCrcCalculatorTool::setBigEndian(bool bigEndian)
|
||||
m_bigEndian = bigEndian;
|
||||
}
|
||||
|
||||
void SAKCrcCalculatorTool::inputBytes(const QByteArray &bytes, const QVariant &context)
|
||||
void SAKCrcCalculatorTool::inputBytes(const QByteArray &bytes)
|
||||
{
|
||||
QByteArray crc = m_crcInterface->calculateBytes(bytes,
|
||||
m_algorithm,
|
||||
@ -72,5 +72,5 @@ void SAKCrcCalculatorTool::inputBytes(const QByteArray &bytes, const QVariant &c
|
||||
QByteArray cookedBytes = bytes;
|
||||
cookedBytes.append(crc);
|
||||
|
||||
emit bytesOutputted(cookedBytes, context);
|
||||
emit bytesOutput(cookedBytes);
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ public:
|
||||
bool bigEndian() const;
|
||||
void setBigEndian(bool bigEndian);
|
||||
|
||||
void inputBytes(const QByteArray &bytes, const QVariant &context = QJsonObject()) override;
|
||||
void inputBytes(const QByteArray &bytes) override;
|
||||
|
||||
private:
|
||||
int m_startIndex;
|
||||
@ -38,4 +38,4 @@ private:
|
||||
SAKCrcInterface *m_crcInterface;
|
||||
};
|
||||
|
||||
#endif // SAKCRCCALCULATORTOOL_H
|
||||
#endif // SAKCRCCALCULATORTOOL_H
|
||||
|
||||
@ -255,7 +255,7 @@ void SAKEmitterTool::try2emit()
|
||||
if (elapsedTime > item.data.itemInterval && item.data.itemEnable) {
|
||||
item.elapsedTime = 0;
|
||||
const auto bytes = itemBytes(item.data);
|
||||
emit bytesOutputted(bytes, QVariant());
|
||||
emit bytesOutput(bytes);
|
||||
}
|
||||
}
|
||||
mItemsMutex.unlock();
|
||||
|
||||
@ -19,24 +19,19 @@ SAKMaskerTool::SAKMaskerTool(QObject *parent)
|
||||
|
||||
SAKMaskerTool::~SAKMaskerTool()
|
||||
{
|
||||
qDebug() << __FUNCTION__;
|
||||
|
||||
}
|
||||
|
||||
void SAKMaskerTool::inputBytes(const QByteArray &bytes)
|
||||
{
|
||||
m_inputBytesListMutex.lock();
|
||||
m_inputBytesList.append(bytes);
|
||||
m_inputBytesListMutex.unlock();
|
||||
}
|
||||
|
||||
void SAKMaskerTool::setMaskCode(qint8 maskCode)
|
||||
{
|
||||
mMask = maskCode;
|
||||
}
|
||||
|
||||
void SAKMaskerTool::inputBytes(const QByteArray &bytes, const QVariant &context)
|
||||
{
|
||||
emit bytesInputted(bytes, context);
|
||||
|
||||
mInputParametersListMutex.lock();
|
||||
InputParameters params;
|
||||
params.bytes = bytes;
|
||||
params.context = context;
|
||||
mInputParametersList.append(params);
|
||||
mInputParametersListMutex.unlock();
|
||||
m_mask = maskCode;
|
||||
}
|
||||
|
||||
void SAKMaskerTool::run()
|
||||
@ -46,14 +41,11 @@ void SAKMaskerTool::run()
|
||||
timer->setSingleShot(true);
|
||||
connect(timer, &QTimer::timeout, timer, [=]() {
|
||||
QByteArray bytes;
|
||||
QVariant context;
|
||||
this->mInputParametersListMutex.lock();
|
||||
if (!this->mInputParametersList.isEmpty()) {
|
||||
auto ctx = mInputParametersList.takeFirst();
|
||||
bytes = ctx.bytes;
|
||||
context = ctx.context;
|
||||
this->m_inputBytesListMutex.lock();
|
||||
if (!this->m_inputBytesList.isEmpty()) {
|
||||
auto ctx = m_inputBytesList.takeFirst();
|
||||
}
|
||||
this->mInputParametersListMutex.unlock();
|
||||
this->m_inputBytesListMutex.unlock();
|
||||
|
||||
if (!bytes.isEmpty()) {
|
||||
QByteArray ba = SAKInterface::arrayToHex(bytes, ' ');
|
||||
@ -64,19 +56,19 @@ void SAKMaskerTool::run()
|
||||
QByteArray cookedBytes;
|
||||
for (int i = 0; i < bytes.length(); i++) {
|
||||
quint8 value = quint8(bytes.at(i));
|
||||
value ^= mMask;
|
||||
value ^= m_mask;
|
||||
cookedBytes.append(reinterpret_cast<char *>(&value), 1);
|
||||
}
|
||||
|
||||
ba = SAKInterface::arrayToHex(cookedBytes, ' ');
|
||||
QString hex = QString::fromLatin1(ba);
|
||||
outputMessage(QtInfoMsg, QString("%1->%2").arg(mToolName, hex));
|
||||
emit bytesOutputted(cookedBytes, context);
|
||||
emit bytesOutput(cookedBytes);
|
||||
} else {
|
||||
ba = SAKInterface::arrayToHex(bytes, ' ');
|
||||
QString hex = QString::fromLatin1(ba);
|
||||
outputMessage(QtInfoMsg, QString("%1->%2").arg(mToolName, hex));
|
||||
emit bytesOutputted(bytes, context);
|
||||
emit bytesOutput(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -19,26 +19,19 @@ class SAKMaskerTool : public SAKBaseTool
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SAKMaskerTool(QObject *parent = Q_NULLPTR);
|
||||
~SAKMaskerTool();
|
||||
~SAKMaskerTool() override;
|
||||
|
||||
void inputBytes(const QByteArray &bytes) override;
|
||||
|
||||
Q_INVOKABLE void setMaskCode(qint8 maskCode);
|
||||
|
||||
virtual void inputBytes(const QByteArray &bytes, const QVariant &context = QJsonObject()) final;
|
||||
|
||||
protected:
|
||||
void run();
|
||||
void run() override;
|
||||
|
||||
private:
|
||||
struct InputParameters
|
||||
{
|
||||
QByteArray bytes;
|
||||
QVariant context;
|
||||
};
|
||||
|
||||
private:
|
||||
std::atomic<quint8> mMask;
|
||||
QList<InputParameters> mInputParametersList;
|
||||
QMutex mInputParametersListMutex;
|
||||
std::atomic<quint8> m_mask;
|
||||
QList<QByteArray> m_inputBytesList;
|
||||
QMutex m_inputBytesListMutex;
|
||||
};
|
||||
|
||||
#endif // SAKMASKERTOOL_H
|
||||
|
||||
@ -315,7 +315,7 @@ void SAKPrestorerTool::try2send()
|
||||
if (index >= 0 && index < mItems.count()) {
|
||||
auto item = mItems.at(index);
|
||||
QByteArray bytes = itemBytes(item);
|
||||
emit bytesOutputted(bytes, QVariant());
|
||||
emit bytesOutput(bytes);
|
||||
}
|
||||
mItemsMutex.unlock();
|
||||
}
|
||||
|
||||
@ -513,7 +513,7 @@ void SAKResponserTool::try2output(const SAKResponserTool::InputContext &ctx, QOb
|
||||
}
|
||||
|
||||
QTimer::singleShot(item.data.itemResponseDelay, receiver, [=]() {
|
||||
emit bytesOutputted(item.data.itemResponseText.toUtf8(), ctx.context);
|
||||
emit bytesOutput(item.data.itemResponseText.toUtf8());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,7 +109,7 @@ bool SAKSerialPortTool::initialize(QString &errStr)
|
||||
return true;
|
||||
}
|
||||
|
||||
void SAKSerialPortTool::writeBytes(const QByteArray &bytes, const QVariant &context)
|
||||
void SAKSerialPortTool::writeBytes(const QByteArray &bytes)
|
||||
{
|
||||
if (mSerialPort && mSerialPort->isOpen()) {
|
||||
qint64 ret = mSerialPort->write(bytes);
|
||||
@ -120,7 +120,7 @@ void SAKSerialPortTool::writeBytes(const QByteArray &bytes, const QVariant &cont
|
||||
QString msg = QString::fromLatin1(hex);
|
||||
msg = QString("%1<-%2").arg(mParameters.portName, msg);
|
||||
outputMessage(QtInfoMsg, msg);
|
||||
emit bytesInputted(bytes, context);
|
||||
emit bytesWritten(bytes, mSerialPort->portName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -134,7 +134,8 @@ void SAKSerialPortTool::readBytes()
|
||||
QString msg = QString::fromLatin1(hex);
|
||||
msg = QString("%1<-%2").arg(mParameters.portName, msg);
|
||||
outputMessage(QtInfoMsg, msg);
|
||||
emit bytesOutputted(bytes, rxJsonObject());
|
||||
emit bytesOutput(bytes);
|
||||
emit bytesRead(bytes, mSerialPort->portName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,10 +54,10 @@ signals:
|
||||
void flowControlChanged();
|
||||
|
||||
protected:
|
||||
virtual bool initialize(QString &errStr) final;
|
||||
virtual void writeBytes(const QByteArray &bytes, const QVariant &context = QJsonObject()) final;
|
||||
virtual void readBytes() final;
|
||||
virtual void uninitialize() final;
|
||||
bool initialize(QString &errStr) override;
|
||||
void writeBytes(const QByteArray &bytes);
|
||||
void readBytes();
|
||||
void uninitialize() override;
|
||||
|
||||
private:
|
||||
struct
|
||||
|
||||
@ -65,7 +65,7 @@ QVariant SAKSerialPortTransmitterTool::itemContext(int index)
|
||||
return obj;
|
||||
}
|
||||
|
||||
void SAKSerialPortTransmitterTool::inputBytes(const QByteArray &bytes, const QVariant &context)
|
||||
void SAKSerialPortTransmitterTool::inputBytes(const QByteArray &bytes)
|
||||
{
|
||||
QByteArray ba = SAKInterface::arrayToHex(bytes, ' ');
|
||||
QString hex = QString::fromLatin1(ba);
|
||||
@ -73,7 +73,7 @@ void SAKSerialPortTransmitterTool::inputBytes(const QByteArray &bytes, const QVa
|
||||
|
||||
mToolVectorMutex.lock();
|
||||
for (auto tool : mToolVector) {
|
||||
tool->inputBytes(bytes, context);
|
||||
tool->inputBytes(bytes);
|
||||
}
|
||||
mToolVectorMutex.unlock();
|
||||
}
|
||||
|
||||
@ -34,8 +34,7 @@ public:
|
||||
explicit SAKSerialPortTransmitterTool(QObject *parent = nullptr);
|
||||
virtual QString cookHeaderString(const QString &str) override;
|
||||
Q_INVOKABLE virtual QVariant itemContext(int index) override;
|
||||
virtual void inputBytes(const QByteArray &bytes,
|
||||
const QVariant &context = QJsonObject()) override;
|
||||
virtual void inputBytes(const QByteArray &bytes) override;
|
||||
|
||||
protected:
|
||||
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
@ -52,14 +52,13 @@ bool SAKTcpClientTool::initialize(QString& errStr)
|
||||
return true;
|
||||
}
|
||||
|
||||
void SAKTcpClientTool::writeBytes(const QByteArray& bytes, const QVariant& context)
|
||||
void SAKTcpClientTool::writeBytes(const QByteArray& bytes)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
qint64 ret = mTcpSocket->write(bytes);
|
||||
if (ret == -1) {
|
||||
outputMessage(QtWarningMsg, mTcpSocket->errorString());
|
||||
} else {
|
||||
emit bytesInputted(bytes, QVariant());
|
||||
emit bytesWritten(bytes, mBindingIpPort);
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,6 +81,7 @@ void SAKTcpClientTool::readBytes()
|
||||
QString info = mBindingIpPort + "<-" + ipport + ":";
|
||||
info += QString::fromLatin1(ba);
|
||||
outputMessage(QtDebugMsg, info);
|
||||
emit bytesOutputted(bytes, rxJsonObject());
|
||||
emit bytesOutput(bytes);
|
||||
emit bytesWritten(bytes, ipport);
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ public:
|
||||
|
||||
protected:
|
||||
virtual bool initialize(QString &errStr) final;
|
||||
virtual void writeBytes(const QByteArray &bytes, const QVariant &context = QJsonObject()) final;
|
||||
virtual void writeBytes(const QByteArray &bytes) final;
|
||||
void readBytes();
|
||||
virtual void uninitialize() final;
|
||||
|
||||
|
||||
@ -43,7 +43,7 @@ bool SAKTcpServerTool::initialize(QString &errStr)
|
||||
QByteArray bytes = client->readAll();
|
||||
QString hex = bytes.toHex();
|
||||
outputMessage(QtInfoMsg, QString("%1<-%2:%3").arg(mBindingIpPort, ipPort, hex));
|
||||
emit bytesOutputted(bytes, QVariant());
|
||||
emit bytesOutput(bytes);
|
||||
});
|
||||
|
||||
connect(client, &QTcpSocket::disconnected, client, [=]() {
|
||||
@ -71,15 +71,14 @@ bool SAKTcpServerTool::initialize(QString &errStr)
|
||||
return true;
|
||||
}
|
||||
|
||||
void SAKTcpServerTool::writeBytes(const QByteArray &bytes, const QVariant &context)
|
||||
void SAKTcpServerTool::writeBytes(const QByteArray &bytes)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
if (mClientIndex >= 0 && mClientIndex < mTcpSocketList.length()) {
|
||||
QTcpSocket *client = mTcpSocketList.at(mClientIndex);
|
||||
writeBytesInner(client, bytes, context);
|
||||
writeBytesInner(client, bytes);
|
||||
} else {
|
||||
for (auto &client : mTcpSocketList) {
|
||||
writeBytesInner(client, bytes, context);
|
||||
writeBytesInner(client, bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -91,9 +90,7 @@ void SAKTcpServerTool::uninitialize()
|
||||
mTcpServer = nullptr;
|
||||
}
|
||||
|
||||
void SAKTcpServerTool::writeBytesInner(QTcpSocket *client,
|
||||
const QByteArray &bytes,
|
||||
const QVariant &context)
|
||||
void SAKTcpServerTool::writeBytesInner(QTcpSocket *client, const QByteArray &bytes)
|
||||
{
|
||||
qint64 ret = client->write(bytes);
|
||||
if (ret == -1) {
|
||||
@ -104,6 +101,6 @@ void SAKTcpServerTool::writeBytesInner(QTcpSocket *client,
|
||||
QString ipPort = QString("%1:%2").arg(ip).arg(port);
|
||||
QString hex = bytes.toHex();
|
||||
outputMessage(QtInfoMsg, QString("%1->%2:%3").arg(mBindingIpPort, ipPort, hex));
|
||||
emit bytesInputted(bytes, context);
|
||||
emit bytesWritten(bytes, ipPort);
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,14 +20,12 @@ public:
|
||||
explicit SAKTcpServerTool(QObject *parent = nullptr);
|
||||
|
||||
protected:
|
||||
virtual bool initialize(QString &errStr) final;
|
||||
virtual void writeBytes(const QByteArray &bytes, const QVariant &context = QJsonObject()) final;
|
||||
virtual bool initialize(QString &errStr) override;
|
||||
virtual void writeBytes(const QByteArray &bytes) override;
|
||||
virtual void uninitialize() final;
|
||||
|
||||
private:
|
||||
void writeBytesInner(QTcpSocket *client,
|
||||
const QByteArray &bytes,
|
||||
const QVariant &context = QJsonObject());
|
||||
void writeBytesInner(QTcpSocket *client, const QByteArray &bytes);
|
||||
|
||||
private:
|
||||
QTcpServer *mTcpServer{nullptr};
|
||||
|
||||
@ -71,11 +71,7 @@ bool SAKTransmitterTool::insertRows(int row, int count, const QModelIndex &paren
|
||||
|
||||
auto initTool = [=](SAKCommunicationTool *tool) {
|
||||
tool->setParent(this);
|
||||
connect(this, &SAKCommunicationTool::bytesInputted, tool, &SAKCommunicationTool::inputBytes);
|
||||
connect(tool,
|
||||
&SAKCommunicationTool::bytesOutputted,
|
||||
this,
|
||||
&SAKCommunicationTool::bytesOutputted);
|
||||
connect(this, &SAKCommunicationTool::bytesOutput, tool, &SAKCommunicationTool::inputBytes);
|
||||
connect(this, &SAKCommunicationTool::started, tool, [=]() { tool->start(); });
|
||||
connect(this, &SAKCommunicationTool::finished, tool, [=]() { tool->exit(); });
|
||||
|
||||
|
||||
@ -48,7 +48,7 @@ bool SAKUdpClientTool::initialize(QString &errStr)
|
||||
return true;
|
||||
}
|
||||
|
||||
void SAKUdpClientTool::writeBytes(const QByteArray &bytes, const QVariant &context)
|
||||
void SAKUdpClientTool::writeBytes(const QByteArray &bytes)
|
||||
{
|
||||
if (mServerIp.isEmpty()) {
|
||||
return;
|
||||
@ -67,7 +67,7 @@ void SAKUdpClientTool::writeBytes(const QByteArray &bytes, const QVariant &conte
|
||||
QString serverInfo = QString("%1:%2").arg(mServerIp, portStr);
|
||||
QString info = mBindingIpPort + "->" + serverInfo + ":" + hex;
|
||||
outputMessage(QtInfoMsg, info);
|
||||
emit bytesInputted(bytes, context);
|
||||
emit bytesWritten(bytes, info);
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,7 +98,8 @@ void SAKUdpClientTool::readBytes()
|
||||
QString serverInfo = address.toString() + ":" + portStr;
|
||||
QString info = mBindingIpPort + "<-" + serverInfo + ":" + hex;
|
||||
outputMessage(QtInfoMsg, info);
|
||||
emit bytesOutputted(bytes, QVariant());
|
||||
emit bytesOutput(bytes);
|
||||
emit bytesRead(bytes, mBindingIpPort);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,8 +19,8 @@ public:
|
||||
explicit SAKUdpClientTool(QObject *parent = nullptr);
|
||||
|
||||
protected:
|
||||
virtual bool initialize(QString &errStr) final;
|
||||
virtual void writeBytes(const QByteArray &bytes, const QVariant &context = QJsonObject()) final;
|
||||
virtual bool initialize(QString &errStr) override;
|
||||
virtual void writeBytes(const QByteArray &bytes) override;
|
||||
virtual void uninitialize() final;
|
||||
void readBytes();
|
||||
|
||||
|
||||
@ -45,20 +45,20 @@ bool SAKUdpServerTool::initialize(QString &errStr)
|
||||
return true;
|
||||
}
|
||||
|
||||
void SAKUdpServerTool::writeBytes(const QByteArray &bytes, const QVariant &context)
|
||||
void SAKUdpServerTool::writeBytes(const QByteArray &bytes)
|
||||
{
|
||||
if (mClientIndex >= 0 && mClientIndex < mClients.length()) {
|
||||
QString ipPort = mClients.at(mClientIndex);
|
||||
QStringList list = ipPort.split(":");
|
||||
QString ip = list.first();
|
||||
quint16 port = list.last().toInt();
|
||||
writeDatagram(bytes, context, ip, port);
|
||||
writeDatagram(bytes, ip, port);
|
||||
} else {
|
||||
for (auto &client : mClients) {
|
||||
QStringList list = client.split(":");
|
||||
QString ip = list.first();
|
||||
quint16 port = list.last().toInt();
|
||||
writeDatagram(bytes, context, ip, port);
|
||||
writeDatagram(bytes, ip, port);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -97,12 +97,12 @@ void SAKUdpServerTool::readBytes()
|
||||
emit clientsChanged();
|
||||
}
|
||||
|
||||
emit bytesOutputted(bytes, info);
|
||||
emit bytesOutput(bytes);
|
||||
emit bytesRead(bytes, info);
|
||||
}
|
||||
}
|
||||
|
||||
void SAKUdpServerTool::writeDatagram(const QByteArray &bytes,
|
||||
const QVariant &context,
|
||||
const QString &ip,
|
||||
quint16 port)
|
||||
{
|
||||
@ -112,6 +112,6 @@ void SAKUdpServerTool::writeDatagram(const QByteArray &bytes,
|
||||
} else {
|
||||
QString hex = QString::fromLatin1(SAKInterface::arrayToHex(bytes, ' '));
|
||||
outputMessage(QtInfoMsg, QString("%1<-%2").arg(mBindingIpPort, hex));
|
||||
emit bytesInputted(bytes, context);
|
||||
emit bytesWritten(bytes, mBindingIpPort);
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,8 +19,8 @@ public:
|
||||
explicit SAKUdpServerTool(QObject *parent = nullptr);
|
||||
|
||||
protected:
|
||||
virtual bool initialize(QString &errStr) final;
|
||||
virtual void writeBytes(const QByteArray &bytes, const QVariant &context = QJsonObject()) final;
|
||||
virtual bool initialize(QString &errStr) override;
|
||||
virtual void writeBytes(const QByteArray &bytes) override;
|
||||
virtual void uninitialize() final;
|
||||
void readBytes();
|
||||
|
||||
@ -28,10 +28,7 @@ private:
|
||||
QUdpSocket *mUdpSocket{nullptr};
|
||||
|
||||
private:
|
||||
void writeDatagram(const QByteArray &bytes,
|
||||
const QVariant &context,
|
||||
const QString &ip,
|
||||
quint16 port);
|
||||
void writeDatagram(const QByteArray &bytes, const QString &ip, quint16 port);
|
||||
};
|
||||
|
||||
#endif // SAKUDPSERVERTOOL_H
|
||||
|
||||
@ -44,13 +44,15 @@ bool SAKWebSocketClientTool::initialize(QString &errStr)
|
||||
QString hex = QString::fromLatin1(ba);
|
||||
QString info = mBindingIpPort + "<-" + this->m_peerInfo + ":" + hex;
|
||||
outputMessage(QtInfoMsg, info);
|
||||
emit bytesOutputted(msg, rxJsonObject());
|
||||
emit bytesOutput(msg);
|
||||
emit bytesRead(msg, this->m_peerInfo);
|
||||
});
|
||||
|
||||
connect(m_webSocket, &QWebSocket::textMessageReceived, m_webSocket, [=](QString message) {
|
||||
QString info = mBindingIpPort + "<-" + this->m_peerInfo + ":" + message;
|
||||
outputMessage(QtInfoMsg, info);
|
||||
emit bytesOutputted(message.toUtf8(), rxJsonObject());
|
||||
emit bytesOutput(message.toUtf8());
|
||||
emit bytesRead(message.toUtf8(), this->m_peerInfo);
|
||||
});
|
||||
|
||||
connect(m_webSocket, SAK_SIG_WEBSOCKETERROROCCURRED, m_webSocket, [=]() {
|
||||
@ -66,9 +68,8 @@ bool SAKWebSocketClientTool::initialize(QString &errStr)
|
||||
return true;
|
||||
}
|
||||
|
||||
void SAKWebSocketClientTool::writeBytes(const QByteArray &bytes, const QVariant &context)
|
||||
void SAKWebSocketClientTool::writeBytes(const QByteArray &bytes)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
qint64 ret = -1;
|
||||
QString hex;
|
||||
if (mMessageType == 0) {
|
||||
@ -84,7 +85,7 @@ void SAKWebSocketClientTool::writeBytes(const QByteArray &bytes, const QVariant
|
||||
} else {
|
||||
QString info = mBindingIpPort + "<-" + this->m_peerInfo + ":" + hex;
|
||||
outputMessage(QtInfoMsg, info);
|
||||
emit bytesInputted(bytes, txJsonObject());
|
||||
emit bytesWritten(bytes, this->m_peerInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -20,8 +20,8 @@ public:
|
||||
explicit SAKWebSocketClientTool(QObject *parent = Q_NULLPTR);
|
||||
|
||||
protected:
|
||||
virtual bool initialize(QString &errStr) final;
|
||||
virtual void writeBytes(const QByteArray &bytes, const QVariant &context = QJsonObject()) final;
|
||||
virtual bool initialize(QString &errStr) override;
|
||||
virtual void writeBytes(const QByteArray &bytes) override;
|
||||
virtual void uninitialize() final;
|
||||
|
||||
private:
|
||||
|
||||
@ -60,7 +60,8 @@ bool SAKWebSocketServerTool::initialize(QString &errStr)
|
||||
QString ipport = QString("%1:%2").arg(ip, QString::number(port));
|
||||
QString hex = QString::fromUtf8(bytes);
|
||||
outputMessage(QtInfoMsg, QString("%1<-%2:%3").arg(mBindingIpPort, ipport, hex));
|
||||
emit bytesOutputted(bytes, QVariant());
|
||||
emit bytesOutput(bytes);
|
||||
emit bytesRead(bytes, ipport);
|
||||
});
|
||||
|
||||
connect(client, &QWebSocket::binaryMessageReceived, client, [=](const QByteArray &message) {
|
||||
@ -69,7 +70,8 @@ bool SAKWebSocketServerTool::initialize(QString &errStr)
|
||||
QString ipport = QString("%1:%2").arg(ip, QString::number(port));
|
||||
QString hex = QString::fromUtf8(message);
|
||||
outputMessage(QtInfoMsg, QString("%1<-%2:%3").arg(mBindingIpPort, ipport, hex));
|
||||
emit bytesOutputted(message, QVariant());
|
||||
emit bytesOutput(message);
|
||||
emit bytesRead(message, ipport);
|
||||
});
|
||||
|
||||
connect(client, &QWebSocket::disconnected, client, [=]() {
|
||||
@ -100,15 +102,14 @@ bool SAKWebSocketServerTool::initialize(QString &errStr)
|
||||
return true;
|
||||
}
|
||||
|
||||
void SAKWebSocketServerTool::writeBytes(const QByteArray &bytes, const QVariant &context)
|
||||
void SAKWebSocketServerTool::writeBytes(const QByteArray &bytes)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
if (mClientIndex >= 0 && mClientIndex < mWebSocketList.length()) {
|
||||
QWebSocket *client = mWebSocketList.at(mClientIndex);
|
||||
writeBytesInner(client, bytes, context);
|
||||
writeBytesInner(client, bytes);
|
||||
} else {
|
||||
for (auto &client : mWebSocketList) {
|
||||
writeBytesInner(client, bytes, context);
|
||||
writeBytesInner(client, bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -141,6 +142,6 @@ void SAKWebSocketServerTool::writeBytesInner(QWebSocket *client,
|
||||
quint16 port = client->peerPort();
|
||||
QString ipport = QString("%1:%2").arg(ip, QString::number(port));
|
||||
outputMessage(QtInfoMsg, QString("%1->%2:%3").arg(this->mBindingIpPort, ipport, hex));
|
||||
emit bytesInputted(bytes, context);
|
||||
emit bytesWritten(bytes, ipport);
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ public:
|
||||
|
||||
protected:
|
||||
virtual bool initialize(QString &errStr) final;
|
||||
virtual void writeBytes(const QByteArray &bytes, const QVariant &context = QJsonObject()) final;
|
||||
virtual void writeBytes(const QByteArray &bytes) override;
|
||||
virtual void uninitialize() final;
|
||||
|
||||
private:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user