4 * Copyright (C) 2015, 2016 , 2017, 2018, 2019 "IoT\.bzh"
5 * Author "Romain Forlot" <romain.forlot@iot.bzh>
6 * Author "Loïc Collignon" <loic.collignon@iot.bzh>
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <sys/socket.h>
23 #include <linux/can/bcm.h>
24 #include <linux/sockios.h>
27 #include "../binding/low-can-hat.hpp"
28 #include "../can/message/can-message.hpp"
30 #define INVALID_SOCKET -1
31 #define NO_CAN_ID 0xFFFFFFFFU
40 socketcan_t(const socketcan_t& s) = delete;
41 socketcan_t(socketcan_t&&);
42 socketcan_t& operator=(const socketcan_t& s);
43 virtual ~socketcan_t();
45 const struct sockaddr_can& get_tx_address() const;
46 explicit operator bool() const;
49 virtual int open(std::string device_name) = 0;
50 int setopt(int level, int optname, const void* optval, socklen_t optlen);
52 virtual std::shared_ptr<message_t> read_message() = 0;
53 virtual int write_message(message_t& obj) = 0;
54 virtual int write_message(std::vector<message_t>& vobj);
58 struct sockaddr_can tx_address_;
59 int open(int domain, int type, int protocol);
60 int bind(const struct sockaddr* addr, socklen_t len);
61 int connect(const struct sockaddr* addr, socklen_t len);