beifen
This commit is contained in:
@@ -3,7 +3,7 @@ TEMPLATE = subdirs
|
||||
CONFIG += ordered
|
||||
|
||||
|
||||
SUBDIRS += VehicleManage
|
||||
#SUBDIRS += VehicleManage
|
||||
SUBDIRS += Skin
|
||||
SUBDIRS += opmap
|
||||
SUBDIRS += Cockpit
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
|
||||
QT += core gui network
|
||||
QT += axcontainer
|
||||
#QT += axcontainer
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
|
||||
+78
-20
@@ -117,7 +117,7 @@ int DLink::SendMessageTo(quint8 ch, quint8 *msg, quint16 len)
|
||||
//qDebug() << "Send Msg";
|
||||
//更加ch选择
|
||||
|
||||
foreach(Node node,clientSockets)
|
||||
foreach(clientNode node,clientSockets)
|
||||
{
|
||||
qint64 flag = node.sock->writeDatagram((const char *)msg,len,node.addr, node.port);
|
||||
if(flag != -1)
|
||||
@@ -165,8 +165,6 @@ bool DLink::setupPort(const QString port, qint32 baudrate, QSerialPort::Parity p
|
||||
}
|
||||
serialPort = new QSerialPort(this);
|
||||
|
||||
//Device.insert(0,serialPort);
|
||||
|
||||
serialPort->setPortName(port);
|
||||
|
||||
if (serialPort->open(QIODevice::ReadWrite))
|
||||
@@ -203,26 +201,88 @@ bool DLink::setupPort(const QString port, qint32 baudrate, QSerialPort::Parity p
|
||||
return isSuccess;
|
||||
}
|
||||
|
||||
bool DLink::statesPort()
|
||||
|
||||
/* 新想法
|
||||
* dlink 当作一个线程一直循环,一旦某一个串口连接,就会把事件循环加入其中,得到事件驱动
|
||||
* 指令按下会把数据存到缓存,等待发送出去,线程就会结束
|
||||
* 发起任务读写,新建一个线程,航线读取发送结束,航线线程结束
|
||||
* 发起参数读写,新建一个线程,参数读取发送结束,参数线程结束
|
||||
*/
|
||||
bool DLink::PortSetup(const QString port, qint32 baud, QSerialPort::Parity parity, const char * method)
|
||||
{
|
||||
if(serialPort)
|
||||
bool isSuccess = false;
|
||||
QSerialPort *serialPort = new QSerialPort(port, this);
|
||||
|
||||
if (serialPort->open(QIODevice::ReadWrite))
|
||||
{
|
||||
return (serialPort != nullptr)?(true):(false);
|
||||
serialPort->setBaudRate(baud);
|
||||
serialPort->setStopBits(QSerialPort::OneStop);
|
||||
serialPort->setParity(parity);
|
||||
serialPort->setDataBits(QSerialPort::Data8);
|
||||
connect(serialPort, SIGNAL(readyRead()), this, method);
|
||||
|
||||
isSuccess = true;
|
||||
|
||||
serialNode node;
|
||||
|
||||
node.port = serialPort;
|
||||
node.baud = baud;
|
||||
node.parity = parity;
|
||||
node.name = port;
|
||||
|
||||
serials.insert(serials.size(),node);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete serialPort;
|
||||
serialPort = NULL;
|
||||
}
|
||||
return isSuccess;
|
||||
}
|
||||
|
||||
bool DLink::PortState(const QString name)
|
||||
{
|
||||
bool flag = false;
|
||||
|
||||
foreach (serialNode node, serials) {
|
||||
if(node.port)
|
||||
{
|
||||
if(node.name == name)
|
||||
{
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DLink::stopPort()
|
||||
{
|
||||
if(serialPort)
|
||||
{
|
||||
emit showMessage(tr("Serial Port close"));
|
||||
if(serialPort->isOpen())
|
||||
{
|
||||
serialPort->close();
|
||||
return flag;
|
||||
}
|
||||
delete serialPort;
|
||||
serialPort = nullptr;
|
||||
|
||||
bool DLink::PortStop(const QString name)
|
||||
{
|
||||
bool flag = false;
|
||||
foreach (serialNode node, serials) {
|
||||
if(node.port)
|
||||
{
|
||||
if(node.name == name)
|
||||
{
|
||||
if(node.port->isOpen())
|
||||
{
|
||||
emit showMessage(tr("%1 close").arg(node.name));
|
||||
node.port->close();
|
||||
}
|
||||
|
||||
//断掉所有的连接
|
||||
disconnect(node.port,nullptr,nullptr,nullptr);
|
||||
|
||||
delete node.port;
|
||||
node.port = nullptr;
|
||||
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
void DLink::connectSignal(QVariant m_state,
|
||||
@@ -325,7 +385,7 @@ void DLink::connectSignal(QVariant m_state,
|
||||
qWarning() << "disconnect";
|
||||
if(m_Type.toString() == "SerialPort")
|
||||
{
|
||||
stopPort();
|
||||
PortStop(m_Param1.toString());
|
||||
emit PortConnected(false,m_usrName,m_Type,m_Param1,m_Param2,m_Param3,m_Param4,m_Param5);
|
||||
}
|
||||
else if(m_Type.toString() == "UDP")
|
||||
@@ -335,8 +395,6 @@ void DLink::connectSignal(QVariant m_state,
|
||||
{
|
||||
for(int i = 0;i < clientSockets.count();i++)
|
||||
{
|
||||
qDebug() << clientSockets.at(i).addr;
|
||||
|
||||
if(clientSockets.at(i).addr == QHostAddress(m_Param3.toString()))
|
||||
{
|
||||
clientSockets.removeAt(i);
|
||||
@@ -397,7 +455,7 @@ bool DLink::setupClient(const QHostAddress &local_addr,int local_port,const QHos
|
||||
connect(Clientsock, SIGNAL(readyRead()),
|
||||
this, SLOT(readPendingDatagramsClient()));
|
||||
|
||||
Node node;
|
||||
clientNode node;
|
||||
node.sock = Clientsock;
|
||||
node.addr = remote_addr;
|
||||
node.port = remote_port;
|
||||
|
||||
+19
-5
@@ -23,10 +23,18 @@ class DLink : public QObject
|
||||
Q_OBJECT
|
||||
//Q_DECLARE_PRIVATE(DLink)
|
||||
|
||||
struct Node{
|
||||
enum devtype{
|
||||
ganeral = 0,
|
||||
datalink,
|
||||
remote,
|
||||
rtk
|
||||
};
|
||||
|
||||
struct clientNode{
|
||||
QUdpSocket * sock;
|
||||
QHostAddress addr;
|
||||
quint16 port;
|
||||
devtype type;
|
||||
};
|
||||
|
||||
struct serialNode{
|
||||
@@ -34,17 +42,23 @@ class DLink : public QObject
|
||||
QString name;
|
||||
qint32 baud;
|
||||
QSerialPort::Parity parity;
|
||||
devtype type;
|
||||
};
|
||||
|
||||
|
||||
|
||||
public:
|
||||
explicit DLink(QObject *parent = nullptr);
|
||||
~DLink();
|
||||
|
||||
bool setupPort(const QString port, qint32 baudrate, QSerialPort::Parity parity);
|
||||
bool statesPort();
|
||||
void stopPort();
|
||||
//bool statesPort(const QString name);
|
||||
//void stopPort(const QString name);
|
||||
|
||||
bool PortSetup(const QString port, qint32 baud, QSerialPort::Parity parity, const char *method);
|
||||
|
||||
bool PortState(const QString name);
|
||||
|
||||
bool PortStop(const QString name);
|
||||
|
||||
bool setup_remote(const QString port, qint32 baud, QSerialPort::Parity parity);
|
||||
bool setup_rtk(const QString port, qint32 baudrate, QSerialPort::Parity parity);
|
||||
@@ -127,7 +141,7 @@ protected:
|
||||
QSerialPort *serialPortRemote = nullptr;
|
||||
QSerialPort *serialPortRTK = nullptr;
|
||||
|
||||
QList<Node> clientSockets;
|
||||
QList<clientNode> clientSockets;
|
||||
QList<serialNode> serials;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user