Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
CanIf.cxx
Go to the documentation of this file.
1
37#include "utils/CanIf.hxx"
38
40{
41 return ifCan_->device()->pool();
42}
43
44void CanFrameWriteFlow::send(Buffer<CanHubData> *message, unsigned priority)
45{
46 LOG(VERBOSE, "outgoing message %" PRIx32 ".",
47 GET_CAN_FRAME_ID_EFF(message->data()->frame()));
48 message->data()->skipMember_ = ifCan_->hub_port();
49 ifCan_->device()->send(message, priority);
50}
51
53{
54 /* NOTE(balazs.racz) This pool should rather be the application-level
55 * buffer pool (for example openlcb::AsyncIf::dispatcher()::pool(), but
56 * that pointer is not available here. At the moment applications use the
57 * mainBufferPool. */
58 return ifCan_->frame_dispatcher()->pool();
59}
60
61void CanFrameReadFlow::send(Buffer<CanHubData> *message, unsigned priority)
62{
63 const struct can_frame &frame = message->data()->frame();
64 if (IS_CAN_FRAME_ERR(frame) || IS_CAN_FRAME_RTR(frame))
65 {
66 // Ignores these frames.
67 message->unref();
68 return;
69 }
70
71 // We typecast the incoming buffer to a different buffer type that should be
72 // the subset of the data.
73 Buffer<CanMessageData> *incoming_buffer;
74
75 // Checks that it fits.
76 HASSERT(sizeof(*incoming_buffer) <= sizeof(*message));
77 // Does the cast.
78 incoming_buffer = static_cast<Buffer<CanMessageData> *>(
79 static_cast<BufferBase *>(message));
80 // Checks that the frame is still in the same place (by pointer).
81 HASSERT(incoming_buffer->data()->mutable_frame() ==
82 message->data()->mutable_frame());
83
86 ifCan_->frame_dispatcher()->send(incoming_buffer, priority);
87}
88
90 : device_(device)
91 , frameWriteFlow_(this)
92 , frameReadFlow_(this)
93 , frameDispatcher_(service) {
94 this->device()->register_port(hub_port());
95}
96
97CanIf::~CanIf() {
99}
Abstract base class for all Buffers.
Definition Buffer.hxx:85
Base class for all QMember types that hold data in an expandable format.
Definition Buffer.hxx:195
void unref()
Decrement count.
Definition Buffer.hxx:675
T * data()
get a pointer to the start of the data.
Definition Buffer.hxx:215
void send(Buffer< CanHubData > *message, unsigned priority=UINT_MAX) OVERRIDE
Entry point to the flow.
Definition CanIf.cxx:61
Pool * pool() OVERRIDE
Definition CanIf.cxx:52
CanIf * ifCan_
Interface that owns this flow.
Definition CanIf.hxx:179
void send(Buffer< CanHubData > *message, unsigned priority=UINT_MAX) OVERRIDE
Entry point to this flow.
Definition CanIf.cxx:44
Pool * pool() OVERRIDE
Definition CanIf.cxx:39
CanIf * ifCan_
Parent that owns this flow.
Definition CanIf.hxx:150
CanIf(Service *service, CanHubFlow *device)
Constructor.
Definition CanIf.cxx:89
FrameDispatchFlow * frame_dispatcher()
Definition CanIf.hxx:208
CanHubPortInterface * hub_port()
Definition CanIf.hxx:244
CanHubFlow * device()
Definition CanIf.hxx:249
virtual Pool * pool()
void register_port(port_type *port)
Adds a new port.
Definition Hub.hxx:167
void unregister_port(port_type *port)
Removes a previously added port.
Definition Hub.hxx:174
Pool of previously allocated, but currently unused, items.
Definition Buffer.hxx:278
Collection of related state machines that pend on incoming messages.
void send(MessageType *msg, unsigned priority=UINT_MAX) OVERRIDE
Sends a message to the state flow for processing.
#define LOG(level, message...)
Conditionally write a message to the logging output.
Definition logging.h:99
static const int VERBOSE
Loglevel that is usually not printed, reporting debugging information.
Definition logging.h:59
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
Definition macros.h:138