2 * Copyright (C) 2015, 2016 "IoT.bzh"
3 * Author "Romain Forlot" <romain.forlot@iot.bzh>
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
25 #include <linux/can.h>
26 #include <linux/can/bcm.h>
27 #include "../../utils/timer.hpp"
29 #define CAN_MESSAGE_SIZE 8
31 #define MAX_BCM_CAN_FRAMES 257
35 * @enum message_format_t
36 * @brief The ID format for a CAN message.
38 enum class message_format_t {
39 STANDARD, ///< STANDARD - standard 11-bit CAN arbitration ID. */
40 EXTENDED, ///< EXTENDED - an extended frame, with a 29-bit arbitration ID. */
41 J1939, ///< J1939 - Format for j1939 messages
42 INVALID, ///< INVALID - INVALID code used at initialization to signify that it isn't usable'*/
48 /// @brief A compact representation of a single CAN message, meant to be used in in/out
49 /// buffers. It is a wrapper of a can_frame struct with some sugar around it for binding purposes.
52 uint32_t maxdlen_; ///< maxdlen_ - Max data length deduce from number of bytes read from the socket.*/
53 uint32_t length_; ///< length_ - the length of the data array. */
54 message_format_t format_; ///< format_ - the format of the message's ID.*/
55 std::vector<uint8_t> data_; ///< data_ - The message's data field with a size of 8 which is the standard about CAN bus messages.*/
56 uint64_t timestamp_; ///< timestamp_ - timestamp of the received message*/
57 int sub_id_; ///< sub_id_ - Subscription index. */
63 message_t(uint32_t maxdlen, uint32_t length, message_format_t format, std::vector<uint8_t>& data, uint64_t timestamp);
64 virtual ~message_t() = default;
66 int get_sub_id() const;
67 const uint8_t* get_data() const;
68 const std::vector<uint8_t> get_data_vector() const;
69 uint32_t get_length() const;
70 uint64_t get_timestamp() const;
72 void set_data(std::vector<uint8_t> &data);
73 void set_sub_id(int sub_id);
74 void set_timestamp(uint64_t timestamp);
75 message_format_t get_msg_format();
76 virtual bool is_set() = 0;
77 virtual std::string get_debug_message() = 0;
78 virtual uint32_t get_id() const = 0;