A CAN gateway device, a message routing method, and a readable storage medium
By configuring FIFO for each routing path in the Cdd Rout layer of the CAN gateway device, the problem of messaging disorder when the sending bus load rate is large is solved, and the sequential transmission of packets in extreme operating conditions is realized.
Patent Information
- Application Number
- CN202410688749.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-30
- Publication Date
- 2025-06-24
- Estimated Expiration
- 2044-05-30
AI Technical Summary
In the scenario where the vehicle's on-board bus communicates with the vehicle, when the sending bus load rate is large, routing messages are received frequently, resulting in the problem of messaging disorder.
It provides a CAN gateway device, including a CAN control module, a CAN driver module and a CAN interface module. Through the Cdd Rout layer, a first-in-first-out storage module (FIFO) is configured for each route path of each received message to ensure that the message is sent according to the first-in-first-out principle.
By configuring FIFO in the Cdd Rout layer, it is ensured that there is only one packet data of the same ID in the transmission queue of the hardware layer at any time, and the occurrence of out-of-order transmission of routed packets is avoided.
Smart Images

Figure CN118413497B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of in-vehicle buses and in-vehicle communications / CAN bus technology, and particularly to a CAN gateway device, a message routing method, and a readable storage medium. Background Art
[0002] In the solution for in-vehicle bus and in-vehicle communication in a vehicle, communication transmission is generally carried out through a CAN bus. When routing and transmitting gateway messages in the prior art, generally when a message is received on the CAN Controller (hardware layer, CAN control module), a receive interrupt is triggered. In the receive interrupt, the received message data is passed to CanIf through the notification function CanIf_RxIndicaiton, and then the received message data is passed to PduR (Protocol Data Unit Router) through the notification function PduR_CanIfRxIndicaiton.
[0003] The routing path is queried in PduR, and the data is sent to the CanIf module (Controller Area Network Interface, an interface module for the controller area network) by calling CanIf_Transmit. Then CanIf writes the data into the transmit queue of the CAN Driver (CAN driver module) by calling Can_Write, and then the subsequent work is automatically processed by the CAN Driver hardware. If there is only 1 message just received in the transmit queue, the message is immediately sent to the CAN Controller; if there are multiple messages in the transmit queue, the CAN Driver will send the messages to the CAN Controller in the order of message ID priority. If the message IDs have the same priority, they will be sent in the order in the queue (not the time order when the messages enter the queue). See specifically Figure 1 as shown.
[0004] However, in the extreme working conditions where the load rate of the sending bus is large and the reception of routing messages is extremely frequent, the situation of out-of-order routing and sending of messages will occur. See specifically Figure 2 as shown in Figure 2Among them, Pdu0_3 is the message received on network number Net0, representing the message name Pdu0 with a sequence number of 3. This message will be routed to network numbers Net1 and Net2 simultaneously. Among them, since the CAN Driver send queue of Net1 was originally empty, it will be sent immediately without waiting after receiving Pdu0_3, which is a normal situation; while the CAN Driver send queue of Net2 was originally in a full state, with a high-priority message Pdu1, and low-priority messages Pdu0_1 and Pdu_2; Pdu1 will be sent first, and then Pdu0_3 will continue to be written into the CAN Driver send queue by CanIf and filled in the position vacated by Pdu1. At this time, the three messages in the queue have the same priority, and the CAN Driver sends them in the order of the message positions in the queue, that is, Pdu0_3 → Pdu0_1 → Pdu0_2, and finally it is shown that the message routing of Pdu0 appears disordered.
[0005] Therefore, it is necessary to solve the problem of message disorder that occurs when message reception is frequent for message routing. Summary of the Invention
[0006] In view of this, it is necessary to provide a CAN gateway device, a message routing method, and a readable storage medium to solve the technical problem in the prior art that when the sending bus load rate is large, the routing message reception is extremely frequent, and then the routing sending message appears disordered.
[0007] In a first aspect, to solve the above technical problem, the present invention provides a CAN gateway device, including: a CAN control module, a CAN driver module, and a CAN interface module, which are sequentially communicatively connected;
[0008] The CAN gateway device further includes:
[0009] Cdd Rout communicatively connected to the CAN interface module, which is configured with a first-in-first-out storage module corresponding to the number of routing paths;
[0010] The Cdd Rout is used to receive the current message data, cache the current message data into the first-in-first-out storage module corresponding to the current routing path, and send the current message data according to the first-in-first-out principle.
[0011] In a possible implementation manner, the Cdd Rout includes a message data writing module and a message data sending module;
[0012] The message data writing module is used to query the current routing path corresponding to the current message data and write the current message data into the current writing position of the first-in-first-out storage module corresponding to the current routing path;
[0013] The message data sending module is used to send the current message data when the message data at the previous position of the current writing position has been sent.
[0014] In a second aspect, to solve the above technical problem, the present invention further provides a message routing method, which is applied to the above-mentioned CAN gateway device. The method includes:
[0015] Receive the current message data, cache the current message data into the first-in-first-out storage module corresponding to the current routing path, and send the current message data according to the first-in-first-out principle.
[0016] In a possible implementation manner, the receiving the current message data includes:
[0017] After the CAN control module receives the current message data, trigger a receive interrupt to the CAN driver module;
[0018] In the receive interrupt, the CAN driver module transfers the current message data to the CAN interface module through a first notification function;
[0019] The CAN interface module transfers the current message data to the Cdd Rout through a second notification function.
[0020] In a possible implementation manner, the caching the current message data into the first-in-first-out storage module corresponding to the current routing path includes:
[0021] The Cdd Rout queries the current routing path corresponding to the current message data, writes the current message data into the current writing position of the first-in-first-out storage module corresponding to the current routing path, and at the same time increments the write pointer of the first-in-first-out storage module by one.
[0022] In a possible implementation manner, after writing the current message data into the current writing position of the first-in-first-out storage module corresponding to the current routing path and incrementing the write pointer of the first-in-first-out storage module by one, it further includes:
[0023] Judge whether the first-in-first-out storage module is filled with data. If so, overwrite the oldest data with the current message data, set the write full flag of the first-in-first-out storage module to true, and increment the read pointer of the first-in-first-out storage module by one and point it to the oldest data that has not been read temporarily;
[0024] If not, no processing is performed.
[0025] In a possible implementation manner, after caching the current message data into the first-in first-out storage module corresponding to the current routing path, the method further includes:
[0026] Determine whether the message data at the previous position of the current write position has been sent;
[0027] If it has been sent, first increment the read pointer of the first-in first-out storage module by one to point to the next position to be read, call the first transmission function to transmit the current message data at the current write position to the CAN interface module, and record the routing path number of the current message data;
[0028] If it has not been sent, the first transmission function returns, and the current message data is temporarily cached in the first-in first-out storage module.
[0029] In a possible implementation manner, sending the current message data in a first-in first-out principle includes:
[0030] After the CAN interface module receives the current message data, transmit the current message data to the CAN driver module, and the CAN driver module transmits the current message data to the CAN control module;
[0031] After the CAN control module receives the current message data, trigger a send interrupt to the CAN driver module, the CAN driver module notifies the CAN interface module through a third notification function, and the CAN interface module notifies the Cdd Rout through a fourth notification function;
[0032] The Cdd Rout queries the current message data and routing path information according to the current message data number and the routing path number, and sets the send completion flag at the position pointed to by the previous read pointer in the first-in first-out storage module to true according to the current message data and routing path information.
[0033] In a possible implementation manner, it further includes:
[0034] The Cdd Rout queries whether there is message data to be sent in the first-in first-out storage module. If so, increment the read pointer of the first-in first-out storage module by one to point to the next position to be read.
[0035] In a third aspect, the present invention further provides a vehicle-mounted terminal, including a memory and a processor, wherein,
[0036] The memory is used to store programs;
[0037] The processor is coupled to the memory and is configured to execute the programs stored in the memory to implement the steps in the message routing method in any of the above possible implementation manners.
[0038] In a fourth aspect, the present invention further provides a computer-readable storage medium, on which a program or instruction is stored, and when the program or instruction is executed by a processor, the steps in the message routing method in any of the above possible implementation manners are implemented.
[0039] The beneficial effects of the present invention are as follows: The CAN gateway device provided by the present invention no longer processes routing messages through the original PduR (Protocol Data Unit Router), but through the newly created Cdd Rout (Complex Driver Router). By configuring a FIFO (First Input First Output) of a certain size for each routing path of each received message in the Cdd Rout layer, when a message is received on the receiving network, the Cdd Rout layer first stores the received message data in the FIFOs corresponding to all routing paths, and then judges one by one whether the previous message data in the FIFO has been sent. If not, the data is cached in the FIFO first; if it has been sent, the current message data is immediately sent. After the message data is sent, the data to be sent cached in the FIFO is further processed for sending in the transmission interrupt. The present invention ensures that there is only one piece of message data with the same ID in the transmission queue of the hardware layer (CAN Controller) at any time, avoiding the occurrence of out-of-order routing and sending of messages under extreme working conditions. Description of the Drawings
[0040] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the following drawings are only some embodiments of the present invention, and those skilled in the art can obtain other drawings without creative efforts based on these drawings.
[0041] Figure 1 It is a schematic diagram of an interaction process of an embodiment of gateway message routing in the prior art;
[0042] Figure 2 It is a schematic diagram of an embodiment of out-of-order messages in gateway message routing in the prior art;
[0043] Figure 3 Schematic diagram of the principle of an embodiment for message routing of the CAN gateway device provided by the present invention;
[0044] Figure 4 Schematic diagram of the timing process of an embodiment for message routing of the CAN gateway device provided by the present invention;
[0045] Figure 5 Schematic diagram of the process of Embodiment 1 for message routing of the CAN gateway device provided by the present invention;
[0046] Figure 6 Schematic diagram of the process of Embodiment 2 for message routing of the CAN gateway device provided by the present invention;
[0047] Figure 7 Schematic diagram of the structure of an embodiment of the vehicle-mounted terminal provided by the present invention. Detailed implementation manners
[0048] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative efforts belong to the scope of protection of the present invention.
[0049] It should be understood that the schematic drawings are not drawn to scale. The flowcharts used in the present invention illustrate the operations implemented according to some embodiments of the present invention. It should be understood that the operations in the flowcharts may not be implemented in sequence, and the steps without logical context relationships may be reversed or implemented simultaneously. In addition, those skilled in the art can add one or more other operations to the flowchart or remove one or more operations from the flowchart under the guidance of the content of the present invention. Some of the block diagrams shown in the drawings are functional entities, which do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor systems and / or microcontroller systems.
[0050] Referring to "embodiment" in this article means that the specific features, structures, or characteristics described in conjunction with the embodiment may be included in at least one embodiment of the present invention. The appearance of this phrase at various positions in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art explicitly and implicitly understand that the embodiments described herein can be combined with other embodiments.
[0051] The present invention provides a CAN gateway device, a message routing method, and a readable storage medium, which will be described separately below.
[0052] Figure 3 FIG. is a schematic diagram of the principle of an embodiment for message routing of the CAN gateway device provided by the present invention. In the embodiment of the present invention, compared with the prior art Figure 1 and Figure 2 innovative improvements have been made to the CAN communication transport layer, replacing the original PduR (Protocol Data Unit Router) layer with a newly created Cdd Rout (Complex Driver Router), while other modules remain unchanged.
[0053] In a specific embodiment, the CAN gateway device provided by the present invention includes: a CAN control module (i.e., CANController, hardware layer, CAN control layer), a CAN driver module (i.e., CAN Driver, CAN driver layer), and a CAN interface module (i.e., Canif, Controller Area Network Interface, which is an interface for the controller area network that allows communication and data exchange between different devices, and usually refers to the software module or component of the controller area network interface layer for managing message transmission and processing on the CAN bus). The CAN control module, the CAN driver module, and the CAN interface module are communicatively connected in sequence.
[0054] It can be understood that the above-mentioned CAN control module, CAN driver module, and CAN interface module are the conventional layers for in-vehicle communication using the CAN bus, which are already existing in the prior art, and their functions and roles will not be elaborated here.
[0055] To solve the problem of message out-of-order, the CAN gateway device provided by the present invention further includes: a Cdd Rout (Complex Driver Router, Cdd Rout layer) communicatively connected to the CAN interface module, which is configured with a first-in-first-out storage module (First Input First Output, FIFO) corresponding to the number of routing paths.
[0056] The Cdd Rout is used to receive the current message data, cache the current message data into the first-in-first-out storage module corresponding to the current routing path, and send the current message data according to the first-in-first-out principle.
[0057] It should be noted that when configuring the FIFO, it can be set according to the number of network nodes in vehicle-mounted communication. Ideally, the number of routing paths can be strictly consistent with the number of FIFIs. In actual operation, the number of FIFIs can be slightly more than the number of routing paths.
[0058] In a possible implementation, the Cdd Rout includes a message data writing module and a message data sending module;
[0059] The message data writing module is used to query the current routing path corresponding to the current message data and write the current message data into the current writing position of the first-in-first-out storage module corresponding to the current routing path;
[0060] The message data sending module is used to send the current message data when the message data at the previous position of the current writing position has been sent.
[0061] It should be noted that when sending a message, the message data needs to be written into the first-in-first-out storage module first, and then it is necessary to determine whether all the message data in the first-in-first-out storage module has been sent. After sending, the current message data is sent. If not all sent, the current message data is cached at the current position.
[0062] To clearly express the implementation of the present invention and to maintain the reading experience and consistency with the drawings, the description language of subsequent specific embodiments will be described in English abbreviations or English in the drawings.
[0063] First, specifically refer to Figure 3 , which details the message routing principle after replacing the original PduR (Protocol Data Unit Router) layer with the newly created Cdd Rout (Complex Driver Router).
[0064] In this embodiment, a FIFO of a certain size is configured for each routing path of each received message in the Cdd Rout layer. For example, in the Cdd Rout layer, through Path0, Path1, ……, Path nTo make a distinction, when the CANController receives the message Rx_Pdu0 of Net0, it is transmitted to the Cdd Rout layer through the Can Driver and Canif in sequence. The Cdd Rout layer first stores Rx_Pdu0 in the FIFO corresponding to the routing path, and then judges whether the previous Pdu0 has been sent for each FIFO. If it has not been sent, the data is first cached in the FIFO; if it has been sent, Pdu0 is immediately sent out. After Pdu0 is sent, the data to be sent cached in the FIFO is further processed for sending in the send interrupt.
[0065] After this operation of the present invention, it is ensured that there is only one piece of message data with the same ID in the send queue of the hardware layer (CAN Controller) at any time, avoiding the occurrence of out-of-order routing of messages in extreme working conditions.
[0066] To further accurately describe how to perform message routing through the CAN gateway device provided by the present invention, the present invention also provides a message routing method, which is applied to the above-mentioned CAN gateway device. The method includes:
[0067] Receive the current message data, cache the current message data in the first-in first-out storage module corresponding to the current routing path, and send the current message data according to the first-in first-out principle.
[0068] In a possible implementation manner, the receiving the current message data includes:
[0069] After the CAN control module receives the current message data, it triggers a receive interrupt to the CAN driver module;
[0070] In the receive interrupt, the CAN driver module transfers the current message data to the CAN interface module through the first notification function;
[0071] The CAN interface module transfers the current message data to the Cdd Rout through the second notification function.
[0072] In a specific implementation manner, the first notification function is CanIf_RxIndicaiton, which is a function generated by the CanIf layer that can notify data information. The specific generation process can adopt the prior art and will not be elaborated here. The second notification function is CddRout_RxIndicaiton, which is a function generated by the CddRout layer that can notify data information. The specific generation process can adopt the prior art and will not be elaborated here either.
[0073] In a possible implementation, caching the current message data into the first-in-first-out storage module corresponding to the current routing path includes:
[0074] The Cdd Rout queries the current routing path corresponding to the current message data, writes the current message data into the current write position of the first-in-first-out storage module corresponding to the current routing path, and simultaneously increments the write pointer of the first-in-first-out storage module by one.
[0075] In a possible implementation, after writing the current message data into the current write position of the first-in-first-out storage module corresponding to the current routing path and simultaneously incrementing the write pointer of the first-in-first-out storage module by one, the following steps are further included:
[0076] Determine whether the first-in-first-out storage module is filled with data. If so, overwrite the oldest data with the current message data, set the write full flag of the first-in-first-out storage module to true, and increment the read pointer of the first-in-first-out storage module by one, and point it to the old data that has not been read temporarily;
[0077] If not, do nothing.
[0078] In a possible implementation, after caching the current message data into the first-in-first-out storage module corresponding to the current routing path, the following steps are further included:
[0079] Determine whether the message data at the previous position of the current write position has been sent successfully;
[0080] If it has been sent successfully, first increment the read pointer of the first-in-first-out storage module by one to point to the next position to be read, call the first transmission function to transmit the current message data at the current write position to the CAN interface module, and simultaneously record the routing path number of the current message data;
[0081] If it has not been sent successfully, the first transmission function returns, and the current message data is temporarily cached in the first-in-first-out storage module.
[0082] In a specific implementation, the first transmission function is CanIf_Transmit, which is a function generated by the CanIf layer that can transmit message data. The specific generation process can adopt existing technologies and will not be elaborated here.
[0083] In a possible implementation, sending the current message data according to the first-in-first-out principle includes:
[0084] After the CAN interface module receives the current message data, it transmits the current message data to the CAN driver module, and the CAN driver module then transmits the current message data to the CAN control module;
[0085] After the CAN control module receives the current message data, it triggers a transmit interrupt to the CAN driver module. The CAN driver module notifies the CAN interface module through a third notification function, and the CAN interface module notifies the Cdd Rout through a fourth notification function;
[0086] The Cdd Rout queries the current message data and routing path information based on the current message data number and the routing path number, and sets the transmission completion flag at the position pointed to by the previous read pointer in the first-in-first-out storage module to true according to the current message data and routing path information.
[0087] In a specific implementation manner, the third notification function is CanIf_TxConfirmation, which is a function generated by the CanIf layer that can notify data information. The specific generation process can adopt existing technologies and will not be elaborated here. The second notification function is CddRout_TxConfirmation, which is a function generated by the CddRout layer that can notify data information. The specific generation process can adopt existing technologies and will not be elaborated here either.
[0088] In a possible implementation manner, it further includes:
[0089] The Cdd Rout queries whether there is message data to be sent in the first-in-first-out storage module. If so, it increments the read pointer of the first-in-first-out storage module to point to the next position to be read.
[0090] The above describes the general implementation scheme of message routing. To more accurately understand the implementation process of the scheme, please further refer to Figure 4 , Figure 4 which is a schematic timing diagram of an embodiment of message routing for the CAN gateway device provided by the present invention.
[0091] In this implementation manner, its specific implementation process is as follows:
[0092] (1) When a message is received on the CAN Controller, it will trigger a receive interrupt. In the receive interrupt, the received message data is passed to CanIf through the notification function CanIf_RxIndicaiton. This step is the same as the traditional scheme;
[0093] (2)CanIf passes the received message data to the CddRout layer through the notification function CddRout_RxIndicaiton; in CddRout_RxIndicaiton, first query the routing path corresponding to the received message, then write the message data into the FIFO of the corresponding routing path, and at the same time increment the write pointer of the FIFO by 1 respectively; if the FIFO is full, the new data overwrites the oldest data, and set the write full flag (WriteFull) of the FIFO to TRUE, and increment the read pointer of the FIFO by 1, pointing to the old data that has not been read temporarily;
[0094] (3)After the data is written into the FIFO, continue to determine whether the message data at the previous position of the current write position has been sent. If it has been sent, first increment the read pointer of the FIFO by 1, pointing to the next position to be read out, and then immediately send the message data at the current position by calling CanIf_Transmit, and at the same time record the routing path Id of the received message for confirming the routing information in the subsequent transmit confirmation notification (TxConfirmation); if it has not been sent, the function returns and the data is temporarily cached in the FIFO.
[0095] (4)After the message is processed and sent out by CanIf, Can Driver and Can Controller, it will trigger the transmit interrupt of CanController. In the transmit interrupt, CanIf is notified through CanIf_TxConfirmation, and then the Cdd Rout layer is notified through CddRout_TxConfirmation.
[0096] (5)In CddRout_TxConfirmation, the Cdd Rout layer first queries the corresponding received message and its routing path information according to the transmit message Id and the previously recorded routing path Id, and then according to this information, set the transmit completion flag of the position pointed to by the previous read pointer in the corresponding FIFO to TRUE, and then query whether there is still message data to be sent in the FIFO. If so, first increment the read pointer of the FIFO by 1, pointing to the next position to be read, and then call CanIf_Transmit to immediately send the message data at the current position.
[0097] It can be understood that through the execution of the above embodiments, it is ensured that there is only one piece of message data with the same ID in the transmit queue of the hardware layer (CANController) at any time, avoiding the occurrence of out-of-order routing transmit messages under extreme working conditions.
[0098] In specific implementation, after the message data is stored in the FIFO, it is then determined whether to send it immediately, and there are two cases: First, there is no message to be sent in the FIFO of each routing path of the current FIFO, so the message data can be sent immediately; Second, there is still more than one unsent message cached in each routing path of the current FIFO. At this time, if another message is received from Net0, it needs to be sent according to the principle of first-in, first-out after waiting. For the specific implementation process, please refer to Figure 5 and Figure 6 。
[0099] Figure 5 FIG. is a schematic flowchart of the first embodiment of message routing for the CAN gateway device provided by the present invention. In this embodiment, message Pdu0 is received by Net0 and routed to Net1 and Net2 respectively. Assume that there is no message to be sent in the FIFO of each routing path in the Cdd Rout layer. At this time, another message is received from Net0. The specific implementation process is as follows:
[0100] (1) After receiving message Pdu0 on the CAN Controller, a receive interrupt is triggered. In the receive interrupt, the received message data is passed to CanIf through the notification function CanIf_RxIndicaiton;
[0101] (2) CanIf passes the received message data to the CddRout layer through the notification function CddRout_RxIndicaiton; In CddRout_RxIndicaiton, first query the routing path corresponding to Pdu0, where path Path0 corresponds to Net1 and path Path1 corresponds to Net2; then write the message data into the FIFOs of the two paths respectively, and at the same time increment the write pointers of the FIFOs by 1;
[0102] (3) After the data is written into the FIFO, since there was no unsent message data in the FIFO before, first increment the read pointer of the FIFO by 1, then call CanIf_Transmit to immediately send the just-written message data, and at the same time record the routing path Id of the received message for confirming the routing information in the subsequent transmit confirmation notification (TxConfirmation);
[0103] (4) After the message is sent out after being processed by CanIf, Can Driver and Can Controller, a transmit interrupt of the CanController will be triggered. In the transmit interrupt, CanIf is notified through CanIf_TxConfirmation, and then the Cdd Rout layer is notified through CddRout_TxConfirmation;
[0104] (5) In CddRout_TxConfirmation, the Cdd Rout layer first queries the corresponding received message and its routing path information according to the sent message ID and the previously recorded routing path ID. Then, based on this information, it sets the transmission completion flag at the position pointed to by the previous read pointer in the corresponding FIFO to TRUE, and then queries whether there is still message data to be sent in this FIFO. Since there is no message to be sent in the FIFO at this time, the process ends.
[0105] Figure 6 It is a schematic flowchart of the second embodiment of message routing for the CAN gateway device provided by the present invention. In this embodiment, message Pdu0 is received by Net0 and routed to Net1 and Net2 respectively. Assume that there are still two unsent messages cached in each routing path in the Cdd Rout layer. At this time, another message is received from Net0. The specific implementation process is as follows:
[0106] (1) After the CAN Controller receives message Pdu0, it triggers a receive interrupt. In the receive interrupt, the received message data is passed to CanIf through the notification function CanIf_RxIndicaiton;
[0107] (2) CanIf passes the received message data to the CddRout layer through the notification function CddRout_RxIndicaiton; in CddRout_RxIndicaiton, first query the routing path corresponding to Pdu0, where path Path0 corresponds to Net1 and path Path1 corresponds to Net2; then write the message data into the FIFOs of the two paths respectively, and at the same time increment the write pointers of the FIFOs by 1;
[0108] (3) After the data is written into the FIFO, continue to determine whether the message data at the previous position of the current write position has been sent. Since there are still two Pdu data cached in the FIFO, the function returns and the data is temporarily cached in the FIFO;
[0109] (4) After the old message Pdu0 that has been sent is processed and sent through CanIf, Can Driver, and Can Controller, it will trigger a transmit interrupt of the Can Controller. In the transmit interrupt, it notifies CanIf through CanIf_TxConfirmation, and then notifies the Cdd Rout layer through CddRout_TxConfirmation;
[0110] (5) In CddRout_TxConfirmation, the Cdd Rout layer first queries the corresponding received message and its routing path information based on the transmitted message Pdu0 Id and the previously recorded routing path Id. Then, based on this information, it sets the transmission completion flag at the position pointed to by the previous read pointer in the corresponding FIFO to TRUE. Next, it checks whether there is any message data pending transmission in this FIFO. Since there are still two messages pending transmission in the FIFO, it first increments the read pointer of this FIFO by 1 to point to the next position to be read, and then calls CanIf_Transmit to immediately transmit the message data at the current position.
[0111] (6) The subsequent message transmission process repeats the process of steps (2) to (5) until all the buffered messages in the FIFO are transmitted, and the process ends.
[0112] It can be understood that through the implementation of the above two embodiments, regardless of the state of the message data, it can ensure that there is only one message data with the same ID in the transmission queue of the hardware layer (CAN Controller) at any time, avoiding the occurrence of out-of-order routing of transmitted messages under extreme working conditions.
[0113] As Figure 7 shown, the present invention also correspondingly provides a vehicle-mounted terminal 700. The vehicle-mounted terminal 700 includes a processor 701, a memory 702, and a display 703. Figure 7 Only some components of the vehicle-mounted terminal 700 are shown, but it should be understood that it is not required to implement all the shown components, and more or fewer components can be alternatively implemented.
[0114] In some embodiments, the processor 701 may be a central processing unit (CPU), a microprocessor, or other data processing chips, and is used to run the program code stored in the memory 702 or process data, such as the CAN gateway device in the present invention.
[0115] In some embodiments of the present invention, the processor 701 may be a single server or a server group. The server group may be centralized or distributed. In some embodiments, the processor 701 may be local or remote. In some embodiments, the processor 701 may be implemented on a cloud platform. In one embodiment, the cloud platform may include a private cloud, a public cloud, a hybrid cloud, a community cloud, a distributed cloud, an internal cloud, a multi-cloud, etc., or any combination of the above.
[0116] The memory 702 may be an internal storage unit of the vehicle terminal 700 in some embodiments, such as the hard disk or memory of the vehicle terminal 700. The memory 702 may also be an external storage device of the vehicle terminal 700 in other embodiments, such as a plug-in hard disk equipped on the vehicle terminal 700, a Smart Media Card (SMC), a Secure Digital (SD) card, a Flash Card, etc.
[0117] Furthermore, the memory 702 may include both the internal storage unit of the vehicle terminal 700 and an external storage device. The memory 702 is used to store the application software installed in the vehicle terminal 700 and various types of data.
[0118] The display 703 may be an LED display, a liquid crystal display, a touch liquid crystal display, and an OLED (Organic Light-Emitting Diode) toucher, etc. in some embodiments. The display 703 is used to display the information of the vehicle terminal 700 and to display a visual user interface. The components 701-703 of the vehicle terminal 700 communicate with each other through the system bus.
[0119] In some embodiments of the present invention, when the processor 701 executes the computer program in the memory 702, the following steps may be implemented:
[0120] Receive the current message data, cache the current message data into the first-in-first-out storage module corresponding to the current routing path, and send the current message data according to the first-in-first-out principle.
[0121] It should be understood that when the processor 701 executes the computer program in the memory 702, in addition to the above functions, other functions may also be implemented. For specific details, reference may be made to the description of the corresponding method embodiments above.
[0122] Furthermore, the embodiments of the present invention do not specifically limit the type of the vehicle terminal 700 mentioned. The vehicle terminal 700 may be a terminal fixed on the vehicle, such as a terminal fixedly connected to the vehicle console and in communication, such as a desktop computer with a touch-sensitive surface (such as a touch panel); it may also be a portable vehicle terminal. Exemplary embodiments of the portable vehicle terminal include, but are not limited to, portable vehicle terminals running on IOS, android, microsoft, HarmonyOS or other operating systems.
[0123] Accordingly, an embodiment of the present invention further provides a computer-readable storage medium, which is used to store computer-readable programs or instructions. When the programs or instructions are executed by a processor, the steps or functions in the CAN gateway device provided in the above method embodiments can be implemented, specifically as follows:
[0124] Receive the current message data, cache the current message data into the first-in-first-out storage module corresponding to the current routing path, and send the current message data according to the first-in-first-out principle.
[0125] Those skilled in the art can understand that all or part of the processes for implementing the methods in the above embodiments can be completed by instructing relevant hardware (such as a processor, a controller, etc.) through a computer program, and the computer program can be stored in a computer-readable storage medium. Among them, the computer-readable storage medium is a magnetic disk, an optical disk, a read-only memory or a random access memory, etc.
[0126] The above has introduced in detail a CAN gateway device, a message routing method, and a readable storage medium provided by the present invention. Specific examples are used in this article to elaborate on the principle and implementation manner of the present invention. The description of the above embodiments is only used to help understand the method and its core idea of the present invention; at the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation manner and application scope. In summary, the content of this specification should not be construed as a limitation to the present invention.
Claims
1. A CAN gateway device, comprising a CAN control module, a CAN driver module, and a CAN interface module, wherein the CAN control module, the CAN driver module, and the CAN interface module are sequentially connected in communication, characterized in that: The CAN gateway device also includes: A Cdd Rout layer communicatively connected to the CAN interface module, configured with a first-in-first-out storage module corresponding to the number of routing paths; The Cdd Rout layer is used to receive current message data, cache the current message data in a first-in-first-out storage module corresponding to the current routing path, and send the current message data according to the first-in-first-out principle; The current message data is cached in a first-in-first-out storage module corresponding to the current routing path, and then the following steps are further included: Determine whether the message data at the previous position of the current write position has been sent; If the sending is completed, the read pointer of the first-in-first-out storage module is increased by one to point to the next position to be read, and the first transmission function is called to transmit the current message data of the current write position to the CAN interface module, and the routing path number of the current message data is recorded at the same time; If the sending is not completed, the first transmission function returns, and the current message data is temporarily cached in the first-in-first-out storage module; When the current message data is successfully sent, the sending interrupt of the CAN control module is triggered, and after the sending interrupt, the Cdd Rout layer is notified; The Cdd Rout layer queries the corresponding received message and its routing path information according to the message number of the sent message data and the previously recorded routing path number, and queries whether there is any message data to be sent in the first-in-first-out storage module. If so, the message data at the next to-be-sent position will be sent out immediately.
2. The CAN gateway device according to claim 1, characterized in that: The Cdd Rout layer includes a message data writing module and a message data sending module; The message data writing module is used to query the current routing path corresponding to the current message data, and write the current message data into the current writing position of the first-in-first-out storage module corresponding to the current routing path; The message data sending module is used to send the current message data when the message data at the previous position of the current writing position has been sent.
3. A message routing method, applied to the CAN gateway device according to any one of claims 1-2, characterized in that: The method comprises: Receive current message data, cache the current message data in a first-in-first-out storage module corresponding to the current routing path, and send the current message data according to the first-in-first-out principle.
4. The message routing method according to claim 3, characterized in that: The receiving current message data comprises: When the CAN control module receives the current message data, a receiving interrupt is triggered to the CAN driver module; In the receiving interrupt, the CAN driver module transmits the current message data to the CAN interface module through the first notification function; The CAN interface module transfers the current message data to the Cdd Rout layer through a second notification function.
5. The message routing method according to claim 4, characterized in that: The step of caching the current message data into a first-in-first-out storage module corresponding to the current routing path includes: The Cdd Rout layer queries the current routing path corresponding to the current message data, writes the current message data into the current write position of the first-in-first-out storage module corresponding to the current routing path, and increases the write pointer of the first-in-first-out storage module by one.
6. The message routing method according to claim 5, characterized in that: The step of writing the current message data into the current write position of the first-in-first-out storage module corresponding to the current routing path and increasing the write pointer of the first-in-first-out storage module by one further comprises: Determine whether the FIFO storage module is full of data. If so, overwrite the oldest data with the current message data, set the full flag position of the FIFO storage module to true, and increase the read pointer of the FIFO storage module by one to point to the old data that has not been read temporarily; If not, no action will be taken.
7. The message routing method according to claim 3, characterized in that: Sending the current message data according to the first-in-first-out principle includes: After the CAN interface module receives the current message data, it transmits the current message data to the CAN driver module, and the CAN driver module then transmits the current message data to the CAN control module; When the CAN control module receives the current message data, it triggers to send an interrupt to the CAN driver module, the CAN driver module notifies the CAN interface module through a third notification function, and the CAN interface module notifies the Cdd Rout layer through a fourth notification function; The Cdd Rout layer queries the current message data and routing path information according to the message number of the current message data and the routing path number, and sets the sending completion flag of the position pointed to by the previous read pointer in the first-in-first-out storage module to true according to the current message data and routing path information.
8. The message routing method according to claim 7, characterized in that: Also includes: The Cdd Rout layer queries whether there is message data to be sent in the first-in-first-out storage module. If so, the read pointer of the first-in-first-out storage module is increased by one to point to the next position to be read.
9. A computer-readable storage medium, characterized in that: The readable storage medium stores a program or instruction, and when the program or instruction is executed by the processor, the steps in the message routing method described in any one of claims 3 to 8 are implemented.