tCanDeviceDummy.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 // -- BEGIN LICENSE BLOCK ----------------------------------------------
3 // This file is part of FZIs ic_workspace.
4 //
5 // This program is free software licensed under the LGPL
6 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
7 // You can find a copy of this license in LICENSE folder in the top
8 // directory of the source code.
9 //
10 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
11 //
12 // -- END LICENSE BLOCK ------------------------------------------------
13 //----------------------------------------------------------------------
20 //----------------------------------------------------------------------
21 
22 
23 #include <icl_core/os_lxrt.h>
24 
26 
28 
29 namespace icl_hardware {
30 namespace can {
31 
32 tCanDeviceDummy::tCanDeviceDummy(const char* device_name,
33  int flags,
34  unsigned char acceptance_code,
35  unsigned char acceptance_mask,
36  unsigned int baud_rate,
37  unsigned int send_fifo_size,
38  unsigned int receive_fifo_size)
39  : m_receive_enabled(false)
40 {
41  LOGGING_DEBUG(CAN, "Dummy CAN adapter created" << endl);
42 }
43 
44 
46 {
47 
48 }
49 
51 {
52  LOGGING_TRACE(CAN, "Dummy CAN mesage sent..." << endl);
53  m_sent_messages.push_back(msg);
54  m_receive_enabled = true;
55  return 0;
56 }
57 
59 {
60  if (m_received_messages.size() > 0 && m_receive_enabled)
61  {
62  LOGGING_TRACE(CAN, "Receive method called..." << endl);
63  msg = m_received_messages.back();
64  m_received_messages.pop_back();
65  return 1;
66  }
67  return 0;
68 }
69 
71 {
72 
73 }
74 
75 
77 {
78  return true;
79 }
80 
82 {
83  if (m_sent_messages.size() > 0)
84  {
85  return m_sent_messages.back();
86  }
87  else
88  {
89  LOGGING_ERROR (CAN, "No sent messages in cache!" << endl);
90  }
91  return tCanMessage();
92 }
93 
94 void tCanDeviceDummy::addResponse(const tCanMessage& msg, const bool wait_for_send)
95 {
96  LOGGING_TRACE(CAN, "Added response message..." << endl);
97  m_receive_enabled = !wait_for_send;
98  m_received_messages.push_back(msg);
99 }
100 
101 
102 
103 }
104 }
virtual void addResponse(const tCanMessage &msg, const bool wait_for_send=true)
Adds a response to a request that will be sent later. By default, the data won&#39;t bee seen by the rece...
Implements a struct representing a can message.
Definition: tCanMessage.h:43
std::vector< tCanMessage > m_sent_messages
virtual int Receive(tCanMessage &msg)
#define LOGGING_DEBUG(streamname, arg)
#define LOGGING_ERROR(streamname, arg)
ThreadStream & endl(ThreadStream &stream)
virtual tCanMessage getLastMessage() const
icl_hardware::can::tCanMessage tCanMessage
Definition: UseMCACan.h:39
virtual int Send(const tCanMessage &msg)
#define LOGGING_TRACE(streamname, arg)
std::vector< tCanMessage > m_received_messages
tCanDeviceDummy(const char *device_name, int flags, unsigned char acceptance_code, unsigned char acceptance_mask, unsigned int baud_rate, unsigned int send_fifo_size, unsigned int receive_fifo_size)


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