36#ifndef _DCC_PROGRAMMINGTRACKBACKEND_HXX_
37#define _DCC_PROGRAMMINGTRACKBACKEND_HXX_
73 enum SendProgrammingPacket
75 SEND_PROGRAMMING_PACKET
94 void reset(SendReset,
unsigned count)
110 bool terminate_on_ack =
true)
168extern void progdebug_log_string(
const char *s);
172 public Singleton<ProgrammingTrackBackend>
176 std::function<
void()> enable_program_track_mode,
177 std::function<
void()> disable_program_track_mode)
195 const bool has_short = pgm->get_disable_output_reasons() &
220 DIE(
"Unknown programming track request command");
258 Action enter_service_mode()
267 if (!packet_processor_add_refresh_source(
271 packet_processor_remove_refresh_source(
this);
294 pgm->clear_disable_output_for_reason(
300 Action exit_service_mode()
311 pgm->disable_output_for_reason(
329 packet_processor_remove_refresh_source(
this);
343 Action send_service_packet()
368#ifdef DEBUG_PROGRAMTRACK_BACKEND
369 progdebug_log_packet(packet);
375#ifdef DEBUG_PROGRAMTRACK_BACKEND
376 progdebug_log_packet(packet);
378 if (
request()->repeatCount_ > 0)
386#ifdef DEBUG_PROGRAMTRACK_BACKEND
387 progdebug_log_string(
"done flush");
DccOutput * get_dcc_output(DccOutput::Type type)
Public API accessor for applications to get the object representing the output hardware.
#define STATE(_fn)
Turns a function name into an argument to be supplied to functions expecting a state.
Action return_ok()
Terminates the flow and returns the request buffer to the caller with an error code of OK (zero).
Action return_with_error(int error)
Terminates the flow and returns the request buffer to the caller with an specific error code.
ProgrammingTrackRequest * request()
@ PGM
DCC output of the program track.
@ INITIALIZATION_PENDING
Set as 1 during construction time, to be cleared by the application when the initialization is comple...
@ SHORTED
Short detector says this output is shorted.
void notify_service_mode_short()
Call this function when the service mode current limit is exceeded.
static constexpr unsigned QUEUE_FLUSH_PACKET_COUNT
How many packets we should send to the track in order to assume that the packet queue has been comple...
Action reset_flush_done()
Called during service mode enter when we managed to flush all packets from the queue.
unsigned isWaitingForPackets_
1 if the flow is blocked waiting for sending out the respective number of packets.
Action entry() override
Entry into the StateFlow activity.
Action exit_flush_done()
Called during service mode exit when we managed to flush all packets from the queue.
std::function< void()> disableProgramTrackMode_
Callback to connect to the program track hardware control.
std::function< void()> enableProgramTrackMode_
Callback to connect to the program track hardware control.
void get_next_packet(unsigned code, dcc::Packet *packet) override
Function that is called by the track driver when we need to generate a DCC packet to the track.
@ OPERATION_PENDING
cleared when done is called.
void notify_service_mode_ack()
Call this function when the service mode acknowledgement is detected by the short detector.
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 call_immediately(Callback c)
Imediately call the next state upon return.
Abstract class that is a packet source but not a TrainImpl.
static constexpr unsigned PROGRAMMING_PRIORITY
Priority value to be used for service mode programming source.
#define DIE(MSG)
Unconditionally terminates the current process with a message.
All callable flow request objects have to derive from this struct.
void reset_base()
Call this from all instances of reset(...).
int resultCode
If high bits are zero, this is a 16-bit OpenLCB result code.
uint8_t send_long_preamble
1: send long preamble instead of packet.
dcc::Packet packetToSend_
This packet will be repeated on the programming track for SEND_SERVICE_PACKET.
void reset(EnterServiceMode)
Set up command to enter service mode.
@ ENTER_SERVICE_MODE
Switch from normal mode to service mode.
@ SEND_RESET
Send some number of reset commands.
@ SEND_SERVICE_PACKET
Send a specific service mode DCC packet.
@ EXIT_SERVICE_MODE
Switch from service mode back to normal operations mode.
void reset(ExitServiceMode)
Set up command to exit service mode.
Type cmd_
What is the instruction to do.
unsigned repeatCount_
How many times maximum to repeat the packet before timing out on no acknowledgement,...
void reset(SendProgrammingPacket, dcc::Packet pkt, unsigned count, bool terminate_on_ack=true)
Set up command to send some number of service mode packets, waiting for an acknowledgement.
unsigned hasShortCircuit_
Set to 1 if the programming track has reached the current limit.
unsigned hasAck_
Output arguments. These are filled by the flow upon return.
void reset_base()
Resets all internal variables to default state.
unsigned terminateOnAck_
Should we short-cut sending the packet repetitions when we've seen an ack.
void reset(SendReset, unsigned count)
Set up command to send some number of reset packets.
Represents a command to be sent to the track driver.
void set_dcc_reset_all_decoders()
Creates a DCC reset-all-decoders packet.
void set_dcc_idle()
Creates a DCC idle packet.