Commit d267469e authored by Franksen, Benjamin's avatar Franksen, Benjamin
Browse files

scan fix error checking when setting up ellsi protocol

parent ab684bbe
......@@ -346,11 +346,12 @@ static int ellsi_set_baudrate(ellsi_state_t *state, int baudrate) {
uint32_t payload;
} __attribute__((packed)) msg;
int r;
uint32_t code = -1;
memset(&msg, 0, sizeof(msg));
msg.header.magic = htonl(ELLSI_MAGIC);
if (baudrate) {
uint32_t code = ellsi_from_baudrate(baudrate);
code = ellsi_from_baudrate(baudrate);
if (code != -1) {
msg.header.command = htonl(ELLSI_CMD_CTRL);
msg.header.subcommand = htonl(ELLSI_IOCTL_CAN_SET_BAUDRATE);
......@@ -360,17 +361,20 @@ static int ellsi_set_baudrate(ellsi_state_t *state, int baudrate) {
printf("ignoring invalid baudrate %d\n", baudrate);
}
}
debug("ellsi_set_baudrate: send magic %#x, cmd %#x subcmd %#x\n",
ELLSI_MAGIC, ELLSI_CMD_CTRL, ELLSI_IOCTL_CAN_SET_BAUDRATE);
debug("ellsi_set_baudrate: send magic %#x cmd %#x subcmd %#x baudrate_code %#x\n",
ELLSI_MAGIC, ELLSI_CMD_CTRL, ELLSI_IOCTL_CAN_SET_BAUDRATE, code);
r = write(state->sock, &msg, sizeof(msg));
if (r < 0) {
printf("ellsi_set_baudrate: write failed\n"); return r;
}
msg.header.command = htonl(ELLSI_CMD_CTRL);
msg.header.subcommand = htonl(ELLSI_IOCTL_GET_LAST_STATE);
msg.header.payloadLen = htonl(sizeof(msg.payload));
r = write(state->sock, &msg, sizeof(msg));
if (r < 0) {
printf("ellsi_set_baudrate: write failed\n"); return r;
}
return r;
#if 0
/* ELLSI_SUBCMD_AUTOACK is not supported for ELLSI_CMD_CTRL */
return ellsi_check(state->sock);
#endif
}
static int ellsi_add_can_ids(ellsi_state_t *state) {
......@@ -393,11 +397,14 @@ static int ellsi_add_can_ids(ellsi_state_t *state) {
if (r < 0) {
printf("ellsi_add_can_ids: write failed\n"); return r;
}
return r;
#if 0
/* ELLSI_SUBCMD_AUTOACK is not supported for ELLSI_CMD_CTRL */
msg.header.command = htonl(ELLSI_CMD_CTRL);
msg.header.subcommand = htonl(ELLSI_IOCTL_GET_LAST_STATE);
msg.header.payloadLen = htonl(sizeof(msg.payload));
r = write(state->sock, &msg, sizeof(msg));
if (r < 0) {
printf("ellsi_add_can_ids: write failed\n"); return r;
}
return ellsi_check(state->sock);
#endif
}
int ellsiConfigPort(int can_port, const char *ip_addr, int ip_port, int baudrate) {
......@@ -441,11 +448,23 @@ int ellsiConfigPort(int can_port, const char *ip_addr, int ip_port, int baudrate
methods->read = ellsi_read;
methods->dump = ellsi_dump;
/* initialize protocol */
ellsi_register(state);
if (ellsi_register(state)) {
fprintf(stderr, "ellsiConfigPort: error in ellsi_register\n");
free(state);
return -1;
}
/* configure baudrate */
ellsi_set_baudrate(state, baudrate);
if (ellsi_set_baudrate(state, baudrate)) {
fprintf(stderr, "ellsiConfigPort: error in ellsi_set_baudrate\n");
free(state);
return -1;
}
/* enable all CAN ids */
ellsi_add_can_ids(state);
if (ellsi_add_can_ids(state)) {
fprintf(stderr, "ellsiConfigPort: error in ellsi_add_can_ids\n");
free(state);
return -1;
}
/* install driver and initialize sci port */
return scan_config_port(can_port, state, methods);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment