Remote differential upgrading method and system without influencing NB-IoT ultrasonic water meter metering
By introducing a reset timing selection based on flow velocity monitoring and a hardware timer collaborative rollback mechanism into the NB-IoT ultrasonic water meter, the problems of long firmware upgrade time, high power consumption, and real-time metering of the NB-IoT ultrasonic water meter are solved. This achieves seamless switching and high success rate upgrades, and improves the system's self-recovery capability and robustness.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HENAN HANWEI ELECTRONICS
- Filing Date
- 2025-12-23
- Publication Date
- 2026-04-21
AI Technical Summary
Existing firmware upgrade methods for NB-IoT ultrasonic water meters are time-consuming and power-intensive in low-speed NB-IoT networks, and the upgrade process can easily affect the real-time performance and reliability of metering. Traditional differential upgrade solutions have failed to effectively solve the problem of upgrade and resume transmission when the network is unstable.
A reset timing selection strategy based on flow rate monitoring is adopted, combined with a hardware and software collaborative rollback mechanism involving hardware timers and watchdog timers. A time-sharing parallel task architecture and a hybrid upgrade mechanism are designed. Seamless switching is achieved by intelligently judging the water flow intermittent window, and an upgrade resume function is introduced.
It enables seamless firmware version switching under NB-IoT network, ensuring the real-time performance and accuracy of metering function, improving the system's self-recovery capability and robustness, reducing network resources and device energy consumption, and increasing the upgrade success rate.
Smart Images

