@@ -31,7 +31,16 @@ void open_lin_slave_state_callback(t_open_lin_slave_state new_state)
31
31
extern " C" void app_main ()
32
32
{
33
33
Serial.begin (115200 );
34
+
35
+ #define LIN_AUTOBAUD
36
+
37
+ #ifdef LIN_AUTOBAUD
38
+ const uint32_t command_baud[] = {1200 , 2400 , 4800 , 9600 , 14400 , 19200 };
39
+ const uint32_t LIN_BAUD_MAX = 20000 ;
40
+ swLin.begin (LIN_BAUD_MAX);
41
+ #else
34
42
swLin.begin (9600 );
43
+ #endif
35
44
36
45
l_u8 frame_data_length[] = {
37
46
5 ,
@@ -61,7 +70,22 @@ extern "C" void app_main()
61
70
open_lin_hw_break_reg = true ;
62
71
open_lin_slave_rx_header (0 ); // To notify that the break has detected
63
72
64
- uint8_t buf[3 + 8 ];
73
+ #ifdef LIN_AUTOBAUD
74
+ uint32_t autobaud = swLin.setAutoBaud (command_baud, sizeof (command_baud)/sizeof (command_baud[0 ]));
75
+ if (autobaud) {
76
+ Serial.printf (" autobaud detection succeeded. Set baud = %u\n\n " , autobaud);
77
+ open_lin_slave_rx_header (0x55 ); // setAutoBaud() has successfully recognized the SYNC
78
+ }
79
+ else {
80
+ Serial.printf (" autobaud detection failed. baud is not changed = %u\n\n " , swLin.baudRate ());
81
+ open_lin_slave_rx_header (0x00 ); // setAutoBaud() failed to recognize SYNC. 0x00 is not expected, thus the slave is reset.
82
+ }
83
+
84
+ uint8_t buf[2 + 8 ]; // 2 for PID, CHECKSUM. SYNC is consumed by swLin.setAutoBaud()
85
+ #else
86
+ uint8_t buf[3 + 8 ]; // 3 for SYNC, PID and CHECKSUM.
87
+ #endif
88
+
65
89
while (slave_state != OPEN_LIN_SLAVE_IDLE) {
66
90
const unsigned long timeout_us = 100000 ; // 100ms timeout
67
91
unsigned long start_micro = micros ();
@@ -90,7 +114,7 @@ extern "C" {
90
114
91
115
void open_lin_on_rx_frame (open_lin_frame_slot_t *slot)
92
116
{
93
- Serial.printf (" [open_lin_on_rx_frame]\n\t " );
117
+ Serial.printf (" [open_lin_on_rx_frame] PID=%d \n\t " , ( int )slot-> pid );
94
118
for (int i = 0 ; i < slot->data_length ; ++i) {
95
119
Serial.printf (" 0x%02X " , slot->data_ptr [i]);
96
120
}
@@ -100,6 +124,64 @@ void open_lin_on_rx_frame(open_lin_frame_slot_t *slot)
100
124
void open_lin_error_handler (t_open_lin_error error_code)
101
125
{
102
126
Serial.printf (" [open_lin_error_handler] error_code = %d\n " , (int )error_code);
127
+
128
+ switch (error_code) {
129
+ case OPEN_LIN_NO_ERROR:
130
+ Serial.printf (" \t %s\n " , " OPEN_LIN_NO_ERROR" );
131
+ break ;
132
+
133
+ case OPEN_LIN_SLAVE_ERROR_INVALID_DATA_RX:
134
+ Serial.printf (" \t %s\n " , " OPEN_LIN_SLAVE_ERROR_INVALID_DATA_RX" );
135
+ break ;
136
+
137
+ case OPEN_LIN_SLAVE_ERROR_INVALID_CHECKSUM:
138
+ Serial.printf (" \t %s\n " , " OPEN_LIN_SLAVE_ERROR_INVALID_CHECKSUM" );
139
+ break ;
140
+
141
+ case OPEN_LIN_SLAVE_ERROR_PID_PARITY:
142
+ Serial.printf (" \t %s\n " , " OPEN_LIN_SLAVE_ERROR_PID_PARITY" );
143
+ break ;
144
+
145
+ case OPEN_LIN_SLAVE_ERROR_INVALID_SYNCH:
146
+ Serial.printf (" \t %s\n " , " OPEN_LIN_SLAVE_ERROR_INVALID_SYNCH" );
147
+ break ;
148
+
149
+ case OPEN_LIN_SLAVE_ERROR_INVALID_BREAK:
150
+ Serial.printf (" \t %s\n " , " OPEN_LIN_SLAVE_ERROR_INVALID_BREAK" );
151
+ break ;
152
+
153
+ case OPEN_LIN_SLAVE_ERROR_ID_NOT_FOUND:
154
+ Serial.printf (" \t %s\n " , " OPEN_LIN_SLAVE_ERROR_ID_NOT_FOUND" );
155
+ break ;
156
+
157
+ case OPEN_LIN_SLAVE_ERROR_HW_TX:
158
+ Serial.printf (" \t %s\n " , " OPEN_LIN_SLAVE_ERROR_HW_TX" );
159
+ break ;
160
+
161
+ case OPEN_LIN_MASTER_ERROR_CHECKSUM:
162
+ Serial.printf (" \t %s\n " , " OPEN_LIN_MASTER_ERROR_CHECKSUM" );
163
+ break ;
164
+
165
+ case OPEN_LIN_MASTER_ERROR_HEADER_TX:
166
+ Serial.printf (" \t %s\n " , " OPEN_LIN_MASTER_ERROR_HEADER_TX" );
167
+ break ;
168
+
169
+ case OPEN_LIN_MASTER_ERROR_DATA_TX:
170
+ Serial.printf (" \t %s\n " , " OPEN_LIN_MASTER_ERROR_DATA_TX" );
171
+ break ;
172
+
173
+ case OPEN_LIN_MASTER_ERROR_DATA_RX:
174
+ Serial.printf (" \t %s\n " , " OPEN_LIN_MASTER_ERROR_DATA_RX" );
175
+ break ;
176
+
177
+ case OPEN_LIN_MASTER_ERROR_DATA_RX_TIMEOUT:
178
+ Serial.printf (" \t %s\n " , " OPEN_LIN_MASTER_ERROR_DATA_RX_TIMEOUT" );
179
+ break ;
180
+
181
+ default :
182
+ assert (0 );
183
+ }
184
+ Serial.println (" \n " );
103
185
}
104
186
105
187
#ifdef __cplusplus
0 commit comments