Skip to content

Commit 427f76b

Browse files
committed
fix spacing & delete unnecessary lines
1 parent 210e2c0 commit 427f76b

File tree

3 files changed

+48
-61
lines changed

3 files changed

+48
-61
lines changed

src/socketcandcl.c

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -298,24 +298,21 @@ inline void state_connected()
298298
return;
299299
}
300300

301-
if(ioctl(raw_socket,SIOCGIFMTU,&ifr) < 0) {
301+
if (ioctl(raw_socket,SIOCGIFMTU,&ifr) < 0) {
302302
PRINT_ERROR("Error while searching for bus MTU %s\n", strerror(errno));
303303
state = STATE_SHUTDOWN;
304304
return;
305305
}
306306

307307
if (ifr.ifr_mtu == CANFD_MTU) {
308308
const int canfd_on = 1;
309-
if(setsockopt(raw_socket, SOL_CAN_RAW, CAN_RAW_FD_FRAMES, &canfd_on, sizeof(canfd_on)) < 0) {
309+
if (setsockopt(raw_socket, SOL_CAN_RAW, CAN_RAW_FD_FRAMES, &canfd_on, sizeof(canfd_on)) < 0) {
310310
PRINT_ERROR("Could not enable CAN FD support\n");
311311
state = STATE_SHUTDOWN;
312312
return;
313313
}
314314
}
315315

316-
// fprintf(stderr, "MTU of %s is %d\n", ldev, ifr.ifr_mtu);
317-
318-
319316
/* bind socket */
320317
if (bind(raw_socket, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
321318
PRINT_ERROR("Error while binding RAW socket %s\n", strerror(errno));
@@ -364,31 +361,29 @@ inline void state_connected()
364361

365362
frame.len = strlen(data_str) / 2;
366363

367-
// fprintf(stderr, "frame.can_id: %d frame.flags: %d frame.len: %d\n", frame.can_id, frame.flags, frame.len);
368-
369364
sscanf(data_str, "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx",
370365
&frame.data[0], &frame.data[1],
371366
&frame.data[2], &frame.data[3],
372367
&frame.data[4], &frame.data[5],
373368
&frame.data[6], &frame.data[7]);
374369

375370
ret = write(raw_socket, &frame, sizeof(struct can_frame));
376-
if(ret != sizeof(struct can_frame)) {
371+
if (ret != sizeof(struct can_frame)) {
377372
perror("Writing CAN frame to can socket\n");
378373
}
379-
} else if(!strncmp("< fdframe", buf, 9)) {
374+
} else if (!strncmp("< fdframe", buf, 9)) {
380375
char data_str[2*64];
381376

382377
sscanf(buf, "< fdframe %x %hhx %*d.%*d %s >", &frame.can_id, &frame.flags,
383378
data_str);
384379

385380
char* s = buf + 9;
386-
for(; ++s;) {
387-
if(*s== ' ') {
381+
for (; ++s;) {
382+
if (*s== ' ') {
388383
break;
389384
}
390385
}
391-
if((s - buf - 9) > 4)
386+
if ((s - buf - 9) > 4)
392387
frame.can_id |= CAN_EFF_FLAG;
393388

394389
frame.len = strlen(data_str) / 2;
@@ -421,7 +416,7 @@ inline void state_connected()
421416
);
422417

423418
ret = write(raw_socket, &frame, sizeof(struct canfd_frame));
424-
if(ret != sizeof(struct canfd_frame)) {
419+
if (ret != sizeof(struct canfd_frame)) {
425420
perror("Writing CAN frame to can socket\n");
426421
}
427422
}
@@ -459,33 +454,27 @@ inline void state_connected()
459454
} else {
460455
int i;
461456

462-
// fprintf(stderr, "frame.can_id: %d frame.flags: %d frame.len: %d\n", frame.can_id, frame.flags, frame.len);
463-
464-
if(ret == sizeof(struct can_frame)) {
465-
if(frame.can_id & CAN_EFF_FLAG) {
457+
if (ret == sizeof(struct can_frame)) {
458+
if (frame.can_id & CAN_EFF_FLAG) {
466459
ret = sprintf(buf, "< send %08X %d ",
467460
frame.can_id & CAN_EFF_MASK, frame.len);
468461
} else {
469462
ret = sprintf(buf, "< send %03X %d ",
470463
frame.can_id & CAN_SFF_MASK, frame.len);
471464
}
472-
} else if(ret == sizeof(struct canfd_frame)) {
473-
if(frame.can_id & CAN_EFF_FLAG) {
465+
} else if (ret == sizeof(struct canfd_frame)) {
466+
if (frame.can_id & CAN_EFF_FLAG) {
474467
ret = sprintf(buf, "< fdsend %08X %02X %d ",
475468
frame.can_id & CAN_EFF_MASK, frame.flags, frame.len);
476469
} else {
477470
ret = sprintf(buf, "< fdsend %03X %02X %d ",
478471
frame.can_id & CAN_SFF_MASK, frame.flags, frame.len);
479472
}
480473
}
481-
for(i=0; i<frame.len; i++) {
482-
ret += sprintf(buf+ret, "%02x ", frame.data[i]);
474+
for (i = 0; i < frame.len; i++) {
475+
ret += sprintf(buf + ret, "%02x ", frame.data[i]);
483476
}
484-
sprintf(buf+ret, ">");
485-
486-
#ifdef DEBUG
487-
PRINT_VERBOSE("%s\n", buf);
488-
#endif
477+
sprintf(buf + ret, " >");
489478

490479
const size_t len = strlen(buf);
491480
ret = send(server_socket, buf, len, 0);

src/state_bcm.c

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void state_bcm()
5757
return;
5858
}
5959

60-
memset(&caddr, 0, sizeof(caddr));
60+
memset(&caddr, 0, sizeof(caddr));
6161
caddr.can_family = PF_CAN;
6262
/* can_ifindex is set to 0 (any device) => need for sendto() */
6363

@@ -102,13 +102,13 @@ void state_bcm()
102102
}
103103

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

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

@@ -117,11 +117,10 @@ void state_bcm()
117117
tcp_quickack(client_socket);
118118
}
119119
} else {
120-
// fprintf(stderr, "msg.msg_head.can_id: %d ret size: %d\n", msg.msg_head.can_id, ret);
121120
switch(ret) {
122121
// if the frame is a classic CAN frame
123122
case sizeof(struct can_frame):
124-
if(msg.msg_head.can_id & CAN_EFF_FLAG) {
123+
if (msg.msg_head.can_id & CAN_EFF_FLAG) {
125124
snprintf(rxmsg, RXLEN, "< frame %08X %ld.%06ld ",
126125
msg.msg_head.can_id & CAN_EFF_MASK, tv.tv_sec, tv.tv_usec);
127126
} else {
@@ -131,7 +130,7 @@ void state_bcm()
131130
break;
132131
// if the frame is a CAN FD frame
133132
case sizeof(struct canfd_frame):
134-
if(msg.msg_head.can_id & CAN_EFF_FLAG) {
133+
if (msg.msg_head.can_id & CAN_EFF_FLAG) {
135134
snprintf(rxmsg, RXLEN, "< fdframe %08X %02X %ld.%06ld ",
136135
msg.msg_head.can_id & CAN_EFF_MASK, msg.msg_head.flags, tv.tv_sec, tv.tv_usec);
137136
} else {
@@ -144,7 +143,7 @@ void state_bcm()
144143
return;
145144
}
146145

147-
for ( i = 0; i < msg.frame.len; i++)
146+
for (i = 0; i < msg.frame.len; i++)
148147
snprintf(rxmsg + strlen(rxmsg), RXLEN - strlen(rxmsg), "%02X ",
149148
msg.frame.data[i]);
150149

@@ -159,7 +158,7 @@ void state_bcm()
159158

160159
ret = receive_command(client_socket, buf);
161160

162-
if(ret != 0) {
161+
if (ret != 0) {
163162
state = STATE_SHUTDOWN;
164163
return;
165164
}
@@ -201,11 +200,11 @@ void state_bcm()
201200
&msg.frame.data[6],
202201
&msg.frame.data[7]);
203202

204-
if ( (items < 2) ||
205-
(msg.frame.len > 8) ||
206-
(items != 2 + msg.frame.len)) {
203+
if ((items < 2) ||
204+
(msg.frame.len > 8) ||
205+
(items != 2 + msg.frame.len)) {
207206
PRINT_ERROR("Syntax error in send command\n");
208-
return;
207+
return;
209208
}
210209

211210
/* < send XXXXXXXX ... > check for extended identifier */
@@ -221,7 +220,7 @@ void state_bcm()
221220
(struct sockaddr *)&caddr, sizeof(caddr));
222221
}
223222
/* Add a send job */
224-
} else if(!strncmp("< fdsend ", buf, 9)) {
223+
} else if (!strncmp("< fdsend ", buf, 9)) {
225224
// First, read the fixed part of the frame
226225
items = sscanf(buf, "< %*s %x %hhx %hhu",
227226
&msg.msg_head.can_id,
@@ -269,15 +268,15 @@ void state_bcm()
269268
&msg.frame.data[56], &msg.frame.data[57], &msg.frame.data[58], &msg.frame.data[59],
270269
&msg.frame.data[60], &msg.frame.data[61], &msg.frame.data[62], &msg.frame.data[63]);
271270

272-
if ( (items < 2) ||
273-
(msg.frame.len > 64) ||
274-
(items != 3 + msg.frame.len)) {
271+
if ((items < 2) ||
272+
(msg.frame.len > 64) ||
273+
(items != 3 + msg.frame.len)) {
275274
PRINT_ERROR("Syntax error in fdsend command\n");
276-
return;
275+
return;
277276
}
278277

279278
/* < fdsend XXXXXXXX ... > check for extended identifier */
280-
if(element_length(buf, 2) == 8)
279+
if (element_length(buf, 2) == 8)
281280
msg.msg_head.can_id |= CAN_EFF_FLAG;
282281

283282
msg.msg_head.opcode = TX_SEND;
@@ -287,8 +286,7 @@ void state_bcm()
287286
caddr.can_ifindex = ifr.ifr_ifindex;
288287
sendto(sc, &msg, sizeof(msg), 0, (struct sockaddr*)&caddr, sizeof(caddr));
289288
}
290-
} else if(!strncmp("< add ", buf, 6)) {
291-
fprintf(stderr, "%s\n", buf);
289+
} else if (!strncmp("< add ", buf, 6)) {
292290
items = sscanf(buf, "< %*s %lu %lu %x %hhu "
293291
"%hhx %hhx %hhx %hhx %hhx %hhx "
294292
"%hhx %hhx >",
@@ -305,7 +303,7 @@ void state_bcm()
305303
&msg.frame.data[6],
306304
&msg.frame.data[7]);
307305

308-
if( (items < 4) ||
306+
if ((items < 4) ||
309307
(msg.frame.len > 8) ||
310308
(items != 4 + msg.frame.len) ) {
311309
PRINT_ERROR("Syntax error in add command.\n");
@@ -341,11 +339,11 @@ void state_bcm()
341339
&msg.frame.data[6],
342340
&msg.frame.data[7]);
343341

344-
if ( (items < 2) ||
345-
(msg.frame.len > 8) ||
346-
(items != 2 + msg.frame.len)) {
342+
if ((items < 2) ||
343+
(msg.frame.len > 8) ||
344+
(items != 2 + msg.frame.len)) {
347345
PRINT_ERROR("Syntax error in update send job command\n");
348-
return;
346+
return;
349347
}
350348

351349
/* < update XXXXXXXX ... > check for extended identifier */
@@ -401,11 +399,11 @@ void state_bcm()
401399
&msg.frame.data[6],
402400
&msg.frame.data[7]);
403401

404-
if( (items < 4) ||
402+
if ((items < 4) ||
405403
(msg.frame.len > 8) ||
406404
(items != 4 + msg.frame.len) ) {
407405
PRINT_ERROR("syntax error in filter command.\n");
408-
return;
406+
return;
409407
}
410408

411409
/* < filter sec usec XXXXXXXX ... > check for extended identifier */
@@ -486,7 +484,7 @@ void state_bcm()
486484
caddr.can_ifindex = ifr.ifr_ifindex;
487485
sendto(sc, &muxmsg, sizeof(struct bcm_msg_head) +
488486
sizeof(struct can_frame) * muxmsg.msg_head.nframes,
489-
0, (struct sockaddr*)&caddr, sizeof(caddr));
487+
0, (struct sockaddr *)&caddr, sizeof(caddr));
490488
}
491489
/* Add a filter */
492490
} else if (!strncmp("< subscribe ", buf, 12)) {

src/state_raw.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ void state_raw()
162162
}
163163
}
164164

165-
for(i=0;i<frame.len;i++) {
166-
ret += sprintf(buf+ret, "%02X", frame.data[i]);
165+
for (i = 0; i < frame.len; i++) {
166+
ret += sprintf(buf + ret, "%02X", frame.data[i]);
167167
}
168168
sprintf(buf + ret, " >");
169169
send(client_socket, buf, strlen(buf), 0);
@@ -206,11 +206,11 @@ void state_raw()
206206
&frame.data[6],
207207
&frame.data[7]);
208208

209-
if ( (items < 2) ||
210-
(frame.len > 8) ||
211-
(items != 2 + frame.len)) {
209+
if ((items < 2) ||
210+
(frame.len > 8) ||
211+
(items != 2 + frame.len)) {
212212
PRINT_ERROR("Syntax error in send command\n");
213-
return;
213+
return;
214214
}
215215

216216
/* < send XXXXXXXX ... > check for extended identifier */

0 commit comments

Comments
 (0)