Figure CN121900786A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of smart water meter technology, and more specifically, to a remote differential upgrade method and system that does not affect the metering of NB-IoT ultrasonic water meters. Background Technology
[0002] NB-IoT ultrasonic water meters, as a widely deployed IoT terminal, are characterized by battery power, NB-IoT network communication (low data rate, high latency), and real-time ultrasonic metering. These characteristics pose significant challenges to traditional firmware upgrade methods: power consumption and network bottlenecks: full-package upgrades require the transmission of complete firmware files, which takes an extremely long time under low-speed NB-IoT networks, severely consuming battery power, and the success rate of upgrades is easily affected by network fluctuations.
[0003] Real-time metering requirements: Ultrasonic metering requires real-time sampling and calculation of ultrasonic signals to measure flow rate, with a maximum sampling period typically of 1 second. If the upgrade process consumes system resources for an extended period or causes program interruption, it will directly result in data loss or errors, affecting the accuracy and reliability of the water meter.
[0004] Existing remote upgrade solutions either focus only on differential upgrades to reduce data volume, but do not fully consider their impact on real-time tasks (such as metering); or although they consider task scheduling, they lack a fine strategy to ensure metering continuity in critical reset and switching stages, and often ignore the issue of upgrade retransmission when the network is unstable.
[0005] Therefore, there is an urgent need in this field for a complete upgrade solution that can comprehensively address data transmission efficiency, ensure that the upgrade process does not affect real-time metering, and possess high reliability. Summary of the Invention
[0006] Therefore, it is necessary to provide a remote differential upgrade method and system that does not affect the metering of NB-IoT ultrasonic water meters to address the above-mentioned technical problems.
[0007] To achieve the above objectives, the first aspect of the present invention provides a remote differential upgrade method that does not affect the metering of NB-IoT ultrasonic water meters, comprising the following steps: Obtain the upgrade configuration frame issued by the platform, verify the version compatibility, and perform local copying after successful verification, copying the corresponding data blocks in the old program area to the corresponding positions in the new program area; Request and receive differential data packets sequentially, and write them to the specified address in the new program area; After all data is received and verified, the water flow status is continuously monitored; When the instantaneous flow rate of water is detected to be zero or lower than the set threshold, a reset preparation flag is written to Flash and the system is triggered to reset. Among them, the upgrade configuration frame and differential data packet are generated by the platform side based on the old program bin file and the new program bin file of the water meter terminal.
[0008] It's understandable that in the final step of an upgrade—resetting and switching to the new firmware—traditional solutions would directly reset, interrupting current metering transactions. This invention doesn't reset immediately after the upgrade; instead, it intelligently waits for a zero-flow window by monitoring water flow velocity in real time. This window signifies a state where the user hasn't used water and there's no water flow in the pipes. Once a sustained zero flow rate is detected, the system quickly completes the reset and application switch within this harmless time window. Because the switch occurs at the instant of no metering activity, it doesn't cause any loss or error in metering data, achieving a truly seamless switch.
[0009] Furthermore, writing the reset preparation flag to Flash and triggering a system reset includes: After the bootloader starts, if a reset preparation flag is detected, it will be changed to an attempt to jump to a new application flag, and then the user will jump to the new application area. If the new application starts normally, the redirection to the new application will be changed to the successful redirection to the new application. If the new application is defective and fails to start, the watchdog will trigger a system reset; When the bootloader restarts, if it detects an attempt to jump to a new application, it determines that the previous upgrade jump failed and automatically jumps back to the old application area. After the old application starts, the identifier will be updated to the successful application redirection identifier, enabling an automatic and safe rollback.
[0010] Furthermore, the method also includes a task scheduling mechanism based on a hardware timer, specifically including: During system initialization, a hardware timer is configured to generate an interrupt signal with a fixed period. When a timer interrupt is triggered, the interrupt service routine is entered, and an atomic increment operation is performed on the system master clock counter, which serves as the system time reference. The task scheduler runs in the system's main loop, and each cycle task is independently configured with execution cycle parameters and a timestamp variable that records the last scheduling time. The scheduler continuously calculates the difference between the current system master clock counter and the timestamp of each task. When the difference is greater than or equal to the task execution cycle, the corresponding task is executed immediately. After the task is completed, update the timestamp variable of the task to the current system master clock counter value to reset its timing cycle.
[0011] Furthermore, the method also includes a preemptive execution mechanism for metering tasks, specifically including: Configure the ultrasonic measurement interrupt to the highest hardware priority, and set the global measurement event pending flag in the interrupt service routine when a measurement event occurs. In the main loop's task scheduler, the metering event pending flag is checked first before any periodic task scheduling is performed. If the flag is detected to be set, the currently executing normal priority task will be immediately paused and the execution of the high-priority metering task will be switched to. Once the metering task is completed, the flag is cleared, and the task scheduler resumes the interrupted task according to a preset strategy.
[0012] Furthermore, upgrade-related tasks such as local copying, network data reception, and Flash writing are set to the lowest priority; When the task scheduler reaches the lowest priority task queue, the network receiving task gets the first chance to execute. This task uses a fragmented receiving mechanism, receiving only data segments that do not exceed the capacity of the RAM buffer in each scheduling, and then actively suspending and updating the receiving state machine. This process is repeated until the complete data packet is received, and then the data packet is stored in the processing queue to wait for subsequent processing. When the scheduler reaches the local copy task, it parses the description information of the same data block from the upgrade configuration frame, including the source address, target address and data length; it reads data from the source address in units of Flash page size; before performing each page programming operation, it strictly checks the status of the metering event flag bit; after confirming that there are no pending metering events, it performs data writing; after completion, it immediately updates the address pointer and saves the operation context, and then suspends the task to wait for the next scheduling cycle to continue execution. Flash write tasks retrieve received differential data packets from the processing queue and decompose them into the smallest write units conforming to the physical characteristics of Flash. Each write unit undergoes dual security verification before execution: first, the metering event pending processing flag is checked; second, the target address is confirmed to be within the legal operation range. Page programming operations are performed under secure conditions, and the duration of a single programming operation must be strictly less than the system-defined maximum response time threshold for metering interruptions.
[0013] If the upgrade process is interrupted due to network connection interruption, the ultrasonic water meter will record the status information such as the current operation type, address pointer, remaining data length and checksum in real time after each atomic operation is completed locally. When the system detects that the metering event flag is set, it will immediately pause the upgrade task after completing the current smallest storage unit operation. The upgrade process will only be allowed to resume after the metering task is completed and no new events are generated within several consecutive scheduling cycles.
[0014] Furthermore, if the upgrade process is interrupted due to network connection interruption, the ultrasonic water meter will record the sequence number of the last data packet that has been successfully received locally; after communication is restored and the connection with the platform is re-established, the ultrasonic water meter will report the sequence number as status information. After receiving the status information, the platform continues to send the remaining differential data starting from the next data packet of that sequence number.
[0015] The second aspect of the present invention provides a remote differential upgrade system that does not affect the metering of NB-IoT ultrasonic water meters, including a platform side and an NB-IoT ultrasonic water meter, wherein the platform side is used to send upgrade configuration frames to the NB-IoT ultrasonic water meter; The NB-IoT ultrasonic water meter verifies version compatibility and performs local copying after successful verification, copying the corresponding data blocks in the old program area to the corresponding positions in the new program area; it sequentially requests and receives differential data packets and writes them to the specified address in the new program area; after all data is received and verified, it continuously monitors the water flow status; when the instantaneous flow rate of the water is detected to be zero or lower than the set threshold, it writes the reset preparation flag to Flash and triggers the system reset; Among them, the upgrade configuration frame and differential data packet are generated by the platform side based on the old program bin file and the new program bin file of the water meter terminal.
[0016] The beneficial effects of this invention are as follows: This invention pioneers a seamless metering assurance system covering the entire process from task scheduling to reset timing. Based on a self-designed time-sharing parallel task architecture, this system effectively ensures that the real-time performance and accuracy of the metering function are unaffected during firmware upgrades. Furthermore, we innovatively introduce a reset timing selection strategy based on flow rate monitoring. By intelligently determining the natural intermittent window of water flow and combining this with the bootloader's rapid switching capability within one second, we achieve zero interference with the metering process during the critical operation of application version switching, precisely addressing a core pain point long overlooked by the industry.
[0017] Regarding the upgrade methodology, a hybrid upgrade mechanism that deeply integrates local replication and network differential transmission is proposed. Building upon traditional differential upgrades, this mechanism uses a cloud platform to intelligently identify identical data blocks between the old and new firmware and instructs the water meter to directly replicate the data in its local Flash memory, transmitting only the necessary difference data via the wireless network. This significant optimization greatly reduces data transmission volume in low-speed, high-power network environments such as NB-IoT, making large-scale, reliable firmware upgrades possible even under demanding narrowband IoT conditions.
[0018] To ensure absolute reliability, a hardware-software collaborative rollback mechanism based on three-state flags and a watchdog timer was designed. By clearly marking three states in non-volatile memory—preparing for reset, attempting to jump to a new application, and successful application jump—and working closely with the hardware watchdog timer, a logically robust safety loop is formed. This mechanism can automatically, quickly, and reliably roll back to a stable and usable older version of the application without manual intervention when a new application startup failure is detected, greatly improving the system's self-recovery capability and overall robustness in the face of unknown anomalies.
[0019] Finally, to address the practical challenge of unstable NB-IoT network connectivity, the solution introduces a robust upgrade resume function. This function allows the upgrade process to automatically resume from the point of interruption after intermittent network outages, rather than starting over. This not only effectively avoids overall upgrade failures due to temporary signal weakness but also significantly saves network resources and device power consumption, thus ensuring a high success rate and final completion of firmware upgrade tasks in complex real-world deployment environments. Attached Figure Description
[0020] Figure 1 This is a schematic diagram of the remote upgrade process for the water meter in this application; Figure 2 This is a flowchart illustrating the differential upgrade algorithm on the platform side of this application; Figure 3 This is a flowchart of the task scheduling mechanism based on a hardware timer in this application. Detailed Implementation
[0021] The following is in conjunction with the appendix Figure 1 -Appendix Figure 3 This application will be described in further detail below.
[0022] Example 1 Please see the appendix Figures 1-2 This embodiment provides a remote differential upgrade method for NB-IoT ultrasonic water meters that does not affect metering, comprising the following steps: Obtain the upgrade configuration frame issued by the platform, verify the version compatibility, and perform local copying after successful verification, copying the corresponding data blocks in the old program area to the corresponding positions in the new program area; Request and receive differential data packets sequentially, and write them to the specified address in the new program area; After all data is received and verified, the water flow status is continuously monitored; When the instantaneous flow rate of water is detected to be zero or lower than the set threshold, a reset preparation flag is written to Flash and the system is triggered to reset. Among them, the upgrade configuration frame and differential data packet are generated by the platform side based on the old program bin file and the new program bin file of the water meter terminal.
[0023] It's understandable that in the final step of an upgrade—resetting and switching to the new firmware—traditional solutions would directly reset, interrupting current metering transactions. This invention doesn't reset immediately after the upgrade; instead, it intelligently waits for a zero-flow window by monitoring water flow velocity in real time. This window signifies a state where the user hasn't used water and there's no water flow in the pipes. Once a sustained zero flow rate is detected, the system quickly completes the reset and application switch within this harmless time window. Because the switch occurs at the instant of no metering activity, it doesn't cause any loss or error in metering data, achieving a truly seamless switch.
[0024] Specifically, the steps for generating upgrade configuration frames and differential data packets include: Obtain the old program bin file and the new program bin file from the water meter, along with their corresponding version numbers and starting addresses in the Flash memory. Calculate the data length and verification of the new and old programs, and identify the same and different data parts between them through a binary comparison algorithm; Generate an upgrade configuration frame, which includes the version number of the new / old program, the starting address, the data length, the verification, the address and length information of the same data block, and the total number of differential data packets; Generate differential data packets, dividing the difference data portion into multiple data packets according to a preset packet length. Each packet contains the starting address, length, and binary content of the data block in the new program. If the data size of a configuration frame or a single differential data packet exceeds the communication protocol limit, it will be transmitted in packets.
[0025] As can be understood, this mechanism, based on traditional differential upgrades, uses a cloud platform to intelligently identify identical data blocks between the old and new firmware, and instructs the water meter to directly copy the data in its local Flash memory, transmitting only the necessary difference data via wireless network. This significant optimization greatly reduces data transmission volume in low-speed, high-power network environments such as NB-IoT, making large-scale, reliable firmware upgrades possible under demanding narrowband IoT conditions.
[0026] Furthermore, the Flash memory is divided into a Bootloader area, an old application area, a new application area, and an upgrade parameter area.
[0027] Under the above premise, the reset preparation flag is written to Flash and the system is reset, including: after the Bootloader starts, if the reset preparation flag is detected, it is modified to attempt to jump to a new application flag and jumps to the new application area; If the new application starts normally, try changing the new application redirection flag to the successful application redirection flag. If the new application is defective and fails to start, the watchdog will trigger a system reset; When the bootloader restarts, if it detects an attempt to jump to a new application, it determines that the previous upgrade jump failed and automatically jumps back to the old application area.
[0028] When the old application starts, the identifier will also be updated to the successful application redirection identifier, achieving automatic and safe rollback.
[0029] As can be understood, the above steps design a hardware-software collaborative rollback mechanism based on three-state flags and a watchdog timer. By clearly marking three states in non-volatile memory—preparing for reset, attempting to jump to a new application, and successful application jump—and working closely with the hardware watchdog timer, a logically rigorous safety closed loop is formed. This mechanism can automatically, quickly, and reliably roll back to a stable and usable older version of the program without manual intervention when a new application startup failure is detected, greatly improving the system's self-recovery capability and overall robustness in the face of unknown anomalies.
[0030] It is understandable that, furthermore, if the upgrade process is interrupted due to network connection interruption, the ultrasonic water meter will record the sequence number of the last data packet that has been successfully received locally; after communication is restored and the connection with the platform is re-established, the ultrasonic water meter will report the sequence number as status information. After receiving the status information, the platform continues to send the remaining differential data starting from the next data packet of that sequence number.
[0031] The above solution allows the upgrade process to automatically resume from the point of interruption and continue execution after intermittent network outages, rather than starting over. This not only effectively avoids overall upgrade failures caused by temporary poor signal, but also significantly saves network resources and device power consumption, thus ensuring a high success rate and final completion of firmware upgrade tasks in complex real-world deployment environments.
[0032] Furthermore, the automatic rollback mechanism and breakpoint resume function can effectively cope with various abnormal situations, ensuring a high success rate in the upgrade process and long-term stable operation of terminal devices.
[0033] It should be understood that although the steps in the flowcharts of the above embodiments are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the above embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0034] Example 2 The difference between this embodiment and Embodiment 1 is that the method further includes a task scheduling mechanism based on a hardware timer, such as... Figure 3 As shown, it specifically includes: During system initialization, a hardware timer is configured to generate an interrupt signal with a fixed period. When a timer interrupt is triggered, the interrupt service routine is entered, and an atomic increment operation is performed on the system master clock counter, which serves as the system time reference. The task scheduler runs in the system's main loop, and each cycle task is independently configured with execution cycle parameters and a timestamp variable that records the last scheduling time. The scheduler continuously calculates the difference between the current system master clock counter and the timestamp of each task. When the difference is greater than or equal to the task execution cycle, the corresponding task is executed immediately. After the task is completed, update the timestamp variable of the task to the current system master clock counter value to reset its timing cycle.
[0035] In the above method, the timing period of the main clock of the task is set according to the timer interrupt. Each task is executed by recording and comparing the main clock timer with the task's running cycle.
[0036] It is understandable that the underlying driver of the above scheme relies on a low-power timer, which is precisely configured to generate a timer interrupt every 10 milliseconds. This periodic interrupt is the reference clock source for scheduling all tasks in the system.
[0037] The interrupt service routine increments a global variable named System Clock Counter, with each increment representing a 10-millisecond time interval. This interrupt service routine runs with the highest hardware priority, ensuring the accuracy and reliability of the system clock.
[0038] On top of this hardware timing mechanism, an application task scheduling layer is built. Each task determines whether it has reached its preset execution cycle by querying and comparing the current system clock value with its own recorded "last execution timestamp".
[0039] Taking an ultrasound metrology task as an example: This task is set to execute once every 1 second (i.e., 100 10-millisecond cycles). Within the program's main loop or a high-priority management function, a condition check is continuously performed: the current system master clock counter minus the task's own recorded timestamp of the last execution is checked to see if it is greater than or equal to 100. Once the condition is met, indicating that 1 second has elapsed, the system immediately executes the ultrasound metrology task.
[0040] Once the task is completed, the current system master clock counter value will be updated to the previous execution timestamp immediately to mark the time point of this execution and prepare for the calculation of the next 1-second cycle.
[0041] This design enables a simple yet efficient collaborative scheduling system for periodic tasks. Through a unified hardware clock source, it allows multiple tasks with different execution cycles (such as data acquisition, communication, and display refresh) to be triggered and executed systematically at their respective times, thus ensuring the real-time performance and timing accuracy of the system. It is particularly suitable for IoT terminal devices such as water meters that require precise timing.
[0042] In particular, the execution time of the subtask is much less than 1 second; the system initialization execution time is much less than 1 second.
[0043] Example 3 The difference between this embodiment and Embodiment 2 is that the method further includes a preemptive execution mechanism for the metering task, specifically including: Configure the ultrasonic measurement interrupt to the highest hardware priority, and set the global measurement event pending flag in the interrupt service routine when a measurement event occurs. In the main loop's task scheduler, the metering event pending flag is checked first before any periodic task scheduling is performed. If the flag is detected to be set, the currently executing normal priority task will be immediately paused and the execution of the high-priority metering task will be switched to. Once the metering task is completed, the flag is cleared, and the task scheduler resumes the interrupted task according to a preset strategy.
[0044] It is understandable that while configuring the ultrasonic metrology interrupt as the highest hardware priority, tasks such as timed data storage, key processing, infrared communication, watchdog maintenance, LCD display, network communication, and upgrade processing are all classified as low-priority tasks. When a high-priority metrology task is triggered and needs to be executed, the system will immediately suspend any currently executing low-priority tasks (such as upgrade processing tasks) to ensure that the metrology task receives an immediate response.
[0045] After the high-priority metering tasks are completed, the system seamlessly resumes the previously suspended low-priority tasks through an efficient context switching mechanism, allowing them to continue execution from the point of interruption, thereby ensuring the integrity and continuity of system functions.
[0046] It is worth emphasizing that, in addition to the event-driven preemptive metering tasks mentioned above, the system scheduler also retains the original periodic metering tasks. The priority of these periodic tasks is set to be second only to event-driven tasks, but still higher than all ordinary background tasks, thus constructing a hierarchical and timely multi-task priority system.
[0047] Specifically, the default strategy is as follows: for recoverable tasks, execution continues from the point of interruption; to ensure system timing stability, it is also possible to update the last execution timestamp of the interrupted task to the current time, which is equivalent to resetting its execution cycle.
[0048] Through the above steps, the system implements event-based preemptive scheduling. Metering events can interrupt most background operations at any time, ensuring the real-time performance and accuracy of metering, while the original time-sharing scheduling mechanism continues to manage non-urgent periodic tasks, together forming a responsive and fully functional system.
[0049] Furthermore, an ultrasonic measurement is performed immediately after initialization; during the upgrade process, the flow rate is continuously checked for stability before reset, and an ultrasonic measurement is performed before reset.
[0050] Example 4 The difference between this embodiment and embodiment 3 is that upgrade-related tasks such as local copying, network data reception, and Flash writing are set to the lowest priority.
[0051] It's understandable that the task scheduler uses fixed-priority scheduling and checks tasks sequentially according to priority. The specific process is as follows: Step 1: Check and execute the highest priority metering task (if the flag is set).
[0052] Step 2: Check and execute the next highest priority periodic metering task (if its period has expired).
[0053] Step 3: The lowest priority upgrade task will only be executed when all the above high priority tasks are no longer required.
[0054] This order is crucial. When the execution process reaches the third step, it indicates that there are no high-priority metering tasks pending in the current system. At this point, the system is in a safe window open for background tasks.
[0055] When the task scheduler reaches the lowest priority task queue, the network receiving task gets the first chance to execute. This task uses a fragmented receiving mechanism, receiving only data segments that do not exceed the capacity of the RAM buffer in each scheduling, and then actively suspending and updating the receiving state machine. This process is repeated until the complete data packet is received, and then the data packet is stored in the processing queue to wait for subsequent processing. When the scheduler reaches the local copy task, it parses the description information of the same data block from the upgrade configuration frame, including the source address, target address and data length; it reads data from the source address in units of Flash page size; before performing each page programming operation, it strictly checks the status of the metering event flag bit; after confirming that there are no pending metering events, it performs data writing; after completion, it immediately updates the address pointer and saves the operation context, and then suspends the task to wait for the next scheduling cycle to continue execution. Flash write tasks retrieve received differential data packets from the processing queue and decompose them into the smallest write units that conform to the physical characteristics of Flash. Each write unit must pass dual security verification before execution: first, the metering event pending flag is checked, and second, the target address is confirmed to be within the legal operation range. Page programming operations are performed under the premise of ensuring security, and the duration of a single programming operation must be strictly less than the maximum response time threshold for metering interruption specified by the system.
[0056] Through this refined task scheduling and secure operation mechanism, the system achieves seamless execution of the entire firmware upgrade process while ensuring the absolute priority of the metering function.
[0057] Furthermore, after each atomic operation is completed, the system saves the current operation type, address pointer, remaining data length, checksum, and other status information in real time. When the system detects that the metering event flag is set, it will immediately pause the upgrade task after completing the current smallest storage unit operation. The upgrade process will only be allowed to resume after the metering task is completed and no new events are generated within several consecutive scheduling cycles.
[0058] Example 4 Based on the same inventive concept, this application provides a remote differential upgrade system that does not affect the metering of NB-IoT ultrasonic water meters, including a platform side and an NB-IoT ultrasonic water meter, wherein the platform side is used to send upgrade configuration frames to the NB-IoT ultrasonic water meter. The NB-IoT ultrasonic water meter verifies version compatibility and performs local copying after successful verification, copying the corresponding data blocks in the old program area to the corresponding positions in the new program area; it sequentially requests and receives differential data packets and writes them to the specified address in the new program area; after all data is received and verified, it continuously monitors the water flow status; when the instantaneous flow rate of the water is detected to be zero or lower than the set threshold, it writes the reset preparation flag to Flash and triggers the system reset; Among them, the upgrade configuration frame and differential data packet are generated by the platform side based on the old program bin file and the new program bin file of the water meter terminal.
[0059] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit them; although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications can still be made to the specific implementation of the present invention or equivalent substitutions can be made to some technical features without departing from the spirit of the technical solutions of the present invention, and all such modifications and substitutions should be covered within the scope of the technical solutions claimed in the present invention.
Claims
1. A remote differential upgrade method that does not affect the metering of NB-IoT ultrasonic water meters, characterized in that, Includes the following steps: Obtain the upgrade configuration frame issued by the platform, verify the version compatibility, and perform local copying after successful verification, copying the corresponding data blocks in the old program area to the corresponding positions in the new program area; Request and receive differential data packets sequentially, and write them to the specified address in the new program area; After all data is received and verified, the water flow status is continuously monitored; When the instantaneous flow rate of water is detected to be zero or lower than the set threshold, a reset preparation flag is written to Flash and the system is triggered to reset. Among them, the upgrade configuration frame and differential data packet are generated by the platform side based on the old program bin file and the new program bin file of the water meter terminal.
2. The remote differential upgrade method for NB-IoT ultrasonic water metering without affecting the metering of the NB-IoT ultrasonic water meter according to claim 1, characterized in that, The steps for generating upgrade configuration frames and differential data packets include: Obtain the old program bin file and the new program bin file from the water meter, along with their corresponding version numbers and starting addresses in the Flash memory. Calculate the data length and verification of the new and old programs, and identify the same and different data parts between them through a binary comparison algorithm; Generate an upgrade configuration frame, which includes the version number of the new / old program, the starting address, the data length, the verification, the address and length information of the same data block, and the total number of differential data packets; Generate differential data packets, dividing the difference data portion into multiple data packets according to a preset packet length. Each packet contains the starting address, length, and binary content of the data block in the new program. If the data size of a configuration frame or a single differential data packet exceeds the communication protocol limit, it will be transmitted in packets.
3. The remote differential upgrade method for NB-IoT ultrasonic water metering without affecting the metering of the NB-IoT ultrasonic water meter according to claim 1, characterized in that: Write the reset preparation flag to Flash and trigger a system reset, including: After the bootloader starts, if a reset preparation flag is detected, it will be changed to an attempt to jump to a new application flag, and then the user will jump to the new application area. If the new application starts normally, the redirection to the new application will be changed to the successful redirection to the new application. If the new application is defective and fails to start, the watchdog will trigger a system reset; When the bootloader restarts, if it detects an attempt to jump to a new application, it determines that the previous upgrade jump failed and automatically jumps back to the old application area. After the old application starts, the identifier will be updated to the successful application redirection identifier, enabling an automatic and safe rollback.
4. A remote differential upgrade method for NB-IoT ultrasonic water metering without affecting the metering of any one of claims 1-3, characterized in that, The method also includes a task scheduling mechanism based on a hardware timer, specifically including: During system initialization, a hardware timer is configured to generate an interrupt signal with a fixed period. When a timer interrupt is triggered, the interrupt service routine is entered, and an atomic increment operation is performed on the system master clock counter, which serves as the system time reference. The task scheduler runs in the system's main loop, and each cycle task is independently configured with execution cycle parameters and a timestamp variable that records the last scheduling time. The scheduler continuously calculates the difference between the current system master clock counter and the timestamp of each task. When the difference is greater than or equal to the task execution cycle, the corresponding task is executed immediately. After the task is completed, update the timestamp variable of the task to the current system master clock counter value to reset its timing period; In this process, an ultrasonic measurement is performed immediately after initialization; in the upgrade process, an ultrasonic measurement is performed before reset.
5. The remote differential upgrade method for NB-IoT ultrasonic water metering without affecting the metering of the NB-IoT ultrasonic water meter according to claim 4, characterized in that, The method also includes a preemptive execution mechanism for metering tasks, specifically including: Configure the ultrasonic measurement interrupt to the highest hardware priority, and set the global measurement event pending flag in the interrupt service routine when a measurement event occurs. In the main loop's task scheduler, the metering event pending flag is checked first before any periodic task scheduling is performed. If the flag is detected to be set, the currently executing normal priority task will be immediately paused and the execution of the high-priority metering task will be switched to. Once the metering task is completed, the flag is cleared, and the task scheduler resumes the interrupted task according to a preset strategy.
6. The remote differential upgrade method for NB-IoT ultrasonic water metering without affecting the metering of the NB-IoT ultrasonic water meter according to claim 4, characterized in that, Set upgrade-related tasks such as local copying, network data reception, and Flash writing to the lowest priority; the task scheduler will execute them in order of priority from high to low. When the task scheduler reaches the lowest priority task queue, the network receiving task gets the first chance to execute. This task uses a fragmented receiving mechanism, receiving only data segments that do not exceed the capacity of the RAM buffer in each scheduling, and then actively suspending and updating the receiving state machine. This process is repeated until the complete data packet is received, and then the data packet is stored in the processing queue to wait for subsequent processing. When the scheduler reaches the local copy task, it parses the description information of the same data block from the upgrade configuration frame, including the source address, target address and data length; it reads data from the source address in units of Flash page size; before performing each page programming operation, it strictly checks the status of the metering event flag bit; after confirming that there are no pending metering events, it performs data writing; after completion, it immediately updates the address pointer and saves the operation context, and then suspends the task to wait for the next scheduling cycle to continue execution. Flash write tasks retrieve received differential data packets from the processing queue and decompose them into the smallest write units that conform to the physical characteristics of Flash. Each write unit must pass dual security verification before execution: first, the metering event pending flag is checked, and second, the target address is confirmed to be within the legal operation range. Page programming operations are performed under the premise of ensuring security, and the duration of a single programming operation must be strictly less than the maximum response time threshold for metering interruption specified by the system.
7. The remote differential upgrade method for NB-IoT ultrasonic water metering without affecting the metering of the NB-IoT ultrasonic water meter according to claim 6, characterized in that, Minimum data block size = min(Flash page size, system available buffer size, maximum safe size derived from the maximum allowed blocking time).
8. The remote differential upgrade method for NB-IoT ultrasonic water metering without affecting the metering of the NB-IoT ultrasonic water meter according to claim 6, characterized in that, After each atomic operation is completed, the system saves the current operation type, address pointer, remaining data length, checksum and other status information in real time. When the system detects that the metering event flag is set, it will immediately pause the upgrade task after completing the current smallest storage unit operation. The upgrade process will only be allowed to resume after the metering task is completed and no new events are generated in several consecutive scheduling cycles.
9. The remote differential upgrade method for NB-IoT ultrasonic water metering without affecting the metering of the NB-IoT ultrasonic water meter according to claim 4, characterized in that, If the upgrade process is interrupted due to network connection interruption, the ultrasonic water meter will record the sequence number of the last data packet that has been successfully received locally; after communication is restored and the connection with the platform is re-established, the ultrasonic water meter will report the sequence number as status information. After receiving the status information, the platform continues to send the remaining differential data starting from the next data packet of that sequence number.
10. A remote differential upgrade system that does not affect the metering of NB-IoT ultrasonic water meters, characterized in that, This includes a platform side and an NB-IoT ultrasonic water meter, wherein the platform side is used to send upgrade configuration frames to the NB-IoT ultrasonic water meter; The NB-IoT ultrasonic water meter verifies version compatibility and performs local copying after successful verification, copying the corresponding data blocks in the old program area to the corresponding positions in the new program area; it sequentially requests and receives differential data packets and writes them to the specified address in the new program area; after all data is received and verified, it continuously monitors the water flow status; when the instantaneous flow rate of the water is detected to be zero or lower than the set threshold, it writes the reset preparation flag to Flash and triggers the system reset; Among them, the upgrade configuration frame and differential data packet are generated by the platform side based on the old program bin file and the new program bin file of the water meter terminal.