Commit 6972715a authored by Robert Loehning's avatar Robert Loehning
Browse files

Symbian/trk: Fixed handling of partial frames


Initial-patch-by: default avatarShane Kearns <shane.kearns@accenture.com>
parent a47e06ee
......@@ -363,7 +363,7 @@ void Launcher::handleResult(const TrkResult &result)
logMessage("TEXT TRACE: " + msg);
}
} else {
logMessage("APPLICATION OUTPUT: " + result.data);
logMessage("APPLICATION OUTPUT: " + stringFromArray(result.data));
msg = result.data;
}
msg.replace("\r\n", "\n");
......
......@@ -624,10 +624,11 @@ private:
void readMessages();
QByteArray m_trkReadBuffer;
bool linkEstablishmentMode;
};
ReaderThreadBase::ReaderThreadBase(const QSharedPointer<DeviceContext> &context) :
m_context(context)
m_context(context), linkEstablishmentMode(true)
{
static const int trkResultMetaId = qRegisterMetaType<trk::TrkResult>();
Q_UNUSED(trkResultMetaId)
......@@ -650,7 +651,7 @@ void ReaderThreadBase::readMessages()
{
TrkResult r;
QByteArray rawData;
while (extractResult(&m_trkReadBuffer, m_context->serialFrame, &r, &rawData)) {
while (extractResult(&m_trkReadBuffer, m_context->serialFrame, &r, linkEstablishmentMode, &rawData)) {
emit messageReceived(r, rawData);
}
}
......
......@@ -287,16 +287,26 @@ ushort isValidTrkResult(const QByteArray &buffer, bool serialFrame, ushort& mux)
return firstDelimiterPos != -1 ? firstDelimiterPos : buffer.size();
}
bool extractResult(QByteArray *buffer, bool serialFrame, TrkResult *result, QByteArray *rawData)
bool extractResult(QByteArray *buffer, bool serialFrame, TrkResult *result, bool &linkEstablishmentMode, QByteArray *rawData)
{
result->clear();
if(rawData)
rawData->clear();
const ushort len = isValidTrkResult(*buffer, serialFrame, result->multiplex);
if (!len)
return false;
ushort len = isValidTrkResult(*buffer, serialFrame, result->multiplex);
// handle receiving application output, which is not a regular command
const int delimiterPos = serialFrame ? 4 : 0;
if (linkEstablishmentMode) {
//when "hot connecting" a device, we can receive partial frames.
//this code resyncs by discarding data until a TRK frame is found
while (buffer->length() > delimiterPos
&& result->multiplex != MuxTextTrace
&& !(result->multiplex == MuxTrk && buffer->at(delimiterPos) == 0x7e)) {
buffer->remove(0,1);
len = isValidTrkResult(*buffer, serialFrame, result->multiplex);
}
}
if (!len)
return false;
if (buffer->at(delimiterPos) != 0x7e) {
result->isDebugOutput = true;
result->data = buffer->mid(delimiterPos, len);
......@@ -323,6 +333,7 @@ bool extractResult(QByteArray *buffer, bool serialFrame, TrkResult *result, QByt
//logMessage(" CURR DATA: " << stringFromArray(data));
//QByteArray prefix = "READ BUF: ";
//logMessage((prefix + "HEADER: " + stringFromArray(header).toLatin1()).data());
linkEstablishmentMode = false; //have received a good TRK packet, therefore in sync
return true;
}
......
......@@ -43,7 +43,7 @@ void appendDateTime(QByteArray *ba, QDateTime dateTime, Endianness = TargetByteO
// returns a QByteArray containing optionally
// the serial frame [0x01 0x90 <len>] and 0x7e encoded7d(ba) 0x7e
QByteArray frameMessage(byte command, byte token, const QByteArray &data, bool serialFrame);
bool extractResult(QByteArray *buffer, bool serialFrame, TrkResult *r, QByteArray *rawData = 0);
bool extractResult(QByteArray *buffer, bool serialFrame, TrkResult *r, bool& linkEstablishmentMode, QByteArray *rawData = 0);
} // namespace trk
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment