Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
openlcb::TractionCvSpace Class Reference

Memory Space implementation for a CV (configuration variable) access on a Railcom-enabled command station. More...

#include <TractionCvSpace.hxx>

Inheritance diagram for openlcb::TractionCvSpace:
openlcb::MemorySpace FlowInterface< MessageType > StateFlowBase Executable Notifiable QMember Destructable

Public Types

enum  { OFFSET_CV_INDEX = 0x7F000000 , OFFSET_CV_VALUE = 0x7F000004 , OFFSET_CV_VERIFY_VALUE = 0x7F000005 , OFFSET_CV_VERIFY_RESULT = 0x7F000006 }
 

Public Member Functions

 TractionCvSpace (MemoryConfigHandler *parent, dcc::TrackIf *track, dcc::RailcomHubFlow *railcom_hub, uint8_t space_id)
 
- Public Member Functions inherited from StateFlowBase
void run () override
 Callback from the executor.
 
void notify () override
 Wakeup call arrived.
 
Serviceservice ()
 Return a pointer to the service I am bound to.
 
- Public Member Functions inherited from Executable
void test_deletion ()
 
- Public Member Functions inherited from QMember
void init ()
 Initiailize a QMember, in place of a public placement construction.
 

Private Types

enum  {
  ERROR_NOOP = 0 , ERROR_PENDING = 1 , ERROR_OK = 2 , _ERROR_BUSY = 3 ,
  ERROR_NACK = 7 , ERROR_NO_RAILCOM_CH2_DATA = 4 , ERROR_GARBAGE = 5 , ERROR_UNKNOWN_RESPONSE = 6 ,
  _ERROR_TIMEOUT = 8
}
 
- Private Types inherited from openlcb::MemorySpace
typedef uint32_t address_t
 
typedef uint16_t errorcode_t
 
- Private Types inherited from FlowInterface< MessageType >
typedef MessageType message_type
 Stores the message template type for external reference.
 

Private Member Functions

bool set_node (Node *node) OVERRIDE
 Specifies which node the next operation pertains.
 
bool read_only () OVERRIDE
 
address_t max_address () OVERRIDE
 
size_t write (address_t destination, const uint8_t *data, size_t len, errorcode_t *error, Notifiable *again) OVERRIDE
 
size_t read (address_t source, uint8_t *dst, size_t len, errorcode_t *error, Notifiable *again) OVERRIDE
 
Action try_read1 ()
 
Action fill_read1_packet ()
 
Action read_returned ()
 
Action try_write1 ()
 
Action fill_write1_packet ()
 
Action write_returned ()
 
Action pgm_verify ()
 
Action pgm_verify_wait_flush ()
 
Action pgm_verify_reset ()
 
Action pgm_verify_packet ()
 
Action pgm_verify_done ()
 
Action pgm_verify_reset_done ()
 
Action pgm_verify_exit ()
 
void send (Buffer< dcc::RailcomHubData > *b, unsigned priority) OVERRIDE
 
void record_railcom_status (unsigned code)
 
Action async_done ()
 Helper function for completing asynchronous processing.
 
- Private Member Functions inherited from openlcb::MemorySpace
virtual address_t min_address ()
 
virtual errorcode_t freeze ()
 Handles space freeze command.
 
virtual errorcode_t unfreeze ()
 Handles space unfreeze command.
 
- Private Member Functions inherited from FlowInterface< MessageType >
virtual Poolpool ()
 
virtual void send (MessageType *message, unsigned priority=UINT_MAX)=0
 Entry point to the flow.
 
virtual MessageType * type_helper ()
 This function is never user in the code, but GDB can use it to infer the correct message types.
 
MessageType * alloc ()
 Synchronously allocates a message buffer from the pool of this flow.
 
void alloc_async (Executable *target)
 Asynchronously allocates a message buffer from the pool of this flow.
 

Private Attributes

MemoryConfigHandlerparent_
 
