yarp-devices
Loading...
Searching...
No Matches
CanBusSocket.hpp
1// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2
3#ifndef __CAN_BUS_SOCKET_HPP__
4#define __CAN_BUS_SOCKET_HPP__
5
6#include <linux/can.h>
7#include <linux/can/raw.h>
8
9#include <string>
10#include <vector>
11
12#include <yarp/dev/DeviceDriver.h>
13#include <yarp/dev/CanBusInterface.h>
14
15#include "SocketCanMessage.hpp"
16#include "CanBusSocket_ParamsParser.h"
17
25class CanBusSocket : public yarp::dev::DeviceDriver,
26 public yarp::dev::ICanBus,
27 public yarp::dev::ImplementCanBufferFactory<roboticslab::SocketCanMessage, struct can_frame>,
29{
30public:
31 // --------- DeviceDriver declarations. Implementation in DeviceDriverImpl.cpp ---------
32 bool open(yarp::os::Searchable& config) override;
33 bool close() override;
34
35 // --------- ICanBus declarations. Implementation in ICanBusImpl.cpp ---------
36 bool canSetBaudRate(unsigned int rate) override;
37 bool canGetBaudRate(unsigned int * rate) override;
38 bool canIdAdd(unsigned int id) override;
39 bool canIdDelete(unsigned int id) override;
40 bool canRead(yarp::dev::CanBuffer & msgs, unsigned int size, unsigned int * read, bool wait = false) override;
41 bool canWrite(const yarp::dev::CanBuffer & msgs, unsigned int size, unsigned int * sent, bool wait = false) override;
42
43private:
44 enum io_operation { READ, WRITE };
45
46 bool waitUntilTimeout(io_operation op, bool * bufferReady);
47 void interpretErrorFrame(const struct can_frame * msg);
48
49 int socketDescriptor {0};
50 std::vector<struct can_filter> filters;
51};
52
53#endif // __CAN_BUS_SOCKET_HPP__
Definition CanBusSocket_ParamsParser.h:49
Definition CanBusSocket.hpp:29