Cleaning the code for now unused functions
[apps/agl-service-can-low-level.git] / low-can-binding / can / can-message.hpp
1 /*
2  * Copyright (C) 2015, 2016 "IoT.bzh"
3  * Author "Romain Forlot" <romain.forlot@iot.bzh>
4  *
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
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 #pragma once
19
20 #include <vector>
21 #include <string>
22 #include <cstdint>
23 #include <linux/can.h>
24
25 #include "../utils/timer.hpp"
26
27 #define CAN_MESSAGE_SIZE 8
28
29 /**
30  * @enum can_message_format_t
31  * @brief The ID format for a CAN message.
32  */
33 enum class can_message_format_t {
34         STANDARD, ///< STANDARD - standard 11-bit CAN arbitration ID. */
35         EXTENDED, ///< EXTENDED - an extended frame, with a 29-bit arbitration ID. */
36         INVALID,    ///< INVALID - INVALID code used at initialization to signify that it isn't usable'*/
37 };
38
39 /// @class can_message_t
40 ///
41 /// @brief A compact representation of a single CAN message, meant to be used in in/out
42 /// buffers. It is a wrapper of a can_frame struct with some sugar around it for binding purposes.
43 class can_message_t {
44 private:
45         uint8_t maxdlen_; ///< maxdlen_ - Max data length deduce from number of bytes read from the socket.*/
46         uint32_t id_; ///< id_ - The ID of the message. */
47         uint8_t length_; ///< length_ - the length of the data array (max 8). */
48         can_message_format_t format_; ///< format_ - the format of the message's ID.*/
49         bool rtr_flag_; ///< rtr_flag_ - Telling if the frame has RTR flag positionned. Then frame hasn't data field*/
50         uint8_t flags_; ///< flags_ - flags of a CAN FD frame. Needed if we catch FD frames.*/
51         std::vector<uint8_t> data_; ///< data_ - The message's data field with a size of 8 which is the standard about CAN bus messages.*/
52         uint64_t timestamp_; ///< timestamp_ - timestamp of the received message*/
53         int sub_id_; ///< sub_id_ - Subscription index. */
54
55 public:
56         can_message_t();
57         can_message_t(uint8_t maxdlen, uint32_t id, uint8_t length, can_message_format_t format, bool rtr_flag_, uint8_t flags, std::vector<uint8_t>& data, uint64_t timestamp);
58
59         uint32_t get_id() const;
60         int get_sub_id() const;
61         const uint8_t* get_data() const;
62         const std::vector<uint8_t> get_data_vector() const;
63         uint8_t get_length() const;
64         uint64_t get_timestamp() const;
65
66         void set_sub_id(int sub_id);
67         void set_timestamp(uint64_t timestamp);
68
69         bool is_correct_to_send();
70
71         static can_message_t convert_from_frame(const canfd_frame& frame, size_t nbytes, uint64_t timestamp);
72 };