forked from ShunzDai/J1939
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathj1939_config.h
103 lines (90 loc) · 4.48 KB
/
j1939_config.h
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
/**
* Copyright 2022 ShunzDai
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef J1939_CONFIG_H
#define J1939_CONFIG_H
#ifdef __cplusplus
extern "C"{
#endif /* __cplusplus */
#define J1939_PORT_SUSPEND 0
#define J1939_PORT_VIRTUAL 1
#define J1939_PORT_STM32 2
#define J1939_PORT_TYPE J1939_PORT_SUSPEND
#define __J1939_Port(val) (J1939_PORT_TYPE == J1939_PORT_##val)
#define J1939_LOG_ENABLE 1
/* CAN buffer size */
#define J1939_SIZE_CAN_BUFFER 8
/* CAN port size */
#define J1939_SIZE_CAN_PORT 8
#if __J1939_Port(VIRTUAL)
#define J1939_SIZE_VIRTUAL_PORT J1939_SIZE_CAN_PORT
#define J1939_SIZE_VIRTUAL_FIFO 3
#endif /* __J1939_Port() */
#if J1939_LOG_ENABLE
#include <stdio.h>
#define J1939_LOG(format, ...) printf(format, ##__VA_ARGS__)
#define J1939_LOG_INFO(format, ...) J1939_LOG("[J1939][Info]" format "\r\n", ##__VA_ARGS__)
#define J1939_LOG_WARN(format, ...) J1939_LOG("[J1939][Warn]" "func %s, file %s, line %d: " format "\r\n", __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__)
#define J1939_LOG_ERROR(format, ...) J1939_LOG("[J1939][Error]" "func %s, file %s, line %d: " format "\r\n", __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__)
#else /* J1939_LOG_ENABLE */
#define J1939_LOG(format, ...)
#define J1939_LOG_INFO(format, ...)
#define J1939_LOG_WARN(format, ...)
#define J1939_LOG_ERROR(format, ...)
#endif /* J1939_LOG_ENABLE */
void J1939_PortAssertError(const char *File, const char *Func, int Line, char *Condition);
#define J1939_Assert(Condition, ...) ((Condition) ? ((void)0U) : J1939_PortAssertError(__FILE__, __FUNCTION__, __LINE__, #Condition ", " #__VA_ARGS__))
#define J1939_ADDRESS_DIVIDE 0xF0/* DO NOT MODIFIED THIS PRAMETER */
#define J1939_ADDRESS_NULL 0xFE/* DO NOT MODIFIED THIS PRAMETER */
#define J1939_ADDRESS_GLOBAL 0xFF/* DO NOT MODIFIED THIS PRAMETER */
/* Config J1939 transport Protocol, enabled by default */
#define J1939_TRANSPORT_PROTOCOL_ENABLE 1
#if J1939_TRANSPORT_PROTOCOL_ENABLE
/* Reference SAE J1939-21 5.10.1.1 */
/* min size = 9, max size = 1785 */
#define J1939_TP_BUFFER_SIZE 1785
/* Config response packets number of TP CTS */
#define J1939_TP_CM_CTS_RESPONSE 4
#define J1939_TP_DEFAULT_PRIORITY 0x07
#define J1939_TP_BAM_TX_INTERVAL 50
/* Reference https://elearning.vector.com/mod/page/view.php?id=422 */
/* Reference SAE J1939-81 */
/* Used for identification of an ECU and for detection of address conflicts */
#define J1939_PGN_ADDR_CLAIMED 0x00EE00
/* Reference SAE J1939-21 */
/* Other PGNs can be requested using this PGN, similarly as for the CAN Remote Frame. */
/* But note: J1939 does not support Remote Frames. The Request PGN is a CAN data frame. */
#define J1939_PGN_REQUEST 0x00EA00
/* Reference SAE J1939-21 */
/* Transmits the payload data for the transport protocols */
#define J1939_PGN_TP_DT 0x00EB00
/* Reference SAE J1939-21 */
/* Supplies the metadata (number of bytes, packets, etc.) for transport protocols */
#define J1939_PGN_TP_CM 0x00EC00
/* Reference SAE J1939-21 */
/* Manufacturer-specific definable specific PGN */
#define J1939_PGN_PROPRIETARY_A 0x00EF00
/* Reference SAE J1939-21 */
/* Manufacturer-specific definable additional specific PGN */
#define J1939_PGN_PROPRIETARY_A1 0x01EF00
/* Reference SAE J1939-21 */
/* Used for acknowledgement of various network services. Can be positive or negative. */
/* The acknowledgement is referenced accordingly in the application layer. */
#define J1939_PGN_ACKNOWLEDGEMENT 0x00E800
#endif /* J1939_TRANSPORT_PROTOCOL_ENABLE */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* J1939_CONFIG_H */