Data Communication Method, Device, System, Equipment and Medium for Embedded Software
By analyzing and querying multi-level command tables, the flexibility and efficient data communication of the lower computer software are achieved, and the resource waste and maintenance complexity problems caused by repeated development are solved.
Patent Information
- Application Number
- CN202510515192.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-23
- Publication Date
- 2025-07-22
- Estimated Expiration
- 2045-04-23
AI Technical Summary
In the prior art, the lower computer software with the same functions needs to be repeatedly developed, resulting in waste of resources and increased software maintenance complexity.
By analyzing the received communication frames, a multi-level command combination is obtained, and a hierarchical query is performed in the pre-established multi-level command table. The multi-level command table is used to standardize the storage of different hierarchical commands, and it depends on the functions implemented by the chip rather than the specific chip, and accurately locates the callback function through the multi-level command combination.
Reduces the complexity of software maintenance, improves the flexibility of the lower computer software, and avoids repeated development operations for the same functions.
Smart Images

Figure CN120045249B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of embedded software technology, and particularly to a data communication method, device, system, equipment and medium for embedded software. Background Art
[0002] In the design of embedded software, the lower computer software system is responsible for tasks such as underlying data acquisition and control execution, and needs to communicate with the upper computer to achieve more complex functions. Usually, polling or state machine switching is used to implement the data communication process with the upper computer.
[0003] As the basis for the operation of the lower computer software, the chip provides basic computing, storage capabilities, and various interface resources. Considering that different chips adopt different architectures and instruction sets, it is usually necessary to design the lower computer software separately to achieve different data communications. However, in the complex technical environment of the chip production and quality inspection system, although there are certain functional differences among multiple chips in the same series, most of the functions are the same. This means that the lower computer software needs to perform repetitive development operations for the same functions, resulting in a waste of development resources and increasing the complexity of software maintenance. Summary of the Invention
[0004] In view of this, this application provides a data communication method, device, system, equipment and medium for embedded software, mainly aiming to solve the problem that repetitive development operations for the same functions in the prior art will cause a waste of development resources and increase the complexity of software maintenance.
[0005] In the first aspect, a data communication method for embedded software is provided, including:
[0006] When receiving a communication frame sent by the upper computer, parsing the communication frame to obtain a multi-level command combination, where the multi-level command combination is obtained by selecting a command combination at each level according to the command hierarchy structure;
[0007] Performing hierarchical query in a pre-established multi-level command table according to the multi-level command combination to obtain a callback function corresponding to the lowest-level command. The multi-level command table includes command tables at different levels constructed according to the command hierarchy structure. The non-lowest-level commands are used as indexes to query the command table at the next level in the command table at the current level, and the lowest-level command is used to query the callback function;
[0008] Passing a preset pointer pointing to the communication frame as a parameter to the callback function, so that the callback function determines a lower computer call function through the preset pointer, and initiates data communication according to the lower computer call function.
[0009] Further, parsing the communication frame to obtain a multi-level command combination includes:
[0010] Determine the field area of the multi-level command in the communication frame according to the frame structure specified by the protocol;
[0011] Decode the command fields of each level in the communication frame according to the field area of the multi-level command to obtain the multi-level command and the logical relationship between the multi-level commands;
[0012] Process the multi-level command by using the logical relationship between the multi-level commands to obtain a multi-level command combination.
[0013] Further, the decoding the command fields of each level in the communication frame according to the field area of the multi-level command to obtain the multi-level command and the logical relationship between the multi-level commands includes:
[0014] Identify the field identification bit of the first-level command in the communication frame according to the field area of the multi-level command, and decode the command field of the first level in the communication frame through the field identification bit of the first-level command to obtain the first-level command;
[0015] On the basis of the first-level command, determine the command field identification bit of the next level in the communication frame, and decode the command field of the next level in the communication frame through the command field identification bit of the next level to obtain the next-level command;
[0016] On the basis of the next-level command, decode the command fields of each level in turn until the command field of the lowest level, and record the association between the commands of each level during the process of decoding the command fields of each level to obtain the multi-level command and the logical relationship between the multi-level commands.
[0017] Further, before performing a hierarchical query in a pre-established multi-level command table according to the multi-level command combination to obtain the callback function corresponding to the lowest-level command, the method further includes:
[0018] Decompose the functions of the embedded software system into multi-level commands;
[0019] Construct command tables of different levels according to the multi-level commands. The command table of the lowest level is constructed according to the lowest-level command and the callback function corresponding to the lowest-level command, and the command tables of non-lowest levels are constructed according to the non-lowest-level commands;
[0020] The command tables of different levels are hierarchically bound with the multi-level commands in the order from the lowest level command to the highest level command to obtain a multi-level command table. During the hierarchical binding process, the command table of the current level is bound to the command of the previous level using the command of the previous level as an index until the highest level command is reached.
[0021] Further, after hierarchically binding the command tables of different levels with the multi-level commands in the order from the lowest level command to the highest level command, the method further includes:
[0022] In the process of hierarchical binding, the binding relationship between the command tables of different hierarchies and the commands of the previous hierarchical level is recorded;
[0023] When the binding relationship changes, the binding relationship between the command table of the corresponding level and the command of the previous level is released, and the command table of the corresponding level is bound to the updated command of the previous level using the updated command of the previous level as an index to update the binding relationship between the command table and the command in the multi-level command table.
[0024] Further, the multi-level command set includes a main command set and a sub-command set, the main command is a non-lowest level command, the sub-command is a lowest level command, and the multi-level command table includes a main command table and a sub-command table;
[0025] Accordingly, the functions of the embedded software system are decomposed into primary commands and secondary commands;
[0026] Constructing a secondary command table and a main command table respectively, wherein the secondary command table is constructed according to the secondary command and the callback function corresponding to the secondary command, and the main command table is constructed according to the main command;
[0027] The secondary command table is bound to the primary command using the primary command as an index to obtain a multi-level command table.
[0028] Furthermore, the lowest level command is stored through a first setting structure, which at least includes a lowest level command field, a callback function pointer variable, and a reserved field; the lowest level command table is stored through a second setting structure, which at least includes a pointer variable of the lowest level command, a command quantity field, a command description field, and a reserved field; the non-lowest level command table is stored through a third setting structure, which at least includes a pointer variable of the non-lowest level command, a command quantity field, a command description field, and a reserved field.
[0029] Further, performing a hierarchical query in a pre-established multi-level command table according to the multi-level command combination to obtain a callback function corresponding to the lowest-level command includes:
[0030] Perform a hierarchical query in a pre-established multi-level command table according to the multi-level command combination, in the order from the highest-level command to the lowest-level command;
[0031] During the hierarchical query, use the current-level command as an index to query in the command table of the current level to obtain the command table of the next level, until the callback function corresponding to the lowest-level command is obtained by querying in the command table of the lowest level using the lowest-level command.
[0032] Furthermore, the multi-level command combination includes a main command and a secondary command. The main command is a non-lowest-level command, and the secondary command is the lowest-level command. The multi-level command table includes a main command table and a secondary command table;
[0033] Correspondingly, when receiving a communication frame sent by the host computer, parse the communication frame to obtain the main command and the secondary command;
[0034] Use the main command as an index to query in the main command table to obtain the secondary command table;
[0035] Query according to the secondary command in the secondary command table to obtain the callback function corresponding to the secondary command.
[0036] In a second aspect, a data communication system for embedded software is provided, including: an application layer, a system layer, an adaptation layer, and a resource library;
[0037] The application layer is used to construct a command table of the lowest level, and hierarchically bind the command table of the lowest level through the exposed pointer method, so that command tables of multiple levels are coupled to obtain a multi-level command table;
[0038] The system layer calls the resource library to store the multi-level command table in the resource library;
[0039] When receiving a communication frame sent by the host computer, the system layer calls the adaptation layer to parse the communication frame, and hierarchically query in the multi-level command table in the resource library according to the multi-level command combination obtained by parsing, to obtain the callback function corresponding to the lowest-level command;
[0040] The system layer initiates data communication with the host computer according to the callback function.
[0041] In a third aspect, a data communication device for embedded software is provided, including:
[0042] A parsing unit, configured to parse the communication frame when receiving a communication frame sent by the host computer to obtain a multi-level command combination, where the multi-level command combination is obtained by selecting one command combination at each level according to the command hierarchical structure;
[0043] A query unit, configured to perform hierarchical query in a pre-established multi-level command table according to the multi-level command combination, so as to obtain a callback function corresponding to the lowest-level command. The multi-level command table includes command tables of different levels constructed according to a command hierarchical structure. A non-lowest-level command serves as an index for querying a command table of the next level in the command table of the current level, and the lowest-level command is used to query the callback function;
[0044] A communication unit, configured to pass a preset pointer pointing to the communication frame as a parameter to the callback function, so that the callback function determines a lower-level machine call function through the preset pointer and initiates data communication according to the lower-level machine call function.
[0045] Further, the parsing unit is specifically configured to:
[0046] Determine a field area of a multi-level command in the communication frame according to a frame structure specified by a protocol;
[0047] Decode command fields of each level in the communication frame according to the field area of the multi-level command to obtain the multi-level command and the logical relationship between the multi-level commands;
[0048] Process the multi-level command by using the logical relationship between the multi-level commands to obtain a multi-level command combination.
[0049] Further, the parsing unit is specifically further configured to:
[0050] Identify a field identification bit of a first-level command in the communication frame according to the field area of the multi-level command, so as to decode the command field of the first level in the communication frame through the field identification bit of the first-level command to obtain the first-level command;
[0051] Based on the first-level command, determine a command field identification bit of the next level in the communication frame, so as to decode the command field of the next level in the communication frame through the command field identification bit of the next level to obtain the next-level command;
[0052] Based on the next-level command, decode the command fields of each level in sequence until the command field of the lowest level, and record the association between the commands of each level during the process of decoding the command fields of each level to obtain the multi-level command and the logical relationship between the multi-level commands.
[0053] Further, the device further includes:
[0054] A disassembling unit, configured to disassemble the functions of the embedded software system into multi-level commands before performing a hierarchical query in a pre-established multi-level command table according to the multi-level command combination to obtain a callback function corresponding to the lowest-level command;
[0055] A construction unit, configured to construct command tables of different levels according to the multi-level commands, wherein the command table of the lowest level is constructed according to the lowest level command and the callback function corresponding to the lowest level command, and the command table of the non-lowest level is constructed according to the non-lowest level command;
[0056] A binding unit is used to hierarchically bind the command tables of different levels with the multi-level commands in the order from the lowest level command to the highest level command to obtain a multi-level command table. During the hierarchical binding process, the command table of the current level is bound to the command of the previous level using the command of the previous level as an index until the highest level command is reached.
[0057] Furthermore, the device also includes:
[0058] a recording unit, configured to record the binding relationship between the command tables of different levels and the commands of a previous level in the process of hierarchical binding after the command tables of different levels are hierarchically bound with the multi-level commands in the order from the lowest level command to the highest level command;
[0059] An updating unit is used to release the binding relationship between the command table of the corresponding level and the command of the previous level when the binding relationship changes, and use the updated command of the previous level as an index to bind the command table of the corresponding level to the updated command of the previous level, so as to update the binding relationship between the command table and the command in the multi-level command table.
[0060] Further, the multi-level command includes a main command and a sub-command, the main command is a non-lowest level command, the sub-command is a lowest level command, and the multi-level command table includes a main command table and a sub-command table;
[0061] Accordingly, the disassembly unit is specifically used to disassemble the functions of the embedded software system into main commands and secondary commands;
[0062] The construction unit is specifically used to construct a secondary command table and a main command table respectively, wherein the secondary command table is constructed according to the secondary commands and the callback functions corresponding to the secondary commands, and the main command table is constructed according to the main commands;
[0063] The binding unit is specifically used to bind the secondary command table to the primary command using the primary command as an index to obtain a multi-level command table.
[0064] Further, the lowest-level command is stored through a first setting structure, and the first setting structure at least includes a lowest-level command field, a callback function pointer variable, and a reserved field; the command table of the lowest level is stored through a second setting structure, and the second setting structure at least includes a pointer variable of the lowest-level command, a command quantity field, a command description field, and a reserved field; the command table of the non-lowest level is stored through a third setting structure, and the third setting structure at least includes a pointer variable of the non-lowest-level command, a command quantity field, a command description field, and a reserved field.
[0065] Further, the query unit is specifically configured to:
[0066] Perform hierarchical query in a pre-established multi-level command table according to the multi-level command combination in the order from the highest-level command to the lowest-level command;
[0067] During the hierarchical query process, use the current-level command as an index to query in the command table of the current level to obtain the command table of the next level until the callback function corresponding to the lowest-level command is obtained by querying in the command table of the lowest level using the lowest-level command.
[0068] Further, the multi-level command combination includes a main command and a secondary command, the main command is a non-lowest-level command, the secondary command is a lowest-level command, and the multi-level command table includes a main command table and a secondary command table;
[0069] Correspondingly, the parsing unit is specifically configured to parse the communication frame to obtain the main command and the secondary command when receiving a communication frame sent by the host computer;
[0070] The query unit is specifically further configured to:
[0071] Use the main command as an index to query in the main command table to obtain the secondary command table;
[0072] Query according to the secondary command in the secondary command table to obtain the callback function corresponding to the secondary command.
[0073] In a fourth aspect, a computer device is provided, including a memory and a processor, where the memory stores a computer program, and when the processor executes the computer program, the steps of the method described in the first aspect above are implemented.
[0074] In a fifth aspect, a readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the method described in the first aspect above are implemented.
[0075] With the above technical solution, a data communication method, device, system, equipment, and medium for embedded software provided by this application, compared with the existing technology that realizes the data communication method of embedded software through the repeated development of the lower computer software for the same function, when this application receives a communication frame sent by the upper computer, it parses the communication frame to obtain a multi-level command combination, and the multi-level command combination is obtained by selecting a command combination at each level according to the command hierarchy structure; perform hierarchical query in a pre-established multi-level command table according to the multi-level command combination to obtain the callback function corresponding to the lowest-level command. The multi-level command table includes command tables at different levels constructed according to the command hierarchy structure. The non-lowest-level commands are used as indexes to query the command table at the next level in the command table at the current level, and the lowest-level commands are used to query the callback function; pass the preset pointer pointing to the communication frame as a parameter to the callback function, so that the callback function determines the lower computer call function through the preset pointer, and initiates data communication with the upper computer according to the lower computer call function. The whole process standardizes and stores different-level commands through a multi-level command table, so that the commands do not depend on specific chips, but on the functions implemented by the chips, avoiding repeated development operations for the same function. In this way, the lower computer software can transfer the function development to the multi-level command table, and accurately locate the callback functions of different functions through the multi-level command combination, making the lower computer software more flexible and reducing the software maintenance complexity.
[0076] The above description is only an overview of the technical solution of this application. In order to be able to understand the technical means of this application more clearly, it can be implemented according to the content of the specification. And in order to make the above and other purposes, features, and advantages of this application more obvious and understandable, the specific implementation manners of this application are specifically exemplified below. Brief Description of the Drawings
[0077] The drawings described herein are used to provide a further understanding of this application, and constitute a part of this application. The schematic embodiments of this application and their descriptions are used to explain this application and do not constitute an improper limitation to this application. In the drawings:
[0078] Figure 1 is a schematic flowchart of the data communication method of embedded software in an embodiment of this application;
[0079] Figure 2 is Figure 1 a schematic flowchart of a specific implementation manner of step 101 in
[0080] Figure 3 is a schematic flowchart of the data communication method of embedded software in another embodiment of this application;
[0081] Figure 4 is a schematic flowchart of the data communication method of embedded software in another embodiment of this application;
[0082] Figure 5 Yes Figure 1 It is a schematic flowchart of a specific implementation manner of step 102 in
[0083] Figure 6 It is a schematic flowchart of a data communication method for embedded software in another embodiment of the present application;
[0084] Figure 7 It is a schematic diagram of a command hierarchical structure in an embodiment of the present application;
[0085] Figure 8 It is a schematic flowchart of using a command hierarchical structure for data communication in an embodiment of the present application;
[0086] Figure 9 It is a schematic diagram of the structure of a data communication system for embedded software in an embodiment of the present application;
[0087] Figure 10 It is a schematic diagram of the structure of a data communication device for embedded software in an embodiment of the present application;
[0088] Figure 11 It is a schematic diagram of the device structure of a computer device provided by an embodiment of the present invention. Specific implementation manner
[0089] Now, the content of the present invention will be discussed with reference to several exemplary embodiments. It should be understood that discussing these embodiments is only to enable those of ordinary skill in the art to better understand and thus implement the content of the present invention, rather than implying any limitation to the scope of the present invention.
[0090] As used herein, the term "comprising" and its variants are to be interpreted as open-ended terms meaning "including but not limited to". The term "based on" is to be interpreted as "at least partially based on". The terms "one embodiment" and "an embodiment" are to be interpreted as "at least one embodiment". The term "another embodiment" is to be interpreted as "at least one other embodiment".
[0091] In the related art, as the basis for the operation of the lower computer software, the chip provides basic computing, storage capabilities, and various interface resources. Considering that different chips adopt different architectures and instruction sets, it is usually necessary to separately design the lower computer software to implement different data communications. However, in the complex technical environment of the chip production and quality inspection system, although there are certain functional differences among multiple chips in the same series, the vast majority of functions are the same, which means that the lower computer software needs to perform repetitive development operations for the same functions, resulting in a waste of development resources and increasing the complexity of software maintenance.
[0092] To solve this problem, this embodiment provides a data communication method for embedded software, as Figure 1 shown, which includes the following steps:
[0093] 101. When receiving a communication frame sent by the host computer, parse the communication frame to obtain a multi-level command combination.
[0094] In the design of embedded software, the lower computer and the host computer are connected through a communication interface, and the same communication protocol needs to be used for transmitting communication frames. The communication frame is used as a carrier for the host computer to transmit information to the lower computer, enabling the host computer to accurately send control instructions, configuration parameters, etc. to the lower computer to achieve control of the lower computer. To meet the control requirements of complex system functions, a multi-level command combination can be constructed in the host computer, and the multi-level command combination is encapsulated into the communication frame according to the set communication protocol and sent to the lower computer. Correspondingly, when the lower computer receives the communication frame sent by the host computer, it parses the communication frame according to the set communication protocol to obtain a multi-level command combination.
[0095] In this embodiment, the multi-level command combination is obtained by selecting a command combination at each level according to the command level structure. For the case where the command level structure has three levels, the multi-level command structure includes the first-level command, the second-level command, and the third-level command. Then, the multi-level command combination needs to select one command from the first-level command, one command from the second-level command, and one command from the third-level command for combination. For example, the first-level command includes command A and command B; the second level includes command C, command D, command E, and command F; the third level includes command G, command H, command I, command J, and command K. The corresponding multi-level command combination can be a combination of command A, command E, and command H, or a combination of command B, command F, and command J, which is not limited here.
[0096] Generally speaking, the command level structure will be divided into multiple levels according to the system function and control logic, and each level corresponds to the function control of the corresponding level. Under such a level structure, the functions of different-level commands are clearly defined, and they can be independently modified and extended according to requirements, which is convenient for software system maintenance.
[0097] 102. Perform a level query in a pre-established multi-level command table according to the multi-level command combination to obtain the callback function corresponding to the lowest-level command;
[0098] Among them, the multi-level command table includes command tables of different levels constructed according to the command level structure. The non-lowest-level commands are used as indexes to query the command table of the next level in the command table of the current level, and the lowest-level commands are used to query the callback function.
[0099] In this embodiment, each non-lowest-level command in the multi-level command table has an indexing function that can query the command table of the next level accordingly. At the lowest-level command, since the lowest-level command is already the end of command refinement, by reading the lowest-level command, a specific functional operation can be executed through the callback function corresponding to the lowest-level command.
[0100] Specifically, each level in the pre-established multi-level command table contains a set of related commands that are functionally somewhat similar or relevant. For example, in an industrial automation control system, there are high-level commands such as device control, parameter setting, and status monitoring. Each high-level command is further broken down into more specific low-level commands. The non-lowest-level commands act as indexes for querying the command table of the next level. Through this indexing mechanism, the command table of the next level associated with commands at different levels can be quickly located. For example, by using the high-level command "device control" as an index, the command table of the next level can be queried, and the corresponding next-level command table contains commands such as "start device", "stop device", and "device reset". The lowest-level commands are used to query callback functions. A callback function can be a pre-written piece of code for performing specific operations or tasks. According to the lowest-level command, the corresponding callback function can be queried, and the corresponding function is completed by executing the callback function. For example, in the multi-level commands for temperature monitoring, the lowest-level command is "read the current temperature value", and the callback function corresponding to this command will precisely execute the operation of reading data from the temperature sensor, processing the data in the format required by the system, and returning it.
[0101] 103. Pass the preset pointer pointing to the communication frame as a parameter to the callback function, so that the callback function determines the lower computer call function through the preset pointer and initiates data communication according to the lower computer call function.
[0102] During the process of data communication, the preset pointer pointing to the communication frame is a variable used to store the address of the communication frame in memory. In the computer memory, when the communication frame is received or sent, the system allocates a continuous storage space for it. The pointer pointing to the communication frame, as an address label, stores the starting address of the memory area where the communication frame is located. Through the preset pointer, the callback function can read the field content in the corresponding memory area of the communication frame, obtain the parameters for calling the lower computer function, determine the lower computer call function according to these parameters, and initiate data communication with the upper computer through the lower computer call function. For example, the callback function is used to call the function for reading sensor data, and the corresponding lower computer call function is used to read sensor data. At this time, through the lower computer call function, the sensor hardware interface can be accessed to obtain the measured value of the sensor, realizing data communication.
[0103] It can be understood that the preset pointer pointing to the communication frame can use different pointer types, which can be an array pointer or a structure pointer. When the communication frame is regarded as a continuous byte sequence without complex internal structure division, it is more appropriate to use an array pointer. For example, in a simple serial communication protocol, data is transmitted in the form of a byte array with a fixed length. At this time, an array pointer can be used to conveniently access each byte in sequence for operations such as data reading and verification. If the communication frame has a clear structure and contains different types of data members, for example, a data packet in network communication may include a header, a data part, a checksum, etc., using a structure to represent the structure of the communication frame will be clearer, which can conveniently access each member for corresponding processing, enhancing the readability and maintainability of the code.
[0104] Considering that the callback function is predefined and is called when specific conditions are met, and different callback functions accept different types of pointer parameters. In order to correctly call the callback function and let it process the communication frame, it is necessary to convert the pointer structure pointing to the communication frame into the pointer type corresponding to the callback function. For example, a callback function is defined to accept a structure pointer type parameter to process the communication frame, but the obtained pointer type pointing to the communication frame is an array pointer. At this time, appropriate conversion is required to ensure that the callback function can correctly access and process the data of the communication frame.
[0105] The data communication method of the embedded software provided by the embodiments of the present application, compared with the existing technology that realizes the data communication method of the embedded software by the repeated development of the lower computer software for the same function. When the present application receives a communication frame sent by the upper computer, it parses the communication frame to obtain a multi-level command combination, and the multi-level command combination is obtained by selecting a command combination at each level according to the command hierarchy structure; perform a hierarchical query in the pre-established multi-level command table according to the multi-level command combination to obtain the callback function corresponding to the lowest-level command. The multi-level command table includes command tables at different levels constructed according to the command hierarchy structure. The non-lowest-level commands are used as indexes to query the command table at the next level in the command table at the current level, and the lowest-level commands are used to query the callback function; pass the preset pointer pointing to the communication frame as a parameter to the callback function, so that the callback function determines the lower computer call function through the preset pointer, and initiates data communication with the upper computer according to the lower computer call function. The whole process standardizes the storage of different-level commands through the multi-level command table, so that the commands do not depend on specific chips, but on the functions implemented by the chips, avoiding repeated development operations for the same function. In this way, the lower computer software can transfer the function development to the multi-level command table, and accurately locate the callback functions of different functions through the multi-level command combination, making the lower computer software more flexible and reducing the software maintenance complexity.
[0106] Considering the logical relationship between commands in a multi-level command combination, specifically during the process of parsing a data frame, as Figure 2 shown, step 101 includes the following steps:
[0107] 201. According to the frame structure stipulated by the protocol, determine the field area of the multi-level command in the communication frame.
[0108] 202. Decode the command fields of each level in the communication frame according to the field area of the multi-level command to obtain the multi-level command and the logical relationship between the multi-level commands.
[0109] 203. Process the multi-level command by using the logical relationship between the multi-level commands to obtain a multi-level command combination.
[0110] In an actual application scenario, different communication protocols have different communication frame structures. Generally, the frame structure stipulated by the protocol will include parts such as a frame header, a command, a data checksum, and a frame tail. After receiving a communication frame, the frame header is used to identify the start of a communication frame, and the frame tail identifies the end of the communication frame. The range of the entire communication frame can be determined by identifying the frame header and the frame tail.
[0111] Correspondingly, the position identifier related to the multi-level command may be a specific field name, a field position offset, or a section starting from a certain fixed position after the frame header. The field area of the multi-level command can be determined in the communication frame through the position identifier. For example, the protocol stipulates that the multi-level command field starts from the 5th byte after the frame header and has a length of 10 bytes. Further, after determining the field area of the multi-level command, analyze the separation method of each level of command in the command field according to the protocol. Here, the multi-level command combination exists in the command field in a specific separation method. For example, different levels of commands are divided by a fixed number of bytes or data types.
[0112] Specifically, during the process of decoding the command fields of each level in the communication frame according to the field area of the multi-level command, the field identification bit of the first-level command in the communication frame can be identified according to the field area of the multi-level command, so as to decode the command field of the first level in the communication frame through the field identification bit of the first-level command to obtain the first-level command; based on the first-level command, determine the field identification bit of the next-level command in the communication frame, so as to decode the command field of the next level in the communication frame through the field identification bit of the next-level command to obtain the next-level command; based on the next-level command, decode the command fields of each level in turn until the command field of the lowest level, and record the association between the commands of each level during the process of decoding the command fields of each level to obtain the multi-level command and the logical relationship between the multi-level commands.
[0113] In this embodiment, since the protocol stipulates the field areas of commands at each level, here we can start from the highest-level or lowest-level commands, extract the corresponding bytes and convert them into the corresponding command values according to the field areas and coding methods. For example, in the field area of a multi-level command, the decoding result of the first-level command parsed from the first byte is 3, and this command value represents the "read data" operation. Then, based on the decoding result of the first-level command, we enter the decoding process of the next-level command, and this process needs to determine the specific meaning or parsing method of the second-level command according to the specific value of the first-level command. For example, if the first-level command is "set parameters", then the second-level command may be the specific parameter value, and further parse the parameter value as 1024 according to the specified two-byte integer type. Repeat the decoding process of the above-level commands until the decoding process of the lowest-level command to obtain the multi-level command.
[0114] At the same time, considering that there is a logical relationship between multi-level commands, we can determine the logical relationship between multi-level commands during the decoding process of multi-level commands. The logical relationships here can include but are not limited to sequential relationships, conditional relationships, inclusion relationships, etc. For example, some commands may be in a parent-child relationship, that is, the first-level command is the parent command, and the second-level command is the specific parameter setting or refinement operation of the parent command; some commands may be in a sequential relationship, that is, first execute the first-level command, and then execute the second-level command according to its result, etc.
[0115] Finally, using the logical relationship between multi-level commands, we can determine the rules for combining multi-level command combinations and combine the commands at each level according to the rules to obtain the multi-level command combination. For example, combine the commands at each level in the hierarchical order, or screen out the commands at each level according to specific conditions for combination.
[0116] In an actual application scenario, considering that there is a certain correlation between multi-level commands and the command tables at each level, for the convenience of querying hierarchical commands, further, as Figure 3 shown, before step 102, the method further includes:
[0117] 301. Decompose the functions of the embedded software system into multi-level commands.
[0118] 302. Construct command tables at different levels according to the multi-level commands.
[0119] 303. Bind the command tables at different levels to the multi-level commands in the order from the lowest-level command to the highest-level command.
[0120] It can be understood that an embedded software system has multiple relatively independent functional modules, and there are interaction relationships between different functional modules. According to the requirements analysis, the functions of the embedded software system can be split into multi-level commands. Specifically, the functions of the embedded software system can be disassembled according to the task priorities in the system, so that the commands corresponding to tasks with higher priorities are placed at higher levels to ensure that they can obtain system resources and execution time preferentially. Correspondingly, the commands corresponding to tasks with lower priorities are placed at lower levels. The functions of the embedded software system can also be disassembled according to the data flow in the system, so that the commands with earlier data flow are placed at lower levels, and the commands with later data flow are placed at higher levels. For example, the data acquisition command is at a lower level and is responsible for obtaining raw data from sensors. The data processing command is at an intermediate level and is responsible for analyzing, calculating, and converting the acquired data. The data transmission command is at a higher level and is responsible for transmitting the processed data to a specified destination.
[0121] In this embodiment, the command tables at different levels are command tables constructed according to the commands at the corresponding levels. Specifically, the command table at the lowest level is constructed according to the lowest-level commands and the callback functions corresponding to the lowest-level commands, and the command tables at non-lowest levels are constructed according to the non-lowest-level commands. In an embedded system, when a command is received, it needs to be parsed and executed according to the command level and specific content. Binding the command table to the level can provide a clear search path and rules for the command parser. Correspondingly, the command parser can first determine the level to which the command belongs according to the level name, and then search for the specific command in the command table at that level, so as to quickly and accurately find the corresponding execution function or operation process and achieve the efficient execution of the command.
[0122] It should be noted that the first-level command table in the multi-level command table usually has reserved fields, that is, there are many empty items in the first-level command table, and there is no command table at the next level for the corresponding commands in the first-level command table. That is to say, the first-level command table can add or delete the current-level commands accordingly. This can save a large amount of memory space. Correspondingly, after the command table at the current level is constructed, it can be directly bound to the command at the upper level or a command can be added and bound at the upper level. If the command table at the current level is not bound to the command at the upper level, it means that this command table cannot be used in the data communication process.
[0123] Specifically, in the process of hierarchical binding, the command table of the current level is bound to the command of the previous level using the command of the previous level as an index, until the highest level command. That is to say, the command table of the current level can be obtained by querying the command of the previous level as an index. For example, the command table of the third level can be queried by the command of the second level as an index, and the command table of the second level can be queried by the command of the first level as an index. By binding the hierarchical command with the command table of the level, the hierarchical command can be used as the index command table of the next level, so that there is a clear hierarchical relationship between the commands of different levels in the system, which is more convenient and quick for developers to understand the system architecture and to maintain and expand the system in the future. When the system receives a command, the index relationship of the hierarchical binding can be used to quickly locate the command table of the corresponding level, and then find the specific command and its execution logic. Just like in a multi-layer file directory, the lowest level command and the callback function corresponding to the lowest level command can be accurately located by indexing step by step, avoiding blind searching in a large number of commands and improving the response speed of the system.
[0124] It should be noted that the above-mentioned hierarchical binding allows the lower-level command table to be bound to the upper-level command, for example, the second-level command table is bound to the upper-level command, but considering that different usage scenarios may require the system to organize and call commands in different ways, the binding relationship between the command table and the command is changeable. For example, in the daily production mode, the command table is bound to the hierarchical command of "routine production operation"; in the equipment maintenance mode, the same command table needs to be switched to bind to the hierarchical command of "equipment maintenance operation" so that maintenance personnel can perform related operations more conveniently, improving the flexibility and adaptability of the system.
[0125] Specifically, in the process of hierarchical binding, the binding relationship between command tables of different levels and commands of the previous level is recorded; when the binding relationship changes, the binding relationship between the command table of the corresponding level and the command of the previous level is released, and the command table of the corresponding level is bound to the updated command of the previous level using the updated command of the previous level as an index to update the binding relationship between the command table and the command in the multi-level command table. Here, the change of binding relationship can be realized by combining multi-level commands. For example, the multi-level command table includes two levels. The command table B1 of the second level is bound to the command a of the first level. The updated binding relationship requires the command table B2 of the second level to be bound to the command a of the first level. At this time, it is necessary to control the command table B1 of the second level to release the binding relationship with the command a of the first level through multi-level commands, and then control the command table B2 of the second level to bind to the command a of the first level to realize the change of binding relationship.
[0126] In an actual application scenario, multi-level commands include a main command and a secondary command. The main command is a non-lowest-level command, and the secondary command is the lowest-level command. The multi-level command table includes a main command table and a secondary command table. Correspondingly, as Figure 4 shown, the above steps 301 to 303 can be implemented through the following steps:
[0127] 401. Decompose the functions of the embedded software system into main commands and secondary commands.
[0128] 402. Construct a secondary command table and a main command table respectively.
[0129] 403. Use the main command as an index to bind the secondary command table to the main command to obtain a multi-level command table.
[0130] In this embodiment, the secondary command table is constructed based on the secondary command and the callback function corresponding to the secondary command, and the main command table is constructed based on the main command. Here, the main command, as the first-level command, can be used as an index to bind the secondary command table to the main command to obtain a multi-level command table.
[0131] In an actual application scenario, the multi-level command combination needs to go through hierarchical queries to obtain the callback function. Specifically, as Figure 5 shown, step 102 includes the following steps:
[0132] 501. According to the multi-level command combination, perform hierarchical queries in the pre-established multi-level command table in the order from the highest-level command to the lowest-level command.
[0133] 502. During the hierarchical query process, use the current-level command as an index to query in the command table of the current level to obtain the command table of the next level until the callback function corresponding to the lowest-level command is obtained by querying in the command table of the lowest level using the lowest-level command.
[0134] In this embodiment, the multi-level command combination has multiple level commands. For non-lowest-level commands, each level command can query the command table of each level layer by layer in the pre-established multi-level command table until the callback function corresponding to the lowest-level command is queried in the command table of the lowest level.
[0135] For example, a multi-level command is combined into a three-level command of "home appliance control - air conditioner control - temperature adjustment". In the pre-established multi-level command table, each level has a corresponding command table, which records the commands at that level and the binding relationship with the command table of the next level. In order, starting from the command table of the highest-level command "home appliance control", use "home appliance control" as an index to query the command table of "air conditioner control" in the "home appliance control" command table, and then use "air conditioner control" as an index to query the command table of "temperature adjustment" in the "air conditioner control" command table. Since "temperature adjustment" is the lowest-level command, finally, query the callback function corresponding to "temperature adjustment" in the "temperature adjustment" command table according to "temperature adjustment".
[0136] In an actual application scenario, the multi-level command combination includes a main command and a secondary command. The main command is a non-lowest-level command, and the secondary command is the lowest-level command. The multi-level command table includes a main command table and a secondary command table; correspondingly, as Figure 6 shown, the above steps 101 to 103 can be implemented through the following steps:
[0137] 601. When receiving a communication frame sent by the host computer, parse the communication frame to obtain the main command and the secondary command.
[0138] 602. Use the main command as an index to query in the main command table to obtain the secondary command table.
[0139] 603. Query according to the secondary command in the secondary command table to obtain the callback function corresponding to the secondary command.
[0140] In this embodiment, after using the multi-level command table for data communication, the main command table can directly use the main command as an index to query the secondary command table, and the time performance of this is , and the time performance of using traversal query for the secondary command table is ; however, if the multi-level command table is not used for data communication, at this time, all main commands and secondary commands will be placed in the same command table, and the time performance of the corresponding query will change to , where is the number of main commands, is the number of secondary commands.
[0141] In an actual application scenario, the lowest-level commands are stored through a first preset structure, and the first preset structure includes at least a lowest-level command field, a callback function pointer variable, and a reserved field; the lowest-level command table is stored through a second preset structure, and the second preset structure includes at least a pointer variable of the lowest-level command, a command quantity field, a command description field, and a reserved field; the non-lowest-level command table is stored through a third preset structure, and the third preset structure includes at least a pointer variable of the non-lowest-level command, a command quantity field, a command description field, and a reserved field. Taking a multi-level command combination including a main command and a secondary command as an example.
[0142] See specifically Figure 7 for the command hierarchy structure in As the structure of the secondary command, it contains 4 fields inside: a one-byte secondary command , two reserved fields and each occupying one byte, and a callback function pointer , and the pointer type of the callback function is . As the structure of the secondary command table, it contains 4 fields inside: a pointer variable of a secondary command , a field describing the quantity of secondary commands , a secondary command description field and a reserved field . As the structure of the main command, it contains a pointer variable of a main command , and usually this pointer variable will be assigned the starting address of an array of secondary commands, and accordingly, the secondary command table can be retrieved by using the main command as an index.
[0143] Correspondingly, the process of using the multi-level command structure for data communication is as Figure 8 shown. When the system receives a communication frame sent by the host computer, it parses the communication frame to obtain a multi-level command combination including a main command and a secondary command . There are a pre-built main command table and a secondary command table . Use the main command as an index to query in the main command table for the pointer pointing to the secondary command table . This pointer can point to the secondary command table where the secondary command is located, and obtain corresponding to . According to the secondary command query the secondary command table Fields in it to obtain the fields corresponding to the sub-command sub_cmd , extract the callback function .
[0144] Furthermore, based on the same inventive concept, an embodiment of the present application also provides a data communication system for embedded software, as Figure 9 shown, including: an application layer, a system layer, an adaptation layer, and a resource library;
[0145] The application layer is used to construct the lowest-level command table, and hierarchically bind the lowest-level command table by means of pointer exposure, so that multiple-level command tables are coupled to obtain a multi-level command table;
[0146] The system layer calls the resource library to store the multi-level command table in the resource library;
[0147] When receiving a communication frame sent by the host computer, the system layer calls the adaptation layer to parse the communication frame, and hierarchically queries the resource library in the multi-level command table according to the parsed multi-level command combination to obtain the callback function corresponding to the lowest-level command;
[0148] The system layer initiates data communication with the host computer according to the callback function.
[0149] As a coupling scenario, after constructing the lowest-level command table in the application layer, the application layer will expose the pointer of the lowest-level command table, so that the system layer binds the lowest-level command table to the upper-level command through the exposed command table pointer, hierarchically binds the command table, and couples multiple-level command tables to obtain a multi-level command table.
[0150] As another coupling scenario, after constructing the lowest-level command table in the application layer, the system layer can expose the interface pointer for operating the upper-level command table, so that the application layer binds the lowest-level command table to the upper-level command through the exposed interface pointer, hierarchically binds the command table, and couples multiple-level command tables to obtain a multi-level command table.
[0151] In actual application scenarios, as the operating environment and basic services of embedded software, the system layer can control the adaptation layer and the resource library. Specifically, the adaptation layer is located between the system layer and the application layer. The system layer can adapt the control instructions and requests of the application layer to the interfaces and services of the system layer by calling the adaptation layer, and at the same time feedback the status and data of the system layer to the application layer. For example, in an intelligent device control system, the control adaptation layer will convert the control commands sent by the user through the mobile application into instructions that the device can understand, and at the same time feedback the operation status information of the device to the mobile application so that the user can understand the current situation of the device. The resource library is used to store multi-level command tables. The hierarchical commands in each level of the command table are bound to the command table of the next lower level, so that the multi-level command table has an indexing mechanism and a clear storage structure. In this way, the system layer can quickly locate specific commands in the multi-level command table by calling the resource library, greatly improving the efficiency of system operations.
[0152] Furthermore, based on the same inventive concept, the embodiments of the present application further provide a data communication device for embedded software, as Figure 10 shown. The device includes: a parsing unit 71, a query unit 72, and a communication unit 73.
[0153] The parsing unit 71 is configured to parse the communication frame received from the host computer when receiving the communication frame, and obtain a multi-level command combination, where the multi-level command combination is obtained by selecting a command combination at each level according to the command hierarchical structure;
[0154] The query unit 72 is configured to perform hierarchical query in a pre-established multi-level command table according to the multi-level command combination, and obtain a callback function corresponding to the lowest-level command. The multi-level command table includes command tables of different levels constructed according to the command hierarchical structure. The non-lowest-level commands are used as indexes to query the command table of the next lower level in the current-level command table, and the lowest-level commands are used to query the callback function;
[0155] The communication unit 73 is configured to pass a preset pointer pointing to the communication frame as a parameter to the callback function, so that the callback function determines a lower computer call function through the preset pointer, and initiates data communication according to the lower computer call function.
[0156] The data communication device of the embedded software provided by the embodiments of the present application, compared with the existing technology that realizes the data communication method of the embedded software through the repeated development of the lower computer software for the same function, when the present application receives a communication frame sent by the upper computer, it parses the communication frame to obtain a multi-level command combination, and the multi-level command combination is obtained by selecting a command combination at each level according to the command hierarchy structure; perform a hierarchical query in a pre-established multi-level command table according to the multi-level command combination to obtain the callback function corresponding to the lowest-level command. The multi-level command table includes command tables at different levels constructed according to the command hierarchy structure, and the non-lowest-level commands are used as indexes to query the command table at the next level in the command table at the current level, and the lowest-level commands are used to query the callback function; pass the preset pointer pointing to the communication frame as a parameter to the callback function, so that the callback function determines the lower computer call function through the preset pointer, and initiates data communication with the upper computer according to the lower computer call function. The whole process standardizes and stores commands at different levels through a multi-level command table, so that the commands do not depend on specific chips, but on the functions implemented by the chips, avoiding repeated development operations for the same function. In this way, the lower computer software can transfer the function development to the multi-level command table, and accurately locate the callback functions of different functions through the multi-level command combination, making the lower computer software more flexible and reducing the software maintenance complexity.
[0157] In an actual application scenario, the parsing unit is specifically configured to:
[0158] Determine the field area of the multi-level command in the communication frame according to the frame structure specified by the protocol;
[0159] Decode the command fields at each level in the communication frame according to the field area of the multi-level command to obtain the multi-level command and the logical relationship between the multi-level commands;
[0160] Process the multi-level command by using the logical relationship between the multi-level commands to obtain a multi-level command combination.
[0161] In an actual application scenario, the parsing unit is specifically further configured to:
[0162] Identify the field identification bit of the first-level command in the communication frame according to the field area of the multi-level command, so as to decode the command field of the first level in the communication frame through the field identification bit of the first-level command to obtain the first-level command;
[0163] On the basis of the first-level command, determine the field identification bit of the command at the next level in the communication frame, so as to decode the command field of the next level in the communication frame through the field identification bit of the command at the next level to obtain the next-level command;
[0164] Based on the next level of commands, the command fields of each level are decoded in turn until the command field of the lowest level. In the process of decoding the command fields of each level, the associations between the commands of each level are recorded to obtain multi-level commands and the logical relationships between the multi-level commands.
[0165] In an actual application scenario, the device further includes:
[0166] A disassembling unit, configured to disassemble the functions of the embedded software system into multi-level commands before performing a hierarchical query in a pre-established multi-level command table according to the multi-level command combination to obtain a callback function corresponding to the lowest-level command;
[0167] A construction unit, configured to construct command tables of different levels according to the multi-level commands, wherein the command table of the lowest level is constructed according to the lowest level command and the callback function corresponding to the lowest level command, and the command table of the non-lowest level is constructed according to the non-lowest level command;
[0168] A binding unit is used to hierarchically bind the command tables of different levels with the multi-level commands in the order from the lowest level command to the highest level command to obtain a multi-level command table. During the hierarchical binding process, the command table of the current level is bound to the command of the previous level using the command of the previous level as an index until the highest level command is reached.
[0169] In an actual application scenario, the device further includes:
[0170] a recording unit, configured to record the binding relationship between the command tables of different levels and the commands of a previous level in the process of hierarchical binding after the command tables of different levels are hierarchically bound with the multi-level commands in the order from the lowest level command to the highest level command;
[0171] An updating unit is used to release the binding relationship between the command table of the corresponding level and the command of the previous level when the binding relationship changes, and use the updated command of the previous level as an index to bind the command table of the corresponding level to the updated command of the previous level, so as to update the binding relationship between the command table and the command in the multi-level command table.
[0172] In an actual application scenario, the multi-level command includes a main command and a secondary command, the main command is a non-lowest level command, the secondary command is a lowest level command, and the multi-level command table includes a main command table and a secondary command table;
[0173] Accordingly, the disassembly unit is specifically used to disassemble the functions of the embedded software system into main commands and secondary commands;
[0174] The construction unit is specifically configured to construct a secondary command table and a primary command table respectively. The secondary command table is constructed based on secondary commands and corresponding callback functions, and the primary command table is constructed based on primary commands;
[0175] The binding unit is specifically configured to bind the secondary command table to the primary command using the primary command as an index to obtain a multi-level command table.
[0176] In an actual application scenario, the lowest-level commands are stored through a first set structure, and the first set structure includes at least a lowest-level command field, a callback function pointer variable, and a reserved field; the lowest-level command table is stored through a second set structure, and the second set structure includes at least a pointer variable of the lowest-level command, a command quantity field, a command description field, and a reserved field; the non-lowest-level command table is stored through a third set structure, and the third set structure includes at least a pointer variable of the non-lowest-level command, a command quantity field, a command description field, and a reserved field.
[0177] In an actual application scenario, the query unit is specifically configured to:
[0178] Perform hierarchical queries in a pre-established multi-level command table according to the multi-level command combination in the order from the highest-level command to the lowest-level command;
[0179] During the hierarchical query process, use the current-level command as an index to query in the command table of the current level to obtain the command table of the next level until the callback function corresponding to the lowest-level command is obtained by querying in the lowest-level command table using the lowest-level command.
[0180] In an actual application scenario, the multi-level command combination includes a primary command and a secondary command. The primary command is a non-lowest-level command, and the secondary command is a lowest-level command. The multi-level command table includes a primary command table and a secondary command table;
[0181] Correspondingly, the parsing unit is specifically configured to parse the communication frame when receiving a communication frame sent by the host computer to obtain a primary command and a secondary command;
[0182] The query unit is specifically further configured to:
[0183] Query in the primary command table using the primary command as an index to obtain the secondary command table;
[0184] Query in the secondary command table according to the secondary command to obtain the callback function corresponding to the secondary command.
[0185] It should be noted that for other corresponding descriptions of each functional unit involved in the data communication device of the embedded software provided in this embodiment, reference can be made to Figures 1 - 6 the corresponding description in
[0186] Based on the above method as Figures 1 - 6 shown, correspondingly, the embodiment of the present application also provides a storage medium, on which a computer program is stored, and when the program is executed by a processor, it implements the data communication method of the embedded software as Figures 1 - 6 shown.
[0187] Based on such an understanding, the technical solution of the present application can be embodied in the form of a software product, and the software product can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.), including several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in various implementation scenarios of the present application.
[0188] Based on the above method as Figures 1 - 6 shown, and Figure 10 the virtual device embodiment shown, in order to achieve the above object, the embodiment of the present application also provides an entity device for the data communication method of the embedded software, which can specifically be a computer, a smart phone, a tablet computer, a smart watch, a server, or a network device, etc. The entity device includes a storage medium and a processor; the storage medium is used to store a computer program; the processor is used to execute the computer program to implement the data communication method of the embedded software as Figures 1 - 6 shown.
[0189] Optionally, the entity device may further include a user interface, a network interface, a camera, a radio frequency (RF) circuit, sensors, an audio circuit, a WI-FI module, etc. The user interface may include a display screen (Display), an input unit such as a keyboard (Keyboard), etc. Optionally, the user interface may further include a USB interface, a card reader interface, etc. The network interface may optionally include a standard wired interface, a wireless interface (such as a WI-FI interface), etc.
[0190] In an exemplary embodiment, referring to Figure 11 , the above entity device includes a communication bus, a processor, a memory, and a communication interface, and may further include an input / output interface and a display device. Among them, each functional unit can complete mutual communication through the bus. The memory stores a computer program, and the processor is used to execute the program stored on the memory to execute the data communication method of the embedded software in the above embodiment.
[0191] Those skilled in the art can understand that the physical device structure for data communication of the embedded software provided in this embodiment does not limit the physical device, and may include more or fewer components, or combine certain components, or have different component arrangements.
[0192] The storage medium may also include an operating system and a network communication module. The operating system is a program for managing the hardware and software resources of the physical device for data communication of the above-mentioned embedded software, and supports the operation of information processing programs and other software and / or programs. The network communication module is used to implement communication between components within the storage medium, as well as communication with other hardware and software in the information processing physical device.
[0193] Through the description of the above embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus a necessary general hardware platform, or can also be implemented by hardware. By applying the technical solution of this application, compared with the current existing methods, this application standardizes the storage of different-level commands through a multi-level command table, so that the commands do not depend on a specific chip, but on the functions implemented by the chip, avoiding repeated development operations for the same function. In this way, the lower-level software can transfer the function development to the multi-level command table, and accurately locate the callback functions of different functions through multi-level command combinations, making the lower-level software more flexible and reducing the software maintenance complexity.
[0194] Those skilled in the art can understand that the drawings are only schematic diagrams of a preferred implementation scenario, and the modules or processes in the drawings are not necessarily essential for implementing this application. Those skilled in the art can understand that the modules in the device in the implementation scenario can be distributed in the device in the implementation scenario according to the description of the implementation scenario, or can be correspondingly changed and located in one or more devices different from this implementation scenario. The modules in the above implementation scenario can be combined into one module, or further split into multiple sub-modules.
[0195] The above serial numbers of this application are only for description and do not represent the advantages or disadvantages of the implementation scenarios. The above disclosure is only several specific implementation scenarios of this application. However, this application is not limited thereto, and any changes that can be thought of by those skilled in the art should fall within the protection scope of this application.
Claims
1. A data communication method for embedded software, characterized in that Including: When receiving a communication frame sent by a host computer, according to the frame structure stipulated by the protocol, determine the field area of multi-level commands in the communication frame; Decode the command fields of each level in the communication frame according to the field area of the multi-level commands, to obtain the multi-level commands and the logical relationships between the multi-level commands. Specifically, identify the field identification bit of the first-level command in the communication frame according to the field area of the multi-level commands, so as to decode the command field of the first level in the communication frame through the field identification bit of the first-level command, and obtain the first-level command; On the basis of the first-level command, determine the command field identification bit of the next level in the communication frame, so as to decode the command field of the next level in the communication frame through the command field identification bit of the next level, and obtain the next-level command; on the basis of the next-level command, decode the command fields of each level in turn until the command field of the lowest level, and record the associations between the commands of each level during the process of decoding the command fields of each level, to obtain the multi-level commands and the logical relationships between the multi-level commands; Process the multi-level commands by using the logical relationships between the multi-level commands, to obtain a multi-level command combination; Perform a hierarchical query in a pre-established multi-level command table according to the multi-level command combination, to obtain the callback function corresponding to the lowest-level command. The multi-level command table includes command tables of different levels constructed according to the command hierarchical structure, with non-lowest-level commands as indexes for querying the command table of the next level in the command table of the current level, and the lowest-level command for querying the callback function; Pass a preset pointer pointing to the communication frame as a parameter to the callback function, so that the callback function determines the lower computer call function through the preset pointer, and initiate data communication according to the lower computer call function.
2. The method according to claim 1, wherein Before performing the hierarchical query in a pre-established multi-level command table according to the multi-level command combination to obtain the callback function corresponding to the lowest-level command, the method further includes: Decompose the functions of the embedded software system into multi-level commands; Construct command tables of different levels according to the multi-level commands. The command table of the lowest level is constructed according to the lowest-level command and the callback function corresponding to the lowest-level command, and the command table of a non-lowest level is constructed according to the non-lowest-level command; Bind the command tables of different levels to the multi-level commands in the order from the lowest-level command to the highest-level command, to obtain a multi-level command table. During the hierarchical binding process, use the command of the upper level as an index to bind the command table of the current level to the command of the upper level until the highest-level command.
3. The method according to claim 2, wherein After binding the command tables of different levels to the multi-level commands in the order from the lowest-level command to the highest-level command, the method further includes: During the hierarchical binding process, record the binding relationships between the command tables of different levels and the commands of the upper level. When the binding relationship changes, the binding relationship between the command table of the corresponding level and the command of the previous level is released, and the command table of the corresponding level is bound to the updated command of the previous level using the updated command of the previous level as an index to update the binding relationship between the command table and the command in the multi-level command table.
4. The method according to claim 2, wherein The multi-level command includes a main command and a sub-command, the main command is a non-lowest level command, the sub-command is a lowest level command, and the multi-level command table includes a main command table and a sub-command table; Accordingly, the functions of the embedded software system are decomposed into primary commands and secondary commands; Constructing a secondary command table and a main command table respectively, wherein the secondary command table is constructed according to the secondary command and the callback function corresponding to the secondary command, and the main command table is constructed according to the main command; The secondary command table is bound to the primary command using the primary command as an index to obtain a multi-level command table.
5. The method according to claim 2, characterized in that, The lowest level command is stored through a first setting structure, which at least includes a lowest level command field, a callback function pointer variable, and a reserved field; the lowest level command table is stored through a second setting structure, which at least includes a pointer variable of the lowest level command, a command quantity field, a command description field, and a reserved field; the non-lowest level command table is stored through a third setting structure, which at least includes a pointer variable of the non-lowest level command, a command quantity field, a command description field, and a reserved field.
6. The method according to any one of claims 1-5, characterized in that, The step of performing a hierarchical query in a pre-established multi-level command table according to the multi-level command combination to obtain a callback function corresponding to the lowest-level command includes: According to the multi-level command combination, a hierarchical query is performed in a pre-established multi-level command table in the order of the highest level command to the lowest level command; During the hierarchical query process, the current level command is used as an index to query the command table of the current level to obtain the command table of the next level, until the lowest level command is used to query the command table of the lowest level to obtain the callback function corresponding to the lowest level command.
7. The method according to claim 6, characterized in that, The multi-level command combination includes a main command and a secondary command, the main command is a non-lowest level command, the secondary command is a lowest level command, and the multi-level command table includes a main command table and a secondary command table; Correspondingly, when receiving the communication frame sent by the host computer, the communication frame is parsed to obtain the main command and the secondary command; Using the main command as an index to search the main command table, to obtain a secondary command table; According to the sub-command, the sub-command table is searched to obtain the callback function corresponding to the sub-command.
8. An embedded software data communication system, characterized in that, include: Application layer, system layer, adaptation layer and resource library; The application layer is used to construct a command table of the lowest level, and hierarchically bind the command table of the lowest level by exposing a pointer, so that command tables of multiple levels are coupled to obtain a multi-level command table; The system layer calls the resource library to store the multi-level command table in the resource library; When receiving a communication frame sent by the host computer, the system layer calls the adaptation layer to parse the communication frame, and based on the multi-level command combination obtained from the parsing, calls the resource library to perform a hierarchical query in the multi-level command table to obtain the callback function corresponding to the lowest-level command; The system layer initiates data communication with the host computer according to the callback function; The specific process of parsing the communication frame is as follows: According to the frame structure specified by the protocol, determine the field area of the multi-level command in the communication frame; Decode the command fields of each level in the communication frame according to the field area of the multi-level command to obtain the multi-level command and the logical relationship between the multi-level commands. Specifically, identify the field identification bit of the first-level command in the communication frame according to the field area of the multi-level command, and decode the command field of the first level in the communication frame through the field identification bit of the first-level command to obtain the first-level command; Based on the first-level command, determine the command field identification bit of the next level in the communication frame, and decode the command field of the next level in the communication frame through the command field identification bit of the next level to obtain the next-level command. Based on the next-level command, decode the command fields of each level in turn until the command field of the lowest level. During the process of decoding the command fields of each level, record the associations between the commands of each level to obtain the multi-level command and the logical relationship between the multi-level commands; Process the multi-level command by using the logical relationship between the multi-level commands to obtain a multi-level command combination.
9. An embedded software data communication device, characterized in that, It includes: A parsing unit, configured to parse the communication frame when receiving a communication frame sent by the host computer to obtain a multi-level command combination, where the multi-level command combination is obtained by selecting one command at each level according to the command hierarchical structure; A query unit, configured to perform a hierarchical query in a pre-established multi-level command table according to the multi-level command combination to obtain the callback function corresponding to the lowest-level command. The multi-level command table includes command tables of different levels constructed according to the command hierarchical structure. The non-lowest-level commands are used as indexes to query the command table of the next level in the command table of the current level, and the lowest-level command is used to query the callback function; A communication unit, configured to pass a preset pointer pointing to the communication frame as a parameter to the callback function, so that the callback function determines the lower computer call function through the preset pointer and initiates data communication according to the lower computer call function; The parsing unit is specifically configured to determine the field area of the multi-level command in the communication frame according to the frame structure specified by the protocol; Decode the command fields of each level in the communication frame according to the field area of the multi-level command to obtain the multi-level command and the logical relationship between the multi-level commands. Specifically, identify the field identification bit of the first-level command in the communication frame according to the field area of the multi-level command, and decode the command field of the first level in the communication frame through the field identification bit of the first-level command to obtain the first-level command; Based on the first-level command, determine the identification bit of the command field at the next level in the communication frame, so as to decode the command field at the next level in the communication frame through the identification bit of the command field at the next level to obtain the next-level command; based on the next-level command, decode the command fields of each level in sequence until the command field at the lowest level, and record the associations between the commands of each level during the process of decoding the command fields of each level to obtain the multi-level commands and the logical relationships between the multi-level commands; Process the multi-level commands by using the logical relationships between the multi-level commands to obtain a multi-level command combination.
10. A computer device, comprising a memory and a processor, the memory storing a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the data communication method of the embedded software described in any one of claims 1 to 7.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the data communication method of the embedded software described in any one of claims 1 to 7.
Citation Information
Patent Citations
Embedded software interface data frame analysis method based on configuration
CN117271323A
Intercommunication device and communication system based on multiple protocols
CN117596312A