Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
CanIf.hxx
Go to the documentation of this file.
1
37#ifndef _UTILS_CANIF_HXX_
38#define _UTILS_CANIF_HXX_
39
40#include "can_frame.h"
41#include "utils/Hub.hxx"
42
45struct CanMessageData : public can_frame
46{
49 {
50 can_id = 0;
51 CLR_CAN_FRAME_ERR(*this);
52 CLR_CAN_FRAME_RTR(*this);
53 SET_CAN_FRAME_EFF(*this);
54 can_dlc = 0;
55 }
56
58 typedef uint32_t id_type;
59
62 static const id_type STANDARD_FRAME_BIT = (1U << 30);
63
66 static const uint32_t CAN_EXT_FRAME_FILTER = 0;
69 static const uint32_t CAN_EXT_FRAME_MASK = ~0x1FFFFFFFU;
70
76 static const uint32_t CAN_STD_FRAME_MASK = ~0x7FFU;
77
78
81 {
82 if (IS_CAN_FRAME_EFF(*this))
83 {
84 return GET_CAN_FRAME_ID_EFF(*this);
85 }
86 else
87 {
88 return GET_CAN_FRAME_ID(*this) | STANDARD_FRAME_BIT;
89 }
90 }
91
93 struct can_frame *mutable_frame()
94 {
95 return this;
96 }
97
99 const struct can_frame &frame() const
100 {
101 return *this;
102 }
103
106 void *unused;
107};
108
118
119class CanIf;
120
130{
131public:
134 : ifCan_(service)
135 {
136 }
137
139 Pool *pool() OVERRIDE;
140
145 void send(
146 Buffer<CanHubData> *message, unsigned priority = UINT_MAX) OVERRIDE;
147
148private:
151};
152
156{
157public:
161 : ifCan_(service)
162 {
163 }
164
167 Pool *pool() OVERRIDE;
168
174 void send(
175 Buffer<CanHubData> *message, unsigned priority = UINT_MAX) OVERRIDE;
176
177private:
180};
181
184class CanIf
185{
186public:
194 CanIf(Service *service, CanHubFlow *device);
195 ~CanIf();
196
200
203 {
204 return frameDispatcher_.service();
205 }
206
209 {
210 return &frameDispatcher_;
211 }
212
215 {
216 return &frameWriteFlow_;
217 }
218
222 {
223 return &frameReadFlow_;
224 }
225
226private:
227 friend class CanFrameWriteFlow;
228 // friend class CanFrameReadFlow;
229
232
235
239
242
245 {
246 return &frameReadFlow_;
247 }
250 {
251 return device_;
252 }
253};
254
255#endif // _UTILS_CANIF_HXX_
StateFlow< Buffer< CanMessageData >, QList< 1 > > IncomingFrameFlow
StateFlow handling incoming messages as registered to the message dispatcher.
Definition CanIf.hxx:115
FlowInterface< Buffer< CanHubData > > OutgoingFrameHandler
Base class of flow to send outgoing CAN frames to.
Definition CanIf.hxx:117
FlowInterface< Buffer< CanMessageData > > IncomingFrameHandler
Definition CanIf.hxx:112
Base class for all QMember types that hold data in an expandable format.
Definition Buffer.hxx:195
This flow is responsible for taking data from the can HUB and sending it to the IfCan's dispatcher.
Definition CanIf.hxx:156
CanFrameReadFlow(CanIf *service)
Constructor.
Definition CanIf.hxx:160
Interface class for the asynchronous frame write flow.
Definition CanIf.hxx:130
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
CanFrameWriteFlow(CanIf *service)
Constructor.
Definition CanIf.hxx:133
CanIf * ifCan_
Parent that owns this flow.
Definition CanIf.hxx:150
Interface class for CANbus-based protocols.
Definition CanIf.hxx:185
FrameDispatchFlow * frame_dispatcher()
Definition CanIf.hxx:208
CanHubPortInterface * hub_port()
Definition CanIf.hxx:244
OutgoingFrameHandler * loopback_frame_write_flow()
Definition CanIf.hxx:221
DispatchFlow< Buffer< CanMessageData >, 4 > FrameDispatchFlow
Type of the dispatcher responsible for routing incoming frames to the frome handlers.
Definition CanIf.hxx:199
OutgoingFrameHandler * frame_write_flow()
Definition CanIf.hxx:214
Service * service()
Definition CanIf.hxx:202
CanFrameReadFlow frameReadFlow_
Flow responsible for translating from CAN hub packets to dispatcher packets.
Definition CanIf.hxx:238
CanHubFlow * device()
Definition CanIf.hxx:249
CanHubFlow * device_
The device we need to send packets to.
Definition CanIf.hxx:231
CanFrameWriteFlow frameWriteFlow_
Flow responsible for writing packets to the CAN hub.
Definition CanIf.hxx:234
FrameDispatchFlow frameDispatcher_
Flow responsible for routing incoming messages to handlers.
Definition CanIf.hxx:241
Type-specific implementations of the DispatchFlow methods.
Abstract class for message recipients.
Data type wrapper for sending data through a Hub.
Definition Hub.hxx:101
Pool of previously allocated, but currently unused, items.
Definition Buffer.hxx:278
A list of queues.
Definition Queue.hxx:466
Collection of related state machines that pend on incoming messages.
State flow with a given typed input queue.
#define OVERRIDE
Function attribute for virtual functions declaring that this funciton is overriding a funciton that s...
Definition macros.h:180
Thin wrapper around struct can_frame that will allow a dispatcher select the frames by CAN ID and mas...
Definition CanIf.hxx:46
struct can_frame * mutable_frame()
Definition CanIf.hxx:93
static const uint32_t CAN_STD_FRAME_FILTER
Filter to OR onto a can ID to tell the dispatcher to only consider extended can frames.
Definition CanIf.hxx:73
const struct can_frame & frame() const
Definition CanIf.hxx:99
static const id_type STANDARD_FRAME_BIT
This bit will be set in standard CAN frames when they get to the dispatcher.
Definition CanIf.hxx:62
CanMessageData()
Constructor.
Definition CanIf.hxx:48
static const uint32_t CAN_EXT_FRAME_MASK
Mask to OR onto a can mask to tell the dispatcher to only consider extended can frames.
Definition CanIf.hxx:69
static const uint32_t CAN_STD_FRAME_MASK
Mask to OR onto a can mask to tell the dispatcher to only consider extended can frames.
Definition CanIf.hxx:76
void * unused
This will be aliased onto CanHubData::skipMember_.
Definition CanIf.hxx:106
id_type id()
Definition CanIf.hxx:80
uint32_t id_type
This is the maskable identifier of the incoming CAN frames.
Definition CanIf.hxx:58
static const uint32_t CAN_EXT_FRAME_FILTER
Filter to OR onto a can ID to tell the dispatcher to only consider extended can frames.
Definition CanIf.hxx:66