Data communication method and device, electronic equipment, storage medium and system
By introducing a communication scheduling layer in the business system, the transmission of data blocks is uniformly scheduled, and the problem of data transmission caused by the communication driver to seize the CPU resources is not timely, which improves the stability of the system.
Patent Information
- Application Number
- CN202310936120.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-27
- Publication Date
- 2025-01-28
Smart Images

Figure CN119376967A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a data communication method, device, electronic device, storage medium and system. Background Art
[0002] As the scale of business systems grows and performance requirements become higher, the amount of data and real-time requirements for communication between modules in the system also increase significantly. In the traditional communication framework, the application layer in the business system caches the data to be transmitted, and then each communication driver sends it according to the busyness of its interface.
[0003] If a module generates a large amount of data, its corresponding communication driver will constantly occupy CPU resources, resulting in data from other modules not being sent in a timely manner, which may lead to instability in the business system. Summary of the invention
[0004] The purpose of the embodiments of the present application is to provide a data communication method, device, electronic device, storage medium and system for uniformly scheduling data that needs to be transmitted by an application program and improving the stability of the system.
[0005] In a first aspect, an embodiment of the present application provides a data communication method, which includes:
[0006] Acquire a data block of the application, wherein the data block includes communication data and communication driver information;
[0007] After obtaining the data block, store the data block in the data block queue;
[0008] According to the scheduling strategy, the communication data corresponding to the data block in the data block queue is sent to the target communication driver corresponding to the communication driver information.
[0009] The embodiment of the present application stores the data that needs to be transmitted generated by the application in the form of data blocks in a data block queue for unified scheduling. Compared with the existing solution, the application directly communicates data with the communication driver and the communication driver seizes CPU resources. The method of the embodiment of the present application uses a scheduling strategy to orderly send the communication data corresponding to the data blocks in the data block queue to the corresponding target communication driver, thereby reducing the situation where the communication driver seizes CPU resources according to its own priority, allowing the communication data to be processed in a timely manner, improving the stability of data transmission, and thereby improving the stability of system operation.
[0010] In any embodiment, when a data block is written into a data queue, the data block may be stored in a data queue of a corresponding priority according to the priority information.
[0011] The embodiment of the present application stores data blocks according to their priority information, so that data with high priority is processed first, and the data is processed in order, thereby improving the stability of the system.
[0012] In any embodiment, sending the communication data corresponding to the data block in the data block queue to the target communication driver corresponding to the communication driver information according to the scheduling strategy includes:
[0013] Based on the priority of the data queue, obtain the data block to be processed from the data queue;
[0014] The communication data corresponding to the data block to be processed is sent to the target communication driver corresponding to the communication driver information.
[0015] The embodiment of the present application processes the data blocks according to the priority of the data queue, so that the data with high priority is processed first, thereby improving the orderliness of data processing and further improving the stability of system operation.
[0016] In any embodiment, sending the communication data corresponding to the data block to be processed to the target communication driver corresponding to the communication driver information includes:
[0017] If the working state of the target communication driver is an idle state, the communication data corresponding to the data block to be processed is sent to the target communication driver; and / or
[0018] If the working state of the target communication driver is busy, the data block to be processed is put back into the original data queue, and the next data block to be processed is obtained from the data queue based on the priority of the data queue;
[0019] If the working state of the target communication driver corresponding to the next data block to be processed is an idle state, the communication data corresponding to the next data block to be processed is sent to the target communication driver corresponding to the next data block to be processed.
[0020] In the embodiment of the present application, whether to send communication data to the target communication driver is determined according to the busy / idle status of the target communication driver, thereby improving the success rate of communication data sending.
[0021] In any embodiment, sending the communication data corresponding to the data block to be processed to the target communication driver corresponding to the communication driver information includes:
[0022] The accumulated duration is calculated according to the duration of the data block sent in the data sending time slot corresponding to the current moment and the estimated duration corresponding to the data block to be processed; wherein the data sending time slot is a time period for sending data blocks obtained by pre-dividing time;
[0023] If the accumulated time length is less than the data sending time slot corresponding to the current moment, the communication data corresponding to the data block to be processed is sent to the target communication driver corresponding to the communication driver information.
[0024] The embodiment of the present application divides time in advance to obtain multiple time slots, and performs corresponding operations in different time slots, so that data that needs to be transmitted in a short period of time or continuous burst communication can be dispersed in multiple time slots for processing, thereby improving the stability of data transmission and further improving the stability of system operation.
[0025] In any embodiment, after sending the communication data corresponding to the data block to be processed to the target communication driver corresponding to the communication driver information, the method further includes:
[0026] Update the duration of the sent data based on the estimated sending duration.
[0027] In the embodiment of the present application, since the size of the data sending time slot is fixed, but the time required to send a communication data is not fixed, the cumulative duration of the sent data can be counted, thereby facilitating the determination of whether to terminate the data sending operation.
[0028] In any embodiment, the method further comprises:
[0029] Preset the time interval for interrupt triggering; the time interval is the time interval between two adjacent interrupts;
[0030] According to a preset division rule, the time slot is divided to obtain a plurality of sub-time slots, wherein different sub-slots are used to perform different data operations.
[0031] The embodiment of the present application divides time into multiple time slots by interruption, and divides each time slot into multiple sub-time slots, thereby stipulating that corresponding data operations are performed in different sub-time slots, thereby reducing the impact of data transmission on task execution.
[0032] In any embodiment, the sub-time slots include: a data reception time slot, a data processing time slot and a data transmission time slot.
[0033] In the embodiment of the present application, by performing data receiving operations in the data receiving time slot, processing data in the data processing time slot, and sending data in the data sending time slot, the impact of the data transmission process on task execution is reduced, and the stability of the data transmission process is improved.
[0034] In any embodiment, a protection period is set before and after the data receiving time slot, the data processing time slot and the data sending time slot.
[0035] The embodiment of the present application reduces the risk of processing timeout by setting a protection time period.
[0036] In any embodiment, the method further comprises:
[0037] If the first data queue includes a target data block to be processed whose waiting time is greater than the preset waiting time, the target data block to be processed is migrated from the first data queue to the second data queue; the priority of the first data queue is lower than that of the second data queue.
[0038] The embodiment of the present application reduces the probability of data not being processed for a long time by increasing the priority of data blocks that have not been processed for a long time.
[0039] In any embodiment, the method further comprises:
[0040] Get the data to be received from the communication driver and send the data to be received to the corresponding application.
[0041] By sending the data obtained from the communication driver to the corresponding application, the embodiment of the present application reduces the impact on task execution compared to the existing solution that generates an interrupt as long as there is data to receive data.
[0042] In a second aspect, an embodiment of the present application provides another data communication method, the method comprising:
[0043] Receive the data block sent by the application layer, the data block includes communication data and communication driver information;
[0044] Store the data block in the data block queue;
[0045] If the current moment is in the data sending time slot, obtain the data block to be processed from the data block queue, and send the communication data corresponding to the data block in the data block queue to the target communication driver corresponding to the communication driver information according to the scheduling strategy; wherein the data sending time slot is a time period for sending data blocks obtained by dividing the time in advance.
[0046] The embodiment of the present application improves the stability of data transmission and thus improves the stability of system operation by uniformly scheduling the data generated by the application program that needs to be transmitted.
[0047] In a third aspect, an embodiment of the present application provides a data communication device, including:
[0048] A data block acquisition module is used to acquire the data block of the application program, the data block includes communication data and communication driver information;
[0049] A cache module, used for storing data blocks in a data block queue;
[0050] The sending module is used to send the data block corresponding to the data block in the data block queue to the target communication driver corresponding to the communication driver information according to the scheduling strategy.
[0051] In a fourth aspect, an embodiment of the present application provides an electronic device, including: a processor, a memory, and a bus, wherein:
[0052] The processor and memory communicate with each other through the bus;
[0053] The memory stores program instructions that can be executed by the processor, and the processor calls the program instructions to execute the method of the first aspect or the second aspect.
[0054] In a fifth aspect, an embodiment of the present application provides a non-transitory computer-readable storage medium, including:
[0055] The non-transitory computer-readable storage medium stores computer instructions, and the computer instructions enable a computer to execute the method of the first aspect or the second aspect.
[0056] In a sixth aspect, an embodiment of the present application provides a data communication system, including an application layer, a communication scheduling layer and a driver layer; wherein:
[0057] The application layer includes application programs, which are used to generate data blocks and send data blocks to the communication scheduling layer;
[0058] The communication scheduling layer is used to execute the method described in the first aspect;
[0059] The driver layer includes a communication driver, and the communication driver is used to receive the communication data sent by the communication scheduling layer and send the communication data.
[0060] In the embodiment of the present application, a communication scheduling layer is introduced into the data communication system, and the communication scheduling layer is responsible for the transmission of data generated by the application program, thereby reducing the negative impact of the short-term transmission of multiple data on the system operation.
[0061] Other features and advantages of the present application will be described in the following description, and partly become apparent from the description, or be understood by practicing the embodiments of the present application. The purpose and other advantages of the present application can be realized and obtained by the structures specifically pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0063] Figure 1 A schematic diagram of a data communication method flow provided in an embodiment of the present application;
[0064] Figure 2 A schematic diagram of a data queue structure provided in an embodiment of the present application;
[0065] Figure 3 A schematic diagram of a time gap provided in an embodiment of the present application;
[0066] Figure 4 A schematic diagram of a data transmission method provided in an embodiment of the present application;
[0067] Figure 5 A schematic diagram of another data communication method flow chart provided in an embodiment of the present application;
[0068] Figure 6 A schematic diagram of the structure of a data communication device provided in an embodiment of the present application;
[0069] Figure 7 A schematic diagram of the physical structure of an electronic device provided in an embodiment of the present application;
[0070] Figure 8 A schematic diagram of the structure of a data communication system provided in an embodiment of the present application. DETAILED DESCRIPTION
[0071] The following embodiments of the technical solution of the present application are described in detail in conjunction with the accompanying drawings. The following embodiments are only used to more clearly illustrate the technical solution of the present application, and are therefore only used as examples, and cannot be used to limit the scope of protection of the present application.
[0072] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by technicians in the technical field to which this application belongs; the terms used herein are only for the purpose of describing specific embodiments and are not intended to limit this application; the terms "including" and "having" in the specification and claims of this application and the above-mentioned figure descriptions and any variations thereof are intended to cover non-exclusive inclusions.
[0073] In the description of the embodiments of the present application, the technical terms "first", "second", etc. are only used to distinguish different objects, and cannot be understood as indicating or implying relative importance or implicitly indicating the number, specific order or primary and secondary relationship of the indicated technical features. In the description of the embodiments of the present application, the meaning of "multiple" is more than two, unless otherwise clearly and specifically defined.
[0074] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0075] In the description of the embodiments of the present application, the term "and / or" is only a description of the association relationship of the associated objects, indicating that there may be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.
[0076] In the description of the embodiments of the present application, the term "multiple" refers to more than two (including two). Similarly, "multiple groups" refers to more than two groups (including two groups), and "multiple pieces" refers to more than two pieces (including two pieces).
[0077] In the description of the embodiments of the present application, unless otherwise clearly specified and limited, technical terms such as "installed", "connected", "connected", "fixed" and the like should be understood in a broad sense. For example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, and it can be the internal connection of two elements or the interaction relationship between two elements. For those of ordinary skill in the art, the specific meanings of the above terms in the embodiments of the present application can be understood according to the specific circumstances.
[0078] At present, automation technology is becoming more and more mature, and all walks of life are inseparable from business systems. The functions implemented by business systems corresponding to different industries are different. As the scale of business systems becomes larger and larger, their performance requirements become higher and higher, and the communication data volume and real-time requirements between modules in the business system are also greatly increased. In the traditional communication architecture, the application software stores the required data in the cache, such as in the FIFO memory, and then each communication driver reads the data from the cache and sends it according to the busy and idle status of its interface. In addition, the communication driver is also the same when receiving data. Usually, the communication driver moves the data after receiving the terminal and sends the data to the application.
[0079] Since each communication driver in the business system works on its own, that is, when a communication driver has data to send or receive, it will occupy CPU resources to send or receive data. During the process of data sending or receiving by the communication driver, other communication drivers cannot transmit data. In the case where the communication driver has a large amount of data to send, other communication drivers need to wait. If the timeliness of the data that other communication drivers need to transmit is high, the data will not be transmitted in time, which may cause system failure. In addition, when receiving data, if there is a large amount of data in a short period of time, the existing solution will frequently generate interruptions, and the priority of the interruption is usually higher than the priority of the operating system task. Frequent interruptions of applications may occur, resulting in the inability to execute high real-time tasks in time, thereby affecting the stability of the business system.
[0080] In order to solve the above technical problems, the embodiments of the present application provide a data communication method, device, electronic device, storage medium and system. By uniformly scheduling the data sent by the application, the application does not directly call the communication driver to send and receive data, thereby improving the stability of data transmission and further improving the stability of business system operation.
[0081] It is understandable that the business system provided in the embodiment of the present application may specifically be an energy storage valve control system, or may be a system in other application fields, such as: power dispatching system, smart grid system, energy management system, bank core system, e-commerce platform, etc. The embodiment of the present application is described with the business system being an energy storage valve control system as a specific application scenario.
[0082] Figure 1 A data communication method flow chart provided in an embodiment of the present application is as follows: Figure 1 As shown, the method includes:
[0083] Step 101: Acquire a data block of an application program, the data block including communication data and communication driver information;
[0084] Step 102: storing the data block in the data block queue;
[0085] Step 103: sending the communication data corresponding to the data block in the data block queue to the target communication driver corresponding to the communication driver information according to the scheduling strategy.
[0086] In step 101, it can be understood that the subject that executes the method described in the embodiment of the present application can be a communication scheduling layer, that is, a communication scheduling layer is set on the business system; the communication scheduling layer is set between the application and the communication driver, and is mainly used for the management and allocation of communication resources. That is, the transmission of data generated by the application is uniformly managed, and the data received in the communication driver is uniformly managed. The specific functions of the communication scheduling layer are described below. Of course, the method of the embodiment of the present application can also be implemented by other functional modules. For the convenience of description, the following embodiments are described with the communication scheduling layer in the business system as the execution subject.
[0087] Data communication is required between multiple applications within the business system. Therefore, when an application needs to send communication data through the corresponding communication driver, it can assemble the generated communication data and the parameters related to the communication data to obtain a data block. Therefore, the data block may include communication data and communication driver information. Among them, communication data refers to data that needs to be sent through the communication driver. Communication driver information refers to information used to represent the communication driver, for example: it can be the name of the communication driver, the ID of the communication driver, etc. The purpose of adding communication driver information in the data block is to allow the communication scheduling layer to send the communication data to the corresponding communication driver.
[0088] In step 102, the data block queue is a first-in-first-out linear table. After receiving the data block, the communication scheduling layer can store the data block in the data block queue according to the time sequence of the data block sent by the received application. It can be understood that there can be one or more data block queues.
[0089] In step 103, the scheduling strategy refers to a strategy for determining the communication data sending time corresponding to the data block in the data block queue, which can be preset according to actual conditions. The communication scheduling layer selects the data block to be sent from the data block queue according to the scheduling strategy, and sends the communication data contained in the selected data block to the specified target communication driver.
[0090] The embodiment of the present application stores the data that needs to be transmitted generated by the application in the form of data blocks in a data block queue for unified scheduling. Compared with the existing solution, the application directly communicates data with the communication driver and the communication driver seizes CPU resources. The method of the embodiment of the present application uses a scheduling strategy to orderly send the communication data corresponding to the data blocks in the data block queue to the corresponding target communication driver, thereby reducing the situation where the communication driver seizes CPU resources according to its own priority, allowing the communication data to be processed in a timely manner, improving the stability of data transmission, and thereby improving the stability of system operation.
[0091] On the basis of the above embodiment, when writing a data block into a data queue, the data block may be stored in a data queue of a corresponding priority according to the priority information.
[0092] In the specific implementation process, the application can also specify the priority information of the data block when generating the data block. The priority information is used to determine the urgency of the corresponding communication data to be sent. Priority information can include high priority, medium priority and low priority, wherein the higher the priority, the faster the corresponding communication data needs to be sent. It is understandable that the priority information can also include more or fewer levels of priority, which can be set in advance according to actual conditions. In addition, in addition to using high, medium and low to divide the priority information, other division methods can also be used, as long as different levels of priority can be distinguished. For example, numbers can be used for division, and different data represent different priorities. English letters can also be used for division. Similarly, different English letters represent different priorities.
[0093] It is understandable that the communication scheduling layer can set a corresponding number of data queues according to the priority information of the data block. For example, when the priority information includes high priority, medium priority and low priority, the communication scheduling layer can set three data queues, namely, a high priority data queue, a medium priority data queue and a low priority data queue. The communication scheduling layer stores the received high priority data block in the high priority data queue, stores the medium priority data block in the medium priority data queue, and stores the low priority data block in the low priority data queue. Figure 2 A schematic diagram of a data queue structure provided in an embodiment of the present application is shown in FIG. Figure 2 shown.
[0094] The embodiment of the present application stores data blocks according to their priority information. The priority of a data block is positively correlated with the timeliness of the data block. When processing data, data in a high-priority data block queue is processed first, so that high-priority communication data can be processed in a timely manner, thereby improving the stability of the system.
[0095] In another embodiment, the communication scheduling layer can also set data queues according to the priority information of the data block and the communication driver. For example, the priority information includes high priority, medium priority and low priority; the communication driver includes a serial communication driver, a network communication driver and a USB communication driver. The communication scheduling layer can set a high priority data queue, a medium priority data queue and a low priority data queue corresponding to the serial communication driver; a high priority data queue, a medium priority data queue and a low priority data queue corresponding to the network communication driver; and a high priority data queue, a medium priority data queue and a low priority data queue corresponding to the USB communication driver.
[0096] In another embodiment, the communication scheduling layer can also set a corresponding data queue according to the communication driver, for example, the communication driver includes a serial communication driver, a network communication driver, and a USB communication driver. The communication scheduling layer can set a data queue corresponding to the serial communication driver, a data queue corresponding to the network communication driver, and a data queue corresponding to the USB communication driver.
[0097] On the basis of the above embodiment, sending the communication data corresponding to the data block in the data block queue to the target communication driver corresponding to the communication driver information according to the scheduling strategy includes:
[0098] Based on the priority of the data queue, obtain the data block to be processed from the data queue;
[0099] The communication data corresponding to the data block to be processed is sent to the target communication driver corresponding to the communication driver information.
[0100] In a specific implementation process, the priority of a data queue corresponds to the priority information of a data block stored in the data queue, that is, a high-priority data block is stored in a high-priority data queue, a medium-priority data block is stored in a medium-priority data queue, and a low-priority data block is stored in a low-priority data queue. The communication scheduling layer may preferentially select a data block from a high-priority data queue. If the high-priority data queue is not empty, the data block may be obtained as a data block to be processed according to the first-in-first-out principle. If the high-priority data queue is empty, the data block is obtained from the medium-priority data queue, and so on.
[0101] After obtaining the data block to be processed, the communication scheduling layer can parse the data block to obtain the communication data and communication driver information corresponding to the data block to be processed. The communication scheduling layer determines the target communication driver according to the communication driver information and sends the communication data to the target communication driver.
[0102] The embodiment of the present application processes the data blocks according to the priority of the data queue. Since the higher the priority, the higher the timeliness of the data, the data with high priority is processed first, thereby improving the orderliness of data processing and further improving the stability of system operation.
[0103] On the basis of the above embodiment, the communication scheduling layer sends the communication data corresponding to the data block to be processed to the target communication driver corresponding to the communication driver information, including at least one of the following situations:
[0104] (1) If the working state of the target communication driver is an idle state, the communication data corresponding to the data block to be processed is sent to the target communication driver.
[0105] In the specific implementation process, the working state of the communication driver includes an idle state and a busy state, wherein the idle state means that the communication driver is not currently processing data transmission, and the busy state means that the communication driver is currently processing data transmission. When the communication driver is in an idle state, it can receive data to be processed. Therefore, after the communication scheduling layer obtains the data block to be processed from the data block queue, it parses the data block to be processed, obtains the corresponding communication driver information and communication data, and queries the working state of the corresponding target communication driver based on the communication driver information. If the working state is an idle state, the communication data obtained by parsing is sent to the target communication driver. After receiving the communication data, the target communication driver sends the communication data.
[0106] (2) If the working state of the target communication driver is busy, the data block to be processed is put back into the original data queue, and based on the priority of the data queue, the next data block to be processed is obtained from the data queue;
[0107] If the working state of the target communication driver corresponding to the next data block to be processed is an idle state, the communication data corresponding to the next data block to be processed is sent to the target communication driver corresponding to the next data block to be processed.
[0108] In the specific implementation process, the communication scheduling layer determines that the working state of the target communication driver is busy based on the communication driver information, which means that the target communication driver is currently processing other data and cannot process the communication data in the data block to be processed. In order to improve the success rate of communication data transmission and improve the efficiency of processing data blocks in the data queue, the communication scheduling layer puts the data block to be processed back into the original data queue. Among them, the original data queue refers to the data queue where the data block to be processed is located before it is taken out. For example, if the data block to be processed is obtained by the communication scheduling layer from a high-priority data queue, then the data block to be processed is put back into the high-priority data queue. It can be understood that the data block to be processed can be placed at the tail of the original data queue or at the head of the original data queue.
[0109] For the case where the data is placed at the tail and the original data queue is a high-priority data queue, the communication scheduling layer can re-acquire the next data block to be processed according to the scheduling strategy, that is, determine whether there are other data blocks in the high-priority data queue. It can be understood that other data blocks refer to data blocks other than the returned data blocks. If there are, the communication scheduling layer obtains the next data block to be processed from the head of the high-priority data queue. If there are no other data blocks in the high-priority data queue, the communication scheduling layer obtains the next data block to be processed from the head of the second-highest priority data queue. According to the above process, it is determined whether the working state of the target communication driver corresponding to the next data block to be processed is an idle state. If it is an idle state, the communication data in the next data block to be processed is sent to the communication driver corresponding to the next data block to be processed. If the working state of the communication driver corresponding to the next data block to be processed is still a busy state, it is processed according to the method described in the above embodiment.
[0110] For the case where the data is placed at the head and the original data queue is a high-priority data queue, the communication scheduling layer can re-acquire the next data block to be processed according to the scheduling strategy, that is, determine whether there are other data blocks in the high-priority data queue. It can be understood that other data blocks refer to data blocks other than the returned data blocks. If there are, the communication scheduling layer obtains the next data block to be processed from the head of the high-priority data queue except the returned data blocks. If there are no other data blocks in the high-priority data queue, the communication scheduling layer obtains the next data block to be processed from the head of the second-highest priority data queue. According to the above process, determine whether the working state of the target communication driver corresponding to the next data block to be processed is an idle state. If it is an idle state, send the communication data in the next data block to be processed to the communication driver corresponding to the next data block to be processed. If the working state of the communication driver corresponding to the next data block to be processed is still a busy state, it is processed according to the method described in the above embodiment.
[0111] In an embodiment of the present application, whether to send communication data to the target communication driver is determined based on the busy or idle state of the target communication driver, so that for a communication driver in a busy state, communication data is temporarily not sent to it. On the one hand, this reduces the load on the communication driver, and on the other hand, it allows the idle communication driver to receive the data to be processed as quickly as possible, making the load on the communication driver more evenly distributed and improving the success rate of communication data sending.
[0112] On the basis of the above embodiment, sending the communication data corresponding to the data block to be processed to the target communication driver corresponding to the communication driver information includes:
[0113] Counting the cumulative duration of the data blocks sent in the data sending time slot corresponding to the current moment; wherein the data sending time slot is a time period for sending data blocks obtained by pre-dividing time;
[0114] If the accumulated duration is less than the data transmission time slot corresponding to the current moment, the communication scheduling layer sends the communication data corresponding to the data block to be processed to the target communication driver corresponding to the communication driver information.
[0115] In the specific implementation process, Figure 3 A time interval schematic diagram provided in an embodiment of the present application, such as Figure 3 As shown. In order to improve the stability of system operation, the time can be divided in advance to obtain multiple time slots, each of which has a corresponding action processing time. For example, a time slot may include a data receiving time slot, a data processing time slot and a data sending time slot. That is, a time slot can be divided to obtain a time period for data reception, a time period for data processing and a time period for data sending. It can be understood that the division of the time slot can adopt a microsecond time interval, which is generated by a device with higher precision (for example: FPGA, etc.). The time slot can be 50 microseconds, and the FPGA generates an interrupt every 50 microseconds. It should be noted that the specific length of the time slot and the division of the time slot can be set according to the actual situation. For example, a 50 microsecond time slot can be divided into 0-15 microseconds as a data receiving time slot, 16-30 microseconds as a data processing time slot, and 31-50 microseconds as a data sending time slot.
[0116] For the data transmission time slot, which is used for data transmission, after the communication scheduling layer obtains the data block to be processed from the data queue, it counts the sum of the duration of the data block sent in the data transmission time slot corresponding to the current moment and the estimated duration required for sending the communication data corresponding to the data block to be processed, that is, the cumulative duration. The estimated duration can be estimated by the application based on the size of the communication data and the data transmission rate of the corresponding communication driver. If the cumulative duration is less than the data transmission time slot corresponding to the current moment, it means that the communication data corresponding to the data block to be processed can be sent out within the data transmission time slot. Therefore, the communication scheduling layer sends the communication data corresponding to the data block to be processed to the corresponding target communication driver.
[0117] If the accumulated duration is greater than or equal to the data transmission time slot corresponding to the current moment, it means that the communication data cannot be completely transmitted within the data transmission time slot, so the data transmission operation is terminated.
[0118] It can be understood that, in order to reduce the impact of data processing timeout, a protection time period can be set before and after each data operation time slot. It can be understood that the protection time period will also be counted in the time gap, that is, the sum of all protection time periods and the time slots corresponding to each data operation is a time gap. For example, a time gap is 50 microseconds, and the protection time period is set to 5 microseconds. There are 4 protection time periods in a time gap, and the data receiving time slot, data processing time slot and data sending time slot are all 10 microseconds. It should be noted that the specific duration of the protection time period and the time slot of each data operation can be preset.
[0119] In the embodiment of the present application, by performing data receiving operations in the data receiving time slot, processing data in the data processing time slot, and sending data in the data sending time slot, the impact of the data transmission process on task execution is reduced, and the stability of the data transmission process is improved. Figure 4 A data transmission method flow chart provided in an embodiment of the present application is as follows: Figure 4 As shown, the method includes:
[0120] Step 301: fetch the data block to be processed from the data queue; the communication scheduling layer selects the data queue for obtaining the data block to be processed according to the priority, and in the selected data queue, obtains the data block to be processed from the data queue according to the first-in-first-out principle.
[0121] Step 302: Query the working status of the communication driver corresponding to the data block to be processed; after obtaining the data block to be processed, the communication scheduling layer parses the data block to be processed to obtain the communication data, communication driver information and estimated duration contained in the data block to be processed. Among them, the communication data is the data that needs to be sent to the communication driver and sent out by the communication driver; the communication driver information is the information used to indicate the communication driver that receives the communication data, and the communication scheduling layer can determine the target communication driver through the communication driver information; the estimated duration is the duration required for the application to successfully send the communication data calculated based on the communication data and the target communication driver. After determining the target communication driver, the communication scheduling layer can query the working status of the target communication driver, which includes an idle state and a busy state.
[0122] Step 303: Determine whether the working status is busy; if the working status is busy, execute step 304; otherwise, execute step 305.
[0123] Step 304: put it back into the original data queue; the communication scheduling layer puts the data block to be processed back into the original data queue. For the specific operation method, please refer to the above embodiment.
[0124] Step 305: Accumulate the time according to the estimated time in the data block to be processed and the time required for the sent data; the communication scheduling layer accumulates the estimated time of the data block to be processed and the time required for the sent data to obtain the cumulative duration.
[0125] Step 306: Determine whether the data transmission time slot threshold is reached; determine whether the accumulated duration is less than the data transmission time slot threshold. If so, send the communication data in the data block to be processed to the corresponding target communication data, and continue to execute step 301; if not, end the data transmission action.
[0126] The embodiment of the present application divides time in advance to obtain multiple time slots, and performs corresponding operations in different time slots, so that data that needs to be transmitted in a short period of time or continuous burst communication can be dispersed in multiple time slots for processing, thereby improving the stability of data transmission and further improving the stability of system operation.
[0127] On the basis of the above embodiment, after sending the communication data in the data block to be processed to the target communication driver corresponding to the communication driver information, the method further includes:
[0128] Update the duration of the sent data based on the estimated sending duration.
[0129] In a specific implementation process, after the communication data in the data block to be processed is sent to the target communication driver, the communication scheduling layer adds the estimated sending duration to the duration of the sent data to obtain the new duration of the sent data. It can be understood that the duration of the sent data before the accumulation refers to the duration required for the data that has been sent before sending the communication data in the data block to be processed to the target communication driver.
[0130] In the embodiment of the present application, since the size of the data sending time slot is fixed, but the time required to send a communication data is not fixed, the cumulative duration of the sent data can be counted, thereby facilitating the determination of whether to terminate the data sending operation.
[0131] Based on the above embodiment, the method further includes:
[0132] If the first data queue includes a target data block to be processed whose waiting time is greater than the preset waiting time, the target data block to be processed is migrated from the first data queue to the second data queue; the priority of the first data queue is lower than that of the second data queue.
[0133] In the specific implementation process, since the communication scheduling layer takes the data blocks to be processed from the queue according to a certain rule, for example, the data queue is selected according to the priority, and the data blocks to be processed are determined by the "first in, first out" rule. In view of this situation, if high-priority data blocks often appear, there may be data blocks in the data queue with low priority that cannot be processed for a long time. In order to solve this problem, the embodiment of the present application upgrades the priority of the data blocks that cannot be processed for a long time, specifically: the communication scheduling layer can time the data blocks stored in the data queue to obtain the waiting time of each data block. When a data queue (the embodiment of the present application is called the first data queue) has a waiting time longer than the preset waiting time, it is called the target data block to be processed, and the target data block to be processed is migrated from the first data queue to the second data queue. It should be noted that the priority of the first data queue is lower than that of the second data queue. For example, the first data queue can be a low-priority data queue, and the second data queue can be a medium-priority data queue or a high-priority data queue.
[0134] The embodiment of the present application reduces the probability of data not being processed for a long time by increasing the priority of data blocks that have not been processed for a long time.
[0135] Based on the above embodiment, the method further includes:
[0136] The data to be received is obtained from the communication driver, and the data to be received is sent to a corresponding application program.
[0137] In a specific implementation, during the data reception process, the communication scheduling layer can query each communication driver whether there is data to be received. If there is data to be received in a communication driver, the communication scheduling layer obtains the data to be received and sends the data to be received to the corresponding application. It is understandable that the communication scheduling layer can query each communication driver at a preset time interval.
[0138] In order to improve the stability of system operation, the system divides the time in advance to obtain multiple time slots, each of which has a corresponding action processing time. For example, a time slot may include a data receiving time slot, a data processing time slot and a data sending time slot. That is, a time slot can be divided to obtain a time period for data reception, a time period for data processing and a time period for data sending. It can be understood that the division of the time slot can be in microsecond time intervals, which are generated by devices with higher precision (for example, FPGA, etc.). The time slot can be 50 microseconds, and the FPGA generates an interrupt every 50 microseconds. It should be noted that the specific length of the time slot and the division of the time slot can be set according to actual conditions. For example, a 50 microsecond time slot can be divided into 0-15 microseconds as a data receiving time slot, 16-30 microseconds as a data processing time slot, and 31-50 microseconds as a data sending time slot.
[0139] For the data receiving time slot, the communication scheduling layer polls each communication driver to obtain the data to be received.
[0140] The embodiment of the present application periodically receives data through the communication scheduling layer and sends the received data to the corresponding application. Compared with the existing solution of generating an interrupt as long as there is data to receive data, the embodiment of the present application reduces the impact on task execution.
[0141] Figure 5 A flow chart of another data communication method provided in an embodiment of the present application is as follows: Figure 5 As shown, the method includes:
[0142] Step 401: The communication scheduling layer receives a data block sent by the application layer, the data block including communication data and communication driving information. It is understandable that the data block may also include other information, such as the size of the communication data, the estimated transmission time, priority information, etc.
[0143] Step 402: The communication scheduling layer stores the data block in the data block queue; for one data block queue, the data block is stored at the end of the data queue. For multiple data queues with different priorities, the data block is stored in the data queue of the corresponding priority according to the priority information of the data block.
[0144] Step 403: If the current time is in the data transmission time slot, the communication scheduling layer obtains the data block to be processed from the data block queue, and sends the communication data corresponding to the data block in the data block queue to the target communication driver corresponding to the communication driver information according to the scheduling strategy; wherein the data transmission time slot is a time period for sending data blocks obtained by pre-dividing the time. It can be understood that the scheduling strategy can refer to the above embodiment, and will not be repeated here.
[0145] The embodiment of the present application performs unified scheduling of data that needs to be transmitted generated by the application through the communication scheduling layer, thereby improving the stability of data transmission and further improving the stability of system operation.
[0146] Figure 6 The present invention provides a schematic diagram of a data communication device structure, which may be a module, program segment or code on an electronic device. Figure 1 The method embodiment corresponds to and can be executed Figure 1 The various steps involved in the method embodiment and the specific functions of the device can be found in the above description. To avoid repetition, detailed description is appropriately omitted here. The device includes: a data block acquisition module 501, a cache module 502 and a sending module 503, wherein:
[0147] The data block acquisition module 501 is used to acquire the data block of the application program, the data block including communication data and communication drive information;
[0148] The cache module 502 is used to store the data block in the data block queue;
[0149] The sending module 503 is used to send the data block corresponding to the data block in the data block queue to the target communication driver corresponding to the communication driver information according to the scheduling strategy.
[0150] Based on the above embodiment, the cache module 502 is specifically used for:
[0151] The data block is stored in a data queue of corresponding priority according to the priority information.
[0152] Based on the above embodiment, the sending module 503 is specifically used for:
[0153] Based on the priority of the data queue, obtaining the to-be-processed data block from the data queue;
[0154] The communication data corresponding to the to-be-processed data block is sent to a target communication driver corresponding to the communication driver information.
[0155] Based on the above embodiment, the sending module 503 is specifically used for:
[0156] If the working state of the target communication driver is an idle state, sending the communication data corresponding to the to-be-processed data block to the target communication driver; and / or
[0157] If the working state of the target communication driver is busy, the to-be-processed data block is put back into the original data queue, and based on the priority of the data queue, the next to-be-processed data block is obtained from the data queue;
[0158] If the working state of the target communication driver corresponding to the next data block to be processed is an idle state, the communication data corresponding to the next data block to be processed is sent to the target communication driver corresponding to the next data block to be processed.
[0159] Based on the above embodiment, the sending module 503 is specifically used for:
[0160] The accumulated duration is calculated according to the duration of the data block sent in the data sending time slot corresponding to the current moment and the estimated duration corresponding to the data block to be processed; wherein the data sending time slot is a time period for sending data blocks obtained by pre-dividing time;
[0161] If the accumulated time length is less than the data sending time slot corresponding to the current moment, the communication data corresponding to the to-be-processed data block is sent to the target communication driver corresponding to the communication driver information.
[0162] Based on the above embodiment, the device further includes an updating module, which is used to:
[0163] The duration of the sent data is updated according to the estimated sending duration.
[0164] Based on the above embodiment, the device further includes a time slot division module, which is used to:
[0165] Preset the time interval for interrupt triggering; the time interval is the time interval between two adjacent interrupts;
[0166] The time gap is divided according to a preset division rule to obtain a plurality of sub-time slots, wherein different sub-time slots are used to perform different data operations.
[0167] Based on the above embodiment, the sub-time slots include: a data receiving time slot, a data processing time slot and a data sending time slot.
[0168] Based on the above embodiment, protection time periods are set before and after the data receiving time slot, the data processing time slot and the data sending time slot.
[0169] Based on the above embodiment, the device further includes a migration module, which is used to:
[0170] If the first data queue includes a target data block to be processed whose waiting time is greater than a preset waiting time, the target data block to be processed is migrated from the first data queue to the second data queue; the priority of the first data queue is lower than that of the second data queue.
[0171] Based on the above embodiment, the device further includes a data receiving module, which is used to:
[0172] The data to be received is obtained from the communication driver, and the data to be received is sent to a corresponding application program.
[0173] Figure 7 A schematic diagram of the physical structure of an electronic device provided in an embodiment of the present application, such as Figure 7 As shown, the electronic device includes: a processor (processor) 601, a memory (memory) 602 and a bus 603; wherein,
[0174] The processor 601 and the memory 602 communicate with each other via the bus 603;
[0175] The processor 601 is used to call the program instructions in the memory 602 to execute the methods provided by the above-mentioned method embodiments, for example, including: obtaining a data block of an application, the data block including communication data and communication driver information; storing the data block in a data block queue; and sending the communication data corresponding to the data block in the data block queue to a target communication driver corresponding to the communication driver information according to a scheduling strategy.
[0176] The processor 601 may be an integrated circuit chip with signal processing capabilities. The processor 601 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. It may implement or execute various methods, steps and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0177] The memory 602 may include but is not limited to random access memory (RAM), read only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable read-only memory (EEPROM), etc.
[0178] The present embodiment discloses a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the methods provided by the above-mentioned method embodiments, for example, including: obtaining a data block of an application, wherein the data block includes communication data and communication driver information; storing the data block in a data block queue; and sending the communication data corresponding to the data block in the data block queue to a target communication driver corresponding to the communication driver information according to a scheduling strategy.
[0179] The present embodiment provides a non-transitory computer-readable storage medium, which stores computer instructions, and the computer instructions enable the computer to execute the methods provided by the above-mentioned method embodiments, for example, including: obtaining a data block of an application, wherein the data block includes communication data and communication driver information; storing the data block in a data block queue; and sending the communication data corresponding to the data block in the data block queue to a target communication driver corresponding to the communication driver information according to a scheduling strategy.
[0180] Figure 8 A schematic diagram of a data communication system structure provided in an embodiment of the present application is shown in FIG. Figure 8 As shown, the system includes an application layer, a communication scheduling layer and a driver layer.
[0181] The application layer includes application programs, which are used to generate data blocks and send data blocks to the communication scheduling layer;
[0182] The communication scheduling layer mainly implements time slot management, data block management and communication decision; among them, time slot management is used for the communication scheduling layer to perform corresponding actions in the corresponding time slot. Data block management is used to receive data blocks sent by the application layer and cache them. Communication decision is used for the communication scheduling layer to obtain the data blocks to be processed from the data queue according to certain rules, and send the communication data in the data blocks to be processed to the corresponding target communication driver.
[0183] The driver layer includes a communication driver, which is used to receive the communication data sent by the communication scheduling layer and send the communication data. It is understandable that the communication driver includes but is not limited to: Ethernet driver, serial port driver, low-voltage differential signal (LVDS) communication driver, serial peripheral interface (SPI) communication driver and USB communication driver.
[0184] In the embodiment of the present application, a communication scheduling layer is introduced into the data communication system, and the communication scheduling layer is responsible for the transmission of data generated by the application program, thereby reducing the negative impact of the short-term transmission of multiple data on the system operation.
[0185] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0186] In addition, the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0187] Furthermore, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
[0188] In this document, relational terms such as first and second, etc. are used merely to distinguish one entity or operation from another entity or operation, but do not necessarily require or imply any such actual relationship or order between these entities or operations.
[0189] The above description is only an embodiment of the present application and is not intended to limit the protection scope of the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A data communication method, characterized in that: include: Acquire a data block of an application, wherein the data block includes communication data and communication driver information; Storing the data block in a data block queue; The communication data corresponding to the data block in the data block queue is sent to a target communication driver corresponding to the communication driver information according to a scheduling strategy.
2. The method according to claim 1, characterized in that The step of storing the data block in a data block queue comprises: The data block is stored in a data queue corresponding to the priority level according to the priority information.
3. The method according to claim 2, characterized in that The sending the communication data corresponding to the data block in the data block queue to the target communication driver corresponding to the communication driver information according to the scheduling strategy includes: Based on the priority of the data queue, obtaining a to-be-processed data block from the data queue; The communication data corresponding to the to-be-processed data block is sent to a target communication driver corresponding to the communication driver information.
4. The method according to claim 3, characterized in that: The sending the communication data corresponding to the to-be-processed data block to the target communication driver corresponding to the communication driver information includes: If the working state of the target communication driver is an idle state, sending the communication data corresponding to the to-be-processed data block to the target communication driver; and / or If the working state of the target communication driver is busy, the to-be-processed data block is put back into the original data queue, and based on the priority of the data queue, the next to-be-processed data block is obtained from the data queue; If the working state of the target communication driver corresponding to the next data block to be processed is an idle state, the communication data corresponding to the next data block to be processed is sent to the target communication driver corresponding to the next data block to be processed.
5. The method according to claim 3, characterized in that: The sending the communication data corresponding to the to-be-processed data block to the target communication driver corresponding to the communication driver information includes: The cumulative duration is calculated according to the duration of the data block sent in the data sending time slot corresponding to the current moment and the estimated sending duration corresponding to the data block to be processed; wherein the data sending time slot is a time period for sending data blocks obtained by dividing the time in advance; If the accumulated time length is less than the data sending time slot corresponding to the current moment, the communication data corresponding to the to-be-processed data block is sent to the target communication driver corresponding to the communication driver information.
6. The method according to claim 5, characterized in that After sending the communication data corresponding to the to-be-processed data block to the target communication driver corresponding to the communication driver information, the method further includes: The duration of the sent data is updated according to the estimated sending duration.
7. The method according to claim 5, characterized in that The method further comprises: Preset the time interval for interrupt triggering; the time interval is the time interval between two adjacent interrupts; The time gap is divided according to a preset division rule to obtain a plurality of sub-time slots, wherein different sub-time slots are used to perform different data operations.
8. The method according to claim 7, characterized in that The sub-time slots include: a data receiving time slot, a data processing time slot and a data sending time slot.
9. The method according to claim 8, characterized in that A protection time period is set before and after the data receiving time slot, the data processing time slot and the data sending time slot.
10. The method according to claim 2, characterized in that The method further comprises: If the first data queue includes a target data block to be processed whose waiting time is greater than a preset waiting time, the target data block to be processed is migrated from the first data queue to the second data queue; the priority of the first data queue is lower than that of the second data queue.
11. The method according to any one of claims 1 to 10, characterized in that: The method further comprises: The data to be received is obtained from the communication driver, and the data to be received is sent to the corresponding application program.
12. A data communication method, characterized in that: The method comprises: Receiving a data block sent by the application layer, wherein the data block includes communication data and communication drive information; Storing the data block in a data block queue; If the current moment is in a data sending time slot, obtain the data block to be processed from the data block queue, and send the communication data corresponding to the data block in the data block queue to the target communication driver corresponding to the communication driver information according to the scheduling strategy; wherein the data sending time slot is a time period for sending data blocks obtained by dividing the time in advance.
13. A data communication device, characterized in that: include: A data block acquisition module, used to acquire a data block of an application, wherein the data block includes communication data and communication drive information; A cache module, used for storing the data block in a data block queue; The sending module is used to send the data block corresponding to the data block in the data block queue to the target communication driver corresponding to the communication driver information according to the scheduling strategy.
14. An electronic device, characterized in that: include: processor, memory and bus, wherein, The processor and the memory communicate with each other via the bus; The memory stores program instructions executable by the processor, and the processor can execute the method according to any one of claims 1 to 12 by calling the program instructions.
15. A non-transitory computer-readable storage medium, characterized in that: The non-transitory computer-readable storage medium stores computer instructions, which, when executed by a computer, cause the computer to perform the method according to any one of claims 1 to 12.
16. A data communication system, characterized in that: It includes application layer, communication scheduling layer and driver layer; among which: The application layer includes an application program, and the application program is used to generate a data block and send the data block to the communication scheduling layer; The communication scheduling layer is used to execute the method according to any one of claims 1 to 9; The driver layer includes a communication driver, and the communication driver is used to receive communication data sent by the communication scheduling layer and send the communication data.
Citation Information
Cited By
Data communication method and apparatus, and electronic device, storage medium and system
EP4749460A1