This commit is contained in:
curtis 2024-11-25 17:15:44 +08:00
commit 32e5360a91
3749 changed files with 1432905 additions and 0 deletions

View File

@ -0,0 +1,21 @@
QMAKE_CXX.QT_COMPILER_STDCXX = 201402L
QMAKE_CXX.QMAKE_GCC_MAJOR_VERSION = 8
QMAKE_CXX.QMAKE_GCC_MINOR_VERSION = 1
QMAKE_CXX.QMAKE_GCC_PATCH_VERSION = 0
QMAKE_CXX.COMPILER_MACROS = \
QT_COMPILER_STDCXX \
QMAKE_GCC_MAJOR_VERSION \
QMAKE_GCC_MINOR_VERSION \
QMAKE_GCC_PATCH_VERSION
QMAKE_CXX.INCDIRS = \
D:/Qt/Qt5.15.12/Tools/mingw810_64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++ \
D:/Qt/Qt5.15.12/Tools/mingw810_64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32 \
D:/Qt/Qt5.15.12/Tools/mingw810_64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward \
D:/Qt/Qt5.15.12/Tools/mingw810_64/lib/gcc/x86_64-w64-mingw32/8.1.0/include \
D:/Qt/Qt5.15.12/Tools/mingw810_64/lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed \
D:/Qt/Qt5.15.12/Tools/mingw810_64/x86_64-w64-mingw32/include
QMAKE_CXX.LIBDIRS = \
D:/Qt/Qt5.15.12/Tools/mingw810_64/lib/gcc/x86_64-w64-mingw32/8.1.0 \
D:/Qt/Qt5.15.12/Tools/mingw810_64/lib/gcc \
D:/Qt/Qt5.15.12/Tools/mingw810_64/x86_64-w64-mingw32/lib \
D:/Qt/Qt5.15.12/Tools/mingw810_64/lib

View File

@ -0,0 +1,5 @@
[General]
number=100033
password=666666
userName=xyyl
user=xyyl

View File

@ -0,0 +1 @@
此文件夹下存放配置文件一般为ini文件

View File

@ -0,0 +1,4 @@
[General]
number=100033
password=666666
userName=xyyl

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<recipeType>
<recipe ID = "1" name = "肱二头肌" startAngle = "60" stopAngle = "270"></recipe>
<recipe ID = "2" name = "肱三头肌" startAngle = "270" stopAngle = "90"></recipe>
<recipe ID = "3" name = "前三角肌" startAngle = "290" stopAngle = "70"></recipe>
<recipe ID = "4" name = "后三角肌" startAngle = "90" stopAngle = "270"></recipe>
<recipe ID = "5" name = "屈腕肌" startAngle = "90" stopAngle = "280"></recipe>
<recipe ID = "6" name = "伸腕肌" startAngle = "290" stopAngle = "70"></recipe>
<recipe ID = "7" name = "肩胛肌" startAngle = "70" stopAngle = "210"></recipe>
<recipe ID = "8" name = "冈上肌" startAngle = "180" stopAngle = "310"></recipe>
<recipe ID = "9" name = "腘绳肌" startAngle = "30" stopAngle = "210"></recipe>
<recipe ID = "10" name = "臀大肌" startAngle = "0" stopAngle = "180"></recipe>
<recipe ID = "11" name = "胫前肌" startAngle = "90" stopAngle = "270"></recipe>
<recipe ID = "12" name = "腓肠肌" startAngle = "290" stopAngle = "110"></recipe>
<recipe ID = "13" name = "腹肌" startAngle = "270" stopAngle = "100"></recipe>
<recipe ID = "14" name = "竖脊肌" startAngle = "100" stopAngle = "120"></recipe>
<recipe ID = "15" name = "肱四头肌" startAngle = "230" stopAngle = "60"></recipe>
</recipeType>

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<recipeType>
<recipe ID = "1" name = "肱二头肌" startAngle = "300" stopAngle = "120"></recipe>
<recipe ID = "2" name = "肱三头肌" startAngle = "120" stopAngle = "270"></recipe>
<recipe ID = "3" name = "前三角肌" startAngle = "90" stopAngle = "270"></recipe>
<recipe ID = "4" name = "后三角肌" startAngle = "270" stopAngle = "90"></recipe>
<recipe ID = "5" name = "屈腕肌" startAngle = "280" stopAngle = "90"></recipe>
<recipe ID = "6" name = "伸腕肌" startAngle = "70" stopAngle = "290"></recipe>
<recipe ID = "7" name = "肩胛肌" startAngle = "210" stopAngle = "90"></recipe>
<recipe ID = "8" name = "冈上肌" startAngle = "310" stopAngle = "180"></recipe>
<recipe ID = "9" name = "腘绳肌" startAngle = "210" stopAngle = "30"></recipe>
<recipe ID = "10" name = "臀大肌" startAngle = "180" stopAngle = "0"></recipe>
<recipe ID = "11" name = "胫前肌" startAngle = "270" stopAngle = "90"></recipe>
<recipe ID = "12" name = "腓肠肌" startAngle = "110" stopAngle = "290"></recipe>
<recipe ID = "13" name = "腹肌" startAngle = "100" stopAngle = "270"></recipe>
<recipe ID = "14" name = "竖脊肌" startAngle = "120" stopAngle = "300"></recipe>
<recipe ID = "15" name = "肱四头肌" startAngle = "270" stopAngle = "90"></recipe>
</recipeType>

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<config>
<tcpAddress IP = "192.168.1.20" port = "8000"></tcpAddress>
<udpServerAddress IP = "192.168.1.10" port = "10000"></udpServerAddress>
<udpClientAddress IP = "192.168.1.100" port = "15000"></udpClientAddress>
<udpGameServerAddress IP = "127.0.0.1" port = "20000"></udpGameServerAddress>
<!--与游戏通信的上位机地址-->
<udpGameClientAddress IP = "127.0.0.1" port = "12000"></udpGameClientAddress>
<!--与上位机通信的游戏地址-->
<serialPort portName = "COM6" baud = "115200" dataBits = "8" parity = "0" stopBit = "0" flowControl = "0"></serialPort>
<!--电刺激板-->
<serialPortA portName = "COM4" baud = "115200" dataBits = "8" parity = "0" stopBit = "0" flowControl = "0"></serialPortA>
<dataBase IP = "192.168.1.20" port = "9000" userName = "root" password = "root"></dataBase>
<videoTips videoPath = "./video/" videoNum = "9">
<videoContent videoId = "1" videoName = "综合评估.mp4" ></videoContent>
<videoContent videoId = "2" videoName = "跖屈背屈评估.mp4" ></videoContent>
<videoContent videoId = "3" videoName = "内收外展评估.mp4" ></videoContent>
<videoContent videoId = "4" videoName = "内翻外翻评估.mp4" ></videoContent>
<videoContent videoId = "5" videoName = "斜跖屈背屈评估.mp4" ></videoContent>
<videoContent videoId = "6" videoName = "被动训练提示.mp4" ></videoContent>
<videoContent videoId = "7" videoName = "主动训练提示.mp4" ></videoContent>
<videoContent videoId = "8" videoName = "初始化提示.mp4" ></videoContent>
<videoContent videoId = "9" videoName = "陀螺仪校准提示.mp4" ></videoContent>
</videoTips>
<communicateType type = "0"></communicateType>
<programMode mode = "1"></programMode>
</config>
<!-- type 0-serialport 1-udp 2-tcp 3-can -->
<!-- udpSever-上位机 udpClient-下位机 -->
<!-- mode 0-debug 1-release -->

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<gameType>
<game ID = "1" name = "单人骑行" path = "./GameExecutable/TJ_SXZ001_SingleplayerBicycleRace/" gameName = "TJ_SXZ001_SingleplayerBicycleRace.exe" iconPath = "signalBike.png" className = "UnityWndClass" windownName = "TJ_SXZ002_SingleplayerBicycleRace"></game>
<game ID = "2" name = "多人骑行" path = "./gameExecutable/TJ_SXZ002_MultiplayerBicycleRace_LBY/" gameName = "TJ_SXZ002_MultiplayerBicycleRace_LBY.exe" iconPath = "mulBike.png" className = "UnityWndClass" windownName = "TJ_SXZ002_MultiplayerBicycleRace_LBY"></game>
<game ID = "3" name = "宇宙快车" path = "./gameExecutable/TJ_SXZ003_MultiplayerRaceSciFi/" gameName = "TJ_SXZ003_MultiplayerRaceSciFi.exe" iconPath = "SciFi.png" className = "UnityWndClass" windownName = "Multiplayer Race ScFi3"></game>
<game ID = "4" name = "捕鱼达人" path = "./gameExecutable/TJ_SXZ004_CatchFish/" gameName = "TJ_SXZ004_CatchFish.exe" iconPath = "SXZ004.png" className = "UnityWndClass" windownName = "TJ_SXZ004_CatchFish"></game>
</gameType>

View File

