refactor: extract shared utilities from duplicated MeshCore interface code - #4
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
… code Create _meshcore_shared.py containing common logic that was duplicated between MeshCore_Channel_Interface and MeshCore_Dynamic_Interface: - load_meshcore(): meshcore library import with error handling - start_asyncio_loop_thread(): event loop thread creation - create_meshcore_connection(): serial/ble/tcp transport init - configure_radio() / configure_channel(): radio+channel setup - process_incoming(): standard RNS inbound delivery - decode_tunnel_frame(): sender-prefix stripping + base64 decode - reassemble_fragment(): thread-safe fragment reassembly - cleanup_stale_fragments(): timed fragment eviction - PacketIdCounter: thread-safe rolling packet ID counter MeshCore_Interface.py is left unchanged (architecturally different, older fragmentation format, different threading model). Import mechanism uses sys.path with __file__ fallback to handle Reticulum's exec()-based interface file loading. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MeshCore_Channel_InterfaceandMeshCore_Dynamic_Interfacecontained substantial duplicated logic. This PR extracts 10 shared utilities into a newInterface/_meshcore_shared.pymodule and rewires both interfaces to use them.Extracted utilities:
load_meshcore(interface_name)_load_meshcore_or_panicimport+log pattern in both filesstart_asyncio_loop_thread(name, iname)_run_loop+threading.Threadboilerplate in both__init__create_meshcore_connection(mc, transport, ...)if/elif/elsecreation blocks (~30 lines each)configure_radio(mc, freq, bw, sf, cr, ...)configure_channel(mc, idx, name, secret, ...)process_incoming(interface, data)processIncomingbody (rxb += len; owner.inbound)decode_tunnel_frame(text, prefix, ...)_process_tunnel_textreassemble_fragment(asm, meta, lock, key, ...)cleanup_stale_fragments(asm, meta, lock, ...)_cleanup_loopPacketIdCounter(bits)_pkt_id+_pkt_id_lock+ manual& 0xFF/& 0xFFFFFFFFin both filesWhat stays in each interface:
_PacketHandlerclasses (different wire formats: 9-byte vs 6-byte headers)Import mechanism for Reticulum's
exec()-based loading:MeshCore_Interface.pyis untouched — its older architecture (custom_safe_log, different fragmentation format,PacketHandlerwithBbstruct) is different enough that forcing shared code would reduce clarity.Net diff: Channel −141 lines, Dynamic −37 lines, shared module +286 lines. The value is in eliminating duplicated patterns that would otherwise drift independently.
Link to Devin session: https://app.devin.ai/sessions/788f2435d2354a17b1474fcb1a261495
Requested by: @comms-engineer