Custom message sending method and device based on Basic CAN
By using pre-send message queues and priority mapping tables in Basic CAN communication, the sending order of CAN ID messages is flexibly controlled, which solves the problem that custom priority cannot be met in the prior art, and improves the flexibility of system communication and efficiency.
Patent Information
- Application Number
- CN202410952673.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-16
- Publication Date
- 2024-11-08
AI Technical Summary
Existing Basic CAN and Full CAN communication methods do not meet the priority requirements of custom CAN ID messages, especially in multitasking cases where high priority messages may not be sent in the expected order.
By obtaining the CAN message to be sent, it is determined whether there are CAN messages stored in the pre-constructed pre-send message queue, and the transmission priority of the CAN message to be sent and the stored CAN message is determined based on the pre-constructed send priority mapping table. , If the priority of the message to be sent is high, insert it into the front of the queue to send; if the priority is low, place it behind the queue; if the queue is empty, send it directly.
It realizes flexible control of the transmission order of CAN messages, improves the flexibility and efficiency of system communication, meets custom priority requirements, reduces manual intervention, and improves the degree of automation and stability of the system.
Smart Images

Figure CN118921330A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of automobile control technology, and in particular to a method and device for sending a custom message based on Basic CAN. Background Art
[0002] There are two main modes of communication in the Controller Area Network (CAN) of the microcontroller unit (MCU) currently on the market: Basic CAN and Full CAN.
[0003] When using Basic CAN, if there are many different CAN ID messages that need to be sent, these messages will be sent in a first-in-first-out (FIFO) manner. In other words, the message that enters the send queue first will be sent out first. This method is simple but has a disadvantage: it is not possible to specify the sending priority of different CAN ID messages in a highly flexible manner. For example, if you want a specific CAN ID message to be sent out faster than other messages, the Basic CAN method cannot do this. In particular, when there are multiple tasks sending messages at different times, the expected high-priority CAN ID messages may not be sent in the expected order.
[0004] When using Full CAN, the priority of CAN messages is determined by the rules of the CAN bus. Specifically, the smaller the CAN ID value, the higher the priority. For example, a message with a CAN ID of 100 will be sent before a message with a CAN ID of 200. This priority mechanism can make good use of the bus arbitration mechanism, but it also has a disadvantage: it cannot meet the needs of custom priorities. If you want some CAN ID messages with larger values (such as messages with a CAN ID of 200) to be sent first, the Full CAN mechanism cannot meet this requirement. Summary of the invention
[0005] In view of this, the present invention provides a method and device for sending a custom message based on Basic CAN, so as to solve the problem in the prior art that both Basic CAN and Full CAN communication modes cannot meet the custom priority requirement.
[0006] In the first aspect, the present invention provides a custom message sending method based on Basic CAN, the method comprising: obtaining a CAN message to be sent; determining whether a CAN message is stored in a pre-built pre-sending message queue; when a CAN message is stored, determining the sending priority of the CAN message to be sent and the stored CAN message according to a pre-built sending priority mapping table; when the priority of the CAN message to be sent is higher than the priority of the stored CAN message, inserting the CAN message to be sent in front of the stored CAN message in the pre-sending message queue for message sending.
[0007] The custom message sending method based on Basic CAN provided by the embodiment of the present invention obtains a CAN message to be sent; determines whether a CAN message is stored in a pre-constructed pre-sending message queue; when a CAN message is stored, determines the sending priority of the CAN message to be sent and the stored CAN message according to a pre-constructed sending priority mapping table; when the priority of the CAN message to be sent is higher than the priority of the stored CAN message, inserts the CAN message to be sent in front of the stored CAN message in the pre-sending message queue for message sending, thereby being able to flexibly control the sending order of the CAN messages, improve the flexibility and efficiency of system communication, and solve the problem that the custom priority requirement cannot be met when the current CAN message is sent.
[0008] In an optional implementation, the method further includes: when the priority of the to-be-sent CAN message is lower than the priority of the stored CAN message, placing the to-be-sent CAN message behind the stored CAN message in the pre-sent message queue for message sending.
[0009] In this embodiment, when it is determined according to the sending priority mapping table that the priority of the CAN message to be sent is lower than the priority of the stored CAN message, the sending order of the CAN message to be sent is later than the sending order of the stored CAN message, thereby placing the CAN message to be sent behind the stored CAN message in the pre-sending message queue, thereby ensuring that the messages are sent in the priority order of the sending priority mapping table.
[0010] In an optional implementation, the method further includes: when no CAN message is stored in the pre-sent message queue, placing the CAN message to be sent in the pre-sent message queue for message sending.
[0011] In this embodiment, when no CAN message is stored in the pre-sent message queue, the CAN message to be sent is directly stored in the pre-sent message queue, so that the sending of the CAN message to be sent can be achieved.
[0012] In an optional implementation, before obtaining the CAN message to be sent, the method also includes: enabling the CAN message sending completion interrupt notification and the CAN message sending failure interrupt notification; entering the message sending function or software calling the message sending interface; and performing atomic protection on the pre-sent message queue.
[0013] In this embodiment, by enabling the interrupt notification of CAN message sending completion and the interrupt notification of CAN message sending failure, the message sending process is made more automated, reducing manual intervention and improving the automation and stability of the system. At the same time, atomic protection is performed on the pre-sent message queue to ensure the security and reliability of the message insertion and sending process, reducing complex concurrent processing issues.
[0014] In an optional implementation, the CAN message to be sent is inserted in front of the CAN message stored in the pre-sending message queue for message sending, including: inserting the CAN message to be sent in front of the CAN message stored in the pre-sending message queue, and exiting atomic protection; after receiving the interrupt notification of the completion of sending the previous frame of CAN message, determining whether the pre-sending message queue is empty; when the pre-sending message queue is not empty, taking out the top CAN message from the pre-sending message queue for sending.
[0015] In an optional implementation, when no CAN message is stored in the pre-sending message queue, the CAN message to be sent is placed in the pre-sending message queue for message sending, including: when no CAN message is stored in the pre-sending message queue, the CAN message to be sent is placed in the pre-sending message queue and atomic protection is exited; after receiving the interrupt notification of the completion of sending the previous frame of CAN message, it is determined whether the pre-sending message queue is empty; when the pre-sending message queue is not empty, the stored CAN message is taken out from the pre-sending message queue for sending.
[0016] In this embodiment, atomic protection is exited after message insertion is completed or stored in the pre-sent message queue, thereby ensuring the security and consistency of message insertion, avoiding competition conditions and data inconsistency problems caused by concurrent access of multiple tasks, and improving system reliability.
[0017] In an optional implementation, before obtaining the CAN message to be sent, the method also includes: constructing a sending priority mapping table, the sending priority mapping table including a mapping relationship between CAN message identifiers and sending priorities; constructing a pre-sending message queue, the pre-sending message queue being used to temporarily store CAN messages waiting to be sent.
[0018] In this embodiment, by constructing a transmission priority mapping table, the CAN message identifier and the transmission priority are mapped, so that the priority of the message can be flexibly configured and updated according to the specific application requirements, and the sending order of the customized CAN ID priority and the flexible management of the message priority are realized. This method enables the system to dynamically adjust the priority of the message according to actual needs, improving the adaptability and flexibility of the system. By constructing a pre-sent message queue, the CAN messages to be sent can be temporarily stored, and the messages in the pre-sent message queue can be sorted according to the priority, ensuring that high-priority messages are sent first, improving the real-time performance and efficiency of the system.
[0019] In a second aspect, the present invention provides a custom message sending device based on Basic CAN, the device comprising: a message acquisition module, used to acquire CAN messages to be sent; a storage judgment module, used to judge whether CAN messages are stored in a pre-built pre-sending message queue; a priority determination module, used to determine the sending priority of the CAN messages to be sent and the stored CAN messages according to a pre-built sending priority mapping table when CAN messages are stored; a sending module, used to insert the CAN message to be sent in front of the stored CAN message in the pre-sending message queue for message sending when the priority of the CAN message to be sent is higher than the priority of the stored CAN message.
[0020] In a third aspect, the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the computer instructions to execute the custom message sending method based on Basic CAN of the above-mentioned first aspect or any corresponding embodiment thereof.
[0021] In a fourth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the custom message sending method based on Basic CAN of the above-mentioned first aspect or any corresponding embodiment thereof.
[0022] In a fifth aspect, the present invention provides a computer program product, comprising computer instructions, wherein the computer instructions are used to enable a computer to execute the method for sending a custom message based on Basic CAN according to the first aspect or any corresponding embodiment thereof. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0024] Figure 1 is a flow chart of a method for sending a custom message based on Basic CAN according to an embodiment of the present invention;
[0025] Figure 2 is a flow chart of another method for sending a custom message based on Basic CAN according to an embodiment of the present invention;
[0026] Figure 3 is a structural block diagram of a custom message sending device based on Basic CAN according to an embodiment of the present invention;
[0027] Figure 4 It is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0028] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0029] According to an embodiment of the present invention, an embodiment of a method for sending a custom message based on Basic CAN is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0030] In this embodiment, a custom message sending method based on Basic CAN is provided. Figure 1 is a flow chart of a method for sending a custom message based on Basic CAN according to an embodiment of the present invention, such as Figure 1 As shown, the process includes the following steps:
[0031] Step S101, obtaining a CAN message to be sent.
[0032] It should be noted that the custom message sending method of this embodiment is applied in MCU, that is, it can be implemented based on this method when CAN communication is performed in MCU. At the same time, this method is specifically implemented based on the communication method of Basic CAN. Since the priority of FULLCAN is determined based on the rules of the CAN bus (such as the smaller the CAN ID value, the higher the priority), it is impossible to implement custom priority, so it cannot be applied to FULL CAN. Among them, the CAN message to be sent can be a new CAN message that needs to be sent at the current moment. The specific content of the CAN message can be determined according to the actual sending requirements, and this embodiment does not make specific limitations on this.
[0033] Step S102, determining whether a CAN message is stored in a pre-constructed pre-sent message queue. The pre-sent message queue can be constructed inside the MCU, and can be constructed before determining the CAN message to be sent. The pre-sent message queue is used to temporarily store the CAN message to be sent. After determining the CAN message to be sent, by determining whether a CAN message is stored in the pre-sent message queue, it is determined whether there are other CAN messages to be sent in addition to the CAN message to be sent.
[0034] Step S103, when CAN messages are stored, the sending priorities of the CAN messages to be sent and the stored CAN messages are determined according to the pre-built sending priority mapping table. Specifically, the sending priority mapping table is a pre-built mapping table including the sending order of different CAN messages. When CAN messages are stored in the pre-sent message queue, it means that in addition to the CAN messages to be sent, there are other CAN messages to be sent. At this time, the sending priorities of the CAN messages to be sent and the stored CAN messages, that is, the sending order of the two, can be determined according to the sending priority mapping table.
[0035] Step S104, when the priority of the CAN message to be sent is higher than the priority of the stored CAN message, the CAN message to be sent is inserted in front of the stored CAN message in the pre-sent message queue for message sending. Specifically, when the priority of the CAN message to be sent is higher than the priority of the stored CAN message, it means that the current demand is to send the CAN message to be sent first, and then send the stored CAN message, but the CAN message has been stored in the pre-sent message queue waiting to be sent, so in order to ensure that the CAN message can be sent as required, the CAN message to be sent is inserted in front of the stored CAN message in the pre-sent message queue, and the messages stored in the pre-sent message queue will be sent in order, so that when the message is sent, it can be ensured that the CAN message to be sent with a high priority is sent first, and the stored CAN message with a low priority is sent later.
[0036] The custom message sending method based on Basic CAN provided by the embodiment of the present invention obtains a CAN message to be sent; determines whether a CAN message is stored in a pre-constructed pre-sending message queue; when a CAN message is stored, determines the sending priority of the CAN message to be sent and the stored CAN message according to a pre-constructed sending priority mapping table; when the priority of the CAN message to be sent is higher than the priority of the stored CAN message, inserts the CAN message to be sent in front of the stored CAN message in the pre-sending message queue for message sending, thereby being able to flexibly control the sending order of the CAN messages, improve the flexibility and efficiency of system communication, and solve the problem that the custom priority requirement cannot be met when the current CAN message is sent.
[0037] In this embodiment, a method for sending a custom message based on Basic CAN is provided, and the process includes the following steps:
[0038] Step S201, construct a sending priority mapping table, the sending priority mapping table includes a mapping relationship between a CAN message identifier and a sending priority; specifically, a CAN message identifier is a CAN message ID, and different CAN messages have different IDs, so the CAN message identifier is used to distinguish different CAN messages. In the related art, although the FULL CAN communication method can also send messages based on priority, in the FULL CAN, the message sending priority is determined according to the numerical value of the CAN ID itself. The sending priority mapping table constructed in this embodiment is configured according to user needs, that is, the sending priority of the CAN message has nothing to do with the ID size of the CAN message. For example, the sending priority mapping table constructed in this embodiment is shown in Table 1 below:
[0039] Table 1
[0040]
[0041]
[0042] As shown in Table 1 above, this embodiment uses the numerical value of the priority to represent the order of priority of sending different CAN messages, that is, the smaller the priority number, the higher the corresponding priority, and the higher the sending order. In other embodiments, other methods can also be used to represent the priorities of different CAN IDs. This embodiment does not make specific restrictions on this, as long as the priority of each CAN ID can be determined. In addition, the sending priority mapping table can also be updated according to user needs, that is, the priority order can be changed. For example, in Table 1, the CAN ID 0x763 has the highest priority. In actual application, it can also be adjusted, such as adjusting the priority of the CAN ID 0x552 to the highest, etc.
[0043] Step S202, construct a pre-sent message queue, which is used to temporarily store CAN messages waiting to be sent. Specifically, the pre-sent message queue can also be expressed as a pre-sent message queue FIFO, that is, the messages stored in the pre-sent message queue are sent in sequence. The pre-sent message queue temporarily stores CAN messages waiting to be sent, that is, when there are CAN messages to be sent at the current moment, they can be stored in the pre-sent message queue to meet the message sending requirements.
[0044] Step S203, obtain the CAN message to be sent. Figure 1 Step S101 of the illustrated embodiment will not be described in detail here.
[0045] Step S204, determine whether there are CAN messages stored in the pre-built pre-send message queue. Figure 1 Step S102 of the illustrated embodiment will not be described in detail here.
[0046] Step S205: When CAN messages are stored, the sending priorities of the to-be-sent CAN messages and the stored CAN messages are determined according to the pre-built sending priority mapping table; see Figure 1 Step S103 of the illustrated embodiment will not be described in detail here.
[0047] Step S206: When the priority of the CAN message to be sent is higher than the priority of the stored CAN message, the CAN message to be sent is inserted in front of the stored CAN message in the pre-sent message queue for message sending. Figure 1 Step S104 of the illustrated embodiment will not be described in detail here.
[0048] In this embodiment, a method for sending a custom message based on Basic CAN is provided, and the method comprises the following steps:
[0049] Step S301, enable the CAN message sending completion interrupt notification and the CAN message sending failure interrupt notification; enter the message sending function or the software calls the message sending interface; and perform atomic protection on the pre-sending message queue.
[0050] Specifically, when the custom message sending method is applied, the CAN message sending completion interrupt notification and the CAN message sending failure interrupt notification can be turned on during the initialization phase, such as when the MCU is initialized internally, so as to determine the sending result of each frame of the message and send the next frame of the message, and at the same time, the message sending process can be made more automated, reducing manual intervention. In addition, when it is necessary to send a message, enter the message sending function or the software application to call the interface for sending the message, and at the same time, perform atomic protection on the pre-sent message queue. The atomic protection can ensure that the message is not interrupted when it is stored in the pre-sent message queue, that is, when writing to the pre-sent message queue, other tasks are not allowed to preempt, ensuring the security and reliability of the message insertion and sending process, and reducing complex concurrent processing issues.
[0051] Step S302: Obtain the CAN message to be sent. Figure 1 Step S101 of the illustrated embodiment will not be described in detail here.
[0052] Step S303, determine whether there is a CAN message stored in the pre-built pre-sent message queue; see Figure 1 Step S102 of the illustrated embodiment will not be described in detail here.
[0053] Step S304, when CAN messages are stored, the sending priorities of the CAN messages to be sent and the stored CAN messages are determined according to the pre-built sending priority mapping table. It should be noted that the number of CAN messages to be sent and the number of stored CAN messages can be multiple, and the priority value of each CAN message needs to be determined when determining the sending priority. For example, the priority value of each CAN message can be determined by Table 1 in the above embodiment, thereby determining the priority of each CAN message.
[0054] Step S305: When the priority of the CAN message to be sent is higher than the priority of the stored CAN message, the CAN message to be sent is inserted in front of the stored CAN message in the pre-sent message queue for message sending.
[0055] Specifically, the above step S305 includes:
[0056] Step S3051, insert the CAN message to be sent in front of the CAN message stored in the pre-sent message queue, and exit the atomic protection; specifically, when the priority of the CAN message to be sent is higher than the priority of the stored CAN message, that is, when the CAN message to be sent needs to be sent first, according to the sequential sending principle in the pre-sent message queue, the CAN message to be sent is inserted in front of the CAN message stored in the pre-sent message queue, thereby ensuring the priority sending of the CAN message to be sent. At the same time, in order to facilitate the subsequent sending process, after completing the storage of the message in the pre-sent message queue, it is necessary to exit the atomic protection, that is, release the atomic protection.
[0057] Step S3052, after receiving the interrupt notification of completion of sending the previous frame of CAN message, determine whether the pre-sending message queue is empty; specifically, after completing the storage of the message in the pre-sending message queue, it is necessary to send the message. Before sending the message, it is necessary to determine whether the interrupt notification of completion of sending the previous frame of CAN message is received. After receiving the notification, it means that the previous frame of message has been sent and the next frame can be sent. At this time, it is necessary to determine whether the pre-sending message queue is empty, that is, whether there is a CAN message waiting to be sent.
[0058] Step S3053, when the pre-sent message queue is not empty, take out the top CAN message from the pre-sent message queue for sending. Specifically, when the pre-sent message queue is not empty, that is, there are messages waiting to be sent stored in the pre-sent message queue, the messages can be taken out and sent in the order of the CAN messages in the pre-sent message queue. Since the order of the CAN messages in the pre-sent message queue has been adjusted in step S3051, the messages can be directly taken out and sent at this time, so that the messages can be sent in the order of actual needs.
[0059] Step S306, when the priority of the CAN message to be sent is lower than the priority of the stored CAN message, the CAN message to be sent is placed behind the stored CAN message in the pre-sent message queue for message sending. Specifically, when the priority of the CAN message to be sent is lower than the priority of the stored CAN message, the CAN message stored in the pre-sent message queue needs to be sent first, so the CAN message to be sent can be placed after the stored CAN message to ensure the priority sending of the stored CAN message. The specific message sending process can be implemented with reference to step S305, which will not be repeated here.
[0060] Step S307: When no CAN message is stored in the pre-sending message queue, the CAN message to be sent is placed in the pre-sending message queue for message sending.
[0061] Specifically, the above step S307 includes:
[0062] Step S3071, when there is no CAN message stored in the pre-sent message queue, the CAN message to be sent is placed in the pre-sent message queue, and the atomic protection is exited.
[0063] Step S3072, after receiving the interrupt notification of the completion of sending the previous frame of CAN message, determine whether the pre-sending message queue is empty.
[0064] Step S3073, when the pre-sent message queue is not empty, taking out the stored CAN message from the pre-sent message queue for sending.
[0065] Specifically, when there is no message stored in the pre-sent message queue, the CAN message to be sent can be directly placed in the pre-sent message queue. At this time, if the CAN message to be sent includes only a single message, the CAN message to be sent can be directly placed in the pre-sent message queue. If the CAN message to be sent includes multiple messages, it is necessary to determine the sending priority of multiple CAN messages according to the sending priority mapping table, and then place multiple CAN messages in the pre-sent message queue in the order of high priority first and low priority last according to the sending priority. After that, after receiving the interrupt notification of the completion of sending the previous frame of CAN message, the CAN message in the front order is taken out from the pre-sent message queue for sending. In addition, it should be noted that because the pre-sent message queue may not store CAN messages, that is, there is no CAN message to be sent at the current moment, so after receiving the interrupt notification of the completion of sending the previous frame of CAN message, first determine whether the pre-sent message queue is empty, and when it is not empty, take out the message for sending.
[0066] As a specific application example of the embodiment of the present invention, Figure 2 As shown, the custom message sending method based on Basic CAN can be implemented based on the following process:
[0067] 1. Map each CAN ID to its corresponding transmission priority and establish a transmission priority mapping table. The mapping table can be configured and updated according to user needs.
[0068] 2. Establish a CAN pre-send message FIFO, i.e. a pre-send message queue, inside the MCU to temporarily store CAN messages to be sent.
[0069] 3. When the MCU is initialized internally, enable the CAN message sending completion interrupt notification and the CAN message sending failure interrupt notification.
[0070] 4. The application software calls the message sending interface and fills in the message parameters.
[0071] 5. Enter the pre-send message FIFO atomic protection.
[0072] 6. Get the CAN message to be sent and determine whether the pre-sent message FIFO is empty.
[0073] 7. When the pre-send message FIFO is empty, directly add the acquired CAN message to be sent to the pre-send message FIFO, exit the pre-send message FIFO atomic protection, and fill the message into the hardware send register to trigger the CAN message sending.
[0074] 8. When the pre-send message FIFO is not empty, the priorities of the CAN messages to be sent and the CAN messages stored in the pre-send message FIFO are determined according to the sending priority mapping table, i.e., the message ID priority table, and the messages are sorted according to the determined priorities and inserted into the pre-send message FIFO, and then the pre-send message FIFO is exited, and then asynchronously waits for the message to be sent.
[0075] 9. Determine whether the previous CAN message sending completion interrupt notification or sending failure interrupt notification is received.
[0076] 10. When receiving a sending failure interrupt notification, it is necessary to resend the failure message and make a judgment on the receiving notification again until a sending completion interrupt notification is received.
[0077] 11. When receiving the transmission completion interrupt notification, determine whether the pre-send message FIFO is empty. If it is not empty, obtain the message from the pre-send message FIFO for transmission. If it is empty, stop sending.
[0078] In this embodiment, a custom message sending device based on Basic CAN is also provided, which is used to implement the above embodiments and preferred implementation modes, and will not be repeated hereafter. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0079] This embodiment provides a custom message sending device based on Basic CAN, such as Figure 3 As shown, including:
[0080] The message acquisition module 31 is used to acquire the CAN message to be sent;
[0081] A storage determination module 32 is used to determine whether a CAN message is stored in the pre-built pre-sent message queue;
[0082] The priority determination module 33 is used to determine the sending priority of the CAN message to be sent and the stored CAN message according to the pre-built sending priority mapping table when there are CAN messages stored;
[0083] The sending module 34 is used to insert the CAN message to be sent in front of the stored CAN message in the pre-sending message queue for message sending when the priority of the CAN message to be sent is higher than the priority of the stored CAN message.
[0084] In an optional implementation, the device further includes: a first sending unit, configured to place the CAN message to be sent behind the stored CAN message in the pre-sent message queue for message sending when the priority of the CAN message to be sent is lower than the priority of the stored CAN message.
[0085] In an optional implementation, the device further includes: a second sending unit, configured to place the to-be-sent CAN message in the pre-sent message queue for message sending when no CAN message is stored in the pre-sent message queue.
[0086] In an optional embodiment, the device also includes: a protection module, which is specifically used to enable CAN message sending completion interrupt notification and CAN message sending failure interrupt notification; enter the message sending function or software call to send the message interface; and perform atomic protection on the pre-sending message queue.
[0087] In an optional implementation, the sending module is specifically used to: insert the CAN message to be sent in front of the CAN message stored in the pre-sending message queue, and exit the atomic protection; after receiving the interrupt notification of the completion of sending the previous frame of CAN message, determine whether the pre-sending message queue is empty; when the pre-sending message queue is not empty, take out the top CAN message from the pre-sending message queue for sending.
[0088] In an optional embodiment, the second sending unit is specifically used for: when no CAN message is stored in the pre-sending message queue, placing the CAN message to be sent in the pre-sending message queue and exiting the atomic protection; after receiving the interrupt notification of the completion of sending the previous frame of CAN message, determining whether the pre-sending message queue is empty; when the pre-sending message queue is not empty, taking out the stored CAN message from the pre-sending message queue for sending.
[0089] In an optional embodiment, the device also includes: a construction module, which is specifically used to construct a sending priority mapping table, the sending priority mapping table includes a mapping relationship between CAN message identifiers and sending priorities; and construct a pre-sending message queue, the pre-sending message queue is used to temporarily store CAN messages waiting to be sent.
[0090] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.
[0091] The embodiment of the present invention also provides a computer device having the above Figure 3The shown device is a custom message sending device based on Basic CAN.
[0092] See also Figure 4 , Figure 4 is a schematic diagram of the structure of a computer device provided by an optional embodiment of the present invention, such as Figure 4 As shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process the instructions executed in the computer device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 3 A processor 10 is taken as an example.
[0093] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.
[0094] The memory 20 stores instructions executable by at least one processor 10, so that at least one processor 10 executes the method shown in the above embodiment.
[0095] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created by the use of a computer device based on the presentation of a small program landing page, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0096] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.
[0097] The computer device further comprises a communication interface 30 for the computer device to communicate with other devices or a communication network.
[0098] The embodiment of the present invention also provides a computer-readable storage medium. The method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium through a network download, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.
[0099] A part of the present invention may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present invention through the operation of the computer. Those skilled in the art should understand that the existence of the computer program instruction in a computer-readable medium includes, but is not limited to, a source file, an executable file, an installation package file, etc., and accordingly, the way in which the computer program instruction is executed by the computer includes, but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer-readable medium may be any available computer-readable storage medium or communication medium accessible to the computer.
[0100] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.
Claims
1. A method for sending a custom message based on Basic CAN, characterized in that: The method comprises: Get the CAN message to be sent; Determine whether there are CAN messages stored in the pre-built pre-send message queue; When CAN messages are stored, the sending priorities of the to-be-sent CAN messages and the stored CAN messages are determined according to a pre-built sending priority mapping table; When the priority of the CAN message to be sent is higher than the priority of the stored CAN message, the CAN message to be sent is inserted in front of the stored CAN message in the pre-send message queue for message sending.
2. The method according to claim 1, characterized in that The method further comprises: When the priority of the CAN message to be sent is lower than the priority of the stored CAN message, the CAN message to be sent is placed behind the stored CAN message in the pre-send message queue for message sending.
3. The method according to claim 1, characterized in that The method further comprises: When no CAN message is stored in the pre-send message queue, the CAN message to be sent is placed in the pre-send message queue for message sending.
4. The method according to claim 3, characterized in that: Before obtaining the CAN message to be sent, the method further includes: Enable the interrupt notification of CAN message sending completion and CAN message sending failure; Enter the message sending function or the software calls the interface for sending messages; Atomic protection is performed on the pre-sent message queue.
5. The method according to claim 4, characterized in that Inserting the CAN message to be sent in front of the CAN message stored in the pre-send message queue to send the message, including: Insert the CAN message to be sent in front of the CAN message stored in the pre-send message queue, and exit the atomic protection; After receiving the interrupt notification of the completion of sending the previous CAN message frame, determine whether the pre-sending message queue is empty; When the pre-send message queue is not empty, the top-ranked CAN message is taken out from the pre-send message queue for sending.
6. The method according to claim 4, characterized in that When no CAN message is stored in the pre-send message queue, the CAN message to be sent is placed in the pre-send message queue for message sending, including: When there is no CAN message stored in the pre-send message queue, the CAN message to be sent is placed in the pre-send message queue and the atomic protection is exited; After receiving the interrupt notification of the completion of sending the previous CAN message frame, determine whether the pre-sending message queue is empty; When the pre-send message queue is not empty, the stored CAN message is taken out from the pre-send message queue for sending.
7. The method according to claim 1, characterized in that Before obtaining the CAN message to be sent, the method further includes: Constructing a transmission priority mapping table, wherein the transmission priority mapping table includes a mapping relationship between a CAN message identifier and a transmission priority; A pre-send message queue is constructed, wherein the pre-send message queue is used to temporarily store CAN messages waiting to be sent.
8. A custom message sending device based on Basic CAN, characterized in that: The device comprises: The message acquisition module is used to obtain the CAN message to be sent; A storage judgment module is used to judge whether a CAN message is stored in a pre-built pre-sent message queue; A priority determination module, used for determining the sending priorities of the to-be-sent CAN messages and the stored CAN messages according to a pre-built sending priority mapping table when CAN messages are stored; The sending module is used to insert the CAN message to be sent in front of the stored CAN message in the pre-sending message queue for message sending when the priority of the CAN message to be sent is higher than the priority of the stored CAN message.
9. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the custom message sending method based on Basic CAN according to any one of claims 1 to 7 by executing the computer instructions.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the custom message sending method based on Basic CAN according to any one of claims 1 to 7.
Citation Information
Cited By
Message management method and device and readable storage medium
CN119922037A
Message management method and device and readable storage medium
CN119922037B
Multi-priority CAN bus voice interaction method and system
CN121727891A
