9cd10e218878d13a2b4a85a1d8039ed468b2a19d
[apps/agl-service-windowmanager.git] / src / low_can_client.hpp
1 /*
2  * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef TMCAGLWM_LOW_CAN_CLIENT_HPP
18 #define TMCAGLWM_LOW_CAN_CLIENT_HPP
19
20
21 #include <string>
22 #include <vector>
23 #include <json-c/json.h>
24
25
26 namespace wm {
27
28 class LowCanClient {
29
30 public:
31     explicit LowCanClient();
32     ~LowCanClient() = default;
33
34     void initialize();
35     void analyzeCanSignal(struct json_object *object);
36     bool isChangedTransGearState();
37     bool isChangedLampState();
38     bool isChangedParkingBrakeState();
39     bool isChangedAccelPedalState();
40     const char* getCurrentTransGearState();
41     const char* getCurrentLampState();
42     const char* getCurrentParkingBrakeState();
43     const char* getCurrentAccelPedalState();
44
45 private:
46     // Disable copy and move
47     LowCanClient(LowCanClient const &) = delete;
48     LowCanClient &operator=(LowCanClient const &) = delete;
49     LowCanClient(LowCanClient &&) = delete;
50     LowCanClient &operator=(LowCanClient &&) = delete;
51
52     enum TransGearPosVal {
53         TransGearPosValD1 = 1,
54         TransGearPosValD2,
55         TransGearPosValD3,
56         TransGearPosValD4,
57         TransGearPosValD5,
58         TransGearPosValD6,
59         TransGearPosValD7,
60         TransGearPosValD8,
61         TransGearPosValR,
62         TransGearPosValN,
63     };
64
65     enum SignalNo {
66         SignalNoVehicliSpeed = 0,
67         SignalNoTransGearPos,
68         SignalNoHeadlame,
69         SignalNoParkingBrake,
70         SignalNoAccelPedalPos,
71
72         SignalNum,
73
74         SignalNoMin = SignalNoVehicliSpeed,
75         SignalNoMax = SignalNum - 1,
76     };
77
78     const std::vector<const char*> kEventName_{
79         "vehicle.speed",
80         "transmission_gear_position",
81         "headlamp_status",
82         "parking_brake_status",
83         "accelerator.pedal.position",
84     };
85
86     const std::vector<const char*> kFilterValue_{
87         "",
88         "",
89         "",
90         "",
91         "", //"{ \"min\": 0, \"max\": 10}",
92     };
93
94     int vehicle_speed_;
95     int trans_gear_pos_;
96     json_bool headlamp_status_;
97     json_bool parking_brake_status_;
98     double accel_pedal_pos_;
99
100     std::string prv_trans_gear_state_;
101     std::string crr_trans_gear_state_;
102     std::string prv_lamp_state_;
103     std::string crr_lamp_state_;
104     std::string prv_parking_brake_state_;
105     std::string crr_parking_brake_state_;
106     std::string prv_accel_pedal_state_;
107     std::string crr_accel_pedal_state_;
108
109     bool is_changed_trans_gear_state_;
110     bool is_changed_lamp_state_;
111     bool is_changed_parking_brake_state_;
112     bool is_changed_accel_pedal_state_;
113 };
114
115 } // namespace wm
116
117
118 #endif  // TMCAGLWM_LOW_CAN_CLIENT_HPP