[go: up one dir, main page]
More Web Proxy on the site http://driver.im/

WO2021046932A1 - Message drive method and device based on real-time operating system - Google Patents

Message drive method and device based on real-time operating system Download PDF

Info

Publication number
WO2021046932A1
WO2021046932A1 PCT/CN2019/108381 CN2019108381W WO2021046932A1 WO 2021046932 A1 WO2021046932 A1 WO 2021046932A1 CN 2019108381 W CN2019108381 W CN 2019108381W WO 2021046932 A1 WO2021046932 A1 WO 2021046932A1
Authority
WO
WIPO (PCT)
Prior art keywords
message
business
task
real
operating system
Prior art date
Application number
PCT/CN2019/108381
Other languages
French (fr)
Chinese (zh)
Inventor
张聪
Original Assignee
北京东土科技股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 北京东土科技股份有限公司 filed Critical 北京东土科技股份有限公司
Publication of WO2021046932A1 publication Critical patent/WO2021046932A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/548Queue

Definitions

  • the present invention relates to the field of computer technology, and more specifically, to a message-driven method and device based on a real-time operating system.
  • RTOS Real Time Operation System
  • the processing system responds quickly, schedules all available resources to complete real-time tasks, and controls the operating system that runs all real-time tasks in a coordinated manner. Providing timely response and high reliability are its main features.
  • a real-time operating system is an operating system that guarantees the completion of specific functions within a certain time limit.
  • the real-time operating system is divided into hard real-time and soft real-time.
  • Hard real-time requires that the operation must be completed within the specified time, which is guaranteed during the design of the operating system; soft real-time, as long as the operation is completed as quickly as possible according to the priority of the task That's it.
  • the commonly used operating system can become a real-time operating system after a certain change. For example, an operating system can be designed to ensure that robots on the production line can acquire an object. In a "hard" real-time operating system, if the calculation to make the object reachable cannot be completed within the allowed time, the operating system will end due to an error.
  • the production line can still continue to work, but the output of the product will slow down because the product cannot arrive within the allowable time, which makes the robot temporarily non-production.
  • Some real-time operating systems are designed for specific applications, while others are general-purpose. Some general-purpose operating systems call themselves real-time operating systems. But to some extent, most general-purpose operating systems, such as Windows NT or IBM's OS/390, have the characteristics of a real-time system. This means that even if an operating system is not strictly a real-time system, they can also solve some real-time application problems.
  • the present invention provides a message-driven method and device based on a real-time operating system that overcomes the above-mentioned problems or at least partially solves the above-mentioned problems.
  • a message-driven method based on a real-time operating system including:
  • the business logic is transmitted based on the task message queue, so that the thread can process the business logic when the message is received.
  • the business logic includes processing business functions and function parameters.
  • obtaining the business data and business logic in the business message body specifically includes:
  • adding the business message body to the task message queue of the corresponding priority specifically includes:
  • the service data is put into different service messages, and based on the data priority, the service message body is put into the task message queue of the corresponding priority.
  • the real-time operating system sends the service message body to the task message queue through the task handle.
  • a message driving device based on a real-time operating system which includes a business scheduling task module and a task message queue module;
  • the business scheduling task module is used to obtain business data and business logic in a business message body, and based on the type of the business data, add the business message body to the task message queue of the corresponding priority;
  • the task message queue module is configured to transmit the business logic based on the task message queue for the thread to process the business logic when the message is received.
  • the task message queue module includes a plurality of message slots, and the message slots are used to accommodate business message bodies and execute the business logic to obtain business data corresponding to the business message.
  • the business scheduling task mold body is used to obtain the business message body in the message queue to be processed, and execute business functions, and extract business data and business logic;
  • the service data is put into different service messages, and based on the data priority, the service message body is put into the task message queue of the corresponding priority.
  • an electronic device including a memory, a processor, and a computer program stored in the memory and running on the processor.
  • a message-driven method based on a real-time operating system provided by any one of the possible implementations.
  • a non-transitory computer-readable storage medium on which a computer program is stored.
  • the computer program is executed by a processor, various possible implementation manners as in the first aspect are implemented.
  • a message-driven method based on a real-time operating system provided by any of the possible implementations.
  • the message-driven method and device based on the real-time operating system provided by the present invention add the business message body to the task message queue of the corresponding priority by acquiring the business data and business logic in the business message body, and based on the type of the business data Medium; Transmit the business logic based on the task message queue for the thread to process the business logic when the message is received.
  • Real-time operating system tasks support message queues, and realize that tasks only process messages in message queues; realize tasks and business programs are decoupled, and business programs are designed in two parts, one is business logic and the other is business data; business logic and business data source are separated Consider, realize the design of decoupling business logic and data; real-time operating system tasks support priority processing, and the messages in the corresponding message queue will obtain the processing business logic according to the corresponding priority.
  • Figure 1 is a schematic diagram of a message-driven flow of a real-time operating system in the prior art
  • FIG. 2 is a schematic diagram of a message-driven method based on a real-time operating system provided by an embodiment of the present invention
  • FIG. 3 is a schematic diagram of a specific flow of a message-driven method based on a real-time operating system provided by an embodiment of the present invention
  • FIG. 4 is a schematic diagram of the flow of processing business programs in the prior art by a message-driven method based on a real-time operating system provided by an embodiment of the present invention
  • FIG. 5 is a schematic diagram of the physical structure of an electronic device provided by an embodiment of the present invention.
  • Task Also called a thread, it is a simple program. Each task is given a certain priority, has its own set of CPU registers and its own stack space. Typically, each task is an infinite loop, and each task is in the following five states: dormant state, ready state, running state, suspended state, and interrupted state;
  • Task switching save the current state of the running task (all contents in the CPU register) in the task's own stack area, and then reload the current state of the next task to be run into the CPU register from the task stack. And start the operation of the next task;
  • Task priority divided into static priority with unchangeable priority and dynamic priority with changeable priority
  • RTOS Real Time Operation System
  • the processing system responds quickly, schedules all available resources to complete real-time tasks, and controls the operating system that runs all real-time tasks in a coordinated manner. Providing timely response and high reliability are its main features.
  • a real-time operating system is an operating system that guarantees the completion of specific functions within a certain time limit.
  • the real-time operating system is divided into hard real-time and soft real-time.
  • Hard real-time requires that the operation must be completed within the specified time, which is guaranteed during the design of the operating system; soft real-time, as long as the operation is completed as quickly as possible according to the priority of the task That's it.
  • the commonly used operating system can become a real-time operating system after a certain change.
  • RTOS Real-time operating system
  • Embedded small operating systems that are installed as part of micro-devices often require real-time operating systems. Some core issues can be considered to meet the requirements of real-time operating systems. However, because other components such as device drivers are usually required by special methods, a real-time operating system is usually larger than the core.
  • the main characteristics of real-time operating system RTOS include: one is real-time, reflecting the ability of real-time operating system to quickly respond to external events; the other is reliability, reflecting the ability of real-time operating system to maintain normal operation without external influence, usually based on system continuous and Reliable running time is measured; the third is security, which reflects the ability of the real-time operating system to resist external attacks and the defects of the application software itself; the fourth is openness, which reflects the real-time operating system’s compliance with international and national standards and whether it can be widely obtained by many third parties Basic conditions of support.
  • the preemptive multi-task real-time kernel based on priority is the core part of the real-time operating system. Its functions mainly include modules such as processor management, task scheduling, task synchronization, inter-task communication, interrupt processing, timer and memory management.
  • the famous VxWorks real-time kernel (Wind) mainly includes priority-based task scheduling, task synchronization and communication, interrupt processing, timers and memory management; ⁇ C/OS-II/III provides priority-based task scheduling and management , Task synchronization and communication, time management and interrupt service, memory management and other functions.
  • the RTOS kernel can basically be decomposed into three parts logically: the timing loop of the task, the ready logic of the task, and the switching of the task.
  • the timing loop of the task and the ready logic of the task can be realized by hardware, and the switching of the task Can be implemented by software. Therefore, the RTOS can be abstracted into a hardware real-time operating system (HRTOS, Hardware RTOS) and a software real-time operating system (SRTOS, Software RTOS).
  • HRTOS hardware real-time operating system
  • SRTOS Software RTOS
  • HRTOS mainly includes the timing loop of the task and the ready logic of the task, which is implemented by hardware.
  • SRTOS mainly includes task switching, which is realized by software.
  • Message is a basic and important concept in windows operating mechanism.
  • a message is a notification that reports the occurrence of an event.
  • the message-driven is developed around the generation and processing of the message, and is realized by the message loop mechanism.
  • a task is a running program. Data exchange between tasks is inevitable. The process of data exchange between tasks is called inter-task communication. Inter-task communication is An indispensable function in a real-time operating system. At present, there are two ways of communication between tasks commonly used in multi-task real-time operating systems: message mailbox and message queue.
  • the business programs are designed in two parts, one is business logic and the other is business data; the business logic and business data source are separated Separate considerations to realize the decoupling design of business logic and data; real-time operating system tasks support priority processing, and the messages in the corresponding message queue will be processed according to the corresponding priority.
  • the following will expand the description and introduction through a number of embodiments.
  • the embodiment of the present invention provides a message-driven method based on a real-time operating system, including:
  • the business logic is transmitted based on the task message queue, so that the thread can process the business logic when the message is received.
  • a real-time operating system is used for message driving, wherein the real-time operating system task supports a message queue, so that the task only processes messages in the message queue.
  • the business procedures are designed in two parts, one is business logic and the other is business data. Separate business logic and business data sources into consideration, and realize the design of decoupling business logic and data; operating system tasks support priority processing, and messages in the corresponding message queue will be processed according to the corresponding priority.
  • the business logic includes processing business functions and function parameters.
  • the task message body is divided into two parts, one is processing business logic, and the other is business data; wherein, the business logic includes processing business functions and function parameters, and the business logic function definition It is void Function(void*pArg).
  • the related task By putting the task message body into the task message slot, the related task will only execute the function of processing the business, and the business function will obtain the current business data.
  • obtaining the business data and business logic in the business message body specifically includes:
  • the real-time operating system task is responsible for obtaining the business message body in the message queue to be processed, and executing the business function to separate the task from the business logic. Separate business logic and business data sources into consideration, and realize the design of decoupling business logic and data.
  • adding the business message body to the task message queue of the corresponding priority specifically includes:
  • the service data is put into different service messages, and based on the data priority, the service message body is put into the task message queue of the corresponding priority.
  • the message queue to be processed includes service 1 message, service 2 message, service 3 message, and service 4 message.
  • the traditional message is to transmit data, and the system message queue is used, and the message team transmits data.
  • the message queue used by the message-driven framework is not to transmit message data, but to process business functions and function parameters. When a thread receives a message, it directly executes the business function. Since the implementation of the message-driven framework of this embodiment, the operating system has very few resources and only relies on semaphores and tasks (or threads) of the system. Unlike traditional messages, traditional messages rely on the message queue of the system.
  • the real-time operating system sends a service message body to the task message queue through a task handle.
  • the business scheduling task is mainly responsible for putting the business data into different business messages according to the type of business data, and putting the business message body into the relevant business message according to the data priority.
  • the real-time operating system task supports the message queue, and sends messages to the task through the task handle, and the message queue provides the priority of the message body.
  • a message-driven device based on a real-time operating system which adopts the message-driven method based on the real-time operating system in the foregoing embodiments, and includes a business scheduling task module and a task message queue module;
  • the business scheduling task module is used to obtain business data and business logic in a business message body, and based on the type of the business data, add the business message body to the task message queue of the corresponding priority;
  • the task message queue module is configured to transmit the business logic based on the task message queue for the thread to process the business logic when the message is received.
  • the task message queue module includes a plurality of message slots, and the message slots are used to accommodate business message bodies and execute the business logic to obtain the business corresponding to the business message. data.
  • the service scheduling task module is specifically configured to obtain the service message body in the message queue to be processed, execute the service function, and extract the service data and business logic;
  • the service data is put into different service messages, and based on the data priority, the service message body is put into the task message queue of the corresponding priority.
  • a message-driven device based on a real-time operating system including a business scheduling task module and a task message queue module;
  • the business scheduling task module is used to obtain business data and business logic in a business message body, and based on the type of the business data, add the business message body to the task message queue of the corresponding priority;
  • the task message queue module is configured to transmit the business logic based on the task message queue for the thread to process the business logic when the message is received.
  • the task message queue module includes a plurality of message slots, and the message slots are used to accommodate business message bodies and execute the business logic to obtain business data corresponding to the business message.
  • the business scheduling task mold body is used to obtain the business message body in the message queue to be processed, and execute business functions, and extract business data and business logic;
  • the service data is put into different service messages, and based on the data priority, the service message body is put into the task message queue of the corresponding priority.
  • the embodiment of the present invention provides an electronic device.
  • the device includes: a processor 501, a communication interface 502, a memory 503, and a communication bus 504.
  • the processor 501, the communication interface 502, and the memory 503 communicate with each other through the communication bus 504.
  • the processor 501 can call a computer program on the memory 503 and run on the processor 501 to execute the message-driven method based on the real-time operating system provided by the foregoing embodiments, for example, including:
  • the business logic is transmitted based on the task message queue, so that the thread can process the business logic when the thread receives the message.
  • the above-mentioned logic instructions in the memory 503 can be implemented in the form of a software functional unit and when sold or used as an independent product, they can be stored in a computer readable storage medium.
  • the technical solution of the present invention essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including Several instructions are used to make a computer device (which may be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the methods in the various embodiments of the present invention.
  • the aforementioned storage media include: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), magnetic disks or optical disks and other media that can store program codes. .
  • the embodiment of the present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored, and the computer program is implemented when executed by a processor to execute the message-driven method based on the real-time operating system provided by the foregoing embodiments. Examples include:
  • the business logic is transmitted based on the task message queue, so that the thread can process the business logic when the thread receives the message.
  • the message-driven method and device based on the real-time operating system obtain the business data and business logic in the business message body, and add the business message body to the business message body based on the type of the business data.
  • the business logic is transmitted based on the task message queue, so that the thread can process the business logic when the thread receives the message.
  • Real-time operating system tasks support message queues, and realize that tasks only process messages in message queues; realize tasks and business programs are decoupled, and business programs are designed in two parts, one is business logic and the other is business data; business logic and business data source are separated Consider, realize the design of decoupling business logic and data; real-time operating system tasks support priority processing, and the messages in the corresponding message queue will obtain the processing business logic according to the corresponding priority.
  • each implementation manner can be implemented by software plus a necessary general hardware platform, and of course, it can also be implemented by hardware.
  • the above technical solution essentially or the part that contributes to the existing technology can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM/RAM, magnetic A disc, an optical disc, etc., include several instructions to make a computer device (which may be a personal computer, a server, or a network device, etc.) execute each embodiment or some part of the method of the embodiment.
  • the present invention provides a message-driven method and device based on a real-time operating system, which overcomes the need for different priority tasks to be processed by different business programs, causing the business programs to be unable to process business operating system task priorities in real time according to business data.
  • the problem has practical application value in industry.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer And Data Communications (AREA)
  • Telephonic Communication Services (AREA)

Abstract

The present invention provides a message drive method and device based on a real-time operating system. By means of obtaining service data and service logic in a service message body, on the basis of the type of said service data, the service message body is added to a task message queue of a corresponding priority; the service logic is transmitted on the basis of the task message queue, so that a thread processes the service logic when the message is received. A real-time operating system task supports message queuing, such that the task processes only messages in a message queue; tasks and service procedures are decoupled, the service message body is designed in two parts, one part being service logic and the other part being service data; the service logic is separated from the service data source, such that the service logic and data are decoupled; the real-time operating system task supports priority processing, and messages in a corresponding message queue obtain a processing service logic according to the corresponding priority.

Description

基于实时操作系统的消息驱动方法和装置Message driving method and device based on real-time operating system
本申请要求于2019年9月12日提交中国专利局、申请号为201910866180.4、发明名称为"基于实时操作系统的消息驱动方法和装置"的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of a Chinese patent application filed with the Chinese Patent Office on September 12, 2019, the application number is 201910866180.4, and the invention title is "message-driven method and device based on real-time operating system", the entire content of which is incorporated by reference In this application.
技术领域Technical field
本发明涉及计算机技术领域,更具体地,涉及一种基于实时操作系统的消息驱动方法和装置。The present invention relates to the field of computer technology, and more specifically, to a message-driven method and device based on a real-time operating system.
背景技术Background technique
实时操作系统(Real Time Operation System,RTOS)是指当外界事件或数据产生时,能够接受并以足够快的速度予以处理,其处理的结果又能在规定的时间之内来控制生产过程或对处理系统做出快速响应,调度一切可利用的资源完成实时任务,并控制所有实时任务协调一致运行的操作系统。提供及时响应和高可靠性是其主要特点。Real Time Operation System (RTOS) means that when external events or data are generated, they can be accepted and processed at a sufficiently fast speed, and the results of the processing can control the production process or control the production process within a specified time. The processing system responds quickly, schedules all available resources to complete real-time tasks, and controls the operating system that runs all real-time tasks in a coordinated manner. Providing timely response and high reliability are its main features.
实时操作系统是保证在一定时间限制内完成特定功能的操作系统。实时操作系统有硬实时和软实时之分,硬实时要求在规定的时间内必须完成操作,这是在操作系统设计时保证的;软实时则只要按照任务的优先级,尽可能快地完成操作即可。通常使用的操作系统在经过一定改变之后就可以变成实时操作系统。例如,可以为确保生产线上的机器人能获取某个物体而设计一个操作系统。在“硬”实时操作系统中,如果不能在允许时间内完成使物体可达的计算,操作系统将因错误结束。在“软”实时操作系统中,生产线仍然能继续工作,但产品的输出会因产品不能在允许时间内到达而减慢,这使机器人有短暂的不生产现象。一些实时操作系统是为特定的应用设计的,另一些是通用的。一些通用目的的操作系统称自己为实时操作系统。但某种程度上,大部分通用目的的操作系统,如Windows NT或IBM的OS/390有实时系统的特征。这就是说,即使一个操作系统不是严格的实时系统,它们也能解决一部分实时应用问题。A real-time operating system is an operating system that guarantees the completion of specific functions within a certain time limit. The real-time operating system is divided into hard real-time and soft real-time. Hard real-time requires that the operation must be completed within the specified time, which is guaranteed during the design of the operating system; soft real-time, as long as the operation is completed as quickly as possible according to the priority of the task That's it. The commonly used operating system can become a real-time operating system after a certain change. For example, an operating system can be designed to ensure that robots on the production line can acquire an object. In a "hard" real-time operating system, if the calculation to make the object reachable cannot be completed within the allowed time, the operating system will end due to an error. In the "soft" real-time operating system, the production line can still continue to work, but the output of the product will slow down because the product cannot arrive within the allowable time, which makes the robot temporarily non-production. Some real-time operating systems are designed for specific applications, while others are general-purpose. Some general-purpose operating systems call themselves real-time operating systems. But to some extent, most general-purpose operating systems, such as Windows NT or IBM's OS/390, have the characteristics of a real-time system. This means that even if an operating system is not strictly a real-time system, they can also solve some real-time application problems.
现有的很多实时操作系统程序设计,业务程序和操作系统任务绑定非常紧密、业务模块之间耦合紧密,业务程序、业务数据、操作系统任务深度耦合,其业务程序的优先级取决操作系统任务,如图1中所示,不同优先级的任务需要通过不同的业务程序处理,造成业务程序不能根据业务数据,实时改变处理业务操作系统任务优先级。Many existing real-time operating system programs are designed, business programs and operating system tasks are very tightly bound, business modules are tightly coupled, and business programs, business data, and operating system tasks are deeply coupled. The priority of their business programs depends on the operating system tasks. , As shown in Figure 1, tasks with different priorities need to be processed by different business programs, causing business programs to be unable to change the priority of processing business operating system tasks in real time based on business data.
发明内容Summary of the invention
为了解决上述问题,本发明提供一种克服上述问题或者至少部分地解决上述问题的基于实时操作系统的消息驱动方法和装置。In order to solve the above-mentioned problems, the present invention provides a message-driven method and device based on a real-time operating system that overcomes the above-mentioned problems or at least partially solves the above-mentioned problems.
根据本发明实施例的第一方面,提供基于实时操作系统的消息驱动方法,包括:According to the first aspect of the embodiments of the present invention, a message-driven method based on a real-time operating system is provided, including:
获取业务消息体中业务数据和业务逻辑,基于所述业务数据的类型,将所述业务消息体添加至对应优先级的任务消息队列中;Obtain business data and business logic in the business message body, and add the business message body to the task message queue of the corresponding priority based on the type of the business data;
基于所述任务消息队列传输所述业务逻辑,以供线程接收到所述消息时处理所述业务逻辑。The business logic is transmitted based on the task message queue, so that the thread can process the business logic when the message is received.
作为优选的,所述业务逻辑包括处理业务函数和函数参数。Preferably, the business logic includes processing business functions and function parameters.
作为优选的,获取业务消息体中业务数据和业务逻辑,具体包括:Preferably, obtaining the business data and business logic in the business message body specifically includes:
获取待处理消息队列中的业务消息体,并执行业务函数,提取业务数据和业务逻辑。Obtain the business message body in the message queue to be processed, execute business functions, and extract business data and business logic.
作为优选的,基于所述业务数据的类型,将所述业务消息体添加至对应优先级的任务消息队列中,具体包括:Preferably, based on the type of the business data, adding the business message body to the task message queue of the corresponding priority specifically includes:
基于所述业务数据的类型,将所述业务数据放入不同业务消息中,并基于数据优先级,将所述业务消息体放入至对应优先级的任务消息队列中。Based on the type of the service data, the service data is put into different service messages, and based on the data priority, the service message body is put into the task message queue of the corresponding priority.
作为优选的,所述实时操作系统通过任务句柄向所述任务消息队列发送业务消息体。Preferably, the real-time operating system sends the service message body to the task message queue through the task handle.
根据本发明实施例的第二方面,提供了基于实时操作系统的消 息驱动装置,包括业务调度任务模块和任务消息队列模块;According to a second aspect of the embodiments of the present invention, a message driving device based on a real-time operating system is provided, which includes a business scheduling task module and a task message queue module;
所述业务调度任务模块,用于获取业务消息体中业务数据和业务逻辑,基于所述业务数据的类型,将所述业务消息体添加至对应优先级的任务消息队列中;The business scheduling task module is used to obtain business data and business logic in a business message body, and based on the type of the business data, add the business message body to the task message queue of the corresponding priority;
所述任务消息队列模块,用于基于所述任务消息队列传输所述业务逻辑,以供线程接收到所述消息时处理所述业务逻辑。The task message queue module is configured to transmit the business logic based on the task message queue for the thread to process the business logic when the message is received.
作为优选的,所述任务消息队列模块包括多个消息槽,所述消息槽用于容纳业务消息体,并执行所述业务逻辑,得到业务消息对应的业务数据。Preferably, the task message queue module includes a plurality of message slots, and the message slots are used to accommodate business message bodies and execute the business logic to obtain business data corresponding to the business message.
作为优选的,所述业务调度任务模具体用于获取待处理消息队列中的业务消息体,并执行业务函数,提取业务数据和业务逻辑;Preferably, the business scheduling task mold body is used to obtain the business message body in the message queue to be processed, and execute business functions, and extract business data and business logic;
基于所述业务数据的类型,将所述业务数据放入不同业务消息中,并基于数据优先级,将所述业务消息体放入至对应优先级的任务消息队列中。Based on the type of the service data, the service data is put into different service messages, and based on the data priority, the service message body is put into the task message queue of the corresponding priority.
根据本发明实施例的第三方面,提供了一种电子设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,处理器执行程序时实现如第一方面的各种可能的实现方式中任一种可能的实现方式所提供的基于实时操作系统的消息驱动方法。According to a third aspect of the embodiments of the present invention, there is provided an electronic device, including a memory, a processor, and a computer program stored in the memory and running on the processor. A message-driven method based on a real-time operating system provided by any one of the possible implementations.
根据本发明实施例的第四方面,提供了一种非暂态计算机可读存储介质,其上存储有计算机程序,该计算机程序被处理器执行时实现如第一方面的各种可能的实现方式中任一种可能的实现方式所提供的基于实时操作系统的消息驱动方法。According to a fourth aspect of the embodiments of the present invention, there is provided a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, various possible implementation manners as in the first aspect are implemented. A message-driven method based on a real-time operating system provided by any of the possible implementations.
本发明提供的基于实时操作系统的消息驱动方法和装置,通过获取业务消息体中业务数据和业务逻辑,基于所述业务数据的类型,将所述业务消息体添加至对应优先级的任务消息队列中;基于所述任务消息队列传输所述业务逻辑,以供线程接收到所述消息时处理所述业务逻辑。实时操作系统任务支持消息队列,实现任务只处理消息队列中的消息;实现任务与业务程序解耦,业务程序分成两部 分设计,一部分是业务逻辑,一部分业务数据;将业务逻辑与业务数据源分开考虑,实现业务逻辑与数据解耦设计;实时操作系统任务支持优先级处理,对应的消息队列中的消息会按照对应的优先级获得处理业务逻辑。The message-driven method and device based on the real-time operating system provided by the present invention add the business message body to the task message queue of the corresponding priority by acquiring the business data and business logic in the business message body, and based on the type of the business data Medium; Transmit the business logic based on the task message queue for the thread to process the business logic when the message is received. Real-time operating system tasks support message queues, and realize that tasks only process messages in message queues; realize tasks and business programs are decoupled, and business programs are designed in two parts, one is business logic and the other is business data; business logic and business data source are separated Consider, realize the design of decoupling business logic and data; real-time operating system tasks support priority processing, and the messages in the corresponding message queue will obtain the processing business logic according to the corresponding priority.
附图概述Brief description of the drawings
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍。显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些图获得其他的附图。In order to explain the embodiments of the present invention or the technical solutions in the prior art more clearly, the following will briefly introduce the drawings that need to be used in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained from these drawings without creative work.
图1为现有技术中实时操作系统消息驱动流程示意图;Figure 1 is a schematic diagram of a message-driven flow of a real-time operating system in the prior art;
图2为本发明实施例提供的基于实时操作系统的消息驱动方法示意图;2 is a schematic diagram of a message-driven method based on a real-time operating system provided by an embodiment of the present invention;
图3为本发明实施例提供的基于实时操作系统的消息驱动方法具体流程示意图;3 is a schematic diagram of a specific flow of a message-driven method based on a real-time operating system provided by an embodiment of the present invention;
图4为本发明实施例提供的基于实时操作系统的消息驱动方法处理现有技术中的业务程序流程示意图;FIG. 4 is a schematic diagram of the flow of processing business programs in the prior art by a message-driven method based on a real-time operating system provided by an embodiment of the present invention;
图5为本发明实施例提供的电子设备的实体结构示意图。FIG. 5 is a schematic diagram of the physical structure of an electronic device provided by an embodiment of the present invention.
本发明的实施方式Embodiments of the present invention
为使本发明实施例的目的、技术方案和优点更加清楚,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚地描述,显然,所描述的实施例是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。In order to make the objectives, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are the present invention. Invented some embodiments, but not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative work shall fall within the protection scope of the present invention.
任务:也称作一个线程,是一个简单的程序。每个任务被赋予一定的优先级,有它自己的一套CPU寄存器和自己的栈空间。典型地,每个任务都是一个无限的循环,每个任务都处在以下五个状态下:休眠态,就绪态,运行态,挂起态,被中断态;Task: Also called a thread, it is a simple program. Each task is given a certain priority, has its own set of CPU registers and its own stack space. Typically, each task is an infinite loop, and each task is in the following five states: dormant state, ready state, running state, suspended state, and interrupted state;
任务切换:将正在运行任务的当前状态(CPU寄存器中的全部内容)保存在任务自己的栈区,然后把下一个将要运行的任务的当前状态从该任务的栈中重新装入CPU的寄存器,并开始下一个任务的运行;Task switching: save the current state of the running task (all contents in the CPU register) in the task's own stack area, and then reload the current state of the next task to be run into the CPU register from the task stack. And start the operation of the next task;
任务优先级:分为优先级不可改变的静态优先级和优先级可改变的动态优先级;Task priority: divided into static priority with unchangeable priority and dynamic priority with changeable priority;
实时操作系统(Real Time Operation System,RTOS)是指当外界事件或数据产生时,能够接受并以足够快的速度予以处理,其处理的结果又能在规定的时间之内来控制生产过程或对处理系统做出快速响应,调度一切可利用的资源完成实时任务,并控制所有实时任务协调一致运行的操作系统。提供及时响应和高可靠性是其主要特点。Real Time Operation System (RTOS) means that when external events or data are generated, they can be accepted and processed at a sufficiently fast speed, and the results of the processing can control the production process or control the production process within a specified time. The processing system responds quickly, schedules all available resources to complete real-time tasks, and controls the operating system that runs all real-time tasks in a coordinated manner. Providing timely response and high reliability are its main features.
实时操作系统是保证在一定时间限制内完成特定功能的操作系统。实时操作系统有硬实时和软实时之分,硬实时要求在规定的时间内必须完成操作,这是在操作系统设计时保证的;软实时则只要按照任务的优先级,尽可能快地完成操作即可。通常使用的操作系统在经过一定改变之后就可以变成实时操作系统。A real-time operating system is an operating system that guarantees the completion of specific functions within a certain time limit. The real-time operating system is divided into hard real-time and soft real-time. Hard real-time requires that the operation must be completed within the specified time, which is guaranteed during the design of the operating system; soft real-time, as long as the operation is completed as quickly as possible according to the priority of the task That's it. The commonly used operating system can become a real-time operating system after a certain change.
实时操作系统(RTOS)要求:Real-time operating system (RTOS) requirements:
多任务;Multitasking;
处理能被区分优先次序的进程线;Process lines that can be prioritized;
一个中断水平的充份数量;A sufficient amount of interruption level;
被装入作为微型设备一部分的内含小操作系统经常要求实时操作系统。一些核心问题能被考虑以符合实时操作系统的需求。然而,因为像设备驱动程序这样的其他成份,也通常被特别的方法需要,一 个实时操作系统通常比核心更大。Embedded small operating systems that are installed as part of micro-devices often require real-time operating systems. Some core issues can be considered to meet the requirements of real-time operating systems. However, because other components such as device drivers are usually required by special methods, a real-time operating system is usually larger than the core.
实时操作系统RTOS主要特性包括:一是实时性,反映实时操作系统快速响应外部事件的能力;二是可靠性,反映实时操作系统能够保持正常运行而不受外界影响的能力,通常以系统连续并且可靠运行时间来度量;三是安全性,反映实时操作系统能够抵御外部攻击和应用软件自身缺陷的能力;四是开放性,反映实时操作系统符合国际和国家标准水平以及能否得到众多第三方广泛支持的基本条件。The main characteristics of real-time operating system RTOS include: one is real-time, reflecting the ability of real-time operating system to quickly respond to external events; the other is reliability, reflecting the ability of real-time operating system to maintain normal operation without external influence, usually based on system continuous and Reliable running time is measured; the third is security, which reflects the ability of the real-time operating system to resist external attacks and the defects of the application software itself; the fourth is openness, which reflects the real-time operating system’s compliance with international and national standards and whether it can be widely obtained by many third parties Basic conditions of support.
基于优先级实现抢占式的多任务实时内核是实时操作系统的核心部分。其功能主要包括处理器管理、任务调度、任务同步、任务间通信、中断处理、定时器和内存管理等模块。例如,著名的VxWorks实时内核(Wind)主要包括基于优先级的任务调度、任务同步和通信、中断处理、定时器和内存管理;μC/OS-II/III提供了基于优先级的任务调度与管理、任务间同步与通信、时间管理和中断服务、内存管理等功能。The preemptive multi-task real-time kernel based on priority is the core part of the real-time operating system. Its functions mainly include modules such as processor management, task scheduling, task synchronization, inter-task communication, interrupt processing, timer and memory management. For example, the famous VxWorks real-time kernel (Wind) mainly includes priority-based task scheduling, task synchronization and communication, interrupt processing, timers and memory management; μC/OS-II/III provides priority-based task scheduling and management , Task synchronization and communication, time management and interrupt service, memory management and other functions.
在RTOS内核中,从逻辑上基本上可以分解为三个部分:任务的定时循环、任务的就绪逻辑和任务的切换,其中,任务的定时循环和任务的就绪逻辑可以由硬件实现,任务的切换可以由软件实现。因此,可以把RTOS抽象为硬件实时操作系统(HRTOS,Hardware RTOS)和软件实时操作系统(SRTOS,Software RTOS)。其中,HRTOS主要包括任务的定时循环和任务的就绪逻辑,由硬件实现。SRTOS主要包括任务的切换,由软件实现。In the RTOS kernel, it can basically be decomposed into three parts logically: the timing loop of the task, the ready logic of the task, and the switching of the task. Among them, the timing loop of the task and the ready logic of the task can be realized by hardware, and the switching of the task Can be implemented by software. Therefore, the RTOS can be abstracted into a hardware real-time operating system (HRTOS, Hardware RTOS) and a software real-time operating system (SRTOS, Software RTOS). Among them, HRTOS mainly includes the timing loop of the task and the ready logic of the task, which is implemented by hardware. SRTOS mainly includes task switching, which is realized by software.
“消息”是windows运行机制中一个基本而又重要的概念。消息是一个报告事件发生的通知,消息驱动是围绕消息的产生与处理展开的,并依靠消息循环机制来实现。"Message" is a basic and important concept in windows operating mechanism. A message is a notification that reports the occurrence of an event. The message-driven is developed around the generation and processing of the message, and is realized by the message loop mechanism.
实时操作系统中运行着多个不同的任务,一个任务就是一个运行的程序,任务间不可避免的要进行数据的交换,这种任务间的数据交换过程被称为任务间通信,任务间通信是实时操作系统中不可缺少的 功能。目前在多任务实时操作系统中常用的任务间通信方式有消息邮箱和消息队列两种。There are many different tasks running in the real-time operating system. A task is a running program. Data exchange between tasks is inevitable. The process of data exchange between tasks is called inter-task communication. Inter-task communication is An indispensable function in a real-time operating system. At present, there are two ways of communication between tasks commonly used in multi-task real-time operating systems: message mailbox and message queue.
现有的很多实时操作系统程序设计,业务程序和操作系统任务绑定非常紧密、业务模块之间耦合紧密,业务程序、业务数据、操作系统任务深度耦合,其业务程序的优先级取决操作系统任务,如图1中所示,不同优先级的任务需要通过不同的业务程序处理,造成业务程序不能根据业务数据,实时改变处理业务操作系统任务优先级。因此,本发明实施例提供的基于实时操作系统的消息驱动方法和装置,实现任务与业务程序解耦,业务程序分成两部分设计,一部分是业务逻辑,一部分业务数据;将业务逻辑与业务数据源分开考虑,实现业务逻辑与数据解耦设计;实时操作系统任务支持优先级处理,对应的消息队列中的消息会按照对应的优先级获得处理业务逻辑。以下将通过多个实施例进行展开说明和介绍。Many existing real-time operating system programs are designed, business programs and operating system tasks are very tightly bound, business modules are tightly coupled, and business programs, business data, and operating system tasks are deeply coupled. The priority of their business programs depends on the operating system tasks. , As shown in Figure 1, tasks with different priorities need to be processed by different business programs, causing business programs to be unable to change the priority of processing business operating system tasks in real time based on business data. Therefore, the message-driven method and device based on the real-time operating system provided by the embodiments of the present invention realize the decoupling of tasks and business programs. The business programs are designed in two parts, one is business logic and the other is business data; the business logic and business data source are separated Separate considerations to realize the decoupling design of business logic and data; real-time operating system tasks support priority processing, and the messages in the corresponding message queue will be processed according to the corresponding priority. The following will expand the description and introduction through a number of embodiments.
如图2和图4中所示,本发明实施例提供基于实时操作系统的消息驱动方法,包括:As shown in FIG. 2 and FIG. 4, the embodiment of the present invention provides a message-driven method based on a real-time operating system, including:
获取业务消息体中业务数据和业务逻辑,基于所述业务数据的类型,将所述业务消息体添加至对应优先级的任务消息队列中;Obtain business data and business logic in the business message body, and add the business message body to the task message queue of the corresponding priority based on the type of the business data;
基于所述任务消息队列传输所述业务逻辑,以供线程接收到所述消息时处理所述业务逻辑。The business logic is transmitted based on the task message queue, so that the thread can process the business logic when the message is received.
在本实施例中,通过实时操作系统进行消息驱动,其中实时操作系统任务支持消息队列,实现任务只处理消息队列中的消息。实现任务与业务程序解耦,业务程序分成两部分设计,一部分是业务逻辑,一部分业务数据。将业务逻辑与业务数据源分开考虑,实现业务逻辑与数据解耦设计;操作系统任务支持优先级处理,对应的消息队列中的消息会按照对应的优先级获得处理业务逻辑。In this embodiment, a real-time operating system is used for message driving, wherein the real-time operating system task supports a message queue, so that the task only processes messages in the message queue. To realize the decoupling of tasks and business procedures, the business procedures are designed in two parts, one is business logic and the other is business data. Separate business logic and business data sources into consideration, and realize the design of decoupling business logic and data; operating system tasks support priority processing, and messages in the corresponding message queue will be processed according to the corresponding priority.
在上述实施例的基础上,所述业务逻辑包括处理业务函数和函数参数。On the basis of the foregoing embodiment, the business logic includes processing business functions and function parameters.
在本实施例中,作为一种优选的实施方式,任务消息体分为两部 分,一部分处理业务的逻辑,另一部分业务数据;其中,业务逻辑包括处理业务函数和函数参数,该业务逻辑函数定义为void Function(void*pArg)。In this embodiment, as a preferred implementation manner, the task message body is divided into two parts, one is processing business logic, and the other is business data; wherein, the business logic includes processing business functions and function parameters, and the business logic function definition It is void Function(void*pArg).
通过把任务消息体放入任务消息槽中,相关的任务会只执行处理业务的函数,并且业务函数获得到当前的业务数据。By putting the task message body into the task message slot, the related task will only execute the function of processing the business, and the business function will obtain the current business data.
在上述实施例的基础上,获取业务消息体中业务数据和业务逻辑,具体包括:On the basis of the foregoing embodiment, obtaining the business data and business logic in the business message body specifically includes:
获取待处理消息队列中的业务消息体,并执行业务函数,提取业务数据和业务逻辑。Obtain the business message body in the message queue to be processed, execute business functions, and extract business data and business logic.
在本实施例中,作为一种优选的实施方式,实时操作系统任务负责获得待处理消息队列中的业务消息体,并且执行业务函数,实现任务与业务逻辑分开。将业务逻辑与业务数据源分开考虑,实现业务逻辑与数据解耦设计。In this embodiment, as a preferred implementation manner, the real-time operating system task is responsible for obtaining the business message body in the message queue to be processed, and executing the business function to separate the task from the business logic. Separate business logic and business data sources into consideration, and realize the design of decoupling business logic and data.
在上述实施例的基础上,基于所述业务数据的类型,将所述业务消息体添加至对应优先级的任务消息队列中,具体包括:On the basis of the foregoing embodiment, based on the type of the business data, adding the business message body to the task message queue of the corresponding priority specifically includes:
基于所述业务数据的类型,将所述业务数据放入不同业务消息中,并基于数据优先级,将所述业务消息体放入至对应优先级的任务消息队列中。Based on the type of the service data, the service data is put into different service messages, and based on the data priority, the service message body is put into the task message queue of the corresponding priority.
在本实施例中,作为一种优选的实施方式,如图3和图4中所示,待处理消息队列包括业务1消息、业务2消息、业务3消息和业务4消息,在其他实施例中,可包括多个业务消息体;待处理消息队列中的业务消息体经业务调度任务处理后,获得消息队列中的消息,并且执行业务函数,实现任务与业务逻辑分开,根据业务数据分发消息,将消息添加到不同优先级的任务消息队列中。即图中消息队列1或消息队列2中,将任务消息体放入消息队列1或消息队列2的任务消息槽中,当线程/任务收到消息直接执行处理业务函数。In this embodiment, as a preferred implementation manner, as shown in FIG. 3 and FIG. 4, the message queue to be processed includes service 1 message, service 2 message, service 3 message, and service 4 message. In other embodiments, , Can include multiple business message bodies; after the business message body in the message queue to be processed is processed by the business scheduling task, the message in the message queue is obtained, and the business function is executed to separate the task from the business logic, and the message is distributed according to the business data. Add messages to task message queues of different priorities. That is, in message queue 1 or message queue 2 in the figure, the task message body is put into the task message slot of message queue 1 or message queue 2, and when the thread/task receives the message, it directly executes the processing business function.
传统消息是传输数据,采用系统消息队列,并且消息队传输数据, 在接收消息端有专用的线程读取数据,并且根据消息类型调用相应处理方法。而在本实施例中,消息驱动框架采用的消息队列中传递不是消息数据,而是处理业务函数、函数参数,当线程收到消息直接执行业务函数。本实施例的消息驱动框架实现以来操作系统资源非常少,仅依赖与系统的信号量和任务(或线程),与传统消息不一样,传统消息依赖系统的消息队列。The traditional message is to transmit data, and the system message queue is used, and the message team transmits data. There is a dedicated thread at the receiving message end to read the data and call the corresponding processing method according to the message type. In this embodiment, the message queue used by the message-driven framework is not to transmit message data, but to process business functions and function parameters. When a thread receives a message, it directly executes the business function. Since the implementation of the message-driven framework of this embodiment, the operating system has very few resources and only relies on semaphores and tasks (or threads) of the system. Unlike traditional messages, traditional messages rely on the message queue of the system.
在上述各实施例的基础上,所述实时操作系统通过任务句柄向所述任务消息队列发送业务消息体。On the basis of the foregoing embodiments, the real-time operating system sends a service message body to the task message queue through a task handle.
在本实施例中,作为一种优选的实施方式,业务调度任务主要负责根据业务数据类型,将业务数据放入到不同业务消息中,并且将根据数据优先级,把业务消息体放入到相关优先级的任务队列中,实时操作系统任务支持消息队列,并且通过任务句柄向任务发送消息,消息队列提供消息体优先级。In this embodiment, as a preferred implementation, the business scheduling task is mainly responsible for putting the business data into different business messages according to the type of business data, and putting the business message body into the relevant business message according to the data priority. In the priority task queue, the real-time operating system task supports the message queue, and sends messages to the task through the task handle, and the message queue provides the priority of the message body.
根据本发明实施例的第二方面,提供了基于实时操作系统的消息驱动装置,采用上述各实施例中的基于实时操作系统的消息驱动方法,包括业务调度任务模块和任务消息队列模块;According to a second aspect of the embodiments of the present invention, a message-driven device based on a real-time operating system is provided, which adopts the message-driven method based on the real-time operating system in the foregoing embodiments, and includes a business scheduling task module and a task message queue module;
所述业务调度任务模块,用于获取业务消息体中业务数据和业务逻辑,基于所述业务数据的类型,将所述业务消息体添加至对应优先级的任务消息队列中;The business scheduling task module is used to obtain business data and business logic in a business message body, and based on the type of the business data, add the business message body to the task message queue of the corresponding priority;
所述任务消息队列模块,用于基于所述任务消息队列传输所述业务逻辑,以供线程接收到所述消息时处理所述业务逻辑。The task message queue module is configured to transmit the business logic based on the task message queue for the thread to process the business logic when the message is received.
在本实施例中,作为一种优选的实施方式,所述任务消息队列模块包括多个消息槽,所述消息槽用于容纳业务消息体,并执行所述业务逻辑,得到业务消息对应的业务数据。In this embodiment, as a preferred implementation manner, the task message queue module includes a plurality of message slots, and the message slots are used to accommodate business message bodies and execute the business logic to obtain the business corresponding to the business message. data.
在本实施例中,作为一种优选的实施方式,所述业务调度任务模块具体用于获取待处理消息队列中的业务消息体,并执行业务函数,提取业务数据和业务逻辑;In this embodiment, as a preferred implementation manner, the service scheduling task module is specifically configured to obtain the service message body in the message queue to be processed, execute the service function, and extract the service data and business logic;
基于所述业务数据的类型,将所述业务数据放入不同业务消息中,并基于数据优先级,将所述业务消息体放入至对应优先级的任务消息队列中。Based on the type of the service data, the service data is put into different service messages, and based on the data priority, the service message body is put into the task message queue of the corresponding priority.
根据本发明实施例的第二方面,提供了基于实时操作系统的消息驱动装置,包括业务调度任务模块和任务消息队列模块;According to a second aspect of the embodiments of the present invention, a message-driven device based on a real-time operating system is provided, including a business scheduling task module and a task message queue module;
所述业务调度任务模块,用于获取业务消息体中业务数据和业务逻辑,基于所述业务数据的类型,将所述业务消息体添加至对应优先级的任务消息队列中;The business scheduling task module is used to obtain business data and business logic in a business message body, and based on the type of the business data, add the business message body to the task message queue of the corresponding priority;
所述任务消息队列模块,用于基于所述任务消息队列传输所述业务逻辑,以供线程接收到所述消息时处理所述业务逻辑。The task message queue module is configured to transmit the business logic based on the task message queue for the thread to process the business logic when the message is received.
作为优选的,所述任务消息队列模块包括多个消息槽,所述消息槽用于容纳业务消息体,并执行所述业务逻辑,得到业务消息对应的业务数据。Preferably, the task message queue module includes a plurality of message slots, and the message slots are used to accommodate business message bodies and execute the business logic to obtain business data corresponding to the business message.
作为优选的,所述业务调度任务模具体用于获取待处理消息队列中的业务消息体,并执行业务函数,提取业务数据和业务逻辑;Preferably, the business scheduling task mold body is used to obtain the business message body in the message queue to be processed, and execute business functions, and extract business data and business logic;
基于所述业务数据的类型,将所述业务数据放入不同业务消息中,并基于数据优先级,将所述业务消息体放入至对应优先级的任务消息队列中。Based on the type of the service data, the service data is put into different service messages, and based on the data priority, the service message body is put into the task message queue of the corresponding priority.
本发明实施例提供了本发明实施例提供了一种电子设备,如图5所示,该设备包括:处理器(processor)501、通信接口(Communications Interface)502、存储器(memory)503和通信总线504,其中,处理器501,通信接口502,存储器503通过通信总线504完成相互间的通信。处理器501可以调用存储器503上并可在处理器501上运行的计算机程序,以执行上述各实施例提供的基于实时操作系统的消息驱动方法,例如包括:The embodiment of the present invention provides an electronic device. As shown in FIG. 5, the device includes: a processor 501, a communication interface 502, a memory 503, and a communication bus 504. The processor 501, the communication interface 502, and the memory 503 communicate with each other through the communication bus 504. The processor 501 can call a computer program on the memory 503 and run on the processor 501 to execute the message-driven method based on the real-time operating system provided by the foregoing embodiments, for example, including:
获取业务消息体中业务数据和业务逻辑,基于所述业务数据的类型,将所述业务消息体添加至对应优先级的任务消息队列中;Obtain business data and business logic in the business message body, and add the business message body to the task message queue of the corresponding priority based on the type of the business data;
基于所述任务消息队列传输所述业务逻辑,以供线程接收到所述 消息时处理所述业务逻辑。The business logic is transmitted based on the task message queue, so that the thread can process the business logic when the thread receives the message.
此外,上述的存储器503中的逻辑指令可以通过软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本发明各个实施例方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。In addition, the above-mentioned logic instructions in the memory 503 can be implemented in the form of a software functional unit and when sold or used as an independent product, they can be stored in a computer readable storage medium. Based on this understanding, the technical solution of the present invention essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including Several instructions are used to make a computer device (which may be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the methods in the various embodiments of the present invention. The aforementioned storage media include: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), magnetic disks or optical disks and other media that can store program codes. .
本发明实施例还提供一种非暂态计算机可读存储介质,其上存储有计算机程序,该计算机程序被处理器执行时实现以执行上述各实施例提供的基于实时操作系统的消息驱动方法,例如包括:The embodiment of the present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored, and the computer program is implemented when executed by a processor to execute the message-driven method based on the real-time operating system provided by the foregoing embodiments. Examples include:
获取业务消息体中业务数据和业务逻辑,基于所述业务数据的类型,将所述业务消息体添加至对应优先级的任务消息队列中;Obtain business data and business logic in the business message body, and add the business message body to the task message queue of the corresponding priority based on the type of the business data;
基于所述任务消息队列传输所述业务逻辑,以供线程接收到所述消息时处理所述业务逻辑。The business logic is transmitted based on the task message queue, so that the thread can process the business logic when the thread receives the message.
综上所述,本发明实施例提供的基于实时操作系统的消息驱动方法和装置,通过获取业务消息体中业务数据和业务逻辑,基于所述业务数据的类型,将所述业务消息体添加至对应优先级的任务消息队列中;基于所述任务消息队列传输所述业务逻辑,以供线程接收到所述消息时处理所述业务逻辑。实时操作系统任务支持消息队列,实现任务只处理消息队列中的消息;实现任务与业务程序解耦,业务程序分成两部分设计,一部分是业务逻辑,一部分业务数据;将业务逻辑与业务数据源分开考虑,实现业务逻辑与数据解耦设计;实时操作系统任务支持优先级处理,对应的消息队列中的消息会按照对应的优先级获得处理业务逻辑。In summary, the message-driven method and device based on the real-time operating system provided by the embodiments of the present invention obtain the business data and business logic in the business message body, and add the business message body to the business message body based on the type of the business data. In the task message queue corresponding to the priority; the business logic is transmitted based on the task message queue, so that the thread can process the business logic when the thread receives the message. Real-time operating system tasks support message queues, and realize that tasks only process messages in message queues; realize tasks and business programs are decoupled, and business programs are designed in two parts, one is business logic and the other is business data; business logic and business data source are separated Consider, realize the design of decoupling business logic and data; real-time operating system tasks support priority processing, and the messages in the corresponding message queue will obtain the processing business logic according to the corresponding priority.
以上所描述的电子设备等实施例仅仅是示意性的,其中作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。本领域普通技术人员在不付出创造性的劳动的情况下,即可以理解并实施。The above-described electronic equipment and other embodiments are only illustrative, where the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in One place, or it can be distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the objectives of the solutions of the embodiments. Those of ordinary skill in the art can understand and implement without creative work.
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到各实施方式可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件。基于这样的理解,上述技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品可以存储在计算机可读存储介质中,如ROM/RAM、磁碟、光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行各个实施例或者实施例的某些部分方法。Through the description of the above implementation manners, those skilled in the art can clearly understand that each implementation manner can be implemented by software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution essentially or the part that contributes to the existing technology can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM/RAM, magnetic A disc, an optical disc, etc., include several instructions to make a computer device (which may be a personal computer, a server, or a network device, etc.) execute each embodiment or some part of the method of the embodiment.
工业实用性Industrial applicability
本发明提供一种基于实时操作系统的消息驱动方法和装置,其克服了不同优先级的任务需要通过不同的业务程序处理,造成业务程序不能根据业务数据,实时改变处理业务操作系统任务优先级等问题,在工业上具有实际应用的价值。The present invention provides a message-driven method and device based on a real-time operating system, which overcomes the need for different priority tasks to be processed by different business programs, causing the business programs to be unable to process business operating system task priorities in real time according to business data. The problem has practical application value in industry.
虽然为了详细阐述的目的,本发明公开了优选的实施方式,然而,本领域普通技术人员应当能够理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本发明各实施例技术方案的精神和范围。Although for the purpose of elaboration, the present invention discloses preferred embodiments, those of ordinary skill in the art should be able to understand that they can still modify the technical solutions described in the foregoing embodiments, or modify some of the technical features. Equivalent replacements; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims (10)

  1. 一种基于实时操作系统的消息驱动方法,其特征在于,包括:A message-driven method based on a real-time operating system is characterized in that it includes:
    获取业务消息体中业务数据和业务逻辑,基于所述业务数据的类型,将所述业务消息体添加至对应优先级的任务消息队列的消息槽中;Obtain business data and business logic in the business message body, and add the business message body to the message slot of the task message queue of the corresponding priority based on the type of the business data;
    基于所述任务消息队列传输所述业务逻辑,以供线程接收到所述消息时处理所述业务逻辑。The business logic is transmitted based on the task message queue, so that the thread can process the business logic when the thread receives the message.
  2. 根据权利要求1所述的基于实时操作系统的消息驱动方法,其特征在于,所述业务逻辑包括处理业务函数和函数参数。The message-driven method based on a real-time operating system according to claim 1, wherein the business logic includes processing business functions and function parameters.
  3. 根据权利要求1所述的基于实时操作系统的消息驱动方法,其特征在于,获取业务消息体中业务数据和业务逻辑,具体包括:The message-driven method based on a real-time operating system according to claim 1, wherein obtaining business data and business logic in a business message body specifically includes:
    获取待处理消息队列中的业务消息体,并执行业务函数,提取业务数据和业务逻辑。Obtain the business message body in the message queue to be processed, execute business functions, and extract business data and business logic.
  4. 根据权利要求3所述的基于实时操作系统的消息驱动方法,其特征在于,基于所述业务数据的类型,将所述业务消息体添加至对应优先级的任务消息队列中,具体包括:The message-driven method based on a real-time operating system according to claim 3, characterized in that, based on the type of the business data, adding the business message body to the task message queue of the corresponding priority specifically includes:
    基于所述业务数据的类型,将所述业务数据放入不同业务消息中,并基于数据优先级,将所述业务消息体放入至对应优先级的任务消息队列中。Based on the type of the service data, the service data is put into different service messages, and based on the data priority, the service message body is put into the task message queue of the corresponding priority.
  5. 根据权利要求3所述的基于实时操作系统的消息驱动方法,其特征在于,所述实时操作系统通过任务句柄向所述任务消息队列发送业务消息体。The message-driven method based on a real-time operating system according to claim 3, wherein the real-time operating system sends a service message body to the task message queue through a task handle.
  6. 一种基于实时操作系统的消息驱动装置,其特征在于,包括业务调度任务模块和任务消息队列模块;A message-driven device based on a real-time operating system, which is characterized by comprising a business scheduling task module and a task message queue module;
    所述业务调度任务模块,用于获取业务消息体中业务数据和业务逻辑,基于所述业务数据的类型,将所述业务消息体添加至对应优先级的任务消息队列中;The business scheduling task module is used to obtain business data and business logic in a business message body, and based on the type of the business data, add the business message body to the task message queue of the corresponding priority;
    所述任务消息队列模块,用于基于所述任务消息队列传输所述业务逻辑,以供线程接收到所述消息时处理所述业务逻辑。The task message queue module is configured to transmit the business logic based on the task message queue for the thread to process the business logic when the message is received.
  7. 根据权利要求6所述的基于实时操作系统的消息驱动装置,其特征在于,所述任务消息队列模块包括多个消息槽,所述消息槽用于容纳业务消息体,并执行所述业务逻辑,得到业务消息对应的业务数据。The message driving device based on a real-time operating system according to claim 6, wherein the task message queue module includes a plurality of message slots, and the message slots are used to accommodate business message bodies and execute the business logic, Obtain the business data corresponding to the business message.
  8. 根据权利要求6所述的基于实时操作系统的消息驱动装置,其特征在于,所述业务调度任务模具体用于获取待处理消息队列中的业务消息体,并执行业务函数,提取业务数据和业务逻辑;The message-driven device based on a real-time operating system according to claim 6, wherein the service scheduling task mold body is used to obtain the service message body in the message queue to be processed, and execute the service function to extract the service data and the service logic;
    基于所述业务数据的类型,将所述业务数据放入不同业务消息中,并基于数据优先级,将所述业务消息体放入至对应优先级的任务消息队列中。Based on the type of the service data, the service data is put into different service messages, and based on the data priority, the service message body is put into the task message queue of the corresponding priority.
  9. 一种电子设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,其特征在于,所述处理器执行所述程序时实现如权利要求1至5任一项所述方法的步骤。An electronic device, comprising a memory, a processor, and a computer program stored on the memory and running on the processor, wherein the processor executes the program as described in any one of claims 1 to 5 The steps of the method.
  10. 一种非暂态计算机可读存储介质,其上存储有计算机程序,其特征在于,该计算机程序被处理器执行时实现如权利要求1至5任一项所述方法的步骤。A non-transitory computer-readable storage medium with a computer program stored thereon, wherein the computer program implements the steps of the method according to any one of claims 1 to 5 when the computer program is executed by a processor.
