HardwareCanSinkPeak.cpp
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of FZIs ic_workspace.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00024 //----------------------------------------------------------------------
00025 #include "HardwareCanSinkPeak.h"
00026 
00027 #include <icl_core_config/Config.h>
00028 #include <icl_hardware_can/Logging.h>
00029 #include <icl_core_thread/tThread.h>
00030 #include <icl_sourcesink/SimpleURI.h>
00031 
00032 namespace icl_hardware {
00033 namespace can {
00034 
00035 HardwareCanSinkPeak::HardwareCanSinkPeak(const std::string& uri, const std::string& name)
00036   : HardwareCanSink(uri, name),
00037     m_can_device()
00038 {
00039   icl_sourcesink::SimpleURI parsed_uri(uri);
00040 
00041   uint32_t can_baudrate = 500;
00042   boost::optional<uint32_t> uri_baudrate = parsed_uri.getQuery<uint32_t>("baudrate");
00043   if (uri_baudrate)
00044   {
00045     can_baudrate = *uri_baudrate;
00046   }
00047 
00048   LOGGING_DEBUG(CAN, "Device: " << parsed_uri.path() << endl);
00049   LOGGING_DEBUG(CAN, "Baudrate: " << can_baudrate << " kbps" << endl);
00050 
00051   LOGGING_DEBUG(CAN, "Opening CAN-Device... " << endl);
00052   tCanDevice::CheckLXRTInterface();
00053   m_can_device.reset(tCanDevice::Create(parsed_uri.path().c_str(),
00054                                         O_RDWR | O_NONBLOCK,
00055                                         0xff,
00056                                         0xff,
00057                                         can_baudrate,
00058                                         300,
00059                                         8000));
00060 
00061   // Check if CAN device was initialized successfully.
00062   if (m_can_device->IsInitialized())
00063   {
00064     LOGGING_DEBUG(CAN, "CAN device successfully initialized." << endl);
00065   }
00066   else
00067   {
00068     m_can_device.reset();
00069     LOGGING_ERROR(CAN, "Error initializing CAN device." << endl);
00070     return;
00071   }
00072 }
00073 
00074 HardwareCanSinkPeak::~HardwareCanSinkPeak()
00075 { }
00076 
00077 void HardwareCanSinkPeak::set(const CanMessageStamped::Ptr& msg)
00078 {
00079   if (!m_can_device)
00080   {
00081     LOGGING_ERROR(CAN, "CAN device is not available, ignoring received message." << endl);
00082     return;
00083   }
00084 
00085   if (!msg || ((*msg)->id == 0 && (*msg)->dlc == 0 && (*msg)->rtr == 0))
00086   {
00087     LOGGING_WARNING(CAN, "No regular message received." << endl);
00088     return;
00089   }
00090 
00091   m_can_device->Send(**msg);
00092 }
00093 
00094 }
00095 }


fzi_icl_can
Author(s):
autogenerated on Thu Jun 6 2019 20:26:01