HardwareCanSinkPeak.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
24 //----------------------------------------------------------------------
25 #include "HardwareCanSinkPeak.h"
26 
27 #include <icl_core_config/Config.h>
29 #include <icl_core_thread/tThread.h>
30 #include <icl_sourcesink/SimpleURI.h>
31 
32 namespace icl_hardware {
33 namespace can {
34 
35 HardwareCanSinkPeak::HardwareCanSinkPeak(const std::string& uri, const std::string& name)
36  : HardwareCanSink(uri, name),
37  m_can_device()
38 {
39  icl_sourcesink::SimpleURI parsed_uri(uri);
40 
41  uint32_t can_baudrate = 500;
42  boost::optional<uint32_t> uri_baudrate = parsed_uri.getQuery<uint32_t>("baudrate");
43  if (uri_baudrate)
44  {
45  can_baudrate = *uri_baudrate;
46  }
47 
48  LOGGING_DEBUG(CAN, "Device: " << parsed_uri.path() << endl);
49  LOGGING_DEBUG(CAN, "Baudrate: " << can_baudrate << " kbps" << endl);
50 
51  LOGGING_DEBUG(CAN, "Opening CAN-Device... " << endl);
53  m_can_device.reset(tCanDevice::Create(parsed_uri.path().c_str(),
54  O_RDWR | O_NONBLOCK,
55  0xff,
56  0xff,
57  can_baudrate,
58  300,
59  8000));
60 
61  // Check if CAN device was initialized successfully.
62  if (m_can_device->IsInitialized())
63  {
64  LOGGING_DEBUG(CAN, "CAN device successfully initialized." << endl);
65  }
66  else
67  {
68  m_can_device.reset();
69  LOGGING_ERROR(CAN, "Error initializing CAN device." << endl);
70  return;
71  }
72 }
73 
75 { }
76 
78 {
79  if (!m_can_device)
80  {
81  LOGGING_ERROR(CAN, "CAN device is not available, ignoring received message." << endl);
82  return;
83  }
84 
85  if (!msg || ((*msg)->id == 0 && (*msg)->dlc == 0 && (*msg)->rtr == 0))
86  {
87  LOGGING_WARNING(CAN, "No regular message received." << endl);
88  return;
89  }
90 
91  m_can_device->Send(**msg);
92 }
93 
94 }
95 }
icl_sourcesink::DataSink< tCanMessage > HardwareCanSink
Base type for all sinks providing tCanMessage data.
unsigned int uint32_t
#define LOGGING_DEBUG(streamname, arg)
static tCanDevice * Create(const char *device_name, int flags, unsigned char acceptance_code, unsigned char acceptance_mask, unsigned int baud_rate, unsigned send_fifo_size, unsigned receive_fifo_size)
Definition: tCanDevice.cpp:96
boost::shared_ptr< Stamped< DataType > > Ptr
#define LOGGING_ERROR(streamname, arg)
static void CheckLXRTInterface()
Definition: tCanDevice.cpp:72
ThreadStream & endl(ThreadStream &stream)
boost::scoped_ptr< tCanDevice > m_can_device
The CAN device.
virtual void set(const CanMessageStamped::Ptr &msg)
HardwareCanSinkPeak(const std::string &uri="HardwareCanSinkPeak", const std::string &name="UnnamedHardwareCanSinkPeak")
Constructor.
#define LOGGING_WARNING(streamname, arg)


fzi_icl_can
Author(s):
autogenerated on Mon Jun 10 2019 13:17:02