Gateway data processing method and device, gateway and storage medium

By introducing target string parsing and dual-stack computing strategies into the gateway, the problems of low adaptation efficiency and high maintenance costs in multi-device data processing of the gateway are solved, realizing the configurability and universality of data processing, and improving device adaptation efficiency and system stability.

CN121814860APending Publication Date: 2026-04-07SHENZHEN SOFAR SOLAR
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511810263.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-03
Publication Date
2026-04-07

AI Technical Summary

Technical Problem

Existing gateways suffer from high adaptation workload and maintenance costs when processing data from multiple types of sub-devices. They are also unable to flexibly handle the needs of multiple device access and complex data processing, and cannot meet the requirements of scalability and universality in engineering sites.

Method used

By acquiring predefined target strings, and based on preset parsing and dual-stack computation strategies, unified parsing and flexible computation processing of raw data from multiple sources are achieved, including basic legality checks, rule parsing, data source acquisition, and dual-stack evaluation, thereby improving data adaptability and versatility.

Benefits of technology

It enables configurable and universal gateway data processing, significantly improves multi-device adaptation efficiency, reduces maintenance costs, and effectively addresses the problems of large differences in data formats and complex processing rules among different devices, meeting the high scalability and high flexibility requirements of energy management, smart grid and industrial monitoring scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121814860A_ABST
    Figure CN121814860A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of industrial Internet of Things data processing, and relates to a gateway data processing method and device, a gateway and a storage medium. A predefined target character string is used as a data processing rule carrier, and the character string is converted into a structured target element sequence based on an analysis strategy, so that processing logic describing different devices and different data items in a unified format is supported. The data source corresponding to the target element sequence is acquired, and the dual-stack calculation strategy is adopted to perform evaluation calculation on the target element sequence, so that the gateway can flexibly complete analysis, conversion and processing on various types of original data without depending on hard coding. Therefore, configurability and universalization of collected data processing logic are achieved, the multi-device adaptation efficiency is remarkably improved, the maintenance cost is reduced, and the problems that in the field, different device data formats are large in difference, and processing rules are complex can be effectively solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of industrial Internet of Things (IoT) data processing technology, specifically relating to a gateway data processing method, device, gateway, and storage medium. Background Technology

[0002] With the large-scale deployment of energy management, smart grids, and industrial monitoring systems, gateways, as the core data aggregation point on the field side, need to collect operational data from various types of sub-devices. Although most sub-devices communicate based on standard protocols such as Modbus, the data they report is often in a scaled or split raw form due to factors such as register design, storage structure, and industry standards. Furthermore, the data representation may differ between different devices and between different measurement items. In practical applications, data from some devices even needs to be processed through multiple register combinations or based on certain conditional relationships, making it impossible to directly use the field data as a valid physical quantity.

[0003] In the process of developing this application, the inventors discovered that the prior art has at least the following problems: Current gateways generally process collected data through hard coding or simple fixed parameters, which not only involves a large workload and high maintenance costs, but also makes it difficult to flexibly cope with the needs of multiple device access and complex data processing, and makes it difficult to meet the requirements of scalability and universality in engineering sites. Summary of the Invention

[0004] To address the aforementioned issues, this application provides a gateway data processing method, apparatus, gateway, and storage medium, enabling unified parsing and flexible computation processing of raw data from multiple sources, thereby improving the gateway's data adaptability and versatility.

[0005] To address the aforementioned technical problems, one technical solution adopted in this application is: providing a gateway data processing method, the method comprising: obtaining a predefined target string; performing rule parsing on the target string based on a preset parsing strategy to obtain a target element sequence; obtaining a data source corresponding to the target element sequence; and performing evaluation calculation on the target element sequence based on a preset dual-stack calculation strategy and the data source to obtain a target calculation result.

[0006] In some embodiments, obtaining a predefined target string includes: reading a rule string from a preset storage area; validating the rule string; and using the rule string as the target string when the rule string meets preset validation conditions.

[0007] In some embodiments, the target string is parsed according to a preset parsing strategy to obtain a target element sequence, including: parsing the target string according to a preset condition; wherein, the rule parsing includes: recognizing the current character of the target string to obtain state information corresponding to the current character, and obtaining element information corresponding to the state information according to the state information; and processing the element information to obtain the target element sequence.

[0008] In some embodiments, the status information includes a data source read status and an operator read status. Based on the status information, the element information corresponding to the status information is obtained, including: when the status information is a data source read status, taking the current character as the starting character, sequentially obtaining characters in the target string until a preset data source read status termination condition is met, and obtaining the data source element corresponding to the data source read status as element information; when the status information is an operator read status, taking the current character as the starting character, sequentially obtaining characters in the target string until a preset operator read status termination condition is met, and obtaining the operator element corresponding to the operator read status as element information.

[0009] In some embodiments, the target element sequence includes a data source identifier. Obtaining the data source corresponding to the target element sequence includes: when the data source identifier is a register variable identifier, obtaining the data source corresponding to the register variable identifier; when the data source identifier is a host computer-sent value identifier, obtaining the data source corresponding to the host computer-sent value identifier; when the data source identifier is a constant identifier, obtaining the data source corresponding to the constant identifier.

[0010] In some embodiments, the element information further includes bracket elements. Based on a preset dual-stack computation strategy and data source, the target element sequence is evaluated to obtain the target computation result, including: initializing a preset data stack and a preset operator stack based on the target element sequence; evaluating the target element sequence in a preset order; wherein the evaluation includes: when the element information is a data source element, writing the data source into the data stack; when the element information is an operator element, performing push control and pop operation processing on the operator element based on a preset operator priority strategy and operator stack; when the element information is a bracket element, performing push marking or pop evaluation operation on the subexpression boundary according to the bracket type corresponding to the bracket element; and obtaining the target computation result after the evaluation is completed.

[0011] To address the aforementioned technical problems, another technical solution adopted in this application is: providing a gateway data processing device, comprising: a target string acquisition module for acquiring a predefined target string; a rule parsing module for parsing the target string according to a preset parsing strategy to obtain a target element sequence; a data source acquisition module for acquiring a data source corresponding to the target element sequence; and a value calculation module for performing value calculation on the target element sequence based on a preset dual-stack calculation strategy and the data source to obtain a target calculation result.

[0012] To solve the above-mentioned technical problems, another technical solution adopted in the embodiments of this application is: to provide a gateway, including: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the above-mentioned method.

[0013] To solve the above-mentioned technical problems, another technical solution adopted in the embodiments of this application is: to provide a non-volatile computer-readable storage medium that stores computer-executable instructions, which, when executed by a gateway, cause the gateway to execute the above-mentioned method.

[0014] To solve the above-mentioned technical problems, another technical solution adopted in the embodiments of this application is: to provide a computer program product, the computer program product including a computer program stored on a non-volatile computer-readable storage medium, the computer program including program instructions, and when the program instructions are executed by the gateway, the gateway performs the above-mentioned method.

[0015] Unlike related technologies, this application provides a gateway data processing method, apparatus, gateway, and storage medium. By using a predefined target string as the carrier of data processing rules and transforming the string into a structured sequence of target elements based on a parsing strategy, it supports the description of processing logic for different devices and different data items in a unified format. By obtaining the data source corresponding to the target element sequence and employing a dual-stack computing strategy to evaluate the target element sequence, the gateway can flexibly complete the parsing, conversion, and processing of various types of raw data without relying on hard coding. Therefore, this application achieves configurability and universality of the acquired data processing logic, significantly improves multi-device adaptation efficiency, reduces maintenance costs, and effectively addresses issues such as large differences in data formats and complex processing rules among different devices in the field, meeting the needs of energy management, smart grids, and industrial monitoring scenarios for highly scalable and flexible data processing capabilities. Attached Figure Description

[0016] One or more embodiments are illustrated by way of example with reference to the accompanying drawings. These illustrations do not constitute a limitation on the embodiments. Elements having the same reference numerals in the drawings are denoted as similar elements. Unless otherwise stated, the figures in the drawings are not to be limited by scale.

[0017] Figure 1 This is a flowchart of a gateway data processing method provided in an embodiment of this application; Figure 2 This is a schematic diagram of the structure of a gateway data processing device provided in an embodiment of this application; Figure 3 This is a schematic diagram of the hardware structure of a gateway for executing a gateway data processing method according to an embodiment of this application. Detailed Implementation

[0018] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and thoroughly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.

[0019] It should be noted that, unless otherwise specified, the various features in the embodiments of this application can be combined with each other, all of which are within the protection scope of this application. Furthermore, although functional modules are divided in the device schematic diagram and a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device schematic diagram or the order in the flowchart.

[0020] Unless otherwise defined, all technical and scientific terms used in this specification have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the scope of this application.

[0021] Please see Figure 1 , Figure 1 This is a flowchart of a gateway data processing method provided in an embodiment of this application. Figure 1 As shown, the method includes steps S11-S14: S11: Get the predefined target string.

[0022] The process of obtaining a predefined target string includes: reading a rule string from a preset storage area; validating the rule string; and using the rule string as the target string when it meets preset validation conditions.

[0023] The gateway first loads the user-defined rule string from a preset storage area. This storage area can be a local non-volatile storage medium (such as EEPROM, Flash, or a rule configuration directory in a file system) used to permanently store the rule text issued by the user or debugging tools.

[0024] After successfully reading the rule string, a basic validity check is performed to ensure that it meets at least the most basic structural requirements, thereby avoiding obvious errors that could cause exceptions in subsequent parsing stages. This basic validity check is a security check in the pre-parsing stage and typically includes the following: Null value check: Determines whether the rule string is empty or consists only of whitespace characters to avoid invalid rules. Length threshold check: Checks whether the length of the rule string exceeds a preset security threshold to prevent risks such as stack overflow or timeouts caused by abnormal configurations or malicious input. Character set legality check: Verifies whether the rule string consists only of allowed characters, such as letters, numbers, square brackets "[ ]", curly braces "{}", parentheses "( )", and operator symbols "+ - * / <>=". If unknown characters or disallowed symbols (such as Chinese characters or control characters) are detected, they are determined to be illegal input. Preliminary structural check: Performs a quick count check on the brackets in the rule string to ensure that the number of left and right brackets is not significantly mismatched, reducing the probability of exceptions in the next stage of syntax parsing.

[0025] The aforementioned basic validity checks aim to filter out the most basic invalid inputs. For example, when the read rule string is (([@4361]{<}[0]){*}([0]{-}[value])){+}..., it will first be confirmed that the rule string is not empty, does not exceed the length limit, and all characters belong to the allowed character set. If all the above checks pass, this rule string is determined as the "target string" and is passed as input to the rule parsing process in step S12.

[0026] By performing the rule string reading and basic validity check in step S11 before rule parsing, it is possible not only to ensure that the obtained rule string is reliable and complete in format, but also to filter out basic errors such as empty strings, abnormal lengths, illegal character sets, and obvious unbalanced brackets in an early stage. This effectively avoids problems such as parsing failure, abnormal interruption, or uncertain calculation results when the parser processes invalid input. This step makes the overall rule calculation process more robust and fault-tolerant at the entry point, significantly improving the stability and maintainability of the system in actual deployment, and providing a pre-checked, structurally safe target string input for subsequent rule parsing and dual-stack evaluation, ensuring that the entire gateway data processing process can operate in a controllable and predictable environment.

[0027] S12: Based on the preset parsing strategy, perform rule parsing on the target string to obtain the target element sequence.

[0028] The process involves parsing the target string according to a preset parsing strategy to obtain a target element sequence. This includes parsing the target string according to a preset condition. The rule parsing process includes identifying the current character of the target string, obtaining the state information corresponding to the current character, and obtaining the element information corresponding to the state information based on the state information. The element information is then processed to obtain the target element sequence.

[0029] The status information includes the data source read status and the operator read status. Based on the status information, the element information corresponding to the status information is obtained, including: when the status information is the data source read status, the current character is used as the starting character, and the characters in the target string are obtained sequentially until the preset data source read status termination condition is met, and the data source element corresponding to the data source read status is obtained as the element information; when the status information is the operator read status, the current character is used as the starting character, and the characters in the target string are obtained sequentially until the preset operator read status termination condition is met, and the operator element corresponding to the operator read status is obtained as the element information.

[0030] In step S12, the target string obtained in step S11 is parsed character by character based on a preset parsing strategy to generate a sequence of target elements that can be executed by the subsequent computing engine. Specifically, the parsing process uses a finite state machine model as the parser, and identifies different semantic units in the target string through state switching and lexical analysis, converting them into structured element objects. This process includes the following: First, the parsing pointer is initialized, and "status information" is set to record the current parsing mode. This status information represents the semantic category of the current character, such as "data source read status," "operator read status," or "bracket recognition status." The parser starts from the first character of the target string and scans each character sequentially until the entire string has been traversed (i.e., the preset condition).

[0031] When a characteristic character indicating the start of a data source (such as "[") is detected, the parser switches to the data source reading state and uses the current character as the starting character of the data source fragment. The parser then continues to read subsequent characters until it encounters a predefined data source end character (such as "]", which is the preset data source reading state termination condition), thereby extracting the complete data source string. Examples include "[@4361]", "[value]", and "

[123] ". After extraction, the parser determines the type of the data source fragment (such as a register variable, a value sent from the host computer, or a constant) based on its content, constructs a "data source element" containing type information, the original text, and metadata required for subsequent calculations, and adds this element to the target element sequence.

[0032] When a non-data source character is detected that belongs to the operator character set (e.g., "+", "-", "*", "<", ">=", etc.), the parser switches its state to operator reading state. In this state, the current character is used as the starting character of the operator fragment, and reading continues until a character that no longer belongs to the current operator is encountered (i.e., the preset operator reading state termination condition is met), thus forming a complete operator element fragment (e.g., ">=", "<", "+", etc.). The parser then appends the corresponding priority information to the operator element according to the predefined operator priority table and adds it to the target element sequence.

[0033] When a bracket character, such as "(" or ")", is detected, the parser directly generates the corresponding bracket element and adds it to the target element sequence. Here, "(" indicates the start position of a subexpression, and ")" indicates the end position of a subexpression, and are used to trigger local priority processing in subsequent calculation stages. The bracket element also serves as a form of element information, its structure containing a type identifier and its semantic role in the expression structure.

[0034] During the process described above, the parser also performs necessary syntax checks, such as checking whether the number of parentheses matches, whether operands are missing around operators, and whether there are unknown characters or illegal combinations, to ensure the integrity and security of the parsing results.

[0035] Finally, after the parser has traversed the entire target string, it outputs an ordered, structured "sequence of target elements". Each element in this sequence contains its type (e.g., data source, operator, parentheses), the original string fragment, operator precedence, and other metadata information required for subsequent calculations. This sequence of target elements will serve as the direct input to the dual-stack computation strategy in step S14, ensuring that the computation engine can accurately reconstruct the user-defined computation logic based on the rule expression.

[0036] By employing a finite state machine-based parsing strategy, the target string is structurally parsed, precisely breaking down the user-defined rule expressions into executable sequences of target elements. This transforms the computational logic, which previously relied on manual coding, into configurable, interpretable, and verifiable rule data. During parsing, different semantic units such as data sources, operators, and parentheses are distinguished, and their types, priorities, and other metadata are appended. This step ensures that the semantic structure of complex expressions is fully preserved, providing clear and reliable input for subsequent computation engine execution. Simultaneously, the built-in syntax validity check mechanism in the parsing phase can detect issues such as mismatched parentheses, illegal characters, and unknown operators in advance, preventing erroneous rules from entering the computation phase and improving the overall system's stability and robustness. Based on this, step S12 enables the gateway to generalize and standardize dynamically configured rules, significantly improving the flexibility, maintainability, and scalability of the rules.

[0037] S13: Obtain the data source corresponding to the target element sequence.

[0038] The target element sequence includes a data source identifier. Obtaining the data source corresponding to the target element sequence includes: when the data source identifier is a register variable identifier, obtaining the data source corresponding to the register variable identifier; when the data source identifier is a host computer-sent value identifier, obtaining the data source corresponding to the host computer-sent value identifier; when the data source identifier is a constant identifier, obtaining the data source corresponding to the constant identifier.

[0039] In step S13, the target element sequence output in step S12 is used as input to identify the data source identifiers contained therein and obtain the actual values ​​from the corresponding data sources accordingly. Finally, the obtained values ​​are written to the runtime cache for subsequent evaluation. The "data source identifier" is a text marker in the target element sequence used to identify the source of operands. Its form is conventionally divided into three categories: register variable identifiers (e.g., "@4361" prefixed with "@", used to identify device register addresses or register mappings), host computer-issued value identifiers (e.g., "value" or other external input parameters identified by predefined keywords, representing runtime parameters issued by the host computer or external system), and constant identifiers (usually pure numeric strings, such as "0" or "123", representing immediate values ​​in expressions). First, the target element sequence is scanned to summarize all unique data source identifiers that appear and need to be obtained, forming a data source request list.

[0040] After forming the data source request list, different acquisition strategies are adopted based on the different semantics of various data source identifiers: For register variable identifiers, the identifier is mapped to the register address or register mapping entry of the underlying device, and a read request is initiated to the device communication module through an abstract data access interface; this abstract interface provides a unified read function prototype to the upper layer, such as read_register(device_id, register_addr, length, context), to support different device types and protocols. To improve communication efficiency and consistency, registers of the same device, with consecutive or similar addresses in the data source request list can be merged into a batch read operation, thereby reducing the number of messages and communication overhead; subsequently, the returned raw byte stream is parsed according to predefined register concatenation rules (such as big-endian / little-endian, word order, whether it is a 32-bit integer or floating-point), and sign extension or two's complement conversion is required to restore the signed value if necessary. For values ​​that need to be obtained by combining multiple registers (such as a 32-bit quantity composed of high and low words), after reading, the register values ​​are assembled into the target operand according to the rules, and the assembly logic is associated with the target element as metadata.

[0041] For values ​​assigned by the host computer, the corresponding values ​​are obtained through the host computer communication interface or the local runtime context. These values ​​may exist in the runtime parameter table or be passed in via a message queue / subscription mechanism. During retrieval, the validity and timeliness of the parameters must be verified. If a value is missing or expired, error handling is performed according to a preset strategy (e.g., using a default value, returning an error, or triggering a re-assignment request). For constant identifiers, their corresponding values ​​are directly used as operands without external reading, but type validation and boundary checks should still be performed to ensure that subsequent calculations do not result in anomalies.

[0042] During the actual reading process, the timestamp of each read should be recorded and the reading results written into a unified data cache structure. This cache is stored in a mapping form of "data source identifier → data item structure". Each data item structure contains the original value read, the parsed value, the read timestamp, the data validity flag, and necessary metadata information (such as source device identifier, register address, byte order information, etc.) so that step S14 can complete the calculation based on consistent data at the same acquisition time when evaluating. In addition, to ensure data consistency, before starting a rule evaluation, it should be ensured that all register values ​​required for this time have been read from the device and are in the same acquisition cycle. If some data is not yet ready, a blocking wait, asynchronous callback, or error return and retry strategy can be adopted. The specific fault tolerance strategy can be determined by the system configuration or engineering deployment.

[0043] In the event of communication anomalies, device timeouts, or data parsing failures, a pre-defined error handling procedure should be executed. This includes retrying the read (limited by the number of retries), logging errors, invalidating the corresponding cached item and returning an error code, or using a backup value (such as the last valid value or the default value) according to a policy. All error and retry information should be written to the operation log for subsequent troubleshooting. To improve system performance and avoid redundant work, duplicate requests are typically deduplicated and merged when forming the data source request list. Furthermore, when multiple rules require the same register, the read results are shared to avoid repeatedly issuing the same read operation.

[0044] For example, assuming the target element sequence contains three types of elements: [@4361], [value], and [0], the system will identify the register variable identifier @4361, the host computer-issued value identifier value, and the constant 0. Subsequently, the system initiates a read request for register 4361 to the device through the abstract data access interface, obtains the current value of value from the host computer communication channel, and directly writes the constant 0 as an immediate value to the cache. The original register value read is stored in the cache with the key @4361, and its entry contains the parsed value, read timestamp, and validity flag. In step S14, during dual-stack evaluation, the value corresponding to @4361 can be found in the cache and used in subsequent calculations.

[0045] By encoding rules such as "treating strings starting with @ as register variables," "treating fields identified by 'value' as data sent by the host computer in real time," and "treating pure numeric strings as fixed constants" into a unified data source parsing mechanism, step S13 can directly locate the corresponding actual data source based on the target element sequence without manual intervention. This allows the computing engine to promptly read the latest original register values, host-sent parameters in the current task context, and constant values ​​that do not require additional lookups. This mechanism not only avoids problems such as unclear data sources or inconsistent acquisition methods during the calculation phase but also reduces latency and resource consumption caused by repeated queries, making rule execution more efficient and stable. Furthermore, since the acquisition logic of the three types of data sources is explicitly separated and encapsulated into an extensible modular process, when new data source types (such as cached variables, environment parameters, etc.) need to be added in the future, it can be easily expanded while maintaining the overall structural stability, thereby improving the maintainability and scalability of the system. Based on this, step S13 ensures that the computing engine always performs calculations based on correct, timely, and clearly sourced data throughout the entire rule parsing and execution process, significantly enhancing the system's reliability, real-time performance, and engineering practicality.

[0046] S14: Based on the preset dual-stack calculation strategy and data source, perform evaluation calculation on the target element sequence to obtain the target calculation result.

[0047] The element information also includes bracket elements. Based on a preset dual-stack calculation strategy and data source, the target element sequence is evaluated to obtain the target calculation result. This includes: initializing a preset data stack and a preset operator stack based on the target element sequence; evaluating the target element sequence according to a preset order; wherein the evaluation calculation includes: when the element information is a data source element, writing the data source to the data stack; when the element information is an operator element, performing push control and pop operation processing on the operator element based on a preset operator priority strategy and operator stack; when the element information is a bracket element, performing push marking or pop evaluation operation on the subexpression boundary according to the bracket type corresponding to the bracket element; and obtaining the target calculation result after the evaluation calculation is completed.

[0048] After receiving the target element sequence from step S12 and the data source cache from step S13, the computing engine starts the evaluation process based on the preset dual-stack computing strategy.

[0049] First, initialization is performed, which involves creating and clearing two LIFO stack structures: a data stack (used to store operand values ​​in the order of calculation, operands can be values ​​read from registers, values ​​sent from the host computer, or constants) and an operator stack (used to store operators and control characters such as left parentheses, so that the timing of the operation can be determined according to the priority and parenthesis boundaries, and at the same time, the operator priority table and arithmetic unit metadata (including the associativity of the operator, the number of operands required, and the corresponding calculation function) are loaded).

