-
Notifications
You must be signed in to change notification settings - Fork 0
/
candump_carcan.cpp
178 lines (149 loc) · 4.36 KB
/
candump_carcan.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include <iostream>
#include <memory>
#include <unordered_set>
#include <boost/exception/diagnostic_information.hpp>
#include <class_loader/class_loader.hpp>
#include <socketcan_interface/socketcan.h>
using namespace can;
#include <iostream>
int rtflag=0;
int statecommand=0;
int act_state=0;
int auto_mode_active=0;
int zero =0;
int throttle_pos=0;
int act_gear=0;
int temp;
float veh_speed=0.0;
float wheel_ang=0.0;
float veh_spd_ref=0.0;
float serv_comm=0.0;
float serv_sens=0.0;
float steer_ang=0.0;
float nissan_veh_speed=0.0;
float WSpd_FR=0.0;
float WSpd_FL=0.0;
float WSpd_RR=0.0;
float WSpd_RL=0.0;
void print_error(const State & s);
void print_frame(const Frame &f){
switch((int) f.id){
case 0x2 :
temp = f.data[0];
steer_ang = temp*256;
temp = f.data[1];
steer_ang += temp;
steer_ang = steer_ang/10/4684.8;
std::cout << "Steering angle = " << steer_ang << "°" << std::endl;
break;
case 0x11 :
rtflag = f.data[0];
statecommand = f.data[1];
std::cout << "RT flag = " << "\t" << rtflag << std::endl;
std::cout << "State command = " << "\t" << statecommand << std::endl;
break;
case 0x12 :
act_state = f.data[1];
std::cout << "Actual state = " << "\t" << act_state << std::endl;
break;
case 0x176 :
temp = f.data[0];
nissan_veh_speed = temp*256;
temp = f.data[1];
nissan_veh_speed += temp;
nissan_veh_speed = nissan_veh_speed/8.570637;
std::cout << "Nissan Veh. speed = " << nissan_veh_speed << " km/h" << std::endl;
break;
case 0x180 :
throttle_pos = 0,5 * (f.data[5]);
std::cout << "Throttle pos = " << "\t" << throttle_pos << " %" << std::endl;
break;
case 0x284 :
temp = f.data[0];
WSpd_FR = temp*16777216;
//std::cout << serv_comm << std::endl;
temp = f.data[1];
WSpd_FR += (temp*65536);
temp = f.data[2];
WSpd_FR += (temp*256);
temp = f.data[3];
WSpd_FR += temp;
temp = f.data[4];
WSpd_FL = temp*16777216;
temp = f.data[5];
WSpd_FL += (temp*65536);
temp = f.data[6];
WSpd_FL += (temp*256);
temp = f.data[7];
WSpd_FL += temp;
std::cout << "WSpeed Front-Right = " << "\t" << WSpd_FR << std::endl;
std::cout << "WSpeed Front-Left = " << "\t" << WSpd_FL << std::endl;
break;
case 0x285 :
temp = f.data[0];
WSpd_RR = temp*16777216;
//std::cout << serv_comm << std::endl;
temp = f.data[1];
WSpd_RR += (temp*65536);
temp = f.data[2];
WSpd_RR += (temp*256);
temp = f.data[3];
WSpd_RR += temp;
temp = f.data[4];
WSpd_RL = temp*16777216;
temp = f.data[5];
WSpd_RL += (temp*65536);
temp = f.data[6];
WSpd_RL += (temp*256);
temp = f.data[7];
WSpd_RL += temp;
std::cout << "WSpeed Rear-Right = " << "\t" << WSpd_RR << std::endl;
std::cout << "WSpeed Rear-Left = " << "\t" << WSpd_RL << std::endl;
break;
case 0x421 :
act_gear = f.data[0];
std::cout << "Actual Gear = " << "\t" << act_gear << std::endl;
break;
default:
//std::cout << "Not defined CAN message recieved!" << std::endl;
;
}
}
std::shared_ptr<class_loader::ClassLoader> g_loader;
DriverInterfaceSharedPtr g_driver;
void print_error(const State & s){
std::string err;
g_driver->translateError(s.internal_error,err);
std::cout << "ERROR: state=" << s.driver_state << " internal_error=" << s.internal_error << "('" << err << "') asio: " << s.error_code << std::endl;
}
int main(int argc, char *argv[]){
if(argc != 2 && argc != 4){
std::cout << "usage: "<< argv[0] << " DEVICE [PLUGIN_PATH PLUGIN_NAME]" << std::endl;
return 1;
}
if(argc == 4 ){
try
{
g_loader = std::make_shared<class_loader::ClassLoader>(argv[2]);
g_driver = g_loader->createUniqueInstance<DriverInterface>(argv[3]);
}
catch(std::exception& ex)
{
std::cerr << boost::diagnostic_information(ex) << std::endl;;
return 1;
}
}else{
g_driver = std::make_shared<SocketCANInterface>();
}
FrameListenerConstSharedPtr frame_printer = g_driver->createMsgListener(print_frame);
StateListenerConstSharedPtr error_printer = g_driver->createStateListener(print_error);
if(!g_driver->init(argv[1], false)){
print_error(g_driver->getState());
return 1;
}
g_driver->run();
g_driver->shutdown();
g_driver.reset();
g_loader.reset();
return 0;
}