truck-code
j1939_utils.h
Go to the documentation of this file.
1 
21 #ifndef INCLUDE_JBUS_J1939_UTILS_H_
22 #define INCLUDE_JBUS_J1939_UTILS_H_
23 
24 #include <math.h>
25 #include <stdio.h>
26 #include "utils/common.h" /* BYTE */
27 
28 
29 /* Parameter group numbers for supported messages (pdu_format, pdu_specific) */
30 
31 #define PDU 0x00ff
32 #define TSC1 0x0000
33 #define EXAC 0x000b
34 #define RQST 0xea00
35 #define ERC1 0xf000
36 #define EBC1 0xf001
37 #define ETC1 0xf002
38 #define EEC2 0xf003
39 #define EEC1 0xf004
40 #define ETC2 0xf005
41 #define GFI2 0xfe81
42 #define EI 0xfe92
43 #define FD 0xfebd
44 #define EBC2 0xfebf
45 #define HRVD 0xfec1
46 #define TURBO 0xfedd
47 #define EEC3 0xfedf
48 #define VD 0xfee0
49 #define RCFG 0xfee1
50 #define TCFG 0xfee2
51 #define ECFG 0xfee3
52 #define ETEMP 0xfeee
53 #define PTO 0xfef0
54 #define CCVS 0xfef1
55 #define LFE 0xfef2
56 #define AMBC 0xfef5
57 #define IEC 0xfef6
58 #define VEP 0xfef7
59 #define TF 0xfef8
60 #define RF 0xfefb
63 /* Return values when retrieving and processing J1939 messages. */
64 
65 #define J1939_RECEIVE_FATAL_ERROR -1
67 #define J1939_RECEIVE_MESSAGE_ERROR 0
69 #define J1939_RECEIVE_MESSAGE_VALID 1
73 /* -------------------------------------------------------------------------- */
74 /* -------------------------------------------------------------------------- */
75 /* -------------------------------------------------------------------------- */
76 
77 
78 /* General purpose macros for extracting fields.
79  *
80  * Bit number in these macros for bytes follows convention in J1939 docs.
81  */
82 
83 /* Macros for short (two bit) values */
84 #define BITS87(x) (((x) & 0xc0) >> 6)
85 #define BITS65(x) (((x) & 0x30) >> 4)
86 #define BITS43(x) (((x) & 0x0c) >> 2)
87 #define BITS21(x) ((x) & 0x03)
88 #define HINIBBLE(x) (((x) & 0xf0) >> 4)
89 #define LONIBBLE(x) ((x) & 0x0f)
91 /* Macros for short (two byte) values */
92 #define HIBYTE(x) (((x) & 0xff00) >> 8)
93 #define LOBYTE(x) ((x) & 0xff)
94 #define TWOBYTES(x, y) ((((x) & 0xff) << 8) | (y & 0xff))
96 /* Macros for int (four byte) values */
97 #define BYTE0(x) (((x) & 0xff))
98 #define BYTE1(x) (((x) & 0xff00) >> 8)
99 #define BYTE2(x) (((x) & 0xff0000) >> 16)
100 #define BYTE3(x) (((x) & 0xff000000) >> 24)
101 #define FOURBYTES(a3, a2, a1, a0) \
102  (((a3) & 0xff) << 24) | \
103  (((a2) & 0xff) << 16) | \
104  (((a1) & 0xff) << 8) | \
105  ((a0) & 0xff)
108 /* -------------------------------------------------------------------------- */
109 /* -------------------------------------------------------------------------- */
110 /* -------------------------------------------------------------------------- */
111 
112 
121 extern float percent_0_to_100(int data);
122 
123 
132 extern float percent_0_to_250(int data);
133 
134 
143 extern float percent_m125_to_p125(int data);
144 
145 
157 int gear_m125_to_p125(int data);
158 
159 
168 extern float gear_ratio(int data);
169 
170 
179 extern float pressure_0_to_4000kpa(int data);
180 
181 
190 extern float pressure_0_to_1000kpa(int data);
191 
192 
201 extern float pressure_0_to_500kpa(int data);
202 
203 
212 extern float pressure_0_to_125kpa(int data);
213 
214 
223 extern float pressure_0_to_12kpa(int data);
224 
225 
234 extern float pressure_m250_to_p252kpa(int data);
235 
236 
247 extern float rotor_speed_in_rpm(unsigned short data);
248 
249 
258 extern float distance_in_km(unsigned int data);
259 
260 
269 extern float hr_distance_in_km(unsigned int data);
270 
271 
280 extern float speed_in_rpm_1byte(int data);
281 
282 
291 extern float speed_in_rpm_2byte(int data);
292 
293 
304 extern float wheel_based_mps(int data);
305 
306 
315 extern float wheel_based_mps_relative(int data);
316 
317 
329 extern float cruise_control_set_meters_per_sec(int data);
330 
331 
341 extern float fuel_rate_cm3_per_sec(int data);
342 
343 
352 extern float fuel_economy_meters_per_cm3(int data);
353 
354 
363 extern float torque_in_nm(unsigned short data);
364 
365 
374 extern float time_0_to_25sec(BYTE data);
375 
376 
385 extern float gain_in_kp(int data);
386 
387 
396 extern float temp_m40_to_p210(int data);
397 
398 
408 extern float temp_m273_to_p1735(int data);
409 
410 
421 extern float current_m125_to_p125amp(int data);
422 
423 
434 extern float current_0_to_250amp(int data);
435 
436 
447 extern float voltage(int data);
448 
449 
460 extern float brake_demand(int data);
461 
462 
473 extern float mass_flow(int data);
474 
475 
486 extern float power_in_kw(int data);
487 
488 
489 #endif /* INCLUDE_JBUS_J1939_UTILS_H_ */
float speed_in_rpm_1byte(int data)
Definition: j1939_utils.cpp:116
float temp_m273_to_p1735(int data)
Definition: j1939_utils.cpp:193
float torque_in_nm(unsigned short data)
Definition: j1939_utils.cpp:165
float pressure_0_to_125kpa(int data)
Definition: j1939_utils.cpp:74
float gain_in_kp(int data)
Definition: j1939_utils.cpp:179
float pressure_0_to_4000kpa(int data)
Definition: j1939_utils.cpp:53
float pressure_0_to_1000kpa(int data)
Definition: j1939_utils.cpp:60
float cruise_control_set_meters_per_sec(int data)
Definition: j1939_utils.cpp:144
float pressure_0_to_500kpa(int data)
Definition: j1939_utils.cpp:67
float current_m125_to_p125amp(int data)
Definition: j1939_utils.cpp:200
float voltage(int data)
Definition: j1939_utils.cpp:214
float percent_0_to_100(int data)
Definition: j1939_utils.cpp:14
float rotor_speed_in_rpm(unsigned short data)
Definition: j1939_utils.cpp:95
float percent_0_to_250(int data)
Definition: j1939_utils.cpp:21
float pressure_0_to_12kpa(int data)
Definition: j1939_utils.cpp:81
float temp_m40_to_p210(int data)
Definition: j1939_utils.cpp:186
float time_0_to_25sec(BYTE data)
Definition: j1939_utils.cpp:172
float current_0_to_250amp(int data)
Definition: j1939_utils.cpp:207
unsigned char BYTE
Definition: common.h:39
float wheel_based_mps(int data)
Definition: j1939_utils.cpp:130
float percent_m125_to_p125(int data)
Definition: j1939_utils.cpp:28
float mass_flow(int data)
Definition: j1939_utils.cpp:228
float wheel_based_mps_relative(int data)
Definition: j1939_utils.cpp:137
float pressure_m250_to_p252kpa(int data)
Definition: j1939_utils.cpp:88
float brake_demand(int data)
Definition: j1939_utils.cpp:221
float speed_in_rpm_2byte(int data)
Definition: j1939_utils.cpp:123
float gear_ratio(int data)
Definition: j1939_utils.cpp:46
float distance_in_km(unsigned int data)
Definition: j1939_utils.cpp:102
float fuel_rate_cm3_per_sec(int data)
Definition: j1939_utils.cpp:151
float power_in_kw(int data)
Definition: j1939_utils.cpp:235
float hr_distance_in_km(unsigned int data)
Definition: j1939_utils.cpp:109
int gear_m125_to_p125(int data)
Definition: j1939_utils.cpp:35
float fuel_economy_meters_per_cm3(int data)
Definition: j1939_utils.cpp:158