[0050] Then, the target element sequence is traversed sequentially: if the current element is a data source element, the corresponding value is retrieved from the cache of step S13 through the abstract data acquisition interface (type conversion or missing detection is performed if necessary), and the value is pushed onto the data stack; if the current element is an operator element, the operator priority is compared with the priority of the operator at the top of the operator stack according to the operator priority table, and associativity is considered: as long as the priority of the operator at the top of the stack is not lower than that of the current operator (and the associativity rule is satisfied), that is, the operator is popped from the operator stack in a loop, and the corresponding number of operands are popped from the data stack (two operands are popped from a binary operator, and one operand is popped from a unary operator), the calculation function is executed according to the arithmetic unit meta-information, and the intermediate result is pushed back onto the data stack until the pop condition is no longer met, and then the current operator is pushed onto the operator stack; if the current element is a left parenthesis element, the left parenthesis is directly pushed onto the operator stack to mark the starting point of the subexpression; if the current element is a right parenthesis element, the pop calculation is performed in a loop (as described above) until a left parenthesis is encountered and popped and discarded, thereby completing the evaluation of the subexpression defined by the parentheses.

[0051] After the traversal is complete, if there are still operators in the operator stack, they are popped one by one and the remaining operations are performed in the same way as described above until the operator stack is empty. Throughout the process, the calculation engine needs to detect and handle several abnormal situations, including but not limited to: stack underflow caused by popping data stack (indicating expression syntax or runtime error), failure to find left parenthesis in the expected position of operator stack (indicating parenthesis mismatch), incompatible operand types, or invalid values ​​read from the cache. When an exception is encountered, fault tolerance should be handled according to the system policy (e.g., logging the error, using the default value, or terminating the current evaluation and returning an error code).

[0052] After all calculations are completed, check that there is only one item left in the data stack. This item is the target calculation result (the final expression value). If there is more than one item in the data stack, it is considered that the expression evaluation is incorrect and the corresponding error process is triggered. For example, for the expression (([@4361]<[0])*([0]-[value]))+(([@4361]>=[0])*[value]), assuming that @4361 = -1, value = 5, and constant [0] = 0 in the cache, when traversing and executing, -1 and 0 are pushed onto the data stack in sequence. When < is encountered, the comparison operation is triggered, which is true (which can be represented by 1) and pushed onto the data stack. Then, when * is encountered, it is combined with the right sub-expression to calculate (1 *(0 - 5)) = -5. The right sub-expression is calculated in the same way to get (0 * 5) = 0. The sum of the two sides results in the final value of -5 remaining in the data stack, which is the target calculation result. The entire S14 process ensures the correct handling of operator precedence and parenthesis boundaries, ensuring that the semantics of complex expressions (including nesting, conditional judgments, and multi-register combinations) are executed accurately. At the same time, it combines exception detection and fault tolerance strategies to improve the robustness of evaluation and engineering usability.

[0053] By introducing a dual-stack computation strategy based on a data stack and an operator stack, the evaluation process of regular expressions can be carried out under strict adherence to operator precedence, parenthesis boundaries, and operational reduction rules, thereby ensuring the accuracy and consistency of the evaluation results. The dual-stack mechanism enables hierarchical management of operands and operators during the traversal of the target element sequence, ensuring that high-priority operations (such as multiplication and comparison operations) are executed early at the correct time, while low-priority operations (such as addition and subtraction) are executed sequentially, effectively avoiding computation order errors that may occur with traditional linear scanning methods. Simultaneously, through the handling of pushing and popping parenthesis elements onto and off the stack, this strategy can accurately identify and solve nested sub-expressions of any level, ensuring that the evaluation logic remains stable and reliable even as the complexity of the expression structure increases. Furthermore, by dynamically extracting operands from the data source cache, regular expressions can be evaluated in real time at runtime by combining different register values, values ​​sent from the host computer, or constants, achieving high flexibility in rule computation across different device scenarios. In conjunction with anomaly detection mechanisms (such as stack underflow, mismatched brackets, invalid data, etc.), this step further enhances the robustness of the evaluation engine, enabling the gateway to maintain high reliability even when faced with complex computational logic. This effectively solves problems such as disordered expression calculation order, difficulty in correctly executing complex rules, and difficulty in locating runtime errors in the background technology.

