2 Copyright (C) 2012 Intel Corporation
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 * \addtogroup libcanbus
27 #include <linux/can.h>
32 * \brief Wrapper around different implementations of SocketCAN.
40 * CAN bus socket error.
41 * @enum CANSocketReadSuccess
44 enum CANSocketReadSuccess {
55 * Opens and initializes CAN socket
57 * @param ifName Name of the CAN bus network interface.
58 * @return True if no error occurs.
60 virtual bool start(const char* ifName) = 0;
67 * Writes CAN frame using the socket
69 * @param message CAN frame with additional information
70 * @param bytesWritten Number of written bytes.
71 * @return True if no error occurs.
73 virtual bool write(const struct CANFrameInfo &message);
75 * Try to read CAN frame
77 * @param message Buffer for CAN frame with additional information
78 * @param timeout Timeout for reading in [ms].
79 * @return Reading operation status code.
81 virtual CANSocket::CANSocketReadSuccess read(struct CANFrameInfo& message, unsigned int timeout = 1000);
83 * Registers CAN ID of a cyclic message for receiving
84 * @fn registerCyclicMessageForReceive
85 * @param canId CAN ID of the message.
86 * @param minCycleTime Minimal interval between messages in seconds. Set to 0 if not used.
87 * @param maxCycleTime Maximum interval between messages for timeout detection in seconds. Set to 0 if no timeout detection is necessary.
88 * @return True if registration succeeds.
90 virtual bool registerCyclicMessageForReceive(int canId, double minCycleTime, double maxCycleTime);
92 * Un-registers CAN ID of a message used of receiving. Valid for cyclic and sporadic messages.
93 * @fn unregisterMessageForReceive
94 * @param canId CAN ID of the message.
95 * @return True if de-registration succeeds.
97 virtual bool unregisterMessageForReceive(int canId);
100 #endif // CANSOCKET_H