kopia lustrzana https://gitlab.com/eliggett/wfview
Fix for crash on MacOS
rodzic
87cf5ec8e4
commit
ff4ec65a0f
|
@ -15,10 +15,15 @@
|
||||||
pttyHandler::pttyHandler(QString pty)
|
pttyHandler::pttyHandler(QString pty)
|
||||||
{
|
{
|
||||||
//constructor
|
//constructor
|
||||||
|
if (pty == "" || pty == "None")
|
||||||
|
{
|
||||||
|
// Just return if pty is not configured.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
portName = pty;
|
portName = pty;
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
port = new QSerialPort();
|
|
||||||
// TODO: The following should become arguments and/or functions
|
// TODO: The following should become arguments and/or functions
|
||||||
// Add signal/slot everywhere for comm port setup.
|
// Add signal/slot everywhere for comm port setup.
|
||||||
// Consider how to "re-setup" and how to save the state for next time.
|
// Consider how to "re-setup" and how to save the state for next time.
|
||||||
|
@ -36,7 +41,6 @@ void pttyHandler::openPort()
|
||||||
{
|
{
|
||||||
serialError = false;
|
serialError = false;
|
||||||
bool success=false;
|
bool success=false;
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
port = new QSerialPort();
|
port = new QSerialPort();
|
||||||
port->setPortName(portName);
|
port->setPortName(portName);
|
||||||
|
@ -90,7 +94,7 @@ void pttyHandler::openPort()
|
||||||
#ifndef Q_OS_WIN
|
#ifndef Q_OS_WIN
|
||||||
ptDevSlave = QString::fromLocal8Bit(ptsname(ptfd));
|
ptDevSlave = QString::fromLocal8Bit(ptsname(ptfd));
|
||||||
|
|
||||||
if (portName != "" && portName != "none")
|
if (portName != "" && portName != "None")
|
||||||
{
|
{
|
||||||
if (!QFile::link(ptDevSlave, portName))
|
if (!QFile::link(ptDevSlave, portName))
|
||||||
{
|
{
|
||||||
|
@ -111,7 +115,7 @@ pttyHandler::~pttyHandler()
|
||||||
|
|
||||||
void pttyHandler::receiveDataFromRigToPtty(const QByteArray& data)
|
void pttyHandler::receiveDataFromRigToPtty(const QByteArray& data)
|
||||||
{
|
{
|
||||||
if ((unsigned char)data[2] != (unsigned char)0xE1 && (unsigned char)data[3] != (unsigned char)0xE1)
|
if (isConnected && (unsigned char)data[2] != (unsigned char)0xE1 && (unsigned char)data[3] != (unsigned char)0xE1)
|
||||||
{
|
{
|
||||||
// send to the pseudo port as well
|
// send to the pseudo port as well
|
||||||
// index 2 is dest, 0xE1 is wfview, 0xE0 is assumed to be the other device.
|
// index 2 is dest, 0xE1 is wfview, 0xE0 is assumed to be the other device.
|
||||||
|
@ -130,19 +134,20 @@ void pttyHandler::sendDataOut(const QByteArray& writeData)
|
||||||
|
|
||||||
//qDebug(logSerial()) << "Data to pseudo term:";
|
//qDebug(logSerial()) << "Data to pseudo term:";
|
||||||
//printHex(writeData, false, true);
|
//printHex(writeData, false, true);
|
||||||
|
if (isConnected) {
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
bytesWritten = port->write(writeData);
|
bytesWritten = port->write(writeData);
|
||||||
#else
|
#else
|
||||||
bytesWritten = ::write(ptfd, writeData.constData(), writeData.size());
|
bytesWritten = ::write(ptfd, writeData.constData(), writeData.size());
|
||||||
#endif
|
#endif
|
||||||
if (bytesWritten != writeData.length()) {
|
if (bytesWritten != writeData.length()) {
|
||||||
qDebug(logSerial()) << "bytesWritten: " << bytesWritten << " length of byte array: " << writeData.length()\
|
qDebug(logSerial()) << "bytesWritten: " << bytesWritten << " length of byte array: " << writeData.length()\
|
||||||
<< " size of byte array: " << writeData.size()\
|
<< " size of byte array: " << writeData.size()\
|
||||||
<< " Wrote all bytes? " << (bool)(bytesWritten == (qint64)writeData.size());
|
<< " Wrote all bytes? " << (bool)(bytesWritten == (qint64)writeData.size());
|
||||||
|
}
|
||||||
|
mutex.unlock();
|
||||||
}
|
}
|
||||||
mutex.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pttyHandler::receiveDataIn(int fd) {
|
void pttyHandler::receiveDataIn(int fd) {
|
||||||
|
@ -241,7 +246,7 @@ void pttyHandler::closePort()
|
||||||
delete port;
|
delete port;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (portName != "" && portName != "none")
|
if (isConnected && portName != "" && portName != "None")
|
||||||
{
|
{
|
||||||
QFile::remove(portName);
|
QFile::remove(portName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ private:
|
||||||
bool havePt;
|
bool havePt;
|
||||||
QString ptDevSlave;
|
QString ptDevSlave;
|
||||||
|
|
||||||
bool isConnected; // port opened
|
bool isConnected=false; // port opened
|
||||||
mutable QMutex mutex;
|
mutable QMutex mutex;
|
||||||
void printHex(const QByteArray& pdata, bool printVert, bool printHoriz);
|
void printHex(const QByteArray& pdata, bool printVert, bool printHoriz);
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue