mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-18 21:12:22 +02:00
feat(modem): DTE to support sending and receiving raw data
MAJOR CHANGE: Enable DTE to redefine on_read() and write(cmd) directly
This commit is contained in:
@ -202,6 +202,34 @@ int DTE::write(uint8_t *data, size_t len)
|
||||
return secondary_term->write(data, len);
|
||||
}
|
||||
|
||||
int DTE::write(DTE_Command command)
|
||||
{
|
||||
return primary_term->write(command.data, command.len);
|
||||
}
|
||||
|
||||
void DTE::on_read(got_line_cb on_read_cb)
|
||||
{
|
||||
if (on_read_cb == nullptr) {
|
||||
primary_term->set_read_cb(nullptr);
|
||||
internal_lock.unlock();
|
||||
return;
|
||||
}
|
||||
internal_lock.lock();
|
||||
primary_term->set_read_cb([this, on_read_cb](uint8_t *data, size_t len) {
|
||||
if (!data) {
|
||||
data = buffer.get();
|
||||
len = primary_term->read(data, buffer.size);
|
||||
}
|
||||
auto res = on_read_cb(data, len);
|
||||
if (res == command_result::OK || res == command_result::FAIL) {
|
||||
primary_term->set_read_cb(nullptr);
|
||||
internal_lock.unlock();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Implemented here to keep all headers C++11 compliant
|
||||
*/
|
||||
|
Reference in New Issue
Block a user