Index: sources/canbus/messageinterpreter.cpp =================================================================== diff -u -r4c1551d45b40987c2d59c11e95760e9b6c55fc68 -rfee7fabf49befb065c89248c19e15efc9ca194e4 --- sources/canbus/messageinterpreter.cpp (.../messageinterpreter.cpp) (revision 4c1551d45b40987c2d59c11e95760e9b6c55fc68) +++ sources/canbus/messageinterpreter.cpp (.../messageinterpreter.cpp) (revision fee7fabf49befb065c89248c19e15efc9ca194e4) @@ -1,6 +1,6 @@ /*! * - * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. + * Copyright (c) 2019-2019 Diality Inc. - All Rights Reserved. * copyright * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, * IN PART OR IN WHOLE, @@ -21,23 +21,24 @@ using namespace Can; +/*! + * \brief MessageInterpreter::MessageInterpreter + * \param parent + */ MessageInterpreter::MessageInterpreter(QObject *parent) : QObject(parent) { } -bool MessageInterpreter::interpretMessage(const Can_Id vCan_Id, const Message &vMessage, GuiActionType &vActionId, QVariantList &vData) -{ - bool ok = false; - switch (vCan_Id) { - case eChlid_HD: - case eChlid_HD_Alarm: - case eChlid_HD_Sync: - ok = interpretMessage_HD(vMessage, vActionId, vData); - default: - - break; - } - return ok; -} - +/*! + * \brief MessageInterpreter::interpretMessage \n + * \details This method will be called \n + * to interpret messages from UI regarding vActionId. \n + * \param vActionId - The Action Id of type GuiActionType \n + * to be interpreted to hex representation of Message ID. \n + * \param vData - The data which has to be sent over the CANBUS. \n + * \param vPayload - The Payload of the frame of Type QByteArray of hex values \n + * Which has been interpreted from vData of Type QVariantList \n + * \return true if the vActionId is valid. \n + * This return value will be used later for error handling. \n + */ bool MessageInterpreter::interpretMessage(const GuiActionType &vActionId, const QVariantList &vData, QByteArray &vPayload) { bool ok = true; @@ -63,7 +64,7 @@ break; case GuiActionType::String: - vPayload = fromVariant(vData[0]); + vPayload = Format::fromVariant(vData[0]); break; default: @@ -75,17 +76,46 @@ return ok; } -QByteArray MessageInterpreter::fromVariant(const QVariant &vData) +/*! + * \brief MessageInterpreter::interpretMessage \n + * \details This method will call appropriate message interpreter \n + * for received messages from HD or DG regarding the Can_Id. \n + * \param vCan_Id - The Channel Id of the CANBUS frame. \n + * \param vMessage - The complete message of type Message which needs to be interpreted. \n + * \param vActionId - The ActionId of GuiActionType which will be extracted from vMessage. \n + * \param vData - The values of QVariantList which is understandable for UI \n + * and has been extracted from hex values of the CANBUS Message Payload \n + * regarding each Message Id definition. \n + * \return true if the message channel is in the range which can be interpreted, false otherwise. \n + * This return value will be used later to emit MessageDispatcher::didActionReceive signal or not \n + */ +bool MessageInterpreter::interpretMessage(const Can_Id vCan_Id, const Message &vMessage, GuiActionType &vActionId, QVariantList &vData) { - QByteArray mData; - if(vData.type() == QVariant::String) { - mData += vData.toByteArray(); - } else { - mData += vData.toUInt(); + bool ok = false; + switch (vCan_Id) { + case eChlid_HD: + case eChlid_HD_Alarm: + case eChlid_HD_Sync: + ok = interpretMessage_HD(vMessage, vActionId, vData); + default: + break; } - return mData; + return ok; } +/*! + * \brief MessageInterpreter::interpretMessage_HD \n + * \details This method will be called \n + * for received messages from HD to interpret the vMessage of type Message \n + * to vData of type QVariantList which UI understands regarding the Can_Id. \n + * \param vMessage - The complete message of type Message which needs to be interpreted. \n + * \param vActionId - The ActionId of GuiActionType which will be extracted from vMessage. \n + * \param vData - The values of QVariantList which is understandable for UI \n + * and has been extracted from hex values of the CANBUS Message Payload \n + * in vMessage of type Message regarding each Message Id definition. \n + * \return true if the message CANBUS channel is in the range which can be interpreted, false otherwise. \n + * This return value will be used later to emit MessageDispatcher::didActionReceive signal or not \n + */ bool MessageInterpreter::interpretMessage_HD(const Message &vMessage, GuiActionType &vActionId, QVariantList &vData) { bool ok = true; @@ -102,21 +132,21 @@ break; } - 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); + case GuiActionType::BloodFlow: { + types::U32 mFlowSetPoint ; + types::F32 mMeasuredFlow ; + types::F32 mRotorSpeed ; + types::F32 mMotorSpeed ; + types::F32 mMotorCtlSpeed ; + types::F32 mMotorCtlCurrent ; + ok = getBloodFlowData(vMessage, mFlowSetPoint, mMeasuredFlow, mRotorSpeed, mMotorSpeed, mMotorCtlSpeed, mMotorCtlCurrent); 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; + vData += mFlowSetPoint .value; + vData += mMeasuredFlow .value; + vData += mRotorSpeed .value; + vData += mMotorSpeed .value; + vData += mMotorCtlSpeed .value; + vData += mMotorCtlCurrent.value; } break; } @@ -140,6 +170,19 @@ return ok; } +/*! + * \brief MessageInterpreter::interpretMessage_DG \n + * \details This method will be called \n + * for received messages from DG to interpret the vMessage of type Message \n + * to vData of type QVariantList which UI understands regarding the Can_Id. \n + * \param vMessage - The complete message of type Message which needs to be interpreted. \n + * \param vActionId - The ActionId of GuiActionType which will be extracted from vMessage. \n + * \param vData - The values of QVariantList which is understandable for UI \n + * and has been extracted from hex values of the CANBUS Message Payload \n + * in vMessage of type Message regarding each Message Id definition. \n + * \return true if the message CANBUS channel is in the range which can be interpreted, false otherwise. \n + * This return value will be used later to emit MessageDispatcher::didActionReceive signal or not \n + */ bool MessageInterpreter::interpretMessage_DG(const Message &vMessage, GuiActionType &vActionId, QVariantList &vData) { Q_UNUSED(vMessage ); @@ -149,7 +192,20 @@ 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) +/*! + * \brief MessageInterpreter::getBloodFlowData + * \details This is the method which interprets the Blood Flow message data in vMessage of type Message + * to its elements of data. + * \param vMessage - The vMessage of type Message which contains all the data, require to be interpreted. + * \param vFlowSetPoint - Flow Set Point value of type unsigned int extracted out. + * \param vMeasuredFlow - Measured Flow value of type float extracted out + * \param vRotorSpeed - Rotor Speed value of type float extracted out + * \param vMotorSpeed - Motor Speed value of type float extracted out + * \param vMotorCtlSpeed - Motor Controller Speed value of type float extracted out + * \param vMotorCtlCurrent - Motor Controller Current value of type float extracted out + * \return true if the message can be successfully converted to the Blood Flow data elements. + */ +bool MessageInterpreter::getBloodFlowData(const Message &vMessage, types::U32 &vFlowSetPoint, types::F32 &vMeasuredFlow, types::F32 &vRotorSpeed, types::F32 &vMotorSpeed, types::F32 &vMotorCtlSpeed, types::F32 &vMotorCtlCurrent) { if ( vMessage.actionId != GuiActionType::BloodFlow ) { return false; @@ -166,54 +222,64 @@ p += 4; j = 0; while (i < p) { - vI32.bytes[j] = vMessage.data[i]; + vFlowSetPoint.bytes[j] = vMessage.data[i]; j++; i++; } p += 4; j = 0; while (i < p) { - vF32_1.bytes[j] = vMessage.data[i]; + vMeasuredFlow.bytes[j] = vMessage.data[i]; j++; i++; } p += 4; j = 0; while (i < p) { - vF32_2.bytes[j] = vMessage.data[i]; + vRotorSpeed.bytes[j] = vMessage.data[i]; j++; i++; } p += 4; j = 0; while (i < p) { - vF32_3.bytes[j] = vMessage.data[i]; + vMotorSpeed.bytes[j] = vMessage.data[i]; j++; i++; } p += 4; j = 0; while (i < p) { - vF32_4.bytes[j] = vMessage.data[i]; + vMotorCtlSpeed.bytes[j] = vMessage.data[i]; j++; i++; } p += 4; j = 0; while (i < p) { - vF32_5.bytes[j] = vMessage.data[i]; + vMotorCtlCurrent.bytes[j] = vMessage.data[i]; j++; i++; } return true; } +/*! + * \brief MessageInterpreter::getPowerOffData \n + * \details This is the method which interprets the PowerOff message data \n + * in vMessage of type Message. \n + * to its elements of data. \n + * \param vMessage - The vMessage of type Message which contains all the data, \n + * require to be interpreted. \n + * \param vShowHide - The return value of extracted fro \n + * \return true if the data can be extracted as defined for PowerOff Message ID \n + */ bool MessageInterpreter::getPowerOffData(const Message &vMessage, quint8 &vShowHide) { bool ok = true; @@ -230,6 +296,13 @@ return ok; } +/*! + * \brief MessageInterpreter::printUnhandled \n + * \details Prints out the formatted string of the vMessage of type Message \n + * In case the Message ID of received CANBUS message \n + * is known to the interpreter but has not been handled/implemented. \n + * \param vMessage - The message contains Unhandled Message ID \n + */ void MessageInterpreter::printUnhandled(const Message &vMessage) { QString mActionIdHexString = Format::toHexString(vMessage.actionId, false, 3);