2 Copyright (C) 2012 Intel Corporation
3 Copyright (C) 2015 Cogent Embedded Inc.
4 Copyright (C) 2015 Renesas Electronics Corporation
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef CANSOCKETBCM_H
22 #define CANSOCKETBCM_H
25 * \addtogroup libcanbus
33 #include <linux/can/bcm.h>
34 #include <linux/can/raw.h>
36 #include "cansocket.h"
39 * \brief CAN Socket wrapper.
42 class CANSocketBCM : public CANSocket
48 * Opens and initialize CAN socket
50 * @param ifName Name of the CAN bus network interface.
51 * @return True if no error occurs.
53 virtual bool start(const char* ifName);
60 * Writes CAN frame using the socket
62 * @param message CAN frame with additional information
63 * @param bytesWritten Number of written bytes.
64 * @return True if no error occurs.
66 virtual bool write(const struct CANFrameInfo &message);
68 * Try to read CAN frame
70 * @param message Buffer for CAN frame with additional information
71 * @param timeout Timeout for reading in [ms].
72 * @return Reading operation status code.
74 virtual CANSocket::CANSocketReadSuccess read(struct CANFrameInfo& message, unsigned int timeout = 1000);
76 * Registers CAN ID of a cyclic message for receiving
77 * @fn registerCyclicMessageForReceive
78 * @param canId CAN ID of the message.
79 * @param minCycleTime Minimal interval between messages in seconds. Set to 0 if not used.
80 * @param maxCycleTime Maximum interval between messages for timeout detection in seconds. Set to 0 if no timeout detection is necessary.
81 * @return True if registration succeeds.
83 virtual bool registerCyclicMessageForReceive(int canId, double minCycleTime, double maxCycleTime);
85 * Unregisters CAN ID for receiving
86 * @fn unregisterMessageForReceive
87 * @param canId CAN ID of the message.
88 * @return True if de-registration succeeds.
90 virtual bool unregisterMessageForReceive(int canId);
97 bool locateInterfaceIndex(struct ifreq& ifr);
98 bool connectSocket(struct sockaddr_can& addr);
100 int waitData(unsigned int timeout);
101 bool writeFrameOneTime(const can_frame& frame);
102 CANSocket::CANSocketReadSuccess readMessage(CANFrameInfo& message);
106 * Socket file descriptor.
112 * Data structure describing a polling request.
119 #endif // CANSOCKETBCM_H