@ -0,0 +1 @@
此文件夹下存放配置文件一般为xml文件

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,349 @@
#include "codecxyckanalog.h"
CODECXyckAnalog::CODECXyckAnalog()
:QObject()
{
_dataList=new QList<MyoelectricData>();
iii=0;
logFile=new QFile("d:/test.txt");
logFile->open(QIODevice::Truncate|QIODevice::ReadWrite);
qDebug()<<"build";
}
QByteArray CODECXyckAnalog::reqSetting(int iChannel, AnalogSetting setting)
{
QByteArray buffer;
buffer.append(static_cast<char>(FUNCCODE_ANALOG_SETTING));
buffer.append(static_cast<char>(iChannel));
buffer.append(static_cast<char>(setting.workmode));
buffer.append(static_cast<char>(setting.samplerate>>8));
buffer.append(static_cast<char>(setting.samplerate%0x100));
buffer.append(static_cast<char>(static_cast<int>(setting.frequency*2)>>8));
buffer.append(static_cast<char>(static_cast<int>(setting.frequency*2)%0x100));
buffer.append(static_cast<char>(setting.pulseWidth>>8));
buffer.append(static_cast<char>(setting.pulseWidth%0x100));
buffer.append(static_cast<char>(static_cast<int>(setting.risingTime*2)>>8));
buffer.append(static_cast<char>(static_cast<int>(setting.risingTime*2)%0x100));
buffer.append(static_cast<char>(setting.holdingTime>>8));
buffer.append(static_cast<char>(setting.holdingTime%0x100));
buffer.append(static_cast<char>(static_cast<int>(setting.fallingTime*2)>>8));
buffer.append(static_cast<char>(static_cast<int>(setting.fallingTime*2)%0x100));
buffer.append(static_cast<char>(setting.breakTime>>8));
buffer.append(static_cast<char>(setting.breakTime%0x100));
return createFrame(buffer);
}
QByteArray CODECXyckAnalog::reqChannalControl(ChannelState ch1, ChannelState ch2, ChannelState ch3, ChannelState ch4)
{
QByteArray buffer;
buffer.append(static_cast<char>(FUNCCODE_ANALOG_CHANNAL_CONTROL));
buffer.append(static_cast<char>(ch1));
buffer.append(static_cast<char>(ch2));
buffer.append(static_cast<char>(ch3));
buffer.append(static_cast<char>(ch4));
return createFrame(buffer);
}
QByteArray CODECXyckAnalog::reqSetCurrent(int iChannel, int iCurrent)
{
if(iCurrent>100||iCurrent<0)
{
return nullptr;
}
QByteArray buffer;
buffer.append(static_cast<char>(FUNCCODE_ANALOG_SET_CURRENT));
buffer.append(static_cast<char>(iChannel));
buffer.append(static_cast<char>(iCurrent));
return createFrame(buffer);
}
QByteArray CODECXyckAnalog::reqDataChange(int iChannel, DataMode datamode)
{
QByteArray buffer;
buffer.append(static_cast<char>(FUNCCODE_ANALOG_DATA_CHANGE));
buffer.append(static_cast<char>(iChannel));
buffer.append(static_cast<char>(datamode));
return createFrame(buffer);
}
QByteArray CODECXyckAnalog::reqSetGain(int iChannel, GainMode gainmode)
{
QByteArray buffer;
buffer.append(static_cast<char>(FUNCCODE_ANALOG_SET_GAIN));
buffer.append(static_cast<char>(iChannel));
buffer.append(static_cast<char>(gainmode));
return createFrame(buffer);
}
QByteArray CODECXyckAnalog::reqSetCollect(int iChannel, ChannelState channelstate)
{
QByteArray buffer;
buffer.append(static_cast<char>(FUNCCODE_ANALOG_SET_COLLECT));
buffer.append(static_cast<char>(iChannel));
buffer.append(static_cast<char>(channelstate));
return createFrame(buffer);
}
QByteArray CODECXyckAnalog::reqSetStimulate(int iChannel, ChannelState channelstate)
{
QByteArray buffer;
buffer.append(static_cast<char>(FUNCCODE_ANALOG_SET_STIMULATE));
buffer.append(static_cast<char>(iChannel));
buffer.append(static_cast<char>(channelstate));
return createFrame(buffer);
}
QByteArray CODECXyckAnalog::reqGetState()
{
QByteArray buffer;
buffer.append(static_cast<char>(FUNCCODE_ANALOG_STATE));
buffer.append(static_cast<char>(0));
buffer.append(static_cast<char>(0));
return createFrame(buffer);
}
void CODECXyckAnalog::dealFrame(QByteArray buffer)
{
switch (static_cast<uint8_t>(buffer.data()[2]))
{
case FUNCCODE_ANALOG_SETTING:
respSetting(buffer);
break;
case FUNCCODE_ANALOG_CHANNAL_CONTROL:
respChannalControl(buffer);
break;
case FUNCCODE_ANALOG_SET_CURRENT:
respSetCurrent(buffer);
break;
case FUNCCODE_ANALOG_DATA_UPLOAD:
respDataUpload(buffer);
break;
case FUNCCODE_ANALOG_DATA_CHANGE:
respDataChange(buffer);
break;
case FUNCCODE_ANALOG_SET_GAIN:
respSetGain(buffer);
break;
case FUNCCODE_ANALOG_SET_COLLECT:
respSetCollect(buffer);
break;
case FUNCCODE_ANALOG_SET_STIMULATE:
respSetStimulate(buffer);
break;
case FUNCCODE_ANALOG_STATE:
respGetState(buffer);
break;
case FUNCCODE_ANALOG_ERROR:
emit commandSendError(static_cast<uint8_t>(buffer.data()[3])
,ErrorCode(static_cast<uint8_t>(buffer.data()[4]))
,static_cast<uint8_t>(buffer.data()[5]));
break;
default:
break;
}
}
void CODECXyckAnalog::clearList()
{
_dataList->clear();
}
QList<MyoelectricData> *CODECXyckAnalog::GetMyoelectricData(int iStep)
{
int iCount=_dataList->length();
if(iCount<=0)
{
return nullptr;
}
int iDT=0;
if(iStep<=iCount&&iStep!=0)
{
iDT=iCount/iStep;
}
if(iDT<1)
{
iDT=0;
}
QList<MyoelectricData> *resultList=new QList<MyoelectricData>();
for(int i=0;i<iCount;)
{
resultList->append(_dataList->takeFirst());
i++;
if(resultList->count()==iStep)
{
break;
}
for(int j=0;j<iDT&&i<iCount;j++)
{
_dataList->takeFirst();
i++;
}
}
return resultList;
}
QByteArray CODECXyckAnalog::respAnalogState(AnalogState *as)
{
QByteArray buffer;
buffer.append(static_cast<char>(FUNCCODE_ANALOG_STATE));
buffer.append(static_cast<char>(0x00));
buffer.append(static_cast<char>(as->electrodeStateA));
buffer.append(static_cast<char>(as->electrodeStateB));
buffer.append(static_cast<char>(as->electrodeStateC));
buffer.append(static_cast<char>(as->electrodeStateD));
buffer.append(static_cast<char>(as->resetState));
buffer.append(static_cast<char>(as->channelWorkStateA));
buffer.append(static_cast<char>(as->channelWorkStateB));
buffer.append(static_cast<char>(as->channelWorkStateC));
buffer.append(static_cast<char>(as->channelWorkStateD));
buffer.append(static_cast<char>(as->AValueA));
buffer.append(static_cast<char>(as->AValueB));
buffer.append(static_cast<char>(as->AValueC));
buffer.append(static_cast<char>(as->AValueD));
return createFrame(buffer);
}
QByteArray CODECXyckAnalog::respMyoelectricData(MyoelectricData *md)
{
QByteArray buffer;
buffer.append(static_cast<char>(FUNCCODE_ANALOG_DATA_UPLOAD));
buffer.append(static_cast<char>(0x00));
buffer.append(static_cast<char>(md->ch1>>8));
buffer.append(static_cast<char>(md->ch1%0x100));
buffer.append(static_cast<char>(md->ch2>>8));
buffer.append(static_cast<char>(md->ch2%0x100));
buffer.append(static_cast<char>(md->ch3>>8));
buffer.append(static_cast<char>(md->ch3%0x100));
buffer.append(static_cast<char>(md->ch4>>8));
buffer.append(static_cast<char>(md->ch4%0x100));
return createFrame(buffer);
}
void CODECXyckAnalog::respSetting(QByteArray buffer)
{
int iChannel=buffer.data()[3];
AnalogSetting *analogSetting=new AnalogSetting();
analogSetting->workmode =WorkMode(static_cast<uint8_t>(buffer.data()[4]));
analogSetting->samplerate=SampleRate((static_cast<uint8_t>(buffer.data()[5])<<8)+static_cast<uint8_t>(buffer.data()[6]));
analogSetting->frequency = ((static_cast<uint8_t>(buffer.data()[7])<<8)+static_cast<uint8_t>(buffer.data()[8]))/2.0;
analogSetting->pulseWidth =(static_cast<uint8_t>(buffer.data()[9])<<8)+static_cast<uint8_t>(buffer.data()[10]);
analogSetting->risingTime= ((static_cast<uint8_t>(buffer.data()[11])<<8)+static_cast<uint8_t>(buffer.data()[12]))/2.0;
analogSetting->holdingTime =(static_cast<uint8_t>(buffer.data()[13])<<8)+static_cast<uint8_t>(buffer.data()[14]);
analogSetting->fallingTime=((static_cast<uint8_t>(buffer.data()[15])<<8)+static_cast<uint8_t>(buffer.data()[16]))/2.0;
analogSetting->breakTime =(static_cast<uint8_t>(buffer.data()[17])<<8)+static_cast<uint8_t>(buffer.data()[18]);
emit analogSettingRev(iChannel,analogSetting);
}
void CODECXyckAnalog::respChannalControl(QByteArray buffer)
{
ChannelState ch1=ChannelState(static_cast<uint8_t>(buffer.data()[3]));
ChannelState ch2=ChannelState(static_cast<uint8_t>(buffer.data()[4]));
ChannelState ch3=ChannelState(static_cast<uint8_t>(buffer.data()[5]));
ChannelState ch4=ChannelState(static_cast<uint8_t>(buffer.data()[6]));
emit channalControlRev(ch1,ch2,ch3,ch4);
}
void CODECXyckAnalog::respSetCurrent(QByteArray buffer)
{
int iChannel=buffer.data()[3];
int iCurrent=static_cast<uint8_t>(buffer.data()[4]);
emit currentRev(iChannel,iCurrent);
}
void CODECXyckAnalog::respDataUpload(QByteArray buffer)
{
ignoreCount++;
MyoelectricData md;
md.ch1=(static_cast<uint8_t>(buffer.data()[4])<<8)+static_cast<uint8_t>(buffer.data()[5]);
md.ch2=(static_cast<uint8_t>(buffer.data()[6])<<8)+static_cast<uint8_t>(buffer.data()[7]);
md.ch3=(static_cast<uint8_t>(buffer.data()[8])<<8)+static_cast<uint8_t>(buffer.data()[9]);
md.ch4=(static_cast<uint8_t>(buffer.data()[10])<<8)+static_cast<uint8_t>(buffer.data()[11]);
QString logTemp=QString::number(md.ch1)+" "+QString::number(md.ch2)+" "+QString::number(md.ch3)+" "+QString::number(md.ch4)+"\r\n";
logFile->write(logTemp.toUtf8());
logFile->flush();
// if(ignoreCount%100==0)
// {
// qDebug()<<QString::number(ignoreCount);
// qDebug()<<"ch1:"<<QString::number(md.ch1)<<"ch2:"<<QString::number(md.ch2)<<"ch3:"<<QString::number(md.ch3)<<"ch4:"<<QString::number(md.ch4);
// }
_dataList->append(md);
//qDebug()<<QString::number(md.ch1);
}
void CODECXyckAnalog::respDataChange(QByteArray buffer)
{
int iChannel=static_cast<uint8_t>(buffer.data()[3]);
DataMode dm=DataMode(static_cast<uint8_t>(buffer.data()[4]));
ignoreCount=0;
emit dataChangeRev(iChannel,dm);
}
void CODECXyckAnalog::respSetGain(QByteArray buffer)
{
int iChannel=static_cast<uint8_t>(buffer.data()[3]);
GainMode gm=GainMode(static_cast<uint8_t>(buffer.data()[4]));
emit gainRev(iChannel,gm);
}
void CODECXyckAnalog::respSetCollect(QByteArray buffer)
{
int iChannel=static_cast<uint8_t>(buffer.data()[3]);
ChannelState cs=ChannelState(static_cast<uint8_t>(buffer.data()[4]));
emit collectRev(iChannel,cs);
}
void CODECXyckAnalog::respSetStimulate(QByteArray buffer)
{
int iChannel=static_cast<uint8_t>(buffer.data()[3]);
ChannelState cs=ChannelState(static_cast<uint8_t>(buffer.data()[4]));
emit stimulateRev(iChannel,cs);
}
void CODECXyckAnalog::respGetState(QByteArray buffer)
{
AnalogState *analogstate = new AnalogState();
analogstate->electrodeStateA=ModeState(static_cast<uint8_t>(buffer.data()[4]));
analogstate->electrodeStateB=ModeState(static_cast<uint8_t>(buffer.data()[5]));
analogstate->electrodeStateC=ModeState(static_cast<uint8_t>(buffer.data()[6]));
analogstate->electrodeStateD=ModeState(static_cast<uint8_t>(buffer.data()[7]));
analogstate->resetState=ModeState(static_cast<uint8_t>(buffer.data()[8]));
analogstate->channelWorkStateA=ChannelWorkState(static_cast<uint8_t>(buffer.data()[9]));
analogstate->channelWorkStateB=ChannelWorkState(static_cast<uint8_t>(buffer.data()[10]));
analogstate->channelWorkStateC=ChannelWorkState(static_cast<uint8_t>(buffer.data()[11]));
analogstate->channelWorkStateD=ChannelWorkState(static_cast<uint8_t>(buffer.data()[12]));
analogstate->AValueA=static_cast<uint8_t>(buffer.data()[13]);
analogstate->AValueB=static_cast<uint8_t>(buffer.data()[14]);
analogstate->AValueC=static_cast<uint8_t>(buffer.data()[15]);
analogstate->AValueD=static_cast<uint8_t>(buffer.data()[16]);
emit stateInfoRev(analogstate);
}
QByteArray CODECXyckAnalog::createFrame(QByteArray dataBuffer)
{
QByteArray buffer;
buffer.append(static_cast<char>(FRAME_HEAD));
buffer.append(static_cast<char>(dataBuffer.length()));
for(int i=0;i<dataBuffer.length();i++)
{
buffer.append(dataBuffer.data()[i]);
}
buffer.append(DataCheck::getSum(buffer,2,buffer.length()-1));
buffer.append(0x55);
return buffer;
}

View File

@ -0,0 +1,87 @@
#ifndef CODECXYCKANALOG_H
#define CODECXYCKANALOG_H
#include <QObject>
#include <QByteArray>
#include <QList>
#include <QDebug>
#include <QFile>
#include "XYComFunc_global.h"
//#include "CommomFunc/datacheck.h"
#include "commonStruct.h"
/**
* @brief
*/
class XYCOMFUNC_EXPORT CODECXyckAnalog :public QObject
{
Q_OBJECT
public:
/**
* @brief
*/
CODECXyckAnalog();
/**
* @brief
* @param
* @param
* @return
*/
QByteArray reqSetting(int iChannel ,AnalogSetting setting);
QByteArray reqChannalControl(ChannelState ch1,ChannelState ch2,ChannelState ch3,ChannelState ch4);
QByteArray reqSetCurrent(int iChannel,int iCurrent);
QByteArray reqDataChange(int iChannel,DataMode datamode);
QByteArray reqSetGain(int iChannel,GainMode gainmode);
QByteArray reqSetCollect(int iChannel,ChannelState channelstate);
QByteArray reqSetStimulate(int iChannel,ChannelState channelstate);
QByteArray reqGetState();
void dealFrame(QByteArray buffer);
void clearList();
QList<MyoelectricData> *GetMyoelectricData(int iStep=0);
//以下仅测试适用,实际由下位机发送
QByteArray respAnalogState(AnalogState *as);
QByteArray respMyoelectricData(MyoelectricData *md);
signals:
void commandSendError(int iChannel,ErrorCode errorcode,int iFunctionCode);
void analogSettingRev(int iChannel,AnalogSetting *analogsetting);
void channalControlRev(ChannelState ch1,ChannelState ch2,ChannelState ch3,ChannelState ch4);
void currentRev(int iChannel,int iCurrent);
void dataChangeRev(int iChannel,DataMode datamode);
void gainRev(int iChannel,GainMode gainmode);
void collectRev(int iChannel,ChannelState channelstate);
void stimulateRev(int iChannel,ChannelState channelstate);
void stateInfoRev(AnalogState *analogstate);
private:
void respSetting(QByteArray buffer);
void respChannalControl(QByteArray buffer);
void respSetCurrent(QByteArray buffer);
void respDataUpload(QByteArray buffer);
void respDataChange(QByteArray buffer);
void respSetGain(QByteArray buffer);
void respSetCollect(QByteArray buffer);
void respSetStimulate(QByteArray buffer);
void respGetState(QByteArray buffer);
QByteArray createFrame(QByteArray dataBuffer);
private:
QList<MyoelectricData> *_dataList;
int iii ;
int ignoreCount=0;
QFile *logFile;
};
#endif // CODECXYCKANALOG_H

View File

