Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
DccDebugFlow.hxx
Go to the documentation of this file.
1
35#ifndef _OPENLCB_DCCDEBUGFLOW_HXX_
36#define _OPENLCB_DCCDEBUGFLOW_HXX_
37
38namespace openlcb {
39
43class DccPacketDebugFlow : public StateFlow<Buffer<dcc::Packet>, QList<1>> {
44 public:
47 node->iface()->dispatcher()->service()),
48 node_(node) {}
49
50 private:
51 Action entry() override {
52 Debug::DccPacketDelay::set(false);
53 return allocate_and_call(node_->iface()->global_message_write_flow(),
54 STATE(msg_allocated));
55 }
56
57 Action msg_allocated() {
58 auto* b =
59 get_allocation_result(node_->iface()->global_message_write_flow());
60
61 b->data()->reset(
62 static_cast<openlcb::Defs::MTI>(openlcb::Defs::MTI_XPRESSNET + 1),
63 node_->node_id(),
64 string((char*)message()->data()->payload, message()->data()->dlc));
65 node_->iface()->global_message_write_flow()->send(b);
66 return release_and_exit();
67 }
68
69 openlcb::Node* node_;
70};
71
73extern DccPacketDebugFlow g_packet_debug_flow;
74
80 public:
81 DccDebugDecodeFlow(Service* service, const char* path) : dcc::DccDecodeFlow(service, path) {}
82
83 private:
84 void dcc_packet_finished(const uint8_t* payload, size_t len) override {
85 auto* b = g_packet_debug_flow.alloc();
86 b->data()->dlc = len;
87 memcpy(b->data()->payload, payload, len);
89 }
90
91 void mm_packet_finished(const uint8_t* payload, size_t len) override {
92 auto* b = g_packet_debug_flow.alloc();
93 b->data()->dlc = len;
94 memcpy(b->data()->payload, payload, len);
95 b->data()->payload[0] |= 0xFC;
97 }
98
99 void debug_data(uint32_t value) override {
100 value /= (configCPU_CLOCK_HZ / 1000000);
101 log(decoder_.state());
102 log(value);
103 }
104
105 void log(uint8_t value) {
106 dbuffer[ptr] = value;
107 ++ptr;
108 if (ptr >= sizeof(dbuffer)) ptr = 0;
109 }
110 uint8_t dbuffer[1024];
111 uint16_t ptr = 0;
112};
113
114
115} // namespace
116
117#endif // _OPENLCB_DCCDEBUGFLOW_HXX_
#define STATE(_fn)
Turns a function name into an argument to be supplied to functions expecting a state.
Definition StateFlow.hxx:61
virtual void send(MessageType *message, unsigned priority=UINT_MAX)=0
Entry point to the flow.
MessageType * alloc()
Synchronously allocates a message buffer from the pool of this flow.
A list of queues.
Definition Queue.hxx:466
Collection of related state machines that pend on incoming messages.
Service * service()
Return a pointer to the service I am bound to.
State flow with a given typed input queue.
Base::Action Action
Allows using Action without having StateFlowBase:: prefix in front of it.
void send(MessageType *msg, unsigned priority=UINT_MAX) OVERRIDE
Sends a message to the state flow for processing.
MessageType * message()
User-space DCC decoding flow.
Definition Receiver.hxx:457
DccDecoder decoder_
State machine that does the DCC decoding.
Definition Receiver.hxx:515
Debug flow for the DCC decoder driver.
Sends every incoming DCC packet as a custom OpenLCB message to the OpenLCB bus.
Action entry() override
Entry into the StateFlow activity.
MessageHandler * global_message_write_flow()
Definition If.hxx:200
MessageDispatchFlow * dispatcher()
Definition If.hxx:224
Base class for NMRAnet nodes conforming to the asynchronous interface.
Definition Node.hxx:52
DccPacketDebugFlow g_packet_debug_flow
Global reference to the packet debug flow.
MTI
Known Message type indicators.