[0054] It should be noted that the gateway data processing method provided in this application has good scalability on the existing basis, especially in terms of rule calculation capabilities. Current calculation rules mainly support standard operators (such as addition, subtraction, multiplication, division, comparison, etc.) for expression evaluation, but can be further extended to support custom formulas or unary operators, such as introducing operations like absolute value, negation, integer division, square root, and trigonometric functions. Specifically, this can be achieved by adding newly defined unary operators and corresponding calculation logic functions to the operator table, and adding recognition and execution rules for unary operators to the dual-stack evaluation strategy. This allows the calculation engine to automatically process the new formulas during the parsing and evaluation stages, thus achieving richer calculation functions without modifying the original rule expression structure. This extension mechanism not only enhances the rule expression capability and the flexibility of the expression, but also improves the gateway's adaptability and engineering practicality in handling diverse data calculation scenarios, providing a reliable technical foundation for subsequent customized calculations for specific businesses or special devices.

[0055] This application provides a gateway data processing method. By introducing a clearly structured and hierarchical processing flow of "basic legality verification—rule parsing—data source acquisition—dual-stack evaluation," the gateway can complete the calculation and processing of complex rule strings with high reliability, high accuracy, and high real-time performance. First, basic legality verification can filter out explicit errors such as empty strings, illegal characters, and input anomalies before the data enters formal parsing, avoiding invalid calculations and anomaly propagation at the source. Second, the rule parsing process uses a finite state machine to identify the expression structure character by character, transforming the original string into a sequence of target elements with semantic information such as type and priority, making the structured processing of expressions more standardized and automated. Subsequently, the data source acquisition stage can accurately extract the real data in the current execution context based on register variable identifiers, host computer-issued value identifiers, or constant identifiers, providing reliable input for the evaluation process. Finally, the dual-stack calculation strategy can ensure that the evaluation process strictly follows operator priority and bracket rules, maintaining the correct calculation order and consistent results even when processing multi-level nested expressions and multi-operator combinations, providing stable computing power for complex business logic. Through the aforementioned collaborative mechanism, this method effectively solves problems such as difficulty in parsing string expressions, error-prone calculation order, inconsistent data reading, and unreliable rule execution, significantly improving the correctness, robustness, and processing efficiency of the gateway when performing rule calculations, linkage logic judgments, and device data processing at the edge.

[0056] Based on the gateway data processing method provided in the above embodiments, this application further provides a gateway data processing apparatus. Please refer to... Figure 2 , Figure 2 This is a schematic diagram of the gateway data processing device. (For example...) Figure 2 As shown, the gateway data processing device 100 includes: a target string acquisition module 110, a rule parsing module 120, a data source acquisition module 130, and a value calculation module 140.

[0057] The target string acquisition module 110 is used to acquire a predefined target string; the rule parsing module 120 is used to perform rule parsing on the target string based on a preset parsing strategy to obtain a target element sequence; the data source acquisition module 130 is used to acquire a data source corresponding to the target element sequence; and the evaluation calculation module 140 is used to perform evaluation calculation on the target element sequence based on a preset dual-stack calculation strategy and the data source to obtain a target calculation result.

[0058] It should be noted that the aforementioned gateway data processing device can execute the gateway data processing method provided in the embodiments of this application, and has the corresponding functional modules and beneficial effects of the method. Technical details not described in detail in the gateway data processing device embodiments can be found in the gateway data processing method provided in the embodiments of this application.

[0059] This application also provides a gateway 200, please refer to... Figure 3 This diagram illustrates the hardware structure of a gateway 200 capable of executing the methods described in the above embodiments. The gateway 200 includes: at least one processor 210; and a memory 220 communicatively connected to the at least one processor 210. Figure 3 Taking a processor 210 as an example, the memory 220 stores instructions executable by the at least one processor 210. These instructions, when executed by the at least one processor 210, enable the at least one processor 210 to perform the gateway data processing method described in the above embodiment. The processor 210 and the memory 220 can be connected via a bus or other means. Figure 3 Taking the example of a connection between China and Israel via a bus.

[0060] The memory 220, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules, such as the program instructions / modules corresponding to the gateway data processing method in the embodiments of this application. The processor 210 executes various functional applications and data processing of the server by running the non-volatile software programs, instructions, and modules stored in the memory 220, thereby implementing the gateway data processing method described in the above embodiments.

[0061] Memory 220 may include a stored program area and a stored data area, wherein the stored program area may store the operating system and applications required for at least one function; the stored data area may store data created based on the use of the computing device, etc. Furthermore, memory 220 may include high-speed random access memory and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other non-volatile solid-state storage device. In some embodiments, memory 220 may optionally include memory remotely located relative to processor 210, and these remote memories may be connected to the computing device via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.

[0062] The one or more modules are stored in the memory 220, and when executed by the one or more processors 210, they perform the gateway data processing method described in the above embodiments.

[0063] The above-described product can execute the methods provided in the embodiments of this application, and has the corresponding functional modules and beneficial effects for executing the methods. Technical details not described in detail in this embodiment can be found in the gateway data processing method described in the embodiments of this application.

