Skip to content

Commit 674e5ee

Browse files
committed
update comments
1 parent d883193 commit 674e5ee

1 file changed

Lines changed: 9 additions & 12 deletions

File tree

state_raw.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ void state_raw() {
6969
return;
7070
}
7171

72+
/*
73+
*if the device supports CAN FD, use it
74+
* if you don't want to use CAN FD, you should initialize the device as classic CAN
75+
*/
7276
if (ifr.ifr_mtu == CANFD_MTU) {
7377
const int canfd_on = 1;
7478
if(setsockopt(raw_socket, SOL_CAN_RAW, CAN_RAW_FD_FRAMES, &canfd_on, sizeof(canfd_on)) < 0) {
@@ -78,9 +82,6 @@ void state_raw() {
7882
}
7983
}
8084

81-
// fprintf(stderr, "MTU of %s is %d\n", bus_name, ifr.ifr_mtu);
82-
83-
8485
if(bind(raw_socket, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
8586
PRINT_ERROR("Error while binding RAW socket %s\n", strerror(errno));
8687
state = STATE_SHUTDOWN;
@@ -143,16 +144,16 @@ void state_raw() {
143144
} else if(frame.can_id & CAN_RTR_FLAG) {
144145
/* TODO implement */
145146
} else {
146-
// fprintf(stderr, "frame.can_id: %d ret size: %d\n", frame.can_id, ret);
147-
148147
switch(ret) {
148+
// if the frame is a classic CAN frame
149149
case sizeof(struct can_frame):
150150
if(frame.can_id & CAN_EFF_FLAG) {
151151
ret = sprintf(buf, "< frame %08X %ld.%06ld ", frame.can_id & CAN_EFF_MASK, tv.tv_sec, tv.tv_usec);
152152
} else {
153153
ret = sprintf(buf, "< frame %03X %ld.%06ld ", frame.can_id & CAN_SFF_MASK, tv.tv_sec, tv.tv_usec);
154154
}
155155
break;
156+
// if the frame is a CAN FD frame
156157
case sizeof(struct canfd_frame):
157158
if(frame.can_id & CAN_EFF_FLAG) {
158159
ret = sprintf(buf, "< fdframe %08X %02X %ld.%06ld ", frame.can_id & CAN_EFF_MASK, frame.flags, tv.tv_sec, tv.tv_usec);
@@ -190,7 +191,7 @@ void state_raw() {
190191
return;
191192
}
192193

193-
/* Send a single frame */
194+
/* Send a single classic CAN frame */
194195
if(!strncmp("< send ", buf, 7)) {
195196
items = sscanf(buf, "< %*s %x %hhu "
196197
"%hhx %hhx %hhx %hhx %hhx %hhx "
@@ -206,8 +207,6 @@ void state_raw() {
206207
&frame.data[6],
207208
&frame.data[7]);
208209

209-
// fprintf(stderr, "%s\n", buf);
210-
211210
if ( (items < 2) ||
212211
(frame.len > 8) ||
213212
(items != 2 + frame.len)) {
@@ -224,6 +223,7 @@ void state_raw() {
224223
state = STATE_SHUTDOWN;
225224
return;
226225
}
226+
/* Send a single CANFD frame */
227227
} else if(!strncmp("< fdsend ", buf, 9)) {
228228
// First, read the fixed part of the frame
229229
items = sscanf(buf, "< %*s %x %hhx %hhu",
@@ -272,17 +272,14 @@ void state_raw() {
272272
&frame.data[56], &frame.data[57], &frame.data[58], &frame.data[59],
273273
&frame.data[60], &frame.data[61], &frame.data[62], &frame.data[63]);
274274

275-
// fprintf(stderr, "items: %d frames: %d\n", items, frame.len);
276-
// fprintf(stderr, "%s %s\n", buf, format);
277-
278275
if ( (items < 2) ||
279276
(frame.len > 64) ||
280277
(items != 3 + frame.len)) {
281278
PRINT_ERROR("Syntax error in send command\n")
282279
return;
283280
}
284281

285-
/* < send XXXXXXXX ... > check for extended identifier */
282+
/* < fdsend XXXXXXXX ... > check for extended identifier */
286283
if(element_length(buf, 2) == 8)
287284
frame.can_id |= CAN_EFF_FLAG;
288285

0 commit comments

Comments
 (0)