Skip to content

Commit 3a322fe

Browse files
committed
support canfd for can raw
1 parent f17c068 commit 3a322fe

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

state_bcm.c

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ void state_bcm() {
4040

4141
struct {
4242
struct bcm_msg_head msg_head;
43-
struct canfd_frame frame;
43+
struct can_frame frame;
4444
} msg;
4545

4646
struct {
4747
struct bcm_msg_head msg_head;
48-
struct canfd_frame frame[257]; /* MAX_NFRAMES + MUX MASK */
48+
struct can_frame frame[257]; /* MAX_NFRAMES + MUX MASK */
4949
} muxmsg;
5050

5151
if(previous_state != STATE_BCM) {
@@ -102,12 +102,12 @@ void state_bcm() {
102102

103103
/* Check if this is an error frame */
104104
if(msg.msg_head.can_id & CAN_ERR_FLAG) {
105-
if(msg.frame.len != CAN_ERR_DLC) {
105+
if(msg.frame.can_dlc != CAN_ERR_DLC) {
106106
PRINT_ERROR("Error frame has a wrong DLC!\n")
107107
} else {
108108
snprintf(rxmsg, RXLEN, "< error %03X %ld.%06ld ", msg.msg_head.can_id, tv.tv_sec, tv.tv_usec);
109109

110-
for ( i = 0; i < msg.frame.len; i++)
110+
for ( i = 0; i < msg.frame.can_dlc; i++)
111111
snprintf(rxmsg + strlen(rxmsg), RXLEN - strlen(rxmsg), "%02X ",
112112
msg.frame.data[i]);
113113

@@ -116,7 +116,6 @@ void state_bcm() {
116116
tcp_quickack(client_socket);
117117
}
118118
} else {
119-
// fprintf(stderr, "msg.msg_head.can_id: %d ret size: %d\n", msg.msg_head.can_id, ret);
120119
if(msg.msg_head.can_id & CAN_EFF_FLAG) {
121120
snprintf(rxmsg, RXLEN, "< frame %08X %ld.%06ld ",
122121
msg.msg_head.can_id & CAN_EFF_MASK, tv.tv_sec, tv.tv_usec);
@@ -125,7 +124,7 @@ void state_bcm() {
125124
msg.msg_head.can_id & CAN_SFF_MASK, tv.tv_sec, tv.tv_usec);
126125
}
127126

128-
for ( i = 0; i < msg.frame.len; i++)
127+
for ( i = 0; i < msg.frame.can_dlc; i++)
129128
snprintf(rxmsg + strlen(rxmsg), RXLEN - strlen(rxmsg), "%02X ",
130129
msg.frame.data[i]);
131130

@@ -171,7 +170,7 @@ void state_bcm() {
171170
"%hhx %hhx %hhx %hhx %hhx %hhx "
172171
"%hhx %hhx >",
173172
&msg.msg_head.can_id,
174-
&msg.frame.len,
173+
&msg.frame.can_dlc,
175174
&msg.frame.data[0],
176175
&msg.frame.data[1],
177176
&msg.frame.data[2],
@@ -182,8 +181,8 @@ void state_bcm() {
182181
&msg.frame.data[7]);
183182

184183
if ( (items < 2) ||
185-
(msg.frame.len > 64) ||
186-
(items != 2 + msg.frame.len)) {
184+
(msg.frame.can_dlc > 8) ||
185+
(items != 2 + msg.frame.can_dlc)) {
187186
PRINT_ERROR("Syntax error in send command\n")
188187
return;
189188
}
@@ -208,7 +207,7 @@ void state_bcm() {
208207
&msg.msg_head.ival2.tv_sec,
209208
&msg.msg_head.ival2.tv_usec,
210209
&msg.msg_head.can_id,
211-
&msg.frame.len,
210+
&msg.frame.can_dlc,
212211
&msg.frame.data[0],
213212
&msg.frame.data[1],
214213
&msg.frame.data[2],
@@ -219,8 +218,8 @@ void state_bcm() {
219218
&msg.frame.data[7]);
220219

221220
if( (items < 4) ||
222-
(msg.frame.len > 64) ||
223-
(items != 4 + msg.frame.len) ) {
221+
(msg.frame.can_dlc > 8) ||
222+
(items != 4 + msg.frame.can_dlc) ) {
224223
PRINT_ERROR("Syntax error in add command.\n");
225224
return;
226225
}
@@ -244,7 +243,7 @@ void state_bcm() {
244243
"%hhx %hhx %hhx %hhx %hhx %hhx "
245244
"%hhx %hhx >",
246245
&msg.msg_head.can_id,
247-
&msg.frame.len,
246+
&msg.frame.can_dlc,
248247
&msg.frame.data[0],
249248
&msg.frame.data[1],
250249
&msg.frame.data[2],
@@ -255,8 +254,8 @@ void state_bcm() {
255254
&msg.frame.data[7]);
256255

257256
if ( (items < 2) ||
258-
(msg.frame.len > 64) ||
259-
(items != 2 + msg.frame.len)) {
257+
(msg.frame.can_dlc > 8) ||
258+
(items != 2 + msg.frame.can_dlc)) {
260259
PRINT_ERROR("Syntax error in update send job command\n")
261260
return;
262261
}
@@ -304,7 +303,7 @@ void state_bcm() {
304303
&msg.msg_head.ival2.tv_sec,
305304
&msg.msg_head.ival2.tv_usec,
306305
&msg.msg_head.can_id,
307-
&msg.frame.len,
306+
&msg.frame.can_dlc,
308307
&msg.frame.data[0],
309308
&msg.frame.data[1],
310309
&msg.frame.data[2],
@@ -315,8 +314,8 @@ void state_bcm() {
315314
&msg.frame.data[7]);
316315

317316
if( (items < 4) ||
318-
(msg.frame.len > 64) ||
319-
(items != 4 + msg.frame.len) ) {
317+
(msg.frame.can_dlc > 8) ||
318+
(items != 4 + msg.frame.can_dlc) ) {
320319
PRINT_ERROR("syntax error in filter command.\n")
321320
return;
322321
}
@@ -399,7 +398,7 @@ void state_bcm() {
399398
if (!ioctl(sc, SIOCGIFINDEX, &ifr)) {
400399
caddr.can_ifindex = ifr.ifr_ifindex;
401400
sendto(sc, &muxmsg, sizeof(struct bcm_msg_head) +
402-
sizeof(struct canfd_frame) * muxmsg.msg_head.nframes,
401+
sizeof(struct can_frame) * muxmsg.msg_head.nframes,
403402
0, (struct sockaddr*)&caddr, sizeof(caddr));
404403
}
405404
/* Add a filter */

0 commit comments

Comments
 (0)