[0064] This application provides a non-volatile computer-readable storage medium storing computer-executable instructions. These instructions are executed by one or more processors to enable the at least one processor to perform the gateway data processing method described in the above embodiments. For example, the non-volatile computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a compact disc read-only memory (CDROM), magnetic tape, floppy disk, or optical data storage device, etc.

[0065] This application provides a computer program product, which includes a computer program stored on a non-volatile computer-readable storage medium. The computer program includes program instructions, which, when executed by a gateway, enable the gateway to perform the gateway data processing method in any of the above method embodiments.

[0066] It should be noted that the device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.

[0067] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of this application.

[0068] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and not to limit them; under the concept of this application, the technical features of the above embodiments or different embodiments can also be combined, the steps can be implemented in any order, and there are many other variations of different aspects of this application as described above, which are not provided in detail for the sake of brevity; although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.

Claims

1. A gateway data processing method, characterized in that, The method includes: Get the predefined target string; Based on a preset parsing strategy, the target string is parsed according to rules to obtain a sequence of target elements; Obtain the data source corresponding to the target element sequence; Based on the preset dual-stack computing strategy and the data source, the target element sequence is evaluated to obtain the target calculation result.

2. The gateway data processing method according to claim 1, characterized in that, The step of obtaining the predefined target string includes: Read the rule string from the preset storage area; The rule string is validated; When the rule string meets the preset verification conditions, the rule string is used as the target string.

3. The gateway data processing method according to claim 1, characterized in that, The target string is parsed according to a preset parsing strategy to obtain a sequence of target elements, including: The target string is parsed according to rules until the preset conditions are met; The rule parsing includes: identifying the current character of the target string, obtaining state information corresponding to the current character, and obtaining element information corresponding to the state information based on the state information; The element information is processed to obtain the target element sequence.

4. The gateway data processing method according to claim 3, characterized in that, The status information includes the data source read status and the operator read status. The step of obtaining element information corresponding to the state information based on the state information includes: When the status information is the data source reading status, the current character is used as the starting character, and the characters in the target string are obtained sequentially until the preset data source reading status termination condition is met, and the data source element corresponding to the data source reading status is obtained as the element information. When the status information is the operator reading state, the current character is used as the starting character, and the characters in the target string are obtained sequentially until the preset operator reading state termination condition is met, and the operator element corresponding to the operator reading state is obtained as the element information.

5. The gateway data processing method according to claim 4, characterized in that, The target element sequence includes a data source identifier, and obtaining the data source corresponding to the target element sequence includes: When the data source identifier is a register variable identifier, obtain the data source corresponding to the register variable identifier; When the data source is identified as a value identifier sent by the host computer, the data source corresponding to the value identifier sent by the host computer is obtained; When the data source identifier is a constant identifier, the data source corresponding to the constant identifier is obtained.

6. The gateway data processing method according to claim 5, characterized in that, The element information also includes bracket elements. The method, based on a preset dual-stack computing strategy and the data source, performs evaluation calculations on the target element sequence to obtain the target calculation result, including: Based on the target element sequence, initialize a preset data stack and a preset operator stack; The target element sequence is evaluated and calculated according to a preset order; The evaluation calculation includes: When the element information is the data source element, the data source is written into the data stack; When the element information is the operator element, the operator element is pushed onto the stack and popped from the stack based on the preset operator priority strategy and the operator stack. When the element information is the bracket element, perform a push-to-stack marking or pop-to-stack evaluation operation on the subexpression boundary according to the bracket type corresponding to the bracket element; After the evaluation calculation is completed, the target calculation result is obtained.

7. A gateway data processing device, characterized in that, The device includes: A target string acquisition module, which is used to acquire a predefined target string; The rule parsing module is used to parse the target string according to a preset parsing strategy to obtain a target element sequence; A data source acquisition module, which is used to acquire a data source corresponding to the target element sequence; The evaluation calculation module is used to perform evaluation calculations on the target element sequence based on a preset dual-stack calculation strategy and the data source to obtain the target calculation result.

8. A gateway, characterized in that, include: At least one processor; as well as, A memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, which, when executed by the at least one processor, enables the at least one processor to perform the method according to any one of claims 1-6.

9. A non-volatile computer-readable storage medium, characterized in that, The non-volatile computer-readable storage medium stores computer-executable instructions that, when executed by the gateway, cause the gateway to perform the method described in any one of claims 1-6.

10. A computer program product, characterized in that, The computer program product includes a computer program stored on a non-volatile computer-readable storage medium, the computer program including program instructions that, when executed by a gateway, cause the gateway to perform the method according to any one of claims 1-6.