dcc::TrackIftrack_
 
dcc::RailcomHubFlowrailcomHub_
 
uint16_t currId_
 Last accepted DCC locomotive node ID (bottom 16 bits).
 
uint16_t dccAddressNum_: 14
 Numberic value of last used DCC address.
 
uint16_t dccIsLong_: 1
 1 for long address, 0 for short address.
 
uint16_t cvNumber_
 CV to read (0 to 1023).
 
uint8_t cvData_
 data read or data to write
 
uint8_t errorCode_: 4
 
uint8_t numTry_: 4
 
uint8_t spaceId_
 
uint16_t lastIndexedNode_
 Stores the last node for which the CV index was written.
 
uint8_t lastVerifyValue_
 Stores the CV value that we're checking the CV against to verify.
 
uint32_t lastIndexedCv_
 Stores the last CV index (for indirect CV lookup).
 
Notifiabledone_
 
StateFlowTimer timer_
 
long long deadline_
 
vector< dcc::RailcomPacketinterpretedResponse_
 

Static Private Attributes

static const unsigned MAX_CV = 1023
 
- Static Private Attributes inherited from openlcb::MemorySpace
static const errorcode_t ERROR_AGAIN = 0x3FFF
 This error code signals that the operation was only partially completed, the again notify was used and will be notified when the operation can be re-tried).
 

Additional Inherited Members

- Static Public Member Functions inherited from StateFlowBase
template<class T , typename... Args>
static void invoke_subflow_and_ignore_result (FlowInterface< Buffer< T > > *target_flow, Args &&... args)
 Calls a helper flow to perform some actions.
 
- Protected Types inherited from StateFlowBase
typedef Action(StateFlowBase::* Callback) ()
 State Flow callback prototype.
 
- Protected Member Functions inherited from StateFlowBase
 StateFlowBase (Service *service)
 Constructor.
 
 ~StateFlowBase ()
 Destructor.
 
void reset_flow (Callback c)
 Resets the flow to the specified state.
 
bool is_state (Callback c)
 
bool is_terminated ()
 
void start_flow (Callback c)
 Resets the flow to the specified state and starts it.
 
Action again ()
 Call the current state again via call_immediately.
 
Action exit ()
 Terminate current StateFlow activity.
 
Action delete_this ()
 Terminates the flow and deletes *this.
 
Action set_terminated ()
 Sets the flow to terminated state.
 
Action call_immediately (Callback c)
 Imediately call the next state upon return.
 
Action wait ()
 Wait for an asynchronous call.
 
Action wait_and_call (Callback c)
 Wait for resource to become available before proceeding to next state.
 
template<class T >
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.
 
Action allocate_and_call (Callback c, QAsync *queue)
 Allocates an entry from an asynchronous queue, and transitions to a state once the allocation is complete.
 
template<class T >
Buffer< T > * full_allocation_result (FlowInterface< Buffer< T > > *target_flow)
 Takes the result of the asynchronous allocation without resetting the object.
 
template<class T >
T * full_allocation_result (TypedQAsync< T > *queue)
 Takes the result of the asynchronous allocation without resetting the object.
 
template<class T >
void cast_allocation_result (T **member)
 Takes the result of the asynchronous allocation without resetting the object.
 
template<class T >
Buffer< T > * get_allocation_result (FlowInterface< Buffer< T > > *target_flow)
 Takes the result of the asynchronous allocation.
 
Action yield_and_call (Callback c)
 Place the current flow to the back of the executor, and transition to a new state after we get the CPU again.
 
Action yield ()
 Place the current flow to the back of the executor, and re-try the current state after we get the CPU again.
 
Action sleep_and_call (::Timer *timer, long long timeout_nsec, Callback c)
 Suspends execution of this control flow for a specified time.
 
template<class T , typename... Args>
Action invoke_subflow_and_wait (FlowInterface< Buffer< T > > *target_flow, Callback c, Args &&... args)
 Calls a helper flow to perform some actions.
 
