Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
clean serialpackage class
Browse files Browse the repository at this point in the history
  • Loading branch information
MPIBR-tushevg committed Jan 4, 2019
1 parent 1ea29c5 commit 3512e50
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 43 deletions.
45 changes: 7 additions & 38 deletions BrainATUMtome/serialpackage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ QString SerialPackage::parse(bool &ok, const QString &message)

// check received checksum
quint8 checksumReceived = 0;
if (!unpack(checksumReceived, buffer.mid(buffer.size() - 2, 2)))
ok = false;
unpack(checksumReceived, buffer.mid(buffer.size() - 2, 2));

// remove checksum from buffer
buffer.remove(buffer.size() - 2, 2);
Expand All @@ -41,30 +40,6 @@ QString SerialPackage::package(const QString &message)
}


quint8 SerialPackage::address(const QString &message)
{
quint8 value;
if (unpack(value, message.mid(0, 2))) {
return value;
}
else {
return 0;
}
}


quint8 SerialPackage::command(const QString &message)
{
quint8 value;
if (unpack(value, message.mid(2, 2))) {
return value;
}
else {
return 0;
}
}


quint8 SerialPackage::checksum(const QString &message)
{
quint8 valueChecksum = 0;
Expand Down Expand Up @@ -99,27 +74,21 @@ QString SerialPackage::pack(quint32 value)
}


bool SerialPackage::unpack(quint8 &value, const QString &textValue)
void SerialPackage::unpack(quint8 &value, const QString &textValue)
{
bool ok;
value = static_cast<quint8>(textValue.toUInt(&ok, 16));
return ok;
value = static_cast<quint8>(textValue.toUInt(nullptr, 16));
}


bool SerialPackage::unpack(quint16 &value, const QString &textValue)
void SerialPackage::unpack(quint16 &value, const QString &textValue)
{
bool ok;
value = static_cast<quint16>(textValue.toUInt(&ok, 16));
return ok;
value = static_cast<quint16>(textValue.toUInt(nullptr, 16));
}


bool SerialPackage::unpack(quint32 &value, const QString &textValue)
void SerialPackage::unpack(quint32 &value, const QString &textValue)
{
bool ok;
value = static_cast<quint32>(textValue.toUInt(&ok, 16));
return ok;
value = static_cast<quint32>(textValue.toUInt(nullptr, 16));
}


Expand Down
8 changes: 3 additions & 5 deletions BrainATUMtome/serialpackage.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@ class SerialPackage
static QString parse(bool &ok, const QString &message);
static QString package(const QString &message);

static quint8 address(const QString &message);
static quint8 command(const QString &message);
static quint8 checksum(const QString &message);

static QString pack(quint8 value);
static QString pack(quint16 value);
static QString pack(quint32 value);

static bool unpack(quint8 &value, const QString &textValue);
static bool unpack(quint16 &value, const QString &textValue);
static bool unpack(quint32 &value, const QString &textValue);
static void unpack(quint8 &value, const QString &textValue);
static void unpack(quint16 &value, const QString &textValue);
static void unpack(quint32 &value, const QString &textValue);
};

#endif // SERIALPACKAGE_H

0 comments on commit 3512e50

Please sign in to comment.