@ -0,0 +1,180 @@
#include "codecxyckdigital.h"
CODECXyckDigital::CODECXyckDigital()
: QObject()
{
}
QByteArray CODECXyckDigital::reqGetInfo()
{
QByteArray buffer;
buffer.append(static_cast<char>(FUNCCODE_DIGITAL_GET_INFO));
buffer.append(static_cast<char>(0x00));
buffer.append(static_cast<char>(0x00));
return createFrame(buffer);
}
QByteArray CODECXyckDigital::reqControl(int iChannel, LightState lightstate)
{
QByteArray buffer;
buffer.append(static_cast<char>(FUNCCODE_DIGITAL_CONTROL));
buffer.append(static_cast<char>(iChannel));
buffer.append(static_cast<char>(lightstate));
return createFrame(buffer);
}
QByteArray CODECXyckDigital::reqPreconditioning(int iChannel, ModeState modestate)
{
qDebug()<<"预设电流: Channel:"<<QString::number(iChannel)<<" Mode:"<<modestate;
QByteArray buffer;
buffer.append(static_cast<char>(FUNCCODE_DIGITAL_PRECONDITIONING));
buffer.append(static_cast<char>(iChannel));
buffer.append(static_cast<char>(modestate));
return createFrame(buffer);
}
QByteArray CODECXyckDigital::resqPowoff(PowState powstate)
{
QByteArray buffer;
buffer.append(static_cast<char>(FUNCCODE_DIGITAL_POWOFF));
buffer.append(static_cast<char>(0x00));
buffer.append(static_cast<char>(powstate));
return createFrame(buffer);
}
QByteArray CODECXyckDigital::reqUpdateA(int iChannel, int AValue)
{
QByteArray buffer;
buffer.append(static_cast<char>(FUNCCODE_DIGITAL_UPDATE_A));
buffer.append(static_cast<char>(iChannel));
buffer.append(static_cast<char>(AValue));
return createFrame(buffer);
}
QByteArray CODECXyckDigital::reqPowOn(ModeState state)
{
QByteArray buffer;
buffer.append(static_cast<char>(FUNCCODE_DIGITAL_POWON));
buffer.append(static_cast<char>(0x00));
buffer.append(static_cast<char>(state));
return createFrame(buffer);
}
void CODECXyckDigital::dealFrame(QByteArray buffer)
{
switch (static_cast<uint8_t>(buffer.data()[2]))
{
case FUNCCODE_DIGITAL_GET_INFO:
respGetInfo(buffer);
break;
case FUNCCODE_DIGITAL_CONTROL:
respControl(buffer);
break;
case FUNCCODE_DIGITAL_PRECONDITIONING:
resqPreconditioning(buffer);
break;
case FUNCCODE_DIGITAL_POWOFF:
reqPowoff();
break;
case FUNCCODE_DIGITAL_UPDATE_A:
resqUpdateA(buffer);
break;
case FUNCCODE_DIGITAL_ERROR:
emit commandSendError(static_cast<uint8_t>(buffer.data()[3])
,ErrorCode(static_cast<uint8_t>(buffer.data()[4]))
,static_cast<uint8_t>(buffer.data()[5]));
break;
default:
emit frameError(ErrorCode::ErrorFuncCode,createError(0,buffer.data()[3],ErrorCode::ErrorFuncCode));
break;
}
}
QByteArray CODECXyckDigital::respDigitalInfo(DigitalInfo *di)
{
QByteArray buffer;
buffer.append(static_cast<char>(FUNCCODE_DIGITAL_GET_INFO));
buffer.append(static_cast<char>(0x00));
buffer.append(static_cast<char>(di->adapterState));
buffer.append(static_cast<char>(di->batteryState));
buffer.append(static_cast<char>(di->reset));
buffer.append(static_cast<char>(di->AChannelA));
buffer.append(static_cast<char>(di->AChannelB));
buffer.append(static_cast<char>(di->AChannelC));
buffer.append(static_cast<char>(di->AChannelD));
buffer.append(static_cast<char>(0));
buffer.append(static_cast<char>(0));
return createFrame(buffer);
}
void CODECXyckDigital::respGetInfo(QByteArray buffer)
{
DigitalInfo *di= new DigitalInfo();
di->adapterState=static_cast<uint8_t>(buffer.data()[4]);
di->batteryState=static_cast<uint8_t>(buffer.data()[5]);
di->reset=static_cast<uint8_t>(buffer.data()[6]);
di->AChannelA=static_cast<uint8_t>(buffer.data()[7]);
di->AChannelB=static_cast<uint8_t>(buffer.data()[8]);
di->AChannelC=static_cast<uint8_t>(buffer.data()[9]);
di->AChannelD=static_cast<uint8_t>(buffer.data()[10]);
//qDebug()<<"AChannelA:"<<QString::number(di->AChannelA)<<"AChannelB:"<<QString::number(di->AChannelB)<<"AChannelC:"<<QString::number(di->AChannelC)<<"AChannelD:"<<QString::number(di->AChannelD);
emit digitalInfoRev(di);
}
void CODECXyckDigital::respControl(QByteArray buffer)
{
LightState ls=LightState(static_cast<uint8_t>(buffer.data()[4]));
emit controlRespond(static_cast<uint8_t>(buffer.data()[3]),ls);
}
void CODECXyckDigital::resqPreconditioning(QByteArray buffer)
{
emit preconditioningRespond(static_cast<uint8_t>(buffer.data()[3]),ModeState(static_cast<uint8_t>(buffer.data()[4])));
}
void CODECXyckDigital::reqPowoff()
{
emit powOffCommandRev();
}
void CODECXyckDigital::resqUpdateA(QByteArray buffer)
{
emit AUpdated(static_cast<uint8_t>(buffer.data()[3]),ModeState(static_cast<uint8_t>(buffer.data()[4])));
}
void CODECXyckDigital::resqPowOn(QByteArray buffer)
{
emit PowOn(ModeState(static_cast<uint8_t>(buffer.data()[4])));
}
QByteArray CODECXyckDigital::createFrame(QByteArray dataBuffer)
{
QByteArray buffer;
buffer.append(static_cast<char>(FRAME_HEAD));
buffer.append(static_cast<char>(dataBuffer.length()));
for(int i=0;i<dataBuffer.length();i++)
{
buffer.append(dataBuffer.data()[i]);
}
buffer.append(DataCheck::getSum(buffer,2,buffer.length()-1));
buffer.append(0x55);
return buffer;
}
QByteArray CODECXyckDigital::createError(int iFuncCode, int iChannel, ErrorCode errcode)
{
QByteArray buffer;
buffer.append(static_cast<char>(0x8F));
buffer.append(static_cast<char>(iChannel));
buffer.append(static_cast<char>(iFuncCode));
buffer.append(static_cast<char>(errcode));
return buffer;
}

View File

@ -0,0 +1,142 @@
#ifndef CODECXYCKDIGITAL_H
#define CODECXYCKDIGITAL_H
#include <QObject>
#include <QByteArray>
#include <QDebug>
#include "XYComFunc_global.h"
#include "CommomFunc/datacheck.h"
#include "commonStruct.h"
class XYCOMFUNC_EXPORT CODECXyckDigital : public QObject
{
Q_OBJECT
public:
CODECXyckDigital();
/**
* @brief
* @return
*/
QByteArray reqGetInfo();
/**
* @brief
* @return
*/
QByteArray reqControl(int iChannel,LightState lightstate);
/**
* @brief
* @return
*/
QByteArray reqPreconditioning(int iChannel,ModeState modestate);
/**
* @brief
* @param powstate
* @return
*/
QByteArray resqPowoff(PowState powstate);
/**
* @brief
* @param buffer
*/
void dealFrame(QByteArray buffer);
QByteArray reqUpdateA(int iChannel,int AValue);
QByteArray reqPowOn(ModeState state);
//以下方法仅仅用于测试
QByteArray respDigitalInfo(DigitalInfo *di);
private:
/**
* @brief
* @param buffer
*/
void respGetInfo(QByteArray buffer);
/**
* @brief
* @param buffer
*/
void respControl(QByteArray buffer);
/**
* @brief
* @param buffer
*/
void resqPreconditioning(QByteArray buffer);
/**
* @brief
*/
void reqPowoff();
/**
* @brief
* @param buffer
*/
void resqError(QByteArray buffer);
void resqUpdateA(QByteArray buffer);
void resqPowOn(QByteArray buffer);
/**
* @brief
* @param
* @return
*/
QByteArray createFrame(QByteArray dataBuffer);
/**
* @brief
* @param iFuncCode
* @param iChannel
* @param errcode
* @return
*/
QByteArray createError(int iFuncCode,int iChannel,ErrorCode errcode);
signals:
void commandSendError(int iChannel,ErrorCode errorcode,int iFunctionCode);
/**
* @brief
* @param errorcode
* @param errBuffer
*/
void frameError(ErrorCode errorcode,QByteArray errBuffer=nullptr);
/**
* @brief
* @param di
*/
void digitalInfoRev(DigitalInfo *di);
/**
* @brief
*/
void powOffCommandRev();
/**
* @brief
* @param iChannel
* @param lightstate
*/
void controlRespond(int iChannel,LightState lightstate);
/**
* @brief
* @param iChannel
* @param modestate
*/
void preconditioningRespond(int iChannel,ModeState modestate);
void AUpdated(int iChannel,int AValue);
void PowOn(ModeState powOnState);
public slots:
};
#endif // CODECXYCKDIGITAL_H

View File

@ -0,0 +1,102 @@
#include "gameclient.h"
GameClient::GameClient() : TcpClientEquipment()
{
}
bool GameClient::setValue(int iValue)
{
QByteArray buffer;
buffer.resize(0);
buffer[0]=static_cast<u_int8_t>(iValue%0xff);
buffer[1]=static_cast<u_int8_t>(iValue>>8);
return this->sendMsg(buffer);
}
bool GameClient::IsReady()
{
return IsReady();
}
void GameClient::sendReady()
{
sendMsg(readyCheckString);
}
void GameClient::sendStart()
{
sendMsg(gameStartString);
}
void GameClient::sendStop()
{
sendMsg(gameStopString);
}
void GameClient::sendLevelHard()
{
sendMsg(gameLevelHard);
}
void GameClient::sendLevelMiddle()
{
sendMsg(gameLevelMiddle);
}
void GameClient::sendLevelEasy()
{
sendMsg(gameLevelEasy);
}
void GameClient::sendScore(int iValue)
{
sendMsg(gameScore+"|"+QString::number(iValue));
}
void GameClient::onDataReceived()
{
QByteArray revBuffer=this->mClient->readAll();
QString strTempBuffer=QString(revBuffer);
if(strTempBuffer.contains("|"))
{
QStringList list=strTempBuffer.split('|');
for (int i=0;i<list.count();i++) {
emit valueReceived(list.at(i).toInt());
}
}
if(strTempBuffer.contains(readyCheckString))
{
emit allReady();
}
if(strTempBuffer.contains(gameLevelEasy))
{
emit gameLevel(GAME_LEVEL_EASY);
}
if(strTempBuffer.contains(gameLevelMiddle))
{
emit gameLevel(GAME_LEVEL_NORMAL);
}
if(strTempBuffer.contains(gameLevelHard))
{
emit gameLevel(GAME_LEVEL_HARD);
}
if(strTempBuffer.contains(gameStartString))
{
emit gameStatus(GAME_STATUS_START);
}
if(strTempBuffer.contains(gameStopString))
{
emit gameStatus(GAME_STATUS_STOP);
}
if(strTempBuffer.contains(gamePauseString))
{
emit gameStatus(GAME_STATUS_PAUSE);
}
if(strTempBuffer.contains(gameContinueString))
{
emit gameStatus(GAME_STATUS_RESUME);
}
}

View File

@ -0,0 +1,48 @@
#ifndef GAMECLIENT_H
#define GAMECLIENT_H
#include <QObject>
#include <QByteArray>
#include "equipmentLib/tcpclientequipment.h"
#include "XYComFunc_global.h"
#include "commonStruct.h"
//游戏通讯客户端类,连接游戏服务器,握手确定就绪,发送游戏数据
class XYCOMFUNC_EXPORT GameClient : public TcpClientEquipment
{
Q_OBJECT
public:
GameClient();
Q_INVOKABLE bool setValue(int iValue);
Q_INVOKABLE bool IsReady();
Q_INVOKABLE void sendReady();
Q_INVOKABLE void sendStart();
Q_INVOKABLE void sendStop();
Q_INVOKABLE void sendLevelHard();
Q_INVOKABLE void sendLevelMiddle();
Q_INVOKABLE void sendLevelEasy();
Q_INVOKABLE void sendScore(int iValue);
signals:
void valueReceived(int iValue);
void allReady();
void gameLevel(GameLevel level);
void gameStatus(GameStatus status);
public slots:
void onDataReceived() override;
private:
bool isReady;
const QString readyCheckString="XYYLGameReady";
const QString gameStartString="XYYLGameStart";
const QString gameStopString="XYYLGameStop";
const QString gamePauseString="XYYLGamePause";
const QString gameContinueString="XYYLGameContinue";
const QString gameLevelHard="XYYLLevelHard";
const QString gameLevelMiddle="XYYLLevelMiddle";
const QString gameLevelEasy="XYYLLevelEasy";
const QString gameScore="XYYLGameScore";
};
#endif // GAMECLIENT_H

View File

@ -0,0 +1,115 @@
#include "gameserver.h"
GameServer::GameServer() : TcpEquipment()
{
}
void GameServer::sendValue(int value)
{
QString tempBuffer=QString::number(value);
tempBuffer+="|";
send2All(tempBuffer);
}
bool GameServer::IsReady()
{
return isReady;
}
void GameServer::sendLevel(GameLevel level)
{
switch (level)
{
case GameLevel::GAME_LEVEL_EASY:
send2All(gameLevelEasy);
break;
case GameLevel::GAME_LEVEL_NORMAL:
send2All(gameLevelMiddle);
break;
case GameLevel::GAME_LEVEL_HARD:
send2All(gameLevelHard);
break;
default:
send2All(gameLevelEasy);
break;
}
}
void GameServer::sendLevel(int level)
{
sendLevel(static_cast<GameLevel>(level));
}
void GameServer::sendStart()
{
sendStatus(GameStatus::GAME_STATUS_START);
}
void GameServer::sendPause()
{
sendStatus(GameStatus::GAME_STATUS_PAUSE);
}
void GameServer::sendContinue()
{
sendStatus(GameStatus::GAME_STATUS_RESUME);
}
void GameServer::sendStop()
{
sendStatus(GameStatus::GAME_STATUS_STOP);
}
void GameServer::dealRev(QString strIP, int iPort, QByteArray buffer)
{
Q_UNUSED(iPort);
QString tempBufferString=QString(buffer);
if(tempBufferString==readyCheckString){
send2One(readyCheckString,strIP);
}
else if(tempBufferString==gameStartString){
emit gameStartReceived(strIP,iPort);
}
else if(tempBufferString==gameStopString){
emit gameStopReceived(strIP,iPort);
}
else if(tempBufferString==gameLevelEasy){
emit gameLevelSet(0);
}
else if(tempBufferString==gameLevelMiddle){
emit gameLevelSet(1);
}
else if(tempBufferString==gameLevelHard){
emit gameLevelSet(2);
}
else if(tempBufferString.contains(gameScore)){
QStringList tempList = tempBufferString.split('|');
if(tempList.count()==2){
emit gameScoreReceived(tempList.at(1).toInt());
}
}
}
void GameServer::sendStatus(GameStatus status)
{
switch (status)
{
case GameStatus::GAME_STATUS_STOP:
send2All(gameStopString);
break;
case GameStatus::GAME_STATUS_PAUSE:
send2All(gamePauseString);
break;
case GameStatus::GAME_STATUS_START:
send2All(gameStartString);
break;
case GameStatus::GAME_STATUS_RESUME:
send2All(gameContinueString);
break;
}
}

View File

