Bug fix: Always changed flag becomes true when restriction mode is changed
[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     enum SignalNo {
35         SignalNoVehicliSpeed = 0,
36         SignalNoTransGearPos,
37         SignalNoHeadlame,
38         SignalNoParkingBrake,
39         SignalNoAccelPedalPos,
40         SignalNoLightstatusBrake,
41
42         SignalNum,
43
44         SignalNoMin = SignalNoVehicliSpeed,
45         SignalNoMax = SignalNum - 1,
46     };
47
48     const std::vector<const char*> kSignalName{
49         "vehicle.speed",
50         "transmission_gear_position",
51         "headlamp_status",
52         "parking_brake_status",
53         "accelerator.pedal.position",
54         "lightstatus.brake",
55     };
56
57     void initialize();
58     const char* analyzeCanSignal(struct json_object *object);
59
60     int getCurrentTransGearState();
61     bool getCurrentHeadlampState();
62     bool getCurrentParkingBrakeState();
63     double getCurrentAccelPedalPosition();
64     bool getCurrentAccelPedalState();
65     bool getCurrentLightstatusBrakeState();
66
67     bool isChangedAccelPedalState();
68
69 private:
70     // Disable copy and move
71     LowCanClient(LowCanClient const &) = delete;
72     LowCanClient &operator=(LowCanClient const &) = delete;
73     LowCanClient(LowCanClient &&) = delete;
74     LowCanClient &operator=(LowCanClient &&) = delete;
75
76     enum TransGearPosVal {
77         TransGearPosValD1 = 1,
78         TransGearPosValD2,
79         TransGearPosValD3,
80         TransGearPosValD4,
81         TransGearPosValD5,
82         TransGearPosValD6,
83         TransGearPosValD7,
84         TransGearPosValD8,
85         TransGearPosValR,
86         TransGearPosValN,
87     };
88
89     const std::vector<const char*> kFilterValue{
90         "", // vehicle.speed
91         "", // transmission_gear_position
92         "", // headlamp_status
93         "", // parking_brake_status
94         "", // accelerator.pedal.position
95         "", // lightstatus.brake
96     };
97
98     int vehicle_speed;
99     int trans_gear_pos;
100     json_bool headlamp_status;
101     json_bool parking_brake_status;
102     double accel_pedal_pos;
103     bool accel_pedal_stt;
104     json_bool lightstatus_brake_status;
105
106     bool is_changed_accel_pedal_stt;
107 };
108
109 } // namespace wm
110
111
112 #endif  // TMCAGLWM_LOW_CAN_CLIENT_HPP