96adadbc6d6e4900e2ed6fa96c7805261b875177
[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 struct bcm_msg
22 {
23         struct bcm_msg_head msg_head;
24         union {
25                 struct canfd_frame fd_frames[MAX_BCM_CAN_FRAMES];
26                 struct can_frame frames[MAX_BCM_CAN_FRAMES];
27         };
28 };
29
30 /// @class can_message_t
31 ///
32 /// @brief A compact representation of a single CAN message, meant to be used in in/out
33 /// buffers. It is a wrapper of a can_frame struct with some sugar around it for binding purposes.
34 class can_message_t : public message_t {
35         private:
36                 uint32_t id_; ///< id_ - The ID of the message. */
37                 bool rtr_flag_; ///< rtr_flag_ - Telling if the frame has RTR flag positionned. Then frame hasn't data field*/
38                 struct bcm_msg bcm_msg_;
39
40         public:
41                 can_message_t();
42                 can_message_t(  uint32_t maxdlen,
43                                 uint32_t id,
44                                 uint32_t length,
45                                 bool rtr_flag_,
46                                 uint32_t flags,
47                                 std::vector<uint8_t>& data,
48                                 uint64_t timestamp);
49
50                 uint32_t get_id() const;
51                 void set_id(const canid_t id);
52
53                 static std::shared_ptr<can_message_t> convert_from_frame(const canfd_frame& frame, size_t nbytes, uint64_t timestamp);
54                 struct canfd_frame convert_to_canfd_frame();
55                 struct std::vector<canfd_frame> convert_to_canfd_frame_vector();
56                 struct bcm_msg& get_bcm_msg();
57                 void set_bcm_msg(struct bcm_msg bcm_msg);
58
59                 std::string get_debug_message();
60 };