6dc2221da7b4f1e31efcd99afbb52ea47ec998bb
[apps/agl-service-can-low-level.git] / CAN-binder / low-can-binding / binding / low-can-cb.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 #include <string>
19 #include <cmath>
20 #include <utility>
21
22 #include "../can/can-signals.hpp"
23 #include "../utils/socketcan-bcm.hpp"
24
25 struct event_filter_t
26 {
27         float frequency;
28         float min;
29         float max;
30         event_filter_t() : frequency{NAN}, min{NAN}, max{NAN} {}
31 };
32
33 class low_can_subscription_t
34 {
35 private:
36         int index_;
37
38         /// Signal part
39         std::shared_ptr<can_signal_t> can_signal_;
40
41         /// Filtering part
42         struct event_filter_t event_filter_;
43
44         utils::socketcan_bcm_t socket_;
45 public:
46         low_can_subscription_t();
47         low_can_subscription_t(struct event_filter_t event_filter);
48         low_can_subscription_t(const low_can_subscription_t& s) = delete;
49         low_can_subscription_t(low_can_subscription_t&& s);
50
51         low_can_subscription_t& operator=(const low_can_subscription_t& s);
52         explicit operator bool() const;
53
54         int get_index() const;
55         const std::shared_ptr<can_signal_t> get_can_signal() const;
56         const std::string get_sig_name() const;
57         float get_frequency() const;
58         float get_min() const;
59         float get_max() const;
60         utils::socketcan_bcm_t& get_socket();
61
62         void set_frequency(float freq);
63         void set_min(float min);
64         void set_max(float max);
65
66         int create_rx_filter();
67         int create_rx_filter(std::shared_ptr<can_signal_t> sig);
68 };