This commit is contained in:
curtis 2024-11-26 16:21:02 +08:00
parent a8eaaf6d0e
commit 2ea5d0b7eb
35 changed files with 1321 additions and 29 deletions

View File

@ -1,10 +1,12 @@
import QtQuick 2.0
import TcpSocket 2.0
Item {
property int hitIndex: -1
property bool bStimulate: false
property int responseTime: 10*1000
property bool bTest: true
property bool bConnect: false;
property int currentIndexTenHz: 0
property var imageFilesTenHz:
@ -65,6 +67,14 @@ Item {
animationTenHz.start();
animationTwelveHz.start();
animationFifteenHz.start();
if(!bConnect)
{
clientSocket.connectToHost();
bConnect = true;
}else
{
clientSocket.writeBytes(getIntArr("1"));
}
}
function stopStimulate()
@ -128,15 +138,15 @@ Item {
{
return;
}
if(index === 0)
if(index === "0")
{
ssvepTenHzTimer.start();
hitTimer.start();
}else if(index === 1)
}else if(index === "1")
{
ssvepTwelveHzTimer.start();
hitTimer.start();
}else if(index === 2)
}else if(index === "2")
{
ssvepFifteenHzTimer.start();
hitTimer.start();
@ -147,6 +157,60 @@ Item {
hitIndex = index;
}
function getStr(intArr){
var str = "";
for(var i=0;i<intArr.length;i++)
str += String.fromCharCode(intArr[i]);
return str;
}
function getIntArr(str){
var ret = [];
for(var i=0;i<str.length;i++)
ret.push(str.charCodeAt(i));
return ret;
}
TcpSocket{
id: clientSocket
peer: "127.0.0.1"
port: 8099
onBytesReceived:
{
var cmd = getStr(bytes);
console.info("Client received: " + cmd);
if(cmd !== "0" && cmd !== "1" && cmd !== "2")
{
return;
}
ssvepHit(cmd);
stopStimulate();
}
onConnected:
{
console.info("Client socket connected");
writeBytes(getIntArr("1"));
}
onDisconnected:
{
console.info("Client socket disconnected");
bConnect = false;
}
onPeerChanged:
{
console.info("Client socket peer changed: " + peer);
}
onPortChanged:
{
console.info("Client socket port changed: " + port);
}
onError:
{
console.info("Client socket disconnected")
}
}
Rectangle{
anchors.top: parent.top
anchors.topMargin: 42

View File

@ -14,6 +14,7 @@
#include <QObject>
#include "fescontroldialog.h"
#include <QSettings>
#include "BCIManager.h"
void outputMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
@ -22,17 +23,17 @@ void outputMessage(QtMsgType type, const QMessageLogContext &context, const QStr
QString text;
switch(type)
{
case QtDebugMsg:
text = QString("Debug:");
break;
case QtWarningMsg:
text = QString("Warning:");
break;
case QtCriticalMsg:
text = QString("Critical:");
break;
case QtFatalMsg:
text = QString("Fatal:");
case QtDebugMsg:
text = QString("Debug:");
break;
case QtWarningMsg:
text = QString("Warning:");
break;
case QtCriticalMsg:
text = QString("Critical:");
break;
case QtFatalMsg:
text = QString("Fatal:");
}
QString context_info = QString("File:(%1) Line:(%2)").arg(QString(context.file)).arg(context.line);
QString current_date_time = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss ddd");
@ -56,7 +57,7 @@ void SetProcessAutoRunSelf(const QString &appPath)
//注册表路径需要使用双反斜杠如果是32位系统要使用QSettings::Registry32Format
QSettings settings("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
QSettings::Registry64Format);
//以程序名称作为注册表中的键
//以程序名称作为注册表中的键
//根据键获取对应的值(程序路径)
QFileInfo fInfo(appPath);
QString name = fInfo.baseName();
@ -70,7 +71,7 @@ void SetProcessAutoRunSelf(const QString &appPath)
{
settings.setValue(name, newPath);
qDebug() <<"添加快捷启动注册表HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run,";
qDebug() << "添加快捷启动注册表HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run,";
}
}
@ -86,16 +87,19 @@ int main(int argc, char *argv[])
//SetProcessAutoRunSelf(qApp->applicationFilePath());
#ifdef DEBUGON
qInstallMessageHandler(outputMessage);
qInstallMessageHandler(outputMessage);
#endif
BCIManager::registerQMLType();
//数据库读取
if(!CDatabaseInterface::getInstance()->openDB("./DependFile/DBFile/UpLow.db","QSQLITE"))
qDebug()<<"UpLow.db open failed!";
if(!CDatabaseInterface::getInstance()->openDB("./DependFile/DBFile/UpLow.db", "QSQLITE"))
{
qDebug() << "UpLow.db open failed!";
}
//配置文件读取
if(!ReadConfig::getInstance()->readConfigFile())
{
qDebug()<<"配置文件读取失败";
qDebug() << "配置文件读取失败";
return -1;
}
@ -129,15 +133,16 @@ int main(int argc, char *argv[])
CMainWindow w;
if(sharedMemory.create(1))
{
QObject::connect(&w,SIGNAL(signalShowCompleted()),&login,SLOT(slotShowCompleted()));
QObject::connect(&w, SIGNAL(signalShowCompleted()), &login, SLOT(slotShowCompleted()));
login.setWindowModality(Qt::WindowModal);//
login.exec(); //
w.show();
}
QObject::connect(&a,&QApplication::aboutToQuit,[](){
FesControlDialog::getInstance()->turnoffDevice(1,1);
QObject::connect(&a, &QApplication::aboutToQuit, []()
{
FesControlDialog::getInstance()->turnoffDevice(1, 1);
});

View File

@ -0,0 +1,35 @@
/*
* Copyright (C) 2016 EPFL
*
* This program 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, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see http://www.gnu.org/licenses/.
*/
/**
* @file QIntPtr.cpp
* @brief QObject wrapper for qintptr
* @author Ayberk Özgür
* @date 2016-11-15
*/
#include"QIntPtr.h"
namespace QMLTcpSockets{
QIntPtr::QIntPtr(QObject* parent) : QObject(parent){
ptr = 0;
}
QIntPtr::~QIntPtr(){ }
}

View File

@ -0,0 +1,66 @@
/*
* Copyright (C) 2016 EPFL
*
* This program 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, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see http://www.gnu.org/licenses/.
*/
/**
* @file QIntPtr.h
* @brief QObject wrapper for qintptr
* @author Ayberk Özgür
* @date 2016-11-15
*/
#ifndef QINTPTR_H
#define QINTPTR_H
#include <QObject>
namespace QMLTcpSockets{
/**
* @brief QObject wrapper for qintptr. Can be passed around in QML but doesn't have any API.
*/
class QIntPtr : public QObject {
/* *INDENT-OFF* */
Q_OBJECT
/* *INDENT-ON* */
public:
/** @cond DO_NOT_DOCUMENT */
/**
* @brief Creates a new QIntPtr with the given Qt parent
*
* @param parent The Qt parent
*/
QIntPtr(QObject* parent = 0);
/**
* @brief Destroys this QIntPtr
*/
~QIntPtr();
qintptr ptr; ///< Wrapped low level pointer
/** @endcond */
};
}
Q_DECLARE_METATYPE(QMLTcpSockets::QIntPtr*)
#endif /* QINTPTR_H */

View File

@ -0,0 +1,48 @@
/*
* Copyright (C) 2016 EPFL
*
* This program 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, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see http://www.gnu.org/licenses/.
*/
/**
* @file QMLTcpSocketsPlugin.h
* @brief Object that exposes the QMLTcpSockets plugin components as QML objects
* @author Ayberk Özgür
* @date 2016-11-10
*/
#include "QMLTcpSocketsPlugin.h"
#include "TcpServer.h"
#include "TcpSocket.h"
#include "QIntPtr.h"
#include "TcpSocketFactory.h"
#include "TcpSocketEnums.h"
namespace QMLTcpSockets{
void QMLTcpSocketsPlugin::registerTypes(const char* uri){
qmlRegisterType<TcpServer>(uri, 1, 0, "TcpServer");
qmlRegisterType<TcpSocket>(uri, 1, 0, "TcpSocket");
qmlRegisterType<QIntPtr>(uri, 1, 0, "QIntPtr");
qmlRegisterSingletonType<TcpSocketFactory>(uri, 1, 0, "TcpSocketFactory",
[] (QQmlEngine* qmlEngine, QJSEngine* jsEngine)->QObject* {
Q_UNUSED(qmlEngine)
Q_UNUSED(jsEngine)
return new TcpSocketFactory();
});
qmlRegisterType<TcpSocketEnums>(uri, 1, 0, "TcpSocketEnums");
}
}

View File

@ -0,0 +1,55 @@
/*
* Copyright (C) 2016 EPFL
*
* This program 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, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see http://www.gnu.org/licenses/.
*/
/**
* @mainpage qml-tcpsockets
*
* qml-tcpsockets contains QML wrappers for QTcpServer and QTcpSocket. More Qt Networking wrappers might come soon. See README.md for more information.
*/
/**
* @file QMLTcpSocketsPlugin.h
* @brief Object that exposes the QMLTcpSockets plugin components as QML objects
* @author Ayberk Özgür
* @date 2016-11-10
*/
#ifndef QMLTCPSOCKETSPLUGIN_H
#define QMLTCPSOCKETSPLUGIN_H
#include <QQmlExtensionPlugin>
#include <qqml.h>
namespace QMLTcpSockets{
/** @cond DO_NOT_DOCUMENT */
class QMLTcpSocketsPlugin : public QQmlExtensionPlugin {
/* *INDENT-OFF* */
Q_OBJECT
/* *INDENT-ON* */
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
public:
void registerTypes(const char* uri);
};
/** @endcond */
}
#endif /* QMLTCPSOCKETSPLUGIN_H */

View File

@ -0,0 +1,35 @@
/*
* Copyright (C) 2016 EPFL
*
* This program 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, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see http://www.gnu.org/licenses/.
*/
/**
* @file QTcpServerPub.cpp
* @brief A QTcpServer that emits incomingConnection() as signal (duh)
* @author Ayberk Özgür
* @date 2016-11-15
*/
#include"QTcpServerPub.h"
namespace QMLTcpSockets{
QTcpServerPub::QTcpServerPub(QObject* parent) : QTcpServer(parent){ }
void QTcpServerPub::incomingConnection(qintptr socketDescriptor){
emit incomingConnectionSignal(socketDescriptor);
}
}

View File

@ -0,0 +1,75 @@
/*
* Copyright (C) 2016 EPFL
*
* This program 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, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see http://www.gnu.org/licenses/.
*/
/**
* @file QTcpServerPub.h
* @brief A QTcpServer that emits incomingConnection() as signal (duh)
* @author Ayberk Özgür
* @date 2016-11-15
*/
#ifndef QTCPSERVERPUB_H
#define QTCPSERVERPUB_H
#include <QTcpServer>
namespace QMLTcpSockets{
/** @cond DO_NOT_DOCUMENT */
/**
* @brief A QTcpServer that emits incomingConnection() as signal (duh)
*/
class QTcpServerPub : public QTcpServer {
/* *INDENT-OFF* */
Q_OBJECT
/* *INDENT-ON* */
public:
/**
* @brief Creates a new QTcpServerPub with the given Qt parent
*
* @param parent The Qt parent
*/
QTcpServerPub(QObject* parent = 0);
signals:
/**
* @brief Emitted when there's a new incoming connection
*
* @param socketDescriptor Descriptor of the incoming connection that can be used to create a QTcpSocket
*/
void incomingConnectionSignal(qintptr socketDescriptor);
protected:
/**
* @brief Called by the super class when there's a new incoming connection
*
* @param socketDescriptor Descriptor of the incoming connection that can be used to create a QTcpSocket
*/
void incomingConnection(qintptr socketDescriptor) override;
};
/** @endcond */
}
#endif /* QTCPSERVERPUB_H */

View File

@ -0,0 +1,95 @@
/*
* Copyright (C) 2016 EPFL
*
* This program 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, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see http://www.gnu.org/licenses/.
*/
/**
* @file TcpServer.cpp
* @brief QML wrapper source for QTcpServer
* @author Ayberk Özgür
* @date 2016-11-10
*/
#include "TcpServer.h"
namespace QMLTcpSockets{
TcpServer::TcpServer(QQuickItem* parent):
QQuickItem(parent),
server(this)
{
host = "0.0.0.0";
port = 0;
connect(&server, SIGNAL(incomingConnectionSignal(qintptr)), this, SLOT(publishIncomingConnection(qintptr)));
}
TcpServer::~TcpServer(){}
bool TcpServer::isListening() const{
return server.isListening();
}
void TcpServer::setListening(bool enable){
bool wasListening = server.isListening();
if(enable){
if(!server.listen(QHostAddress(host), port))
qWarning() << "TcpServer::setListening(): Couldn't start listening: " << server.errorString();
}
else
server.close();
if(wasListening != server.isListening())
emit listeningChanged();
}
void TcpServer::setHost(QString host){
if(host != this->host){
bool wasListening = isListening();
setListening(false);
this->host = host;
if(wasListening)
setListening(true);
emit hostChanged();
}
}
void TcpServer::setPort(int port){
if(port < 0){
qWarning() << "TcpServer::setPort(): port given was negative, setting to 0.";
port = 0;
}
else if(port > 0xFFFF){
qWarning() << "TcpServer::setPort(): port given was larger than 65535, setting to 65535.";
port = 0xFFFF;
}
if(port != this->port){
bool wasListening = isListening();
setListening(false);
this->port = port;
if(wasListening)
setListening(true);
emit portChanged();
}
}
void TcpServer::publishIncomingConnection(qintptr socketDescriptor){
QIntPtr* wrappedSocketDesc = new QIntPtr();
wrappedSocketDesc->ptr = socketDescriptor;
emit newConnection(wrappedSocketDesc);
}
}

View File

@ -0,0 +1,160 @@
/*
* Copyright (C) 2016 EPFL
*
* This program 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, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see http://www.gnu.org/licenses/.
*/
/**
* @file TcpServer.h
* @brief QML wrapper header for QTcpServer
* @author Ayberk Özgür
* @date 2016-11-10
*/
#ifndef TCPSERVER_H
#define TCPSERVER_H
#include <QQuickItem>
#include "QTcpServerPub.h"
#include "TcpSocket.h"
#include "QIntPtr.h"
namespace QMLTcpSockets{
/**
* @brief QML wrapper for QTcpServer
*
* Due to the sandboxing of WinRT, cannot listen on nor connect to localhost sockets on this platform.
*/
class TcpServer : public QQuickItem {
/* *INDENT-OFF* */
Q_OBJECT
/* *INDENT-ON* */
/** @brief Whether to listen for incoming connections, default false */
Q_PROPERTY(bool listen READ isListening WRITE setListening NOTIFY listeningChanged)
/** @brief Address to listen on, default "0.0.0.0" i.e any address */
Q_PROPERTY(QString host READ getHost WRITE setHost NOTIFY hostChanged)
/** @brief Port to listen on, must be in [0,65535], default 0 */
Q_PROPERTY(int port READ getPort WRITE setPort NOTIFY portChanged)
public:
/** @cond DO_NOT_DOCUMENT */
/**
* @brief Creates a new TcpServer with the given QML parent
*
* @param parent The QML parent
*/
TcpServer(QQuickItem* parent = 0);
/**
* @brief Destroys this TcpServer
*/
~TcpServer();
/**
* @brief Gets whether the socket is listening
*
* @return Whether the socket is listening
*/
bool isListening() const;
/**
* @brief Enables/disables listening
*
* @param enable Whether to listen or close the socket and stop listening
*/
void setListening(bool enable);
/**
* @brief Gets the current host name
*
* @return Current host name, e.g "127.0.0.1"
*/
QString getHost() const { return host; }
/**
* @brief Sets the host name
*
* @param host The new host name, e.g "127.0.0.1"
*/
void setHost(QString host);
/**
* @brief Gets the current port
*
* @return Current port
*/
int getPort() const { return port; }
/**
* @brief Sets the port
*
* @param port The new port, must be in [0,65535]
*/
void setPort(int port);
/** @endcond */
signals:
/** @cond DO_NOT_DOCUMENT */
/**
* @brief Emitted when listening changes
*/
void listeningChanged();
/**
* @brief Emitted when the host name changes
*/
void hostChanged();
/**
* @brief Emitted whe the port changes
*/
void portChanged();
/** @endcond */
/**
* @brief Emitted when a new connection is made to the server, socketDescriptor must be passed to a TcpSocket or a TcpSocketFactory to create the socket
*
* @param socketDescriptor Native descriptor to the socket that has just connected
*/
void newConnection(QMLTcpSockets::QIntPtr* socketDescriptor);
private slots:
/**
* @brief Gets the incoming connection descriptor, wraps it in a QIntPtr and publishes it
*/
void publishIncomingConnection(qintptr socketDescriptor);
private:
QString host; ///< Host address, e.g "127.0.0.1"
quint16 port; ///< Port to listen to
QTcpServerPub server; ///< The QTcpServer object to wrap
};
}
#endif /* TCPSERVER_H */

View File

@ -0,0 +1,160 @@
/*
* Copyright (C) 2016 EPFL
*
* This program 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, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see http://www.gnu.org/licenses/.
*/
/**
* @file TcpSocket.cpp
* @brief QML wrapper source for QTcpSocket
* @author Ayberk Özgür
* @date 2016-11-10
*/
#include "TcpSocket.h"
#include <QHostAddress>
namespace QMLTcpSockets{
TcpSocket::TcpSocket(QQuickItem* parent):
QQuickItem(parent),
socket(this)
{
connect(&socket, SIGNAL(connected()), this, SIGNAL(connected()));
connect(&socket, SIGNAL(disconnected()), this, SIGNAL(disconnected()));
connect(&socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(emitErrorAsInt(QAbstractSocket::SocketError)));
connect(&socket, SIGNAL(readyRead()), this, SLOT(publish()));
peer = "";
port = 0;
}
TcpSocket::TcpSocket(QIntPtr* socketDescriptor, QQuickItem* parent):
TcpSocket(parent)
{
socket.setSocketDescriptor(socketDescriptor->ptr);
socketDescriptor->deleteLater();
peer = socket.peerAddress().toString();
port = socket.peerPort();
}
TcpSocket::~TcpSocket(){
socket.flush();
}
void TcpSocket::setSocketDescriptor(QIntPtr* socketDescriptor){
socket.flush();
socket.disconnectFromHost();
socket.setSocketDescriptor(socketDescriptor->ptr);
socketDescriptor->deleteLater();
QString peer = socket.peerAddress().toString();
if(this->peer != peer){
this->peer = peer;
emit peerChanged();
}
quint16 port = socket.peerPort();
if(this->port != port){
this->port = port;
emit portChanged();
}
emit connected();
}
void TcpSocket::setSocketOption(int option, QVariant value){
socket.setSocketOption((QAbstractSocket::SocketOption)option, value);
}
void TcpSocket::setPeer(QString peer){
if(peer != this->peer){
if(socket.state() != TcpSocketEnums::UnconnectedState)
qWarning() << "TcpSocket::setPeer(): Can only set peer while disconnected.";
else{
this->peer = peer;
emit peerChanged();
}
}
}
void TcpSocket::setPort(int port){
if(port < 0){
qWarning() << "TcpSocket::setPort(): port given was negative, setting to 0.";
port = 0;
}
else if(port > 0xFFFF){
qWarning() << "TcpSocket::setPort(): port given was larger than 65535, setting to 65535.";
port = 0xFFFF;
}
if(port != this->port){
if(socket.state() != TcpSocketEnums::UnconnectedState)
qWarning() << "TcpSocket::setPort(): Can only set port while disconnected.";
else{
this->port = port;
emit portChanged();
}
}
}
void TcpSocket::connectToHost(){
socket.connectToHost(peer, port);
}
void TcpSocket::disconnectFromHost(){
socket.disconnectFromHost();
}
void TcpSocket::emitErrorAsInt(QAbstractSocket::SocketError socketError){
emit error(socketError);
}
void TcpSocket::publish(){
QList<int> list;
QByteArray receivedBytes = socket.readAll();
for(char c : receivedBytes)
list << (int)(*((unsigned char*)(&c)));
emit bytesReceived(list);
}
bool TcpSocket::writeBytes(QList<int> bytes){
QByteArray container;
for(int b : bytes){
if(b < 0 || b > 0xFF){
qWarning() << "TcpSocket::writeBytes(): bytes contain integer not in [0x00,0xFF], not writing";
return false;
}
else
container.append((char)b);
}
int numBytesToWrite = container.size();
const char* bytesRaw = container.constData();
while(numBytesToWrite > 0){
int bytesWritten = socket.write(bytesRaw, numBytesToWrite);
if(bytesWritten < 0){
qWarning() << "TcpSocket::writeBytes(): Bytes were not written: " << socket.errorString();
return false;
}
numBytesToWrite -= bytesWritten;
bytesRaw += bytesWritten;
}
socket.flush();
return true;
}
}

View File

@ -0,0 +1,209 @@
/*
* Copyright (C) 2016 EPFL
*
* This program 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, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see http://www.gnu.org/licenses/.
*/
/**
* @file TcpSocket.h
* @brief QML wrapper header for QTcpSocket
* @author Ayberk Özgür
* @date 2016-11-10
*/
#ifndef TCPSOCKET_H
#define TCPSOCKET_H
#include <QQuickItem>
#include <QTcpSocket>
#include <QList>
#include "QIntPtr.h"
#include "TcpSocketEnums.h"
namespace QMLTcpSockets{
/**
* @brief QML wrapper for QTcpSocket
*
* Can be created from a native socket descriptor returned from a TcpServer incoming connection, or can connect to a peer on its own.
* Due to the sandboxing of WinRT, cannot listen on nor connect to localhost sockets on this platform.
*/
class TcpSocket : public QQuickItem {
/* *INDENT-OFF* */
Q_OBJECT
/* *INDENT-ON* */
/** @brief Address to connect to, or address of the already open remote connection, default "" */
Q_PROPERTY(QString peer READ getPeer WRITE setPeer NOTIFY peerChanged)
/** @brief Port to connect to, or port of the already open remote connection , must be in [0,65535], default 0 */
Q_PROPERTY(int port READ getPort WRITE setPort NOTIFY portChanged)
public:
/** @cond DO_NOT_DOCUMENT */
/**
* @brief Creates a new TcpSocket with the given QML parent
*
* @param parent The QML parent
*/
TcpSocket(QQuickItem* parent = 0);
/**
* @brief Creates a new TcpSocket with the given QML parent, calls socketDescriptor->deleteLater()
*
* @param socketDescriptor Descriptor to the external native socket that was opened outside this wrapper, calls deleteLater() on it in the end
* @param parent The QML parent
*/
TcpSocket(QMLTcpSockets::QIntPtr* socketDescriptor, QQuickItem* parent = 0);
/**
* @brief Destroys this TcpSocket
*/
~TcpSocket();
/**
* @brief Gets the current peer name
*
* @return Current peer name, e.g "127.0.0.1"
*/
QString getPeer() const { return peer; }
/**
* @brief Sets the peer name
*
* @param peer The new peer name, e.g "127.0.0.1"
*/
void setPeer(QString peer);
/**
* @brief Gets the current port
*
* @return Current port
*/
int getPort() const { return port; }
/**
* @brief Sets the port
*
* @param port The new port, must be in [0,65535]
*/
void setPort(int port);
/** @endcond */
public slots:
/**
* @brief Initializes the socket with the given native descriptor (returned from TcpServer), calls socketDescriptor->deleteLater() in the end
*
* @param socketDescriptor Native socket descriptor, calls deleterLater() on it in the end
*/
void setSocketDescriptor(QMLTcpSockets::QIntPtr* socketDescriptor);
/**
* Sets the given low level option to the value described by value.
*
* @param option The option of TcpSocketEnums::SocketOption type (see http://doc.qt.io/qt-5/qabstractsocket.html#SocketOption-enum)
* @param value The value
*/
void setSocketOption(int option, QVariant value);
/**
* @brief Initiates a connection to the peer on port
*/
void connectToHost();
/**
* @brief Starts closing the socket
*/
void disconnectFromHost();
/**
* @brief Writes bytes over the socket
*
* @param bytes Bytes to write, all must be within [0x00,0xFF]
* @return Whether all bytes were successfully written
*/
bool writeBytes(QList<int> bytes);
signals:
/** @cond DO_NOT_DOCUMENT */
/**
* @brief Emitted when the peer name changes
*/
void peerChanged();
/**
* @brief Emitted whe the port changes
*/
void portChanged();
/** @endcond */
/**
* @brief Emitted when the socket is connected
*/
void connected();
/**
* @brief Emitted when the socket is disconected
*/
void disconnected();
/**
* @brief Emitted when there is an error
*
* @param socketError The error of TcpSocketEnums::SocketError type (see http://doc.qt.io/qt-5/qabstractsocket.html#SocketError-enum)
*/
void error(int socketError);
/**
* @brief Emitted when some bytes are received
*
* @param bytes Byte array that was received, all elements are guaranteed to be in [0x00, 0xFF]
*/
void bytesReceived(QList<int> bytes);
private slots:
/**
* @brief Publishes all available received bytes via bytesReceived(QVariant)
*/
void publish();
/**
* @brief Emits error(int socketError)
*
* @param socketError The socket error to emit
*/
void emitErrorAsInt(QAbstractSocket::SocketError socketError);
private:
QTcpSocket socket; ///< The low level socket
QString peer; ///< Peer address
quint16 port; ///< Connection port
};
}
Q_DECLARE_METATYPE(QMLTcpSockets::TcpSocket*)
#endif /* TCPSOCKET_H */

View File

@ -0,0 +1,33 @@
/*
* Copyright (C) 2016 EPFL
*
* This program 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, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see http://www.gnu.org/licenses/.
*/
/**
* @file TcpSocketEnums.cpp
* @brief Wrapper to expose QAbstractSocket enums
* @author Ayberk Özgür
* @date 2016-11-16
*/
#include "TcpSocketEnums.h"
namespace QMLTcpSockets{
TcpSocketEnums::TcpSocketEnums(QObject* parent) : QAbstractSocket(QAbstractSocket::TcpSocket, parent){ }
TcpSocketEnums::~TcpSocketEnums(){ }
}

View File

@ -0,0 +1,62 @@
/*
* Copyright (C) 2016 EPFL
*
* This program 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, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see http://www.gnu.org/licenses/.
*/
/**
* @file TcpSocketEnums.h
* @brief Wrapper to expose QAbstractSocket enums
* @author Ayberk Özgür
* @date 2016-11-16
*/
#ifndef TCPSOCKETENUMS_H
#define TCPSOCKETENUMS_H
#include <QAbstractSocket>
namespace QMLTcpSockets{
/**
* @brief Wrapper to expose QAbstractSocket enums, see http://doc.qt.io/qt-5/qabstractsocket.html
*/
class TcpSocketEnums : public QAbstractSocket {
/* *INDENT-OFF* */
Q_OBJECT
/* *INDENT-ON* */
public:
/** @cond DO_NOT_DOCUMENT */
/**
* @brief Creates a new TcpSocketEnums with the given Qt parent
*
* @param parent The Qt parent
*/
TcpSocketEnums(QObject* parent = 0);
/**
* @brief Destroys this TcpSocketEnums
*/
~TcpSocketEnums();
/** @endcod */
};
}
#endif /* TCPSOCKETENUMS_H */

View File

@ -0,0 +1,37 @@
/*
* Copyright (C) 2016 EPFL
*
* This program 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, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see http://www.gnu.org/licenses/.
*/
/**
* @file TcpSocketFactory.cpp
* @brief Singleton TcpSocket factory for QML
* @author Ayberk Özgür
* @date 2016-11-15
*/
#include"TcpSocketFactory.h"
namespace QMLTcpSockets{
TcpSocketFactory::TcpSocketFactory(QQuickItem* parent) : QQuickItem(parent){ }
TcpSocketFactory::~TcpSocketFactory(){ }
TcpSocket* TcpSocketFactory::fromDescriptor(QIntPtr* socketDescriptor, QQuickItem* parent){
return new TcpSocket(socketDescriptor, parent);
}
}

View File

@ -0,0 +1,77 @@
/*
* Copyright (C) 2016 EPFL
*
* This program 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, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see http://www.gnu.org/licenses/.
*/
/**
* @file TcpSocketFactory.h
* @brief Singleton TcpSocket factory for QML
* @author Ayberk Özgür
* @date 2016-11-15
*/
#ifndef TCPSOCKETFACTORY_H
#define TCPSOCKETFACTORY_H
#include <QQuickItem>
#include "TcpSocket.h"
#include "QIntPtr.h"
namespace QMLTcpSockets{
/**
* @brief Creates new TcpSocket from native socket descriptor (returned from a TcpServer incoming connection).
* @singleton
*/
class TcpSocketFactory : public QQuickItem {
/* *INDENT-OFF* */
Q_OBJECT
/* *INDENT-ON* */
public:
/** @cond DO_NOT_DOCUMENT */
/**
* @brief Creates a new TcpSocketFactory with the given QML parent
*
* @param parent The QML parent
*/
TcpSocketFactory(QQuickItem* parent = 0);
/**
* @brief Destroys this TcpSocketFactory
*/
~TcpSocketFactory();
/** @endcond */
public slots:
/**
* @brief Creates and returns a new open socket that wraps the native socket descriptor, with the given QML parent (optional)
*
* @param socketDescriptor Native socket descriptor
* @param parent QML parent of the newly created TcpSocket
* @return New socket, open if the descriptor is valid
*/
static QMLTcpSockets::TcpSocket* fromDescriptor(QMLTcpSockets::QIntPtr* socketDescriptor, QQuickItem* parent = 0);
};
}
#endif /* TCPSOCKETFACTORY_H */

View File

@ -1,5 +1,6 @@
#include "eyetrainwidget.h"
#include "ui_eyetrainwidget.h"
#include "BCIManager.h"
eyeTrainWidget::eyeTrainWidget(QWidget *parent) :
QWidget(parent),
@ -22,6 +23,8 @@ eyeTrainWidget::eyeTrainWidget(QWidget *parent) :
m_st_bicycleParam.resistance = 10; //阻力 Nm 0~20挡
m_st_bicycleParam.spasmType = 0; //默认逆向
BCIManager::getInstance().startLinkerPrograme();
// int8_t controlState;//状态控制 0-停止 1启动 2-暂停 3-继续
// int8_t bodyPart; //训练部位 0-上肢 1-下肢 2-四肢 3-垂直上肢
@ -37,6 +40,7 @@ eyeTrainWidget::eyeTrainWidget(QWidget *parent) :
// int8_t spasmType; //痉挛后方向 1-正向 0-逆向,默认逆向,没有了
// uint8_t trainTime; //训练时间 0~120min
}
eyeTrainWidget::~eyeTrainWidget()

View File

@ -116,6 +116,14 @@ SOURCES += \
Src/Report/trainreporttwothree.cpp \
Src/Report/trainreporttwotwo.cpp \
Src/Setting/settingwidget.cpp \
Src/TrainManager/BCIManager.cpp \
Src/TrainManager/QmlTcpSocket/QIntPtr.cpp \
Src/TrainManager/QmlTcpSocket/QMLTcpSocketsPlugin.cpp \
Src/TrainManager/QmlTcpSocket/QTcpServerPub.cpp \
Src/TrainManager/QmlTcpSocket/TcpServer.cpp \
Src/TrainManager/QmlTcpSocket/TcpSocket.cpp \
Src/TrainManager/QmlTcpSocket/TcpSocketEnums.cpp \
Src/TrainManager/QmlTcpSocket/TcpSocketFactory.cpp \
Src/TrainManager/armorleg.cpp \
# Src/TrainManager/fesparamset.cpp \
Src/TrainManager/braintrain.cpp \
@ -186,6 +194,14 @@ HEADERS += \
Src/Report/trainreporttwothree.h \
Src/Report/trainreporttwotwo.h \
Src/Setting/settingwidget.h \
Src/TrainManager/BCIManager.h \
Src/TrainManager/QmlTcpSocket/QIntPtr.h \
Src/TrainManager/QmlTcpSocket/QMLTcpSocketsPlugin.h \
Src/TrainManager/QmlTcpSocket/QTcpServerPub.h \
Src/TrainManager/QmlTcpSocket/TcpServer.h \
Src/TrainManager/QmlTcpSocket/TcpSocket.h \
Src/TrainManager/QmlTcpSocket/TcpSocketEnums.h \
Src/TrainManager/QmlTcpSocket/TcpSocketFactory.h \
Src/TrainManager/armorleg.h \
# Src/TrainManager/fesparamset.h \
Src/TrainManager/braintrain.h \

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 12.0.1, 2024-11-25T16:28:27. -->
<!-- Written by QtCreator 12.0.1, 2024-11-26T15:49:59. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
@ -241,14 +241,14 @@
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:F:/updown/ZBD_IIIDL_S_Project/UpLowLimp.pro</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">F:/updown/ZBD_IIIDL_S_Project/UpLowLimp.pro</value>
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">UpLowLimp2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:F:/updown/UpLowLimp/ZBD_IIIDL_S_Project/UpLowLimp.pro</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">F:/updown/UpLowLimp/ZBD_IIIDL_S_Project/UpLowLimp.pro</value>
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">true</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">F:/updown/ZBD_IIIDL_S_Project/release</value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">F:/updown/UpLowLimp/ZBD_IIIDL_S_Project/release</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>

View File

@ -232,5 +232,60 @@
<file>DependFile/Source/brainTrain/brain_icon_vision.png</file>
<file>DependFile/QML/Ssvep.qml</file>
<file>DependFile/Source/signal/icon_brain_on.png</file>
<file>DependFile/Source/brainTrain/vision_btn_start.png</file>
<file>DependFile/Source/brainTrain/vision_img_board.png</file>
<file>DependFile/Source/brainTrain/upTest/upper_stretch_R01.png</file>
<file>DependFile/Source/brainTrain/upTest/upper_stretch_R02.png</file>
<file>DependFile/Source/brainTrain/upTest/upper_stretch_R03.png</file>
<file>DependFile/Source/brainTrain/upTest/upper_stretch_R04.png</file>
<file>DependFile/Source/brainTrain/upTest/upper_stretch_R05.png</file>
<file>DependFile/Source/brainTrain/upTest/upper_stretch_R06.png</file>
<file>DependFile/Source/brainTrain/upTest/upper_stretch_R07.png</file>
<file>DependFile/Source/brainTrain/upTest/upper_stretch_R08.png</file>
<file>DependFile/Source/brainTrain/upTest/upper_stretch_R09.png</file>
<file>DependFile/Source/brainTrain/upTest/upper_stretch_R10.png</file>
<file>DependFile/Source/brainTrain/upTest/upper_stretch_R11.png</file>
<file>DependFile/Source/brainTrain/upTest/upper_stretch_R12.png</file>
<file>DependFile/Source/brainTrain/upTest/upper_stretch_R13.png</file>
<file>DependFile/Source/brainTrain/upTest/upper_stretch_R14.png</file>
<file>DependFile/Source/brainTrain/upTest/upper_stretch_R15.png</file>
<file>DependFile/Source/brainTrain/upTest1/upper_stretch_R01.png</file>
<file>DependFile/Source/brainTrain/upTest1/upper_stretch_R02.png</file>
<file>DependFile/Source/brainTrain/upTest1/upper_stretch_R03.png</file>
<file>DependFile/Source/brainTrain/upTest1/upper_stretch_R04.png</file>
<file>DependFile/Source/brainTrain/upTest1/upper_stretch_R05.png</file>
<file>DependFile/Source/brainTrain/upTest1/upper_stretch_R06.png</file>
<file>DependFile/Source/brainTrain/upTest1/upper_stretch_R07.png</file>
<file>DependFile/Source/brainTrain/upTest1/upper_stretch_R08.png</file>
<file>DependFile/Source/brainTrain/upTest1/upper_stretch_R09.png</file>
<file>DependFile/Source/brainTrain/upTest1/upper_stretch_R10.png</file>
<file>DependFile/Source/brainTrain/upTest1/upper_stretch_R11.png</file>
<file>DependFile/Source/brainTrain/upTest1/upper_stretch_R12.png</file>
<file>DependFile/Source/brainTrain/upTest1/upper_stretch_R13.png</file>
<file>DependFile/Source/brainTrain/upTest1/upper_stretch_R14.png</file>
<file>DependFile/Source/brainTrain/upTest1/upper_stretch_R15.png</file>
<file>DependFile/Source/brainTrain/upTest2D/upper_stretch_R01.png</file>
<file>DependFile/Source/brainTrain/upTest2D/upper_stretch_R02.png</file>
<file>DependFile/Source/brainTrain/upTest2D/upper_stretch_R03.png</file>
<file>DependFile/Source/brainTrain/upTest2D/upper_stretch_R04.png</file>
<file>DependFile/Source/brainTrain/upTest2D/upper_stretch_R05.png</file>
<file>DependFile/Source/brainTrain/upTest2D/upper_stretch_R06.png</file>
<file>DependFile/Source/brainTrain/upTest2D/upper_stretch_R07.png</file>
<file>DependFile/Source/brainTrain/upTest3/upper_stretch_R01.png</file>
<file>DependFile/Source/brainTrain/upTest3/upper_stretch_R02.png</file>
<file>DependFile/Source/brainTrain/upTest3/upper_stretch_R03.png</file>
<file>DependFile/Source/brainTrain/upTest3/upper_stretch_R04.png</file>
<file>DependFile/Source/brainTrain/upTest3/upper_stretch_R05.png</file>
<file>DependFile/Source/brainTrain/upTest3/upper_stretch_R06.png</file>
<file>DependFile/Source/brainTrain/upTest3/upper_stretch_R07.png</file>
<file>DependFile/Source/brainTrain/upTest3/upper_stretch_R08.png</file>
<file>DependFile/Source/brainTrain/upTest3/upper_stretch_R09.png</file>
<file>DependFile/Source/brainTrain/upTest3/upper_stretch_R10.png</file>
<file>DependFile/Source/brainTrain/upTest3/upper_stretch_R11.png</file>
<file>DependFile/Source/brainTrain/upTest3/upper_stretch_R12.png</file>
<file>DependFile/Source/brainTrain/upTest3/upper_stretch_R13.png</file>
<file>DependFile/Source/brainTrain/upTest3/upper_stretch_R14.png</file>
<file>DependFile/Source/brainTrain/upTest3/upper_stretch_R15.png</file>
<file>DependFile/Source/brainTrain/upTest3/upper_stretch_R16.png</file>
</qresource>
</RCC>

View File

Before

Width:  |  Height:  |  Size: 176 KiB

After

Width:  |  Height:  |  Size: 176 KiB

View File

Before

Width:  |  Height:  |  Size: 218 KiB

After

Width:  |  Height:  |  Size: 218 KiB

View File

Before

Width:  |  Height:  |  Size: 99 KiB

After

Width:  |  Height:  |  Size: 99 KiB

View File

Before

Width:  |  Height:  |  Size: 201 KiB

After

Width:  |  Height:  |  Size: 201 KiB

View File

Before

Width:  |  Height:  |  Size: 208 KiB

After

Width:  |  Height:  |  Size: 208 KiB

View File

Before

Width:  |  Height:  |  Size: 75 KiB

After

Width:  |  Height:  |  Size: 75 KiB

View File

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -0,0 +1 @@
decoder_main.exe -t 0 -c com1 -p 115200

View File

Before

Width:  |  Height:  |  Size: 164 KiB

After

Width:  |  Height:  |  Size: 164 KiB