Overall Technical Description of the Main Control Software for Ultrasonic Smart Water Meters
Unified Architecture and Implementation Points for Switchable Multiple Communication Modes
This document provides an overview of the main control software for ultrasonic smart water meters, covering its overall architecture, metering and business implementation, and the design for switchable multiple communication modes. The software uses the same set of business code and protocol code to adapt, through configuration, to multiple communication units such as cellular, LoRa, wireless LAN, and wired bus, and supports multiple transport protocols, thereby enabling product form derivatives without modifying the upper-layer business logic.

I. Overall Architecture
The software is organized according to the principle of "decoupling business from communication" and is divided, from bottom to top, into the driver layer, middleware layer, business layer, and communication layer. The driver layer encapsulates on-chip resources such as serial ports, buses, Flash, real-time clock, and analog acquisition. The middleware layer provides common capabilities such as ring buffers, timer tasks, logging and exception traceback, and non-volatile storage. The business layer performs metering, valve control, prepayment, local interaction, and history recording. The communication layer interfaces with specific modules or buses through a unified interface and provides send, receive, and status query services upward.
Table 1 Software layers and main modules
Layer Main modules and responsibilities:
- Driver layer: Serial port, IIC, SPI, Flash, real-time clock, battery and voltage acquisition
- Middleware layer: Ring buffer, software timers, leveled logging, exception traceback, parameter storage
- Business layer: Metering acquisition, valve control, prepayment, local interaction, history freezing and storage
- Communication layer: Module or bus driver, transport protocol adaptation, frame transmission/reception and status mapping
Metering and communication interact only through data structures: metering results are written into a unified data area, and the communication layer frames them according to the protocol before sending; platform commands are parsed by the communication layer and then passed to the business layer for execution. This constraint ensures that business code does not need to be modified when a new communication mode is added.
II. Metering and Business Implementation
The metering part supports three acquisition channels: ultrasonic, pulse, and switching value. The ultrasonic channel is based on the time-difference method: a high-precision timing unit measures the propagation time difference between downstream and upstream flow, and the flow is calculated in combination with the acoustic path coefficient and temperature compensation, while outputting forward cumulative volume, reverse cumulative volume, and instantaneous flow. The pulse and switching value channels are used to be compatible with existing meter types; after connection, results are provided externally through the same data area.
The business part includes valve control, prepayment management, local buttons and display, and history data freezing and storage. Valve status, balance, and alarms are uniformly written into the status area for shared use by display and communication; when the balance is insufficient, the valve is closed according to the strategy, and it is restored after successful recharge. Key metering and configuration parameters are stored in partitions with verification and are automatically restored after power failure and reset.
III. Switching of Multiple Communication Modes
The communication mode is determined by configuration items at compile time, covering forms such as no communication, cellular network, LoRaWAN, wireless LAN, and wired bus. The transport protocol is independent of the communication mode selection and includes IoT proprietary protocols, TCP, UDP, MQTT, and Modbus. The two layers of configuration are orthogonal to each other and can be combined into product forms for different projects.
Table 2 Combinable relationship between communication forms and transport protocols
Communication form Typical transport protocols Applicable scenarios
Cellular network: Proprietary protocol, TCP, UDP, MQTT Residential household meter remote transmission, wide coverage, dependent on operator networks
LoRaWAN: Proprietary protocol Self-built networks in parks and villages/towns, low power consumption, no operator tariffs
Wireless LAN: TCP, UDP, MQTT Indoor or centralized installation scenarios with stable hotspots
Wired bus: Modbus Centralized meter reading, renovation of existing pipe networks, polled by the master station
No communication: None Pure local metering or calibration tooling
To ensure consistency across modes, the communication layer exposes only unified semantics to the upper layer, such as initialization, execution, send, receive, connection status, and signal quality. Module differences are confined within the driver, and the frame format does not change with the module. Exception handling is also unified: links, registration, bearers, and transmission/reception are encoded segmentally according to semantics, and screen display and platform reporting share the same set of codes.
IV. Display and On-Site Interaction
The display uses a branch menu. The five branches—main interface, calibration, information, history, and communication—respectively carry metering data, calibration parameters, device information, frozen records, and communication configuration. Pages are trimmed according to the communication mode configuration. For example, in wired mode, the card number and reporting period pages are not displayed, and the address page changes to display the bus address and baud rate; this difference is determined by compile switches and is not a display abnormality.
V. Reliability and Maintainability
The software has an independent watchdog, saving of key data before power failure, exception site traceback, and leveled logging. The communication process uses a non-blocking state machine, and retries and backoff are completed in the background without occupying the processing time of metering and display. Functional items are centrally configured, making it easy to trim according to project requirements and to control code size and power consumption.
VI. Summary
The technical core of this software is "decoupling metering from business, pluggable communication, and separation of protocol from module." The same set of business code adapts to multiple communication forms and transport protocols through configuration, which shortens the delivery cycle of new product forms and enables on-site problems to be located according to a unified layering and coding scheme.
https://www.zhongyismart.com Wuxi Zhongyi Smart Technology Co., Ltd. focuses on R&D and production of smart water meters, energy meters and gas meters. Our products are available in over 90 countries across the globe. Feel free to contact Zhongyi Intelligent for inquiries about smart water meters, electricity meters and gas meters.


