CAN terminal node address allocation method and device
By coordinating between master and terminal nodes in a CAN network and allocating logical addresses using random delay and CAN bus arbitration mechanisms, the problem of fast, reliable, and plug-and-play address allocation in high-density networks is solved, reducing conflict rates and deployment costs.
Patent Information
- Application Number
- CN202511749233.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-26
- Publication Date
- 2026-02-27
AI Technical Summary
Existing CAN node address allocation methods are cumbersome to configure and difficult to maintain in high-density networks. They cannot support plug-and-play nodes and dynamic networking, and have a high collision rate and severe network congestion, failing to meet the requirements for fast and reliable address allocation.
The master node periodically sends address allocation request messages, and the terminal node sends address request messages after a random delay. Logical addresses are allocated using the CAN bus arbitration mechanism and a preset strategy. The random delay time is calculated based on the number of conflict retries, and the address table is dynamically updated to avoid conflicts.
It enables fast and reliable address allocation in high-density CAN node networks, reduces the probability of message collisions, supports plug-and-play nodes, and reduces deployment and maintenance costs.
Smart Images

Figure CN121585642A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of communication technology, in particular to a CAN terminal node address allocation method and device. BACKGROUND
[0002] In the field of modern industrial automation, automotive electronics and other fieldbus applications, CAN (Controller Area Network) bus is widely used due to its high reliability. At present, the allocation methods of CAN node addresses mainly include the following: 1. Setting node address by physical dial code, which is high in cost, easy to make mistakes and does not support dynamic change. 2. Burning a unique address for each node during the production stage, which lacks flexibility and cannot adapt to on-site replacement and expansion. 3. Manually configuring slave node address by master node through special command, which is complex in operation and low in automation. 4. Static protocol based on physical location of nodes, which relies on the physical location of nodes on the bus. This method requires strict wiring and has poor scalability. These methods are not only complicated to configure and difficult to maintain, but also cannot support plug-and-play and dynamic networking of nodes, making it difficult to meet the needs of flexible expansion and automatic deployment of modern intelligent systems.
[0003] Especially in high-density node scenarios, the existing node address dynamic allocation method also has the following significant defects: after address conflict, the node often uses a simple retry mechanism, resulting in high conflict rate; when the bus load is high, the fixed retry delay further aggravates network congestion. These defects result in the existing node address dynamic allocation method being unable to meet the needs of fast and reliable address allocation in high-density CAN node networks. SUMMARY
[0004] The purpose of the present application is to overcome the defects in the prior art and provide a CAN terminal node address allocation method and device to achieve fast and reliable address allocation in high-density CAN node networks.
[0005] To achieve the above purpose, the first aspect of the present application provides a CAN terminal node address allocation method applied to a master node or a configuration node in a CAN network, comprising: periodically sending an address allocation request message to each unconfigured terminal node, so that the terminal node returns an address application message after a random time within a target range, the address allocation request message including an address range and a time window; receiving the address application message returned by the terminal node within the time window in the current period; allocating a logical address within the address range to the corresponding terminal node based on the address application message; sending an address allocation confirmation message containing the logical address to the corresponding terminal node, so that the corresponding terminal node stores and uses the logical address for communication.
[0006] Further, the target range is positively correlated with the number of conflict retries when the terminal node sends the address application message. The calculation formula of the random time in the target range is as follows: ) Wherein, RAND(a,b) represents a uniformly distributed random number generated in the interval [a,b], represents the initial delay base, the value range is 1ms to 100ms, C is the number of conflict retries when the terminal node sends the address application message, and the initial value is 0.
[0007] Further, the address application message returned by the terminal node in the current period is received in the time window, including: The address application message returned by the terminal node is received in the time window based on the arbitration mechanism of CAN bus; The arbitration mechanism of CAN bus is that when a plurality of terminal nodes return address application messages at the same time, the priority of the CAN identifier of each address application message is used to determine the priority of the transmitted message.
[0008] Further, a logical address in the address range is allocated to the corresponding terminal node based on the address application message, including: A logical address in the address range is allocated to the corresponding terminal node according to a preset strategy, and the address application message includes the hardware identifier of the corresponding terminal node; The preset strategy includes any one of the following: The logical addresses in the address range are allocated to the terminal nodes in turn according to the sorting of the hardware identifiers of the terminal nodes; The logical addresses in the address range are allocated to the terminal nodes in turn according to the order of the time of receiving the address application message; The logical addresses in the address range are randomly allocated to the terminal nodes.
[0009] Further, the method further includes: The hardware identifier of the terminal node is bound with the logical address allocated to it and recorded in the allocated address table; According to the allocated address table, the target terminal node whose allocated logical address is repeated is detected; sending an address conflict notification to the target terminal node to make the target terminal node release its stored logical address and recover to an unconfigured state.
[0010] The second aspect of the application provides a CAN terminal node address allocation method, which is applied to a terminal node in a CAN network and comprises the following steps: entering an unconfigured state after power-on start, receiving an address allocation request message sent by a master node, wherein the address allocation request message comprises an address range and a time window; generating a random time in a target range as a delay time and generating an address application message for applying for a logical address in the address range; sending the address application message to the master node after the delay time ends; receiving an address allocation confirmation message sent by the master node, wherein the address allocation confirmation message comprises an allocated logical address; storing the logical address and using the logical address for communication.
[0011] Further, the calculation formula of the random time in the target range is as follows: ) wherein, the random time in the target range, RAND(a, b) represents a uniformly distributed random number generated in the interval [a, b], the initial delay base, the value range is 1 ms to 100 ms, C is the conflict retry number of the terminal node when sending the address application message, and the initial value is 0.
[0012] Further, sending the address application message to the master node comprises the following steps: detecting the current transmission state of the CAN bus when sending the address application message; determining whether a conflict occurs when sending the address application message according to whether the transmission state of the CAN bus when sending the address application message is consistent with the current transmission state of the CAN bus; when it is determined that a conflict occurs when sending the address application message, increasing the conflict retry number by one, calculating the backoff time according to the current conflict retry number according to the calculation formula, and resending the address application message after delaying the backoff time.
[0013] The third aspect of the application provides a CAN terminal node address allocation device, which is applied to a master node or a configuration node in a CAN network and comprises the following steps: The first sending module is configured to periodically send an address allocation request message to each unconfigured terminal node, so that the terminal node returns an address application message after delaying a random time within a target range, and the address allocation request message comprises an address range and a time window; The first receiving module is configured to receive the address application message returned by the terminal node within the time window in the current period. The allocation module is configured to allocate a logical address within the address range to the corresponding terminal node based on the address application message. The first sending module is further configured to send an address allocation confirmation message comprising the logical address to the corresponding terminal node, so that the corresponding terminal node stores and uses the logical address for communication.
[0014] Further, the target range is positively correlated with the number of conflict retries when the terminal node sends the address application message. The calculation formula of the random time within the target range is as follows: ) wherein, rand(a,b) represents a uniformly distributed random number generated in the interval [a,b], represents an initial delay base, and the value range is 1ms to 100ms, C is the number of conflict retries when the terminal node sends the address application message, and the initial value is 0.
[0015] Further, when the first receiving module receives the address application message returned by the terminal node within the time window in the current period, it is specifically configured to receive the address application message returned by the terminal node within the time window based on the arbitration mechanism of the CAN bus; when a plurality of terminal nodes return the address application message at the same time, the arbitration mechanism of the CAN bus determines the priority transmission message according to the priority of the CAN identifier of each address application message.
[0016] Further, when the allocation module allocates a logical address within the address range to the corresponding terminal node based on the address application message, it is specifically configured to allocate a logical address within the address range to the terminal node corresponding to the address application message according to a preset strategy, and the address application message comprises a hardware identifier of the corresponding terminal node; the preset strategy comprises any one of the following: allocating the logical addresses within the address range to the terminal nodes in turn according to the ordering of the hardware identifiers of the terminal nodes; allocating the logical addresses within the address range to the terminal nodes in turn according to the order of the time of receiving the address application message; and randomly allocating the logical addresses within the address range to the terminal nodes.
[0017] Further, the device further comprises a dynamic updating module, configured to record the hardware identifier of the terminal node and the logical address allocated to the terminal node in an allocated address table; detect a target terminal node with a duplicated allocated logical address according to the allocated address table; and send an address conflict notification to the target terminal node to make the target terminal node release the stored logical address and recover to an unconfigured state.
[0018] The fourth aspect of the present application provides a CAN terminal node address allocation device, applied to a terminal node in a CAN network, comprising: A second receiving module, configured to enter an unconfigured state after power-on, and receive an address allocation request message sent by a master node, wherein the address allocation request message comprises an address range and a time window; A generating module, configured to generate a random time in a target range as a delay time, and generate an address application message for applying for a logical address in the address range; A second sending module, configured to send the address application message to the master node after the delay time ends; The second receiving module is further configured to receive an address allocation confirmation message sent by the master node, wherein the address allocation confirmation message comprises an allocated logical address; A processing module, configured to store the logical address, and use the logical address for communication.
[0019] Further, the random time in the target range is calculated according to the following formula: ) wherein, RAND(a,b) represents a uniformly distributed random number generated in the interval [a,b], represents an initial delay base, and the value range is 1ms to 100ms, C is the conflict retry number when the terminal node sends the address application message, and the initial value is 0.
[0020] Further, when the second sending module sends the address application message to the master node, it is specifically configured to detect the current transmission state of the CAN bus when sending the address application message; determine whether the sending of the address application message has a conflict according to whether the transmission state of the CAN bus when the CAN bus transmits the address application message is consistent with the current transmission state of the CAN bus; when it is determined that the sending of the address application message has a conflict, increase the conflict retry number by one, and calculate the backoff time according to the current conflict retry number according to the calculation formula, and resend the address application message after delaying the backoff time.
[0021] The fifth aspect of the present invention provides a computer-readable storage medium having program instructions stored thereon, which, when executed, implement the method described in either the first or second aspect.
[0022] The advantages and beneficial effects of this invention are as follows: By delaying the address allocation request message sent by each terminal node within a random time range within a target range after receiving the request, the response time of multiple terminal nodes is distributed, avoiding the situation where multiple terminal nodes contend for the bus at the same time, and significantly reducing the probability of message collisions. Furthermore, due to the reduced collision rate, terminal nodes do not need to frequently retry address requests, reducing the additional time overhead caused by collisions and shortening the time required for terminal nodes to complete address allocation, thereby achieving fast and reliable address allocation in high-density CAN node networks. In addition, this method fully utilizes the characteristics of the CAN bus, without increasing hardware costs, enabling plug-and-play nodes without manual intervention or hardware configuration, significantly reducing deployment and maintenance costs. Attached Figure Description
[0023] Figure 1 This is a flowchart of the CAN terminal node address allocation method of the present invention applied to the master node or configuration node; Figure 2 This is a flowchart of the CAN terminal node address allocation method of the present invention applied to terminal nodes; Figure 3 This is a schematic diagram of the structure of the CAN terminal node address allocation device of the present invention applied to the master node or configuration node; Figure 4 This is a schematic diagram of the CAN terminal node address allocation device of the present invention applied to terminal nodes. Detailed Implementation
[0024] The specific embodiments of the present invention will be further described below with reference to the accompanying drawings and examples. The following examples are only used to more clearly illustrate the technical solutions of the present invention and should not be construed as limiting the scope of protection of the present invention.
[0025] like Figure 1 The CAN terminal node address allocation method shown is applied to the master node or configuration node in a CAN network. For example... Figure 2 The CAN terminal node address allocation method shown is applied to terminal nodes in a CAN network. For example, the master node or configuration node can be the central control unit of the vehicle system, and the terminal nodes can be the various sensor modules of the vehicle system. Each sensor module is connected to the central control unit via the CAN bus, and the central control unit executes this CAN terminal node address allocation method.
[0026] The method for assigning CAN terminal node addresses to master nodes or configuration nodes includes the following steps: S110. Periodically send address allocation request messages to each unconfigured terminal node, so that the terminal node returns an address request message after a random time within a target range. The address allocation request message includes an address range and a time window.
[0027] S120. Receive the address request message returned by the terminal node within the current period during the time window.
[0028] S130. Based on the address request message, allocate a logical address within the address range to the corresponding terminal node.
[0029] S140. Send an address allocation confirmation message containing the logical address to the corresponding terminal node, so that the corresponding terminal node stores and uses the logical address for communication.
[0030] The CAN terminal node address allocation method applied to terminal nodes includes the following steps: S210. After power-on startup, the system enters an unconfigured state and receives an address allocation request message sent by the master node. The address allocation request message includes an address range and a time window.
[0031] S220. Generate a random time within the target range as a delay time, and generate an address request message requesting a logical address within the address range.
[0032] S230. After the delay time ends, send the address request message to the master node.
[0033] S240. Receive the address allocation confirmation message sent by the master node, the address allocation confirmation message including the allocated logical address.
[0034] S250. Store the logical address and use the logical address for communication.
[0035] The following combination Figure 1 , Figure 2 The CAN terminal node address allocation method shown in this embodiment of the invention introduces the interaction process between the master node and the terminal node when performing address allocation.
[0036] 1. During the initialization phase, the CAN terminal node executes S210. All CAN terminal nodes without assigned addresses enter the "unconfigured" state after power-on and listen for specific address allocation request messages on the bus. The master node (or configuration node) in the CAN network executes S110. The master node periodically sends address allocation request messages, which contain the allocatable address range and time window. For example, the address allocation request message (CAN ID: 0x700) contains the address range 0x01~0x0A.
[0037] 2、Response and competition phase, the terminal node executes S220 and S230, the terminal node in the “unconfigured” state receives the address allocation request message, generates a random delay time (Tdelay) in the target range (such as 10~100ms) respectively, and sends an address application message (such as CAN ID:0x701) to the master node through the bus after the delay time ends. The address application message contains the unique hardware identifier of the terminal node (i.e. terminal node ID, such as MCU serial number, MAC address segment, etc.). In addition, the address application message can also include the logical address applied by the terminal node and the timestamp of the message. The logical address applied by the terminal node can be consistent with the logical address in the factory configuration.
[0038] 3、Conflict detection and arbitration phase, if multiple terminal nodes send “address application” at the same time, the inherent arbitration mechanism (based on ID priority) of the CAN bus will determine which message is transmitted first. The terminal node that fails to send (detects that the CAN bus data does not match its sent content) determines that a conflict has occurred, records the number of conflicts, and increases the random delay according to the backoff algorithm (binary exponential backoff) to re-enter the competition phase.
[0039] 4、Address allocation and confirmation phase, the master node (or configuration node) executes S120 and S130, the master node receives all address application messages returned within the time window, and allocates a unique logical address within the above address range to each successfully applied terminal node according to a preset strategy. For example, the addresses 0x01~0x0A are allocated in the order of the MCU serial number of the terminal node. Then the master node executes S140, sends an address allocation confirmation message (CAN ID:0x702+terminal node ID) to the application node, which contains the allocated logical address and verification information.
[0040] Correspondingly, the terminal node executes S240 and S250, after receiving the address allocation confirmation message, the terminal node writes the allocated address into the non-volatile memory (such as EEPROM), and switches to the “configured” state, and starts to use the allocated new address to participate in normal communication. For example, the allocated address is used to send temperature data.
[0041] The embodiment of the application can effectively complete the address allocation of all nodes within a few seconds, and supports the automatic access of newly added terminal nodes.
[0042] The embodiment of the present application disperses the response time of multiple terminal nodes by delaying a random time in a target range after receiving the address allocation request, thereby avoiding the case that multiple terminal nodes contend for the bus at the same time, significantly reducing the probability of message collision. Moreover, due to the reduction of the collision rate, the terminal node does not need to frequently retry the address application, reducing the additional time cost caused by the collision, shortening the time required for the terminal node to complete the address allocation, thereby realizing fast and reliable address allocation in a high-density CAN node network. In addition, the method fully utilizes the characteristics of the CAN bus, without increasing the hardware cost, and can realize plug-and-play of the node without manual intervention or hardware setting, significantly reducing the deployment and maintenance cost.
[0043] To reduce the collision rate of the terminal node sending the address application message, the preferred embodiment of the present application is that the target range is positively correlated with the number of collision retries when the terminal node sends the address application message. The calculation formula of the random time in the target range is as follows: ) Wherein, Tdelay represents the random time in the target range, RAND(a, b) represents a uniformly distributed random number generated in the interval [a, b], Cinit represents the initial delay base, the value range is 1ms to 100ms, and the preferred value is 5ms, and C is the number of collision retries when the terminal node sends the address application message, and the initial value is 0.
[0044] The concept of the formula is a basic random delay + collision number weighting. In an embodiment of the present application, the calculation of the random delay time Tdelay can also be realized by the following way: the terminal node first obtains its unique hardware identifier HWID (i.e. terminal node ID) and the current number of collision retries C. Then, the HWID and C are XORed to generate a random seed S. The seed is used to initialize the pseudo-random number generator to generate a random number R in the range of 0~65535. Finally, the delay time is calculated as Tdelay = (R mod 50ms) × 2^C, (R mod 50ms) represents that a large random number range 0~65535 is mapped to a specified time range to take the random number R corresponding time by using the modulo operation, and mod is the modulo operation. For example, when C=0, the delay range is 0~50ms; when C=1, the delay range expands to 0~100ms, and so on. This method makes the target range of the random time exponentially grow with the number of collisions, ensuring that different terminal nodes can effectively stagger the sending time of the address application message in multiple address application retries, significantly reducing the message collision rate in the address allocation process.
[0045] In order to reduce the cost of message collision arbitration, the preferred embodiment of the present application is that the address application message returned by the terminal node in the current period is received in the time window, comprising: receiving the address application message returned by the terminal node in the time window based on the arbitration mechanism of CAN bus; the arbitration mechanism of CAN bus determines the message with priority transmission when multiple terminal nodes return address application messages at the same time according to the priority of the CAN identifier of each address application message.
[0046] The CAN identifier refers to the CAN message ID, which is part of the CAN frame header, and is a 11-bit or 29-bit field specially used for bus arbitration and message filtering. It determines the priority of the message, and the smaller the value, the higher the priority, which is the inherent arbitration mechanism of CAN bus. The priority of the address application message sent at the same time is determined by the priority of the CAN identifier, the message with high priority is continuously sent, the message with low priority is exited and stopped, and is sent again after a delay of the backoff time. This collision arbitration mechanism is completely based on the physical layer characteristics of CAN bus, and does not require additional hardware, which can reduce the cost.
[0047] In addition, the CAN identifier in the address application message adopts a predefined high priority ID, which can ensure that the transmission priority of the address application message is higher than that of other types of messages, thereby ensuring the real-time performance of the address allocation process.
[0048] In order to improve the flexibility of the address allocation strategy and extend the scenarios that the scheme can adapt to, the preferred embodiment of the present application is that a logical address within the address range is allocated to the corresponding terminal node based on the address application message, comprising: allocating a logical address within the address range to the terminal node corresponding to the address application message according to a preset strategy, the address application message including the hardware identifier of the corresponding terminal node; the preset strategy includes any one of the following: allocating logical addresses within the address range to terminal nodes in turn according to the order of the hardware identifiers of the terminal nodes; allocating logical addresses within the address range to terminal nodes in turn according to the order of the time of receiving the address application message; randomly allocating logical addresses within the address range to terminal nodes.
[0049] In order to solve the conflict problem of the address allocated to the terminal node and realize dynamic update after address conflict, the preferred embodiment of the present application is that the method further comprises: recording the hardware identifier of the terminal node and the logical address allocated to it in the allocated address table; detecting the target terminal node with repeated allocated logical address according to the allocated address table; sending an address conflict notification to the target terminal node to make the target terminal node release its stored logical address and recover to the unconfigured state.
[0050] In order to avoid address conflict, the master node maintains an allocated address table when allocating addresses, and binds the hardware identifier of the terminal node with the logical address allocated to the terminal node in the allocated address table. If the terminal node finds that the allocated address conflicts with other terminal nodes (by listening to the bus or being informed by the master node), the terminal node initiates a new address application after releasing the address and re-entering the "unconfigured" state.
[0051] In order to avoid address conflict, the master node maintains an allocated address table when allocating addresses, and binds the hardware identifier of the terminal node with the logical address allocated to the terminal node in the allocated address table. If the terminal node finds that the allocated address conflicts with other terminal nodes (by listening to the bus or being informed by the master node), the terminal node initiates a new address application after releasing the address and re-entering the "unconfigured" state.
[0052] The conflict detection mechanism of the embodiment of the application is completely based on the physical layer characteristics of the CAN bus, and does not require additional hardware, but only uses the bit arbitration function of a standard CAN controller (such as the CAN peripheral of STM32) to achieve the conflict detection. The conflict detection is achieved at the hardware level by detecting the CAN_SR_TERR bit of the CAN controller register, without the need for additional software polling. In the specific implementation, the terminal node judges the sending state by CAN_GetStatus(CAN1)&CAN_SR_TXOK after sending a message, and determines that a conflict occurs if TXOK=0, records the conflict count C, and starts the backoff algorithm to calculate the backoff time.
[0053] The level detection principle of the CAN bus is that the CAN bus adopts differential signal transmission, the explicit level (logic 0) is defined as the voltage difference between CAN_H and CAN_L > 2V (for example, CAN_H = 3.3V and CAN_L = 0V), and the implicit level (logic 1) is defined as the voltage difference < 0.5V (for example, CAN_H = 2.5V and CAN_L = 2.5V). When a node transmits a bit, the bus level is monitored in real time through the receiving end (RX) of the CAN transceiver, and the level of the node itself is output through the transmitting end (TX). The conflict triggering condition of the CAN bus is that when the bit level transmitted by the terminal node is inconsistent with the actual bus level, it is determined that a conflict occurs. Specifically, when the terminal node transmits an implicit bit (1) but the bus is in an explicit state (0), it indicates that other nodes are transmitting an explicit bit (conflict).
[0054] For example, when node A transmits an explicit level (logic 0), the CAN bus is pulled into an explicit level (logic 0). At this time, node B wants to transmit an implicit level (logic 1), but it monitors through RX that the CAN bus is in an explicit level (logic 1), which is inconsistent with the implicit level (logic 1) to be transmitted by its own TX, so node B immediately determines that the transmission of the message by itself occurs a conflict (i.e., arbitration failure), and stops transmitting. The arbitration function of the CAN bus is that all nodes simultaneously transmit the binary bits of the message ID transmitted by themselves bit by bit, and when all transmit an implicit level (logic 1), continue transmitting. However, as long as any node transmits an explicit level (logic 0), the CAN bus is pulled into an explicit level (logic 0). Other nodes transmitting an implicit level (logic 1) determine that a conflict occurs and that their arbitration fails, and immediately exit the competition and stop transmitting.
[0055] Therefore, when transmitting the address application message, the terminal node detects the current transmission state of the CAN bus, determines whether the transmission state of the address application message transmitted by the terminal node through the CAN bus is an explicit level or an implicit level, determines whether it is consistent with the current transmission state (explicit level) of the CAN bus, determines whether a conflict occurs when the terminal node transmits the address application message, increases the conflict retry count by one when it is determined that a conflict occurs when transmitting the address application message, refreshes the conflict count C and starts the backoff algorithm to calculate the backoff time, and resets the transmission state and starts the timer to wait for the delay of the backoff time to end and then retries.
[0056] Figure 3 The CAN terminal node address allocation device shown can perform the processing flow provided by the CAN terminal node address allocation method applied to the master node or the configuration node, and the device can be configured in the master node or the configuration node. The device comprises: The first sending module 310 is configured to periodically send an address allocation request message to each unconfigured terminal node, so that the terminal node returns an address application message after delaying a random time in a target range, and the address allocation request message comprises an address range and a time window; The first receiving module 320 is configured to receive the address application message returned by the terminal node in the current period within the time window. The allocation module 330 is configured to allocate a logical address in the address range to the corresponding terminal node based on the address application message. The first sending module 310 is further configured to send an address allocation confirmation message comprising the logical address to the corresponding terminal node, so that the corresponding terminal node stores and uses the logical address for communication.
[0057] In an embodiment, the target range is positively correlated with the number of conflict retries when the terminal node sends the address application message. The calculation formula of the random time in the target range is as follows: ) Wherein, RAND(a,b) represents a uniformly distributed random number generated in the interval [a,b], represents an initial delay base, and the value range is 1ms to 100ms, C is the number of conflict retries when the terminal node sends the address application message, and the initial value is 0.
[0058] In an embodiment, when the first receiving module 320 receives the address application message returned by the terminal node in the current period within the time window, it is specifically configured to receive the address application message returned by the terminal node within the time window based on the arbitration mechanism of the CAN bus; when a plurality of terminal nodes return the address application message at the same time, the arbitration mechanism of the CAN bus determines the message to be transmitted preferentially according to the priority of the CAN identifier of each address application message.
[0059] In an embodiment, when the allocation module 330 allocates a logical address in the address range to the corresponding terminal node based on the address application message, it is specifically configured to allocate a logical address in the address range to the terminal node corresponding to the address application message according to a preset strategy, and the address application message comprises a hardware identifier of the corresponding terminal node; the preset strategy comprises any one of the following: allocating the logical addresses in the address range to the terminal nodes in turn according to the ordering of the hardware identifiers of the terminal nodes; allocating the logical addresses in the address range to the terminal nodes in turn according to the order of the time of receiving the address application message; and randomly allocating the logical addresses in the address range to the terminal nodes.
[0060] In an embodiment, the device further comprises a dynamic updating module 340 for recording the binding of the hardware identifier of a terminal node and the logical address assigned thereto in an assigned address table; detecting a target terminal node whose assigned logical address is duplicated according to the assigned address table; and sending an address conflict notification to the target terminal node to make the target terminal node release its stored logical address and recover to an unconfigured state.
[0061] Figure 4 The illustrated CAN terminal node address allocation device can perform the processing flow provided by the CAN terminal node address allocation method applied to the terminal node, and the device can be configured in a terminal node in a CAN network. The device comprises: a second receiving module 410 for entering an unconfigured state after power-on, receiving an address allocation request message sent by a master node, the address allocation request message comprising an address range and a time window; a generating module 420 for generating a random time within a target range as a delay time, and generating an address application message for applying for a logical address within the address range; a second sending module 430 for sending the address application message to the master node after the delay time ends; the second receiving module 410 is further configured to receive an address allocation confirmation message sent by the master node, the address allocation confirmation message comprising an assigned logical address; a processing module 440 for storing the logical address and using the logical address for communication.
[0062] In an embodiment, the calculation formula of the random time within the target range is as follows: ) wherein, RAND(a,b) represents a uniformly distributed random number generated within the interval [a,b], represents an initial delay base, the value range is 1ms to 100ms, C is the conflict retry number of the terminal node when sending the address application message, and the initial value is 0.
[0063] In an implementation, the second sending module 430 is configured to detect the current transmission state of the CAN bus when sending the address application message to the master node, and determine whether the terminal node sends the address application message in conflict according to whether the transmission state when the terminal node returns the address application message through the CAN bus is consistent with the current transmission state of the CAN bus, increase the conflict retry number by one when determining that the address application message is sent in conflict, and calculate the backoff time according to the current conflict retry number according to the calculation formula, and resend the address application message after delaying the backoff time.
[0064] The application further provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the CAN terminal node address allocation method in the above embodiments. The storage medium can be a non-volatile / non-temporary computer readable storage medium.
[0065] The application further provides a CAN terminal node address allocation system for implementing the method embodiments, which comprises a master node configured with the CAN terminal node address allocation device as shown in Figure 3 a slave node configured with the CAN terminal node address allocation device as shown in Figure 4 a CAN bus connecting all the nodes and transmitting address allocation related messages.
[0066] It should be noted that, in this document, relational terms such as "first" and "second", and the like, are used solely to distinguish one entity or action from another entity or action, without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises", "comprising", or any other variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but can include other elements not expressly listed or inherent to such process, method, article, or apparatus. An element proceeded by "comprises... a" does not, without more constraints, exclude the existence of additional identical elements in the process, method, article, or apparatus that comprises the element.
[0067] The above description is only the preferred embodiments of the application, and it should be pointed out that, for those skilled in the art, without departing from the technical principles of the application, a number of improvements and refinements can be made, and these improvements and refinements should also be considered as the protection scope of the application.
Claims
1. A CAN terminal node address allocation method, applied to a master node or configuration node in a CAN network, characterized in that, include: The address allocation request message is periodically sent to each unconfigured terminal node so that the terminal node returns an address request message after a random time within a target range. The address allocation request message includes an address range and a time window. Within the time window, receive the address request messages returned by the terminal node in the current period; Based on the address request message, allocate a logical address within the address range to the corresponding terminal node; Send an address allocation confirmation message containing the logical address to the corresponding terminal node, so that the corresponding terminal node stores and uses the logical address for communication.
2. The CAN terminal node address allocation method according to claim 1, characterized in that, The target range is positively correlated with the number of conflict retries when the terminal node sends an address request message; The formula for calculating the random time within the target range is as follows: ) in, Let RAND(a,b) represent the random time within the target range, and let RAND(a,b) represent uniformly distributed random numbers generated within the interval [a,b]. This represents the initial delay base, ranging from 1ms to 100ms. C is the number of conflict retries when the terminal node sends an address request message, with an initial value of 0.
3. The CAN terminal node address allocation method according to claim 1, characterized in that, Within the time window, receive address request messages returned by the terminal node during the current period, including: Within the time window, the address request message returned by the terminal node is received through an arbitration mechanism based on the CAN bus. The arbitration mechanism of the CAN bus is that when multiple terminal nodes return address request messages at the same time, the message to be transmitted first is determined according to the priority of the CAN identifier of each address request message.
4. The CAN terminal node address allocation method according to claim 1, characterized in that, Based on the address request message, allocate a logical address within the address range to the corresponding terminal node, including: According to a preset strategy, a logical address within the address range is allocated to the terminal node corresponding to the address request message, and the address request message includes the hardware identifier of the corresponding terminal node. The preset strategy includes any one of the following: Logical addresses within the address range are assigned to the terminal nodes in the order of their hardware identifiers. Logical addresses within the address range are allocated to the terminal nodes in the order in which the address request messages are received. A logical address within the specified address range is randomly assigned to the terminal node.
5. The CAN terminal node address allocation method according to claim 4, characterized in that, The method further includes: The hardware identifier of the terminal node is bound to its assigned logical address and recorded in the allocated address table; The system detects target terminal nodes where the allocated logical addresses are duplicated based on the allocated address table. Send an address conflict notification to the target terminal node so that the target terminal node releases its stored logical address and returns to an unconfigured state.
6. A CAN terminal node address allocation method, applied to terminal nodes in a CAN network, characterized in that, include: After power-on startup, it enters an unconfigured state and receives address allocation request messages sent by the master node. The address allocation request message includes an address range and a time window. A random time within the target range is generated as a delay time, and an address request message is generated to request a logical address within the stated address range; After the delay time has elapsed, the address request message is sent to the master node. Receive an address allocation confirmation message sent by the master node, the address allocation confirmation message including the allocated logical address; Store the logical address and use the logical address for communication.
7. The CAN terminal node address allocation method according to claim 6, characterized in that, The formula for calculating the random time within the target range is as follows: ) in, Let RAND(a,b) represent the random time within the target range, and let RAND(a,b) represent uniformly distributed random numbers generated within the interval [a,b]. This represents the initial delay base, ranging from 1ms to 100ms. C is the number of conflict retries when the terminal node sends an address request message, with an initial value of 0.
8. The CAN terminal node address allocation method according to claim 7, characterized in that, Sending the address request message to the master node includes: Detect the current transmission status of the CAN bus when sending the address request message; Based on whether the transmission status of the address request message during CAN bus transmission is consistent with the current transmission status of the CAN bus, it is determined whether a conflict occurs when sending the address request message. When a conflict is determined to occur when sending the address request message, the number of conflict retry attempts is increased by one, and the backoff time is calculated according to the calculation formula based on the current number of conflict retry attempts. After delaying the backoff time, the address request message is resent.
9. A CAN terminal node address allocation device, applied to a master node or configuration node in a CAN network, characterized in that, include: The first sending module is used to periodically send address allocation request messages to each unconfigured terminal node, so that the terminal node returns an address request message after a random time within a target range. The address allocation request message includes an address range and a time window. The first receiving module receives the address request messages returned by the terminal node within the current period within the time window; The allocation module is used to allocate a logical address within the address range to the corresponding terminal node based on the address request message; The first sending module is further configured to send an address allocation confirmation message containing the logical address to the corresponding terminal node, so that the corresponding terminal node stores and uses the logical address for communication.
10. A CAN terminal node address allocation device, applied to terminal nodes in a CAN network, characterized in that, include: The second receiving module is used to enter an unconfigured state after power-on startup and receive address allocation request messages sent by the master node. The address allocation request message includes an address range and a time window. The generation module is used to generate a random time within the target range as a delay time, and to generate an address request message for requesting a logical address within the address range; The second sending module is used to send the address request message to the master node after the delay time has ended; The second receiving module is also used to receive the address allocation confirmation message sent by the master node, wherein the address allocation confirmation message includes the allocated logical address; A processing module is used to store the logical address and use the logical address for communication.