automotive-message-broker  0.14.803
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
cansocketraw.h
1 /*
2 Copyright (C) 2012 Intel Corporation
3 
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.
8 
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.
13 
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
17 */
18 
19 #ifndef CANSOCKETRAW_H
20 #define CANSOCKETRAW_H
21 
27 #include <net/if.h>
28 #include <sys/poll.h>
29 #include <string>
30 #include <linux/can/raw.h>
31 
32 #include "cansocket.h"
33 
38 class CANSocketRaw : public CANSocket
39 {
40 public:
41  CANSocketRaw();
42  virtual ~CANSocketRaw(){} /*LCOV_EXCL_LINE*/
43 
50  virtual bool start(const char* ifName);
55  virtual void stop();
62  virtual bool write(const struct CANFrameInfo &message);
70  virtual CANSocket::CANSocketReadSuccess read(struct CANFrameInfo& message, unsigned int timeout = 1000);
71 
72 private:
76  bool createSocket();
77  bool enableCANErrors(can_err_mask_t errorMask);
78  bool enableTimestamps();
79  bool locateInterfaceIndex(struct ifreq& ifr);
80  bool bindSocket(struct sockaddr_can &addr);
81  bool closeSocket();
82  int waitData(unsigned int timeout);
83  bool writeFrame(const struct can_frame &frame);
84  ssize_t readFrame(can_frame& frame, double &timestamp);
85 
86 private:
92  int mSocket;
98  struct pollfd mPoll;
99 };
100 
101 #endif // CANSOCKETRAW_H
102