|
Open Model Railroad Network (OpenMRN)
|
Memory Space implementation for a CV (configuration variable) access on a Railcom-enabled command station. More...
#include <TractionCvSpace.hxx>
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. | |
| Service * | service () |
| 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 Pool * | pool () |
| 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 | |
| MemoryConfigHandler * | parent_ |
| dcc::TrackIf * | track_ |
| dcc::RailcomHubFlow * | railcomHub_ |
| 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). | |
| Notifiable * | done_ |
| StateFlowTimer | timer_ |
| long long | deadline_ |
| vector< dcc::RailcomPacket > | interpretedResponse_ |
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 | |
| QMember * | next |
| 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. | |
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.
|
private |
Definition at line 133 of file TractionCvSpace.hxx.
| anonymous enum |
Definition at line 147 of file TractionCvSpace.hxx.
| openlcb::TractionCvSpace::TractionCvSpace | ( | MemoryConfigHandler * | parent, |
| dcc::TrackIf * | track, | ||
| dcc::RailcomHubFlow * | railcom_hub, | ||
| uint8_t | space_id | ||
| ) |
Definition at line 54 of file TractionCvSpace.cxx.
| openlcb::TractionCvSpace::~TractionCvSpace | ( | ) |
Definition at line 70 of file TractionCvSpace.cxx.
|
inlineprivate |
Helper function for completing asynchronous processing.
Definition at line 157 of file TractionCvSpace.hxx.
|
private |
Definition at line 291 of file TractionCvSpace.cxx.
|
private |
Definition at line 396 of file TractionCvSpace.cxx.
|
inlineprivatevirtual |
Implements openlcb::MemorySpace.
Definition at line 86 of file TractionCvSpace.hxx.
|
private |
Definition at line 200 of file TractionCvSpace.cxx.
|
private |
Definition at line 248 of file TractionCvSpace.cxx.
|
private |
Definition at line 275 of file TractionCvSpace.cxx.
|
private |
Definition at line 229 of file TractionCvSpace.cxx.
|
private |
Definition at line 222 of file TractionCvSpace.cxx.
|
private |
Definition at line 266 of file TractionCvSpace.cxx.
|
private |
Definition at line 208 of file TractionCvSpace.cxx.
|
privatevirtual |
| again | when 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.
|
inlineprivatevirtual |
Reimplemented from openlcb::MemorySpace.
Definition at line 81 of file TractionCvSpace.hxx.
|
private |
Definition at line 313 of file TractionCvSpace.cxx.
|
private |
Definition at line 453 of file TractionCvSpace.cxx.
|
private |
Definition at line 460 of file TractionCvSpace.cxx.
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.
|
private |
Definition at line 282 of file TractionCvSpace.cxx.
|
private |
Definition at line 286 of file TractionCvSpace.cxx.
|
privatevirtual |
| again | when 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.
|
private |
Definition at line 420 of file TractionCvSpace.cxx.
|
private |
Last accepted DCC locomotive node ID (bottom 16 bits).
Definition at line 122 of file TractionCvSpace.hxx.
|
private |
data read or data to write
Definition at line 130 of file TractionCvSpace.hxx.
|
private |
CV to read (0 to 1023).
Definition at line 128 of file TractionCvSpace.hxx.
|
private |
Numberic value of last used DCC address.
Definition at line 124 of file TractionCvSpace.hxx.
|
private |
1 for long address, 0 for short address.
Definition at line 126 of file TractionCvSpace.hxx.
|
private |
Definition at line 174 of file TractionCvSpace.hxx.
|
private |
Definition at line 172 of file TractionCvSpace.hxx.
|
private |
Definition at line 131 of file TractionCvSpace.hxx.
|
private |
Definition at line 175 of file TractionCvSpace.hxx.
|
private |
Stores the last CV index (for indirect CV lookup).
Definition at line 170 of file TractionCvSpace.hxx.
|
private |
Stores the last node for which the CV index was written.
Definition at line 166 of file TractionCvSpace.hxx.
|
private |
Stores the CV value that we're checking the CV against to verify.
Definition at line 168 of file TractionCvSpace.hxx.
|
staticprivate |
Definition at line 77 of file TractionCvSpace.hxx.
|
private |
Definition at line 132 of file TractionCvSpace.hxx.
|
private |
Definition at line 118 of file TractionCvSpace.hxx.
|
private |
Definition at line 120 of file TractionCvSpace.hxx.
|
private |
Definition at line 164 of file TractionCvSpace.hxx.
|
private |
Definition at line 173 of file TractionCvSpace.hxx.
|
private |
Definition at line 119 of file TractionCvSpace.hxx.