Communication Library for Autonomous Systems v1.0
Reliable and secure communication library for autonomous vehicle systems
Loading...
Searching...
No Matches
bus.h
Go to the documentation of this file.
1#ifndef CAN_H
2#define CAN_H
3
4#include "api/traits.h"
5#include "api/util/observed.h"
6#include "api/util/debug.h"
8#include <cstring>
9
10class Condition {
11 public:
15
17 Condition() = default;
18 ~Condition() = default;
19
20 const Unit unit() const;
21 const Type type() const;
22
23 inline bool operator==(const Condition& other) const;
24 inline bool operator!=(const Condition& other) const;
25
26 private:
27 Unit _unit;
28 Type _type;
29};
30
32 _unit = unit;
33 _type = type;
34}
35
37 return _unit;
38}
39
41 return _type;
42}
43
45 return ((_unit == other.unit()) && (_type == other.type()));
46}
47
49 return !(*this == other);
50}
51
52class CAN : public Concurrent_Observed<Initializer::Message, Condition>{
53 public:
60
61 CAN() = default;
62 ~CAN() = default;
63
64 int send(Message* msg);
65 bool notify(Message* buf, Condition c) override;
66};
67
69 db<CAN>(TRC) << "CAN::send() called!\n";
70 Condition c(msg->unit(), msg->message_type());
71 if (!notify(msg, c))
72 return 0;
73
74 return msg->size();
75}
76
79 bool notified = false;
80
81 db<CAN>(INF) << "Notifying observers...\n";
82
83 for (typename Observers::Iterator obs = _observers.begin(); obs != _observers.end(); ++obs) {
84
85 if ((*obs)->rank() == c || (*obs)->rank().type() == Condition::Type::UNKNOWN) {
86 Message* msg = new Message(*buf);
87 (*obs)->update((*obs)->rank(), msg);
88 notified = true;
89 }
90 }
91
93 return notified;
94}
95
96#endif // CAN_H
Definition bus.h:52
CAN()=default
int send(Message *msg)
Definition bus.h:68
Concurrent_Observer< Message, Condition > Observer
Definition bus.h:58
~CAN()=default
Initializer::Message Message
Definition bus.h:54
Concurrent_Observed< Message, Condition > Observed
Definition bus.h:59
Message::Unit Unit
Definition bus.h:56
Message::Type Type
Definition bus.h:57
bool notify(Message *buf, Condition c) override
Definition bus.h:77
Initializer::Protocol_T::Address Address
Definition bus.h:55
Definition observed.h:106
pthread_mutex_t _mtx
Definition observed.h:124
Observers _observers
Definition observed.h:125
Definition observer.h:79
Definition bus.h:10
Initializer::Message Message
Definition bus.h:12
Message::Type Type
Definition bus.h:14
bool operator!=(const Condition &other) const
Definition bus.h:48
bool operator==(const Condition &other) const
Definition bus.h:44
Message::Unit Unit
Definition bus.h:13
Condition()=default
const Type type() const
Definition bus.h:40
const Unit unit() const
Definition bus.h:36
~Condition()=default
Template class for network messages with Clock integration.
Definition message.h:31
Type
Definition message.h:35
std::uint32_t Unit
Definition message.h:48
Iterator begin()
Definition list.h:81
Iterator end()
Definition list.h:86
std::list< Observer * >::iterator Iterator
Definition list.h:27
Definition protocol.h:134
@ INF
Definition debug.h:208
Select_Debug<(Traits< T >::debugged &&Traits< Debug >::error)> db(Debug_Error l)
Definition debug.h:166
@ TRC
Definition debug.h:231