From 35dd0c9c6299f24cecb00d795ae79e15791a2f2f Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Mon, 31 May 2021 17:55:01 +0100 Subject: [PATCH] Fix for crashing pty on mac --- audiohandler.cpp | 1 + pttyhandler.cpp | 19 ++++++++++++++----- udphandler.cpp | 10 +++++++--- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/audiohandler.cpp b/audiohandler.cpp index 5441db3..1b3e001 100644 --- a/audiohandler.cpp +++ b/audiohandler.cpp @@ -145,6 +145,7 @@ bool audioHandler::init(const quint8 bits, const quint8 radioChan, const quint16 wf_resampler_get_ratio(resampler, &ratioNum, &ratioDen); qInfo(logAudio()) << (isInput ? "Input" : "Output") << "wf_resampler_init() returned: " << resample_error << " ratioNum" << ratioNum << " ratioDen" << ratioDen; + qInfo(logAudio()) << (isInput ? "Input" : "Output") << "thread id" << QThread::currentThreadId(); return isInitialized; } diff --git a/pttyhandler.cpp b/pttyhandler.cpp index d24f5f0..f39f904 100644 --- a/pttyhandler.cpp +++ b/pttyhandler.cpp @@ -15,7 +15,7 @@ pttyHandler::pttyHandler(QString pty) { //constructor - if (pty == "" || pty == "None") + if (pty == "" || pty.toLower() == "none") { // Just return if pty is not configured. return; @@ -94,7 +94,7 @@ void pttyHandler::openPort() #ifndef Q_OS_WIN ptDevSlave = QString::fromLocal8Bit(ptsname(ptfd)); - if (portName != "" && portName != "None") + if (portName != "" && portName.toLower() != "none") { if (!QFile::link(ptDevSlave, portName)) { @@ -115,7 +115,16 @@ pttyHandler::~pttyHandler() void pttyHandler::receiveDataFromRigToPtty(const QByteArray& data) { - if (isConnected && (unsigned char)data[2] != (unsigned char)0xE1 && (unsigned char)data[3] != (unsigned char)0xE1) + int fePos=data.lastIndexOf((char)0xfe); + if (fePos>0) + fePos=fePos-1; + else + { + qDebug(logSerial()) << "Invalid command"; + printHex(data,false,true); + } + + if (isConnected && (unsigned char)data.mid(fePos)[2] != (unsigned char)0xE1 && (unsigned char)data.mid(fePos)[3] != (unsigned char)0xE1) { // send to the pseudo port as well // index 2 is dest, 0xE1 is wfview, 0xE0 is assumed to be the other device. @@ -124,7 +133,7 @@ void pttyHandler::receiveDataFromRigToPtty(const QByteArray& data) // 0xE0 = pseudo-term host // 0x00 = broadcast to all //qInfo(logSerial()) << "Sending data from radio to pseudo-terminal"; - sendDataOut(data); + sendDataOut(data.mid(fePos)); } } @@ -258,7 +267,7 @@ void pttyHandler::closePort() delete port; } #else - if (isConnected && portName != "" && portName != "None") + if (isConnected && portName != "" && portName.toLower() != "none") { QFile::remove(portName); } diff --git a/udphandler.cpp b/udphandler.cpp index 701dafa..d2fde85 100644 --- a/udphandler.cpp +++ b/udphandler.cpp @@ -590,7 +590,7 @@ void udpCivData::watchdog() void udpCivData::send(QByteArray d) { - // qInfo(logUdp()) << "Sending: (" << d.length() << ") " << d; + //qInfo(logUdp()) << "Sending: (" << d.length() << ") " << d; data_packet p; memset(p.packet, 0x0, sizeof(p)); // We can't be sure it is initialized with 0x00! p.len = sizeof(p)+d.length(); @@ -642,6 +642,7 @@ void udpCivData::dataReceived() //qInfo(logUdp()) << "Received: " << datagram.data(); QByteArray r = datagram.data(); + switch (r.length()) { case (CONTROL_SIZE): // Control packet @@ -678,7 +679,9 @@ void udpCivData::dataReceived() lastReceived = QTime::currentTime(); if (quint16(in->datalen + 0x15) == (quint16)in->len) { - emit receive(r.mid(0x15)); + //if (r.mid(0x15).length() != 157) + emit receive(r.mid(0x15)); + //qDebug(logUdp()) << "Got incoming CIV datagram" << r.mid(0x15).length(); } } @@ -687,6 +690,7 @@ void udpCivData::dataReceived() } } udpBase::dataReceived(r); // Call parent function to process the rest. + r.clear(); datagram.clear(); @@ -852,7 +856,7 @@ void udpAudio::watchdog() /* Just log it at the moment, maybe try signalling the control channel that it needs to try requesting civ/audio again? */ - qInfo(logUdp()) << " Audio Watchdog: no audio data received for 2s, restart required"; + qInfo(logUdp()) << " Audio Watchdog: no audio data received for 2s, restart required?"; alerted = true; } }