@ -0,0 +1,52 @@
#ifndef GAMESERVER_H
#define GAMESERVER_H
#include <QObject>
#include <QByteArray>
#include <QString>
#include <QStringList>
#include "equipmentLib/tcpequipment.h"
#include "XYComFunc_global.h"
#include "commonStruct.h"
//游戏服务器类,等待游戏连入,进行握手,等待游戏就绪,向游戏发送数据
class XYCOMFUNC_EXPORT GameServer : public TcpEquipment
{
Q_OBJECT
public:
GameServer();
Q_INVOKABLE void sendValue(int value);
Q_INVOKABLE bool IsReady();
Q_INVOKABLE void sendLevel(GameLevel level);
Q_INVOKABLE void sendLevel(int level);
Q_INVOKABLE void sendStart();
Q_INVOKABLE void sendPause();
Q_INVOKABLE void sendContinue();
Q_INVOKABLE void sendStop();
private:
void dealRev(QString strIP,int iPort,QByteArray buffer) override;
void sendStatus(GameStatus status);
signals:
void gameStartReceived(QString strIP,int iPort);
void gameStopReceived(QString strIP,int iPort);
void gameLevelSet(int iLevel);
void gameScoreReceived(int iScore);
public slots:
private:
bool isReady;
const QString readyCheckString="XYYLGameReady";
const QString gameStartString="XYYLGameStart";
const QString gameStopString="XYYLGameStop";
const QString gamePauseString="XYYLGamePause";
const QString gameContinueString="XYYLGameContinue";
const QString gameLevelHard="XYYLLevelHard";
const QString gameLevelMiddle="XYYLLevelMiddle";
const QString gameLevelEasy="XYYLLevelEasy";
const QString gameScore="XYYLGameScore";
};
#endif // GAMESERVER_H

View File

@ -0,0 +1,92 @@
#include "selectcomport.h"
selectComPort::selectComPort(QObject *parent,int iDiBaudRate,int iMNBaudRate) : QThread(parent)
{
this->diBaudRate=iDiBaudRate;
this->mnBaudRate=iMNBaudRate;
this->isFinish=false;
}
selectComPort::selectComPort(int iDiBaudRate, int iMNBaudRate) :QThread()
{
this->diBaudRate=iDiBaudRate;
this->mnBaudRate=iMNBaudRate;
this->isFinish=false;
}
void selectComPort::run()
{
QList<QString> comList=SerialEquipment::getAllPorts();
QString strComDi;
QString strComMN;
for (int i=0;i<comList.length();i++) {
qDebug()<<comList.at(i);
XYCKDigitalBoard testDI(comList.at(i),static_cast<QSerialPort::BaudRate>(this->diBaudRate));
if(testDI.connectPort()){
//testDI.startTest();
int j=10;
while(j>0){
testDI.startTest();
if(testDI.getTestConnectSuccess()){
strComDi=comList.at(i);
QThread::msleep(500);
testDI.reqPowOn(ModeState::ModeOut);
QThread::msleep(500);
testDI.reqPowOn(ModeState::ModeIn);
QThread::msleep(500);
break;
}
else{
QThread::msleep(10);
}
j--;
}
testDI.closePort();
if(!strComDi.isEmpty()){
break;
}
}
}
for (int i=0;i<comList.count();i++) {
if(comList.at(i)==strComDi){
continue;
}
XYCKAnalogBoard testMN(comList.at(i),static_cast<QSerialPort::BaudRate>(this->mnBaudRate));
qDebug()<<comList.at(i);
if(testMN.connectPort()){
// testMN.startTest();
int j=10;
while(j>0){
testMN.startTest();
if(testMN.getTestConnectSuccess()){
strComMN=comList.at(i);
break;
}
else{
QThread::msleep(10);
}
j--;
}
testMN.closePort();
if(!strComMN.isEmpty()){
break;
}
}
}
if(!strComDi.isEmpty()){
XYCKDigitalBoard testDI1(strComDi,static_cast<QSerialPort::BaudRate>(this->diBaudRate));
if(testDI1.connectPort()){
QThread::msleep(1000);
testDI1.reqPowOn(ModeState::ModeOut);
testDI1.closePort();
}
}
qDebug()<<"数字板:"<<strComDi;
qDebug()<<"模拟板:"<<strComMN;
this->diPort=strComDi;
this->mnPort=strComMN;
isFinish=true;
emit comPortSelected(strComDi,strComMN);
}

View File

@ -0,0 +1,42 @@
#ifndef SELECTCOMPORT_H
#define SELECTCOMPORT_H
#include <QObject>
#include <QThread>
#include <QString>
#include <QList>
#include <QDebug>
#include "equipmentLib/XY-CK-SerialPort/xyckanalogboard.h"
#include "equipmentLib/XY-CK-SerialPort/xyckdigitalboard.h"
#include "XYComFunc_global.h"
class XYCOMFUNC_EXPORT selectComPort : public QThread
{
Q_OBJECT
public:
selectComPort(QObject *parent = nullptr,int iDiBaudRate=115200,int iMNBaudRate=115200);
selectComPort(int iDiBaudRate=115200,int iMNBaudRate=115200);
signals:
void comPortSelected(QString comDi,QString comMN);
protected:
virtual void run();
public:
bool isFinish;
QString diPort;
QString mnPort;
public slots:
private:
int diBaudRate;
int mnBaudRate;
};
#endif // SELECTCOMPORT_H

View File

@ -0,0 +1,362 @@
#include "xyckanalogboard.h"
XYCKAnalogBoard::XYCKAnalogBoard()
: SerialEquipment()
{
initCodec();
}
XYCKAnalogBoard::XYCKAnalogBoard(QString portName, QSerialPort::BaudRate baunRate, QSerialPort::DataBits dataBits, QSerialPort::Parity parity, QSerialPort::StopBits stopBits, int readBufferSize)
: SerialEquipment(portName,baunRate,dataBits,parity,stopBits,readBufferSize)
{
initCodec();
}
XYCKAnalogBoard::XYCKAnalogBoard(QString portName)
: SerialEquipment(portName)
{
initCodec();
}
XYCKAnalogBoard::XYCKAnalogBoard(QString portName, QSerialPort::BaudRate baunRate)
: SerialEquipment(portName,baunRate)
{
initCodec();
}
bool XYCKAnalogBoard::reqSetting(int iChannel, AnalogSetting setting)
{
return sendMsg(_codec->reqSetting(iChannel,setting));
}
bool XYCKAnalogBoard::reqChannalControl(ChannelState ch1, ChannelState ch2, ChannelState ch3, ChannelState ch4)
{
return sendMsg(_codec->reqChannalControl(ch1,ch2,ch3,ch4));
}
bool XYCKAnalogBoard::reqChannalControl(int ch1, int ch2, int ch3, int ch4)
{
//qDebug()<<"reqChannalControl";
return sendMsg(_codec->reqChannalControl((ChannelState)ch1,(ChannelState)ch2,(ChannelState)ch3,(ChannelState)ch4));
}
qreal XYCKAnalogBoard::getIniInfo(int Channel, QString strValueType)
{
QSettings configIni("config.ini",QSettings::IniFormat);
return configIni.value("/"+QString::number(Channel)+"/"+strValueType).toDouble();
}
void XYCKAnalogBoard::setIniInfo(int Channel, QString strValueType, qreal rValue)
{
QSettings configIni("config.ini",QSettings::IniFormat);
configIni.setValue("/"+QString::number(Channel)+"/"+strValueType,rValue);
return;
}
void XYCKAnalogBoard::clearList()
{
_codec->clearList();
}
QString XYCKAnalogBoard::getCountLog()
{
if(this->testJDCount==0){
bTestDebug=true;
}
else {
bTestDebug=false;
}
QString strLog="JDCount:"+QString::number(this->testJDCount)+"Total:"+QString::number(this->testTotalCount);
this->testJDCount=0;
this->testTotalCount=0;
return strLog;
}
bool XYCKAnalogBoard::reqSetCurrent(int iChannel, int iCurrent)
{
//qDebug()<<"set MN A CHannl:"<<QString::number(iChannel)<<",A Value:"<<QString::number(iCurrent);
return sendMsg(_codec->reqSetCurrent(iChannel,iCurrent));
}
bool XYCKAnalogBoard::reqDataChange(int iChannel, DataMode datamode)
{
return sendMsg(_codec->reqDataChange(iChannel,datamode));
}
bool XYCKAnalogBoard::reqDataChange(int iChannel, int datamode)
{
return sendMsg(_codec->reqDataChange(iChannel,(DataMode)datamode));
}
bool XYCKAnalogBoard::reqSetGain(int iChannel, GainMode gainmode)
{
return sendMsg(_codec->reqSetGain(iChannel,gainmode));
}
bool XYCKAnalogBoard::reqSetGain(int iChannel, int gainmode)
{
return sendMsg(_codec->reqSetGain(iChannel,(GainMode)gainmode));
}
bool XYCKAnalogBoard::reqSetCollect(int iChannel, ChannelState channelstate)
{
return sendMsg(_codec->reqSetCollect(iChannel,channelstate));
}
bool XYCKAnalogBoard::reqSetCollect(int iChannel, int channelstate)
{
return sendMsg(_codec->reqSetCollect(iChannel,(ChannelState)channelstate));
}
bool XYCKAnalogBoard::reqSetStimulate(int iChannel, ChannelState channelstate)
{
return sendMsg(_codec->reqSetStimulate(iChannel,channelstate));
}
bool XYCKAnalogBoard::reqSetStimulate(int iChannel, int channelstate)
{
return sendMsg(_codec->reqSetStimulate(iChannel,(ChannelState)channelstate));
}
bool XYCKAnalogBoard::reqGetState()
{
return sendMsg(_codec->reqGetState());
}
int XYCKAnalogBoard::getInfo()
{
return 11;
}
void XYCKAnalogBoard::setInfo(QString portName, int baunRate)
{
this->setSerialInfo(portName,(QSerialPort::BaudRate)baunRate);
}
//void XYCKAnalogBoard::setInfo(QString portName)
//{
// this->setSerialInfo(portName,QSerialPort::Baud1152000);
//}
bool XYCKAnalogBoard::connectPort()
{
if(this->getPortState())
{
return true;
}
else
{
return this->openPort();
}
}
bool XYCKAnalogBoard::disConnectPort()
{
if(this->getPortState())
{
return this->closePort();
}
else
{
return true;
}
}
bool XYCKAnalogBoard::getConnectState()
{
return this->getPortState();
}
bool XYCKAnalogBoard::reqSetting(int iChannel, int workMode, int samplerate, qreal frequency, int pulseWidth, qreal risingtime,int breaktime,qreal fallingtime,int holdingtime)
{
AnalogSetting tempSetting;
tempSetting.workmode=(WorkMode)workMode;
tempSetting.samplerate=(SampleRate)samplerate;
tempSetting.frequency=frequency;
tempSetting.pulseWidth=pulseWidth;
tempSetting.risingTime=risingtime;
tempSetting.breakTime=breaktime;
tempSetting.fallingTime=fallingtime;
tempSetting.holdingTime=holdingtime;
//qDebug()<<"send";
return reqSetting(iChannel,tempSetting);
}
QList<MyoelectricData> *XYCKAnalogBoard::getMyoelectricData(int iStep)
{
return _codec->GetMyoelectricData(iStep);
}
QVariantList XYCKAnalogBoard::getMyoelectricDataQml(int iStep)
{
QList<MyoelectricData> *list=getMyoelectricData(iStep);
QVariantList returnList;
if(list==nullptr)
{
return returnList;
}
for(int i=0;i<list->length();i++)
{
returnList.append(list->at(i).ch1);
returnList.append(list->at(i).ch2);
returnList.append(list->at(i).ch3);
returnList.append(list->at(i).ch4);
}
delete list;
list=nullptr;
return returnList;
}
//QList<int> XYCKAnalogBoard::GetMyoelectricDataIntArray()
//{
// QList<int> array;
// for(int i=0;i<0;i++)
// {
// array.append(i);
// }
// return array;
//}
//QList<int> XYCKAnalogBoard::m_info()
//{
// QList<int> array;
// for(int i=0;i<0;i++)
// {
// array.append(i);
// }
// return array;
//}
//QQmlListProperty<MyoelectricData> XYCKAnalogBoard::datalist()
//{
// m_dataList.clear();
// MyoelectricData* test=new MyoelectricData();
// test->ch1=1;
// test->ch2=2;
// test->ch3=3;
// test->ch4=4;
// return QQmlListProperty<MyoelectricData>(this,m_dataList);
//}
void XYCKAnalogBoard::OnCommandSendErrorRev(int iChannel, ErrorCode errorcode, int iFunctionCode)
{
emit commandSendError(iChannel,errorcode,iFunctionCode);
}
void XYCKAnalogBoard::OnAnalogSettingRev(int iChannel, AnalogSetting *analogsetting)
{
emit analogSettingRev(iChannel,analogsetting);
}
void XYCKAnalogBoard::OnChannalControlRev(ChannelState ch1, ChannelState ch2, ChannelState ch3, ChannelState ch4)
{
emit channalControlRev(ch1,ch2,ch3,ch4);
}
void XYCKAnalogBoard::OnCurrentRev(int iChannel, int iCurrent)
{
emit currentRev(iChannel,iCurrent);
}
void XYCKAnalogBoard::OnDataChangeRev(int iChannel, DataMode datamode)
{
emit dataChangeRev(iChannel,datamode);
}
void XYCKAnalogBoard::OnGainRev(int iChannel, GainMode gainmode)
{
emit gainRev(iChannel,gainmode);
}
void XYCKAnalogBoard::OnCollectRev(int iChannel, ChannelState channelstate)
{
emit collectRev(iChannel,channelstate);
}
void XYCKAnalogBoard::OnStimulateRev(int iChannel, ChannelState channelstate)
{
emit stimulateRev(iChannel,channelstate);
}
void XYCKAnalogBoard::OnStateInfoRev(AnalogState *analogstate)
{
//qDebug()<<"received";
if(this->testStart){
this->testConnectSuccess=true;
}
QVariantMap stateMap;
stateMap.insert("resetState",analogstate->resetState);
stateMap.insert("electrodeStateA",analogstate->electrodeStateA);
stateMap.insert("electrodeStateB",analogstate->electrodeStateB);
stateMap.insert("electrodeStateC",analogstate->electrodeStateC);
stateMap.insert("electrodeStateD",analogstate->electrodeStateD);
stateMap.insert("channelWorkStateA",analogstate->channelWorkStateA);
stateMap.insert("channelWorkStateB",analogstate->channelWorkStateB);
stateMap.insert("channelWorkStateC",analogstate->channelWorkStateC);
stateMap.insert("channelWorkStateD",analogstate->channelWorkStateD);
stateMap.insert("AValueA",analogstate->AValueA);
stateMap.insert("AValueB",analogstate->AValueB);
stateMap.insert("AValueC",analogstate->AValueC);
stateMap.insert("AValueD",analogstate->AValueD);
emit stateInfoRev(stateMap);
}
void XYCKAnalogBoard::initCodec()
{
_codec=new CODECXyckAnalog();
connect(_codec,&CODECXyckAnalog::analogSettingRev,this,&XYCKAnalogBoard::OnAnalogSettingRev);
connect(_codec,&CODECXyckAnalog::channalControlRev,this,&XYCKAnalogBoard::OnChannalControlRev);
connect(_codec,&CODECXyckAnalog::currentRev,this,&XYCKAnalogBoard::OnCurrentRev);
connect(_codec,&CODECXyckAnalog::dataChangeRev,this,&XYCKAnalogBoard::OnDataChangeRev);
connect(_codec,&CODECXyckAnalog::gainRev,this,&XYCKAnalogBoard::OnGainRev);
connect(_codec,&CODECXyckAnalog::collectRev,this,&XYCKAnalogBoard::OnCollectRev);
connect(_codec,&CODECXyckAnalog::stimulateRev,this,&XYCKAnalogBoard::OnStimulateRev);
connect(_codec,&CODECXyckAnalog::stateInfoRev,this,&XYCKAnalogBoard::OnStateInfoRev);
connect(_codec,&CODECXyckAnalog::commandSendError,this,&XYCKAnalogBoard::OnCommandSendErrorRev);
this->_frameHead.clear();
this->_frameHead.append(static_cast<char>(0xaa));
this->_frameTail.clear();
this->_frameTail.append(0x55);
setLogInfo(true);
this->testStart=true;
this->testConnectSuccess=false;
}
bool XYCKAnalogBoard::getTestConnectSuccess() const
{
return testConnectSuccess;
}
void XYCKAnalogBoard::startTest()
{
this->testConnectSuccess=false;
this->testStart=true;
this->reqGetState();
}
void XYCKAnalogBoard::dealDate(QByteArray buffer)
{
_codec->dealFrame(buffer);
}

