Program Listing for File socket_can_common.hpp

Return to documentation for file (/tmp/ws/src/ros2_socketcan/ros2_socketcan/include/ros2_socketcan/socket_can_common.hpp)

// Copyright 2021 the Autoware Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Co-developed by Tier IV, Inc. and Apex.AI, Inc.

#ifndef ROS2_SOCKETCAN__SOCKET_CAN_COMMON_HPP_
#define ROS2_SOCKETCAN__SOCKET_CAN_COMMON_HPP_

#include <sys/select.h>
#include <sys/time.h>
#include <linux/can.h>

#include <chrono>
#include <cstdint>
#include <string>
#include <vector>

namespace drivers
{
namespace socketcan
{

int32_t bind_can_socket(const std::string & interface, bool enable_fd);

void set_can_filter(int32_t fd, const std::vector<struct can_filter> & f_list);

void set_can_err_filter(int32_t fd, can_err_mask_t err_mask);

void set_can_filter_join(int32_t fd, bool join_filters);

struct timeval to_timeval(const std::chrono::nanoseconds timeout) noexcept;
uint64_t from_timeval(const struct timeval tv) noexcept;
fd_set single_set(int32_t file_descriptor) noexcept;

}  // namespace socketcan
}  // namespace drivers

#endif  // ROS2_SOCKETCAN__SOCKET_CAN_COMMON_HPP_