Index: sources/canbus/MessageInterpreter.cpp =================================================================== diff -u -rf91ee3bac4f77fc7a0fe8d122c8c49b34b6984ec -rc0b30f1fa82d0121706351057ab52b3bb1141459 --- sources/canbus/MessageInterpreter.cpp (.../MessageInterpreter.cpp) (revision f91ee3bac4f77fc7a0fe8d122c8c49b34b6984ec) +++ sources/canbus/MessageInterpreter.cpp (.../MessageInterpreter.cpp) (revision c0b30f1fa82d0121706351057ab52b3bb1141459) @@ -19,7 +19,9 @@ // #include // Project +#include "Logger.h" #include "format.h" +#include "Settings.h" using namespace Can; @@ -30,7 +32,7 @@ // would be better later to be replaced by a template method // like the notify method of received messages #define INTERPRET_TRANSMIT_MESSAGE(vMODEL) \ - if ( ! length ) { logInvalidLength(); return false; } \ + if ( ! length ) { logInvalidLength(vActionId); return false; } \ vCanId = vMODEL::canid(); \ vPayload = Format::fromVariant(vData); \ LOG_APPED_MSG(vActionId, vMODEL::toString(vData)); \ @@ -39,7 +41,7 @@ // another version of the INTERPRET_TRANSMIT_MESSAGE for empty messages // same later improvements apply to this MACRO as well. #define INTERPRET_TRSMT_MT_MESSAGE(vMODEL) \ - if ( length ) { logInvalidLength(); return false; } \ + if ( length ) { logInvalidLength(vActionId); return false; } \ vCanId = vMODEL::canid(); \ vPayload = Format::fromVariant(vData); \ LOG_APPED_MSG(vActionId, vMODEL::toString(vData)); \ @@ -69,6 +71,7 @@ { bool ok = false; TModel tModel; + if ( ! isValidMessage(vMessage) ) return ok; ok = tModel.fromByteArray(vMessage.data); tModel.toVariantList(vData); // disabled coco begin validated : Tested manually. This code will never go false @@ -77,8 +80,8 @@ if ( ! ok ) return false; // disabled coco end emit didActionReceive(tModel.data()); - //LOG_APPED_MSG(vIdCheck, tModel.toString()); // TODO is this needed? - //DEBUG_SIGNAL(vIdCheck, typeid(TModel).name()) // TODO is this needed? + //LOG_APPED_MSG("0","0"); + DEBUG_SIGNAL(0, typeid(TModel).name()) return ok; } @@ -117,17 +120,16 @@ */ bool MessageInterpreter::isPayloadLenValid(const Message &vMessage) const { + Q_UNUSED(vMessage); + /* int len = vMessage.data.length(); - QString mActionIdHexString = Format::toHexString(0); - Q_UNUSED(mActionIdHexString); - Q_UNUSED(len); - qDebug() << "In paylod valid"; - /*if ( ! payloadLen.contains(vType) ) { - LOG_DEBUG(QString("Undefined data length for received Message with ID '%1'").arg(mActionIdHexString)); // TODO is this needed? + QString mActionIdHexString = Format::toHexString(vMessage.actionId); + if ( ! payloadLen.contains(vType) ) { + LOG_DEBUG(QString("Undefined data length for received Message with ID '%1'").arg(mActionIdHexString)); return false; } if ( len < payloadLen[vType] ) { - LOG_DEBUG(QString("Incorrect data length (%2 of %3) for received Message with ID '%1'") // TODO is this needed? + LOG_DEBUG(QString("Incorrect data length (%2 of %3) for received Message with ID '%1'") .arg(mActionIdHexString) .arg(len) .arg(payloadLen[vType]) @@ -145,9 +147,10 @@ */ void MessageInterpreter::logInvalidLength() { - qDebug() << "Paylod invalid"; - //LOG_DEBUG(QString("Incorrect data length for transmit message with ID '%1'") - // .arg(mActionIdHexString)); // TODO is this needed? + quint8 vActionId = 0; + QString mActionIdHexString = Format::toHexString(vActionId); + LOG_DEBUG(QString("Incorrect data length for transmit message with ID '%1'") + .arg(mActionIdHexString)); } /*! @@ -159,10 +162,8 @@ */ bool MessageInterpreter::isValidMessage(const Message &vMessage) const { - qDebug() << "Is valid message"; - Q_UNUSED(vMessage); - //if ( ! isType (vMessage, vType) ) return false; - //if ( ! isPayloadLenValid(vMessage, vType) ) return false; + if ( ! isType (vMessage) ) return false; + if ( ! isPayloadLenValid(vMessage) ) return false; return true; } @@ -176,14 +177,14 @@ void MessageInterpreter::printUnhandled(const Message &vMessage) const { if ( logUnhandledMessage(vMessage)) return; // the message is defined as unhandled and can still be handled and logged, return. - //if ( gDisableUnhandledReport ) return; // if the unhandled message error has been disabled, return. - QString mActionIdHexString = Format::toHexString(0, false, 0); + if ( gDisableUnhandledReport ) return; // if the unhandled message error has been disabled, return. + QString mActionIdHexString = Format::toHexString(vMessage.actionId, false, eLenMessageIDDigits); QString logMessage = tr("Unhandled Message ID (HD)") + '\n' + QString("%1 # %2 %3") - .arg(int(0), 3, 16, QChar('0')) + .arg(int(vMessage.can_id), 3, 16, QChar('0')) .arg(mActionIdHexString) .arg(QString(vMessage.data.toHex('.'))).toUpper(); - //LOG_DEBUG(logMessage); // TODO is this needed? + LOG_DEBUG(logMessage); } /*! @@ -200,12 +201,12 @@ */ bool MessageInterpreter::interpretMessage(const QVariantList &vData, QByteArray &vPayload, Can_Id &vCanId) { - qDebug() << "Interpret"; - Q_UNUSED(vData); bool ok = true; if (vCanId == Can::Can_Id::eChlid_NONE ) vCanId = Can::Can_Id::eChlid_UI_HD ; vPayload.clear(); + int length = vData.length(); + Q_UNUSED(length); return ok; } @@ -306,14 +307,19 @@ bool MessageInterpreter::interpretMessage(const Message &vMessage, QVariantList &vData) { bool ok = false; - Q_UNUSED(vData); - qDebug() << "I am called"; - printUnhandled (vMessage ); - //switch (identifySource(vMessage.can_id)) { - //case Can_Source::eCan_HD: ok = interpretMessage_HD(vMessage, vData); break; - //case Can_Source::eCan_DG: ok = interpretMessage_DG(vMessage, vData); break; - //default : printUnhandled (vMessage ); break; // ok is false, the individual interpreters for ?HD/DG should not be called, and it should be done here. - //} + + if ( ! gLogUnhandledOnly ) { + switch (identifySource(vMessage.can_id)) { + case Can_Source::eCan_HD: ok = interpretMessage_HD(vMessage, vData); break; + case Can_Source::eCan_DG: ok = interpretMessage_DG(vMessage, vData); break; + default : printUnhandled (vMessage ); qDebug() << "2" <<__FUNCTION__; break; // ok is false, the individual interpreters for ?HD/DG should not be called, and it should be done here. + } + } + else { + Q_UNUSED (vData ); + printUnhandled (vMessage ); + qDebug() << "1" <<__FUNCTION__; + } return ok; } @@ -334,11 +340,9 @@ { bool ok = false; vData.clear(); + Q_UNUSED(vMessage); + // TODO print unhandled? - // unhandled messages: these will only be logged as received message - // there has nothing been defined for these messages. - printUnhandled(vMessage); - return ok; } @@ -359,7 +363,8 @@ { bool ok = false; vData.clear(); - printUnhandled(vMessage); + Q_UNUSED(vMessage); + // TODO print unhandled? return ok; } @@ -403,8 +408,17 @@ */ void MessageInterpreter::updateUnhandledMessages() { - // TODO is this needed? - qDebug() << "Update"; + QString category = Storage::Settings_Category_MessagesUnhandled; + QStringList groups = _Settings.groups(category); + qDebug() << "cat"; + // DEBUG: qDebug() << groups; + for(const auto &group: qAsConst(groups)) { + bool ok; + quint16 id = QString(group).toUInt(&ok,16); + if (!ok) continue; + _messageList[ id ] = _Settings.keys(category, group); + // DEBUG: qDebug() << _Settings.keys(group); + } } /*! @@ -415,8 +429,9 @@ */ bool MessageInterpreter::logUnhandledMessage(const Message &vMessage) const { bool ok = false; - quint16 id = 0; // TODO what is instead? + quint16 id = vMessage.actionId; QString logString = QString("%1,").arg(id,4,16); + qDebug() << "ID" << logString; if (_messageList.contains(id)) { ok = true; QStringList items = _messageList[id]; @@ -475,13 +490,13 @@ } } } - //LOG_APPED(logString); // TODO is this needed? - qDebug() << "H" + logString; + LOG_APPED(logString); + qDebug() << "Message" << logString; } else { - //if ( gDisableUnhandledReport ) { // if the unhandled message error has been disabled, return. - // LOG_DEBUG(QString("Undefined unhandled message [%1]").arg(id, 0, 16)); - //} // TODO is this needed? + if ( gDisableUnhandledReport ) { // if the unhandled message error has been disabled, return. + LOG_DEBUG(QString("Undefined unhandled message [%1]").arg(id, 0, 16)); + } } return ok; }