View File

@ -0,0 +1,100 @@
#ifndef XYCKANALOGBOARD_H
#define XYCKANALOGBOARD_H
#include <QObject>
#include <QList>
#include <QVariant>
#include <QVariantMap>
#include <QVariantList>
#include <QtQml/QQmlListProperty>
#include <QSettings>
#include <QSerialPort>
#include "serialequipment.h"
#include "XYComFunc_global.h"
#include "CODEC/codecxyckanalog.h"
class XYCOMFUNC_EXPORT XYCKAnalogBoard : public SerialEquipment
{
Q_OBJECT
// Q_PROPERTY(QList<int> m_info READ m_info)
// Q_PROPERTY(QQmlListProperty<MyoelectricData>datalist READ datalist )
public:
explicit XYCKAnalogBoard();
explicit XYCKAnalogBoard(QString portName,QSerialPort::BaudRate baunRate,QSerialPort::DataBits dataBits,QSerialPort::Parity parity,QSerialPort::StopBits stopBits,int readBufferSize);
explicit XYCKAnalogBoard(QString portName);
explicit XYCKAnalogBoard(QString portName,QSerialPort::BaudRate baunRate);
bool reqSetting(int iChannel ,AnalogSetting setting);
Q_INVOKABLE bool reqSetting(int iChannel, int workMode, int samplerate, qreal frequency, int pulseWidth, qreal risingtime,int breaktime,qreal fallingtime,int holdingtime);
bool reqChannalControl(ChannelState ch1,ChannelState ch2,ChannelState ch3,ChannelState ch4);
Q_INVOKABLE bool reqChannalControl(int ch1,int ch2,int ch3,int ch4);
Q_INVOKABLE bool reqSetCurrent(int iChannel,int iCurrent);
bool reqDataChange(int iChannel,DataMode datamode);
Q_INVOKABLE bool reqDataChange(int iChannel,int datamode);
bool reqSetGain(int iChannel,GainMode gainmode);
Q_INVOKABLE bool reqSetGain(int iChannel,int gainmode);
bool reqSetCollect(int iChannel,ChannelState channelstate);
Q_INVOKABLE bool reqSetCollect(int iChannel,int channelstate);
bool reqSetStimulate(int iChannel,ChannelState channelstate);
Q_INVOKABLE bool reqSetStimulate(int iChannel,int channelstate);
//Q_INVOKABLE void setInfo(QString portName);
Q_INVOKABLE bool reqGetState();
int getInfo();
Q_INVOKABLE void setInfo(QString portName, int baunRate);
Q_INVOKABLE bool connectPort();
Q_INVOKABLE bool disConnectPort();
Q_INVOKABLE bool getConnectState();
QList<MyoelectricData> *getMyoelectricData(int iStep=0);
Q_INVOKABLE QVariantList getMyoelectricDataQml(int iStep=0);
Q_INVOKABLE qreal getIniInfo(int Channel,QString strValueType);
Q_INVOKABLE void setIniInfo(int Channel,QString strValueType,qreal rValue);
Q_INVOKABLE void clearList();
Q_INVOKABLE QString getCountLog();
//QList<int> GetMyoelectricDataIntArray();
//QList<int> m_info();
//QQmlListProperty<MyoelectricData> datalist();
bool getTestConnectSuccess() const;
void startTest();
signals:
void commandSendError(int iChannel,ErrorCode errorcode,int iFunctionCode);
void analogSettingRev(int iChannel,AnalogSetting *analogsetting);
void channalControlRev(ChannelState ch1,ChannelState ch2,ChannelState ch3,ChannelState ch4);
void currentRev(int iChannel,int iCurrent);
void dataChangeRev(int iChannel,DataMode datamode);
void gainRev(int iChannel,GainMode gainmode);
void collectRev(int iChannel,ChannelState channelstate);
void stimulateRev(int iChannel,ChannelState channelstate);
void stateInfoRev(QVariantMap stateMap);
private slots:
void OnCommandSendErrorRev(int iChannel,ErrorCode errorcode,int iFunctionCode);
void OnAnalogSettingRev(int iChannel,AnalogSetting *analogsetting);
void OnChannalControlRev(ChannelState ch1,ChannelState ch2,ChannelState ch3,ChannelState ch4);
void OnCurrentRev(int iChannel,int iCurrent);
void OnDataChangeRev(int iChannel,DataMode datamode);
void OnGainRev(int iChannel,GainMode gainmode);
void OnCollectRev(int iChannel,ChannelState channelstate);
void OnStimulateRev(int iChannel,ChannelState channelstate);
void OnStateInfoRev(AnalogState *analogstate);
private:
void initCodec();
private:
CODECXyckAnalog *_codec;
bool testConnectSuccess;
bool testStart;
QList<MyoelectricData *> m_dataList;
protected:
void dealDate(QByteArray buffer) override;
};
#endif // XYCKANALOGBOARD_H

View File

@ -0,0 +1,216 @@
#include "xyckdigitalboard.h"
XYCKDigitalBoard::XYCKDigitalBoard()
: SerialEquipment()
{
initCodec();
}
XYCKDigitalBoard::XYCKDigitalBoard(QString portName, QSerialPort::BaudRate baunRate, QSerialPort::DataBits dataBits, QSerialPort::Parity parity, QSerialPort::StopBits stopBits, int readBufferSize)
:SerialEquipment(portName,baunRate,dataBits,parity,stopBits,readBufferSize)
{
initCodec();
}
XYCKDigitalBoard::XYCKDigitalBoard(QString portName)
:SerialEquipment(portName)
{
initCodec();
}
XYCKDigitalBoard::XYCKDigitalBoard(QString portName, QSerialPort::BaudRate baunRate)
:SerialEquipment(portName,baunRate)
{
initCodec();
}
void XYCKDigitalBoard::setInfo(QString portName)
{
this->setSerialInfo(portName,QSerialPort::Baud115200);
}
void XYCKDigitalBoard::setInfo(QString portName, int baunRate)
{
this->setSerialInfo(portName,(QSerialPort::BaudRate)baunRate);
}
bool XYCKDigitalBoard::reqGetInfo()
{
return sendMsg(_codec->reqGetInfo());
}
bool XYCKDigitalBoard::reqControl(int iChannel, LightState lightstate)
{
return sendMsg(_codec->reqControl(iChannel,lightstate));
}
bool XYCKDigitalBoard::reqControl(int iChannel, int lightstate)
{
//qDebug()<<"lightControl channel:"+QString::number(iChannel)+"---"+QString::number(lightstate);
return sendMsg(_codec->reqControl(iChannel, (LightState)lightstate));
}
bool XYCKDigitalBoard::reqPreconditioning(int iChannel, ModeState modestate)
{
if(iChannel<1||iChannel>4)
{
return false;
}
return sendMsg(_codec->reqPreconditioning(iChannel,modestate));
}
bool XYCKDigitalBoard::reqPreconditioning(int iChannel, int modestate)
{
if(iChannel<1||iChannel>4)
{
return false;
}
return sendMsg(_codec->reqPreconditioning(iChannel,(ModeState)modestate));
}
bool XYCKDigitalBoard::reqUpdateA(int iChannel, int AValue)
{
//qDebug()<<"set DI A CHannl:"<<QString::number(iChannel)<<",A Value:"<<QString::number(AValue);
return sendMsg(_codec->reqUpdateA(iChannel,AValue));
}
bool XYCKDigitalBoard::reqPowOn(ModeState state)
{
return sendMsg(_codec->reqPowOn(state));
}
bool XYCKDigitalBoard::reqPowOn(int state)
{
return sendMsg(_codec->reqPowOn((ModeState)state));
}
bool XYCKDigitalBoard::resqPowoff(PowState powstate)
{
return sendMsg(_codec->resqPowoff(powstate));
}
bool XYCKDigitalBoard::resqPowoff(int powstate)
{
return sendMsg(_codec->resqPowoff((PowState)powstate));
}
bool XYCKDigitalBoard::connectPort()
{
if(this->getPortState())
{
return true;
}
else
{
return this->openPort();
}
}
bool XYCKDigitalBoard::disConnectPort()
{
if(this->getPortState())
{
return this->closePort();
}
else
{
return true;
}
}
bool XYCKDigitalBoard::getConnectState()
{
return this->getPortState();
}
void XYCKDigitalBoard::dealDate(QByteArray buffer)
{
_codec->dealFrame(buffer);
}
bool XYCKDigitalBoard::getTestConnectSuccess() const
{
return testConnectSuccess;
}
void XYCKDigitalBoard::startTest()
{
this->testConnectSuccess=false;
this->testStart=true;
this->reqGetInfo();
}
void XYCKDigitalBoard::initCodec()
{
_codec=new CODECXyckDigital();
connect(_codec,&CODECXyckDigital::commandSendError,this,&XYCKDigitalBoard::OnCommandSendErrorRev);
connect(_codec,&CODECXyckDigital::frameError,this,&XYCKDigitalBoard::OnFrameErrorRev);
connect(_codec,&CODECXyckDigital::digitalInfoRev,this,&XYCKDigitalBoard::OnDigitalInfoRev);
connect(_codec,&CODECXyckDigital::powOffCommandRev,this,&XYCKDigitalBoard::OnPowOffCommandRev);
connect(_codec,&CODECXyckDigital::controlRespond,this,&XYCKDigitalBoard::OnControlRespondRev);
connect(_codec,&CODECXyckDigital::preconditioningRespond,this,&XYCKDigitalBoard::OnPreconditioningRespondRev);
connect(_codec,&CODECXyckDigital::AUpdated,this,&XYCKDigitalBoard::OnAUpdated);
connect(_codec,&CODECXyckDigital::PowOn,this,&XYCKDigitalBoard::OnPowOn);
this->_frameHead.clear();
this->_frameHead.append(static_cast<char>(0xaa));
this->_frameTail.clear();
this->_frameTail.append(0x55);
this->testStart=false;
}
void XYCKDigitalBoard::OnCommandSendErrorRev(int iChannel, ErrorCode errorcode, int iFunctionCode)
{
emit commandSendError(iChannel,errorcode,iFunctionCode);
}
void XYCKDigitalBoard::OnFrameErrorRev(ErrorCode errorcode, QByteArray errBuffer)
{
emit frameError(errorcode,errBuffer);
}
void XYCKDigitalBoard::OnDigitalInfoRev(DigitalInfo *di)
{
if(this->testStart){
this->testConnectSuccess=true;
}
QVariantMap result;
result.insert("reset",di->reset);
result.insert("AChannelA",di->AChannelA);
result.insert("AChannelB",di->AChannelB);
result.insert("AChannelC",di->AChannelC);
result.insert("AChannelD",di->AChannelD);
result.insert("adapterState",di->adapterState);
result.insert("batteryState",di->batteryState);
emit digitalInfoRev(result);
}
void XYCKDigitalBoard::OnPowOffCommandRev()
{
emit powOffCommandRev();
}
void XYCKDigitalBoard::OnControlRespondRev(int iChannel, LightState lightstate)
{
emit controlRespond(iChannel,lightstate);
}
void XYCKDigitalBoard::OnPreconditioningRespondRev(int iChannel, ModeState modestate)
{
emit preconditioningRespond(iChannel,modestate);
}
void XYCKDigitalBoard::OnAUpdated(int iChannel, int AValue)
{
emit AUpdated(iChannel,AValue);
}
void XYCKDigitalBoard::OnPowOn(ModeState powOnState)
{
emit PowOn(powOnState);
}

View File

