message: Default frame layout as little endian.
[apps/agl-service-can-low-level.git] / low-can-binding / can / message-definition.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 /**
19  * @class message_definition_t
20  *
21  * @brief The definition of a CAN message. This includes a lot of metadata, so
22  * to save memory this struct should not be used for storing incoming and
23  * outgoing CAN messages.
24  */
25
26 #pragma once
27
28 #include <vector>
29 #include <memory>
30
31 #include "signals.hpp"
32 #include "message-set.hpp"
33 #include "../utils/timer.hpp"
34 #include "message/message.hpp"
35
36 class message_set_t;
37
38 /// @brief The definition of a CAN message. This includes a lot of metadata, so
39 ///  to save memory this class gets the signal_t object related to a CAN message.
40 class message_definition_t
41 {
42 private:
43         std::shared_ptr<message_set_t> parent_; ///< parent_ - Pointer to the CAN message set holding this CAN message definition */
44         std::string bus_; ///< bus_ - Address of CAN bus device. */
45         uint32_t id_; ///< id_ - The ID or the PGN (if j1939) of the message.*/
46         std::string name_; ///< name_ - J1939 PGN name
47         uint32_t length_; ///< length_ - Message data length in bytes. For J1939 message, this is the expected data size
48         uint32_t flags_; ///< format_ - the format of the message's ID.*/
49         frequency_clock_t frequency_clock_; ///<  clock_ - an optional frequency clock to control the output of this
50                                                         ///      message, if sent raw, or simply to mark the max frequency for custom
51                                                         ///      handlers to retrieve.*/
52         bool force_send_changed_; ///< force_send_changed_ - If true, regardless of the frequency, it will send CAN
53                                                         ///     message if it has changed when using raw passthrough.*/
54         std::vector<uint8_t> last_value_; ///< last_value_ - The last received value of the message. Defaults to undefined.
55                                                                                 ///     This is required for the forceSendChanged functionality, as the stack
56                                                                                 ///     needs to compare an incoming CAN message with the previous frame.*/
57         vect_ptr_signal_t signals_; ///< signals_ - Vector holding signal_t object which share the same arbitration ID */
58
59 public:
60         //message_definition_t(const message_definition_t& b);
61         message_definition_t(const std::string bus);
62         message_definition_t(const std::string bus, uint32_t id, frequency_clock_t frequency_clock, bool force_send_changed);
63         message_definition_t(const std::string bus, uint32_t id, uint32_t flags, frequency_clock_t frequency_clock, bool force_send_changed);
64         message_definition_t(const std::string bus,
65                                  uint32_t id,
66                                  uint32_t flags,
67                                  frequency_clock_t frequency_clock,
68                                  bool force_send_changed,
69                                  const vect_ptr_signal_t& signals);
70         message_definition_t(const std::string bus,
71                                  uint32_t id,
72                                  std::string name,
73                                  uint32_t length,
74                                  uint32_t flags,
75                                  frequency_clock_t frequency_clock,
76                                  bool force_send_changed,
77                                  const vect_ptr_signal_t& signals);
78
79
80         const std::string get_bus_name() const;
81         const std::string get_bus_device_name() const;
82         const std::string get_name() const;
83         uint32_t get_id() const;
84         bool is_fd() const;
85         bool is_j1939() const;
86         bool is_isotp() const;
87         vect_ptr_signal_t& get_signals();
88         uint32_t get_length() const;
89         uint32_t get_flags() const;
90         bool frame_layout_is_bigendian() const;
91
92         void set_parent(std::shared_ptr<message_set_t> parent);
93         void set_last_value(std::shared_ptr<message_t>  m);
94 };