274 return ba; |
274 return ba; |
275 } |
275 } |
276 |
276 |
277 /* returns 0 if array doesn't represent a result, |
277 /* returns 0 if array doesn't represent a result, |
278 otherwise returns the length of the result data */ |
278 otherwise returns the length of the result data */ |
279 ushort isValidTrkResult(const QByteArray &buffer, bool serialFrame) |
279 ushort isValidTrkResult(const QByteArray &buffer, bool serialFrame, ushort& mux) |
280 { |
280 { |
281 if (serialFrame) { |
281 if (serialFrame) { |
282 // Serial protocol with length info |
282 // Serial protocol with length info |
283 if (buffer.length() < 4) |
283 if (buffer.length() < 4) |
284 return 0; |
284 return 0; |
285 if (buffer.at(0) != 0x01 || byte(buffer.at(1)) != 0x90) |
285 mux = extractShort(buffer.data()); |
286 return 0; |
|
287 const ushort len = extractShort(buffer.data() + 2); |
286 const ushort len = extractShort(buffer.data() + 2); |
288 return (buffer.size() >= len + 4) ? len : ushort(0); |
287 return (buffer.size() >= len + 4) ? len : ushort(0); |
289 } |
288 } |
290 // Frameless protocol without length info |
289 // Frameless protocol without length info |
291 const char delimiter = char(0x7e); |
290 const char delimiter = char(0x7e); |
292 const int firstDelimiterPos = buffer.indexOf(delimiter); |
291 const int firstDelimiterPos = buffer.indexOf(delimiter); |
293 // Regular message delimited by 0x7e..0x7e |
292 // Regular message delimited by 0x7e..0x7e |
294 if (firstDelimiterPos == 0) { |
293 if (firstDelimiterPos == 0) { |
|
294 mux = MuxTrk; |
295 const int endPos = buffer.indexOf(delimiter, firstDelimiterPos + 1); |
295 const int endPos = buffer.indexOf(delimiter, firstDelimiterPos + 1); |
296 return endPos != -1 ? endPos + 1 - firstDelimiterPos : 0; |
296 return endPos != -1 ? endPos + 1 - firstDelimiterPos : 0; |
297 } |
297 } |
298 // Some ASCII log message up to first delimiter or all |
298 // Some ASCII log message up to first delimiter or all |
299 return firstDelimiterPos != -1 ? firstDelimiterPos : buffer.size(); |
299 return firstDelimiterPos != -1 ? firstDelimiterPos : buffer.size(); |
302 bool extractResult(QByteArray *buffer, bool serialFrame, TrkResult *result, QByteArray *rawData) |
302 bool extractResult(QByteArray *buffer, bool serialFrame, TrkResult *result, QByteArray *rawData) |
303 { |
303 { |
304 result->clear(); |
304 result->clear(); |
305 if(rawData) |
305 if(rawData) |
306 rawData->clear(); |
306 rawData->clear(); |
307 const ushort len = isValidTrkResult(*buffer, serialFrame); |
307 const ushort len = isValidTrkResult(*buffer, serialFrame, result->multiplex); |
308 if (!len) |
308 if (!len) |
309 return false; |
309 return false; |
310 // handle receiving application output, which is not a regular command |
310 // handle receiving application output, which is not a regular command |
311 const int delimiterPos = serialFrame ? 4 : 0; |
311 const int delimiterPos = serialFrame ? 4 : 0; |
312 if (buffer->at(delimiterPos) != 0x7e) { |
312 if (buffer->at(delimiterPos) != 0x7e) { |
313 result->isDebugOutput = true; |
313 result->isDebugOutput = true; |
314 result->data = buffer->mid(delimiterPos, len); |
314 result->data = buffer->mid(delimiterPos, len); |
315 result->data.replace("\r\n", "\n"); |
|
316 *buffer->remove(0, delimiterPos + len); |
315 *buffer->remove(0, delimiterPos + len); |
317 return true; |
316 return true; |
318 } |
317 } |
319 // FIXME: what happens if the length contains 0xfe? |
318 // FIXME: what happens if the length contains 0xfe? |
320 // Assume for now that it passes unencoded! |
319 // Assume for now that it passes unencoded! |
348 { |
347 { |
349 uint res = byte(data[0]); |
348 uint res = byte(data[0]); |
350 res *= 256; res += byte(data[1]); |
349 res *= 256; res += byte(data[1]); |
351 res *= 256; res += byte(data[2]); |
350 res *= 256; res += byte(data[2]); |
352 res *= 256; res += byte(data[3]); |
351 res *= 256; res += byte(data[3]); |
|
352 return res; |
|
353 } |
|
354 |
|
355 SYMBIANUTILS_EXPORT quint64 extractInt64(const char *data) |
|
356 { |
|
357 quint64 res = byte(data[0]); |
|
358 res <<= 8; res += byte(data[1]); |
|
359 res <<= 8; res += byte(data[2]); |
|
360 res <<= 8; res += byte(data[3]); |
|
361 res <<= 8; res += byte(data[4]); |
|
362 res <<= 8; res += byte(data[5]); |
|
363 res <<= 8; res += byte(data[6]); |
|
364 res <<= 8; res += byte(data[7]); |
353 return res; |
365 return res; |
354 } |
366 } |
355 |
367 |
356 SYMBIANUTILS_EXPORT QString quoteUnprintableLatin1(const QByteArray &ba) |
368 SYMBIANUTILS_EXPORT QString quoteUnprintableLatin1(const QByteArray &ba) |
357 { |
369 { |