@ -0,0 +1,152 @@
#ifndef XYCKDIGITALBOARD_H
#define XYCKDIGITALBOARD_H
#include <QObject>
#include <QVariantMap>
#include "XYComFunc_global.h"
#include "equipmentLib/serialequipment.h"
#include "equipmentLib/CODEC/codecxyckdigital.h"
#include "commonStruct.h"
class XYCOMFUNC_EXPORT XYCKDigitalBoard :public SerialEquipment
{
Q_OBJECT
public:
explicit XYCKDigitalBoard();
explicit XYCKDigitalBoard(QString portName,QSerialPort::BaudRate baunRate,QSerialPort::DataBits dataBits,QSerialPort::Parity parity,QSerialPort::StopBits stopBits,int readBufferSize);
explicit XYCKDigitalBoard(QString portName);
explicit XYCKDigitalBoard(QString portName,QSerialPort::BaudRate baunRate);
Q_INVOKABLE void setInfo(QString portName);
Q_INVOKABLE void setInfo(QString portName,int baunRate);
/**
* @brief
* @return
*/
Q_INVOKABLE bool reqGetInfo();
/**
* @brief
* @return
*/
Q_INVOKABLE bool reqControl(int iChannel,LightState lightstate);
Q_INVOKABLE bool reqControl(int iChannel,int lightstate);
/**
* @brief
* @return
*/
bool reqPreconditioning(int iChannel,ModeState modestate);
Q_INVOKABLE bool reqPreconditioning(int iChannel,int modestate);
Q_INVOKABLE bool reqUpdateA(int iChannel,int AValue);
Q_INVOKABLE bool reqPowOn(ModeState state);
Q_INVOKABLE bool reqPowOn(int state);
/**
* @brief
* @param powstate
* @return
*/
bool resqPowoff(PowState powstate);
Q_INVOKABLE bool resqPowoff(int powstate);
Q_INVOKABLE bool connectPort();
Q_INVOKABLE bool disConnectPort();
Q_INVOKABLE bool getConnectState();
bool getTestConnectSuccess() const;
void startTest();
signals:
void commandSendError(int iChannel,ErrorCode errorcode,int iFunctionCode);
/**
* @brief
* @param errorcode
* @param errBuffer
*/
void frameError(ErrorCode errorcode,QByteArray errBuffer=nullptr);
/**
* @brief
* @param di
*/
void digitalInfoRev(QVariantMap digitalInfo);
/**
* @brief
*/
void powOffCommandRev();
/**
* @brief
* @param iChannel
* @param lightstate
*/
void controlRespond(int iChannel,LightState lightstate);
/**
* @brief
* @param iChannel
* @param modestate
*/
void preconditioningRespond(int iChannel,ModeState modestate);
void AUpdated(int iChannel,int AValue);
void PowOn(ModeState powOnState);
protected:
void dealDate(QByteArray) override;
private:
CODECXyckDigital *_codec;
bool testConnectSuccess;
bool testStart;
private:
void initCodec();
public slots:
void OnCommandSendErrorRev(int iChannel,ErrorCode errorcode,int iFunctionCode);
/**
* @brief
* @param errorcode
* @param errBuffer
*/
void OnFrameErrorRev(ErrorCode errorcode,QByteArray errBuffer=nullptr);
/**
* @brief
* @param di
*/
void OnDigitalInfoRev(DigitalInfo *di);
/**
* @brief
*/
void OnPowOffCommandRev();
/**
* @brief
* @param iChannel
* @param lightstate
*/
void OnControlRespondRev(int iChannel,LightState lightstate);
/**
* @brief
* @param iChannel
* @param modestate
*/
void OnPreconditioningRespondRev(int iChannel,ModeState modestate);
void OnAUpdated(int iChannel,int AValue);
void OnPowOn(ModeState powOnState);
};
#endif // XYCKDIGITALBOARD_H

View File

@ -0,0 +1,12 @@
#ifndef XYCOMFUNC_GLOBAL_H
#define XYCOMFUNC_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(XYCOMFUNC_LIBRARY)
# define XYCOMFUNC_EXPORT Q_DECL_EXPORT
#else
# define XYCOMFUNC_EXPORT Q_DECL_IMPORT
#endif
#endif // XYCOMFUNC_GLOBAL_H

View File

@ -0,0 +1,173 @@
#ifndef COMMONSTRUCT_H
#define COMMONSTRUCT_H
//电刺激相关
#define FRAME_HEAD 0xAA
#define FRAME_END 0x55
#define FUNCCODE_DIGITAL_GET_INFO 0x81
#define FUNCCODE_DIGITAL_CONTROL 0X82
#define FUNCCODE_DIGITAL_PRECONDITIONING 0x83
#define FUNCCODE_DIGITAL_POWOFF 0x84
#define FUNCCODE_DIGITAL_ERROR 0x8F
#define FUNCCODE_ANALOG_SETTING 0x91
#define FUNCCODE_ANALOG_CHANNAL_CONTROL 0x92
#define FUNCCODE_ANALOG_SET_CURRENT 0x93
#define FUNCCODE_ANALOG_DATA_UPLOAD 0x94
#define FUNCCODE_ANALOG_DATA_CHANGE 0x95
#define FUNCCODE_ANALOG_SET_GAIN 0x96
#define FUNCCODE_ANALOG_SET_COLLECT 0x97
#define FUNCCODE_ANALOG_SET_STIMULATE 0x98
#define FUNCCODE_ANALOG_STATE 0x99
#define FUNCCODE_ANALOG_ERROR 0x9F
#define FUNCCODE_ANALOG_ERROR 0x9F
#include <QObject>
enum PowState
{
PowCancel=0,
PowOff=1,
PowOn=2
};
enum CheckFunc
{
CheckFuncSum,
CheckFuncXOR,
CheckFuncCRC16
};
enum LightState
{
LightO1 = 1,
LightOff = 2,
LightFlicker = 3
};
enum ModeState
{
ModeOut = 0,
ModeIn =1
};
enum ErrorCode
{
ErrorCheckSum = 0,
ErrorFuncCode = 1
};
enum SampleRate
{
SamplingRate4K=4000,
SamplingRate8k=8000
};
enum WorkMode //工作模式
{
WorkModeCollect=1, //采集
WorkModeStimulate=2,//刺激
WorkModeTrigge=3 //触发
};
enum ChannelState
{
ChannelStateClose = 0,
ChannelStateOpen = 1,
ChannelStatePause = 2,
ChannelStateContinue=3
};
enum ChannelWorkState //工作状态
{
ChannelWorkFree = 0,//空闲态
ChannelWorkRise = 1,//上坡态
ChannelWorkFall = 2,//下坡态
ChannelWorkHold = 3,//保持态
ChannelWorkBreak = 4//休息态
};
enum DataMode
{
DataModeRMS = 0,
DataModeRaw = 1
};
enum GainMode
{
GainMode10 = 0,
GainMode100 = 1
};
struct DigitalInfo
{
uint8_t adapterState;
uint8_t batteryState;
uint8_t reset;
uint8_t AChannelA;
uint8_t AChannelB;
uint8_t AChannelC;
uint8_t AChannelD;
};
struct SerialLogInfo
{
int iRevTotalByte;
int iGoodFrameCount;
int iCheckNGFrameCount;
int iRevGoodByte;
int iSendFrameCount;
int iSendNGFrameCount;
};
struct AnalogSetting
{
WorkMode workmode; //模式
SampleRate samplerate;//采样率
qreal frequency; //频率
int pulseWidth; //脉宽
qreal risingTime; //上升时间
qreal fallingTime; //下降时间
int holdingTime; //保持时间
int breakTime; //休息时间
};
struct AnalogState
{
ModeState electrodeStateA;
ModeState electrodeStateB;
ModeState electrodeStateC;
ModeState electrodeStateD;
ModeState resetState;
ChannelWorkState channelWorkStateA;
ChannelWorkState channelWorkStateB;
ChannelWorkState channelWorkStateC;
ChannelWorkState channelWorkStateD;
};
struct MyoelectricData
{
int ch1;
int ch2;
int ch3;
int ch4;
};
Q_DECLARE_METATYPE(MyoelectricData)
#endif // COMMONSTRUCT_H

View File

@ -0,0 +1,447 @@
#include "serialequipment.h"
SerialEquipment::SerialEquipment()
{
_isLog=false;
this->_serialPort=new QSerialPort();
connect(this->_serialPort,SIGNAL(readyRead()),this,SLOT(dataReceive()));
_mutex=new QMutex(QMutex::Recursive);
}
SerialEquipment::SerialEquipment(QString portName,QSerialPort::BaudRate baunRate,QSerialPort::DataBits dataBits,QSerialPort::Parity parity,QSerialPort::StopBits stopBits,int readBufferSize)
{
_isLog=false;
this->setSerialInfo(portName,baunRate,dataBits,parity,stopBits,readBufferSize);
this->_serialPort=new QSerialPort();
connect(this->_serialPort,SIGNAL(readyRead()),this,SLOT(dataReceive()));
_mutex=new QMutex(QMutex::Recursive);
}
SerialEquipment::SerialEquipment(QString portName)
{
_isLog=false;
this->setSerialInfo(portName,QSerialPort::Baud460800,QSerialPort::Data8,QSerialPort::NoParity,QSerialPort::OneStop,30);
this->_serialPort=new QSerialPort();
connect(this->_serialPort,SIGNAL(readyRead()),this,SLOT(dataReceive()));
_mutex=new QMutex(QMutex::Recursive);
}
SerialEquipment::SerialEquipment(QString portName, QSerialPort::BaudRate baunRate)
{
_isLog=false;
this->setSerialInfo(portName,baunRate,QSerialPort::Data8,QSerialPort::NoParity,QSerialPort::OneStop,30);
this->_serialPort=new QSerialPort();
connect(this->_serialPort,SIGNAL(readyRead()),this,SLOT(dataReceive()));
_mutex=new QMutex(QMutex::Recursive);
}
SerialEquipment::~SerialEquipment()
{
closePort();
delete this->_serialPort;
}
void SerialEquipment::setSerialInfo(QString portName, QSerialPort::BaudRate baunRate, QSerialPort::DataBits dataBits, QSerialPort::Parity parity, QSerialPort::StopBits stopBits, int readBufferSize)
{
_isLog=false;
this->_strPortName=portName;
this->_iBaudRate=baunRate;
this->_iDataBits=dataBits;
this->_iParity=parity;
this->_iStopBits=stopBits;
this->_iReadBufferSize=readBufferSize;
this->needWait=true;
}
void SerialEquipment::setSerialInfo(QString portName, QSerialPort::BaudRate baunRate)
{
setSerialInfo(portName,baunRate,QSerialPort::Data8,QSerialPort::NoParity,QSerialPort::OneStop,512);
}
bool SerialEquipment::getPortState()
{
if(this->_serialPort==nullptr)
{
return false;
}
else
{
if(this->_serialPort->isOpen())
{
return true ;
}
else
{
return false;
}
}
}
bool SerialEquipment::openPort()
{
_isLog=false;
testJDCount=0;
testTotalCount=0;
bTestDebug=false;
if(this->_serialPort==nullptr)
{
return false;
}
else
{
if(!this->_serialPort->isOpen())
{
this->_serialPort->setPortName(this->_strPortName);
this->_serialPort->setBaudRate(this->_iBaudRate);
this->_serialPort->setParity(this->_iParity);
this->_serialPort->setStopBits(this->_iStopBits);
this->_serialPort->setDataBits(this->_iDataBits);
this->_serialPort->setFlowControl(QSerialPort::NoFlowControl);
this->_serialPort->setReadBufferSize(512);
bool bresult=this->_serialPort->open(QIODevice::ReadWrite);
return bresult;
}
else
{
return false;
}
}
}
bool SerialEquipment::closePort()
{
if(this->_serialPort==nullptr)
{
return false;
}
else
{
if(this->_serialPort->isOpen())
{
this->_serialPort->close();
return true;
}
else
{
return false;
}
}
}
void SerialEquipment::dataReceive()
{
QByteArray revBuffer;
int iHeadLength=this->_frameHead.length();
int iTailLength=this->_frameTail.length();
while(this->_serialPort->bytesAvailable()>0)
{
revBuffer.clear();
revBuffer=this->_serialPort->readAll();
//this->testTotalCount+=revBuffer.count();
// if(bTestDebug)
// {
//qDebug()<<"rev All: "<<tool::ByteArray2HEXQString(revBuffer);
// }
//
emit onDataReceived(&revBuffer);
if(iHeadLength==0||iTailLength==0)
{
return;
}
int iLen=revBuffer.length();
if(_isLog)
{
_logInfo->iRevTotalByte+=iLen;
}
int iCount=0;
while(iCount<iLen)
{
//qDebug()<<"tempArrayCount"<<_tempArray.count();
if(_tempArray.length()==iHeadLength)
{
if(!tool::checkArraySame(this->_frameHead,_tempArray,iHeadLength-1,0))
{
_tempArray.remove(0,1);
}
}
_tempArray.append(revBuffer.data()[iCount]);
if(_tempArray.length()==iHeadLength+1)
{
this->_iFrameSize= static_cast<uint8_t>(revBuffer.data()[iCount])+iHeadLength+iTailLength+2;
if(this->_iFrameSize>30){
qDebug()<<"lastBag:"<<tool::ByteArray2HEXQString(_tempArray);
_tempArray.clear();
continue;
}
//qDebug()<<"_iFrameSize"<<this->_iFrameSize;
}
iCount++;
if(_tempArray.length()==this->_iFrameSize)
{
if(this->_iFrameSize>30){
qDebug()<<"lastBag:"<<tool::ByteArray2HEXQString(_tempArray);
}
QByteArray frameArray=_tempArray;
// if(bTestDebug)
// {
// if(frameArray.at(2)==static_cast<char>(0x94)){
// qDebug()<<QString::number(this->_iFrameSize)+"wait check: "<<tool::ByteArray2HEXQString(frameArray);
// }
// }
if(tool::checkArraySame(frameArray,_frameTail,frameArray.length()-iTailLength,frameArray.length()-1)
&& checkData(frameArray,iTailLength))
{
// if(bTestDebug)
// {
// qDebug()<<"check:true ";
// }
emit this->onFrameReceived(&frameArray);
// if(frameArray[2]!= 0x94)
// {
// testJDCount++;
// }
dealDate(frameArray);
if(_isLog)
{
_logInfo->iGoodFrameCount++;
_logInfo->iRevGoodByte+=frameArray.count();
if(static_cast<uint8_t>(frameArray.data()[2])==0x8F||static_cast<uint8_t>(frameArray.data()[2])==0x9F)
{
_logInfo->iSendNGFrameCount++;
}
}
_tempArray.clear();
}
else
{
qDebug()<<"count:"+QString::number(iCount)+"--error--"<<tool::ByteArray2HEXQString(_tempArray);
if(_isLog)
{
_logInfo->iCheckNGFrameCount++;
}
//_tempArray=adjustList(_tempArray);
_tempArray.clear();
// //iCount-=_tempArray.count();
// if(iCount<0){
// iCount=0;
// }
//qDebug()<<"count:"+QString::number(iCount)+"--back--"<<tool::ByteArray2HEXQString(_tempArray);
//_tempArray.clear();
}
}
}
}
revBuffer.clear();
}
bool SerialEquipment::checkData(QByteArray buffer, int iTailIndex)
{
return DataCheck::sumCheck(buffer,iTailIndex);
}
void SerialEquipment::dataReceive1()
{
QByteArray revBuffer;
int iHeadLength=this->_frameHead.length();
while(this->_serialPort->bytesAvailable()>0)
{
revBuffer.clear();
revBuffer=this->_serialPort->readAll();
int iLen=revBuffer.length();
int iCount=0;
while(iCount<iLen)
{
if(_tempArray.length()==iHeadLength)
{
if(!tool::checkArraySame(this->_frameHead,_tempArray,iHeadLength-1,0))
{
_tempArray.remove(0,1);
}
}
_tempArray.append(revBuffer.data()[iCount]);
iCount++;
if(_tempArray.length()==this->_iFrameSize)
{
QByteArray frameArray=_tempArray;
if(DataCheck::sumCheck(frameArray))
{
emit this->onFrameReceived(&frameArray);
_tempArray.clear();
}
else
{
_tempArray=adjustList(_tempArray);
}
}
}
}
revBuffer.clear();
}
void SerialEquipment::dealDate(QByteArray)
{
}
SerialLogInfo *SerialEquipment::GetLogInfo()
{
return _logInfo;
}
void SerialEquipment::delayMsec(int mesc)
{
QTime temp=QTime::currentTime().addMSecs(mesc);
while(QTime::currentTime()<temp)
{
QCoreApplication::processEvents(QEventLoop::AllEvents,100);
}
}
QList<QString> SerialEquipment::getAllPorts()
{
QList<QString> resultList;
QList<QSerialPortInfo> portList = QSerialPortInfo::availablePorts();
for (int i=0;i<portList.count();i++)
{
resultList.append(portList[i].portName());
}
return resultList;
}
void SerialEquipment::setNeedWait(bool value)
{
needWait = value;
}
QList<char> SerialEquipment::adjustList(QList<char> srcList)
{
if(srcList.length()>0)
{
srcList.removeAt(0);
}
else
{
return srcList;
}
return tool::findHead(srcList,this->_frameHead);
}
QByteArray SerialEquipment::adjustList(QByteArray srcList)
{
if(srcList.length()>0)
{
srcList.remove(0,1);
}
else
{
return srcList;
}
return tool::findHead(srcList,this->_frameHead);
}
bool SerialEquipment::sendMsg(QByteArray sendBuffer)
{
if(this->getPortState())
{
_mutex->lock();
this->_serialPort->write(sendBuffer);
if(needWait){
qDebug()<<"wait";
if(!this->_serialPort->waitForBytesWritten()){
_mutex->unlock();
return false;
}
}
_mutex->unlock();
emit onFrameSended(&sendBuffer);
// if(sendBuffer.count()>3&&static_cast<u_int8_t>(sendBuffer[2])!=static_cast<u_int8_t>(0x81)&&static_cast<u_int8_t>(sendBuffer[2])!=static_cast<u_int8_t>(0x99)){
// QString tempString = tool::ByteArray2HEXQString(sendBuffer);
// qDebug()<<"send: "<<tempString;
// }
// if(static_cast<u_int8_t>(sendBuffer[2])==static_cast<u_int8_t>(0x85))
// {
// QString tempString = tool::ByteArray2HEXQString(sendBuffer);
// qDebug()<<"sendDI_A: "<<tempString;
// }
// if(static_cast<u_int8_t>(sendBuffer[2])==static_cast<u_int8_t>(0x93))
// {
// QString tempString = tool::ByteArray2HEXQString(sendBuffer);
// qDebug()<<tempString;
// }
return true;
}
else
{
return false;
}
}
void SerialEquipment::setLogInfo(bool isLog)
{
isLog=false;
if(isLog)
{
_logInfo=new SerialLogInfo();
_logInfo->iCheckNGFrameCount=0;
_logInfo->iGoodFrameCount=0;
_logInfo->iRevGoodByte=0;
_logInfo->iRevTotalByte=0;
_logInfo->iSendNGFrameCount=0;
_logInfo->iSendFrameCount=0;
}
_isLog=isLog;
}
bool SerialEquipment::sendMsg(QString strMessage)
{
if(this->getPortState())
{
QByteArray sendBuffer=strMessage.toLatin1();
_mutex->lock();
this->_serialPort->write(sendBuffer);
if(needWait){
//qDebug()<<"wait";
if(!this->_serialPort->waitForBytesWritten()){
_mutex->unlock();
return false;
}
}
_mutex->unlock();
emit onFrameSended(&sendBuffer);
if(_isLog)
{
_logInfo->iSendFrameCount++;
}
qDebug()<<"send: "<<strMessage;
return true;
}
else
{
return false;
}
}
void SerialEquipment::setFrameHead(QByteArray frameHead)
{
this->_frameHead=frameHead;
}
void SerialEquipment::setFrameTail(QByteArray frameTail)
{
this->_frameTail=frameTail;
}
void SerialEquipment::setFrameSize(int iFramSize)
{
this->_iFrameSize=iFramSize;
}

