Commit 5d4273cc authored by con's avatar con
Browse files

Extract a separate launcher.

parent 4b26aaa3
This diff is collapsed.
TEMPLATE = subdirs
SUBDIRS = trkserver adapter swapendian
SUBDIRS = trkserver adapter swapendian trklauncher.pro
trkserver.file = trkserver.pro
adapter.file = adapter.pro
......
TEMPLATE = app
QT = core network
QT -= gui
win32:CONFIG += console
win32:DEFINES += USE_NATIVE
SOURCES = launcher.cpp \
trkutils.cpp
HEADERS = trkutils.h
......@@ -80,38 +80,38 @@ QByteArray frameMessage(byte command, byte token, const QByteArray &data)
return ba;
}
TrkResult extractResult(QByteArray *buffer)
/* returns 0 if array doesn't represent a result,
otherwise returns the length of the result data */
ushort isValidTrkResult(const QByteArray &buffer)
{
TrkResult result;
if (buffer->at(0) != 0x01 || byte(buffer->at(1)) != 0x90) {
logMessage("*** ERROR READBUFFER INVALID (2): "
<< stringFromArray(*buffer)
<< int(buffer->at(0))
<< int(buffer->at(1))
<< buffer->size());
return result;
if (buffer.length() < 9)
return 0;
if (buffer.at(0) != 0x01 || byte(buffer.at(1)) != 0x90) {
return 0;
}
ushort len = extractShort(buffer->data() + 2);
ushort len = extractShort(buffer.data() + 2);
//logMessage(" READ BUF: " << stringFromArray(*buffer));
if (buffer->size() < len + 4) {
logMessage("*** INCOMPLETE RESPONSE: "
<< stringFromArray(*buffer));
return result;
if (buffer.size() < len + 4) {
return 0;
}
if (byte(buffer->at(4)) != 0x7e) {
logMessage("** ERROR READBUFFER BEGIN FRAME MARKER INVALID: "
<< stringFromArray(*buffer) << len);
return result;
if (byte(buffer.at(4)) != 0x7e) {
return 0;
}
if (byte(buffer->at(4 + len - 1)) != 0x7e) {
logMessage("** ERROR READBUFFER END FRAME MARKER INVALID: "
<< stringFromArray(*buffer) << len);
return result;
if (byte(buffer.at(4 + len - 1)) != 0x7e) {
return 0;
}
return len;
}
TrkResult extractResult(QByteArray *buffer)
{
TrkResult result;
ushort len = isValidTrkResult(*buffer);
if (!len)
return result;
// FIXME: what happens if the length contains 0xfe?
// Assume for now that it passes unencoded!
QByteArray data = decode7d(buffer->mid(5, len - 2));
......
......@@ -35,10 +35,10 @@
#include <QtCore/QString>
#include <QtCore/QVariant>
namespace trk {
typedef unsigned char byte;
namespace trk {
QByteArray decode7d(const QByteArray &ba);
QByteArray encode7d(const QByteArray &ba);
......@@ -149,6 +149,7 @@ struct TrkResult
// returns a QByteArray containing 0x01 0x90 <len> 0x7e encoded7d(ba) 0x7e
QByteArray frameMessage(byte command, byte token, const QByteArray &data);
ushort isValidTrkResult(const QByteArray &buffer);
TrkResult extractResult(QByteArray *buffer);
QByteArray errorMessage(byte code);
QByteArray hexNumber(uint n, int digits = 0);
......
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