aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-02-20 20:19:59 +0000
committerRomain Forlot <romain.forlot@iot.bzh>2017-02-21 10:59:27 +0000
commitcba9b59fab054d3a33a4d58ed227fc3d4b6f6d9d (patch)
treebc504f0955794d17453a4e4e4717c7b108b5cffe /src
parent4bcb47864452b2d219572862aed3d173c3c0a945 (diff)
Clean up include statement...
Change-Id: Ie909836171ea5eb030246255bb08f1c5b8a65641 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src')
-rw-r--r--src/can-decoder.hpp2
-rw-r--r--src/can-signals.hpp5
-rw-r--r--src/can-utils.cpp37
-rw-r--r--src/can-utils.hpp25
-rw-r--r--src/can_reader.cpp4
-rw-r--r--src/low-can-binding.cpp21
-rw-r--r--src/low-can-binding.hpp18
7 files changed, 67 insertions, 45 deletions
diff --git a/src/can-decoder.hpp b/src/can-decoder.hpp
index eda77277..1b58ea3c 100644
--- a/src/can-decoder.hpp
+++ b/src/can-decoder.hpp
@@ -144,4 +144,4 @@ class decoder_t
*/
openxc_DynamicField decodeSignal(const CanSignal& signal, float value,
const CanSignal& signals, bool* send);
-} \ No newline at end of file
+}; \ No newline at end of file
diff --git a/src/can-signals.hpp b/src/can-signals.hpp
index b115263c..5e7e5816 100644
--- a/src/can-signals.hpp
+++ b/src/can-signals.hpp
@@ -26,6 +26,11 @@
#include "can-utils.hpp"
#include "low-can-binding.hpp"
+extern "C"
+{
+ #include <afb/afb-event-itf.h>
+}
+
#define MESSAGE_SET_ID 0
/** Can signal event map making access to afb_event
diff --git a/src/can-utils.cpp b/src/can-utils.cpp
index 72f00aa9..71788856 100644
--- a/src/can-utils.cpp
+++ b/src/can-utils.cpp
@@ -28,20 +28,20 @@ can_bus_dev_t::can_bus_dev_t(const std::string &dev_name)
{
}
-int can_bus_dev_t::open()
+int can_bus_dev_t::open(const struct afb_binding_interface* interface)
{
const int canfd_on = 1;
struct ifreq ifr;
struct timeval timeout = {1, 0};
- DEBUG(interface_, "open_can_dev: CAN Handler socket : %d", can_socket_);
+ DEBUG(interface, "open_can_dev: CAN Handler socket : %d", can_socket_);
if (can_socket_ >= 0)
return 0;
can_socket_ = ::socket(PF_CAN, SOCK_RAW, CAN_RAW);
- if (socket < 0)
+ if (can_socket_ < 0)
{
- ERROR(interface_, "open_can_dev: socket could not be created");
+ ERROR(interface, "open_can_dev: socket could not be created");
}
else
{
@@ -50,25 +50,25 @@ int can_bus_dev_t::open()
/* try to switch the socket into CAN_FD mode */
if (::setsockopt(can_socket_, SOL_CAN_RAW, CAN_RAW_FD_FRAMES, &canfd_on, sizeof(canfd_on)) < 0)
{
- NOTICE(interface_, "open_can_dev: Can not switch into CAN Extended frame format.");
+ NOTICE(interface, "open_can_dev: Can not switch into CAN Extended frame format.");
is_fdmode_on_ = false;
} else {
is_fdmode_on_ = true;
}
/* Attempts to open a socket to CAN bus */
- ::strcpy(ifr.ifr_name, device);
+ ::strcpy(ifr.ifr_name, device_name_.c_str());
if(::ioctl(can_socket_, SIOCGIFINDEX, &ifr) < 0)
- ERROR(interface_, "open_can_dev: ioctl failed");
+ ERROR(interface, "open_can_dev: ioctl failed");
else
{
- txAddress.can_family = AF_CAN;
- txAddress.can_ifindex = ifr.ifr_ifindex;
+ txAddress_.can_family = AF_CAN;
+ txAddress_.can_ifindex = ifr.ifr_ifindex;
/* And bind it to txAddress */
if (::bind(can_socket_, (struct sockaddr *)&txAddress_, sizeof(txAddress_)) < 0)
{
- ERROR(interface_, "open_can_dev: bind failed");
+ ERROR(interface, "open_can_dev: bind failed");
}
else
{
@@ -87,8 +87,7 @@ int can_bus_dev_t::close()
can_socket_ = -1;
}
-
-canfd_frame can_bus_dev_t::read()
+canfd_frame can_bus_dev_t::read(const struct afb_binding_interface* interface)
{
ssize_t nbytes;
//int maxdlen;
@@ -97,7 +96,7 @@ canfd_frame can_bus_dev_t::read()
/* Test that socket is really opened */
if (can_socket_ < 0)
{
- ERROR(interface_, "read_can: Socket unavailable. Closing thread.");
+ ERROR(interface, "read_can: Socket unavailable. Closing thread.");
is_running_ = false;
}
@@ -106,17 +105,17 @@ canfd_frame can_bus_dev_t::read()
switch(nbytes)
{
case CANFD_MTU:
- DEBUG(interface_, "read_can: Got an CAN FD frame with length %d", canfd_frame.len);
+ DEBUG(interface, "read_can: Got an CAN FD frame with length %d", canfd_frame.len);
//maxdlen = CANFD_MAX_DLEN;
break;
case CAN_MTU:
- DEBUG(interface_, "read_can: Got a legacy CAN frame with length %d", canfd_frame.len);
+ DEBUG(interface, "read_can: Got a legacy CAN frame with length %d", canfd_frame.len);
//maxdlen = CAN_MAX_DLEN;
break;
default:
if (errno == ENETDOWN)
- ERROR(interface_, "read_can: %s interface down", device);
- ERROR(interface_, "read_can: Error reading CAN bus");
+ ERROR(interface, "read_can: %s interface down", device_name_);
+ ERROR(interface, "read_can: Error reading CAN bus");
::memset(&canfd_frame, 0, sizeof(canfd_frame));
is_running_ = false;
break;
@@ -225,7 +224,9 @@ int init_can_dev()
for(const auto& device : devices_name)
{
- can_bus_dev_t(device);
+ can_bus_dev_t can_bus_device_handler(device);
+ can_bus_device_handler.open(interface_);
+ can_bus_device_handler.start_reading(interface_);
i++;
}
diff --git a/src/can-utils.hpp b/src/can-utils.hpp
index 20267ae2..ee87790e 100644
--- a/src/can-utils.hpp
+++ b/src/can-utils.hpp
@@ -23,11 +23,23 @@
#include <cstdio>
#include <string>
#include <thread>
+#include <fcntl.h>
+#include <unistd.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
#include <linux/can.h>
+#include <sys/socket.h>
+#include <linux/can/raw.h>
#include "timer.hpp"
#include "openxc.pb.h"
+extern "C"
+{
+ #include <afb/afb-binding.h>
+ #include <afb/afb-service-itf.h>
+}
+
// TODO actual max is 32 but dropped to 24 for memory considerations
#define MAX_ACCEPTANCE_FILTERS 24
// TODO this takes up a ton of memory
@@ -38,6 +50,13 @@
#define CAN_ACTIVE_TIMEOUT_S 30
/**
+ * @brief Function representing thread activated by can bus objects
+ */
+void can_reader(can_bus_dev_t& can_bus);
+void can_decode_message(can_bus_t& can_bus);
+void can_event_push(can_bus_t& can_bus);
+
+/**
* @brief The type signature for a CAN signal decoder.
*
* @desc A SignalDecoder transforms a raw floating point CAN signal into a number,
@@ -146,11 +165,13 @@ class can_bus_dev_t {
public:
can_bus_dev_t(const std::string& dev_name);
- int open();
+ int open(const struct afb_binding_interface* interface);
int close();
bool is_running();
+ void start_reading();
+ canfd_frame read(const struct afb_binding_interface *interface);
- can_message_t* next_can_message();
+ can_message_t next_can_message();
void push_new_can_message(const can_message_t& can_msg);
bool has_can_message() const;
};
diff --git a/src/can_reader.cpp b/src/can_reader.cpp
index c8891eec..b8ada8d2 100644
--- a/src/can_reader.cpp
+++ b/src/can_reader.cpp
@@ -18,13 +18,13 @@
#include "low-can-binding.hpp"
-void can_reader(can_bus_t &can_bus)
+void can_reader(can_bus__dev_t &can_bus)
{
can_message_t can_message;
while(can_bus.is_running())
{
- can_message.convert_from_canfd_frame(canbus.read());
+ can_message.convert_from_canfd_frame(can_bus.read(interface));
can_bus.push_new_can_message(can_message);
}
} \ No newline at end of file
diff --git a/src/low-can-binding.cpp b/src/low-can-binding.cpp
index 18346fae..aaa9e54a 100644
--- a/src/low-can-binding.cpp
+++ b/src/low-can-binding.cpp
@@ -16,27 +16,6 @@
* limitations under the License.
*/
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#include <net/if.h>
-#include <linux/can.h>
-#include <linux/can/raw.h>
-#include <fcntl.h>
-#include <systemd/sd-event.h>
-#include <errno.h>
-#include <vector>
-#include <map>
-#include <queue>
-#include <string>
-#include <functional>
-#include <memory>
-#include <thread>
-
-#include <json-c/json.h>
-#include <openxc.pb.h>
-
#include "low-can-binding.hpp"
/********************************************************************************
diff --git a/src/low-can-binding.hpp b/src/low-can-binding.hpp
index ea2c027c..a46da6af 100644
--- a/src/low-can-binding.hpp
+++ b/src/low-can-binding.hpp
@@ -18,13 +18,29 @@
#pragma once
+#include <map>
#include <queue>
-#include <sys/timeb.h>
+#include <vector>
+#include <string>
+#include <memory>
+#include <thread>
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+#include <net/if.h>
+#include <functional>
+#include <sys/ioctl.h>
#include <linux/can.h>
+#include <openxc.pb.h>
+#include <sys/timeb.h>
+#include <sys/types.h>
+#include <sys/socket.h>
#include <json-c/json.h>
#include <linux/can/raw.h>
+#include <systemd/sd-event.h>
#include "obd2.hpp"
+#include "timer.hpp"
#include "openxc.pb.h"
#include "can-utils.hpp"
#include "can-signals.hpp"