View File

@ -0,0 +1,133 @@
#ifndef SERIAL_EQUIPMENT_H
#define SERIAL_EQUIPMENT_H
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>
#include <QList>
#include <QTime>
#include <QCoreApplication>
#include <QEventLoop>
#include <QDebug>
#include <QMutex>
#include <QThread>
#include <QFile>
#include "XYComFunc_global.h"
//#include "CommomFunc/tool.h"
//#include "CommomFunc/datacheck.h"
#include "commonStruct.h"
//串口设备类
//实现串口通讯,目前支持固定包头固定长度的帧的解析。若非固定包头固定长度,请重写接收事件
/**
* @brief
* checksum01dataReceive事件
*
*/
class XYCOMFUNC_EXPORT SerialEquipment:public QObject
{
Q_OBJECT
Q_SIGNALS:
//帧接收事件
void onFrameReceived(QByteArray *receiveBuffer);
void onFrameSended(QByteArray *sendBuffer);
void onDataReceived(QByteArray *revBuffer);
public:
//默认构造
SerialEquipment();
//构造
SerialEquipment(QString portName,QSerialPort::BaudRate baunRate,QSerialPort::DataBits dataBits,QSerialPort::Parity parity,QSerialPort::StopBits stopBits,int readBufferSize);
SerialEquipment(QString portName);
SerialEquipment(QString portName,QSerialPort::BaudRate baunRate);
~SerialEquipment();
//设置串口参数
void setSerialInfo(QString portName,QSerialPort::BaudRate baunRate,QSerialPort::DataBits dataBits,QSerialPort::Parity parity,QSerialPort::StopBits stopBits,int readBufferSize);
void setSerialInfo(QString portName, QSerialPort::BaudRate baunRate);
//打开串口
bool openPort();
//关闭串口
bool closePort();
//获取串口状态
bool getPortState();
//设置帧头
void setFrameHead(QByteArray frameHead);
void setFrameTail(QByteArray frameTail);
//设置帧长
void setFrameSize(int iFramSize);
//发送指令
bool sendMsg(QString sendBuffer);
bool sendMsg(QByteArray buffer);
void setLogInfo(bool isLog);
SerialLogInfo *GetLogInfo();
void delayMsec(int mesc);
static QList<QString> getAllPorts();
Q_INVOKABLE void setNeedWait(bool value);
protected:
//串口类
QSerialPort *_serialPort;
//串口号
QString _strPortName;
//用于暂存帧信息的List
QByteArray _tempArray;
//QList<char> tempList;
//波特率
QSerialPort::BaudRate _iBaudRate;
//数据位
QSerialPort::DataBits _iDataBits;
//校验位
QSerialPort::Parity _iParity;
//停止位
QSerialPort::StopBits _iStopBits;
//缓冲区读取大小
int _iReadBufferSize;
//帧长度
int _iFrameSize;
//暂存上byte
char _lastByte;
//帧头
QByteArray _frameHead;
QByteArray _frameTail;
SerialLogInfo *_logInfo;
bool _isLog;
QMutex* _mutex;
int testJDCount;
int testTotalCount;
bool bTestDebug;
bool needWait;
protected:
//出现异常帧时,用于调整帧内容
QList<char> adjustList(QList<char> srcList);
QByteArray adjustList(QByteArray srcList);
void dataReceive1();
virtual void dealDate(QByteArray);
protected slots:
//串口接收事件
virtual void dataReceive();
virtual bool checkData(QByteArray buffer,int iTailIndex);
};
#endif // SERIAL_EQUIPMENT_H

View File

@ -0,0 +1,84 @@
#include "tcpclientequipment.h"
TcpClientEquipment::TcpClientEquipment(QObject *parent) : QObject(parent)
{
this->flag=false;
}
void TcpClientEquipment::setInfo(QString strIP, int iPort)
{
this->ip=strIP;
this->port=iPort;
}
void TcpClientEquipment::connect2Server()
{
this->mClient=new QTcpSocket(this);
connect(mClient,&QTcpSocket::readyRead,this,&TcpClientEquipment::onDataReceived);
this->mClient->connectToHost(QHostAddress(ip),port,QTcpSocket::ReadWrite);
this->flag=true;
}
void TcpClientEquipment::connect2Server(QString strIP, int iPort)
{
setInfo(strIP,iPort);
this->mClient=new QTcpSocket(this);
connect(mClient,&QTcpSocket::readyRead,this,&TcpClientEquipment::onDataReceived);
this->mClient->connectToHost(QHostAddress(ip),port,QTcpSocket::ReadWrite);
this->flag=true;
}
bool TcpClientEquipment::getState()
{
return this->flag;
}
bool TcpClientEquipment::sendMsg(QByteArray buffer)
{
if(this->flag){
int iResult = this->mClient->write(buffer);
if(iResult==-1){
return false;
}
else
{
return true;
}
}
else
{
return false;
}
}
bool TcpClientEquipment::sendMsg(QString buffer)
{
return this->sendMsg(buffer.toUtf8());
}
void TcpClientEquipment::reconnect2Server()
{
disconnect2Server();
connect2Server();
}
void TcpClientEquipment::disconnect2Server()
{
if(this->flag){
mClient->close();
mClient->deleteLater();
mClient=nullptr;
}
}
void TcpClientEquipment::onDataReceived()
{
QByteArray revBuffer=this->mClient->readAll();
dateReceived(revBuffer);
}

View File

@ -0,0 +1,40 @@
#ifndef TCPCLIENTEQUIPMENT_H
#define TCPCLIENTEQUIPMENT_H
#include <QObject>
#include <QTcpSocket>
#include <QObject>
#include <QMap>
#include <QHostAddress>
#include <QDebug>
#include <CommomFunc/tool.h>
#include <QByteArray>
#include "XYComFunc_global.h"
class XYCOMFUNC_EXPORT TcpClientEquipment : public QObject
{
Q_OBJECT
public:
explicit TcpClientEquipment(QObject *parent = 0);
Q_INVOKABLE void setInfo(QString strIP,int iPort);
Q_INVOKABLE void connect2Server();
Q_INVOKABLE void connect2Server(QString strIP,int iPort);
Q_INVOKABLE bool getState();
Q_INVOKABLE bool sendMsg(QByteArray buffer);
Q_INVOKABLE bool sendMsg(QString buffer);
void reconnect2Server();
void disconnect2Server();
signals:
void dateReceived(QByteArray buffer);
public slots:
virtual void onDataReceived();
protected:
QTcpSocket *mClient;
QString ip;
int port;
bool flag;
};
#endif // TCPCLIENTEQUIPMENT_H

View File

@ -0,0 +1,144 @@
#include "tcpequipment.h"
TcpEquipment::TcpEquipment()
{
}
TcpEquipment::TcpEquipment(QString IP)
{
this->listenIp=IP;
this->serverFlag=false;
}
void TcpEquipment::setIP(QString IP)
{
this->listenIp=IP;
}
void TcpEquipment::startServer()
{
this->server=new QTcpServer(this);
if(listenIp.isEmpty())
{
this->server->listen(QHostAddress::Any,TCP_SERVER_PORT);
}
else
{
this->server->listen(QHostAddress(this->listenIp),TCP_SERVER_PORT);
}
QObject::connect(this->server,&QTcpServer::newConnection,this,&TcpEquipment::onClientConnected);
QObject::connect(this->server,&QTcpServer::acceptError,this,&TcpEquipment::onServerAcceptError);
this->serverFlag=true;
}
void TcpEquipment::startServer(QString IP)
{
setIP(IP);
startServer();
}
void TcpEquipment::stopServer()
{
QList<QString> keyList=this->clientList.keys();
for(int i=0;i<keyList.count();i++)
{
this->clientList[keyList[i]]->close();
}
this->clientList.clear();
this->server->close();
this->serverFlag=false;
}
void TcpEquipment::send2All(QString strMsg)
{
if(!this->serverFlag){
return;
}
QList<QString> mKeys=clientList.keys();
for(int i=0;i<mKeys.count();i++){
QTcpSocket *temp= (QTcpSocket*)(clientList.value(mKeys[i]));
temp->write(strMsg.toUtf8());
}
}
void TcpEquipment::send2All(QByteArray buffer)
{
if(!this->serverFlag){
return;
}
QList<QString> mKeys=clientList.keys();
for(int i=0;i<mKeys.count();i++){
QTcpSocket *temp= (QTcpSocket*)(clientList.value(mKeys[i]));
temp->write(buffer);
}
}
void TcpEquipment::send2One(QString strMsg, QString ip)
{
if(!this->serverFlag){
return;
}
QTcpSocket *temp= (QTcpSocket*)(clientList.value(ip));
temp->write(strMsg.toUtf8());
}
void TcpEquipment::send2One(QByteArray buffer, QString ip)
{
if(!this->serverFlag){
return;
}
QTcpSocket *temp= (QTcpSocket*)(clientList.value(ip));
temp->write(buffer);
}
void TcpEquipment::onServerAcceptError()
{
}
void TcpEquipment::onClientConnected()
{
QTcpSocket* tcp =this->server->nextPendingConnection();
QString strIP=tcp->peerAddress().toString();
int iPort=tcp->peerPort();
qDebug()<<"Connected!!IP:"+strIP+":"+QString::number(iPort);
emit stateChanged("Connected!!IP:"+strIP+":"+QString::number(iPort));
QObject::connect(tcp,&QTcpSocket::readyRead,this,&TcpEquipment::onClientDataReceived);
QObject::connect(tcp,&QTcpSocket::disconnected,this,&TcpEquipment::onClinetDisconnected);
this->clientList.insert(strIP,tcp);
}
void TcpEquipment::onClientDataReceived()
{
QTcpSocket* tcp = dynamic_cast<QTcpSocket*>(sender());
QString strIP=tcp->peerAddress().toString();
int iPort=tcp->peerPort();
QByteArray tempBuffer=tcp->readAll();
QString strBuffer=QString(tempBuffer);
qDebug()<<"IP:"+strIP+":"+QString::number(iPort)+"--"+strBuffer;
dealRev(strIP,iPort,tempBuffer);
emit dateReceived(strIP,iPort,tempBuffer);
}
void TcpEquipment::onClinetDisconnected()
{
QTcpSocket* tcp = dynamic_cast<QTcpSocket*>(sender());
QString strIP=tcp->peerAddress().toString();
int iPort=tcp->peerPort();
qDebug()<<"Disconnected!!IP:"+strIP+":"+QString::number(iPort);
emit stateChanged("Disconnected!!IP:"+strIP+":"+QString::number(iPort));
QObject::disconnect(tcp,&QTcpSocket::readyRead,this,&TcpEquipment::onClientDataReceived);
QObject::disconnect(tcp,&QTcpSocket::disconnected,this,&TcpEquipment::onClinetDisconnected);
//delete this->clientList.value(strIP);
this->clientList.remove(strIP);
}
void TcpEquipment::dealRev(QString strIP, int iPort, QByteArray buffer)
{
Q_UNUSED(strIP)
Q_UNUSED(iPort)
Q_UNUSED(buffer)
}

