1.阻抗显示 2.解码器启动配置文件更改

This commit is contained in:
curtis 2025-01-05 14:41:32 +08:00
parent 5de05d7b45
commit 1968baa30e
8 changed files with 276 additions and 119 deletions

View File

@ -223,7 +223,8 @@ Item {
id: connectTimer id: connectTimer
interval: 3*1000; interval: 3*1000;
onTriggered: { onTriggered: {
clientSocket.connected(); clientSocket.disconnectFromHost();
clientSocket.connectToHost();
} }
} }
@ -241,19 +242,19 @@ Item {
{ {
stimulateTimer.stop() stimulateTimer.stop()
} }
if(index === "2") if(index === "0")
{ {
ssvepTenHzTimer.start(); ssvepTenHzTimer.start();
hitTimer.start(); hitTimer.start();
bci.startTrain(0,responseTime-2); bci.startTrain(0,responseTime-2);
hitIndex = 0; hitIndex = 0;
}else if(index === "0") }else if(index === "1")
{ {
ssvepTwelveHzTimer.start(); ssvepTwelveHzTimer.start();
hitTimer.start(); hitTimer.start();
bci.startTrain(1,responseTime-2); bci.startTrain(1,responseTime-2);
hitIndex = 1; hitIndex = 1;
}else if(index === "1") }else if(index === "2")
{ {
ssvepFifteenHzTimer.start(); ssvepFifteenHzTimer.start();
hitTimer.start(); hitTimer.start();
@ -298,6 +299,13 @@ Item {
{ {
bci.initTrain(); bci.initTrain();
clientSocket.connectToHost(); 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 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++) 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(channels[i] < parts.length)
{ {
if(Number(parts[channels[i]]) < popimpedance.minImpedance) if(Number(parts[channels[i]]) < popimpedance.minImpedance)
{ {
console.info("green");
popimpedance.colorChange(i,green) popimpedance.colorChange(i,green)
}else if(Number(parts[channels[i]]) > popimpedance.maxImpedance) }else if(Number(parts[channels[i]]) > popimpedance.maxImpedance)
{ {
console.info("red");
popimpedance.colorChange(i,red) popimpedance.colorChange(i,red)
}else }else
{ {
console.info("yellow");
popimpedance.colorChange(i,yellow) popimpedance.colorChange(i,yellow)
} }
} }
@ -339,7 +351,7 @@ Item {
} }
onConnected: onConnected:
{ {
console.info("Client socket connected"); console.info("Client socket connected 111111");
bConnect = true; bConnect = true;
bci.deviceStatus(true); bci.deviceStatus(true);
if(connectTimer.running) if(connectTimer.running)
@ -1033,6 +1045,14 @@ Item {
anchors.fill: parent anchors.fill: parent
onClicked: { onClicked: {
popimpedance.show() 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(9,green)
popimpedance.colorChange(10,green) popimpedance.colorChange(10,green)
} }
@ -1041,8 +1061,8 @@ Item {
} }
PopImpedance{ PopImpedance{
id:popimpedance id:popimpedance
property int maxImpedance: 6 property int maxImpedance: 15*100
property int minImpedance: 3 property int minImpedance: 10*100
Timer { Timer {
id: impedanceTimer id: impedanceTimer
interval: 1000 interval: 1000
@ -1055,10 +1075,14 @@ Item {
{ {
if(visible) if(visible)
{ {
impedanceTimer.start(); //impedanceTimer.start();
//
clientSocket.writeBytes(getIntArr("3"));
}else }else
{ {
impedanceTimer.stop(); //impedanceTimer.stop();
//
clientSocket.writeBytes(getIntArr("4"));
} }
} }
} }

View File

@ -2,11 +2,13 @@
#include <QFile> #include <QFile>
#include <QApplication> #include <QApplication>
#include <QDebug> #include <QDebug>
#include <QSettings>
#include <QTextCodec>
BCIManager::BCIManager(QObject *parent) BCIManager::BCIManager(QObject *parent)
: QObject{parent} : QObject{parent}
{ {
readConfigFile();
} }
bool BCIManager::startLinkerPrograme() bool BCIManager::startLinkerPrograme()
@ -38,7 +40,7 @@ bool BCIManager::startLinkerPrograme()
//启动进程 //启动进程
//QString strCmd = QApplication::applicationDirPath().append("/BCILinker/SunnyLinkTool/") + strContent; //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; qDebug() << strCmd;
if(nullptr == m_pCmd) if(nullptr == m_pCmd)
@ -47,7 +49,7 @@ bool BCIManager::startLinkerPrograme()
connect(m_pCmd, &QProcess::readyReadStandardOutput, this, &BCIManager::slotLinkerProgrameReadyReadStandardOutput); connect(m_pCmd, &QProcess::readyReadStandardOutput, this, &BCIManager::slotLinkerProgrameReadyReadStandardOutput);
connect(m_pCmd, &QProcess::readyReadStandardError, this, &BCIManager::slotLinkerProgrameReadyReadStandardError); connect(m_pCmd, &QProcess::readyReadStandardError, this, &BCIManager::slotLinkerProgrameReadyReadStandardError);
} }
m_pCmd->start(strCmd); m_pCmd->startDetached(strCmd);
} }
void BCIManager::initTrain() void BCIManager::initTrain()
@ -130,6 +132,7 @@ void BCIManager::slotTrainTimer()
void BCIManager::startTrain(int Part, int Time) void BCIManager::startTrain(int Part, int Time)
{ {
qDebug() << "33333333333333333333";
initTrain(); initTrain();
if(trainTimer->isActive()) if(trainTimer->isActive())
{ {
@ -188,3 +191,85 @@ void BCIManager::deviceStatus(bool bConnected)
{ {
emit signalDeviceStatus(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;
}

View File

@ -35,6 +35,17 @@ public:
Q_INVOKABLE void continueTrain(); Q_INVOKABLE void continueTrain();
Q_INVOKABLE void deviceStatus(bool bConnected); Q_INVOKABLE void deviceStatus(bool bConnected);
Q_INVOKABLE QVariantList getChannels();
QString getExe();
QString getIp();
int getPort();
private:
void readConfigFile();
private slots: private slots:
//Linker程序的标准输出 //Linker程序的标准输出
void slotLinkerProgrameReadyReadStandardOutput(); void slotLinkerProgrameReadyReadStandardOutput();
@ -59,6 +70,12 @@ private:
int heartCount = 0; //心跳次数,用于检测通信 int heartCount = 0; //心跳次数,用于检测通信
ST_BicycleParam m_st_bicycleParam; //启动参数 ST_BicycleParam m_st_bicycleParam; //启动参数
QString m_strIp;
int m_nPort;
QVector<int> m_vecChannels;
QString m_strExe;
uint m_nSamplerate;
}; };
#endif // BCIMANAGER_H #endif // BCIMANAGER_H

View File

@ -26,34 +26,37 @@
#include <QHostAddress> #include <QHostAddress>
namespace QMLTcpSockets{ namespace QMLTcpSockets
{
TcpSocket::TcpSocket(QQuickItem* parent): TcpSocket::TcpSocket(QQuickItem *parent):
QQuickItem(parent), QQuickItem(parent),
socket(this) socket(this)
{ {
connect(&socket, SIGNAL(connected()), this, SIGNAL(connected())); connect(&socket, SIGNAL(connected()), this, SIGNAL(connected()));
connect(&socket, SIGNAL(disconnected()), this, SIGNAL(disconnected())); connect(&socket, SIGNAL(disconnected()), this, SIGNAL(disconnected()));
connect(&socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(emitErrorAsInt(QAbstractSocket::SocketError))); connect(&socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(emitErrorAsInt(QAbstractSocket::SocketError)));
connect(&socket, SIGNAL(readyRead()), this, SLOT(publish())); connect(&socket, SIGNAL(readyRead()), this, SLOT(publish()));
peer = ""; peer = "";
port = 0; port = 0;
} }
TcpSocket::TcpSocket(QIntPtr* socketDescriptor, QQuickItem* parent): TcpSocket::TcpSocket(QIntPtr *socketDescriptor, QQuickItem *parent):
TcpSocket(parent) TcpSocket(parent)
{ {
socket.setSocketDescriptor(socketDescriptor->ptr); socket.setSocketDescriptor(socketDescriptor->ptr);
socketDescriptor->deleteLater(); socketDescriptor->deleteLater();
peer = socket.peerAddress().toString(); peer = socket.peerAddress().toString();
port = socket.peerPort(); port = socket.peerPort();
} }
TcpSocket::~TcpSocket(){ TcpSocket::~TcpSocket()
{
socket.flush(); socket.flush();
} }
void TcpSocket::setSocketDescriptor(QIntPtr* socketDescriptor){ void TcpSocket::setSocketDescriptor(QIntPtr *socketDescriptor)
{
socket.flush(); socket.flush();
socket.disconnectFromHost(); socket.disconnectFromHost();
@ -61,91 +64,119 @@ void TcpSocket::setSocketDescriptor(QIntPtr* socketDescriptor){
socketDescriptor->deleteLater(); socketDescriptor->deleteLater();
QString peer = socket.peerAddress().toString(); QString peer = socket.peerAddress().toString();
if(this->peer != peer){ if(this->peer != peer)
{
this->peer = peer; this->peer = peer;
emit peerChanged(); emit peerChanged();
} }
quint16 port = socket.peerPort(); quint16 port = socket.peerPort();
if(this->port != port){ if(this->port != port)
{
this->port = port; this->port = port;
emit portChanged(); emit portChanged();
} }
emit connected(); emit connected();
} }
void TcpSocket::setSocketOption(int option, QVariant value){ void TcpSocket::setSocketOption(int option, QVariant value)
{
socket.setSocketOption((QAbstractSocket::SocketOption)option, value); socket.setSocketOption((QAbstractSocket::SocketOption)option, value);
} }
void TcpSocket::setPeer(QString peer){ void TcpSocket::setPeer(QString peer)
if(peer != this->peer){ {
if(peer != this->peer)
{
if(socket.state() != TcpSocketEnums::UnconnectedState) if(socket.state() != TcpSocketEnums::UnconnectedState)
{
qWarning() << "TcpSocket::setPeer(): Can only set peer while disconnected."; qWarning() << "TcpSocket::setPeer(): Can only set peer while disconnected.";
else{ }
else
{
this->peer = peer; this->peer = peer;
emit peerChanged(); emit peerChanged();
} }
} }
} }
void TcpSocket::setPort(int port){ void TcpSocket::setPort(int port)
if(port < 0){ {
if(port < 0)
{
qWarning() << "TcpSocket::setPort(): port given was negative, setting to 0."; qWarning() << "TcpSocket::setPort(): port given was negative, setting to 0.";
port = 0; port = 0;
} }
else if(port > 0xFFFF){ else if(port > 0xFFFF)
{
qWarning() << "TcpSocket::setPort(): port given was larger than 65535, setting to 65535."; qWarning() << "TcpSocket::setPort(): port given was larger than 65535, setting to 65535.";
port = 0xFFFF; port = 0xFFFF;
} }
if(port != this->port){ if(port != this->port)
{
if(socket.state() != TcpSocketEnums::UnconnectedState) if(socket.state() != TcpSocketEnums::UnconnectedState)
{
qWarning() << "TcpSocket::setPort(): Can only set port while disconnected."; qWarning() << "TcpSocket::setPort(): Can only set port while disconnected.";
else{ }
else
{
this->port = port; this->port = port;
emit portChanged(); emit portChanged();
} }
} }
} }
void TcpSocket::connectToHost(){ void TcpSocket::connectToHost()
{
socket.connectToHost(peer, port); socket.connectToHost(peer, port);
} }
void TcpSocket::disconnectFromHost(){ void TcpSocket::disconnectFromHost()
{
socket.disconnectFromHost(); socket.disconnectFromHost();
} }
void TcpSocket::emitErrorAsInt(QAbstractSocket::SocketError socketError){ void TcpSocket::emitErrorAsInt(QAbstractSocket::SocketError socketError)
{
emit error(socketError); emit error(socketError);
} }
void TcpSocket::publish(){ void TcpSocket::publish()
{
QList<int> list; QList<int> list;
QByteArray receivedBytes = socket.readAll(); QByteArray receivedBytes = socket.readAll();
for(char c : receivedBytes) for(char c : receivedBytes)
list << (int)(*((unsigned char*)(&c))); {
list << (int)(*((unsigned char *)(&c)));
}
emit bytesReceived(list); emit bytesReceived(list);
} }
bool TcpSocket::writeBytes(QList<int> bytes){ bool TcpSocket::writeBytes(QList<int> bytes)
{
QByteArray container; QByteArray container;
for(int b : bytes){ for(int b : bytes)
if(b < 0 || b > 0xFF){ {
if(b < 0 || b > 0xFF)
{
qWarning() << "TcpSocket::writeBytes(): bytes contain integer not in [0x00,0xFF], not writing"; qWarning() << "TcpSocket::writeBytes(): bytes contain integer not in [0x00,0xFF], not writing";
return false; return false;
} }
else else
{
container.append((char)b); container.append((char)b);
} }
}
int numBytesToWrite = container.size(); int numBytesToWrite = container.size();
const char* bytesRaw = container.constData(); const char *bytesRaw = container.constData();
while(numBytesToWrite > 0){ while(numBytesToWrite > 0)
{
int bytesWritten = socket.write(bytesRaw, numBytesToWrite); int bytesWritten = socket.write(bytesRaw, numBytesToWrite);
if(bytesWritten < 0){ if(bytesWritten < 0)
{
qWarning() << "TcpSocket::writeBytes(): Bytes were not written: " << socket.errorString(); qWarning() << "TcpSocket::writeBytes(): Bytes were not written: " << socket.errorString();
return false; return false;
} }
@ -155,6 +186,6 @@ bool TcpSocket::writeBytes(QList<int> bytes){
socket.flush(); socket.flush();
return true; return true;
} }
} }