added TCP Commander
This commit is contained in:
parent
9e9d6018b5
commit
00d294491c
File diff suppressed because it is too large
Load Diff
@ -19,6 +19,7 @@ PLUGIN_DIRS = \
|
|||||||
unitec \
|
unitec \
|
||||||
leynew \
|
leynew \
|
||||||
udpcommander \
|
udpcommander \
|
||||||
|
tcpcommander \
|
||||||
kodi \
|
kodi \
|
||||||
elgato \
|
elgato \
|
||||||
awattar \
|
awattar \
|
||||||
|
|||||||
142
tcpcommander/deviceplugintcpcommander.cpp
Normal file
142
tcpcommander/deviceplugintcpcommander.cpp
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Bernhard Trinnes <bernhard.trinnes@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh. *
|
||||||
|
* *
|
||||||
|
* Guh is free software: you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation, version 2 of the License. *
|
||||||
|
* *
|
||||||
|
* Guh is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with guh. If not, see <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include "deviceplugintcpcommander.h"
|
||||||
|
#include "plugininfo.h"
|
||||||
|
|
||||||
|
|
||||||
|
DevicePluginTcpCommander::DevicePluginTcpCommander()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceManager::HardwareResources DevicePluginTcpCommander::requiredHardware() const
|
||||||
|
{
|
||||||
|
return DeviceManager::HardwareResourceNone;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DeviceManager::DeviceSetupStatus DevicePluginTcpCommander::setupDevice(Device *device)
|
||||||
|
{
|
||||||
|
if (device->deviceClassId() == tcpOutputDeviceClassId) {
|
||||||
|
QTcpSocket *tcpSocket = new QTcpSocket(this);
|
||||||
|
m_tcpSockets.insert(tcpSocket, device);
|
||||||
|
return DeviceManager::DeviceSetupStatusSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (device->deviceClassId() == tcpInputDeviceClassId) {
|
||||||
|
int port = device->paramValue(portParamTypeId).toInt();
|
||||||
|
TcpServer *tcpServer = new TcpServer(port, this);
|
||||||
|
//TODO Connect TCP Server request received
|
||||||
|
if (tcpServer->isValid()) {
|
||||||
|
m_tcpServer.insert(tcpServer, device);
|
||||||
|
connect(tcpServer, &TcpServer::connected, this, &DevicePluginTcpCommander::onTcpServerConnected);
|
||||||
|
connect(tcpServer, &TcpServer::disconnected, this, &DevicePluginTcpCommander::onTcpServerDisconnected);
|
||||||
|
return DeviceManager::DeviceSetupStatusSuccess;
|
||||||
|
} else {
|
||||||
|
qDebug(dcTCPCommander()) << "Could not open TCP Server";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return DeviceManager::DeviceSetupStatusFailure;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DeviceManager::DeviceError DevicePluginTcpCommander::executeAction(Device *device, const Action &action)
|
||||||
|
{
|
||||||
|
if (device->deviceClassId() == tcpOutputDeviceClassId) {
|
||||||
|
|
||||||
|
if (action.actionTypeId() == outputDataActionTypeId) {
|
||||||
|
int port = device->paramValue(portParamTypeId).toInt();
|
||||||
|
QHostAddress address= QHostAddress(device->paramValue(ipv4addressParamTypeId).toString());
|
||||||
|
QTcpSocket *tcpSocket = m_tcpSockets.key(device);
|
||||||
|
QByteArray data = device->paramValue(outputDataAreaParamTypeId).toByteArray();
|
||||||
|
tcpSocket->connectToHost(address, port);
|
||||||
|
tcpSocket->write(data);
|
||||||
|
tcpSocket->close();
|
||||||
|
return DeviceManager::DeviceErrorNoError;
|
||||||
|
}
|
||||||
|
return DeviceManager::DeviceErrorActionTypeNotFound;
|
||||||
|
}
|
||||||
|
return DeviceManager::DeviceErrorDeviceClassNotFound;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DevicePluginTcpCommander::deviceRemoved(Device *device)
|
||||||
|
{
|
||||||
|
if(device->deviceClassId() == tcpOutputDeviceClassId){
|
||||||
|
m_tcpSockets.remove(m_tcpSockets.key(device));
|
||||||
|
}else if(device->deviceClassId() == tcpInputDeviceClassId){
|
||||||
|
TcpServer *tcpServer = m_tcpServer.key(device);
|
||||||
|
m_tcpServer.remove(tcpServer);
|
||||||
|
tcpServer->deleteLater();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DevicePluginTcpCommander::onTcpServerConnected()
|
||||||
|
{
|
||||||
|
TcpServer *tcpServer = static_cast<TcpServer *>(sender());
|
||||||
|
Device *device = m_tcpServer.value(tcpServer);
|
||||||
|
qDebug(dcTCPCommander()) << device->name() << "Tcp Server Client connected" ;
|
||||||
|
device->setStateValue(connectedStateTypeId, true);
|
||||||
|
connect(tcpServer, &TcpServer::textMessageReceived, this, &DevicePluginTcpCommander::onTcpServerTextMessageReceived);
|
||||||
|
//send signal device Setup was successfull
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DevicePluginTcpCommander::onTcpServerDisconnected()
|
||||||
|
{
|
||||||
|
TcpServer *tcpServer = static_cast<TcpServer *>(sender());
|
||||||
|
Device *device = m_tcpServer.value(tcpServer);
|
||||||
|
qDebug(dcTCPCommander()) << device->name() << "Tcp Server Client disconnected" ;
|
||||||
|
device->setStateValue(connectedStateTypeId, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DevicePluginTcpCommander::onTcpServerTextMessageReceived(QByteArray data)
|
||||||
|
{
|
||||||
|
TcpServer *tcpServer = static_cast<TcpServer *>(sender());
|
||||||
|
Device *device = m_tcpServer.value(tcpServer);
|
||||||
|
qDebug(dcTCPCommander()) << device->name() << "Message received" << data;
|
||||||
|
device->setStateValue(responseStateTypeId, data); //TODO change wording
|
||||||
|
|
||||||
|
if (device->paramValue(comparisionParamTypeId).toString() == "Is exactly") {
|
||||||
|
qDebug(dcTCPCommander()) << "is exacly";
|
||||||
|
if (data == device->paramValue(inputDataParamTypeId)) {
|
||||||
|
qDebug(dcTCPCommander()) << "comparison successful";
|
||||||
|
emitEvent(Event(commandReceivedEventTypeId, device->id()));
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (device->paramValue(comparisionParamTypeId).toString() == "Contains") {
|
||||||
|
if (data.contains(device->paramValue(inputDataParamTypeId).toByteArray())) {
|
||||||
|
emitEvent(Event(commandReceivedEventTypeId, device->id()));
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (device->paramValue(comparisionParamTypeId) == "Contains not") {
|
||||||
|
if (!data.contains(device->paramValue(inputDataParamTypeId).toByteArray()))
|
||||||
|
emitEvent(Event(commandReceivedEventTypeId, device->id()));
|
||||||
|
|
||||||
|
} else if (device->paramValue(comparisionParamTypeId) == "Starts with") {
|
||||||
|
if (data.startsWith(device->paramValue(inputDataParamTypeId).toByteArray()))
|
||||||
|
emitEvent(Event(commandReceivedEventTypeId, device->id()));
|
||||||
|
|
||||||
|
} else if (device->paramValue(comparisionParamTypeId) == "Ends with") {
|
||||||
|
if (data.endsWith(device->paramValue(inputDataParamTypeId).toByteArray()))
|
||||||
|
emitEvent(Event(commandReceivedEventTypeId, device->id()));
|
||||||
|
}
|
||||||
|
}
|
||||||
56
tcpcommander/deviceplugintcpcommander.h
Normal file
56
tcpcommander/deviceplugintcpcommander.h
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Bernhard Trinnes <bernhard.trinnes@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh. *
|
||||||
|
* *
|
||||||
|
* Guh is free software: you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation, version 2 of the License. *
|
||||||
|
* *
|
||||||
|
* Guh is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with guh. If not, see <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef DEVICEPLUGINDEVTCPCOMMANDER_H
|
||||||
|
#define DEVICEPLUGINDEVTCPCOMMANDER_H
|
||||||
|
|
||||||
|
#include "plugin/deviceplugin.h"
|
||||||
|
#include "devicemanager.h"
|
||||||
|
#include "tcpserver.h"
|
||||||
|
|
||||||
|
class DevicePluginTcpCommander : public DevicePlugin
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PLUGIN_METADATA(IID "guru.guh.DevicePlugin" FILE "deviceplugintcpcommander.json")
|
||||||
|
Q_INTERFACES(DevicePlugin)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit DevicePluginTcpCommander();
|
||||||
|
|
||||||
|
DeviceManager::HardwareResources requiredHardware() const override;
|
||||||
|
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override;
|
||||||
|
|
||||||
|
void deviceRemoved(Device *device) override;
|
||||||
|
|
||||||
|
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QHash<QTcpSocket *, Device *> m_tcpSockets;
|
||||||
|
QHash<TcpServer *, Device *> m_tcpServer;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onTcpServerConnected();
|
||||||
|
void onTcpServerDisconnected();
|
||||||
|
void onTcpServerTextMessageReceived(QByteArray message);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DEVICEPLUGINTCPCOMMANDER_H
|
||||||
148
tcpcommander/deviceplugintcpcommander.json
Normal file
148
tcpcommander/deviceplugintcpcommander.json
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
{
|
||||||
|
"name": "tcp commander",
|
||||||
|
"idName": "TCPCommander",
|
||||||
|
"id": "741b7b0a-0c9c-4c93-be99-0d0bcf5a4643",
|
||||||
|
"vendors": [
|
||||||
|
{
|
||||||
|
"name": "TCP Commander",
|
||||||
|
"idName": "tcpCommander",
|
||||||
|
"id": "9181278e-7812-4a3e-a9ce-f00f3f8b8afd",
|
||||||
|
"deviceClasses": [
|
||||||
|
{
|
||||||
|
"id": "c67d059f-694f-47cb-8e1d-9e3e6d014c1a",
|
||||||
|
"idName": "tcpOutput",
|
||||||
|
"name": "TCP Output",
|
||||||
|
"deviceIcon": "Network",
|
||||||
|
"createMethods": ["user"],
|
||||||
|
"basicTags": [
|
||||||
|
"Service"
|
||||||
|
],
|
||||||
|
"criticalStateTypeId": "725b541a-9e0c-4634-81eb-e415c0b8f025",
|
||||||
|
"primaryStateTypeId": "725b541a-9e0c-4634-81eb-e415c0b8f025",
|
||||||
|
"paramTypes": [
|
||||||
|
{
|
||||||
|
"id": "2a3fcb23-931b-4ba1-b134-c49b656c76f7",
|
||||||
|
"idName": "ipv4address",
|
||||||
|
"name": "IPv4 Address",
|
||||||
|
"type": "QString",
|
||||||
|
"inputType": "IPv4Address",
|
||||||
|
"defaultValue": "127.0.0.1",
|
||||||
|
"index" : 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "bee8b151-815a-4159-9d8a-42b76e99b42c",
|
||||||
|
"idName": "port",
|
||||||
|
"name": "Port",
|
||||||
|
"type": "int",
|
||||||
|
"defaultValue": "22",
|
||||||
|
"index" : 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateTypes":[
|
||||||
|
{
|
||||||
|
"id": "725b541a-9e0c-4634-81eb-e415c0b8f025",
|
||||||
|
"idName": "connected",
|
||||||
|
"name": "connected",
|
||||||
|
"type": "bool",
|
||||||
|
"defaultValue": false,
|
||||||
|
"eventTypeName": "connection status changed",
|
||||||
|
"index" : 0
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"actionTypes": [
|
||||||
|
{
|
||||||
|
"id": "6bc52462-b192-46a4-a6df-92cc5a479c89",
|
||||||
|
"idName": "outputData",
|
||||||
|
"name": "Send Data",
|
||||||
|
"index": 0,
|
||||||
|
"paramTypes": [
|
||||||
|
{
|
||||||
|
"id": "6604c852-6b24-4707-b8e5-1ddd8032efcc",
|
||||||
|
"idName": "outputDataArea",
|
||||||
|
"name": "Data",
|
||||||
|
"type": "QString",
|
||||||
|
"index": 0,
|
||||||
|
"inputType": "TextArea"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "bc40e84a-69c4-4fd2-beb0-bd65f19aa8ff",
|
||||||
|
"idName": "tcpInput",
|
||||||
|
"name": "TCP Input",
|
||||||
|
"deviceIcon": "Network",
|
||||||
|
"createMethods": ["user"],
|
||||||
|
"basicTags": [
|
||||||
|
"Service"
|
||||||
|
],
|
||||||
|
"primaryStateTypeId": "725b541a-9e0c-4634-81eb-e415c0b8f025",
|
||||||
|
"paramTypes": [
|
||||||
|
{
|
||||||
|
"id": "bee8b151-815a-4159-9d8a-42b76e99b42c",
|
||||||
|
"idName": "port",
|
||||||
|
"name": "Port",
|
||||||
|
"type": "int",
|
||||||
|
"defaultValue": "22",
|
||||||
|
"index" : 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "d99f55c7-0e14-45ee-b0f0-33f2d1d2e674",
|
||||||
|
"idName": "comparision",
|
||||||
|
"name": "Data Comparison",
|
||||||
|
"type": "QString",
|
||||||
|
"allowedValues": [
|
||||||
|
"Is exactly",
|
||||||
|
"Contains",
|
||||||
|
"Contains not",
|
||||||
|
"Starts with",
|
||||||
|
"Ends with"
|
||||||
|
],
|
||||||
|
"defaultValue": "Exactly",
|
||||||
|
"index" : 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "23051bdf-3f50-41fa-abde-bc4fe0bcc4fc",
|
||||||
|
"idName": "inputData",
|
||||||
|
"name": "Data",
|
||||||
|
"type": "QString",
|
||||||
|
"inputType": "TextArea",
|
||||||
|
"defaultValue": "",
|
||||||
|
"index" : 2
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateTypes": [
|
||||||
|
{
|
||||||
|
"id": "725b541a-9e0c-4634-81eb-e415c0b8f025",
|
||||||
|
"idName": "connected",
|
||||||
|
"name": "connected",
|
||||||
|
"type": "bool",
|
||||||
|
"defaultValue": false,
|
||||||
|
"eventTypeName": "connection status changed",
|
||||||
|
"index" : 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "b98fdacc-59d7-41c4-b790-1fdca50dfb22",
|
||||||
|
"idName": "response",
|
||||||
|
"name": "Response",
|
||||||
|
"type": "QString",
|
||||||
|
"inputType": "TextArea",
|
||||||
|
"defaultValue": "",
|
||||||
|
"eventTypeName": "response received",
|
||||||
|
"index" : 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"eventTypes": [
|
||||||
|
{
|
||||||
|
"id": "6d7c6df6-cb61-4d9e-b0d7-37c43911ca4b",
|
||||||
|
"idName": "commandReceived",
|
||||||
|
"name": "Command Received",
|
||||||
|
"index": 0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
16
tcpcommander/tcpcommander.pro
Normal file
16
tcpcommander/tcpcommander.pro
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
TRANSLATIONS = translations/en_US.ts \
|
||||||
|
translations/de_DE.ts
|
||||||
|
|
||||||
|
# Note: include after the TRANSLATIONS definition
|
||||||
|
include(../plugins.pri)
|
||||||
|
|
||||||
|
TARGET = $$qtLibraryTarget(guh_deviceplugintcpcommander)
|
||||||
|
|
||||||
|
SOURCES += \
|
||||||
|
deviceplugintcpcommander.cpp \
|
||||||
|
tcpserver.cpp \
|
||||||
|
|
||||||
|
HEADERS += \
|
||||||
|
deviceplugintcpcommander.h \
|
||||||
|
tcpserver.h \
|
||||||
|
|
||||||
101
tcpcommander/tcpserver.cpp
Normal file
101
tcpcommander/tcpserver.cpp
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Bernhard Trinnes <bernhard.trinnes@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh. *
|
||||||
|
* *
|
||||||
|
* Guh is free software: you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation, version 2 of the License. *
|
||||||
|
* *
|
||||||
|
* Guh is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with guh. If not, see <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include "tcpserver.h"
|
||||||
|
#include "extern-plugininfo.h"
|
||||||
|
#include <QNetworkInterface>
|
||||||
|
|
||||||
|
|
||||||
|
TcpServer::TcpServer(const QHostAddress address, const int &port, QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
m_tcpServer = new QTcpServer(this);
|
||||||
|
connect(m_tcpServer, &QTcpServer::newConnection, this, &TcpServer::newConnection);
|
||||||
|
qDebug(dcTCPCommander()) << "TCP Server on Port: " << port << "Address: " << address.toString();
|
||||||
|
if (!m_tcpServer->listen(address, port)) {
|
||||||
|
qDebug(dcTCPCommander()) << "Unable to start the server: " << m_tcpServer->errorString();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TcpServer::TcpServer(const int &port, QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
m_tcpServer = new QTcpServer(this);
|
||||||
|
connect(m_tcpServer, &QTcpServer::newConnection, this, &TcpServer::newConnection);
|
||||||
|
qDebug(dcTCPCommander()) << "TCP Server on Port: " << port;
|
||||||
|
if (!m_tcpServer->listen(QHostAddress::Any, port)) {
|
||||||
|
qDebug(dcTCPCommander()) << "Unable to start the server: " << m_tcpServer->errorString();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TcpServer::~TcpServer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TcpServer::isValid()
|
||||||
|
{
|
||||||
|
return m_tcpServer->isListening();
|
||||||
|
}
|
||||||
|
|
||||||
|
QHostAddress TcpServer::serverAddress()
|
||||||
|
{
|
||||||
|
return m_tcpServer->serverAddress();
|
||||||
|
}
|
||||||
|
|
||||||
|
int TcpServer::serverPort()
|
||||||
|
{
|
||||||
|
return m_tcpServer->serverPort();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpServer::newConnection()
|
||||||
|
{
|
||||||
|
qDebug(dcTCPCommander()) << "TCP Server new Connection request";
|
||||||
|
m_socket = m_tcpServer->nextPendingConnection();
|
||||||
|
m_socket->write("Hello client");
|
||||||
|
m_socket->flush();
|
||||||
|
|
||||||
|
emit connected();
|
||||||
|
connect(m_socket, &QTcpSocket::disconnected, this, &TcpServer::onDisconnected);
|
||||||
|
connect(m_socket, &QTcpSocket::readyRead, this, &TcpServer::readData);
|
||||||
|
// Note: error signal will be interpreted as function, not as signal in C++11
|
||||||
|
//connect(m_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onError(QAbstractSocket::SocketError)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TcpServer::onDisconnected()
|
||||||
|
{
|
||||||
|
qDebug(dcTCPCommander()) << "TCP Server connection aborted";
|
||||||
|
disconnect(m_socket, &QTcpSocket::disconnected, this, &TcpServer::onDisconnected);
|
||||||
|
disconnect(m_socket, &QTcpSocket::readyRead, this, &TcpServer::readData);
|
||||||
|
m_socket->deleteLater();
|
||||||
|
emit disconnected();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpServer::readData()
|
||||||
|
{
|
||||||
|
QByteArray data = m_socket->readAll();
|
||||||
|
qDebug(dcTCPCommander()) << "TCP Server data received: " << data;
|
||||||
|
emit textMessageReceived(data);
|
||||||
|
|
||||||
|
}
|
||||||
60
tcpcommander/tcpserver.h
Normal file
60
tcpcommander/tcpserver.h
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Bernhard Trinnes <bernhard.trinnes@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh. *
|
||||||
|
* *
|
||||||
|
* Guh is free software: you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation, version 2 of the License. *
|
||||||
|
* *
|
||||||
|
* Guh is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with guh. If not, see <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef TCPSERVER_H
|
||||||
|
#define TCPSERVER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QTcpSocket>
|
||||||
|
#include <QTcpServer>
|
||||||
|
|
||||||
|
class TcpServer : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit TcpServer(const QHostAddress address, const int &port, QObject *parent);
|
||||||
|
explicit TcpServer(const int &port, QObject *parent = 0);
|
||||||
|
~TcpServer();
|
||||||
|
|
||||||
|
bool isValid();
|
||||||
|
QHostAddress serverAddress();
|
||||||
|
int serverPort();
|
||||||
|
|
||||||
|
void setPort(int port);
|
||||||
|
void setServerAddress(const QHostAddress &address);
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
QTcpServer *m_tcpServer;
|
||||||
|
QTcpSocket *m_socket;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void newPendingConnection();
|
||||||
|
void textMessageReceived(QByteArray message);
|
||||||
|
void connected();
|
||||||
|
void disconnected();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void newConnection();
|
||||||
|
void onDisconnected();
|
||||||
|
void readData();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TCPSERVER_H
|
||||||
94
tcpcommander/translations/de_DE.ts
Normal file
94
tcpcommander/translations/de_DE.ts
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!DOCTYPE TS>
|
||||||
|
<TS version="2.1" language="de_DE">
|
||||||
|
<context>
|
||||||
|
<name>TCPCommander</name>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="41"/>
|
||||||
|
<source>tcp commander</source>
|
||||||
|
<extracomment>The name of the plugin tcp commander (741b7b0a-0c9c-4c93-be99-0d0bcf5a4643)</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="44"/>
|
||||||
|
<source>TCP Commander</source>
|
||||||
|
<extracomment>The name of the vendor (9181278e-7812-4a3e-a9ce-f00f3f8b8afd)</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="47"/>
|
||||||
|
<source>TCP Output</source>
|
||||||
|
<extracomment>The name of the DeviceClass (c67d059f-694f-47cb-8e1d-9e3e6d014c1a)</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="50"/>
|
||||||
|
<source>IPv4 Address</source>
|
||||||
|
<extracomment>The name of the paramType (2a3fcb23-931b-4ba1-b134-c49b656c76f7) of TCP Output</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="53"/>
|
||||||
|
<source>Port</source>
|
||||||
|
<extracomment>The name of the paramType (bee8b151-815a-4159-9d8a-42b76e99b42c) of TCP Output</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="56"/>
|
||||||
|
<source>connection status changed</source>
|
||||||
|
<extracomment>The name of the autocreated EventType (725b541a-9e0c-4634-81eb-e415c0b8f025)</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="59"/>
|
||||||
|
<source>connected</source>
|
||||||
|
<extracomment>The name of the ParamType of StateType (725b541a-9e0c-4634-81eb-e415c0b8f025) of DeviceClass TCP Output</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="62"/>
|
||||||
|
<source>Send Data</source>
|
||||||
|
<extracomment>The name of the ActionType 6bc52462-b192-46a4-a6df-92cc5a479c89 of deviceClass TCP Output</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="65"/>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="74"/>
|
||||||
|
<source>Data</source>
|
||||||
|
<extracomment>The name of the paramType (6604c852-6b24-4707-b8e5-1ddd8032efcc) of TCP Output
|
||||||
|
----------
|
||||||
|
The name of the paramType (23051bdf-3f50-41fa-abde-bc4fe0bcc4fc) of TCP Input</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="68"/>
|
||||||
|
<source>TCP Input</source>
|
||||||
|
<extracomment>The name of the DeviceClass (bc40e84a-69c4-4fd2-beb0-bd65f19aa8ff)</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="71"/>
|
||||||
|
<source>Data Comparison</source>
|
||||||
|
<extracomment>The name of the paramType (d99f55c7-0e14-45ee-b0f0-33f2d1d2e674) of TCP Input</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="77"/>
|
||||||
|
<source>response received</source>
|
||||||
|
<extracomment>The name of the autocreated EventType (b98fdacc-59d7-41c4-b790-1fdca50dfb22)</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="80"/>
|
||||||
|
<source>Response</source>
|
||||||
|
<extracomment>The name of the ParamType of StateType (b98fdacc-59d7-41c4-b790-1fdca50dfb22) of DeviceClass TCP Input</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="83"/>
|
||||||
|
<source>Command Received</source>
|
||||||
|
<extracomment>The name of the EventType 6d7c6df6-cb61-4d9e-b0d7-37c43911ca4b of deviceClass TCP Input</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
|
</TS>
|
||||||
94
tcpcommander/translations/en_US.ts
Normal file
94
tcpcommander/translations/en_US.ts
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!DOCTYPE TS>
|
||||||
|
<TS version="2.1">
|
||||||
|
<context>
|
||||||
|
<name>TCPCommander</name>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="41"/>
|
||||||
|
<source>tcp commander</source>
|
||||||
|
<extracomment>The name of the plugin tcp commander (741b7b0a-0c9c-4c93-be99-0d0bcf5a4643)</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="44"/>
|
||||||
|
<source>TCP Commander</source>
|
||||||
|
<extracomment>The name of the vendor (9181278e-7812-4a3e-a9ce-f00f3f8b8afd)</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="47"/>
|
||||||
|
<source>TCP Output</source>
|
||||||
|
<extracomment>The name of the DeviceClass (c67d059f-694f-47cb-8e1d-9e3e6d014c1a)</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="50"/>
|
||||||
|
<source>IPv4 Address</source>
|
||||||
|
<extracomment>The name of the paramType (2a3fcb23-931b-4ba1-b134-c49b656c76f7) of TCP Output</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="53"/>
|
||||||
|
<source>Port</source>
|
||||||
|
<extracomment>The name of the paramType (bee8b151-815a-4159-9d8a-42b76e99b42c) of TCP Output</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="56"/>
|
||||||
|
<source>connection status changed</source>
|
||||||
|
<extracomment>The name of the autocreated EventType (725b541a-9e0c-4634-81eb-e415c0b8f025)</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="59"/>
|
||||||
|
<source>connected</source>
|
||||||
|
<extracomment>The name of the ParamType of StateType (725b541a-9e0c-4634-81eb-e415c0b8f025) of DeviceClass TCP Output</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="62"/>
|
||||||
|
<source>Send Data</source>
|
||||||
|
<extracomment>The name of the ActionType 6bc52462-b192-46a4-a6df-92cc5a479c89 of deviceClass TCP Output</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="65"/>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="74"/>
|
||||||
|
<source>Data</source>
|
||||||
|
<extracomment>The name of the paramType (6604c852-6b24-4707-b8e5-1ddd8032efcc) of TCP Output
|
||||||
|
----------
|
||||||
|
The name of the paramType (23051bdf-3f50-41fa-abde-bc4fe0bcc4fc) of TCP Input</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="68"/>
|
||||||
|
<source>TCP Input</source>
|
||||||
|
<extracomment>The name of the DeviceClass (bc40e84a-69c4-4fd2-beb0-bd65f19aa8ff)</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="71"/>
|
||||||
|
<source>Data Comparison</source>
|
||||||
|
<extracomment>The name of the paramType (d99f55c7-0e14-45ee-b0f0-33f2d1d2e674) of TCP Input</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="77"/>
|
||||||
|
<source>response received</source>
|
||||||
|
<extracomment>The name of the autocreated EventType (b98fdacc-59d7-41c4-b790-1fdca50dfb22)</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="80"/>
|
||||||
|
<source>Response</source>
|
||||||
|
<extracomment>The name of the ParamType of StateType (b98fdacc-59d7-41c4-b790-1fdca50dfb22) of DeviceClass TCP Input</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../../build-guh-plugins-Desktop-Debug/tcpcommander/plugininfo.h" line="83"/>
|
||||||
|
<source>Command Received</source>
|
||||||
|
<extracomment>The name of the EventType 6d7c6df6-cb61-4d9e-b0d7-37c43911ca4b of deviceClass TCP Input</extracomment>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
|
</TS>
|
||||||
Loading…
x
Reference in New Issue
Block a user