35#ifndef _DCC_RAILCOMPORTDEBUG_HXX
36#define _DCC_RAILCOMPORTDEBUG_HXX
70 for (
int i = 0; i < len; ++i)
72 ofs += sprintf(buf + ofs,
"0x%02x (0x%02x), ", data[i],
83 case dcc::RMOB_ADRLOW:
84 ofs += sprintf(buf + ofs,
"adrlow=%d", payload);
86 case dcc::RMOB_ADRHIGH:
87 ofs += sprintf(buf + ofs,
"adrhigh=%d", payload);
90 ofs += sprintf(buf + ofs,
"ext=%d", payload);
93 ofs += sprintf(buf + ofs,
"dyn=%d", payload);
96 ofs += sprintf(buf + ofs,
"subid=%d", payload);
99 ofs += sprintf(buf + ofs,
"type-%d=%d", type, payload);
102 return string(buf, ofs);
168 unsigned correct = 0;
170 for (
unsigned i = 0; i < fb.
ch1Size; i++)
177 for (
unsigned i = 0; i < fb.
ch2Size; i++)
184 if (total > 0 && correct == total)
188 for (
volatile int i = 0; i < 3000; i++) { }
216 bool ack_enabled =
true)
220 , occupancyPort_(occupancy_port)
234 , occupancyPort_(
nullptr)
248 if (
message()->data()->channel == 0xff)
250 if (occupancyPort_) {
257 if (
message()->data()->channel >= 0xf0)
269 STATE(ch1_msg_allocated), &outputPool_);
277 Action ch1_msg_allocated()
284 node_->node_id(),
string());
285 b->data()->payload.push_back(
message()->data()->channel | 0x10);
286 b->data()->payload.append(
293 Action maybe_send_ch2()
295 if (
message()->data()->ch2Size &&
298 dcc::railcom_decode[
message()->data()->ch2Data[0]] !=
303 STATE(ch2_msg_allocated), &outputPool_);
311 Action ch2_msg_allocated()
318 node_->node_id(),
string());
319 b->data()->payload.push_back(
message()->data()->channel | 0x20);
320 b->data()->payload.append(
std::unique_ptr< Buffer< T >, BufferDelete< T > > AutoReleaseBuffer
This class will automatically unref a Buffer when going out of scope.
const uint8_t railcom_decode[256]
Table for 8-to-6 decoding of railcom data.
#define STATE(_fn)
Turns a function name into an argument to be supplied to functions expecting a state.
Base class for all QMember types that hold data in an expandable format.
Abstract class for message recipients.
virtual void send(MessageType *message, unsigned priority=UINT_MAX)=0
Entry point to the flow.
Templated implementation of the HubFlow.
void register_port(port_type *port)
Adds a new port.
void unregister_port(port_type *port)
Removes a previously added port.
OS-independent abstraction for GPIO.
virtual void write(Value new_state) const =0
Writes a GPIO output pin (set or clear to a specific state).
Implementation of a Pool interface that takes memory from mainBufferPool (configurable) but limits th...
size_t free_items() override
Number of free items in the pool.
Return type for a state flow callback.
Action allocate_and_call(FlowInterface< Buffer< T > > *target_flow, Callback c, Pool *pool=nullptr)
Allocates a buffer from a pool and proceed to the next state when allocation is successful.
Buffer< T > * get_allocation_result(FlowInterface< Buffer< T > > *target_flow)
Takes the result of the asynchronous allocation.
Action exit()
Terminates the processing of this flow.
Action release_and_exit()
Terminates the processing of the current message.
State flow with a given typed input queue.
void release() OVERRIDE
Unrefs the current buffer.
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 * transfer_message()
Releases ownership of the current message.
Action call_immediately(Callback c)
Imediately call the next state upon return.
Registers as a member ofthe railcom hub.
dcc::RailcomHubFlow * parent_
Flow to which we are registered.
void send(Buffer< dcc::RailcomHubData > *d, unsigned prio) OVERRIDE
Incoming railcom data.
string display_railcom_data(const uint8_t *data, int len)
Helper function to turn some railcom data into string.
RailcomPrintfFlow(dcc::RailcomHubFlow *source)
Constructor.
This flow listens to Railcom packets coming from the hub, and if they are correctly decoded,...
RailcomToGpioFlow(dcc::RailcomHubFlow *source, const Gpio *output)
Constructor.
const Gpio * output_
Output gpio to toggle.
void send(Buffer< dcc::RailcomHubData > *d, unsigned prio) OVERRIDE
Incoming railcom data.
dcc::RailcomHubFlow * parent_
Flow to which we are registered.
MessageHandler * global_message_write_flow()
Base class for NMRAnet nodes conforming to the asynchronous interface.
This flow proxies all incoming railcom traffic to the openlcb bus in non-standard messages.
uint8_t ch1Enabled_
True if we should transmit channel1 data.
uint8_t ackEnabled_
True if we should transmit data that starts with an ACK.
Action entry() override
Entry into the StateFlow activity.
#define LOG(level, message...)
Conditionally write a message to the logging output.
static const int INFO
Loglevel that is printed by default, reporting some status information.
#define OVERRIDE
Function attribute for virtual functions declaring that this funciton is overriding a funciton that s...
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
uint8_t ch2Size
Number of bytes in channel two.
uint8_t ch1Size
Number of bytes in channel one.
uint8_t channel
Used by multi-channel railcom receiver drivers.
uint8_t ch1Data[2]
Payload of channel 1.
uintptr_t feedbackKey
Opaque identifier that allows linking outgoing dcc::Packet sent to the DCC waveform generator to the ...
uint8_t ch2Data[6]
Payload of channel 2.
Structure used for reading (railcom) feedback data from DCC / Railcom device drivers.
@ ACK
Railcom ACK; the decoder received the message ok.
@ INV
invalid value (not conforming to the 4bit weighting requirement)
MTI
Known Message type indicators.