A communication task scheduling and execution method and system based on priority queue

By adopting the priority queue-based communication task scheduling and execution method in the smart grid, the problem of increasing communication task volume and complex priority relationship in the smart grid is solved, and the normal and reliable execution of communication tasks, easy expansion and low coupling characteristics are achieved. .

CN114185653BActive Publication Date: 2025-02-21XJ ELECTRIC CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111316191.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-08
Publication Date
2025-02-21
Estimated Expiration
2041-11-08

AI Technical Summary

Technical Problem

The prior art is difficult to meet the problems of increasing communication tasks and complex priority relationships in smart power grids, and traditional multi-threaded and highly coupled communication methods cannot meet the requirements of easy expansion.

Method used

The communication task scheduling and execution method based on priority queue is adopted, and the priority comparison and scheduling of communication tasks is realized through the Task generator, priority comparator and Task executor to ensure that the tasks are executed according to priority.

Benefits of technology

It realizes the normal and reliable execution of communication tasks, meets the needs of programming and on-site monitoring, and ensures the easy-to-scaling and low-coupling characteristics of communication tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114185653B_ABST
    Figure CN114185653B_ABST
Patent Text Reader

Abstract

The present invention provides a communication task scheduling and execution method based on priority queue, comprising the following steps: the host computer UI process sends a command to the communication task scheduling process; the communication task scheduling process converts the command to binary data and sends it to the hardware platform; the hardware platform feeds back the data to the communication task scheduling process according to the received command; the communication task scheduling process receives the data and sends the data to the UI process for display by the UI. The present invention can meet the needs of programmers to conduct simulation experiments on the control protection program to verify the reliability of the program, meet the needs of on-site personnel to monitor the system, understand the operation of the system, the changes in the values ​​of key parameters in real time, etc., and ensure the normal and reliable execution of the communication task; the present invention can ensure the easy expansion and low coupling characteristics of the communication task. The present invention adopts a communication task scheduling and execution method based on the priority queue to realize the scheduling and expansion management of the communication task.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the field of direct current transmission control and protection, and in particular to a communication task scheduling and execution method and system based on a priority queue. Background Art

[0002] In recent years, with the development of smart grids, the required control commands, control and protection platform device status information, DC transmission system operation status information, etc. have continued to increase and expand, and the amount of communication tasks has continued to increase. Some communication tasks have clear sequence relationships, and some communication tasks have clear priority relationships. The current traditional multi-threaded and highly coupled communication methods can no longer meet the requirements of easy scalability. Summary of the invention

[0003] The object of the present invention is to provide a communication task scheduling and execution method and system based on priority queue.

[0004] To achieve the above object, the present invention provides a communication task scheduling and execution method based on a priority queue, characterized in that the method comprises the following steps:

[0005] Step 1: The host computer UI process sends the command to the communication task scheduling process;

[0006] Step 2: The communication task scheduling process converts the command into binary data and sends it to the hardware platform;

[0007] Step 3: The hardware platform feeds the data back to the communication task scheduling process according to the received command;

[0008] Step 4: The communication task scheduling process receives the data and sends the data to the UI process for display by the UI.

[0009] In a preferred embodiment, the communication task scheduling process performs the following operations:

[0010] Step 11: The Task generator in the communication task scheduling process receives the command sent by the UI process, and generates a Task instance according to the command;

[0011] Step 12: The Task instance is processed by the priority comparator, wherein the result of the processing includes one of the following: creating an auxiliary Task thread and executing the Task instance, terminating the Task task in the main Task thread and executing the Task task, or inserting the Task instance into a priority Task queue according to the priority.

[0012] Step 13: For the auxiliary Task thread task, after the execution is completed, the thread is terminated; for the main Task thread task, after the execution is completed, it sleeps for the Sleep time set, and then obtains a new Task task from the priority Task queue.

[0013] In a preferred embodiment, the Task generator is configured to perform the following operations:

[0014] Step 21: Determine the command type according to the command sent by the UI process;

[0015] Step 22: If it is determined that the command sent by the UI process is a composite command, a sub-Task task instance is created, and the sub-Task task is encapsulated to generate a composite Task task instance;

[0016] If the command sent by the UI process is determined to be a normal command, a Task instance is created;

[0017] Step 23: Set the priority, blocking mode and Task type of the Task instance.

[0018] In a preferred embodiment, the priority comparator is configured to perform the following operations:

[0019] Step 31: Determine whether the priority of the newly created Task instance is higher than or equal to the priority of the Task instance in the current main Task thread;

[0020] Step 32: If it is determined that the priority of the newly created Task instance is higher than or equal to the priority of the Task instance in the current main Task thread, then continue to determine whether the new Task instance is a temporary Task instance;

[0021] If it is determined that the priority of the newly created Task instance is lower than the priority of the Task instance in the current main Task thread, the newly created Task instance is inserted into the priority Task queue according to the priority of the newly created Task;

[0022] Step 33: If it is determined that the new Task instance is a temporary Task instance, create an auxiliary Task thread and execute the new Task instance;

[0023] If it is determined that the new Task instance is not a temporary Task instance, then determine whether the current main Task thread task is a composite Task;

[0024] Step 34: If it is determined that the current main Task thread task is a composite Task, the newly created Task instance is inserted into the priority Task queue according to the priority of the newly created Task;

[0025] If it is determined that the current main Task thread task is not a composite Task, the current main Task thread task is terminated, and the newly created Task task instance is set as the current Task task and executed.

[0026] In a preferred embodiment, the communication task scheduling process further includes a Task executor, wherein the Task executor is configured to perform the following operations:

[0027] Step 41: Get the task mode Mode, and determine whether the Mode is the send mode SendMode. If the Mode is determined to be SendMode, execute step 42; if the Mode is determined not to be SendMode, execute step 43;

[0028] Step 42: Encapsulate the commands and data to be sent to the hardware platform, set the Task Mode to the receiving mode RecieveMode, and send the encapsulated commands and data to the hardware platform;

[0029] Step 43: Receive the data sent by the hardware platform, first receive the data length, and according to the length of the received data, receive the data until it is received completely, then parse the data type, perform different parsing processes according to different data types, and finally send the parsed data to the UI process.

[0030] The present invention provides a communication task scheduling and execution system based on a priority queue, characterized in that the system includes a communication task scheduling process, wherein the communication task scheduling process is configured to perform the following operations:

[0031] Receive commands sent by the host computer UI process;

[0032] Convert the command into binary data and send it to the hardware platform;

[0033] Receive feedback data sent by the hardware platform;

[0034] Send the received feedback data to the UI process for display by the UI;

[0035] The communication task scheduling process includes: Task generator, priority comparator and Task executor.

[0036] In a preferred embodiment, the communication task scheduling process is further configured to perform the following operations:

[0037] Step 11: The Task generator in the communication task scheduling process receives the command sent by the UI process, and generates a Task instance according to the command;

[0038] Step 12: The Task instance is processed by the priority comparator, wherein the result of the processing includes one of the following: creating an auxiliary Task thread and executing the Task instance, terminating the Task task in the main Task thread and executing the Task task, or inserting the Task instance into a priority Task queue according to the priority.

[0039] Step 13: For the auxiliary Task thread task, after the execution is completed, the thread is terminated; for the main Task thread task, after the execution is completed, it sleeps for the Sleep time set, and then obtains a new Task task from the priority Task queue.

[0040] In a preferred embodiment, the Task generator is configured to perform the following operations:

[0041] Step 21: Determine the command type according to the command sent by the UI process;

[0042] Step 22: If it is determined that the command sent by the UI process is a composite command, a sub-Task task instance is created, and the sub-Task task is encapsulated to generate a composite Task task instance;

[0043] If the command sent by the UI process is determined to be a normal command, a Task instance is created;

[0044] Step 23: Set the priority, blocking mode and Task type of the Task instance.

[0045] In a preferred embodiment, the priority comparator is configured to perform the following operations:

[0046] Step 31: Determine whether the priority of the newly created Task instance is higher than or equal to the priority of the Task instance in the current main Task thread;

[0047] Step 32: If it is determined that the priority of the newly created Task instance is higher than or equal to the priority of the Task instance in the current main Task thread, then continue to determine whether the new Task instance is a temporary Task instance;

[0048] If it is determined that the priority of the newly created Task instance is lower than the priority of the Task instance in the current main Task thread, the newly created Task instance is inserted into the priority Task queue according to the priority of the newly created Task;

[0049] Step 33: If it is determined that the new Task instance is a temporary Task instance, create an auxiliary Task thread and execute the new Task instance;

[0050] If it is determined that the new Task instance is not a temporary Task instance, then determine whether the current main Task thread task is a composite Task;

[0051] Step 34: If it is determined that the current main Task thread task is a composite Task, the newly created Task instance is inserted into the priority Task queue according to the priority of the newly created Task;

[0052] If it is determined that the current main Task thread task is not a composite Task, the current main Task thread task is terminated, and the newly created Task task instance is set as the current Task task and executed.

[0053] In a preferred embodiment, the Task executor is configured to perform the following operations:

[0054] Step 41: Get the task mode Mode, and determine whether the Mode is the send mode SendMode. If the Mode is determined to be SendMode, execute step 42; if the Mode is determined not to be SendMode, execute step 43;

[0055] Step 42: Encapsulate the commands and data to be sent to the hardware platform, set the Task Mode to the receiving mode RecieveMode, and send the encapsulated commands and data to the hardware platform;

[0056] Step 43: Receive the data sent by the hardware platform, first receive the data length, and according to the length of the received data, receive the data until it is received completely, then parse the data type, perform different parsing processes according to different data types, and finally send the parsed data to the UI process.

[0057] Compared with the prior art, the present invention has the following advantages: the present invention can satisfy the needs of program designers to conduct simulation experiments on control protection programs to verify the reliability of the programs, and can satisfy the needs of on-site personnel to monitor the system and understand the operation status of the system, changes in the values ​​of key parameters, etc. in real time, thereby ensuring the normal and reliable execution of communication tasks; the present invention can ensure the easy expansion and low coupling characteristics of communication tasks, and the present invention adopts a communication task scheduling and execution method based on a priority queue to realize the scheduling and expansion management of communication tasks. BRIEF DESCRIPTION OF THE DRAWINGS

[0058] Figure 1 It is a schematic diagram of the communication between the present invention and the host computer and the device;

[0059] Figure 2 A schematic diagram of the communication task scheduling process of the present invention;

[0060] Figure 3 It is a schematic diagram of the Task generator of the present invention.

[0061] Figure 4 Schematic diagram of a priority comparator of the present invention.

[0062] Figure 5 It is a schematic diagram of the Task executor of the present invention. DETAILED DESCRIPTION

[0063] The specific implementation modes of the present invention are described in detail below in conjunction with the accompanying drawings, but it should be understood that the protection scope of the present invention is not limited by the specific implementation modes.

[0064] Unless explicitly stated otherwise, throughout the specification and claims, the term “comprise” or variations such as “include” or “comprising”, etc., will be understood to include the stated elements or components but not to exclude other elements or components.

[0065] Figure 1 Schematic diagram of the present invention communicating with the host computer and the device; Figure 1 As shown, the method of the present invention comprises the following steps:

[0066] Step 1: The host computer UI process sends the command to the communication task scheduling process;

[0067] Step 2: The communication task scheduling process converts the command into binary data and sends it to the hardware platform;

[0068] Step 3: The hardware platform feeds the data back to the communication task scheduling process according to the received command;

[0069] Step 4: The communication task scheduling process receives the data and sends the data to the UI process for display by the UI.

[0070] like Figure 2 As shown, the communication task scheduling process performs the following operations:

[0071] Step 11: The Task generator in the communication task scheduling process receives the command sent by the UI process, and generates a Task instance according to the command;

[0072] Step 12: The Task instance is processed by the priority comparator, wherein the result of the processing includes one of the following: creating an auxiliary Task thread and executing the Task instance, terminating the Task task in the main Task thread and executing the Task task, or inserting the Task instance into a priority Task queue according to the priority.

[0073] Step 13: For the auxiliary Task thread task, after the execution is completed, the thread is terminated; for the main Task thread task, after the execution is completed, it sleeps for the Sleep time set, and then obtains a new Task task from the priority Task queue (executed through the POPTask action).

[0074] like Figure 3 As shown, the Task generator is configured to do the following:

[0075] Step 21: Determine the command type according to the command sent by the UI process;

[0076] Step 22: If it is determined that the command sent by the UI process is a composite command, a sub-Task task instance is created, and the sub-Task task is encapsulated to generate a composite Task task instance;

[0077] If the command sent by the UI process is determined to be a normal command, a Task instance is created;

[0078] Step 23: Set the priority, blocking mode and Task type of the Task instance.

[0079] like Figure 4 As shown, the priority comparator is configured to perform the following operations:

[0080] Step 31: Determine whether the priority of the newly created Task instance is higher than or equal to the priority of the Task instance in the current main Task thread;

[0081] Step 32: If it is determined that the priority of the newly created Task instance is higher than or equal to the priority of the Task instance in the current main Task thread, then continue to determine whether the new Task instance is a temporary Task instance;

[0082] If it is determined that the priority of the newly created Task instance is lower than the priority of the Task instance in the current main Task thread, the newly created Task instance is inserted into the priority Task queue according to the priority of the newly created Task (through the insertion of the Task action, PushTask);

[0083] Step 33: If it is determined that the new Task instance is a temporary Task instance, create an auxiliary Task thread and execute the new Task instance (by creating and executing the Task action, CreateAndExecTask);

[0084] If it is determined that the new Task instance is not a temporary Task instance, then determine whether the current main Task thread task is a composite Task;

[0085] Step 34: If it is determined that the current main Task thread task is a composite Task, the newly created Task instance is inserted into the priority Task queue according to the priority of the newly created Task;

[0086] If it is determined that the current main Task thread task is not a composite Task, the current main Task thread task is terminated (by suspending and executing the Task action, SuspendAndExecTask), and the newly created Task task instance is set as the current Task task and executed.

[0087] like Figure 5 As shown, the Task executor is configured to perform the following operations:

[0088] Step 41: Get the task mode Mode, and determine whether the Mode is the send mode SendMode. If the Mode is determined to be SendMode, execute step 42; if the Mode is determined not to be SendMode, execute step 43;

[0089] Step 42: Encapsulate the commands and data to be sent to the hardware platform, set the Task Mode to the receiving mode RecieveMode, and send the encapsulated commands and data to the hardware platform;

[0090] Step 43: Receive the data sent by the hardware platform, first receive the data length, and according to the length of the received data, receive the data until it is received completely, then parse the data type, perform different parsing processes according to different data types, and finally send the parsed data to the UI process.

[0091] The present invention also provides a communication task low coupling expansion method, comprising:

[0092] Create a communication task interface class and design key interface functions: WorkSend(), WorkRecieved(), TaskDone() methods. Extend the communication task, create a new communication task class, inherit the communication task interface, and implement the abstract methods WorkSend(), WorkRecieved(), and TaskDone().

[0093] The present invention also provides a communication task low-coupling scheduling and execution system, the system comprising:

[0094] Task generator, which is used to instantiate a single communication task on the one hand, and to instantiate multiple communication tasks and encapsulate them into a composite communication task on the other hand, and to set the priority, blocking mode and type of the communication task instance;

[0095] A priority comparator is used to compare the priority of the communication task instance generated by the Task generator with the priority of the communication task instance being executed on the current main Task thread. If the priority of the communication task instance generated by the Task generator is less than the priority of the communication task instance being executed on the current main Task thread, PushTask is returned; if the priority of the communication task instance generated by the Task generator is greater than or equal to the priority of the communication task instance being executed on the current main Task thread, it is determined whether the type of the communication task instance generated by the Task generator is a temporary Task. If it is a temporary Task, CreateAndExecTask is returned; otherwise, whether the type of the communication task instance generated by the Task generator is a composite Task. If so, PushTask is returned; otherwise, SuspendAndExecTask is returned.

[0096] The communication task scheduling process is used to schedule the execution of communication tasks. If the priority comparator returns PushTask, the communication task instance generated by the Task generator is inserted into the priority Task queue according to the priority. If the priority comparator returns SuspendAndExecTask, the communication task being executed in the main Task thread is terminated and the communication task instance generated by the Task generator is executed. If the priority comparator returns CreateAndExecTask, an auxiliary Task thread is created to execute the communication task instance.

[0097] The main Task thread executor is used to execute the communication task. First, the Mode of the current communication task is determined. If the Mode is SendMode, the WorkSend() method of the communication task is executed. After the method is executed, the Mode is set to RecieveMode. If the Mode is RecieveMode, the WorkRecieved() method of the communication task is executed. If the execution is successful or abnormal, the TaskDone() method of the communication task is executed. After the current communication task is executed, the next communication task to be executed will be obtained from the communication task queue and executed.

[0098] In summary, the present invention provides a communication task scheduling and execution method based on priority queue, including the following steps: the host computer UI process sends a command to the communication task scheduling process; the communication task scheduling process converts the command into binary data and sends it to the hardware platform; the hardware platform feeds back the data to the communication task scheduling process according to the received command; the communication task scheduling process receives the data and sends the data to the UI process for display by the UI. The present invention can meet the needs of programmers to conduct simulation experiments on the control protection program to verify the reliability of the program, meet the needs of on-site personnel to monitor the system, understand the operation of the system, the changes in the values ​​of key parameters, etc. in real time, and ensure the normal and reliable execution of communication tasks; the present invention can ensure the easy expansion and low coupling characteristics of communication tasks. The present invention adopts a communication task scheduling and execution method based on priority queue to realize the scheduling and expansion management of communication tasks.

[0099] The foregoing description of specific exemplary embodiments of the present invention is for the purpose of illustration and demonstration. These descriptions are not intended to limit the present invention to the precise form disclosed, and it is clear that many changes and variations can be made based on the above teachings. The purpose of selecting and describing the exemplary embodiments is to explain the specific principles of the present invention and its practical application, so that those skilled in the art can realize and utilize various different exemplary embodiments of the present invention and various different selections and changes. The scope of the present invention is intended to be limited by the claims and their equivalents.

Claims

1. A communication task scheduling and execution method based on priority queue, characterized in that: The method comprises the following steps: Step 1: The host computer UI process sends the command to the communication task scheduling process; Step 2: The communication task scheduling process converts the command into binary data and sends it to the hardware platform; Step 3: The hardware platform feeds back the data to the communication task scheduling process according to the received command; Step 4: The communication task scheduling process receives the data and sends the data to the UI process for display by the UI; The communication task scheduling process performs the following operations: Step 11: The Task generator in the communication task scheduling process receives the command sent by the UI process, and generates a Task instance according to the command; Step 12: The Task instance is processed by the priority comparator, wherein the result of the processing includes one of the following: creating an auxiliary Task thread and executing the Task instance, terminating the Task task in the main Task thread and executing the Task task, or inserting the Task instance into a priority Task queue according to the priority. Step 13: For the auxiliary Task thread task, after the execution is completed, the thread is terminated; for the main Task thread task, after the execution is completed, it sleeps for the Sleep time set, and then obtains a new Task task from the priority Task queue; The Task builder is configured to do the following: Step 21: Determine the command type according to the command sent by the UI process; Step 22: If it is determined that the command sent by the UI process is a composite command, a sub-Task task instance is created, and the sub-Task task is encapsulated to generate a composite Task task instance; If the command sent by the UI process is determined to be a normal command, a Task instance is created; Step 23: Set the priority, blocking mode and Task type of the Task instance; The priority comparator is configured to perform the following operations: Step 31: Determine whether the priority of the newly created Task instance is higher than or equal to the priority of the Task instance in the current main Task thread; Step 32: If it is determined that the priority of the newly created Task instance is higher than or equal to the priority of the Task instance in the current main Task thread, then continue to determine whether the new Task instance is a temporary Task instance; If it is determined that the priority of the newly created Task instance is lower than the priority of the Task instance in the current main Task thread, the newly created Task instance is inserted into the priority Task queue according to the priority of the newly created Task; Step 33: If it is determined that the new Task instance is a temporary Task instance, create an auxiliary Task thread and execute the new Task instance; If it is determined that the new Task instance is not a temporary Task instance, then determine whether the current main Task thread task is a composite Task; Step 34: If it is determined that the current main Task thread task is a composite Task, the newly created Task instance is inserted into the priority Task queue according to the priority of the newly created Task; If it is determined that the current main Task thread task is not a composite Task, the current main Task thread task is terminated, and the newly created Task task instance is set as the current Task task and executed.

