CAN protocol automatic identification method, device, equipment and medium
Through the CAN protocol method of automatic identification and priority management, the compatibility problem of BMS system in a multi-protocol environment is solved, and an efficient and reliable communication solution is achieved.
Patent Information
- Application Number
- CN202410065581.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-16
- Publication Date
- 2025-07-18
AI Technical Summary
When connecting to PCS/EMS systems, it is difficult to compatible with multiple CAN protocols, resulting in low communication accuracy.
By receiving external protocols, making judgments based on preset priority information and conducting protocol transitions or protocol arbitration, different CAN protocols are automatically identified and distinguished to ensure that high-priority protocols have no interference transmission.
It improves the efficiency of the BMS system to adapt to different CAN protocols, simplifies system design, saves CAN resources, enhances the adaptability and flexibility of the system, and ensures the smooth transmission of high-priority data.
Smart Images

Figure CN120343114A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of bus communication technologies, and in particular, to a method, apparatus, device, and medium for automatically identifying CAN protocols. Background Art
[0002] CAN communication networks are a very common communication method in energy storage systems. In an actual CAN network, multiple device nodes are mounted, and at this time each device node will have its own communication protocol.
[0003] However, when the BMS system is docked with the PCS or EMS system, the PCS / EMS will have multiple CAN protocol communication methods, and at this time it is very difficult for the BMS system to be compatible with these communication protocols. Therefore, there is an urgent need for a method for the BMS system to adapt to multiple protocols in the CAN local area network, so as to improve the accuracy of communication of the BMS system and better dock with the PCS and EMS systems of other manufacturers. Summary of the Invention
[0004] In view of this, embodiments of this application provide a method, apparatus, device, and medium for automatically identifying CAN protocols, which can improve the efficiency of the BMS system in adapting to different CAN protocols.
[0005] The technical solution of the embodiments of this application is implemented as follows:
[0006] In a first aspect, embodiments of this application provide a method for automatically identifying CAN protocols, including the following steps:
[0007] Receive an external protocol, and judge the priority of the external protocol and the current protocol based on preset priority information. If the priority of the external protocol is higher than the priority of the current protocol, perform protocol transition; if the priority of the external protocol is not higher than the priority of the current protocol, do not perform protocol transition; wherein, the protocol transition is used to update the current protocol to the external protocol;
[0008] Judge whether the current protocol is an immediate reply protocol based on preset type information. If so, directly reply to the information; if not, perform protocol arbitration based on a timer; wherein, performing protocol arbitration based on a timer includes replying to the information after the timer period is completed; otherwise, do not reply to the information.
[0009] In a second aspect, embodiments of this application further provide a device for automatically identifying CAN protocols, and the device includes:
[0010] The first judgment module is used to receive an external protocol, judge the priority of the external protocol and the current protocol based on preset priority information. If the priority of the external protocol is higher than that of the current protocol, protocol transition is performed; if the priority of the external protocol is not higher than that of the current protocol, protocol transition is not performed; wherein, the protocol transition is used to update the current protocol to the external protocol.
[0011] The second judgment module is used to judge whether the current protocol is an immediate reply protocol based on preset type information. If so, information is directly replied; if not, protocol arbitration is performed based on a timer; wherein, performing protocol arbitration based on a timer includes replying information after the timer period is completed; otherwise, information is not replied.
[0012] In a third aspect, an embodiment of the present application further provides an electronic device, including: a processor, a storage medium, and a bus. The storage medium stores machine-readable instructions executable by the processor. When the electronic device runs, communication between the processor and the storage medium is performed through the bus, and the processor executes the machine-readable instructions to execute the CAN protocol automatic recognition method according to any one of the first aspects.
[0013] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is run by a processor, the CAN protocol automatic recognition method according to any one of the first aspects is executed.
[0014] The embodiments of the present application have the following beneficial effects:
[0015] (1) Multi-protocol support and resource optimization: Through a single CAN port, this method can support and be compatible with a variety of different CAN protocols. This means that under the same hardware resources, the functions of the system are greatly expanded without adding additional hardware or ports for each protocol. This method not only simplifies the system design but also saves CAN resources, thereby improving the overall performance of the system.
[0016] (2) Automatic protocol recognition during operation: During operation, this method can automatically recognize and distinguish different CAN protocols. This means that the system no longer requires manual intervention or preset conditions to recognize protocols, but can dynamically and intelligently recognize them based on the actually received data. This automatic recognition function enhances the adaptability and flexibility of the system.
[0017] (3) Priority management to avoid interference: In the same CAN sub-network, since various CAN protocols may coexist simultaneously, to avoid interference from low-priority protocols to high-priority protocols, this method only responds to high-priority CAN protocols. This ensures that high-priority data can be transmitted smoothly and without interference, improving the efficiency and reliability of communication.
[0018] In summary, the embodiments of the present application not only improve the resource utilization rate and performance of the system, but also enhance the intelligence and adaptability of the system. It brings a more efficient and reliable communication solution to the fields of automotive electronics and industrial automation. Brief Description of the Drawings
[0019] To more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings required to be used in the embodiments. It should be understood that the following drawings only show some embodiments of the present application, and therefore should not be regarded as a limitation of the scope. For those of ordinary skill in the art, without creative efforts, other relevant drawings can also be obtained based on these drawings.
[0020] Figure 1 is a schematic flowchart of steps S101 - S102 provided by the embodiments of the present application;
[0021] Figure 2 is a schematic flowchart of steps S201 - S202 provided by the embodiments of the present application;
[0022] Figure 3 is a schematic diagram of the principle of automatic CAN protocol identification provided by the embodiments of the present application;
[0023] Figure 4 is one of the schematic diagrams of the principle of external timeout fault determination provided by the embodiments of the present application;
[0024] Figure 5 is the other schematic diagram of the principle of external timeout fault determination provided by the embodiments of the present application;
[0025] Figure 6 is a schematic structural diagram of the automatic CAN protocol identification device provided by the embodiments of the present application;
[0026] Figure 7 is a schematic structural diagram of the composition of the electronic device provided by the embodiments of the present application. Detailed Embodiments
[0027] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the following will clearly and completely describe the technical solutions in the embodiments of this application with reference to the accompanying drawings in the embodiments of this application. It should be understood that the accompanying drawings in this application are only for the purpose of illustration and description, and are not used to limit the protection scope of this application. Additionally, it should be understood that the schematic drawings are not drawn to scale. The flowcharts used in this application illustrate the operations implemented according to some embodiments of this application. It should be understood that the operations in the flowchart may not be implemented in sequence, and steps without logical context relationships may be reversed in order 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 this application.
[0028] In the following description, reference is made to "some embodiments", which describe a subset of all possible embodiments. However, it can be understood that "some embodiments" can be the same subset or different subsets of all possible embodiments, and can be combined with each other without conflict.
[0029] In addition, the described embodiments are only a part of the embodiments of this application, rather than all of the embodiments. The components of the embodiments of this application usually described and illustrated in the accompanying drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely represents the selected embodiments of this application. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative efforts fall within the protection scope of this application.
[0030] In the following description, the terms "first", "second", and "third" involved are only used to distinguish similar objects, and do not represent a specific order for the objects. It can be understood that "first", "second", and "third" can be interchanged with a specific order or sequence when allowed, so that the embodiments of this application described here can be implemented in an order other than that illustrated or described here.
[0031] It should be noted that the term "including" will be used in the embodiments of this application to indicate the existence of the features stated thereafter, but does not exclude the addition of other features.
[0032] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the technical field to which this application belongs. The terms used herein are for the purpose of describing the embodiments of this application and do not limit this application.
[0033] See Figure 1 , Figure 1It is a schematic flowchart of steps S101 - S102 of the CAN protocol automatic recognition method provided by an embodiment of this application, and will be described in conjunction with Figure 1 the steps S101 - S102 shown.
[0034] Step S101: Receive an external protocol, and judge the priority of the external protocol and the current protocol based on preset priority information. If the priority of the external protocol is higher than the priority of the current protocol, perform protocol transition; if the priority of the external protocol is not higher than the priority of the current protocol, do not perform protocol transition; wherein, the protocol transition is used to update the current protocol to the external protocol;
[0035] Step S102: Judge whether the current protocol is an immediate reply protocol based on preset type information. If so, directly reply the information; if not, perform protocol arbitration based on a timer; wherein, performing protocol arbitration based on a timer includes replying the information after the timer period is completed; otherwise, do not reply the information.
[0036] The above CAN protocol automatic recognition method has the following beneficial effects:
[0037] (1) Multi - protocol support and resource optimization: Through a single CAN port, this method can support and be compatible with multiple different CAN protocols. This means that under the same hardware resources, the functions of the system are greatly expanded without adding additional hardware or ports for each protocol. This method not only simplifies the system design, but also saves CAN resources, thereby improving the overall performance of the system.
[0038] (2) Automatic protocol recognition during operation: During operation, this method can automatically recognize and distinguish different CAN protocols. This means that the system no longer needs manual intervention or preset conditions to recognize protocols, but can dynamically and intelligently recognize according to the actually received data. This automatic recognition function enhances the adaptability and flexibility of the system.
[0039] (3) Priority management to avoid interference: In the same CAN sub - network, since various CAN protocols may exist simultaneously, in order to avoid interference of low - priority protocols on high - priority protocols, this method only responds to high - priority CAN protocols. This ensures that high - priority data can be transmitted smoothly and without interference, improving the communication efficiency and reliability.
[0040] In summary, the embodiments of this application not only improve the resource utilization rate and performance of the system, but also enhance the intelligence and adaptability of the system. It brings a more efficient and reliable communication solution to the fields of automotive electronics and industrial automation.
[0041] The above exemplary steps of the embodiments of the present application will be described separately below.
[0042] In step S101, an external protocol is received, and the priorities of the external protocol and the current protocol are judged based on preset priority information. If the priority of the external protocol is higher than that of the current protocol, protocol transition is performed; if the priority of the external protocol is not higher than that of the current protocol, protocol transition is not performed; wherein, the protocol transition is used to update the current protocol to the external protocol.
[0043] Here, when the system receives an externally incoming CAN protocol, it will first perform reception. These external protocols can be data signals from other devices or systems. The system compares the priority of the newly received external protocol with that of the currently processed protocol according to the preset priority information. The determination of the priority can be based on various factors, such as the type of the protocol, the identity of the sender, the importance of the data, etc.
[0044] If the priority of the newly received external protocol is higher than that of the current protocol, the system will perform "protocol transition". This means that the system will stop the current processing and update the external protocol to the currently processed protocol. This mechanism allows the system to automatically adjust the processed tasks according to the priority, ensuring that high-priority protocols are processed in a timely manner.
[0045] In step S102, it is judged whether the current protocol is an immediate reply protocol based on preset type information. If so, information is directly replied; if not, protocol arbitration is performed based on a timer; wherein, performing protocol arbitration based on a timer includes replying information after the timer period is completed; otherwise, information is not replied.
[0046] Here, the system judges whether the current protocol is an "immediate reply protocol" according to the preset type information. An immediate reply protocol refers to a protocol that requires the system to respond immediately after reception.
[0047] If the current protocol is not an immediate reply protocol, the system will use a timer for arbitration. The timer will start timing and judge whether information needs to be replied according to preset conditions. After the timer period is completed, the system will judge whether information needs to be replied according to the conditions. This can be based on various factors, such as data integrity, error rate, etc.
[0048] The main function of the timer period is to provide a certain delay or waiting time in the case of a non-immediate reply protocol. This helps the system to remain stable and efficient when processing non-urgent tasks. If the timer period is not completed and other reply conditions are not met, the system will not reply information. This can avoid unnecessary communication and resource consumption.
[0049] The above method has good scalability and adaptability. Through the preset priority information and type information, the system can flexibly process various CAN protocols and automatically adjust and optimize as needed. By automatically identifying and responding to CAN protocols, this solution can improve the efficiency and response ability of the system. This helps to ensure that the system is always in an efficient and reliable state to meet various real-time communication requirements.
[0050] In some embodiments, referring to Figure 2 , Figure 2 is a schematic flow chart of steps S201 - S202 provided by an embodiment of the present application. Priority information can be preset through steps S201 - S202, and will be described in combination with each step.
[0051] In step S201, a protocol array is preset, where the protocol array is used to store protocol identifiers of multiple target protocols.
[0052] In step S202, the protocol identifiers of the multiple target protocols in the protocol array are sorted, where the protocol identifier that is more forward has a higher priority.
[0053] Here, first, a protocol array needs to be preset. This array is used to store protocol identifiers of multiple target protocols. The protocol identifier can be a unique identifier pointing to a specific protocol, used to distinguish different protocols, such as CANID.
[0054] Next, the protocol identifiers of the multiple target protocols in the protocol array are sorted. The basis for sorting is the priority of the protocol. The protocol identifier that is more forward has a higher priority. This can ensure that when the system compares the priority of a newly received external protocol with the current protocol, it can make a judgment according to the preset order.
[0055] When performing the sorting process, the protocol identifiers can be sorted according to the set priority rules. The priority rules can be formulated according to actual needs, such as setting according to factors such as the type of protocol, importance, and identity of the sender.
[0056] To maintain the timeliness and accuracy of the priority information, the protocol array can be updated and maintained regularly. For example, when a new protocol is added or the priority of an existing protocol changes, the protocol array can be re - sorted or the corresponding protocol identifier can be adjusted.
[0057] In the entire system, the maintenance and update of the protocol array need to be consistent. Ensure that all relevant components or modules follow the same priority rules and sorting methods to ensure the overall coordination and consistency of the system.
[0058] The above method presets priority information. When the system receives an external protocol, it can compare and judge according to the preset priority information, and then decide whether to perform protocol transition or directly reply to the information based on the priority level. This helps to improve the efficiency and response ability of the system and ensure the timely processing of high-priority protocols.
[0059] In some embodiments, after receiving the external protocol, the method further includes:
[0060] Judge whether the protocol identifier of the external protocol exists in the protocol array. If so, judge the priority of the external protocol and the current protocol based on the preset priority information; if not, do not process.
[0061] Here, the system first judges whether the protocol identifier of the external protocol exists in the preset protocol array. If it exists, it means that the external protocol is a protocol known or recognizable by the system.
[0062] If the protocol identifier exists in the protocol array, the system further judges the priority of the external protocol and the current protocol based on the preset priority information. The determination of the priority can be based on various factors, such as the type of the protocol, the identity of the sender, the importance of the data, etc.
[0063] If the protocol identifier of the external protocol does not exist in the protocol array, the system will not perform any processing, which can avoid unnecessary processing of unknown or unrecognizable protocols.
[0064] By judging the existence or non-existence of the protocol identifier and accordingly deciding whether to perform priority comparison, the robustness and reliability of the system can be enhanced. Only when the external protocol is known and recognizable will the system perform corresponding processing according to the priority, which helps to avoid misjudgment and incorrect operations.
[0065] The above method allows the system to be more easily extended and updated in the future. When a new protocol needs to be added, only its protocol identifier needs to be added to the protocol array without modifying the existing logic or code. This can maintain the flexibility and scalability of the system.
[0066] In some embodiments, after receiving the external protocol, the method further includes:
[0067] If the current protocol does not exist, directly determine the external protocol as the current protocol.
[0068] Here, after receiving the external protocol, if there is no currently processed protocol, that is, the current protocol does not exist, then the system directly determines the external protocol as the current protocol for processing. This can avoid the situation of processing vacancies or delays and ensure that the system can respond to external protocols in a timely manner.
[0069] This processing method is applicable to scenarios that require quick response or processing, such as real-time communication or critical task handling. By ensuring that external protocols can be promptly recognized and processed when they arrive, the system can improve the response speed and processing efficiency, better meeting the real-time requirements.
[0070] At the same time, such a design also enhances the adaptability and flexibility of the system. Even in the absence of the current protocol, the system can quickly respond according to external protocols instead of waiting for new protocols to appear or be processed. This mechanism makes the system more intelligent and autonomous, better able to adapt to the changing external environment and workload.
[0071] In some embodiments, the type information is preset in the following manner:
[0072] Classify the protocol identifiers of the multiple target protocols in the protocol array to obtain protocol identifiers of the first type and protocol identifiers of the second type. Among them, the protocol identifiers of the first type indicate that the protocol requires an immediate reply, and the protocol identifiers of the second type indicate that the protocol does not require a reply during the protocol arbitration.
[0073] Here, first, classify the protocol identifiers of the multiple target protocols stored in the protocol array. The basis for classification is the type of the protocol, and the protocol identifiers can be divided into the first type and the second type.
[0074] The protocol identifiers of the first type are used to indicate those protocols that require an immediate reply. These protocols usually have a higher priority or importance and require the system to respond immediately after reception. The protocol identifiers of the second type are used to indicate those protocols that do not require a reply during the protocol arbitration. These protocols may have a lower priority or specific processing requirements and need to be replied at a specific time or under specific conditions.
[0075] When performing the classification process, the protocol identifiers can be classified according to preset classification rules. The classification rules can be formulated according to actual needs, such as classifying according to factors such as the real-time requirements of the protocol, the priority level, and the identity of the sender.
[0076] To maintain the real-time nature and accuracy of the type information, the classification of the protocol identifiers can be updated and maintained regularly. For example, when a new protocol is added or the type of an existing protocol changes, the protocol array can be reclassified or the corresponding protocol identifiers can be adjusted.
[0077] Throughout the system, the classification maintenance and update of the protocol identifiers need to be consistent. Ensure that all relevant components or modules follow the same classification rules and classification methods to ensure the overall coordination and consistency of the system.
[0078] By presetting type information in the above - mentioned manner, when the system receives an external protocol, it can determine whether the current protocol is an immediate reply protocol according to the preset type information. This helps the system adopt different processing strategies according to different types of protocols, improving the efficiency and response ability of the system.
[0079] In some embodiments, the protocol arbitration based on a timer includes:
[0080] Judge whether the running period of the timer has ended. If so, determine the current protocol as the final protocol and reply to the information of the final protocol;
[0081] If not, judge whether there is an end request to forcibly end the running period of the timer. If there is, end the running period of the timer. If not, continue to run the running period of the timer.
[0082] Here, first of all, the system will judge whether the running period of the timer has ended. The running period of the timer is a preset time period used to determine whether a reply is needed. If the running period of the timer ends, the system will determine the current protocol as the final protocol. This means that after a period of waiting or processing, the system believes that the current protocol already meets the conditions for a reply. Once the final protocol is determined, the system will reply to the information of this protocol. This can be sending a confirmation signal, performing a specific action, or sending data, etc., depending on the requirements of the protocol.
[0083] Before the running period of the timer ends, the system will also check whether there is an end request to forcibly end the running period of the timer. This may be triggered by certain specific conditions or abnormal situations, and it is necessary to end the running period of the timer in advance. If there is a forced end request, the system will end the running period of the timer and take corresponding processing measures according to the situation, such as returning an error message, performing a specific operation, etc. If the running period of the timer has not ended and there is no forced end request, the system will continue to run the remaining time of the timer, waiting to meet other conditions or trigger other events.
[0084] By performing protocol arbitration based on a timer, the system can flexibly adjust the processing method according to the actual situation and external conditions. This can better adapt to the changing communication requirements and workloads, improving the adaptability and reliability of the system.
[0085] The above - mentioned manner is a key step in this solution. By judging the running state and triggering conditions of the timer, the system can select a suitable processing method according to the actual situation to ensure timely and accurate response to the requirements of external protocols.
[0086] Next, please refer to Figure 3 , Figure 3It is the schematic diagram of automatic CAN protocol recognition provided by the embodiments of this application. The following preparations are required before entering the process:
[0087] Store the CAN IDs of different protocols in the protocol array protoArray, and sort these protocols in high and low priority order.
[0088] The supported protocols are divided into two categories. One category is those that do not require a reply within the trigger cycle time. The other category is those that reply immediately after receiving the protocol.
[0089] Please refer to Figure 3 , the adaptive protocol has two life cycle processes, one is the protocol processing line process, and the other is the timer cycle line process. They are introduced separately below.
[0090] 1. Protocol processing line operation process:
[0091] Step 1. If external data is received, go to Step 2; otherwise, exit.
[0092] Step 2. Determine whether the CAN ID of the received protocol data exists in the array protoArray; if it exists, go to Step 3; otherwise, exit.
[0093] Step 3. If this protocol is the first protocol, go to Step 4; otherwise, go to Step 5.
[0094] Step 4. Set this protocol as the current protocol. And determine whether this protocol belongs to the protocol that needs to be replied immediately. If it belongs to the protocol that needs to be replied immediately, go to Step 6; otherwise, go to Step 7.
[0095] Step 5. Judge whether the priority of the received data protocol is higher than the current protocol priority. If it is higher than the current protocol priority, go to Step 8; otherwise, exit.
[0096] Step 6. Close the timer running cycle, directly reply the information, and exit.
[0097] Step 7. During the timer running cycle, no information will be replied to avoid misidentification by PCS / EMS, and exit.
[0098] Step 8. If the priority of the latest received protocol is higher than the current protocol, perform protocol transition. Set the received protocol as the current protocol, and set the priority as the priority of the received protocol, and go to Step 9.
[0099] Step 9. Determine whether the current protocol is an immediate reply protocol. If it is, go to Step 6; otherwise, exit. According to the timer cycle operation process, determine whether information needs to be replied. When the adaptive countdown is completed, information needs to be replied. Otherwise, no information needs to be replied.
[0100] In some embodiments, the method further includes:
[0101] Perform an external timeout fault determination on the current automatic CAN protocol recognition, and when the determination result is a fault, send the corresponding fault information.
[0102] The system will perform a timeout fault determination on the current automatic CAN protocol recognition. A timeout fault means that the system fails to complete the protocol recognition or processing within the specified time, which may be caused by communication delays, system busyness, or other reasons. When the determination result is a fault, it means that the system fails to complete the automatic CAN protocol recognition within the normal time. This may indicate communication problems, system errors, or other abnormal situations. In the case of a fault determination, the system will send the corresponding fault information. These messages may include the type of fault, the time of occurrence, and other relevant details for subsequent problem diagnosis and resolution.
[0103] Specifically, when the time for the current automatic CAN protocol recognition to complete is before the timeout of the external timeout fault determination, the method further includes:
[0104] If the current automatic CAN protocol recognition is successful, the external timeout fault determination does not report an error;
[0105] If the external timeout fault determination times out and the current automatic CAN protocol recognition is not successful, the external timeout fault determination reports an error and sends the corresponding fault information, where the time when the external timeout fault determination times out is the earliest closing time of the relay, and the closing of the relay indicates functional interaction with an external entity based on the established connection.
[0106] Please refer to Figure 4 , Figure 4 which is one of the schematic diagrams of the external timeout fault determination provided by the embodiments of the present application. As shown in Figure 4 , when the time for the automatic recognition to complete is before the first external communication timeout time, there will be two cases at this time. The first case is that the protocol is successfully recognized in the protocol adaptation stage, and then the error of 0x1000 will not occur; the second case is that the protocol is not recognized, and then the error of 0x1000 will be reported.
[0107] In Figure 4 , the 15s of protocol adaptation can be regarded as a complete life cycle of an external protocol. If, after the end of the life cycle of this external protocol (for example, the first external protocol, which can be the Solax protocol or the Pjn protocol, and its priority order is: IBC > Pylon > Solax > Pjn), a higher-level IBC protocol or Pylon protocol is introduced, protocol transition will still occur at this time.
[0108] When the time for the automatic recognition of the current CAN protocol is after the timeout for the external timeout fault determination, the method further includes:
[0109] If the external timeout fault determination times out and the automatic recognition of the current CAN protocol fails, an error is reported for the external timeout fault determination, corresponding fault information is sent, and the external timeout fault determination is performed again. If the next automatic recognition of the CAN protocol is successful during the re - execution of the external timeout fault determination, the corresponding fault information is cleared.
[0110] Please refer to Figure 5 , Figure 5 which is the second schematic diagram of the external timeout fault determination provided by the embodiments of the present application. As Figure 5 shown, when the time for the automatic recognition is after the first external communication timeout time, there will be five situations at this time.
[0111] The first situation: If it is not detected within 30 seconds, a 0×1000 fault will be reported;
[0112] The second situation: If the IBC protocol is not detected within 30 seconds, a 0×1000 fault will also be reported;
[0113] The third situation: If the IBC protocol is not detected within the first 30 seconds and the IBC protocol is not detected within these 15 seconds either, a 0×1000 fault will be reported during this stage;
[0114] The fourth situation: If the IBC protocol is detected within this event cycle, it is directly set as the IBC protocol;
[0115] The fifth situation: After the 15 - second protocol automatic recognition is completed, if the IBC protocol is not detected, a determination will be made. If something that can match is received, the protocol that can match is set, and if there is a 0×1000 fault, it is cleared.
[0116] Regarding the closing of the relay, it is divided into three types:
[0117] 1. Before the time point indicated by the dotted line, if the IBC protocol is received, it is under three - level control;
[0118] 2. Before the time point indicated by the dotted line, if the IBC protocol is not received but the Pylon protocol is received, the relay will close at the time point indicated by the dotted line;
[0119] 3. Before the time point indicated by the dotted line, if neither the IBC protocol nor the Pylon protocol is received, the relay will not close.
[0120] In the above - mentioned method, detailed fault determination is carried out during the entire automatic recognition and processing process. If a fault is detected, the system will take corresponding measures, such as resending information, recording error logs, or performing fault recovery, etc. This helps to ensure the stability and reliability of the system.
[0121] In summary, the embodiments of the present application have the following beneficial effects:
[0122] (1) Multi - protocol support and resource optimization: Through a single CAN port, this method can support and be compatible with multiple different CAN protocols. This means that under the same hardware resources, the functions of the system are greatly expanded without adding additional hardware or ports for each protocol. This method not only simplifies the system design but also saves CAN resources, thus improving the overall performance of the system.
[0123] (2) Automatic protocol recognition during runtime: During operation, this method can automatically recognize and distinguish different CAN protocols. This means that the system no longer requires manual intervention or preset conditions to recognize protocols, but can dynamically and intelligently recognize according to the actually received data. This automatic recognition function enhances the adaptability and flexibility of the system.
[0124] (3) Priority management to avoid interference: Under the same CAN sub - network, since various CAN protocols may co - exist, in order to avoid interference from low - priority protocols to high - priority protocols, this method only responds to high - priority CAN protocols. This ensures that high - priority data can be transmitted smoothly and without interference, improving the efficiency and reliability of communication.
[0125] In summary, the embodiments of the present application not only improve the resource utilization rate and performance of the system, but also enhance the intelligence and adaptability of the system. It brings a more efficient and reliable communication solution to the fields of automotive electronics and industrial automation.
[0126] Based on the same inventive concept, the embodiments of the present application also provide a CAN protocol automatic recognition device corresponding to the CAN protocol automatic recognition method in the first embodiment. Since the principle of solving problems by the device in the embodiments of the present application is similar to the above - mentioned CAN protocol automatic recognition method, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be elaborated.
[0127] As Figure 6 shown, Figure 6 is a schematic structural diagram of the CAN protocol automatic recognition device 600 provided by the embodiments of the present application. The CAN protocol automatic recognition device 600 includes:
[0128] The first judgment module 601 is configured to receive an external protocol, determine the priority of the external protocol and the current protocol based on preset priority information. If the priority of the external protocol is higher than that of the current protocol, protocol transition is performed; if the priority of the external protocol is not higher than that of the current protocol, protocol transition is not performed. Wherein, the protocol transition is used to update the current protocol to the external protocol.
[0129] The second judgment module 602 is configured to determine whether the current protocol is an immediate response protocol based on preset type information. If so, information is directly replied; if not, protocol arbitration is performed based on a timer. Wherein, performing protocol arbitration based on a timer includes replying information after the timer period is completed; otherwise, information is not replied.
[0130] Those skilled in the art should understand that Figure 6 The implementation functions of the various units in the shown CAN protocol automatic recognition device 600 can be understood with reference to the relevant descriptions of the foregoing CAN protocol automatic recognition method. Figure 6 The functions of the various units in the shown CAN protocol automatic recognition device 600 can be implemented by a program running on a processor or by specific logic circuits.
[0131] In a possible implementation manner, the first judgment module 601 presets the priority information in the following manner:
[0132] Preset a protocol array, where the protocol array is used to store protocol identifiers of multiple target protocols.
[0133] Perform a sorting process on the protocol identifiers of the multiple target protocols in the protocol array, where the protocol identifier that is more forward has a higher priority.
[0134] In a possible implementation manner, after the first judgment module 601 receives an external protocol, it further includes:
[0135] Judge whether the protocol identifier of the external protocol exists in the protocol array. If so, judge the priority of the external protocol and the current protocol based on the preset priority information; if not, no processing is performed.
[0136] In a possible implementation manner, after the first judgment module 601 receives an external protocol, it further includes:
[0137] If the current protocol does not exist, directly determine the external protocol as the current protocol.
[0138] In a possible implementation manner, the second judgment module 602 presets the type information in the following manner:
[0139] Classify the protocol identifiers of the multiple target protocols in the protocol array to obtain a first type of protocol identifier and a second type of protocol identifier, where the first type of protocol identifier indicates that the protocol requires an immediate response, and the second type of protocol identifier indicates that the protocol does not require a response during the protocol arbitration.
[0140] In a possible implementation, the second determination module 602 performs protocol arbitration based on a timer, including:
[0141] Determine whether the running period of the timer has ended. If so, determine the current protocol as the final protocol and reply to the information of the final protocol;
[0142] If not, determine whether there is an end request to forcibly end the running period of the timer. If there is, end the running period of the timer. If not, continue to run the running period of the timer.
[0143] In a possible implementation, the second determination module 602 further includes:
[0144] Perform an external timeout fault determination on the automatic identification of the current CAN protocol. When the determination result is a fault, send the corresponding fault information.
[0145] In a possible implementation, when the time when the automatic identification of the current CAN protocol is completed is before the timeout of the external timeout fault determination, the second determination module 602 further includes:
[0146] If the automatic identification of the current CAN protocol is successful, the external timeout fault determination does not report an error;
[0147] If the external timeout fault determination times out and the automatic identification of the current CAN protocol is not successful, the external timeout fault determination reports an error and sends the corresponding fault information, where the time when the external timeout fault determination times out is the earliest closing time of the relay, and the closing of the relay indicates functional interaction with an external entity based on an established connection.
[0148] In a possible implementation, when the time when the automatic identification of the current CAN protocol is completed is after the timeout of the external timeout fault determination, the second determination module 602 further includes:
[0149] If the external timeout fault determination times out and the automatic CAN protocol recognition fails this time, the external timeout fault determination reports an error, sends the corresponding fault information, and re-performs the external timeout fault determination. If the next automatic CAN protocol recognition is successful when re-performing the external timeout fault determination, the corresponding fault information is cleared. Among them, when the external timeout fault determination times out or when the automatic CAN protocol recognition ends this time is the earliest closing time of the relay. The closing of the relay indicates functional interaction with the external entity on the basis of establishing a connection.
[0150] The above CAN protocol automatic recognition device has the following beneficial effects:
[0151] (1) Multi-protocol support and resource optimization: Through a single CAN port, this method can support and be compatible with a variety of different CAN protocols. This means that under the same hardware resources, the functions of the system are greatly expanded without adding additional hardware or ports for each protocol. This method not only simplifies the system design but also saves CAN resources, thereby improving the overall performance of the system.
[0152] (2) Automatic protocol recognition during operation: During operation, this method can automatically recognize and distinguish different CAN protocols. This means that the system no longer requires manual intervention or preset conditions to recognize the protocol, but can dynamically and intelligently recognize it according to the actually received data. This automatic recognition function enhances the adaptability and flexibility of the system.
[0153] (3) Priority management to avoid interference: Under the same CAN sub-network, since various CAN protocols may exist simultaneously, to avoid interference from low-priority protocols to high-priority protocols, this method only responds to high-priority CAN protocols. This ensures that high-priority data can be transmitted smoothly and without interference, improving the efficiency and reliability of communication.
[0154] In summary, the embodiments of the present application not only improve the resource utilization rate and performance of the system, but also enhance the intelligence and adaptability of the system. It brings a more efficient and reliable communication solution to the fields of automotive electronics and industrial automation.
[0155] As Figure 7 shown, Figure 7 is a schematic structural diagram of an electronic device 700 provided by an embodiment of the present application. The electronic device 700 includes:
[0156] A processor 701, a storage medium 702, and a bus 703. The storage medium 702 stores machine-readable instructions executable by the processor 701. When the electronic device 700 runs, the processor 701 communicates with the storage medium 702 via the bus 703. The processor 701 executes the machine-readable instructions to perform the steps of the CAN protocol automatic recognition method described in the embodiments of the present application.
[0157] In practical applications, each component in the electronic device 700 is coupled together via the bus 703. It can be understood that the bus 703 is used to realize the connection and communication between these components. In addition to the data bus, the bus 703 also includes a power bus, a control bus, and a status signal bus. However, for the sake of clear illustration, in Figure 7 all kinds of buses are labeled as the bus 703.
[0158] The above-mentioned electronic device has the following beneficial effects:
[0159] (1) Multi-protocol support and resource optimization: Through a single CAN port, this method can support and be compatible with a variety of different CAN protocols. This means that under the same hardware resources, the functions of the system are greatly expanded without adding additional hardware or ports for each protocol. This method not only simplifies the system design but also saves CAN resources, thereby improving the overall performance of the system.
[0160] (2) Automatic protocol recognition during operation: During operation, this method can automatically recognize and distinguish different CAN protocols. This means that the system no longer requires manual intervention or preset conditions to recognize protocols, but can dynamically and intelligently recognize according to the actually received data. This automatic recognition function enhances the adaptability and flexibility of the system.
[0161] (3) Priority management to avoid interference: In the same CAN sub-network, since various CAN protocols may exist simultaneously, in order to avoid interference from low-priority protocols to high-priority protocols, this method only responds to high-priority CAN protocols. This ensures that high-priority data can be transmitted smoothly and without interference, improving the efficiency and reliability of communication.
[0162] In summary, the embodiments of the present application not only improve the resource utilization rate and performance of the system but also enhance the intelligence and adaptability of the system. It brings a more efficient and reliable communication solution to the fields of automotive electronics and industrial automation.
[0163] The embodiments of the present application also provide a computer-readable storage medium. The storage medium stores executable instructions. When the executable instructions are executed by at least one processor 701, the CAN protocol automatic recognition method described in the embodiments of the present application is implemented.
[0164] In some embodiments, the storage medium may be a ferromagnetic random access memory (FRAM), read only memory (ROM), programmable read only memory (PROM), erasable programmable read only memory (EPROM), electrically erasable programmable read only memory (EEPROM), flash memory, magnetic surface memory, optical disc, or compact disc read only memory (CD ROM), etc.; it may also be various devices including one or any combination of the above memories.
[0165] In some embodiments, the executable instructions may be in the form of a program, software, software module, script, or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including being deployed as an independent program or being deployed as a module, component, subroutine, or other unit suitable for use in a computing environment.
[0166] As an example, the executable instructions may or may not correspond to a file in the file system, may be stored as part of a file that holds other programs or data, for example, in one or more scripts in a hypertext markup language (HTML) document, stored in a single file dedicated to the program being discussed, or, stored in multiple cooperating files (e.g., files that store one or more modules, subroutines, or portions of code).
[0167] As an example, the executable instructions may be deployed to execute on one computing device, or on multiple computing devices located at one location, or, on multiple computing devices distributed at multiple locations and interconnected by a communication network.
[0168] The above computer-readable storage medium has the following beneficial effects:
[0169] (1) Multi - protocol support and resource optimization: Through a single CAN port, this method can support and be compatible with multiple different CAN protocols. This means that under the same hardware resources, the functions of the system are greatly expanded without adding additional hardware or ports for each protocol. This method not only simplifies the system design but also saves CAN resources, thus improving the overall performance of the system.
[0170] (2) Automatic protocol recognition during runtime: During operation, this method can automatically recognize and distinguish different CAN protocols. This means that the system no longer requires manual intervention or preset conditions to identify protocols, but can dynamically and intelligently identify them based on the actually received data. This automatic recognition function enhances the adaptability and flexibility of the system.
[0171] (3) Priority management to avoid interference: In the same CAN sub - network, since various CAN protocols may co - exist, to avoid interference from low - priority protocols to high - priority protocols, this method only responds to high - priority CAN protocols. This ensures that high - priority data can be transmitted smoothly and without interference, improving the efficiency and reliability of communication.
[0172] In summary, the embodiments of this application not only improve the resource utilization rate and performance of the system, but also enhance the intelligence and adaptability of the system. It brings a more efficient and reliable communication solution to the fields of automotive electronics and industrial automation.
[0173] In several embodiments provided by this application, it should be understood that the disclosed methods and electronic devices can be implemented in other ways. The device embodiments described above are only illustrative. For example, the division of the units is only a logical function division, and there may be other division methods in actual implementation. For example, multiple units or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the couplings, direct couplings, or communication connections between the various components shown or discussed can be through some interfaces, and the indirect couplings or communication connections of devices or units can be electrical, mechanical, or other forms.
[0174] The modules described as separate components may or may not be physically separated. The components shown as modules may or may not be physical units, that is, they can be located in one place or distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0175] In addition, the functional units in each embodiment of this application can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit.
[0176] When the above-mentioned function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a non-volatile computer-readable storage medium executable by a processor. Based on such an understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a platform server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present application. The foregoing storage medium includes: various media such as USB flash drives, mobile hard disks, ROM, RAM, magnetic disks, or optical discs that can store program codes.
[0177] The above is only the specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present application can easily think of changes or substitutions, which should all be covered by the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.
Claims
1. A method for automatically identifying CAN protocol, characterized in that, The method includes: Receiving an external protocol, judging the priority of the external protocol and the current protocol based on preset priority information. If the priority of the external protocol is higher than that of the current protocol, protocol transition is performed; if the priority of the external protocol is not higher than that of the current protocol, protocol transition is not performed; wherein, the protocol transition is used to update the current protocol to the external protocol. Judging whether the current protocol is an immediate reply protocol based on preset type information. If so, directly reply the information; if not, perform protocol arbitration based on a timer; wherein, performing protocol arbitration based on a timer includes replying the information after the timer period is completed; otherwise, do not reply the information.
2. The method according to claim 1, wherein The priority information is preset in the following way: Presetting a protocol array, wherein the protocol array is used to store protocol identifiers of multiple target protocols. Performing sorting processing on the protocol identifiers of the multiple target protocols in the protocol array, wherein the protocol identifier that is more forward has a higher priority.
3. The method according to claim 2, wherein After receiving the external protocol, the method further includes: Judging whether the protocol identifier of the external protocol exists in the protocol array. If so, judging the priority of the external protocol and the current protocol based on preset priority information; if not, no processing is performed.
4. The method according to claim 1, wherein After receiving the external protocol, the method further includes: If the current protocol does not exist, directly determine the external protocol as the current protocol.
5. The method according to claim 2, wherein The type information is preset in the following way: Performing classification processing on the protocol identifiers of the multiple target protocols in the protocol array to obtain protocol identifiers of a first type and protocol identifiers of a second type, wherein the protocol identifiers of the first type indicate that this protocol needs to be immediately replied, and the protocol identifiers of the second type indicate that this protocol does not need to be replied during the protocol arbitration.
6. The method according to claim 1, wherein Performing protocol arbitration based on a timer includes: Judging whether the running period of the timer ends. If so, determining the current protocol as the final protocol and replying the information for the final protocol. If not, judging whether there is an end request to forcibly end the running period of the timer. If there is, end the running period of the timer; if not, continue to run the running period of the timer.
7. The method according to any one of claims 1 to 6, characterized in that The method further includes: Performing an external timeout fault determination on the automatic recognition of the current CAN protocol, and sending corresponding fault information when the determination result is a fault.
8. The method according to claim 7, characterized in that, When the time for the automatic recognition of the current CAN protocol is before the timeout of the external timeout fault determination, the method further includes: If the automatic recognition of the current CAN protocol is successful, the external timeout fault determination does not report an error. If the external timeout fault determination times out and the automatic recognition of the current CAN protocol is not successful, the external timeout fault determination reports an error and sends corresponding fault information, wherein the time when the external timeout fault determination times out is the earliest closing time of the relay, and the closing of the relay means performing functional interaction with an external entity on the basis of establishing a connection.
9. The method according to claim 7, wherein When the time for the automatic recognition of the current CAN protocol is after the timeout of the external timeout fault determination, the method further includes: If the external timeout fault determination times out and the current CAN protocol automatic recognition fails, the external timeout fault determination reports an error, sends the corresponding fault information, and retries the external timeout fault determination. If the next CAN protocol automatic recognition is successful during the retry of the external timeout fault determination, the corresponding fault information is cleared. Among them, when the external timeout fault determination times out or when the current CAN protocol automatic recognition ends is the earliest closing time of the relay. The relay closing indicates functional interaction with the external entity based on the established connection.
10. An automatic CAN protocol recognition device, characterized in that, The device includes: A first judgment module, configured to receive an external protocol, judge the priority of the external protocol and the current protocol based on preset priority information. If the priority of the external protocol is higher than that of the current protocol, protocol transition is performed; if the priority of the external protocol is not higher than that of the current protocol, protocol transition is not performed. Among them, the protocol transition is used to update the current protocol to the external protocol. A second judgment module, configured to judge whether the current protocol is an immediate reply protocol based on preset type information. If so, directly reply the information; if not, perform protocol arbitration based on a timer. Among them, performing protocol arbitration based on a timer includes replying the information after the timer period is completed; otherwise, not replying the information.
11. An electronic device, characterized in that, It includes: A processor, a storage medium, and a bus. The storage medium stores machine-readable instructions executable by the processor. When the electronic device runs, the processor communicates with the storage medium through the bus. The processor executes the machine-readable instructions to execute the CAN protocol automatic recognition method according to any one of claims 1 to 9.
12. A computer-readable storage medium, characterized in that, A computer program is stored on the computer-readable storage medium. When the computer program is run by the processor, it executes the CAN protocol automatic recognition method according to any one of claims 1 to 9.