Action read_repeated (StateFlowSelectHelper *helper, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
 Blocks until size bytes are read and then invokes the next state.
 
Action read_single (StateFlowSelectHelper *helper, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
 Attempts to read at most size_t bytes, and blocks the caller until at least one byte is read.
 
Action read_nonblocking (StateFlowSelectHelper *helper, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
 Attempts to read at most size bytes, and then invokes the next state, even if only zero bytes are available right now.
 
Action read_repeated_with_timeout (StateFlowTimedSelectHelper *helper, long long timeout_nsec, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
 Blocks until size bytes are read, or a timeout expires.
 
Action internal_try_read ()
 Implementation state that gets repeatedly called upon every wakeup and tries to make progress on reading.
 
Action write_repeated (StateFlowSelectHelper *helper, int fd, const void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
 Writes some data into a file descriptor, repeating the operation as necessary until all bytes are written.
 
Action internal_try_write ()
 Implementation state that gets repeatedly called upon every wakeup and tries to make progress on writing.
 
- Protected Member Functions inherited from QMember
 QMember ()
 Constructor.
 
 ~QMember ()
 Destructor.
 
- Protected Attributes inherited from QMember
QMembernext
 pointer to the next member in the queue
 
- Static Private Member Functions inherited from FlowInterface< MessageType >
static MessageType * cast_alloc (QMember *entry)
 Down casts and initializes an asynchronous allocation result to the appropriate flow's buffer type.
 

Detailed Description

Memory Space implementation for a CV (configuration variable) access on a Railcom-enabled command station.

Reads are turned into DCC extended packets for Programming-on-Main mode CV reads, and the Railcom feedback is evaluated for the result of the memory read operation. Writes are turned into POM-mode CV write packets, and the Railcom feedback is evaluated for success acknowledgement.

A single instance of this class works for all DCC locomotives, assuming that the memory configuration handler was registered for all virtual nodes of the given interface.

Restrictions: the DCC locmotives are required to have theid NodeID allocated as TractionDefs::NODE_ID_DCC + address. There is a hard-coded assumption that node IDs lower, than 128 are shoprt addresses, and higher addresses are long addresses.

@TODO(balazs.racz) Wire up a link to the traction service to somehow remove these restrictions.

Definition at line 66 of file TractionCvSpace.hxx.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private

Definition at line 133 of file TractionCvSpace.hxx.

◆ anonymous enum

anonymous enum

Definition at line 147 of file TractionCvSpace.hxx.

Constructor & Destructor Documentation

◆ TractionCvSpace()

openlcb::TractionCvSpace::TractionCvSpace ( MemoryConfigHandler parent,
dcc::TrackIf track,
dcc::RailcomHubFlow railcom_hub,
uint8_t  space_id 
)

Definition at line 54 of file TractionCvSpace.cxx.

◆ ~TractionCvSpace()

openlcb::TractionCvSpace::~TractionCvSpace ( )

Definition at line 70 of file TractionCvSpace.cxx.

Member Function Documentation

◆ async_done()

Action openlcb::TractionCvSpace::async_done ( )
inlineprivate

Helper function for completing asynchronous processing.

Definition at line 157 of file TractionCvSpace.hxx.

◆ fill_read1_packet()

StateFlowBase::Action openlcb::TractionCvSpace::fill_read1_packet ( )
private

Definition at line 291 of file TractionCvSpace.cxx.

◆ fill_write1_packet()

StateFlowBase::Action openlcb::TractionCvSpace::fill_write1_packet ( )
private

Definition at line 396 of file TractionCvSpace.cxx.

◆ max_address()

address_t openlcb::TractionCvSpace::max_address ( )
inlineprivatevirtual
Returns
the largest valid address for this block. A read of 1 from this address should succeed in returning the last byte.

Implements openlcb::MemorySpace.

Definition at line 86 of file TractionCvSpace.hxx.

◆ pgm_verify()

StateFlowBase::Action openlcb::TractionCvSpace::pgm_verify ( )
private

Definition at line 200 of file TractionCvSpace.cxx.

◆ pgm_verify_done()

StateFlowBase::Action openlcb::TractionCvSpace::pgm_verify_done ( )
private

Definition at line 248 of file TractionCvSpace.cxx.

◆ pgm_verify_exit()

StateFlowBase::Action openlcb::TractionCvSpace::pgm_verify_exit ( )
private

Definition at line 275 of file TractionCvSpace.cxx.

◆ pgm_verify_packet()

StateFlowBase::Action openlcb::TractionCvSpace::pgm_verify_packet ( )
private

Definition at line 229 of file TractionCvSpace.cxx.

◆ pgm_verify_reset()

StateFlowBase::Action openlcb::TractionCvSpace::pgm_verify_reset ( )
private

Definition at line 222 of file TractionCvSpace.cxx.

◆ pgm_verify_reset_done()

StateFlowBase::Action openlcb::TractionCvSpace::pgm_verify_reset_done ( )
private

Definition at line 266 of file TractionCvSpace.cxx.

◆ pgm_verify_wait_flush()

StateFlowBase::Action openlcb::TractionCvSpace::pgm_verify_wait_flush ( )
private

Definition at line 208 of file TractionCvSpace.cxx.

◆ read()

size_t openlcb::TractionCvSpace::read ( address_t  source,
uint8_t *  dst,
size_t  len,
errorcode_t *  error,
Notifiable again 
)
privatevirtual
Returns
the number of bytes successfully read (before hitting end of space). If *error is set to non-null, then the operation has failed. If the operation needs to be continued, then sets error to ERROR_AGAIN, and calls the Notifiable
Parameters
againwhen a re-try makes sense. The caller should call read once more, with the offset adjusted with the previously returned bytes.

Implements openlcb::MemorySpace.

Definition at line 121 of file TractionCvSpace.cxx.

◆ read_only()

bool openlcb::TractionCvSpace::read_only ( )
inlineprivatevirtual
Returns
whether the memory space does not accept writes.

Reimplemented from openlcb::MemorySpace.

Definition at line 81 of file TractionCvSpace.hxx.

◆ read_returned()

StateFlowBase::Action openlcb::TractionCvSpace::read_returned ( )
private

Definition at line 313 of file TractionCvSpace.cxx.

◆ record_railcom_status()

void openlcb::TractionCvSpace::record_railcom_status ( unsigned  code)
private

Definition at line 453 of file TractionCvSpace.cxx.

◆ send()

void openlcb::TractionCvSpace::send ( Buffer< dcc::RailcomHubData > *  b,
unsigned  priority 
)
private

Definition at line 460 of file TractionCvSpace.cxx.

◆ set_node()

bool openlcb::TractionCvSpace::set_node ( Node node)
privatevirtual

Specifies which node the next operation pertains.

If it returns false, the operation will be rejected by "unknown memory space ID".

Reimplemented from openlcb::MemorySpace.

Definition at line 79 of file TractionCvSpace.cxx.

◆ try_read1()

StateFlowBase::Action openlcb::TractionCvSpace::try_read1 ( )
private

Definition at line 282 of file TractionCvSpace.cxx.

◆ try_write1()

StateFlowBase::Action openlcb::TractionCvSpace::try_write1 ( )
private

Definition at line 286 of file TractionCvSpace.cxx.

◆ write()

size_t openlcb::TractionCvSpace::write ( address_t  destination,
const uint8_t *  data,
size_t  len,
errorcode_t *  error,
Notifiable again 
)
privatevirtual
Returns
the number of bytes successfully written (before hitting end of space). If *error is set to non-null, then the operation has failed. If the operation needs to be continued, then sets error to MemorySpace::ERROR_AGAIN, and calls the Notifiable
Parameters
againwhen a re-try makes sense. The caller should call write once more, with the offset adjusted with the previously returned bytes.

Reimplemented from openlcb::MemorySpace.

Definition at line 341 of file TractionCvSpace.cxx.

◆ write_returned()

StateFlowBase::Action openlcb::TractionCvSpace::write_returned ( )
private
Todo:
(balazs.racz) keep a timestamp to not keep trying forever.

Definition at line 420 of file TractionCvSpace.cxx.

Member Data Documentation

◆ currId_

uint16_t openlcb::TractionCvSpace::currId_
private

Last accepted DCC locomotive node ID (bottom 16 bits).

Definition at line 122 of file TractionCvSpace.hxx.

◆ cvData_

uint8_t openlcb::TractionCvSpace::cvData_
private

data read or data to write

Definition at line 130 of file TractionCvSpace.hxx.

◆ cvNumber_

uint16_t openlcb::TractionCvSpace::cvNumber_
private

CV to read (0 to 1023).

Definition at line 128 of file TractionCvSpace.hxx.

◆ dccAddressNum_

uint16_t openlcb::TractionCvSpace::dccAddressNum_
private

Numberic value of last used DCC address.

Definition at line 124 of file TractionCvSpace.hxx.

◆ dccIsLong_

uint16_t openlcb::TractionCvSpace::dccIsLong_
private

1 for long address, 0 for short address.

Definition at line 126 of file TractionCvSpace.hxx.

◆ deadline_

long long openlcb::TractionCvSpace::deadline_
private

Definition at line 174 of file TractionCvSpace.hxx.

◆ done_

Notifiable* openlcb::TractionCvSpace::done_
private

Definition at line 172 of file TractionCvSpace.hxx.

◆ errorCode_

uint8_t openlcb::TractionCvSpace::errorCode_
private

Definition at line 131 of file TractionCvSpace.hxx.

◆ interpretedResponse_

vector<dcc::RailcomPacket> openlcb::TractionCvSpace::interpretedResponse_
private

Definition at line 175 of file TractionCvSpace.hxx.

◆ lastIndexedCv_

uint32_t openlcb::TractionCvSpace::lastIndexedCv_
private

Stores the last CV index (for indirect CV lookup).

Definition at line 170 of file TractionCvSpace.hxx.

◆ lastIndexedNode_

uint16_t openlcb::TractionCvSpace::lastIndexedNode_
private

Stores the last node for which the CV index was written.

Definition at line 166 of file TractionCvSpace.hxx.

◆ lastVerifyValue_

uint8_t openlcb::TractionCvSpace::lastVerifyValue_
private

Stores the CV value that we're checking the CV against to verify.

Definition at line 168 of file TractionCvSpace.hxx.

◆ MAX_CV

const unsigned openlcb::TractionCvSpace::MAX_CV = 1023
staticprivate

Definition at line 77 of file TractionCvSpace.hxx.

◆ numTry_

uint8_t openlcb::TractionCvSpace::numTry_
private

Definition at line 132 of file TractionCvSpace.hxx.

◆ parent_

MemoryConfigHandler* openlcb::TractionCvSpace::parent_
private

Definition at line 118 of file TractionCvSpace.hxx.

◆ railcomHub_

dcc::RailcomHubFlow* openlcb::TractionCvSpace::railcomHub_
private

Definition at line 120 of file TractionCvSpace.hxx.

◆ spaceId_

uint8_t openlcb::TractionCvSpace::spaceId_
private

Definition at line 164 of file TractionCvSpace.hxx.

◆ timer_

StateFlowTimer openlcb::TractionCvSpace::timer_
private

Definition at line 173 of file TractionCvSpace.hxx.

◆ track_

dcc::TrackIf* openlcb::TractionCvSpace::track_
private

Definition at line 119 of file TractionCvSpace.hxx.


The documentation for this class was generated from the following files: