Lely core libraries
2.3.4
|
#include "io.h"
#include <lely/util/errnum.h>
#include <lely/can/socket.h>
#include "handle.h"
#include <lely/io/can.h>
#include <assert.h>
#include <string.h>
#include <linux/can/error.h>
#include <linux/can/netlink.h>
#include <linux/can/raw.h>
Go to the source code of this file.
Data Structures | |
struct | can |
A CAN device. More... | |
Functions | |
io_handle_t | io_open_can (const char *path) |
Opens a CAN device. More... | |
int | io_can_read (io_handle_t handle, struct can_msg *msg) |
Reads a single CAN or CAN FD frame. More... | |
int | io_can_write (io_handle_t handle, const struct can_msg *msg) |
Writes a single CAN or CAN FD frame. More... | |
int | io_can_start (io_handle_t handle) |
Starts transmission and reception on a CAN device. More... | |
int | io_can_stop (io_handle_t handle) |
Stops transmission and reception on a CAN device. More... | |
int | io_can_get_state (io_handle_t handle) |
Obtains the state of a CAN device. More... | |
int | io_can_get_error (io_handle_t handle, int *perror) |
Obtains and clears the current error number of a CAN device, and stores the value (any combination of CAN_ERROR_BIT , CAN_ERROR_STUFF , CAN_ERROR_CRC , CAN_ERROR_FORM and CAN_ERROR_ACK ) in *perror. More... | |
int | io_can_get_ec (io_handle_t handle, uint16_t *ptxec, uint16_t *prxec) |
Obtains the transmit and/or receive error count of a CAN device and stores the value in *ptxec and/or *prxec. More... | |
int | io_can_get_bitrate (io_handle_t handle, uint32_t *pbitrate) |
Obtains the bitrate (in bit/s) of a CAN device and stores the value in *pbitrate. More... | |
int | io_can_set_bitrate (io_handle_t handle, uint32_t bitrate) |
Sets the bitrate (in bit/s) of a CAN device. More... | |
int | io_can_get_txqlen (io_handle_t handle, size_t *ptxqlen) |
Obtains the length of the transmission queue (in number of CAN frames) of a CAN device and stores the value in *ptxqlen. More... | |
int | io_can_set_txqlen (io_handle_t handle, size_t txqlen) |
Sets the length of the transmission queue (in number of CAN frames) of a CAN device. More... | |
This file is part of the I/O library; it contains the implementation of the Controller Area Network (CAN) functions.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Definition in file can.c.
io_handle_t io_open_can | ( | const char * | path | ) |
Opens a CAN device.
path | the (platform dependent) path (or interface) name of the device. |
int io_can_read | ( | io_handle_t | handle, |
struct can_msg * | msg | ||
) |
Reads a single CAN or CAN FD frame.
handle | a valid CAN device handle. |
msg | the address at which to store the received frame. |
ERRNUM_IO
), the CAN device state and error can be obtained with io_can_get_state() and io_can_get_error(), respectively. int io_can_write | ( | io_handle_t | handle, |
const struct can_msg * | msg | ||
) |
Writes a single CAN or CAN FD frame.
handle | a valid CAN device handle. |
msg | a pointer to the frame to be written. |
int io_can_start | ( | io_handle_t | handle | ) |
Starts transmission and reception on a CAN device.
On Linux, this operation requires the process to have the CAP_NET_ADMIN capability.
int io_can_stop | ( | io_handle_t | handle | ) |
Stops transmission and reception on a CAN device.
On Linux, this operation requires the process to have the CAP_NET_ADMIN capability.
int io_can_get_state | ( | io_handle_t | handle | ) |
Obtains the state of a CAN device.
CAN_STATE_ACTIVE
, CAN_STATE_PASSIVE
, CAN_STATE_BUSOFF
, or -1 on error. In the latter case, the error number can be obtained with get_errc(). int io_can_get_error | ( | io_handle_t | handle, |
int * | perror | ||
) |
Obtains and clears the current error number of a CAN device, and stores the value (any combination of CAN_ERROR_BIT
, CAN_ERROR_STUFF
, CAN_ERROR_CRC
, CAN_ERROR_FORM
and CAN_ERROR_ACK
) in *perror.
int io_can_get_ec | ( | io_handle_t | handle, |
uint16_t * | ptxec, | ||
uint16_t * | prxec | ||
) |
Obtains the transmit and/or receive error count of a CAN device and stores the value in *ptxec and/or *prxec.
int io_can_get_bitrate | ( | io_handle_t | handle, |
uint32_t * | pbitrate | ||
) |
Obtains the bitrate (in bit/s) of a CAN device and stores the value in *pbitrate.
int io_can_set_bitrate | ( | io_handle_t | handle, |
uint32_t | bitrate | ||
) |
Sets the bitrate (in bit/s) of a CAN device.
Note that not all bitrates are supported on every CAN controller. Standard bitrates are 10 kbit/s, 20 kbit/s, 50 kbit/s, 125 kbit/s, 250 kbit/s, 500 kbit/s, 800 kbit/s and 1 Mbit/s. On Linux, this operation requires the process to have the CAP_NET_ADMIN capability.
int io_can_get_txqlen | ( | io_handle_t | handle, |
size_t * | ptxqlen | ||
) |
Obtains the length of the transmission queue (in number of CAN frames) of a CAN device and stores the value in *ptxqlen.
int io_can_set_txqlen | ( | io_handle_t | handle, |
size_t | txqlen | ||
) |
Sets the length of the transmission queue (in number of CAN frames) of a CAN device.
On Linux, this operation requires the process to have the CAP_NET_ADMIN capability.