Skip to content

Commit

Permalink
Removed unused baud rate parameter from 'LinuxCanBus::Init()' functio…
Browse files Browse the repository at this point in the history
…n. Improved documentation. Added link to documentation on README.
  • Loading branch information
gbmhunter committed Mar 28, 2018
1 parent 224d7c0 commit 5688800
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 31 deletions.
9 changes: 1 addition & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,7 @@ A C++ user-space CAN bus driver for Linux (using socketCAN).
.. image:: https://codecov.io/gh/mbedded-ninja/CppTemplate/branch/master/graph/badge.svg
:target: https://codecov.io/gh/mbedded-ninja/CppTemplate

--------
Features
--------

- Easy to use API for controller a CAN device in Linux
- CMake-based build system
- Conan (package manager) support

See http://linuxcanbus.readthedocs.io for installation instructions, examples and other documentation!



Expand Down
8 changes: 8 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
Welcome to LinuxCanBus's documentation!
=======================================

--------
Features
--------

- Easy to use API for controller a CAN device in Linux
- CMake-based build system
- Conan (package manager) support

.. toctree::
:maxdepth: 2
:caption: Contents:
Expand Down
9 changes: 6 additions & 3 deletions docs/usage/basic_example.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Basic Example
=============

NOTE: LinuxCanBus does not configure and bring "up" the CAN interface itself. This has to be done with command-lind calls to :code:`ip link` and similar before using the library.

.. code-block:: cpp
#include "LinuxCanBus/LinuxCanBus.hpp"
Expand All @@ -9,8 +11,8 @@ Basic Example
LinuxCanBus canBus;
// Setup CAN bus using interface can0, 250000 baud, and standard frame format (i.e. not extended)
canBus.Init("can0", 250000, LinuxCanBus::FrameFormat::STANDARD);
// Setup CAN bus using CAN interface can0 and the standard frame format (i.e. not extended)
canBus.Init("can0", LinuxCanBus::FrameFormat::STANDARD);
// Write to CAN bus
CanMsg writeMsg;
Expand All @@ -19,7 +21,8 @@ Basic Example
writeMsg.GetDataMutable().push_back(0x34);
canBus.Write(writeMsg);
// Read from CAN bus
// Read from CAN bus, if available
// (0 means no blocking)
CanMsg readMsg;
canBus.Read(readMsg, 0);
Expand Down
6 changes: 5 additions & 1 deletion docs/usage/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Requires Conan to be installed.
~/LinuxCanBus$ conan create . testuser/testing
This will provide a static library called libLinuxCanBus.a and header files under a folder called :code:`:LinuxCanBus`, available to other Conan packages.

------------
Manual Build
------------
Expand All @@ -20,4 +22,6 @@ Manual Build
~/LinuxCanBus$ mkdir build
~/LinuxCanBus$ cd build/
~/LinuxCanBus/build$ conan install ..
~/LinuxCanBus/build$ conan build ..
~/LinuxCanBus/build$ conan build ..
This will build a static library called libLinuxCanBus.a and header files under a folder called :code:`:LinuxCanBus`.
6 changes: 2 additions & 4 deletions include/LinuxCanBus/LinuxCanBus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace mn {
/// \param interfaceName The name of the CAN interface you want to connect to (e.g. 'can0', 'vcan3').
/// \param bitRate The bit rate of the CAN interface.
/// \param frameType The frame type you wish to use with the CAN bus interface.
void Init(const std::string &interfaceName, int bitRate, FrameFormat frameFormat);
void Init(const std::string &interfaceName, FrameFormat frameFormat);

void SetLinuxApi(std::shared_ptr<ILinuxApi> linuxApi);

Expand Down Expand Up @@ -108,9 +108,7 @@ namespace mn {

FrameFormat frameFormat_;

int socketFd_;

int bitRate_;
int socketFd_;

struct ifreq ifr_;
struct sockaddr_can addr_;
Expand Down
5 changes: 2 additions & 3 deletions src/LinuxCanBus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ namespace mn {
linuxApi_ = std::shared_ptr<ILinuxApi>(new LinuxApiReal());
}

void LinuxCanBus::Init(const std::string &interfaceName, int bitRate, FrameFormat frameFormat) {
void LinuxCanBus::Init(const std::string &interfaceName, FrameFormat frameFormat) {
std::cout << "Init() called." << std::endl;

interfaceName_ = interfaceName;
bitRate_ = bitRate;
interfaceName_ = interfaceName;
frameFormat_ = frameFormat;
}

Expand Down
2 changes: 1 addition & 1 deletion test/BasicTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace {
}

void Init() {
linuxCanBus_.Init("vcan0", 0, LinuxCanBus::FrameFormat::STANDARD);
linuxCanBus_.Init("vcan0", LinuxCanBus::FrameFormat::STANDARD);

linuxCanBus_.SetLinuxApi(mockLinuxApi_);
}
Expand Down
17 changes: 6 additions & 11 deletions test_package/BasicTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,15 @@ namespace {

class BasicTests : public ::testing::Test {
protected:

BasicTests() {
}

virtual ~BasicTests() {
}

BasicTests() {}
virtual ~BasicTests() {}
};

TEST_F(BasicTests, LinkedCorrectly) {
LinuxApiReal linuxApiReal;
TEST_F(BasicTests, LinkedCorrectly) {
// The ability to create an object and call a function indicates that
// the LinuxCanBus library was created and linked correctly
LinuxCanBus linuxCanBus;
linuxCanBus.Init(&linuxApiReal, "vcan0", 0, LinuxCanBus::FrameFormat::STANDARD);
ASSERT_EQ(2, 2);
linuxCanBus.Init("vcan0", LinuxCanBus::FrameFormat::STANDARD);
}


Expand Down

0 comments on commit 5688800

Please sign in to comment.