Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
LocalTrackIf.cxx
1
36#include <unistd.h>
37#include <fcntl.h>
38
39#include "openmrn_features.h"
40#ifdef OPENMRN_FEATURE_FD_CAN_DEVICE
41
42#define LOGLEVEL INFO
43
44#ifdef __FreeRTOS__
45#include "freertos/can_ioctl.h"
46#else
47#include "can_ioctl.h"
48#endif
49
50#endif // OPENMRN_FEATURE_FD_CAN_DEVICE
51
52#include "dcc/LocalTrackIf.hxx"
53
54namespace dcc
55{
56
57LocalTrackIf::LocalTrackIf(Service *service, int pool_size)
58 : StateFlow<Buffer<dcc::Packet>, QList<1>>(service)
59 , fd_(-1)
60 , pool_(sizeof(Buffer<dcc::Packet>), pool_size)
61{
62}
63
64#if defined(OPENMRN_FEATURE_FD_CAN_DEVICE) || defined(GTEST)
66{
67 HASSERT(fd_ >= 0);
68 auto *p = message()->data();
69 int ret = write(fd_, p, sizeof(*p));
70 if (ret < 0) {
71 HASSERT(errno == ENOSPC);
72 #ifndef GTEST
74 #endif
75 return wait();
76 }
77 return finish();
78}
79#endif
80
82 HASSERT(fd_ >= 0);
83 auto *p = message()->data();
84 return write_repeated(&helper_, fd_, p, sizeof(*p), STATE(finish));
85}
86
87} // namespace dcc
88
int ioctl(int fd, unsigned long int key,...)
Request and ioctl transaction.
Definition Fileio.cxx:452
#define STATE(_fn)
Turns a function name into an argument to be supplied to functions expecting a state.
Definition StateFlow.hxx:61
Base class for all QMember types that hold data in an expandable format.
Definition Buffer.hxx:195
A list of queues.
Definition Queue.hxx:466
Collection of related state machines that pend on incoming messages.
Return type for a state flow callback.
State flow with a given typed input queue.
MessageType * message()
StateFlowSelectHelper helper_
Helper class for select() ing the target device.
Action entry() OVERRIDE
Entry into the StateFlow activity.
LocalTrackIf(Service *service, int pool_size)
Constructs a TrackInterface from an fd to the mainline.
Action entry() OVERRIDE
Entry into the StateFlow activity.
int fd_
Filedes of the device to which we are writing the generated packets.
#define CAN_IOC_WRITE_ACTIVE
write active ioctl.
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
Definition macros.h:138
Represents a command to be sent to the track driver.
Definition Packet.hxx:52