PCT/CN2019/108381 2019-09-12 2019-09-27 Message drive method and device based on real-time operating system WO2021046932A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910866180.4A CN111475312B (en) 2019-09-12 2019-09-12 Message driving method and device based on real-time operating system
CN201910866180.4 2019-09-12

Publications (1)

Publication Number Publication Date
WO2021046932A1 true WO2021046932A1 (en) 2021-03-18

Family

ID=71744961

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/108381 WO2021046932A1 (en) 2019-09-12 2019-09-27 Message drive method and device based on real-time operating system

Country Status (2)

Country Link
CN (1) CN111475312B (en)
WO (1) WO2021046932A1 (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114138054A (en) * 2021-10-14 2022-03-04 北京国科天迅科技有限公司 A time stamp acquisition method, device, electronic device and storage medium
CN115002224B (en) * 2022-05-26 2025-01-07 阿里巴巴(中国)有限公司 Message processing method, device, system, electronic device and storage medium
CN115167996A (en) * 2022-06-23 2022-10-11 哲库科技(北京)有限公司 Scheduling method and device, chip, electronic device and storage medium
CN115631558A (en) * 2022-10-25 2023-01-20 德施曼机电(中国)有限公司 Intelligent lock control method and system based on RTOS (real time operating System) and intelligent lock

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1409209A (en) * 2001-09-24 2003-04-09 深圳市中兴通讯股份有限公司上海第二研究所 Realizing method for multiple task real-time operation system
CN1745549A (en) * 2002-12-13 2006-03-08 艾利森公司 A system for processing messages based on content
CN101452399A (en) * 2007-12-05 2009-06-10 中兴通讯股份有限公司 Task secondary scheduling module and method
US20140101663A1 (en) * 2012-10-04 2014-04-10 Lawrence J. Dickson Method and apparatus implemented in processors for real-time scheduling and task organization based on response time order of magnitude
CN105137800A (en) * 2015-09-11 2015-12-09 浙江中烟工业有限责任公司 PLC cooperative control device based on SOPC technology
CN109901917A (en) * 2017-12-07 2019-06-18 龙芯中科技术有限公司 Real time operating system dispatching method and device, computer readable storage medium

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1217513C (en) * 2002-12-27 2005-08-31 北京邮电大学 Method of ensuring service grade protocol in multijob multiuser service platform
CN102880475B (en) * 2012-10-23 2015-08-12 普元信息技术股份有限公司 Based on the real-time event disposal system of cloud computing and method in computer software
US9612865B2 (en) * 2015-06-15 2017-04-04 International Business Machines Corporation Managed services coordinator
CN105740069B (en) * 2016-01-29 2021-09-21 中国电力科学研究院 Automatic scheduling method for multi-level data conversion tasks
CN109471711B (en) * 2018-11-12 2021-03-02 中国银行股份有限公司 Task processing method and device
CN110007902B (en) * 2019-03-12 2023-11-24 中国平安财产保险股份有限公司 Method and device for configuring business processing flow
CN110189206A (en) * 2019-06-04 2019-08-30 苏州程旅网络科技有限公司 Asynchronous ordering system and ordering method from the background

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1409209A (en) * 2001-09-24 2003-04-09 深圳市中兴通讯股份有限公司上海第二研究所 Realizing method for multiple task real-time operation system
CN1745549A (en) * 2002-12-13 2006-03-08 艾利森公司 A system for processing messages based on content
CN101452399A (en) * 2007-12-05 2009-06-10 中兴通讯股份有限公司 Task secondary scheduling module and method
US20140101663A1 (en) * 2012-10-04 2014-04-10 Lawrence J. Dickson Method and apparatus implemented in processors for real-time scheduling and task organization based on response time order of magnitude
CN105137800A (en) * 2015-09-11 2015-12-09 浙江中烟工业有限责任公司 PLC cooperative control device based on SOPC technology
CN109901917A (en) * 2017-12-07 2019-06-18 龙芯中科技术有限公司 Real time operating system dispatching method and device, computer readable storage medium

Also Published As

Publication number Publication date
CN111475312B (en) 2021-05-18
CN111475312A (en) 2020-07-31

Similar Documents

Publication Publication Date Title
WO2021046932A1 (en) Message drive method and device based on real-time operating system
US7451447B1 (en) Method, computer program and apparatus for operating system dynamic event management and task scheduling using function calls
EP3051414A1 (en) Computer device, method and apparatus for scheduling service process
US7043729B2 (en) Reducing interrupt latency while polling
WO2021000758A1 (en) Robotic resource task cycle management and control method and apparatus
CN105224886B (en) A kind of mobile terminal safety partition method, device and mobile terminal
WO2021197128A1 (en) Traffic rate-limiting method and apparatus
WO2016177081A1 (en) Notification message processing method and device
CN106775964A (en) The operating system framework and method for scheduling task of time/event mixing triggering
US10545890B2 (en) Information processing device, information processing method, and program
JP4584935B2 (en) Behavior model based multi-thread architecture
US11461134B2 (en) Apparatus and method for deferral scheduling of tasks for operating system on multi-core processor
US9507650B2 (en) Power efficient callback patterns
CN113535341B (en) Method and device for realizing interrupt communication between CPU cores under Linux
CN118132271A (en) Asynchronous application execution system and method for embedded software interface
CN118295778A (en) Task scheduling method and device, electronic equipment and storage medium
US9563494B2 (en) Systems and methods for managing task watchdog status register entries
CN101308469A (en) A method and device for implementing soft interrupt load balancing
JP2007164421A (en) Parallel processors, parallel processing method and parallel processing program
CN110955507B (en) Method for multitask access to same IIC bus based on vxWorks system
CN113032110A (en) High-availability task scheduling method based on distributed peer-to-peer architecture design
US20240362061A1 (en) Mechanism for sharing a common resource in a multi-threaded environment
WO2022174442A1 (en) Multi-core processor, multi-core processor processing method, and related device
CN107239417B (en) System and method for processing low-speed peripheral access based on asynchronous event framework mechanism
WO2023144878A1 (en) Intra-server delay control device, intra-server delay control method, and program

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 19945181

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 090522)

122 Ep: pct application non-entry in european phase

Ref document number: 19945181

Country of ref document: EP

Kind code of ref document: A1