mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-29 18:27:31 +02:00
fix(esp_modem): Implement movable unique_buffer to bundle data, size, ptr
Also improves and fixes tests
This commit is contained in:
@ -25,7 +25,7 @@ int LoopbackTerm::write(uint8_t *data, size_t len)
|
||||
if (command == "+++") {
|
||||
response = "NO CARRIER\r\n";
|
||||
} else if (command == "ATE1\r" || command == "ATE0\r") {
|
||||
response = "OK\r\n";
|
||||
response = "OK\r\n ";
|
||||
} else if (command == "ATO\r") {
|
||||
response = "ERROR\r\n";
|
||||
} else if (command.find("ATD") != std::string::npos) {
|
||||
@ -43,7 +43,16 @@ int LoopbackTerm::write(uint8_t *data, size_t len)
|
||||
} else if (command.find("AT+CPIN?\r") != std::string::npos) {
|
||||
response = pin_ok ? "+CPIN: READY\r\nOK\r\n" : "+CPIN: SIM PIN\r\nOK\r\n";
|
||||
} else if (command.find("AT") != std::string::npos) {
|
||||
response = "OK\r\n";
|
||||
if (command.length() > 4) {
|
||||
response = command;
|
||||
response[0] = 'O';
|
||||
response[1] = 'K';
|
||||
response[2] = '\r';
|
||||
response[3] = '\n';
|
||||
} else {
|
||||
response = "OK\r\n";
|
||||
}
|
||||
|
||||
}
|
||||
if (!response.empty()) {
|
||||
data_len = response.length();
|
||||
@ -55,7 +64,7 @@ int LoopbackTerm::write(uint8_t *data, size_t len)
|
||||
}
|
||||
if (len > 2 && data[0] == 0xf9) { // Simple CMUX responder
|
||||
// turn the request into a reply -> implements CMUX loopback
|
||||
if (data[2] == 0x3f) { // SABM command
|
||||
if (data[2] == 0x3f || data[2] == 0x53) { // SABM command
|
||||
data[2] = 0x73;
|
||||
} else if (data[2] == 0xef) { // Generic request
|
||||
data[2] = 0xff; // generic reply
|
||||
|
@ -77,6 +77,7 @@ TEST_CASE("DTE send/receive command", "[esp_modem]")
|
||||
CHECK(ret == command_result::OK);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("DCE commands", "[esp_modem]")
|
||||
{
|
||||
auto term = std::make_unique<LoopbackTerm>();
|
||||
@ -96,7 +97,6 @@ TEST_CASE("DCE commands", "[esp_modem]")
|
||||
}, 1000);
|
||||
CHECK(ret == command_result::OK);
|
||||
}
|
||||
|
||||
TEST_CASE("DCE AT commands", "[esp_modem]")
|
||||
{
|
||||
auto term = std::make_unique<LoopbackTerm>();
|
||||
@ -128,9 +128,21 @@ TEST_CASE("DCE modes", "[esp_modem]")
|
||||
auto dce = create_SIM7600_dce(&dce_config, dte, &netif);
|
||||
CHECK(dce != nullptr);
|
||||
|
||||
// UNDER -> CMD (OK)
|
||||
CHECK(dce->set_mode(esp_modem::modem_mode::COMMAND_MODE) == true);
|
||||
// CMD -> CMD (Fail)
|
||||
CHECK(dce->set_mode(esp_modem::modem_mode::COMMAND_MODE) == false);
|
||||
// CMD -> DATA (OK)
|
||||
CHECK(dce->set_mode(esp_modem::modem_mode::DATA_MODE) == true);
|
||||
// DATA -> CMUX (Fail)
|
||||
CHECK(dce->set_mode(esp_modem::modem_mode::CMUX_MODE) == false);
|
||||
// DATA back -> CMD (OK)
|
||||
CHECK(dce->set_mode(esp_modem::modem_mode::COMMAND_MODE) == true);
|
||||
// CMD -> CMUX (OK)
|
||||
CHECK(dce->set_mode(esp_modem::modem_mode::CMUX_MODE) == true);
|
||||
// CMUX -> DATA (Fail)
|
||||
CHECK(dce->set_mode(esp_modem::modem_mode::DATA_MODE) == false);
|
||||
// CMUX back -> CMD (OK)
|
||||
CHECK(dce->set_mode(esp_modem::modem_mode::COMMAND_MODE) == true);
|
||||
}
|
||||
|
||||
@ -171,7 +183,7 @@ TEST_CASE("Test CMUX protocol by injecting payloads", "[esp_modem]")
|
||||
CHECK(dce->set_mode(esp_modem::modem_mode::CMUX_MODE) == true);
|
||||
const auto test_command = "Test\n";
|
||||
// 1 byte payload size
|
||||
uint8_t test_payload[] = {0xf9, 0x05, 0xff, 0x0b, 0x54, 0x65, 0x73, 0x74, 0x0a, 0xbb, 0xf9 };
|
||||
uint8_t test_payload[] = {0xf9, 0x09, 0xff, 0x0b, 0x54, 0x65, 0x73, 0x74, 0x0a, 0xbb, 0xf9 };
|
||||
loopback->inject(&test_payload[0], sizeof(test_payload), 1);
|
||||
auto ret = dce->command(test_command, [&](uint8_t *data, size_t len) {
|
||||
std::string response((char *) data, len);
|
||||
@ -181,7 +193,7 @@ TEST_CASE("Test CMUX protocol by injecting payloads", "[esp_modem]")
|
||||
CHECK(ret == command_result::OK);
|
||||
|
||||
// 2 byte payload size
|
||||
uint8_t long_payload[453] = { 0xf9, 0x05, 0xef, 0x7c, 0x03, 0x7e }; // header
|
||||
uint8_t long_payload[453] = { 0xf9, 0x09, 0xef, 0x7c, 0x03, 0x7e }; // header
|
||||
long_payload[5] = 0x7e; // payload to validate
|
||||
long_payload[449] = 0x7e;
|
||||
long_payload[450] = '\n';
|
||||
|
Reference in New Issue
Block a user