aboutsummaryrefslogtreecommitdiffstats
path: root/CAN-binder/low-can-binding/can/can-bus-dev.hpp
blob: 04914cec26eaf1f0773df4b1920af9c7bbab55b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold
/*
 * Copyright (C) 2015, 2016, 2017 "IoT.bzh"
 * Author "Romain Forlot" <romain.forlot@iot.bzh>
 * Author "Loïc Collignon" <loic.collignon@iot.bzh>
 *
 * 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.
 */

#pragma once

#include <stdint.h>
#include <linux/can.h>
#include <string>
#include <thread>

#include "../utils/socketcan.hpp"

class can_bus_t;
class can_message_t;
class can_signal_t;

/// @brief Object representing a can device. Handle opening, closing and reading on the
/// socket. This is the low level object to be initialized and use by can_bus_t.
class can_bus_dev_t
{
private:
	std::string device_name_; ///< a string identifier identitfying the linux CAN device.
	utils::socketcan_t can_socket_;

	int32_t address_; ///< an identifier used through binding that refer to that device

	std::thread th_reading_; ///< Thread handling read the socket can device filling can_message_q_ queue of can_bus_t
	bool is_running_ = false; ///< boolean telling whether or not reading is running or not
	void can_reader(can_bus_t& can_bus);

public:
	can_bus_dev_t(const std::string& dev_name, int32_t address);

	std::string get_device_name() const;
	uint32_t get_address() const;

	int open();
	void configure();
	int close();

	void start_reading(can_bus_t& can_bus);

	void stop_reading();

	can_message_t read();
	int create_rx_filter(const can_signal_t& s);

	int send(can_message_t& can_msg);
	bool shims_send(const uint32_t arbitration_id, const uint8_t* data, const uint8_t size);
};