yarp-devices
YarpCanSenderDelegate.hpp
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 #ifndef __YARP_CAN_SENDER_DELEGATE_HPP__
4 #define __YARP_CAN_SENDER_DELEGATE_HPP__
5 
6 #include <atomic>
7 #include <mutex>
8 #include <unordered_map>
9 
10 #include <yarp/dev/CanBusInterface.h>
11 
12 #include "ICanSenderDelegate.hpp"
13 
14 namespace roboticslab
15 {
16 
22 {
23 public:
25  YarpCanSenderDelegate(yarp::dev::CanBuffer & _buffer, std::mutex & _bufferMutex,
26  unsigned int & n, unsigned int size)
27  : buffer(_buffer),
28  bufferMutex(_bufferMutex),
29  preparedMessages(n),
30  maxSize(size),
31  isActive(true)
32  {}
33 
34  bool prepareMessage(const can_message & msg) override;
35  void reportAvailability(bool available, unsigned int id) override;
36 
37 private:
38  yarp::dev::CanBuffer & buffer;
39  std::mutex & bufferMutex;
40  unsigned int & preparedMessages;
41  unsigned int maxSize;
42  std::atomic_bool isActive;
43  std::unordered_map<unsigned int, bool> nodeAvailability;
44 };
45 
46 } // namespace roboticslab
47 
48 #endif // __YARP_CAN_SENDER_DELEGATE_HPP__
Implementation-agnostic consumer for TX CAN transfers.
Definition: ICanSenderDelegate.hpp:22
A sender delegate that adheres to standard YARP interfaces for CAN.
Definition: YarpCanSenderDelegate.hpp:22
void reportAvailability(bool available, unsigned int id) override
Report availability of CAN node.
Definition: YarpCanSenderDelegate.cpp:38
YarpCanSenderDelegate(yarp::dev::CanBuffer &_buffer, std::mutex &_bufferMutex, unsigned int &n, unsigned int size)
Constructor, takes a reference to an existing CAN message buffer.
Definition: YarpCanSenderDelegate.hpp:25
bool prepareMessage(const can_message &msg) override
Register CAN message for write.
Definition: YarpCanSenderDelegate.cpp:11
The main, catch-all namespace for Robotics Lab UC3M.
Definition: groups.dox:6
Proxy CAN message structure.
Definition: CanMessage.hpp:20