Add feature to build messages and fix some functions
[apps/agl-service-can-low-level.git] / low-can-binding / can / message / 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 #include "./message.hpp"
20
21
22
23 /// @class can_message_t
24 ///
25 /// @brief A compact representation of a single CAN message, meant to be used in in/out
26 /// buffers. It is a wrapper of a can_frame struct with some sugar around it for binding purposes.
27 class can_message_t : public message_t {
28         private:
29                 uint32_t id_; ///< id_ - The ID of the message. */
30                 bool rtr_flag_; ///< rtr_flag_ - Telling if the frame has RTR flag positionned. Then frame hasn't data field*/
31                 uint32_t flags_; ///< flags_ - flags of a CAN FD frame. Needed if we catch FD frames.*/
32                 struct bcm_msg bcm_msg_;
33
34         public:
35                 can_message_t();
36                 can_message_t(uint32_t maxdlen, uint32_t id, uint32_t length, message_format_t format, bool rtr_flag_, uint32_t flags, std::vector<uint8_t>& data, uint64_t timestamp);
37
38                 uint32_t get_id() const;
39
40                 static std::shared_ptr<can_message_t> convert_from_frame(const canfd_frame& frame, size_t nbytes, uint64_t timestamp);
41                 struct canfd_frame convert_to_canfd_frame();
42                 struct can_frame convert_to_can_frame();
43
44                 bool is_correct_to_send();
45                 bool is_set();
46                 struct bcm_msg get_bcm_msg();
47                 void set_bcm_msg(struct bcm_msg bcm_msg);
48
49                 std::string get_debug_message();
50                 uint32_t get_flags();
51 };