2. The communication task scheduling and execution method based on priority queue as claimed in claim 1, wherein: The communication task scheduling process further includes a Task executor, wherein the Task executor is configured to perform the following operations: Step 41: Get the task mode Mode, and determine whether the Mode is the send mode SendMode. If the Mode is determined to be SendMode, execute step 42; if the Mode is determined not to be SendMode, execute step 43; Step 42: Encapsulate the commands and data to be sent to the hardware platform, set the Task Mode to the receiving mode RecieveMode, and send the encapsulated commands and data to the hardware platform; Step 43: Receive the data sent by the hardware platform, first receive the data length, and according to the length of the received data, receive the data until it is received completely, then parse the data type, perform different parsing processes according to different data types, and finally send the parsed data to the UI process.

3. A communication task scheduling and execution system based on priority queue, characterized in that: The system includes a communication task scheduling process, wherein the communication task scheduling process is configured to perform the following operations: Receive commands sent by the host computer UI process; Convert the command into binary data and send it to the hardware platform; Receive feedback data sent by the hardware platform; Sending the received feedback data to the UI process for display by the UI; The communication task scheduling process includes: a task generator, a priority comparator and a task executor; The communication task scheduling process performs the following operations: Step 11: The Task generator in the communication task scheduling process receives the command sent by the UI process, and generates a Task instance according to the command; Step 12: The Task instance is processed by the priority comparator, wherein the result of the processing includes one of the following: creating an auxiliary Task thread and executing the Task instance, terminating the Task task in the main Task thread and executing the Task task, or inserting the Task instance into a priority Task queue according to the priority. Step 13: For the auxiliary Task thread task, after the execution is completed, the thread is terminated; for the main Task thread task, after the execution is completed, it sleeps for the Sleep time set, and then obtains a new Task task from the priority Task queue; The Task builder is configured to do the following: Step 21: Determine the command type according to the command sent by the UI process; Step 22: If it is determined that the command sent by the UI process is a composite command, a sub-Task task instance is created, and the sub-Task task is encapsulated to generate a composite Task task instance; If the command sent by the UI process is determined to be a normal command, a Task instance is created; Step 23: Set the priority, blocking mode and Task type of the Task instance; The priority comparator is configured to perform the following operations: Step 31: Determine whether the priority of the newly created Task instance is higher than or equal to the priority of the Task instance in the current main Task thread; Step 32: If it is determined that the priority of the newly created Task instance is higher than or equal to the priority of the Task instance in the current main Task thread, then continue to determine whether the new Task instance is a temporary Task instance; If it is determined that the priority of the newly created Task instance is lower than the priority of the Task instance in the current main Task thread, the newly created Task instance is inserted into the priority Task queue according to the priority of the newly created Task; Step 33: If it is determined that the new Task instance is a temporary Task instance, create an auxiliary Task thread and execute the new Task instance; If it is determined that the new Task instance is not a temporary Task instance, then determine whether the current main Task thread task is a composite Task; Step 34: If it is determined that the current main Task thread task is a composite Task, the newly created Task instance is inserted into the priority Task queue according to the priority of the newly created Task; If it is determined that the current main Task thread task is not a composite Task, the current main Task thread task is terminated, and the newly created Task task instance is set as the current Task task and executed.

4. The priority queue-based communication task scheduling and execution system as claimed in claim 3, wherein: The Task executor is configured to perform the following operations: Step 41: Get the task mode Mode, and determine whether the Mode is the send mode SendMode. If the Mode is determined to be SendMode, execute step 42; if the Mode is determined not to be SendMode, execute step 43; Step 42: Encapsulate the commands and data to be sent to the hardware platform, set the Task Mode to the receiving mode RecieveMode, and send the encapsulated commands and data to the hardware platform; Step 43: Receive the data sent by the hardware platform, first receive the data length, and according to the length of the received data, receive the data until it is received completely, then parse the data type, perform different parsing processes according to different data types, and finally send the parsed data to the UI process.

Citation Information

Patent Citations

  • Communication method of DVD (Digital Video Disk) movement decoding serial port

    CN102508805A

  • Task priority control implementation method and device for Spark JDBC

    CN109857535A