Index: sources/canbus/CanInterface.cpp =================================================================== diff -u -rc9f8f8cf3c6c37fc6460d8675c62c9442c4d4263 -r20b370a54d2737831b307a0de82aec9e06e2b772 --- sources/canbus/CanInterface.cpp (.../CanInterface.cpp) (revision c9f8f8cf3c6c37fc6460d8675c62c9442c4d4263) +++ sources/canbus/CanInterface.cpp (.../CanInterface.cpp) (revision 20b370a54d2737831b307a0de82aec9e06e2b772) @@ -25,6 +25,7 @@ #include "Logger.h" #include "MessageGlobals.h" #include "FrameInterface.h" +#include "UiSwUpdate.h" // namespace using namespace Can; @@ -230,6 +231,62 @@ } /*! + * \brief Turn CAN driver SW mode on/off. + * + * \param on Turn the mode on (true) or off (false). + */ +void CanInterface::setSWUpdateMode(bool on) +{ + _SWUpdateMode = on; +} + +/*! + * \brief Send from UI. + * + * \param msgId The CAN message Id. + * \param pData The payload data. + * \param length Length in bytes. + */ +bool CanInterface::sendSWUpdateMsg(uint16_t msgId, uint8_t* pData, uint32_t length) +{ + bool ok = false; + + if (_canDevice && _SWUpdateMode) + { + int32_t slength = (int32_t)length; // Use signed math. + ok = true; + std::size_t offset = 0; + while (ok && (slength > 0)) + { + QCanBusFrame frame; + + // Always 8 bytes, zero the remaining. + QByteArray qb((qsizetype)8, (char)0); + uint32_t limit = slength > 8 ? 8 : slength; + + // Fill in the data. + for (std::size_t ii = 0; ii < limit; ii++) { + qb[(uint)ii] = pData[offset + ii]; + } + frame.setFrameId(msgId); + frame.setPayload(qb); + offset += 8; + slength -= 8; + + ok = _canDevice->writeFrame(frame); + { + if (ok) { + _txFrameCount++; + } else { + _erFrameCount++; + } + } + } + } + return ok; +} + +/*! * \brief CanInterface status * \details Sets the Can interface status description * \param vDescription - Description about the CANBus Interface errors @@ -262,7 +319,11 @@ // disabled coco begin validated: Manually tested since required to disable and enable the CANBus if( !_canDevice ) return false; //disabled coco end - return _canDevice->writeFrame(vFrame); + if (_SWUpdateMode) { + return true; + } else { + return _canDevice->writeFrame(vFrame); + } } /*! @@ -410,10 +471,23 @@ const QCanBusFrame frame = _canDevice->readFrame(); rxCount(); // disabled coco begin validated: This code is only for debugging purposes and had been tested manually. - if ( _enableConsoleOut ) + if ( _enableConsoleOut ) { consoleOut(frame, QString("Rx:%1").arg(_rxFrameCount)); - // disabled coco end - emit didFrameReceive(frame); + } + + if (_SWUpdateMode) { + + uint16_t msgId = frame.frameId(); + QByteArray qb = frame.payload(); + + uint8_t* pData = (uint8 *)qb.data(); + + SwUpdate::UiSwUpdate::instance().receive(msgId, pData); + } else { + + // disabled coco end + emit didFrameReceive(frame); + } } } @@ -428,8 +502,9 @@ bool ok = transmit(vFrame); txCount(); // disabled coco begin validated: This code is only for debugging purposes and had been tested manually. - if ( _enableConsoleOut ) + if ( _enableConsoleOut ) { consoleOut(vFrame, QString("Tx:%1").arg(_txFrameCount)); + } // disabled coco end emit didFrameTransmit(ok); }