Progress Log: Protocol Architecture Symmetry (v1.8.6)¶
Task Description¶
Implement v1.8.6 refactoring to achieve complete architectural symmetry between binary_protocol and text_protocol layers. This involves:
- Phase 1: Removing unused serial wrapper functions (
serial_available(),serial_send_response(),serial_send_text_response()) - Phase 2: Renaming
serial_flush()toserial_discard()for clarity (distinguish from Arduino'sSerial.flush()) - Phase 3: Moving text protocol queue management from
text_protocol_handler.cpptotext_protocol.cppto match binary_protocol structure - Documentation: Updating REFACTORING_ROADMAP.md and protocol-naming-convention.md
Goal: Both protocols should have identical structure at Layer 2 (Protocol Implementation) with queue management integrated.
Outcome¶
✅ All phases completed successfully
Phase 1: Unused Function Removal¶
- ✅ Deleted
serial_available()from serial_protocol.h/cpp (unused wrapper) - ✅ Deleted
serial_send_response()from serial_protocol.h/cpp (main.cpp usage →Serial.println()) - ✅ Deleted
serial_send_text_response()from text_protocol.h/cpp (text_protocol.cpp usage →Serial.print()/println())
Phase 2: Function Naming Clarity¶
- ✅ Renamed
serial_flush()→serial_discard()across all call sites: - binary_protocol.cpp (2 occurrences)
- text_protocol.cpp (1 occurrence)
- ✅ Enhanced docstring: "Discard remaining data in serial input buffer (safe with size limit)"
- ✅ Clear distinction from
Serial.flush()(output buffer synchronization vs input discard)
Phase 3: Text Protocol Queue Integration¶
- ✅ Moved
text_queue(),text_queued(),text_dequeue()from text_protocol_handler.cpp to text_protocol.cpp - ✅ Added declarations to text_protocol.h (in new QUEUE MANAGEMENT section)
- ✅ Removed declarations from text_protocol_handler.h
- ✅ Updated
text_command_handler_init()to empty function (API compatibility maintained) - ✅ Implementation uses same FIFO pattern as binary_protocol (circular buffer with head/tail/count)
Build Verification¶
- ✅
task build(esp32dev-dev) compilation success - ✅ RAM usage: 7.3% (23912 bytes)
- ✅ Flash usage: 24.0% (314201 bytes)
- ✅ No new warnings or errors introduced
Documentation Updates¶
- ✅ REFACTORING_ROADMAP.md:
- Updated v1.8.6 status from "計画中" to "実装中"
- Added detailed Phase 1-3 completion documentation
- Added architecture comparison table showing complete symmetry
- Updated version history with 2025-11-24 entry
- ✅ docs/protocol-naming-convention.md:
- Updated Shared Utilities section
- Enhanced Historical Context with v1.8.6 improvements
Git Commits¶
a288363- refactor(serial-protocol): rename serial_flush to serial_discard for clarity40e2ddf- docs(binary-protocol, text-protocol): improve reception logic documentation91b5c64- refactor(text-protocol): move queue management from handler to protocol layerf7d67c8- docs(refactoring-roadmap): update v1.8.6 progress with architecture improvementse471d76- docs(protocol-naming-convention): update for v1.8.6 improvements
Architecture Achievement¶
Before v1.8.6¶
binary_protocol vs text_protocol were asymmetric:
- binary: Queue in serial_protocol.cpp (Layer 2)
- text: Queue in text_protocol_handler.cpp (Layer 3)
- Different function naming patterns
- Unused wrapper functions cluttering API
After v1.8.6¶
Complete Symmetry Achieved:
| Function | binary_protocol | text_protocol |
|---|---|---|
| Reception | binary_receive() |
text_receive() |
| Line Read | binary_receive_line() |
text_receive_line() |
| Queue Ops | binary_queue() |
text_queue() ✅ |
| Queue Check | binary_queued() |
text_queued() ✅ |
| Dequeue Exec | binary_dequeue() |
text_dequeue() ✅ |
| Main Loop | binary_execute() |
text_execute() |
Layer Structure (Now Symmetric):
- Layer 1: serial_protocol (shared utilities:
serial_init(),serial_discard()) - Layer 2: binary_protocol/text_protocol (reception + queue management)
- Layer 3: binary_protocol_handler/text_protocol_handler (validation + execution)
Learnings¶
Design Insights¶
- Architectural Symmetry: Identical function naming and structure across protocols improves:
- Code discoverability (search for
binary_*ortext_*finds all protocol functions) - Developer onboarding (new developers understand pattern immediately)
-
Maintenance (adding new protocols follows proven template)
-
API Surface Reduction: Removing 3 unused wrapper functions:
- Reduces cognitive load (fewer functions to understand)
- Simplifies API (only essential functions exposed)
-
Encourages direct Arduino API use where appropriate
-
Naming Clarity:
serial_flush()→serial_discard()distinction: - Arduino
Serial.flush()= wait for output buffer transmission (blocking) - Our
serial_discard()= discard input buffer data (non-blocking, safe) - Prevents confusion and implementation bugs
Implementation Notes¶
- Queue management naturally belongs in Layer 2 (protocol implementation) not Layer 3 (handlers)
- Both protocols use identical FIFO implementation (circular buffer, 10-item capacity)
text_command_handler_init()kept as empty function for API stability (no callers, but avoids link errors)
Next Steps¶
v1.8.7 (Planned): Continue with remaining naming convention updates
- Implement
[protocol]_[stage]()naming consistently for remaining functions - Rename Stage 1-2 functions to complete unified naming scheme
- Consider creating shared queue abstraction if patterns prove reusable
Long-term: Phase 4 (main.cpp integration) - Update main loop to use final unified function names:
#if ENABLE_TEXT_PROTOCOL
text_receive(); // Receive and queue
text_execute(); // Execute queued
#else
binary_receive(); // Receive and queue
binary_execute(); // Execute queued
#endif
Summary¶
v1.8.6 successfully establishes complete architectural symmetry between binary and text protocols through:
- 3 unused functions removed (cleaner API)
- 1 function renamed for clarity (better semantics)
- Queue management unified at Layer 2 (better architecture)
- Full documentation updated (consistent knowledge)
Result: Maintainable, symmetric protocol layer ready for future extensions.