Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
@@ -0,0 +1,275 @@
|
||||
// **************************************************************************
|
||||
//
|
||||
// (C) Copyright 2009 Swiss SIMTEC AG
|
||||
//
|
||||
// **************************************************************************
|
||||
//
|
||||
// $HeadURL$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
//
|
||||
// **************************************************************************
|
||||
|
||||
#include "LogViewField.hpp"
|
||||
#include <QtCore/QDateTime>
|
||||
#include "LogViewXdrElement.hpp"
|
||||
#include "LogViewXdrStandardType.hpp"
|
||||
|
||||
namespace N_LogView
|
||||
{
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
LogViewField::LogViewField(const QString& a_name, const E_FieldKind a_kind, const LogViewXdrElement* a_xdrElement)
|
||||
: m_Name(a_name),
|
||||
m_IsRightAligned(false),
|
||||
m_Offset(0),
|
||||
m_Size(0),
|
||||
m_MaxArraySize(0),
|
||||
m_IsDynamicArray(false),
|
||||
m_HasContent(true),
|
||||
m_bDeleteXdr(false),
|
||||
m_Kind(a_kind),
|
||||
m_XdrElement(a_xdrElement),
|
||||
m_logger(getLogger("LogViewField"))
|
||||
{
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
LogViewField::~LogViewField()
|
||||
{
|
||||
for (LogViewField *f : qAsConst(m_Child))
|
||||
delete f;
|
||||
if (m_bDeleteXdr)
|
||||
delete m_XdrElement;
|
||||
}
|
||||
|
||||
LogViewField *LogViewField::clone(int arrayIdx) const
|
||||
{
|
||||
LogViewField *f = new LogViewField(*this);
|
||||
f->m_Child.clear();
|
||||
f->m_bDeleteXdr = false;
|
||||
for (auto * c : m_Child)
|
||||
{
|
||||
auto *clonedChild = c->clone(-1);
|
||||
if (arrayIdx >= 0)
|
||||
{
|
||||
QStringList sl = clonedChild->jsonPath();
|
||||
if (sl.size() > 1 && sl.at(sl.size() - 2).startsWith(QStringLiteral("index: ")))
|
||||
{
|
||||
sl[sl.size() - 2] = QStringLiteral("index: %1").arg(arrayIdx);
|
||||
clonedChild->setJsonPath(sl);
|
||||
}
|
||||
}
|
||||
f->addChild(clonedChild);
|
||||
}
|
||||
for (auto &val : f->m_ValueList)
|
||||
val.clear();
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
void LogViewField::addChild(LogViewField* a_child)
|
||||
{
|
||||
if (a_child)
|
||||
m_Child.push_back(a_child);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
void LogViewField::removeLastChild()
|
||||
{
|
||||
if (m_Child.empty())
|
||||
return;
|
||||
delete m_Child.takeLast();
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
LogViewField* LogViewField::child(int arrayIdx)
|
||||
{
|
||||
if (m_Child.size() > arrayIdx)
|
||||
return m_Child.at(arrayIdx);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
void LogViewField::addValue(const QString &value)
|
||||
{
|
||||
m_ValueList.append(value);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
void LogViewField::addValueBinaryHex(const QString &value)
|
||||
{
|
||||
const QByteArray ba = QByteArray::fromHex(value.toLatin1());
|
||||
for (const char c : ba)
|
||||
m_ValueList.append(QString::number(static_cast<unsigned char>(c)));
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Returns the value at position a_index converted to a string.
|
||||
// If the field is a date-time-field, the returned value is
|
||||
// converted to a string containing date and time, execpt when
|
||||
// a_doNotMakeSpecialConversions is set to true, the unix-time
|
||||
// will be returned as value.
|
||||
// ---------------------------------------------------------------
|
||||
QString LogViewField::value(int arrayIdx, const bool a_doNotMakeSpecialConversions) const
|
||||
{
|
||||
if (m_ValueList.size() > arrayIdx)
|
||||
{
|
||||
const QString &ret = m_ValueList.at(arrayIdx);
|
||||
if (!a_doNotMakeSpecialConversions)
|
||||
{
|
||||
if (isDateTimeField())
|
||||
return QDateTime::fromMSecsSinceEpoch(ret.toLongLong() * 1000).toString(QStringLiteral("dd.mm.yy hh:mm:ss.zzz"));
|
||||
if (isMSecsField())
|
||||
return QDateTime::fromMSecsSinceEpoch(ret.toLongLong()).toString(QStringLiteral("dd.mm.yy hh:mm:ss.zzz"));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
int64_t LogViewField::getHighestValue() const
|
||||
{
|
||||
switch (m_XdrElement->getKind())
|
||||
{
|
||||
case LogViewXdrElement::e_KindStandardType:
|
||||
{
|
||||
int64_t highest = 1;
|
||||
//const LogViewXdrStandardType* xdrStandardType = static_cast<const LogViewXdrStandardType*>(m_XdrElement);
|
||||
uint16_t bitSize = 8*static_cast<const LogViewXdrStandardType*>(m_XdrElement)->getEditSize();
|
||||
// fixme: mache configurierbar
|
||||
if ((0 == m_Name.compare(QLatin1String("utm nordwert"), Qt::CaseInsensitive)) ||
|
||||
(0 == m_Name.compare(QLatin1String("utm ostwert"), Qt::CaseInsensitive)))
|
||||
bitSize -= 8;
|
||||
|
||||
switch (static_cast<const LogViewXdrStandardType*>(m_XdrElement)->getValueKind()) {
|
||||
case LogViewXdrStandardType::e_Boolean:
|
||||
return 1;
|
||||
case LogViewXdrStandardType::e_Signed:
|
||||
bitSize--;
|
||||
Q_FALLTHROUGH();
|
||||
case LogViewXdrStandardType::e_Unsigned:
|
||||
case LogViewXdrStandardType::e_Data:
|
||||
highest = highest << bitSize;
|
||||
highest--;
|
||||
break;
|
||||
default:
|
||||
highest = 0;
|
||||
break;
|
||||
}
|
||||
return highest;
|
||||
}
|
||||
default:
|
||||
ERROR_LOG(m_logger) << "Case not implemented";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
int64_t LogViewField::getLowestValue() const
|
||||
{
|
||||
switch (m_XdrElement->getKind())
|
||||
{
|
||||
case LogViewXdrElement::e_KindStandardType:
|
||||
{
|
||||
int64_t lowest = 0;
|
||||
//const LogViewXdrStandardType* xdrStandardType = static_cast<const LogViewXdrStandardType*>(a_field->getXdrElement());
|
||||
switch (static_cast<const LogViewXdrStandardType*>(m_XdrElement)->getValueKind()) {
|
||||
case LogViewXdrStandardType::e_Boolean:
|
||||
return 0;
|
||||
case LogViewXdrStandardType::e_Signed:
|
||||
lowest = getHighestValue() + 1;
|
||||
lowest = -lowest;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return lowest;
|
||||
}
|
||||
default:
|
||||
ERROR_LOG(m_logger) << "Case not implemented";
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
void LogViewField::dump(const QString &a_indent) const
|
||||
{
|
||||
INFO_LOG(m_logger) << a_indent << "[";
|
||||
INFO_LOG(m_logger) << a_indent << "Field[" << m_Name << "]: m_Kind=" << m_Kind << " m_Offset=" << m_Offset << " m_Size=" << m_Size << " m_MaxArraySize=" << m_MaxArraySize << " m_IsRightAligned=" << m_IsRightAligned << " m_IsDynamicArray=" << m_IsDynamicArray << " m_ToolTipText=" << m_ToolTipText;
|
||||
// m_XdrElement->dump();
|
||||
for (int i=0; i<m_ValueList.size(); i++)
|
||||
INFO_LOG(m_logger) << a_indent << "m_Value[" << i << "]=" << m_ValueList[i];
|
||||
|
||||
for (auto *c : m_Child)
|
||||
c->dump(a_indent + QLatin1Char(' '));
|
||||
|
||||
INFO_LOG(m_logger) << a_indent << "]";
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Makes the text <a_uncleanText> pretty for human readable.
|
||||
// It does following:
|
||||
// - generates umlaute (ä, ö, ü)
|
||||
// - removes _rt at end
|
||||
// - replaces _ with space
|
||||
// - uppercase of every word
|
||||
// ---------------------------------------------------------------
|
||||
QString LogViewField::makeClean(const QString &text)
|
||||
{
|
||||
QString a_uncleanText = text;
|
||||
// remove _rt at end
|
||||
if (a_uncleanText.endsWith(QLatin1String("_rt")))
|
||||
a_uncleanText = a_uncleanText.left(a_uncleanText.length() - 3);
|
||||
|
||||
// replace _ with space
|
||||
a_uncleanText = a_uncleanText.replace(QLatin1Char('_'), QLatin1Char(' '));
|
||||
|
||||
// first character of every word must be uppercase
|
||||
int pos = 0;
|
||||
while (a_uncleanText.length() > pos)
|
||||
{
|
||||
a_uncleanText[pos] = a_uncleanText[pos].toUpper();
|
||||
pos = a_uncleanText.indexOf(QLatin1Char(' '), pos + 1);
|
||||
if (-1 == pos)
|
||||
break;
|
||||
pos++;
|
||||
}
|
||||
|
||||
return a_uncleanText;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// returns true if the field is a date-time
|
||||
// ---------------------------------------------------------------
|
||||
bool LogViewField::isDateTimeField() const
|
||||
{
|
||||
QString name = m_Name.toLower();
|
||||
return name == QLatin1String("gps_zeit");
|
||||
}
|
||||
|
||||
bool LogViewField::isMSecsField() const
|
||||
{
|
||||
QString name = m_Name.toLower();
|
||||
return (name == QLatin1String("timestamp")) || (name == QLatin1String("effectstart"));
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
void LogViewField::setMaxArraySize(uint16_t newVal, const bool a_isDynamic)
|
||||
{
|
||||
m_MaxArraySize = newVal;
|
||||
m_IsDynamicArray = a_isDynamic;
|
||||
}
|
||||
|
||||
} // namespace N_LogView
|
||||
Reference in new issue
Block a user