tCanDeviceDummy.cpp
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00003 // This file is part of FZIs ic_workspace.
00004 //
00005 // This program is free software licensed under the LGPL
00006 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00007 // You can find a copy of this license in LICENSE folder in the top
00008 // directory of the source code.
00009 //
00010 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00011 //
00012 // -- END LICENSE BLOCK ------------------------------------------------
00013 //----------------------------------------------------------------------
00020 //----------------------------------------------------------------------
00021 
00022 
00023 #include <icl_core/os_lxrt.h>
00024 
00025 #include "icl_hardware_can/Logging.h"
00026 
00027 #include "icl_hardware_can/tCanDeviceDummy.h"
00028 
00029 namespace icl_hardware {
00030 namespace can {
00031 
00032 tCanDeviceDummy::tCanDeviceDummy(const char* device_name,
00033                                  int flags,
00034                                  unsigned char acceptance_code,
00035                                  unsigned char acceptance_mask,
00036                                  unsigned int baud_rate,
00037                                  unsigned int send_fifo_size,
00038                                  unsigned int receive_fifo_size)
00039   : m_receive_enabled(false)
00040 {
00041  LOGGING_DEBUG(CAN, "Dummy CAN adapter created" << endl);
00042 }
00043 
00044 
00045 tCanDeviceDummy::~tCanDeviceDummy()
00046 {
00047 
00048 }
00049 
00050 int tCanDeviceDummy::Send(const tCanMessage& msg)
00051 {
00052   LOGGING_TRACE(CAN, "Dummy CAN mesage sent..." << endl);
00053   m_sent_messages.push_back(msg);
00054   m_receive_enabled = true;
00055   return 0;
00056 }
00057 
00058 int tCanDeviceDummy::Receive(tCanMessage& msg)
00059 {
00060   if (m_received_messages.size() > 0 && m_receive_enabled)
00061   {
00062     LOGGING_TRACE(CAN, "Receive method called..." << endl);
00063     msg = m_received_messages.back();
00064     m_received_messages.pop_back();
00065     return 1;
00066   }
00067   return 0;
00068 }
00069 
00070 void tCanDeviceDummy::Reset()
00071 {
00072 
00073 }
00074 
00075 
00076 bool tCanDeviceDummy::IsInitialized()
00077 {
00078   return true;
00079 }
00080 
00081 tCanMessage tCanDeviceDummy::getLastMessage() const
00082 {
00083   if (m_sent_messages.size() > 0)
00084   {
00085     return m_sent_messages.back();
00086   }
00087   else
00088   {
00089     LOGGING_ERROR (CAN, "No sent messages in cache!" << endl);
00090   }
00091   return tCanMessage();
00092 }
00093 
00094 void tCanDeviceDummy::addResponse(const tCanMessage& msg, const bool wait_for_send)
00095 {
00096   LOGGING_TRACE(CAN, "Added response message..." << endl);
00097   m_receive_enabled = !wait_for_send;
00098   m_received_messages.push_back(msg);
00099 }
00100 
00101 
00102 
00103 }
00104 }


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