diff --git a/pttyhandler.cpp b/pttyhandler.cpp index d709de1..63b272a 100644 --- a/pttyhandler.cpp +++ b/pttyhandler.cpp @@ -189,6 +189,18 @@ void pttyHandler::receiveDataIn(int fd) { port->commitTransaction(); #endif + int lastFE = inPortData.lastIndexOf((char)0xfe); + if (civId == 0 && inPortData.length() > lastFE + 2 && (quint8)inPortData[lastFE + 2] > (quint8)0xdf && (quint8)inPortData[lastFE + 2] < (quint8)0xef) { + // This is (should be) the remotes CIV id. + civId = (quint8)inPortData[lastFE + 2]; + qDebug(logSerial()) << "pty detected remote CI-V:" << hex << civId; + } + else if (civId != 0 && inPortData.length() > lastFE + 2 && (quint8)inPortData[lastFE + 2] != civId) + { + civId = (quint8)inPortData[lastFE + 2]; + qDebug(logSerial()) << "pty remote CI-V changed:" << hex << (quint8)civId; + } + // filter 1A 05 01 12/27 = C-IV transceive command before forwarding on. if (inPortData.contains(QByteArrayLiteral("\x1a\x05\x01\x12")) || inPortData.contains(QByteArrayLiteral("\x1a\x05\x01\x27"))) { @@ -200,7 +212,7 @@ void pttyHandler::receiveDataIn(int fd) { sendDataOut(inPortData); // Echo command back sendDataOut(reply); } - else + else if (inPortData.length() > lastFE + 2 && ((quint8)inPortData[lastFE + 1] == civId || (quint8)inPortData[lastFE + 2] == civId)) { emit haveDataFromPort(inPortData); //qDebug(logSerial()) << "Data from pseudo term:"; diff --git a/pttyhandler.h b/pttyhandler.h index c066df2..ac96684 100644 --- a/pttyhandler.h +++ b/pttyhandler.h @@ -67,7 +67,7 @@ private: void printHex(const QByteArray& pdata, bool printVert, bool printHoriz); QSocketNotifier *ptReader = nullptr; - + quint8 civId=0; }; #endif // PTTYHANDLER_H