Skip to content

556 fixing the modem code. Fix modem I/O, connection lifecycle, and graceful shutdown - #557

Open
dmitriyk-aethernet wants to merge 15 commits into
mainfrom
556-fixing-the-modem-code
Open

dmitriyk-aethernet wants to merge 15 commits into
mainfrom
556-fixing-the-modem-code

Conversation

@dmitriyk-aethernet

Copy link
Copy Markdown
Contributor

This PR fixes modem communication stalls and shutdown crashes, and adds orderly network cleanup for SIM7070 and Thingy91X. Application exit now waits for modem shutdown before releasing runtime resources.
Changes include:

  • Fix Windows overlapped serial I/O, receive callback locking, and port cleanup.
  • Handle fragmented AT responses, binary +CARECV payloads, and data-entry prompts; prevent duplicate request completion.
  • Close sockets and deactivate network service during SIM7070 and Thingy91X shutdown.
  • Remove stale transport subscriptions and defer disconnect handling to prevent access violations.
  • Retry SIM readiness and operator selection after SIM7070 wakes from minimum functionality mode.
  • Release registration transports after completion and resume packet queues after asynchronous sends.
  • Reduce SIM7070 startup template complexity and limit Visual Studio builds to four parallel jobs.
  • Add escaped telemetry output, regression tests, and English Doxygen documentation.
    The branch also enables SIM7070 by default, increases connection/request timeouts, limits cloud connections to one, and replaces several configurable capacities with fixed values.
    Validation:
  • Targeted modem shutdown and server connection tests passed.
  • A/B and SIM7070 cloud smoke tests passed on both fresh and preserved state.
  • Hardware logs confirmed socket closure, PDP deactivation, and successful shutdown.
  • Thingy91X shutdown was verified with a mock modem.
  • Four previously observed failures remain in the broader serial-port suite.

@dmitriyk-aethernet dmitriyk-aethernet linked an issue Sep 10, 2026 that may be closed by this pull request
Comment thread aether/adapters/adapter.cpp Outdated
#include "aether/adapters/adapter.h"

namespace ae {
Action* Adapter::Stop() { return nullptr; }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

leave it pure virtual

Comment thread aether/adapters/adapter.h Outdated

// Stop runtime network resources. The adapter owns the returned action and
// keeps it alive until destruction. nullptr means no asynchronous work.
virtual Action* Stop();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

define your own action interface based on Action
like class IAdapterStop: public Action.

return refernce to it.


void ProtocolContext::SetSendResultResponse(RequestId request_id) {
auto entry = TakePending(request_id);
auto* p = parser();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What problem are you trying to solve?

// IWYU pragma: end_keeps

namespace ae {
namespace ethernet_transport_factory_internal {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why?

# include "aether/channels/channel.h"

namespace ae::modem_channel_internal {
TransportBuildSender ConnectTransport(std::unique_ptr<ByteIStream> transport);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why?


s = t->stream_update_event().Subscribe([&]() {
if (t->stream_info().link_state == LinkState::kLinked) {
auto complete = [&]() noexcept {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

don't make sense to me

Uid const& destination() const;

private:
static constexpr auto kBufferCapacity = AE_P2P_MESSAGE_STREAM_BUFFER_CAPACITY;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

don't have words

template <std::size_t Capacity>
class SafeStream;

static constexpr inline std::size_t kP2pSafeStreamCapacity =

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The rule
define static constexpr variable and assign to it defined values from config
Than use this variable in templates.


private:
SizedPacketGate sized_packet_gate_;
// TODO: add config

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

looks like you solved merge conflicts wrong

Comment thread aether/executors/with_timeout.h Outdated
// task_sub controls if task reset or no
op_base_.task_sub = ac_.scheduler().DelayedTask(
[&]() noexcept {
if (op_base_.is_reset()) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

make no sense
Reset twice do nothing

- Make Adapter::Stop() pure virtual and return IAdapterStop&.
- Add adapter-owned shutdown operations with stable lifetimes.
- Restore configurable buffer, queue, and action pool capacities.
- Remove the redundant timeout guard and internal modem channel header.
- Preserve transport subscription cleanup that prevents shutdown crashes.
- Keep early returns for unexpected protocol responses and remove redundant parser checks.
- Add regression tests for shutdown lifetimes and unknown or duplicate responses.

Validation: clean single-threaded build, four targeted test suites, and
fresh/preserved-state A/B and cloud smoke tests over Ethernet passed.
- Implement buffered UART transport.
- Add a FireBeetle 2 ESP32-C6 configuration for SIM7070G.
- Stop pings and reconnection attempts before shutting down the modem.
- Power off the modem using AT+CPOWD=1 and wait for NORMAL POWER DOWN.
- Add shutdown and modem error-handling tests.
- Set the main task stack size to 24 KB.
- Switch the current build configuration to Wi-Fi.
- Define WIFI_SSID and WIFI_PASSWORD through target_compile_definitions.
- Use the supplied credentials instead of hardcoded values.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fixing the modem code.

2 participants