Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[modem]: Add support for guessing mode #612

Merged
merged 2 commits into from
Nov 6, 2024

Conversation

david-cermak
Copy link
Collaborator

@david-cermak david-cermak commented Jul 10, 2024

  • Supports only DATA and PPP mode

  • Add CMUX modes

@david-cermak david-cermak added this to the modem-v1.2.0 milestone Jul 10, 2024
@david-cermak david-cermak self-assigned this Jul 10, 2024
@david-cermak david-cermak force-pushed the feat/modem_mode_detect branch 2 times, most recently from 85abac4 to 6f4231b Compare July 15, 2024 06:41
@david-cermak david-cermak marked this pull request as ready for review July 15, 2024 06:41
components/esp_modem/include/cxx_include/esp_modem_dte.hpp Outdated Show resolved Hide resolved
return false;
}
mode = modem_mode::UNDEF;
ESP_LOGI("DCE mode", "Detected mode: %d", static_cast<int>(guessed));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to log it in INFO mode? Could we move to DEBUG or VERBOSE?

components/esp_modem/src/esp_modem_dce.cpp Outdated Show resolved Hide resolved
components/esp_modem/src/esp_modem_dce.cpp Outdated Show resolved Hide resolved
// Check whether the response resembles the "golden" reply (for these 3 protocols)
if (reply_pos >= sizeof(probe::ppp::lcp_echo_reply_head)) {
// check for initial 2 bytes
uint8_t *ptr = static_cast<uint8_t *>(memmem(reply, reply_pos, probe::ppp::lcp_echo_reply_head, 2));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build a string_view from the received buffer and use provided algorithms might lead to simpler code here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any idea how to do it without reinterpret cast?

    std::string_view reply_view(reinterpret_cast<const char*>(reply), reply_size);
    
    // Create a string_view for the bytes to compare against
    std::string_view head_view(reinterpret_cast<const char*>(ppp::lcp_echo_reply_head.data()), 2);

    // Check if the reply starts with the first 2 bytes of lcp_echo_reply_head
    return reply_view.starts_with(head_view);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is that I'm actually testing if the current protocol is binary or ascii, so I think the best option is to just use the old good memmem()...

@david-cermak david-cermak force-pushed the feat/modem_mode_detect branch from de23a00 to 52598e5 Compare November 1, 2024 12:50
@david-cermak david-cermak merged commit 2442f6b into espressif:master Nov 6, 2024
80 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants