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 <low-can/can-message.hpp>
31 /// @brief A compact representation of a single CAN message, meant to be used in in/out
32 /// buffers. It is a wrapper of a can_frame struct with some sugar around it for binding purposes.
35 uint32_t maxdlen_; ///< maxdlen_ - Max data length deduce from number of bytes read from the socket.*/
36 uint32_t length_; ///< length_ - the length of the data array. */
37 uint32_t flags_; ///< format_ - the format mask of the message that control which socketcan will used*/
38 std::vector<uint8_t> data_; ///< data_ - The message's data field with a size of 8 which is the standard about CAN bus messages.*/
39 uint64_t timestamp_; ///< timestamp_ - timestamp of the received message*/
40 int sub_id_; ///< sub_id_ - Subscription index. */
44 message_t(uint32_t maxdlen, uint32_t length, uint32_t flags, std::vector<uint8_t>& data, uint64_t timestamp);
45 virtual ~message_t() = default;
47 int get_sub_id() const;
48 const uint8_t* get_data() const;
49 const std::vector<uint8_t> get_data_vector() const;
50 uint32_t get_length() const;
51 uint64_t get_timestamp() const;
53 void set_data(std::vector<uint8_t> data);
54 void set_sub_id(int sub_id);
55 void set_timestamp(uint64_t timestamp);
56 virtual bool is_set() = 0;
57 virtual std::string get_debug_message() = 0;
58 virtual uint32_t get_id() const = 0;
59 virtual void set_id(canid_t id) = 0;
61 void set_flags(uint32_t flags);
63 uint32_t get_maxdlen();
64 void set_maxdlen(uint32_t maxdlen);
65 void set_length(uint32_t length);