Index: sources/canbus/messagebuilder.cpp =================================================================== diff -u -r44a85c96ab55e424866ec4cca0270aa218355f82 -rd2035a8728794afeefaa244bf8d1597926d945f5 --- sources/canbus/messagebuilder.cpp (.../messagebuilder.cpp) (revision 44a85c96ab55e424866ec4cca0270aa218355f82) +++ sources/canbus/messagebuilder.cpp (.../messagebuilder.cpp) (revision d2035a8728794afeefaa244bf8d1597926d945f5) @@ -15,6 +15,7 @@ #include "messagebuilder.h" // Qt +#include // Project #include "logger.h" @@ -105,13 +106,13 @@ */ bool MessageBuilder::addActionId(QByteArray &vPayload, Gui::GuiActionType vAction) { - if (vAction != Gui::GuiActionType::Unknown) { + if (vAction != Gui::GuiActionType::ID_Unknown) { quint16 mAction = static_cast(vAction); vPayload += (mAction >> 8) & 0xFF; // high byte vPayload += mAction & 0xFF; // low byte } else { QString mHexString = Format::toHexString(vAction, false, eLenMessageIDDigits); - LOG_ERROR(tr("Incorrect Action ID '%1'").arg(mHexString)); + LOG_DEBUG(QString("Incorrect Action ID '%1'").arg(mHexString)); return false; } return true; @@ -138,9 +139,12 @@ } } if (vData.length() < len) { - QString mHexString = Format::toHexString(vAction, false, eLenMessageIDDigits); - LOG_ERROR(tr("Not enough data has been provided for the Message ID '%1'").arg(mHexString)); - LOG_ERROR(vData.toHex('.')); + QString mHexMIdString = Format::toHexString(vAction, false, eLenMessageIDDigits); + QString mHexDatString = vData.toHex('.').toUpper(); + LOG_DEBUG(QString("Not enough data has been provided for the Message ID '%1'\r\n%2") + .arg(mHexMIdString) + .arg(mHexDatString) + ); return false; } vPayload += len; @@ -227,7 +231,7 @@ quint8 mBeenRead = 0; if ( ! checkCRC(crcData, mExpected, mBeenRead ) ) { // CRC is always next byte after Data static quint64 erCRC = 0; - LOG_ERROR(tr("%1 - CRC error, expected %2 but got %3 : %4") + LOG_DEBUG(QString("%1 - CRC error, expected %2 but got %3 : %4") .arg(++erCRC) .arg(Format::toHexString(mExpected, true, eLenCRCDigits)) .arg(Format::toHexString(mBeenRead, true, eLenCRCDigits)) @@ -257,12 +261,12 @@ vMessage.can_id = vCan_Id; vMessage.head = getHeader (mPayload); // keep header before taking it out of the payload. doesn't affect payload vMessage.sequence = getSequence (mPayload); - vMessage.actionId = getActionId (mPayload); + vMessage.actionId = static_cast(getActionId(mPayload)); vMessage.length = getLength (mPayload); vMessage.data = getData (mPayload, vMessage.length); vMessage.initialized = true; } else { // Expected Header but got pure data - LOG_ERROR(tr("Expected Header, got frame without Sync byte")); + LOG_DEBUG(QString("Expected Header, got frame without Sync byte")); printPayload(vPayload, false ,vCan_Id); return false; } @@ -283,6 +287,23 @@ } /*! + * \brief MessageBuilder::enableConsoleOut + * \details + * \param vEnabled + */ +void MessageBuilder::enableConsoleOut(bool vEnabled) { + // coco begin validated: This code meant to be used only for debugging and tested manually + if (_enableConsoleOut == vEnabled) return; + _enableConsoleOut = vEnabled; + if (_enableConsoleOut) { + LOG_DEBUG("Console out MessageBuilder enabled"); + } else { + LOG_DEBUG("Console out MessageBuilder disabled"); + } +} +// coco end + +/*! * \brief MessageBuilder::hasSyncByte * \details Checks for Sync byte and take it out of vPayload * \param vPayload - The payload of type QByteArray @@ -337,7 +358,7 @@ { QByteArray headInfo; if (vPayload.length() < eLenHeaderInfo) { - LOG_ERROR("Incorrect Message Header"); + LOG_DEBUG("Incorrect Message Header"); return headInfo; } for (int i = 0; i < eLenHeaderInfo; i++) { @@ -355,12 +376,11 @@ * \note Removes the 2 bytes of ActionID from vPayload * It starts from the first byte so those 2 bytes should be the first 2 bytes. */ -Gui::GuiActionType MessageBuilder::getActionId(QByteArray &vPayload) +quint16 MessageBuilder::getActionId(QByteArray &vPayload) { - quint16 mActionId; - mActionId = (vPayload[0] << 8) | vPayload[1]; + quint16 mActionId = vPayload.mid(0,eLenActionId).toHex().toUInt(0,16); vPayload = vPayload.mid(eLenActionId); - return static_cast(mActionId); + return mActionId; } /*! @@ -464,8 +484,5 @@ void MessageBuilder::consoleOut(const QByteArray &vPayload, bool vIsHeader, Can_Id vCan_Id, bool vUseColor) { if ( ! _enableConsoleOut) return; - - LOG_EVENT_ONCE(QObject::tr("console out MessageDispatcher Enabled")); - printPayload(vPayload, vIsHeader, vCan_Id, vUseColor); }