C

Qt Quick Ultralite Automotive Cluster Demo

/****************************************************************************** ** ** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Quick Ultralite module. ** ** $QT_BEGIN_LICENSE:COMM$ ** ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see http://www.qt.io/terms-conditions. For further ** information use the contact form at http://www.qt.io/contact-us. ** ** $QT_END_LICENSE$ ** ******************************************************************************/
#include "rawcanmessageadapter.h" extern "C" { #include <rscanfd/rscanfd_uciaprcn/rscfd.h> #include <rscanfd/rscanfd_uciaprcn/rscfd_p.h> #include <rscanfd/rscanfd_uciaprcn/rscfd_s.h> } #include <algorithm> namespace CanBus { RawCanMessageAdapter::RawCanMessageAdapter(ee_rscfd_message &rawFrame) : rawMessage(rawFrame) {} const uint8_t *RawCanMessageAdapter::data() const { return static_cast<const uint8_t *>(rawMessage.data); } uint8_t RawCanMessageAdapter::length() const { return static_cast<uint8_t>(rawMessage.flag.dlc); } uint32_t RawCanMessageAdapter::id() const { return static_cast<uint32_t>(rawMessage.hdr.id); } CanBusDevice::CanFrameType RawCanMessageAdapter::type() { if (rawMessage.fdsts.esi) { return CanBusDevice::ErrorFrame; } else if (rawMessage.hdr.rtr) { return CanBusDevice::RemoteRequestFrame; } else { return CanBusDevice::DataFrame; } } RawCanMessageAdapter &RawCanMessageAdapter::setId(uint32_t id) { rawMessage.hdr.id = id; return *this; } RawCanMessageAdapter &RawCanMessageAdapter::setType(CanBusDevice::CanFrameType type) { rawMessage.fdsts.esi = EE_RSCFD_CLEAR; rawMessage.hdr.rtr = EE_RSCFD_CLEAR; switch (type) { case CanBusDevice::ErrorFrame: rawMessage.fdsts.esi = EE_RSCFD_SET; break; case CanBusDevice::RemoteRequestFrame: rawMessage.hdr.rtr = EE_RSCFD_SET; break; } return *this; } RawCanMessageAdapter &RawCanMessageAdapter::setData(const uint8_t *payload, uint8_t payloadLength) { const size_t length = std::min((size_t) payloadLength, sizeof(rawMessage.data)); memcpy(&rawMessage.data[0], payload, length); rawMessage.flag.dlc = length; return *this; } RawCanMessageAdapter &RawCanMessageAdapter::setIsExtended(bool extended) { rawMessage.hdr.ide = extended ? EE_RSCFD_SET : EE_RSCFD_CLEAR; return *this; } RawCanMessageAdapter &RawCanMessageAdapter::setIsCanFD(bool canFD) { rawMessage.fdsts.fdf = canFD ? EE_RSCFD_SET : EE_RSCFD_CLEAR; return *this; } RawCanMessageAdapter &RawCanMessageAdapter::setBitrateSwitch(bool bitrateSwitch) { rawMessage.fdsts.brs = bitrateSwitch ? EE_RSCFD_SET : EE_RSCFD_CLEAR; return *this; } } // namespace CanBus