first push
This commit is contained in:
49
MID/Mid_Ble.cpp
Normal file
49
MID/Mid_Ble.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#include "MID/Mid_Ble.h"
|
||||
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
QString Mid_GetBleOpcodeText(quint8 Opcode)
|
||||
{
|
||||
return QStringLiteral("Opcode 0x%1")
|
||||
.arg(Opcode, 2, 16, QLatin1Char('0'))
|
||||
.toUpper();
|
||||
}
|
||||
|
||||
QString Mid_NormalizeBleAddress(const QString& Text)
|
||||
{
|
||||
QString HexText;
|
||||
HexText.reserve(Text.size());
|
||||
|
||||
for (const QChar Character : Text.trimmed())
|
||||
{
|
||||
if (Character.isDigit() ||
|
||||
((Character >= QLatin1Char('a')) && (Character <= QLatin1Char('f'))) ||
|
||||
((Character >= QLatin1Char('A')) && (Character <= QLatin1Char('F'))))
|
||||
{
|
||||
HexText.append(Character.toUpper());
|
||||
}
|
||||
}
|
||||
|
||||
return HexText.size() == 12 ? HexText : QString();
|
||||
}
|
||||
|
||||
QString Mid_FormatBleAddress(const QString& Address)
|
||||
{
|
||||
const QString Normalized = Mid_NormalizeBleAddress(Address);
|
||||
if (Normalized.isEmpty())
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
|
||||
QStringList PartList;
|
||||
for (int Index = 0; Index < Normalized.size(); Index += 2)
|
||||
{
|
||||
PartList.append(Normalized.mid(Index, 2));
|
||||
}
|
||||
return PartList.join(QLatin1Char(':'));
|
||||
}
|
||||
|
||||
bool Mid_IsBleAddressValid(const QString& Address)
|
||||
{
|
||||
return !Mid_NormalizeBleAddress(Address).isEmpty();
|
||||
}
|
||||
Reference in New Issue
Block a user