Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
BootloaderPort.hxx
Go to the documentation of this file.
1
36#ifndef _OPENLCB_BOOTLOADERPORT_HXX_
37#define _OPENLCB_BOOTLOADERPORT_HXX_
38
39#include "utils/Hub.hxx"
40
41namespace openlcb {
42
45{
46public:
49 {
50 is_waiting_ = false;
51 }
52
53 bool is_waiting()
54 {
55 return is_waiting_;
56 }
57
58 Action entry() override
59 {
60 AtomicHolder h(this);
61 is_waiting_ = true;
62 return wait_and_call(STATE(sent));
63 }
64
65 Action sent()
66 {
67 return release_and_exit();
68 }
69
70 bool read_can_frame(struct can_frame *frame)
71 {
72 {
73 AtomicHolder h(this);
74 if (is_waiting_)
75 {
76 *frame = *message()->data();
77 is_waiting_ = false;
78 }
79 else
80 {
81 return false;
82 }
83 }
84 notify();
85 return true;
86 }
87
88private:
91 bool is_waiting_ = false;
92};
93
94} // namespace openlcb
95
96#endif //_OPENLCB_BOOTLOADERPORT_HXX_
97
StateFlow< Buffer< CanHubData >, QList< 1 > > CanHubPort
Base class for a port to an CAN hub that is implemented as a stateflow.
Definition Hub.hxx:143
#define STATE(_fn)
Turns a function name into an argument to be supplied to functions expecting a state.
Definition StateFlow.hxx:61
See OSMutexLock in os/OS.hxx.
Definition Atomic.hxx:153
Collection of related state machines that pend on incoming messages.
Return type for a state flow callback.
Service * service()
Return a pointer to the service I am bound to.
Action wait_and_call(Callback c)
Wait for resource to become available before proceeding to next state.
void notify() override
Wakeup call arrived. Schedules *this on the executor.
Action release_and_exit()
Terminates the processing of the current message.
State flow with a given typed input queue.
Proxy class for sending canbus traffic to the Bootloader HAL.
bool is_waiting_
True if an incoming message is ready for dispatching and the current flow is waiting for a notify.
Action entry() override
Entry into the StateFlow activity.