Abstract:
In this article, we take the R60ABD1 radar as a practical case to detail the design and analysis method of a custom serial communication protocol architecture in the MicroPython environment, focusing on the core of data parsing and business logic separation. We break down key aspects such as protocol encapsulation and command interaction, providing reusable embedded serial driver development ideas.
Original link:
https://www.cnblogs.com/FreakEmbedded/p/19239873

Also see:
https://f1829ryac0m.feishu.cn/docx/O1trdIGMEocKh2xRX7QcGTLxnNd?from=from_copylink

Content
Due to the lengthy nature of this article and the original text being written in MD format, there are some issues when placed in the public account. Therefore, a brief outline of the content is provided along with a directory screenshot. Interested readers can visit my blog for more details:
The original intention of this article is to address the pain points in embedded development regarding the difficulty of custom serial protocol parsing, severe coupling of data and business logic, and insufficient driver performance optimization under MicroPython’s resource constraints. Using the R60ABD1 radar as a practical carrier, we output a general driver design methodology of “data parsing and business logic separation” to help developers efficiently complete serial protocol driver development.
The article covers the following core modules:
- Basic Layer: Understanding Protocols and Hardware Analyze the core protocol (frame structure, command types, status encoding) from the R60ABD1 data manual, set up a hardware debugging environment, and summarize the interaction logic of the radar’s basic commands, human presence, heart rate/breathing/sleep monitoring, and other full-function commands. Common issues in development (such as abnormal functional configuration responses and initialization process bottlenecks) are also addressed to solidify the foundational understanding of the protocol for driver development.
- Architecture Layer: Layered Driver Design A detailed explanation of the “data parsing layer + business logic layer” layered architecture of the MicroPython driver:
<span>DataFlowProcessor</span>class is responsible for pure data parsing (timer cycle determination, frame header/length/CRC verification, command sending encapsulation), decoupling hardware data reading from business logic;<span>R60ABD1</span>class serves as the business logic layer, mapping protocol values through class attribute constants, parsing raw data (human position, waveform, sleep state, etc.) via private methods, and then converting “raw data → business attributes” through the<span>update_properties_from_frame</span>method, while implementing command response logic (active query/control interaction process, return parameter specifications).- Practical Layer: Driver Integration and Verification Optimize the driver initialization process (configurable parameters, fault tolerance retries, error tracing), write full-function test scripts (initialization verification, functional interface testing, real-time data monitoring), and analyze performance testing under different parsing intervals regarding CPU usage and method execution time, verifying the reliability and efficiency of the driver in resource-constrained environments.
In summary, the article presents a complete process of “protocol understanding → architecture design → functional development → testing optimization” in the custom serial protocol driver, showcasing the practical process of “data and business logic separation”. It serves as a typical reference for MicroPython and embedded developers learning serial driver development.











The relevant firmware and source code used for testing can be downloaded from the link below:
https://f1829ryac0m.feishu.cn/docx/O1trdIGMEocKh2xRX7QcGTLxnNd?from=from_copylink