Index: sources/canbus/messageinterpreter.cpp =================================================================== diff -u -r1732e83d2a0308b9c706f37d6d7724a364bbff2a -r460df093c4475816fc25d6b4c3ebfc50424ccca3 --- sources/canbus/messageinterpreter.cpp (.../messageinterpreter.cpp) (revision 1732e83d2a0308b9c706f37d6d7724a364bbff2a) +++ sources/canbus/messageinterpreter.cpp (.../messageinterpreter.cpp) (revision 460df093c4475816fc25d6b4c3ebfc50424ccca3) @@ -13,6 +13,10 @@ */ #include "messageinterpreter.h" +// Qt + +// Project + using namespace Can; MessageInterpreter::MessageInterpreter(QObject *parent) : QObject(parent) { } @@ -32,7 +36,7 @@ return ok; } -bool MessageInterpreter::interpretAction(const GuiActionType &vActionId, const QVariantList &vData, QByteArray &vPayload) +bool MessageInterpreter::interpretMessage(const GuiActionType &vActionId, const QVariantList &vData, QByteArray &vPayload) { bool ok = true; vPayload.clear(); @@ -44,17 +48,25 @@ if (l >= ix + 1) { quint8 tmp = vData[ix].toUInt(); vPayload += tmp; + } else { + QString mActionIdHexString = GuiActions::toHexString(vActionId); + qDebug() << "ERROR :" << tr("Incorrect data for Message ID (UI) '%1'").arg(mActionIdHexString); + ok = false; } break; case GuiActionType::KeepAlive: + // Nothing needs to be done. + // KeepAlive has No data. + // Mentioned in the switch/case to be registered as a valid message. break; case GuiActionType::String: vPayload = fromVariant(vData[0]); break; default: - qDebug() << "ERROR :" << "Unknown Message ID"; + QString mActionIdHexString = GuiActions::toHexString(vActionId); + qDebug() << "ERROR :" << tr("Unknown Message ID (UI) '%1'").arg(mActionIdHexString); ok = false; break; } @@ -74,32 +86,49 @@ bool MessageInterpreter::interpretMessage_HD(const Message &vMessage, GuiActionType &vActionId, QVariantList &vData) { - bool ok = true; - int l = vMessage.data.length(); - quint8 ix = 0; - quint16 id = static_cast(vActionId); - vActionId = vMessage.actionId; + bool ok = true; + vActionId = vMessage.actionId; vData.clear(); switch (vActionId) { // notice we are in receive mode - case GuiActionType::PowerOff: - ix = static_cast(GuiActionIndx::PowerOff_ShowHide); - if (l >= ix + 1) { - quint8 tmp = vMessage.data[ix]; - vData += tmp; - } else { - qDebug() << "ERROR :" << tr("Incorrect data for MessageId %1").arg(id); - ok = false; + case GuiActionType::PowerOff: { + quint8 mShowHide; + ok = getPowerOffData(vMessage, mShowHide); + if (ok) { + vData += mShowHide; } break; - case GuiActionType::BloodFlow: - ok = false; + } + + case GuiActionType::BloodFlow: { + types::I32 i32 ; + types::F32 f32_1; + types::F32 f32_2; + types::F32 f32_3; + types::F32 f32_4; + types::F32 f32_5; + ok = getBloodFlowData(vMessage, i32, f32_1, f32_2, f32_3, f32_4, f32_5); + if (ok) { + vData += i32 .value; + vData += f32_1.value; + vData += f32_2.value; + vData += f32_3.value; + vData += f32_4.value; + vData += f32_5.value; + } break; - default: - qDebug() << "ERROR :" << "Unknown Message ID"; + } + + case GuiActionType::Alarm: + break; + + default: { + QString mActionIdHexString = GuiActions::toHexString(vMessage.actionId); + qDebug() << "ERROR :" << tr("Unknown Message ID (HD) '%1'").arg(mActionIdHexString); ok = false; break; } + } return ok; } @@ -108,6 +137,87 @@ Q_UNUSED(vMessage ); Q_UNUSED(vActionId); Q_UNUSED(vData ); - // No data have been interpreted from GD yet + // No data have been interpreted from DG yet return false; } + +bool MessageInterpreter::getBloodFlowData(const Message &vMessage, types::I32 &vI32, types::F32 &vF32_1, types::F32 &vF32_2, types::F32 &vF32_3, types::F32 &vF32_4, types::F32 &vF32_5) +{ + if ( vMessage.actionId != GuiActionType::BloodFlow ) { + return false; + } + if ( vMessage.data.length() < payloadLen[GuiActionType::BloodFlow] ) { + QString mActionIdHexString = GuiActions::toHexString(vMessage.actionId); + qDebug() << "ERROR :" << tr("Incorrect data for Message ID (HD) '%1'").arg(mActionIdHexString); + return false; + } + int i = 0; + int p = 0; + int j = 0; + + p += 4; + j = 0; + while (i < p) { + vI32.bytes[j] = vMessage.data[i]; + j++; + i++; + } + + p += 4; + j = 0; + while (i < p) { + vF32_1.bytes[j] = vMessage.data[i]; + j++; + i++; + } + + p += 4; + j = 0; + while (i < p) { + vF32_2.bytes[j] = vMessage.data[i]; + j++; + i++; + } + + p += 4; + j = 0; + while (i < p) { + vF32_3.bytes[j] = vMessage.data[i]; + j++; + i++; + } + + p += 4; + j = 0; + while (i < p) { + vF32_4.bytes[j] = vMessage.data[i]; + j++; + i++; + } + + p += 4; + j = 0; + while (i < p) { + vF32_5.bytes[j] = vMessage.data[i]; + j++; + i++; + } + + return true; +} + +bool MessageInterpreter::getPowerOffData(const Message &vMessage, quint8 &vShowHide) +{ + bool ok = true; + int l = vMessage.data.length(); + quint8 ix = static_cast(GuiActionIndx::PowerOff_ShowHide); + if (l >= ix + 1) { + quint8 tmp = vMessage.data[ix]; + vShowHide = tmp; + } else { + QString mActionIdHexString = GuiActions::toHexString(vMessage.actionId); + qDebug() << "ERROR :" << tr("Incorrect data for Message ID (HD) '%1'").arg(mActionIdHexString); + ok = false; + } + return ok; +}