1.阻抗显示 2.解码器启动配置文件更改
This commit is contained in:
parent
5de05d7b45
commit
1968baa30e
@ -223,7 +223,8 @@ Item {
|
||||
id: connectTimer
|
||||
interval: 3*1000;
|
||||
onTriggered: {
|
||||
clientSocket.connected();
|
||||
clientSocket.disconnectFromHost();
|
||||
clientSocket.connectToHost();
|
||||
}
|
||||
}
|
||||
|
||||
@ -241,19 +242,19 @@ Item {
|
||||
{
|
||||
stimulateTimer.stop()
|
||||
}
|
||||
if(index === "2")
|
||||
if(index === "0")
|
||||
{
|
||||
ssvepTenHzTimer.start();
|
||||
hitTimer.start();
|
||||
bci.startTrain(0,responseTime-2);
|
||||
hitIndex = 0;
|
||||
}else if(index === "0")
|
||||
}else if(index === "1")
|
||||
{
|
||||
ssvepTwelveHzTimer.start();
|
||||
hitTimer.start();
|
||||
bci.startTrain(1,responseTime-2);
|
||||
hitIndex = 1;
|
||||
}else if(index === "1")
|
||||
}else if(index === "2")
|
||||
{
|
||||
ssvepFifteenHzTimer.start();
|
||||
hitTimer.start();
|
||||
@ -298,6 +299,13 @@ Item {
|
||||
{
|
||||
bci.initTrain();
|
||||
clientSocket.connectToHost();
|
||||
|
||||
var channels = bci.getChannels();
|
||||
for(var i=0;i<channels.length;i++)
|
||||
{
|
||||
console.log("12344",channels[i])
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -314,19 +322,23 @@ Item {
|
||||
//判断是不是阻抗数据
|
||||
var parts = cmd.split(":");
|
||||
//通道序列号
|
||||
var channels = [0,1,2,3,4,5,6,7]
|
||||
var channels = bci.getChannels();
|
||||
for(var i=0;i<channels.length;i++)
|
||||
{
|
||||
console.info(channels[i],parts[channels[i]],popimpedance.minImpedance,popimpedance.maxImpedance);
|
||||
if(channels[i] < parts.length)
|
||||
{
|
||||
if(Number(parts[channels[i]]) < popimpedance.minImpedance)
|
||||
{
|
||||
console.info("green");
|
||||
popimpedance.colorChange(i,green)
|
||||
}else if(Number(parts[channels[i]]) > popimpedance.maxImpedance)
|
||||
{
|
||||
console.info("red");
|
||||
popimpedance.colorChange(i,red)
|
||||
}else
|
||||
{
|
||||
console.info("yellow");
|
||||
popimpedance.colorChange(i,yellow)
|
||||
}
|
||||
}
|
||||
@ -339,7 +351,7 @@ Item {
|
||||
}
|
||||
onConnected:
|
||||
{
|
||||
console.info("Client socket connected");
|
||||
console.info("Client socket connected 111111");
|
||||
bConnect = true;
|
||||
bci.deviceStatus(true);
|
||||
if(connectTimer.running)
|
||||
@ -1033,6 +1045,14 @@ Item {
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
popimpedance.show()
|
||||
popimpedance.colorChange(0,green)
|
||||
popimpedance.colorChange(1,green)
|
||||
popimpedance.colorChange(2,green)
|
||||
popimpedance.colorChange(3,green)
|
||||
popimpedance.colorChange(4,green)
|
||||
popimpedance.colorChange(5,green)
|
||||
popimpedance.colorChange(6,green)
|
||||
popimpedance.colorChange(7,green)
|
||||
popimpedance.colorChange(9,green)
|
||||
popimpedance.colorChange(10,green)
|
||||
}
|
||||
@ -1041,8 +1061,8 @@ Item {
|
||||
}
|
||||
PopImpedance{
|
||||
id:popimpedance
|
||||
property int maxImpedance: 6
|
||||
property int minImpedance: 3
|
||||
property int maxImpedance: 15*100
|
||||
property int minImpedance: 10*100
|
||||
Timer {
|
||||
id: impedanceTimer
|
||||
interval: 1000
|
||||
@ -1055,10 +1075,14 @@ Item {
|
||||
{
|
||||
if(visible)
|
||||
{
|
||||
impedanceTimer.start();
|
||||
//impedanceTimer.start();
|
||||
//开启阻抗
|
||||
clientSocket.writeBytes(getIntArr("3"));
|
||||
}else
|
||||
{
|
||||
impedanceTimer.stop();
|
||||
//impedanceTimer.stop();
|
||||
//关闭阻抗
|
||||
clientSocket.writeBytes(getIntArr("4"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,13 @@
|
||||
#include <QFile>
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QSettings>
|
||||
#include <QTextCodec>
|
||||
|
||||
BCIManager::BCIManager(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
|
||||
readConfigFile();
|
||||
}
|
||||
|
||||
bool BCIManager::startLinkerPrograme()
|
||||
@ -38,7 +40,7 @@ bool BCIManager::startLinkerPrograme()
|
||||
//启动进程
|
||||
//QString strCmd = QApplication::applicationDirPath().append("/BCILinker/SunnyLinkTool/") + strContent;
|
||||
|
||||
QString strCmd = QString("./") + strContent;
|
||||
QString strCmd = QString("./%1 -t 1 -c %2 -p %3").arg(m_strExe).arg(m_strIp).arg(m_nPort);
|
||||
|
||||
qDebug() << strCmd;
|
||||
if(nullptr == m_pCmd)
|
||||
@ -47,7 +49,7 @@ bool BCIManager::startLinkerPrograme()
|
||||
connect(m_pCmd, &QProcess::readyReadStandardOutput, this, &BCIManager::slotLinkerProgrameReadyReadStandardOutput);
|
||||
connect(m_pCmd, &QProcess::readyReadStandardError, this, &BCIManager::slotLinkerProgrameReadyReadStandardError);
|
||||
}
|
||||
m_pCmd->start(strCmd);
|
||||
m_pCmd->startDetached(strCmd);
|
||||
}
|
||||
|
||||
void BCIManager::initTrain()
|
||||
@ -130,6 +132,7 @@ void BCIManager::slotTrainTimer()
|
||||
|
||||
void BCIManager::startTrain(int Part, int Time)
|
||||
{
|
||||
qDebug() << "33333333333333333333";
|
||||
initTrain();
|
||||
if(trainTimer->isActive())
|
||||
{
|
||||
@ -188,3 +191,85 @@ void BCIManager::deviceStatus(bool bConnected)
|
||||
{
|
||||
emit signalDeviceStatus(bConnected);
|
||||
}
|
||||
|
||||
QVariantList BCIManager::getChannels()
|
||||
{
|
||||
QVariantList lstChannels;
|
||||
for(int i = 0; i < m_vecChannels.length(); i++)
|
||||
{
|
||||
lstChannels.push_back(m_vecChannels.at(i));
|
||||
}
|
||||
return lstChannels;
|
||||
}
|
||||
|
||||
QString BCIManager::getExe()
|
||||
{
|
||||
return m_strExe;
|
||||
}
|
||||
|
||||
QString BCIManager::getIp()
|
||||
{
|
||||
return m_strIp;
|
||||
}
|
||||
|
||||
int BCIManager::getPort()
|
||||
{
|
||||
return m_nPort;
|
||||
}
|
||||
|
||||
void BCIManager::readConfigFile()
|
||||
{
|
||||
//文件路径+文件名
|
||||
QString fileName = QCoreApplication::applicationDirPath() + "/DevConfig.ini";
|
||||
//创建配置目标,输入文件路径,文件格式
|
||||
QSettings *setting = new QSettings(fileName, QSettings::IniFormat);
|
||||
//设置文件编码,配置文件中使用中文时,这是必须的,否则乱码
|
||||
setting->setIniCodec(QTextCodec::codecForName("UTF-8"));
|
||||
// 判断文件是否存在
|
||||
if(QFile::exists(fileName)) // 文件存在,读出配置项
|
||||
{
|
||||
// 这里的setting->value的第二参数,是配置项缺省值,即当读取的配置项不存在时,读取该值
|
||||
// User是配置组,name和age是配置项
|
||||
m_strExe = setting->value("Comm/Exe", "decoder_main.exe").toString();
|
||||
m_strIp = setting->value("Comm/Ip", "192.168.1.111").toString();
|
||||
m_nPort = setting->value("Comm/Port", 5086).toInt();
|
||||
m_vecChannels.push_back(setting->value("Channels/Channel_0", 13).toInt());
|
||||
m_vecChannels.push_back(setting->value("Channels/Channel_1", 14).toInt());
|
||||
m_vecChannels.push_back(setting->value("Channels/Channel_2", 15).toInt());
|
||||
m_vecChannels.push_back(setting->value("Channels/Channel_3", 27).toInt());
|
||||
m_vecChannels.push_back(setting->value("Channels/Channel_4", 28).toInt());
|
||||
m_vecChannels.push_back(setting->value("Channels/Channel_5", 32).toInt());
|
||||
m_vecChannels.push_back(setting->value("Channels/Channel_6", 34).toInt());
|
||||
m_vecChannels.push_back(setting->value("Channels/Channel_7", 58).toInt());
|
||||
m_nSamplerate = setting->value("Dev/Samplerate", 250).toUInt();
|
||||
}
|
||||
else // 文件不存在,写入配置项,生成配置文件
|
||||
{
|
||||
setting->value("Comm/Exe", "decoder_main.exe").toString();
|
||||
m_strExe = "decoder_main.exe";
|
||||
setting->setValue("Comm/Ip", "192.168.1.111");
|
||||
m_strIp = "192.168.1.111";
|
||||
setting->setValue("Comm/Port", 5086);
|
||||
m_nPort = 5086;
|
||||
setting->setValue("Channels/Channel_0", 13);
|
||||
m_vecChannels.push_back(13);
|
||||
setting->setValue("Channels/Channel_1", 14);
|
||||
m_vecChannels.push_back(14);
|
||||
setting->setValue("Channels/Channel_2", 15);
|
||||
m_vecChannels.push_back(15);
|
||||
setting->setValue("Channels/Channel_3", 27);
|
||||
m_vecChannels.push_back(27);
|
||||
setting->setValue("Channels/Channel_4", 28);
|
||||
m_vecChannels.push_back(28);
|
||||
setting->setValue("Channels/Channel_5", 32);
|
||||
m_vecChannels.push_back(32);
|
||||
setting->setValue("Channels/Channel_6", 34);
|
||||
m_vecChannels.push_back(34);
|
||||
setting->setValue("Channels/Channel_7", 58);
|
||||
m_vecChannels.push_back(58);
|
||||
setting->setValue("Dev/Samplerate", 250);
|
||||
m_nSamplerate = 250;
|
||||
setting->sync();
|
||||
}
|
||||
delete setting;
|
||||
}
|
||||
|
@ -35,6 +35,17 @@ public:
|
||||
Q_INVOKABLE void continueTrain();
|
||||
Q_INVOKABLE void deviceStatus(bool bConnected);
|
||||
|
||||
Q_INVOKABLE QVariantList getChannels();
|
||||
|
||||
QString getExe();
|
||||
|
||||
QString getIp();
|
||||
|
||||
int getPort();
|
||||
|
||||
private:
|
||||
void readConfigFile();
|
||||
|
||||
private slots:
|
||||
//Linker程序的标准输出
|
||||
void slotLinkerProgrameReadyReadStandardOutput();
|
||||
@ -59,6 +70,12 @@ private:
|
||||
|
||||
int heartCount = 0; //心跳次数,用于检测通信
|
||||
ST_BicycleParam m_st_bicycleParam; //启动参数
|
||||
|
||||
QString m_strIp;
|
||||
int m_nPort;
|
||||
QVector<int> m_vecChannels;
|
||||
QString m_strExe;
|
||||
uint m_nSamplerate;
|
||||
};
|
||||
|
||||
#endif // BCIMANAGER_H
|
||||
|
@ -26,135 +26,166 @@
|
||||
|
||||
#include <QHostAddress>
|
||||
|
||||
namespace QMLTcpSockets{
|
||||
|
||||
TcpSocket::TcpSocket(QQuickItem* parent):
|
||||
QQuickItem(parent),
|
||||
socket(this)
|
||||
namespace QMLTcpSockets
|
||||
{
|
||||
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();
|
||||
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;
|
||||
}
|
||||
|
||||
quint16 port = socket.peerPort();
|
||||
if(this->port != port){
|
||||
this->port = port;
|
||||
emit portChanged();
|
||||
TcpSocket::TcpSocket(QIntPtr *socketDescriptor, QQuickItem *parent):
|
||||
TcpSocket(parent)
|
||||
{
|
||||
socket.setSocketDescriptor(socketDescriptor->ptr);
|
||||
socketDescriptor->deleteLater();
|
||||
peer = socket.peerAddress().toString();
|
||||
port = socket.peerPort();
|
||||
}
|
||||
|
||||
emit connected();
|
||||
}
|
||||
TcpSocket::~TcpSocket()
|
||||
{
|
||||
socket.flush();
|
||||
}
|
||||
|
||||
void TcpSocket::setSocketOption(int option, QVariant value){
|
||||
socket.setSocketOption((QAbstractSocket::SocketOption)option, value);
|
||||
}
|
||||
void TcpSocket::setSocketDescriptor(QIntPtr *socketDescriptor)
|
||||
{
|
||||
socket.flush();
|
||||
socket.disconnectFromHost();
|
||||
|
||||
void TcpSocket::setPeer(QString peer){
|
||||
if(peer != this->peer){
|
||||
if(socket.state() != TcpSocketEnums::UnconnectedState)
|
||||
qWarning() << "TcpSocket::setPeer(): Can only set peer while disconnected.";
|
||||
else{
|
||||
socket.setSocketDescriptor(socketDescriptor->ptr);
|
||||
socketDescriptor->deleteLater();
|
||||
|
||||
QString peer = socket.peerAddress().toString();
|
||||
if(this->peer != peer)
|
||||
{
|
||||
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{
|
||||
quint16 port = socket.peerPort();
|
||||
if(this->port != port)
|
||||
{
|
||||
this->port = port;
|
||||
emit portChanged();
|
||||
}
|
||||
|
||||
emit connected();
|
||||
}
|
||||
}
|
||||
|
||||
void TcpSocket::connectToHost(){
|
||||
socket.connectToHost(peer, port);
|
||||
}
|
||||
void TcpSocket::setSocketOption(int option, QVariant value)
|
||||
{
|
||||
socket.setSocketOption((QAbstractSocket::SocketOption)option, value);
|
||||
}
|
||||
|
||||
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;
|
||||
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();
|
||||
}
|
||||
}
|
||||
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;
|
||||
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();
|
||||
}
|
||||
}
|
||||
numBytesToWrite -= bytesWritten;
|
||||
bytesRaw += bytesWritten;
|
||||
}
|
||||
socket.flush();
|
||||
|
||||
return true;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user