Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
common/Can.hxx
Go to the documentation of this file.
1
34#ifndef _FREERTOS_DRIVERS_COMMON_CAN_HXX_
35#define _FREERTOS_DRIVERS_COMMON_CAN_HXX_
36
37#include "Devtab.hxx"
38#include "can_frame.h"
39#include "nmranet_config.h"
40#include "os/OS.hxx"
42#include "DeviceBuffer.hxx"
43
45class Can : public NonBlockNode
46{
47public:
48 static unsigned numReceivedPackets_;
49 static unsigned numTransmittedPackets_;
50
51protected:
57 Can(const char *name, size_t tx_buffer_size = config_can_tx_buffer_size(),
58 size_t rx_buffer_size = config_can_rx_buffer_size())
60 , txBuf(DeviceBuffer<struct can_frame>::create(tx_buffer_size,
61 tx_buffer_size / 2))
62 , rxBuf(DeviceBuffer<struct can_frame>::create(rx_buffer_size))
63 , overrunCount(0)
64 , busOffCount(0)
66 {
67 }
68
72 {
73 txBuf->destroy();
74 rxBuf->destroy();
75 }
76
77 void enable() override = 0;
78 void disable() override = 0;
79 virtual void tx_msg() = 0;
86 return txBuf->space();
87 }
88
94 return rxBuf->pending();
95 }
96
97 void flush_buffers() OVERRIDE;
99 DeviceBuffer<struct can_frame> *txBuf;
100 DeviceBuffer<struct can_frame> *rxBuf;
101 unsigned int overrunCount;
102 unsigned int busOffCount;
103 unsigned int softErrorCount;
105protected:
112 ssize_t read(File *file, void *buf, size_t count) OVERRIDE;
113
120 ssize_t write(File *file, const void *buf, size_t count) OVERRIDE;
121
128 bool select(File* file, int mode) OVERRIDE;
129
130private:
132};
133
134#endif /* _FREERTOS_DRIVERS_COMMON_CAN_HXX_ */
Base class for a CAN device for the Arduino environment.
unsigned int overrunCount
overrun count
unsigned int softErrorCount
soft error count
DeviceBuffer< struct can_frame > * txBuf
transmit buffer
int read(struct can_frame *frame)
Read a frame if there is one available.
void flush_buffers() OVERRIDE
called after disable
unsigned int busOffCount
bus-off count
~Can()
Destructor.
Can(const char *name, size_t tx_buffer_size=config_can_tx_buffer_size(), size_t rx_buffer_size=config_can_rx_buffer_size())
Constructor.
bool has_rx_buffer_data() OVERRIDE
void disable() override=0
function to disable device
DeviceBuffer< struct can_frame > * rxBuf
receive buffer
bool has_tx_buffer_space() OVERRIDE
virtual void tx_msg()=0
function to try and transmit a message
bool select(File *file, int mode) OVERRIDE
Device select method.
void enable() override=0
function to enable device
int write(const struct can_frame *frame)
Send a frame if there is space available.
size_t space()
Return the number of items for which space is available.
size_t pending()
Return the number of items in the queue.
Implements a smart buffer specifically designed for character device drivers.
void destroy()
Destroy an existing DeviceBuffer instance.
const char * name
device name
Definition Devtab.hxx:266
Node information for a device node in the filesystem that has support for nonblocking mode via Notifi...
Definition Devtab.hxx:611
#define OVERRIDE
Function attribute for virtual functions declaring that this funciton is overriding a funciton that s...
Definition macros.h:180
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Removes default copy-constructor and assignment added by C++.
Definition macros.h:171
File information.
Definition Devtab.hxx:52