C

Qt Quick Ultralite Automotive Cluster Demo

/****************************************************************************** ** ** Copyright (C) 2020 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$ ** ******************************************************************************/
#pragma once #include <qul/property.h> #include <qul/singleton.h> #include <qul/signal.h> #include <cstdint> #define CANBUS_MAX_RAW_HANDLERS 1 namespace CanBus { struct CanBusDevice : Qul::Singleton<CanBusDevice> { friend struct Qul::Singleton<CanBusDevice>; enum CanBusDeviceState { UnconnectedState, ConnectingState, ConnectedState, DisconnectingState }; enum CanBusDeviceError { NoError, ReadError, WriteError, ConnectionError, ConfigurationError, UnknownError }; enum CanFrameType { UnknownFrame, DataFrame, ErrorFrame, RemoteRequestFrame, InvalidFrame }; enum FormatFilter { MatchBaseFormat, MatchExtendedFormat, MatchBaseAndExtendedFormat }; typedef void (*RawCanMessageHandler)( uint32_t msgId, CanFrameType type, const uint8_t *paylod, uint8_t payloadLength, void *userData); Qul::Signal<void(CanBusDevice::CanBusDeviceError error)> error; Qul::Property<CanBusDevice::CanBusDeviceState> status; Qul::Property<uint32_t> bitrate; Qul::Property<bool> isCanFD; Qul::Property<uint32_t> dataBitrate; void connect(); void disconnect(); void sendRawMessage(uint32_t msgId, CanFrameType type, const uint8_t *payload, uint8_t payloadLength, bool isExtended = false, bool isCanFD = false, bool bitrateSwitch = false); void appendMessageFilter(uint32_t frameId, uint32_t frameIdMask, FormatFilter format = MatchBaseAndExtendedFormat, CanFrameType type = InvalidFrame); bool registerRawMessageHandler(uint32_t msgId, RawCanMessageHandler handler, void *userData = NULL); bool registerGlobalMessageHandler(RawCanMessageHandler handler, void *userData = NULL); void processPendingData(); protected: CanBusDevice(); CanBusDevice(const CanBusDevice &); CanBusDevice &operator=(const CanBusDevice &); }; } // namespace CanBus