@@ -15,24 +15,24 @@ using namespace esp_modem;
15
15
static const size_t dte_default_buffer_size = 1000 ;
16
16
17
17
DTE::DTE (const esp_modem_dte_config *config, std::unique_ptr<Terminal> terminal):
18
- buffer(config->dte_buffer_size),
19
- cmux_term(nullptr ), term (std::move(terminal)), other_term(term ),
20
- mode(modem_mode::UNDEF) {}
18
+ buffer(config->dte_buffer_size),
19
+ cmux_term(nullptr ), primary_term (std::move(terminal)), secondary_term(primary_term ),
20
+ mode(modem_mode::UNDEF) {}
21
21
22
22
DTE::DTE (std::unique_ptr<Terminal> terminal):
23
- buffer(dte_default_buffer_size),
24
- cmux_term(nullptr ), term (std::move(terminal)), other_term(term ),
25
- mode(modem_mode::UNDEF) {}
23
+ buffer(dte_default_buffer_size),
24
+ cmux_term(nullptr ), primary_term (std::move(terminal)), secondary_term(primary_term ),
25
+ mode(modem_mode::UNDEF) {}
26
26
27
27
command_result DTE::command (const std::string &command, got_line_cb got_line, uint32_t time_ms, const char separator)
28
28
{
29
29
Scoped<Lock> l (internal_lock);
30
30
result = command_result::TIMEOUT;
31
31
signal.clear (GOT_LINE);
32
- term ->set_read_cb ([this , got_line, separator](uint8_t *data, size_t len) {
32
+ primary_term ->set_read_cb ([this , got_line, separator](uint8_t *data, size_t len) {
33
33
if (!data) {
34
34
data = buffer.get ();
35
- len = term ->read (data + buffer.consumed , buffer.size - buffer.consumed );
35
+ len = primary_term ->read (data + buffer.consumed , buffer.size - buffer.consumed );
36
36
} else {
37
37
buffer.consumed = 0 ; // if the underlying terminal contains data, we cannot fragment
38
38
}
@@ -46,13 +46,13 @@ command_result DTE::command(const std::string &command, got_line_cb got_line, ui
46
46
buffer.consumed += len;
47
47
return false ;
48
48
});
49
- term ->write ((uint8_t *)command.c_str (), command.length ());
49
+ primary_term ->write ((uint8_t *)command.c_str (), command.length ());
50
50
auto got_lf = signal.wait (GOT_LINE, time_ms);
51
51
if (got_lf && result == command_result::TIMEOUT) {
52
52
ESP_MODEM_THROW_IF_ERROR (ESP_ERR_INVALID_STATE);
53
53
}
54
54
buffer.consumed = 0 ;
55
- term ->set_read_cb (nullptr );
55
+ primary_term ->set_read_cb (nullptr );
56
56
return result;
57
57
}
58
58
@@ -68,26 +68,26 @@ bool DTE::exit_cmux()
68
68
}
69
69
auto ejected = cmux_term->detach ();
70
70
// return the ejected terminal and buffer back to this DTE
71
- term = std::move (ejected.first );
71
+ primary_term = std::move (ejected.first );
72
72
buffer = std::move (ejected.second );
73
- other_term = term ;
73
+ secondary_term = primary_term ;
74
74
return true ;
75
75
}
76
76
77
77
bool DTE::setup_cmux ()
78
78
{
79
- cmux_term = std::make_shared<CMux>(term , std::move (buffer));
79
+ cmux_term = std::make_shared<CMux>(primary_term , std::move (buffer));
80
80
if (cmux_term == nullptr ) {
81
81
return false ;
82
82
}
83
83
if (!cmux_term->init ()) {
84
84
return false ;
85
85
}
86
- term = std::make_unique<CMuxInstance>(cmux_term, 0 );
87
- if (term == nullptr ) {
86
+ primary_term = std::make_unique<CMuxInstance>(cmux_term, 0 );
87
+ if (primary_term == nullptr ) {
88
88
return false ;
89
89
}
90
- other_term = std::make_unique<CMuxInstance>(cmux_term, 1 );
90
+ secondary_term = std::make_unique<CMuxInstance>(cmux_term, 1 );
91
91
return true ;
92
92
}
93
93
@@ -108,7 +108,7 @@ bool DTE::set_mode(modem_mode m)
108
108
if (m == modem_mode::DATA_MODE) {
109
109
if (mode == modem_mode::CMUX_MODE || mode == modem_mode::CMUX_MANUAL_MODE) {
110
110
// mode stays the same, but need to swap terminals (as command has been switched)
111
- other_term .swap (term );
111
+ secondary_term .swap (primary_term );
112
112
} else {
113
113
mode = m;
114
114
}
@@ -150,19 +150,20 @@ bool DTE::set_mode(modem_mode m)
150
150
}
151
151
// manual CMUX transitions: Swap terminals
152
152
if (m == modem_mode::CMUX_MANUAL_SWAP && mode == modem_mode::CMUX_MANUAL_MODE) {
153
- other_term .swap (term );
153
+ secondary_term .swap (primary_term );
154
154
return true ;
155
155
}
156
- return true ;
156
+ mode = modem_mode::UNDEF;
157
+ return false ;
157
158
}
158
159
159
160
void DTE::set_read_cb (std::function<bool (uint8_t *, size_t )> f)
160
161
{
161
162
on_data = std::move (f);
162
- other_term ->set_read_cb ([this ](uint8_t *data, size_t len) {
163
+ secondary_term ->set_read_cb ([this ](uint8_t *data, size_t len) {
163
164
if (!data) { // if no data available from terminal callback -> need to explicitly read some
164
165
data = buffer.get ();
165
- len = other_term ->read (buffer.get (), buffer.size );
166
+ len = secondary_term ->read (buffer.get (), buffer.size );
166
167
}
167
168
if (on_data) {
168
169
return on_data (data, len);
@@ -173,22 +174,22 @@ void DTE::set_read_cb(std::function<bool(uint8_t *, size_t)> f)
173
174
174
175
void DTE::set_error_cb (std::function<void (terminal_error err)> f)
175
176
{
176
- other_term ->set_error_cb (f);
177
- term ->set_error_cb (f);
177
+ secondary_term ->set_error_cb (f);
178
+ primary_term ->set_error_cb (f);
178
179
}
179
180
180
181
int DTE::read (uint8_t **d, size_t len)
181
182
{
182
183
auto data_to_read = std::min (len, buffer.size );
183
184
auto data = buffer.get ();
184
- auto actual_len = other_term ->read (data, data_to_read);
185
+ auto actual_len = secondary_term ->read (data, data_to_read);
185
186
*d = data;
186
187
return actual_len;
187
188
}
188
189
189
190
int DTE::write (uint8_t *data, size_t len)
190
191
{
191
- return other_term ->write (data, len);
192
+ return secondary_term ->write (data, len);
192
193
}
193
194
194
195
/* *
0 commit comments