Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
TractionCvSpace.hxx
Go to the documentation of this file.
1
36#ifndef _OPENLCB_TRACTIONCVSPACE_HXX_
37#define _OPENLCB_TRACTIONCVSPACE_HXX_
38
39#include "dcc/RailCom.hxx"
40#include "dcc/RailcomHub.hxx"
41#include "dcc/TrackIf.hxx"
44
45namespace openlcb
46{
47
68 public StateFlowBase
69{
70public:
72 dcc::RailcomHubFlow *railcom_hub, uint8_t space_id);
73
75
76private:
77 static const unsigned MAX_CV = 1023;
78
79 bool set_node(Node *node) OVERRIDE;
80
82 {
83 return false;
84 }
85
87 {
88 return OFFSET_CV_VALUE;
89 }
90
91 size_t write(address_t destination, const uint8_t *data, size_t len,
92 errorcode_t *error, Notifiable *again) OVERRIDE;
93
94 size_t read(address_t source, uint8_t *dst, size_t len, errorcode_t *error,
96
97 // State flow states.
98 Action try_read1();
99 Action fill_read1_packet();
100 Action read_returned();
101
102 Action try_write1();
103 Action fill_write1_packet();
104 Action write_returned();
105
106 Action pgm_verify();
107 Action pgm_verify_wait_flush();
108 Action pgm_verify_reset();
109 Action pgm_verify_packet();
110 Action pgm_verify_done();
111 Action pgm_verify_reset_done();
112 Action pgm_verify_exit();
113
114 // Railcom feedback
115 void send(Buffer<dcc::RailcomHubData> *b, unsigned priority) OVERRIDE;
116 void record_railcom_status(unsigned code);
117
118 MemoryConfigHandler *parent_;
119 dcc::TrackIf *track_;
120 dcc::RailcomHubFlow *railcomHub_;
122 uint16_t currId_;
124 uint16_t dccAddressNum_ : 14;
126 uint16_t dccIsLong_ : 1;
128 uint16_t cvNumber_;
130 uint8_t cvData_;
131 uint8_t errorCode_ : 4;
132 uint8_t numTry_ : 4;
133 enum
134 {
135 ERROR_NOOP = 0,
136 ERROR_PENDING = 1,
137 ERROR_OK = 2,
138 _ERROR_BUSY = 3,
139 ERROR_NACK = 7,
140 ERROR_NO_RAILCOM_CH2_DATA = 4,
141 ERROR_GARBAGE = 5,
142 ERROR_UNKNOWN_RESPONSE = 6,
143 _ERROR_TIMEOUT = 8,
144 };
145
146public:
147 enum
148 {
149 OFFSET_CV_INDEX = 0x7F000000,
150 OFFSET_CV_VALUE = 0x7F000004,
151 OFFSET_CV_VERIFY_VALUE = 0x7F000005,
152 OFFSET_CV_VERIFY_RESULT = 0x7F000006,
153 };
154
155private:
158 {
159 done_->notify();
160 done_ = nullptr;
161 return exit();
162 }
163
164 uint8_t spaceId_;
171
172 Notifiable *done_; //< notify when transfer is done
173 StateFlowTimer timer_;
174 long long deadline_; //< time when we should give up and return error.
175 vector<dcc::RailcomPacket> interpretedResponse_;
176};
177
178} // namespace openlcb
179
180#endif // _OPENLCB_TRACTIONCVSPACE_HXX_
Base class for all QMember types that hold data in an expandable format.
Definition Buffer.hxx:195
Abstract class for message recipients.
Templated implementation of the HubFlow.
Definition Hub.hxx:150
An object that can schedule itself on an executor to run.
virtual void notify()=0
Generic callback.
Return type for a state flow callback.
Use this timer class to deliver the timeout notification to a stateflow.
Base class for state machines.
Action exit()
Terminate current StateFlow activity.
Action again()
Call the current state again via call_immediately.
Implementation of the Memory Access Configuration Protocol for OpenLCB.
Abstract base class for the address spaces exported via the Memory Config Protocol.
Base class for NMRAnet nodes conforming to the asynchronous interface.
Definition Node.hxx:52
Memory Space implementation for a CV (configuration variable) access on a Railcom-enabled command sta...
Action async_done()
Helper function for completing asynchronous processing.
address_t max_address() OVERRIDE
uint16_t dccIsLong_
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 lastVerifyValue_
Stores the CV value that we're checking the CV against to verify.
size_t read(address_t source, uint8_t *dst, size_t len, errorcode_t *error, Notifiable *again) OVERRIDE
uint16_t currId_
Last accepted DCC locomotive node ID (bottom 16 bits).
uint16_t dccAddressNum_
Numberic value of last used DCC address.
size_t write(address_t destination, const uint8_t *data, size_t len, errorcode_t *error, Notifiable *again) OVERRIDE
bool set_node(Node *node) OVERRIDE
Specifies which node the next operation pertains.
uint32_t lastIndexedCv_
Stores the last CV index (for indirect CV lookup).
uint16_t lastIndexedNode_
Stores the last node for which the CV index was written.
#define OVERRIDE
Function attribute for virtual functions declaring that this funciton is overriding a funciton that s...
Definition macros.h:180