Symbian/trk: Fix debugging output for the N8.

1. Fix hanging behaviour when we receive a message on the wrong mux in
framed mode
2. Treat messages on the trace mux (0102) as debug output
3. Separate timestamp from text in trace messages
Initial-patch-by: Shane Kearns <shane.kearns@accenture.com>
This commit is contained in:
Friedemann Kleint
2010-05-11 13:27:07 +02:00
parent 626221b685
commit 8c95dfebbf
3 changed files with 41 additions and 7 deletions

View File

@@ -353,8 +353,22 @@ void Launcher::handleResult(const TrkResult &result)
QByteArray prefix = "READ BUF: "; QByteArray prefix = "READ BUF: ";
QByteArray str = result.toString().toUtf8(); QByteArray str = result.toString().toUtf8();
if (result.isDebugOutput) { // handle application output if (result.isDebugOutput) { // handle application output
logMessage("APPLICATION OUTPUT: " + result.data); QString msg;
emit applicationOutputReceived(result.data); if (result.multiplex == MuxTextTrace) {
if (result.data.length() > 8) {
quint64 timestamp = extractInt64(result.data) & 0x0FFFFFFFFFFFFFFFULL;
quint64 secs = timestamp / 1000000000;
quint64 ns = timestamp % 1000000000;
msg = QString("[%1.%2] %3").arg(secs).arg(ns).arg(QString(result.data.mid(8)));
logMessage("TEXT TRACE: " + msg);
}
} else {
logMessage("APPLICATION OUTPUT: " + result.data);
msg = result.data;
}
msg.replace("\r\n", "\n");
if(!msg.endsWith('\n')) msg.append('\n');
emit applicationOutputReceived(msg);
return; return;
} }
switch (result.code) { switch (result.code) {

View File

@@ -264,14 +264,13 @@ QByteArray frameMessage(byte command, byte token, const QByteArray &data, bool s
/* returns 0 if array doesn't represent a result, /* returns 0 if array doesn't represent a result,
otherwise returns the length of the result data */ otherwise returns the length of the result data */
ushort isValidTrkResult(const QByteArray &buffer, bool serialFrame) ushort isValidTrkResult(const QByteArray &buffer, bool serialFrame, ushort& mux)
{ {
if (serialFrame) { if (serialFrame) {
// Serial protocol with length info // Serial protocol with length info
if (buffer.length() < 4) if (buffer.length() < 4)
return 0; return 0;
if (buffer.at(0) != 0x01 || byte(buffer.at(1)) != 0x90) mux = extractShort(buffer.data());
return 0;
const ushort len = extractShort(buffer.data() + 2); const ushort len = extractShort(buffer.data() + 2);
return (buffer.size() >= len + 4) ? len : ushort(0); return (buffer.size() >= len + 4) ? len : ushort(0);
} }
@@ -280,6 +279,7 @@ ushort isValidTrkResult(const QByteArray &buffer, bool serialFrame)
const int firstDelimiterPos = buffer.indexOf(delimiter); const int firstDelimiterPos = buffer.indexOf(delimiter);
// Regular message delimited by 0x7e..0x7e // Regular message delimited by 0x7e..0x7e
if (firstDelimiterPos == 0) { if (firstDelimiterPos == 0) {
mux = MuxTrk;
const int endPos = buffer.indexOf(delimiter, firstDelimiterPos + 1); const int endPos = buffer.indexOf(delimiter, firstDelimiterPos + 1);
return endPos != -1 ? endPos + 1 - firstDelimiterPos : 0; return endPos != -1 ? endPos + 1 - firstDelimiterPos : 0;
} }
@@ -292,7 +292,7 @@ bool extractResult(QByteArray *buffer, bool serialFrame, TrkResult *result, QByt
result->clear(); result->clear();
if(rawData) if(rawData)
rawData->clear(); rawData->clear();
const ushort len = isValidTrkResult(*buffer, serialFrame); const ushort len = isValidTrkResult(*buffer, serialFrame, result->multiplex);
if (!len) if (!len)
return false; return false;
// handle receiving application output, which is not a regular command // handle receiving application output, which is not a regular command
@@ -300,7 +300,6 @@ bool extractResult(QByteArray *buffer, bool serialFrame, TrkResult *result, QByt
if (buffer->at(delimiterPos) != 0x7e) { if (buffer->at(delimiterPos) != 0x7e) {
result->isDebugOutput = true; result->isDebugOutput = true;
result->data = buffer->mid(delimiterPos, len); result->data = buffer->mid(delimiterPos, len);
result->data.replace("\r\n", "\n");
*buffer->remove(0, delimiterPos + len); *buffer->remove(0, delimiterPos + len);
return true; return true;
} }
@@ -341,6 +340,19 @@ SYMBIANUTILS_EXPORT uint extractInt(const char *data)
return res; return res;
} }
SYMBIANUTILS_EXPORT quint64 extractInt64(const char *data)
{
quint64 res = byte(data[0]);
res <<= 8; res += byte(data[1]);
res <<= 8; res += byte(data[2]);
res <<= 8; res += byte(data[3]);
res <<= 8; res += byte(data[4]);
res <<= 8; res += byte(data[5]);
res <<= 8; res += byte(data[6]);
res <<= 8; res += byte(data[7]);
return res;
}
SYMBIANUTILS_EXPORT QString quoteUnprintableLatin1(const QByteArray &ba) SYMBIANUTILS_EXPORT QString quoteUnprintableLatin1(const QByteArray &ba)
{ {
QString res; QString res;

View File

@@ -123,9 +123,16 @@ enum Command {
TrkDSPositionFile = 0xd4 TrkDSPositionFile = 0xd4
}; };
enum SerialMultiplexor {
MuxRaw = 0,
MuxTextTrace = 0x0102,
MuxTrk = 0x0190
};
inline byte extractByte(const char *data) { return *data; } inline byte extractByte(const char *data) { return *data; }
SYMBIANUTILS_EXPORT ushort extractShort(const char *data); SYMBIANUTILS_EXPORT ushort extractShort(const char *data);
SYMBIANUTILS_EXPORT uint extractInt(const char *data); SYMBIANUTILS_EXPORT uint extractInt(const char *data);
SYMBIANUTILS_EXPORT quint64 extractInt64(const char *data);
SYMBIANUTILS_EXPORT QString quoteUnprintableLatin1(const QByteArray &ba); SYMBIANUTILS_EXPORT QString quoteUnprintableLatin1(const QByteArray &ba);
@@ -205,6 +212,7 @@ struct SYMBIANUTILS_EXPORT TrkResult
int errorCode() const; int errorCode() const;
QString errorString() const; QString errorString() const;
ushort multiplex;
byte code; byte code;
byte token; byte token;
QByteArray data; QByteArray data;