View File

@ -0,0 +1,55 @@
#ifndef TCPEQUIPMENT_H
#define TCPEQUIPMENT_H
#define TCP_SERVER_PORT 23333
#include <QTcpServer>
#include <QTcpSocket>
#include <QObject>
#include <QMap>
#include <QHostAddress>
#include <QDebug>
#include <CommomFunc/tool.h>
#include <QByteArray>
#include "XYComFunc_global.h"
class XYCOMFUNC_EXPORT TcpEquipment:public QObject
{
Q_OBJECT
public:
TcpEquipment();
TcpEquipment(QString IP);
Q_INVOKABLE void setIP(QString IP);
Q_INVOKABLE void startServer();
Q_INVOKABLE void startServer(QString IP);
Q_INVOKABLE void stopServer();
Q_INVOKABLE void send2All(QString strMsg);
Q_INVOKABLE void send2All(QByteArray buffer);
Q_INVOKABLE void send2One(QString strMsg,QString ip);
Q_INVOKABLE void send2One(QByteArray buffer,QString ip);
signals:
void dateReceived(QString strIP,int iPort,QByteArray buffer);
void stateChanged(QString strStateInfo);
public slots:
void onServerAcceptError();
void onClientConnected();
void onClientDataReceived();
void onClinetDisconnected();
protected:
virtual void dealRev(QString strIP,int iPort,QByteArray buffer);
private:
QMap<QString,QTcpSocket*> clientList;
QTcpServer* server;
QString listenIp;
bool serverFlag;
};
#endif // TCPEQUIPMENT_H

View File

@ -0,0 +1 @@
此文件夹下存放第三方库dll文件

Binary file not shown.

After

Width:  |  Height:  |  Size: 434 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 258 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 320 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -0,0 +1 @@
此文件夹下存放本地图片

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,7 @@
import QtQuick 2.0
Item {
}

View File

@ -0,0 +1,24 @@
/* 未下拉时QComboBox的样式 */
QComboBox {
border: 1px solid gray; /* 边框 */
border-radius: 3px; /* 圆角 */
padding: 1px 18px 1px 3px; /*字体填衬 */
color: #000;
font: 25px "黑体";
background: transparent;
}
/* 下拉后,整个下拉窗体样式 */
QComboBox QAbstractItemView {
outline: 0px solid gray; /* 选定项的虚框 */
border: 0px solid gray; /* 整个下拉窗体的边框 */
color: black;
background-color: #C3E4F3; /* 整个下拉窗体的背景色 */
selection-background-color: lightgreen; /* 整个下拉窗体被选中项的背景色 */
font: 25px "黑体";
}
/* 下拉后,整个下拉窗体每项的样式 */
QComboBox QAbstractItemView::item {
height: 50px; /* 项的高度设置pComboBox->setView(new QListView());后,该项才起作用) */
}

View File

@ -0,0 +1,72 @@
/**********首先指定是水平还是竖直*不添加此代码,下方不起作用******/
QSlider::groove:horizontal {
border: 0px solid #bbb;
}
/*1.滑动过的槽设计参数*/
QSlider::sub-page:horizontal {
/*槽颜色*/
background: #05A6EC;
/*外环区域倒圆角度*/
border-radius: 4px;
/*上遮住区域高度*/
margin-top:8px;
/*下遮住区域高度*/
margin-bottom:8px;
/*width在这里无效不写即可*/
}
/*2.未滑动过的槽设计参数*/
QSlider::add-page:horizontal {
/*槽颜色*/
background: #ECEBEB;
/*外环大小0px就是不显示默认也是0*/
border: 0px solid #777;
/*外环区域倒圆角度*/
border-radius: 4px;
/*上遮住区域高度*/
margin-top:9px;
/*下遮住区域高度*/
margin-bottom:9px;
}
/*3.平时滑动的滑块设计参数*/
/3.1**********使用纯代码实现*****/
QSlider::handle:horizontal {
/*滑块颜色*/
background: rgb(255,255,255);
/*滑块的宽度*/
width: 30px;
/*滑块外环为1px再加颜色*/
border: 1px solid #05A6EC;
/*滑块外环倒圆角度*/
border-radius: 15px;
/*上遮住区域高度*/
margin-top:0px;
/*下遮住区域高度*/
margin-bottom:0px;
}
/*********使用背景图的方式添加滑块***********/
QSlider::handle:horizontal {
width: 30px;
background:transparent;
background-image: url(:/DependFile/Source/channel/slder.png);
margin: -5px -0px -0px -0px;
}
/*4.手动拉动时显示的滑块设计参数*/
QSlider::handle:horizontal:hover {
/*滑块颜色*/
background: rgb(193,204,208);
/*滑块的宽度*/
width: 30px;
/*滑块外环为1px再加颜色*/
border: 1px solid rgb(193,204,208);
/*滑块外环倒圆角度*/
border-radius: 5px;
/*上遮住区域高度*/
margin-top:4px;
/*下遮住区域高度*/
margin-bottom:4px;
}

View File

@ -0,0 +1,82 @@
/**********首先指定是水平还是竖直*不添加此代码,下方不起作用******/
QSlider::groove:horizontal {
border: 0px solid #bbb;
}
/*1.滑动过的槽设计参数*/
QSlider::sub-page:horizontal {
/*槽颜色*/
background:#05A6EC;
/*外环区域倒圆角度*/
border-radius: 4px;
/*上遮住区域高度*/
margin-top:14px;
/*下遮住区域高度*/
margin-bottom:14px;
/*width在这里无效不写即可*/
/*****/
margin-left:8px;
}
/*2.未滑动过的槽设计参数*/
QSlider::add-page:horizontal {
/*槽颜色*/
background: #ECEBEB;
/*外环大小0px就是不显示默认也是0*/
border: 0px solid #777;
/*外环区域倒圆角度*/
border-radius: 4px;
/*上遮住区域高度*/
margin-top:14px;
/*下遮住区域高度*/
margin-bottom:14px;
margin-right:8px;
}
/********使用图片填充滑块效果***********/
QSlider::handle:horizontal {
width: 43px;
background:transparent;
background-image: url(:/DependFile/Source/channel/slder.png);
margin: -0px -0px -0px -0px;
}
/********radioButton效果***********/
QRadioButton::indicator:unchecked{
image: url(:/DependFile/Source/radioButton/normal.png);
width:20;
height:20;
}
QRadioButton::indicator:checked{
image: url(:/DependFile/Source/radioButton/checked.png);
width:20;
height:20;
}
/* 未下拉时QComboBox的样式 */
QComboBox {
border: 1px solid gray; /* 边框 */
border-radius: 3px; /* 圆角 */
padding: 1px 18px 1px 3px; /* 字体填衬 */
color: #000;
font: 20px "黑体";
background: transparent;
}
/* 下拉后,整个下拉窗体样式 */
QComboBox QAbstractItemView {
outline: 0px solid gray; /* 选定项的虚框 */
border: 0px solid gray; /* 整个下拉窗体的边框 */
color: black;
background-color: #C3E4F3; /* 整个下拉窗体的背景色 */
selection-background-color: lightgreen; /* 整个下拉窗体被选中项的背景色 */
font: 20px "黑体";
}
/* 下拉后,整个下拉窗体每项的样式 */
QComboBox QAbstractItemView::item {
height: 50px; /* 项的高度设置pComboBox->setView(new QListView());后,该项才起作用) */
}

View File

@ -0,0 +1 @@
此文件夹下存放qss文件

View File

@ -0,0 +1,191 @@
//无数据部分表头
QHeaderView{
border: none;
border-bottom: 3px solid rgb(0, 160, 230);
background: rgb(57, 58, 60);
min-height: 30px;
}
//有数据部分水平表头
QHeaderView::section:horizontal {
border: none;
color: white;
background: transparent;
padding-left: 5px;
}
//有数据部分垂直表头
QHeaderView::section:vertical {
border: none;
color: white;
background: transparent;
padding-left: 5px;
}
//有数据部分表格角落按钮
QTableCornerButton:section{
background:#039092;
border:1px solid #777777;
}
QTreeView,QListView,QTableView,QSplitter::handle,QTreeView::branch{
background:#ff0000;
}
QHeaderView::section:horizontal:hover {
background: rgb(0, 160, 230);
}
QHeaderView::section:horizontal:pressed {
background: rgb(0, 180, 255);
}
QHeaderView::up-arrow {
width: 13px;
height: 11px;
padding-right: 5px;
image: url(:/Black/topArrow);
subcontrol-position: center right;
}
QHeaderView::up-arrow:hover, QHeaderView::up-arrow:pressed {
image: url(:/Black/topArrowHover);
}
QHeaderView::down-arrow {
width: 13px;
height: 11px;
padding-right: 5px;
image: url(:/Black/bottomArrow);
subcontrol-position: center right;
}
QHeaderView::down-arrow:hover, QHeaderView::down-arrow:pressed {
image: url(:/Black/bottomArrowHover);
}
/**********表格**********/
//无数据部分内容样式
QTableView {
border: 1px solid rgb(45, 45, 45);
background: rgb(57, 58, 60);
gridline-color: rgb(60, 60, 60);//表格数据部分网格线
}
//有数据部分内容样式
QTableView::item {
padding-left: 5px;
padding-right: 5px;
border: none;
background: rgb(72, 72, 74);
border-right: 1px solid rgb(45, 45, 45);
border-bottom: 1px solid rgb(45, 45, 45);
}
QTableView::item:selected {
background: rgba(255, 255, 255, 40);
}
QTableView::item:selected:!active {
color: white;
}
QTableView::indicator {
width: 20px;
height: 20px;
}
QTableView::indicator:enabled:unchecked {
image: url(:/Black/checkBox);
}
QTableView::indicator:enabled:unchecked:hover {
image: url(:/Black/checkBoxHover);
}
QTableView::indicator:enabled:unchecked:pressed {
image: url(:/Black/checkBoxPressed);
}
QTableView::indicator:enabled:checked {
image: url(:/Black/checkBoxChecked);
}
QTableView::indicator:enabled:checked:hover {
image: url(:/Black/checkBoxCheckedHover);
}
QTableView::indicator:enabled:checked:pressed {
image: url(:/Black/checkBoxCheckedPressed);
}
QTableView::indicator:enabled:indeterminate {
image: url(:/Black/checkBoxIndeterminate);
}
QTableView::indicator:enabled:indeterminate:hover {
image: url(:/Black/checkBoxIndeterminateHover);
}
QTableView::indicator:enabled:indeterminate:pressed {
image: url(:/Black/checkBoxIndeterminatePressed);
}
/**********滚动条-水平**********/
QScrollBar:horizontal {
height: 20px;
background: transparent;
margin-top: 3px;
margin-bottom: 3px;
}
QScrollBar::handle:horizontal {
height: 20px;
min-width: 30px;
background: rgb(68, 69, 73);
margin-left: 15px;
margin-right: 15px;
}
QScrollBar::handle:horizontal:hover {
background: rgb(80, 80, 80);
}
QScrollBar::sub-line:horizontal {
width: 15px;
background: transparent;
image: url(:/Black/arrowLeft);
subcontrol-position: left;
}
QScrollBar::add-line:horizontal {
width: 15px;
background: transparent;
image: url(:/Black/arrowRight);
subcontrol-position: right;
}
QScrollBar::sub-line:horizontal:hover {
background: rgb(68, 69, 73);
}
QScrollBar::add-line:horizontal:hover {
background: rgb(68, 69, 73);
}
QScrollBar::add-page:horizontal,QScrollBar::sub-page:horizontal {
background: transparent;
}
/**********滚动条-垂直**********/
QScrollBar:vertical {
width: 20px;
background: transparent;
margin-left: 3px;
margin-right: 3px;
}
QScrollBar::handle:vertical {
width: 20px;
min-height: 30px;
background: rgb(68, 69, 73);
margin-top: 15px;
margin-bottom: 15px;
}
QScrollBar::handle:vertical:hover {
background: rgb(80, 80, 80);
}
QScrollBar::sub-line:vertical {
height: 15px;
background: transparent;
image: url(:/Black/arrowTop);
subcontrol-position: top;
}
QScrollBar::add-line:vertical {
height: 15px;
background: transparent;
image: url(:/Black/arrowBottom);
subcontrol-position: bottom;
}
QScrollBar::sub-line:vertical:hover {
background: rgb(68, 69, 73);
}
QScrollBar::add-line:vertical:hover {
background: rgb(68, 69, 73);
}
QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {
background: transparent;
}
QScrollBar#verticalScrollBar:vertical {
margin-top: 30px;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 400 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 310 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 576 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 345 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 437 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 340 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 487 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 533 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 640 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Some files were not shown because too many files have changed in this diff Show More