Distributed dynamic address allocation and recovery method for CAN bus nodes
By employing a distributed dynamic address allocation and reclamation method, and utilizing the CAN bus node's listening, rule-based selection, and cross-layer collaborative arbitration mechanism, the static address management problem of CAN bus nodes is solved, enabling nodes to negotiate autonomously and automatically reclaim addresses, thereby improving the system's dynamic scalability and deployment flexibility.
Patent Information
- Application Number
- CN202511444341.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-10
- Publication Date
- 2025-12-05
AI Technical Summary
In existing technologies, the address management method of CAN bus nodes cannot achieve dynamic self-organization, resulting in static binding of network identities, which cannot support the dynamic joining or leaving of nodes. Furthermore, the open-loop address resource management limits the scalability and deployment flexibility of the system.
A distributed dynamic address allocation and reclamation method is adopted. By performing listening, rule-based selection and cross-layer collaborative arbitration mechanisms on newly powered node devices, combined with the non-destructive bit arbitration mechanism of the CAN bus protocol, the node can autonomously negotiate a unique and valid network identity and automatically release address resources after the node goes offline.
It achieves deterministic address allocation for nodes the moment they connect to the bus, avoiding address conflicts and resource waste, and constructs a closed-loop node address lifecycle management method, supporting dynamic expansion and flexible deployment of the system.
Smart Images

Figure CN121078024A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application relates to a distributed dynamic address allocation and recycling method of a CAN bus node and belongs to the technical field of controller area network communication. BACKGROUND
[0002] At present, a controller area network bus is widely applied in a distributed industrial control system due to high reliability and communication certainty, and in particular, in a modular application scene in which a plurality of battery management systems are cooperatively managed by an energy storage converter, has become a common communication mode; along with development of the system in a direction of larger scale, higher flexibility and lower whole life cycle maintenance cost, an inherent limitation begins to restrict deployment flexibility and maintenance efficiency of the system, and the limitation is mainly reflected in a network identity (CANID) management mode of a node; in an application in which a system scale is fixed and a topology is constant, a traditional method of pre-burning a fixed address for each node in a production stage or manually configuring by a technician with the aid of a code switch and an upper computer software tool in a deployment site can meet basic communication requirements; however, when the system requires dynamic expansion, online hot plug of a fault node and rapid on-site replacement capacity, the address management mode depending on static preset or manual intervention cannot adapt to new application requirements.
[0003] The traditional methods are all based on a common premise that a network topology remains static or is controllable in a running period, and the premise is fundamentally inconsistent with dynamic self-organizing characteristics required by a modern distributed system, and simply improving convenience of a manual configuration tool or formulating a more strict operation process cannot solve the problem, and in actual application, the problem mainly manifests as follows: 1. lacking of an internal conflict avoidance and arbitration mechanism, when a plurality of nodes are concurrently accessed or configured, address conflicts are easily generated, and network communication is abnormal; 2. a network identity of a node is statically bound to a physical entity, and dynamic joining or exiting of the node in a running period is not supported, and any topology change needs to shut down the system or perform complicated manual intervention; 3. management of address resources is open-loop, and an address of a node that is offline or removed cannot be automatically identified and recycled by the system, and long-term running will lead to reduction of available address resources, and limits scalability of the system.
[0004] In order to overcome the disadvantages of the static configuration, the industry has explored the scheme of dynamic address management, but the control logic often has fundamental defects, for example, the authorized publication number CN104994181B of Chinese invention patent discloses a kind of method for displaying dynamic MAC address table in distributed OLT system, which uses a kind of centralization request response mechanism, and all dynamic addresses are acquired by initiating query task by main control board, and each line card is passively executed and reported result, this architecture realizes the dynamic display of address, but it is contrary to the distributed, centerless peer-to-peer communication concept pursued by CAN bus, it does not solve the core problem of multiple peer nodes being powered on at the same time (i.e. concurrent conflict) without central coordinator, but introduces the risk of main control board single point failure and additional communication overhead, which cannot meet the self-organizing network demand of plug and play in high reliability industrial scene.Therefore, how to provide a kind of distributed node address management method independent of central control and free from manual configuration, so that any node in the network can quickly obtain a unique valid network identity in the moment of accessing bus through a deterministic autonomous negotiation mechanism, and can automatically release the address resources occupied by the node after offline, to adapt to the real needs of dynamic system and flexible deployment, become the technical problem to be solved by the present application. SUMMARY
[0005] The present application provides a kind of distributed dynamic address allocation and recovery method of CAN bus node, its main purpose is to solve the problem that node address cannot be automatically distributed and recycled without conflict in prior art due to dependence on static preset or manual configuration.
[0006] To achieve the above purpose, the present application provides a kind of distributed dynamic address allocation and recovery method of CAN bus node, the method is executed in a CAN bus network including monitoring end and at least one node device, including the following computer-implemented steps: Step a, when the newly powered-on node device accesses CAN bus network, execute premise construction and constraint step, the newly powered-on node device executes listening operation in first competition window, the length of competition window is set to be greater than the period of periodic heartbeat message broadcasted by all online node devices in network, to obtain the CANID set occupied by current bus; Step b, execute regularized selection step, newly powered-on node device sets its own to-be-allocated CANID as the first unoccupied ID value in address pool defined by preset start address and end address according to occupied CANID set, according to preset increasing rule; Step c, performing a cross-layer coordination step, in the presence of concurrent collision condition that at least two node devices select the same CAN ID to be assigned according to the regularized selection step, both node devices send a claim message containing the same ID through their CAN controllers, and cooperatively perform the non-destructive bit arbitration physical mechanism inherent to the CAN bus protocol, which determines that one of the claim messages is completely transmitted, and the application layer of the node device that fails the arbitration receives the arbitration failure event reported by the CAN controller, and returns to perform the regularized selection step according to the event until the node device becomes the only winner in the bit arbitration mechanism and completes the address assignment.
[0007] Preferably, in the premise construction and constraint step, the length of the contention window is set to be greater than or equal to the least common multiple of the minimum periodicity of the periodic heartbeat messages broadcast by all online node devices in the network, to ensure that a newly powered-on node device can at least completely listen to the round heartbeat messages of all online node devices before it makes the first regularized selection.
[0008] Preferably, in the regularized selection step, the preset increment rule is that the newly powered-on node device sets its initial CAN ID to be assigned as the starting address of the address pool, and if it listens to that ID being occupied or experiences arbitration failure in the cross-layer coordination step, it performs an increment operation on its current CAN ID to be assigned, and takes the newly generated ID value as its own CAN ID to be assigned, and repeatedly performs the operation until the address assignment is completed.
[0009] Preferably, after the newly powered-on node device completes the address assignment, it further includes a stable state maintenance step: the node device continuously broadcasts a periodic heartbeat message containing its own assigned CAN ID to the CAN bus network at a fixed transmission period.
[0010] Preferably, the method further includes a dynamic address recovery step performed by a monitoring end, which continuously listens to the periodic heartbeat messages of all assigned CAN IDs in the network, and maintains an independent timeout timer for each assigned CAN ID.
[0011] Preferably, in the dynamic address recovery step, the monitoring end determines the timeout state according to the following rules: if it does not receive a periodic heartbeat message from a certain preset CAN ID within a preset timeout period , it determines that the node device occupying the preset CAN ID has been offline, wherein, , is the transmission period of the periodic heartbeat message, is an integer in the range of 3 to 5 preset according to the bus load and communication reliability requirements.
[0012] Preferably, after determining that the node device occupying the preset CANID has been dropped off, the monitoring end removes the entry corresponding to the preset CANID in the online device list maintained by the monitoring end, and marks the preset CANID as a free address available for allocation.
[0013] Preferably, the address pool is a continuous address space defined by a start address and an end address, the master device in the CAN bus network occupies a fixed address outside the address pool, and all slave node devices perform dynamic address allocation in the address pool through the method.
[0014] Preferably, the method further comprises, if the newly powered-on node device fails to become the only winner in the first competition window, the node device automatically enters a next competition window with the same length as the first competition window, and repeats the regular selection step and the cross-layer synchronization step.
[0015] Preferably, the node device is a battery management system (BMS), and the monitoring end is a power conversion system (PCS).
[0016] Compared with the prior art, the present application has the following beneficial effects: 1. By establishing a fixed initial competition window and combining the incremental logic of finding the current minimum available address, the address configuration process originally relying on manual presetting or upper computer intervention is changed into an orderly self-organizing behavior triggered by the newly added node to complete based on real-time bus information, so that any node can be integrated into the network communication system at the moment of accessing the physical bus, and the address conflict or allocation omission problem caused by human operation error or centralized configuration logic failure is avoided.
[0017] 2. The address competition process after the node is powered on is combined with the inherent bit arbitration mechanism of the controller area network bus, and in the extreme condition that multiple nodes are physically started at the same time and attempt to apply for the same address, the arbitration result at the bus hardware level directly becomes the basis for the node to judge whether the address has been occupied, and the node that fails to send will immediately give up the current address and enter the next round of attempt, so that the address allocation obtains certainty at the physical layer, and the complexity and uncertainty of the application layer software processing of concurrent conflicts are avoided.
[0018] 3. The node with the obtained address sends the message to the bus at a fixed period, and the monitoring end of the system continuously monitors these messages, constituting a distributed node state maintenance and dynamic sensing mechanism; when the periodic message of a certain node disappears within a preset timeout period, the monitoring end identifies the occupied address as idle, and this mechanism makes the release and recovery of the address an automatic process accompanying the physical online state of the node, ensuring the dynamic cyclic use of the system address resources, and the above-mentioned node autonomous address allocation, parallel conflict processing based on bus arbitration, and node state maintenance and address dynamic recovery are organically integrated into one, building a complete and closed node address life cycle management mode; the mode does not depend on a preset central management unit, and the joining, exiting and concurrent competition of each node are coordinated and solved among the nodes and between the node and the bus protocol through unified rules, finally making the entire multi-node system present a robust adaptive ability in the actual application scene of frequent dynamic changes. BRIEF DESCRIPTION OF DRAWINGS
[0019] Fig. 1 Flow chart for autonomous address allocation of new power-on node of the application; Fig. 2 Initialization performance comparison chart under the concurrent power-on scene of the multi-node of the application. DETAILED DESCRIPTION
[0020] In order to make the purpose, technical scheme and advantages of the application clearer, the technical scheme of the application will be described in detail below, but the protection scope of the application is not limited to the specific examples in the text.
[0021] The application relates to a distributed dynamic address allocation and recycling method of a CAN bus node, which is performed in a controller area network (CAN) bus network comprising a monitoring terminal and at least one node device, and the operation process comprises three stages of address autonomous declaration, cross-layer cooperative arbitration and dynamic address recycling, and the three stages jointly constitute a closed-loop management procedure for CAN bus network node identity (CANID); in a storage energy system in which a power conversion system (PCS) serves as a monitoring terminal and manages a plurality of battery management system (BMS) slave node devices, when a newly powered-on BMS node device accesses the CAN bus network, the built-in micro control unit (MCU) firmware of the BMS node device will perform prerequisite construction and constraint steps; specifically, the CAN controller of the node device is configured to only listen to the working mode of the bus, and in a first competition window with a time length of 400 ms, all message frames transmitted on the bus are continuously captured, and the time length of 400 ms is set to be greater than the period of periodic heartbeat messages broadcast by all online node devices in the network (the period is determined to be 100 ms in the embodiment), so that sufficient redundancy time is provided for the new node device to ensure that at least one round of heartbeat messages of all online node devices can be listened to, thereby generating a CANID set occupied on the current bus in the internal memory of the node device; then, the application layer firmware of the node device performs a regular selection step, and according to the generated occupied CANID set, the to-be-allocated CANID of the node device is set to be the first unoccupied ID value in the address pool defined by the starting address 0x201 and the ending address For example, if it is found that the addresses 0x201 and 0x202 are occupied, the to-be-allocated CANID of the first attempt of the node device is set to be 0x203.
[0022] In the concurrent collision condition that two or more BMS node devices are physically powered on at the same time and select the same first unoccupied CAN ID (for example, 0x203), the method of the application performs a cross-layer synchronization step; in this condition, all node devices that attempt to claim the 0x203 address send a claim message containing the same ID to the bus through their CAN controllers, and cooperatively perform the non-destructive bit arbitration physical mechanism inherent in the CAN bus protocol, which can determine that only one arbitration-winning claim message is completely sent; the application layer firmware of the node devices that fail in the arbitration receives an arbitration failure event reported by the CAN controller, which is interpreted by the application layer firmware as a signal that the ID has been occupied, and returns to perform the regular selection step according to the hardware event return execution rule, that is, performs the add-one operation on the current own to-be-allocated CAN ID (0x203), and takes the newly generated ID value (0x204) as the own to-be-allocated CAN ID, and attempts to send the claim message again until the node device becomes the only winner in the subsequent bit arbitration mechanism and completes the address allocation; the specific implementation of the arbitration failure event acquisition in step c depends on the hardware state feedback mechanism of the CAN controller in the node device. When the CAN controller detects that the bus level is inconsistent with the level it sends during the arbitration field of the sent message and determines that the arbitration has failed, the hardware automatically sets a preset flag bit, i.e., an arbitration loss flag, in one or more state registers to the effective level. The application layer firmware captures this hardware event through two alternative computer implementation paths: one path is to poll the state register at a fixed time interval in the main task loop of the firmware and detect the level change of the arbitration loss flag bit; the other path is to configure the CAN controller to automatically trigger a hardware interrupt to the micro control unit (MCU) core when the arbitration loss flag bit is set by the hardware during the system initialization phase, and an interrupt service program bound to the interrupt vector is triggered in response to the event. The final effect of the two paths is to convert the physical layer arbitration failure result into a deterministic Boolean judgment condition in the application layer address allocation logic to trigger the subsequent to-be-allocated CAN ID increment and retry operation.
[0023] After the node devices complete the address allocation, the system performs a stable state maintenance step and a dynamic address recovery step; any BMS node device that has successfully obtained an address will continuously broadcast a periodic heartbeat message containing its own allocated CAN ID to the CAN bus network at a fixed sending period of 100 ms; as a monitoring end, the PCS continuously listens to all periodic heartbeat messages from the address pool (0x201 to The operation procedure of the timeout timer is set as follows: if the timeout timer expires before the PCS receives a periodic heartbeat message from the node device associated with the CAN ID, the PCS will consider that the node device has been offline for a long time and will trigger the address recovery process for the CAN ID. If no periodic heartbeat message is received from a preset CANID, the node device occupying that preset CANID is determined to be offline. The value of follows the formula ,in, The sending period for periodic heartbeat messages is 100ms. This is an integer preset within the range of 3 to 5 based on bus load and communication reliability requirements. For example, in a system with a relatively stable communication environment, it can be... Set to 3, that is The response time is 300ms, but in an environment with strong electromagnetic interference, it can be... Set to 5, that is The time is 500ms. After the monitoring PCS determines that the node device occupying the preset CANID has gone offline, the PCS will remove the entry corresponding to the preset CANID from the online device list maintained internally, and mark the preset CANID as an idle address that can be allocated to subsequent newly powered-on nodes, thereby realizing the dynamic recycling of address resources.
[0024] Example 1: In a large-scale battery energy storage power station deployed in a container, a momentary voltage drop in the external power grid caused the auxiliary power system of one of the energy storage containers to trigger undervoltage protection. This resulted in all 16 battery management system (BMS) nodes inside the container being simultaneously powered off and then simultaneously powered on and restarted. In this multi-node concurrent power-on scenario, if multiple nodes simultaneously request the same network address during the address allocation process, it will cause bus communication conflicts, thereby delaying the grid connection recovery time of the entire energy storage unit. After this scenario occurs, all 16 BMS nodes start up simultaneously and begin executing the address allocation process. Each device first enters a... During a 400ms contention window, a listening operation is performed. Since all BMS devices in the network start simultaneously, there are no periodic heartbeat messages on the bus during this window. After completing the listening, all 16 devices generate an empty set of occupied CANIDs. Accordingly, when performing the regularized selection step, each device uses the starting address 0x201 of the address pool as its own CANID to be allocated, and at the end of the 400ms contention window, it simultaneously attempts to send a declaration message containing ID 0x201 to the bus. At this point, the system enters the cross-layer coordination step described in the aforementioned specific implementation.
[0025] When 16 devices send the message with ID 0x201 at the same time, the non-destructive bit arbitration mechanism inherent in the CAN bus physical layer is activated, and it is determined that one of the arbitration winning messages is completely sent, and the CAN controllers of the remaining 15 devices all report the arbitration failure event at the hardware level; the application layer firmware of the 15 arbitration-failed devices interprets this hardware event as a signal that the address 0x201 has been occupied, and immediately returns to the regular selection step to perform the add-one operation on the respective CAN ID to be allocated, and attempts to send the declaration message again with the newly generated ID value 0x202; this process is repeated among the remaining 15, 14, or even fewer devices, forming a deterministic, cascading address preemption sequence based on hardware arbitration; the regular selection step of the application layer provides an ordered candidate sequence for address allocation, while the bit arbitration mechanism of the physical layer provides a non-deadlock decision method for concurrent conflicts, and the two work together to downshift the arbitration of concurrent conflicts at the application layer to the hardware execution at the physical layer; ultimately, within tens of milliseconds after the first 400 ms competition window ends, all 16 BMS node devices autonomously complete the unique CAN ID allocation from 0x201 to 0x210 through the above cascading arbitration method, and then start broadcasting their periodic heartbeat messages with a period of 100 ms; the PCS receives the heartbeat messages of the 16 new IDs in a short time and includes all the BMS node devices in the online device list for normal monitoring, and the entire energy storage container quickly recovers from the large-scale concurrent power-on state to the controllable grid-connected operation state without human intervention, and the system communication link also records no error frames caused by address conflicts during this process.
[0026] Example 2: To objectively quantify the performance of the distributed dynamic address allocation and recovery method of the foregoing CAN bus node under the condition of concurrent power-on of multiple nodes, a comparative verification test is designed and performed to measure and compare the system initialization speed and communication link stability of the test group using the method of the present application and the control group using two prior art methods under different numbers of concurrent nodes; the test is performed on a hardware platform composed of 16 BMS node device hardware units, a programmable power supply that can accurately control the power-on timing of each unit, and a CAN bus analyzer for monitoring and recording bus data; all BMS node device hardware units are configured with CAN controllers conforming to the ISO11898-1 standard and are connected to a common CAN bus with a baud rate set to 500 kbit / s; the CAN bus analyzer has a function of recording the timestamp of all message frames with a precision better than 1 μs and can count bus error frames; the core variable parameter in the test is the number of concurrent power-on nodes The values are set to 4, 8, 12, and 16 respectively to simulate system startup scenarios of different scales.
[0027] The experiment consisted of one sample group and two control groups based on the present invention. All sample groups were tested on the aforementioned experimental platform, targeting each... The values were tested; Control group A adopted a host computer power switch sequential configuration method, in which the programmable power supply powered on the BMS node devices one by one. After each device was powered on, the host computer sent an address write command through the CAN bus. After the node device returned a frame confirmation, the next node device was powered on, until all configurations were completed; Control group B adopted a simplified distributed listen-preemption method, in which all node devices were powered on simultaneously. After a 400ms listening window, each attempted to apply for the first unoccupied ID. If its declaration message failed due to bus conflict, it waited for a random duration of 10ms to 50ms before trying again; The present invention sample group adopted the complete method disclosed, especially when concurrent conflicts occurred during the transmission of declaration messages, it used cross-layer collaborative steps to treat the arbitration failure event reported by the CAN controller as a signal that the ID was occupied, and immediately incremented its own CANID before trying again; During the experiment, the key performance indicators recorded by the CAN bus analyzer were: From The total system initialization time is from the moment all node devices power on simultaneously until the moment the last node device successfully obtains a unique ID and sends its first periodic heartbeat message; the percentage of node devices that successfully obtain a unique ID within the total system initialization time is [not specified]. The percentage, i.e., the address allocation success rate; and the number of bus error frames that appear on the bus during the total system initialization time, and the number of concurrent power-on nodes for each sample group. The performance index test results under the specified conditions are shown in Table 1.
[0028] Table 1: Comparison of performance indicators for each sample group.
[0029]
[0030] Analysis of the data in Table 1 shows that the total system initialization time of control group A increases with the number of nodes. It increases linearly with the increase, in The duration was more than 3 seconds at 16:00; control group B was... When the value is greater than 4, multiple node devices simultaneously attempt to transmit again after random backoff, causing continuous bus collisions. This leads to a surge in the number of bus error frames and a sharp drop in the address allocation success rate. Under condition 8, the system could not complete initialization within 5 seconds; however, the sample of this invention maintained a 100% address allocation success rate and a near-zero number of bus error frames under all test conditions, with a total system initialization time of [missing information]. is still below 500 ms, because the cross-layer synchronization step of the inventive set will determine the address conflict problem of the application layer through the physical layer bit arbitration mechanism within microseconds, avoiding the non-deterministic and inefficient problems of the software random backoff strategy in the control group B.
[0031] Embodiment 3: This embodiment combines Figs. 1-2 , a kind of CAN bus node distributed dynamic address allocation and recycling method is described as shown in Fig. 1 , the flow starts from the start state, first executes the operation of creating CANID, i.e. selecting an initial ID to be allocated, then entering a loop listening and decision-making phase, capturing bus information in the step of listening CANID message, and entering the decision point of judging whether the ID is occupied, if the result is yes, execute the operation of CANID+1 of itself to increment the ID, and return to continue listening CANID message, if the result is no, the flow continues to the step of determining the CANID of itself, completes the uniqueness of address allocation, and finally enters the stable running state of timing sending CAN message.
[0032] As shown in Fig. 2 , the abscissa of the graph is the number of concurrent power-on nodes, and the ordinate is the initialization time length ms, the three curves in the graph respectively represent the performance of the inventive method, the control group A sequential configuration and the control group B simplified listening and occupation, the data shows that the initialization time length of the inventive method does not increase with the increase of the number of nodes, and is always maintained below 500 ms, while the time length of the control group A increases linearly, and the control group B fails to initialize due to communication conflict when the number of nodes is greater than 4, and the time length exceeds 5000 ms.
[0033] Embodiment 4: This embodiment provides a systematic engineering calibration procedure for key time parameters, to ensure that the inventive method can reliably run under different physical environments and network load conditions; in a specific engineering practice, when the method claimed in the present application needs to be deployed on a mobile engineering machinery platform with high electromagnetic interference characteristics and variable number of nodes, the preset general parameters may not adapt to the preset working environment, at this time, a time length suitable for the environment needs to be set for the first competition window of the newly powered-on node, and a timeout time length that can balance sensitivity and anti-interference needs to be set for the dynamic address recycling step of the monitoring end ; to determine the time length of the competition window , first define the network boundary conditions of the target application scene, including the maximum number of node devices , the CAN bus communication baud rate , and the maximum length of the message frame ; based on these boundary conditions, the time length of the competition window The time length of the contention window can be determined by a calculation formula with a safety margin, i.e. wherein, is the internal processing delay required by the node device firmware to receive and process the packet, is a safety factor greater than 1, which is set in the interval of 1.2 to 2.0, and a typical value is 1.5; in a specific calibration process, if is 16, is 500 kbit / s, is 135 bits, is set to 1 ms, then the calculation can be ms, which can be rounded to 40 ms in engineering, and this value is used as the contention window time length of all newly powered node devices in the preset application environment.
[0034] To determine the timeout time length in the dynamic address recycling step , especially the value of the key integer , the bus communication quality of the target platform needs to be quantitatively evaluated; the specific operation is to capture and count the total number of periodic heartbeat packets sent by any node device using a CAN bus analyzer under the condition that the system is continuously running with typical load for a preset time length (e.g. 30 minutes) , and the number of packets that cannot be successfully received during this period , and then calculate the average packet loss rate in this environment; the value of the integer is selected according to the measured according to the following rules: when is less than 0.01%, set to 3; when is between 0.01% and 0.1%, set to 4; when is greater than or equal to 0.1%, set to 5; if the measured on the above mobile engineering machinery platform is 0.06%, according to the rule, the value of is determined to be 4, and accordingly, the timeout time length is set to ms; through this series of standardized calibration procedures, the key time parameters previously set by experience are given traceable engineering basis, making the deployment of the method of the present application adaptable to different application environments.
[0035] Example 5: In a distributed industrial control system which has been using the method of the present application and has been running stably for a long time, the monitoring terminal which executes the dynamic address recovery step is unexpectedly offline due to its own hardware failure. As a result, if a node device which has been allocated a CAN ID is removed from the bus for maintenance, the address occupied by the node device cannot be marked as available by the system due to the lack of recovery instructions from the monitoring terminal. If this state continues for a long time, it will lead to a gradual decrease in available address resources. To deal with this boundary condition, each node device in the method of the present application is configured not only to periodically broadcast its own heartbeat message, but also to continuously listen to the periodic heartbeat message of the monitoring terminal. A separate monitoring terminal timeout timer is set inside the node device, and the time length of the timer is set to . If the heartbeat message from the monitoring terminal cannot be received within the time length, the node device automatically enters a communication safety mode. In this mode, the application layer firmware of the node device will suspend the regular selection step in the address allocation process, and the node devices that are online will keep their existing CAN IDs unchanged and continue to perform their basic data communication tasks, while setting a status flag bit indicating that the monitoring terminal is offline in the periodically broadcasted message. When a new or repaired monitoring terminal accesses the bus and starts broadcasting its heartbeat message, all node devices in the communication safety mode automatically exit the safety mode and restore their complete address allocation and recovery functions upon receiving the message. After the new monitoring terminal goes online, it can rebuild the list of online devices in the network by listening to the heartbeat messages of all node devices, and can identify those nodes that have been physically removed but whose addresses have not been recovered, and then re-include their addresses in the pool of available free addresses, so as to restore the entire network to a normal operating state.
[0036] Example 6: This example describes the fault tolerance mechanism of the method of the present application for node devices to complete address allocation across the contention window under extreme network load conditions. In a high-density data acquisition system containing a large number of node devices and with bus load continuously above 80%, a newly powered-on BMS node device completes its first 400ms contention window and enters the address declaration phase. Due to the existence of a large number of high-priority real-time data messages on the bus, the declaration message containing the to-be-allocated CAN ID sent by the node device fails to be successfully sent and complete arbitration before the end of the contention window in multiple attempts due to congestion of the sending buffer or continuous encounter with higher-priority messages in bus arbitration.
[0037]
[0038] Within the internal firmware logic of this BMS node device, an internal timer synchronized with the contention window is initiated. When this timer expires, indicating that the first contention window has ended and the node device has not yet become the sole winner of the arbitration, it immediately suspends the current address claim attempt and stops sending any claim messages. It will re-enter a listening-only mode until the start of the next contention window is detected. Then, the node device will discard the set of occupied CANIDs it acquired in the previous window and re-execute the entire process of premise construction and constraint steps, rule-based selection steps, and cross-layer coordination steps. That is, within a completely new contention window, based on the latest listening results of the bus state, it restarts the address allocation attempt. By forcing the node device to return to the initial listening state and restart the complete allocation process after the contention window times out, this mechanism ensures that even under continuous and extreme bus congestion or concurrent conflict conditions, the node device can still obtain a valid CANID by retrying in subsequent contention windows with lower load, thus providing the final guarantee for the successful address allocation of the method in various complex network environments.
[0039] To further verify the technical necessity of the cross-layer collaborative step in the method of this invention from a reverse perspective, the following comparative example 1 is provided.
[0040] Comparative Example 1: This comparative example aims to verify a conventional technical approach that a person skilled in the art might use when facing concurrent address conflicts among multiple nodes, namely a conflict resolution method based on application-layer random backoff and retry; in addition to the conflict resolution method, the experimental platform, hardware configuration, CAN bus baud rate (500kbit / s), address pool range to be allocated, and number of concurrently powered-on nodes used in this comparative example are also specified. All test conditions (4, 8, 12, 16, etc.) were used, and all were kept completely consistent with the conditions set for the test group using the method of the present invention in Example 2 above to ensure the fairness of the comparison. The core difference in this comparative example is that when multiple BMS node devices are powered on concurrently and attempt to declare the same CANID (e.g., 0x201), causing a bus conflict, the conflict resolution method executed by their firmware is modified as follows: After the CAN controller of the node device fails to transmit, it reports a general transmission failure event to its application layer. After receiving the event, the application layer firmware does not immediately increment its own CANID to be assigned, but starts an internal timer, waits for a duration randomly selected between 10ms and 50ms, and then attempts to send a declaration message containing the original CANID (0x201) again. This process is repeated until the message is successfully sent or the preset number of retries is exceeded. This method represents a conventional approach to resolving packet collisions in network communication protocol design.
[0041] Under the same test procedure as Example 2, the test group using this application layer random backoff retry method is tested, and the system initialization total time, address allocation success rate and bus error frame number are recorded by the CAN bus analyzer. In a typical test scenario (N=8, T=8), 8 BMS node devices are powered on at the same time and attempt to claim ID 0x201, which immediately causes a message conflict on the bus. All 8 devices' CAN controllers report a send failure. Then, each device enters a random wait of 10-50 ms. Due to the randomness of the waiting time, it is very likely that two or more devices will initiate a claim for ID 0x201 again after the random wait ends, within a very small time window (microsecond level), thereby triggering a new round of bus conflict and error frames. This conflict-random backoff-reconflict cycle worsens rapidly with the increase in the number of nodes.
[0042] Table 2: Performance index test table of Comparative Example 1.
[0043]
[0044] The test results of Comparative Example 1 show that when there is no mechanism to deterministically bind physical layer arbitration failure events with application layer address increment, simply relying on the random backoff strategy of the application layer cannot effectively solve the address conflict problem when multiple nodes are powered on at the same time. When the number of concurrent nodes is only 4, this method has already failed in address allocation (success rate 75.0%) and a large number of bus error frames (112), and the initialization time has increased. When the number of concurrent nodes increases to 8 or more, continuous and chain-like bus conflicts cause the communication link to be severely congested, the address allocation success rate drops sharply, and the system cannot complete initialization within a 5000 ms observation window, proving that this conventional technical path has inherent defects in the face of the technical problems to be solved by the present application.
[0045] It is obvious to those skilled in the art that the present application is not limited to the details of the above exemplary embodiments, and can be implemented in other specific forms without departing from the spirit or essential characteristics of the present application.
[0046] Finally, it should be noted that the above examples are only used to illustrate the technical solutions of the present application and are not limiting. Although the present application has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present application can be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the present application.
Claims
1. A method for distributed dynamic address assignment and recovery of CAN bus nodes, the method being performed in a CAN bus network comprising a supervision node and at least one node device, characterized in that The method comprises the following computer-implemented steps: Step a, when a newly powered-on node device accesses the CAN bus network, a premise construction and constraint step is performed, the newly powered-on node device performs a listening operation within a first contention window, the length of the contention window is set to be greater than the period of periodic heartbeat messages broadcast by all online node devices in the network, so as to obtain a set of occupied CAN IDs on the current bus; Step b, a regularized selection step is performed, according to the set of occupied CAN IDs, the newly powered-on node device sets its own to-be-assigned CAN ID as the first unoccupied ID value in an address pool defined by a preset start address and end address according to a preset incremental rule; Step c, a cross-layer coordination step is performed, in the case of concurrent conflict in which at least two node devices select the same to-be-assigned CAN ID according to the regularized selection step, the node devices all send a declaration message containing the same ID through their CAN controllers, and cooperatively perform a non-destructive bit arbitration physical mechanism inherent in the CAN bus protocol, which determines that a declaration message that wins the arbitration is completely sent, and the application layer of a node device that fails in the arbitration receives an arbitration failure event reported by the CAN controller, and returns to perform the regularized selection step according to the event until the node device becomes the only winner in the bit arbitration mechanism and completes address allocation.
2. The method according to claim 1, wherein, In the premise construction and constraint step, the length of the contention window is set to be greater than or equal to the least common multiple period of periodic heartbeat messages broadcast by all online node devices in the network.
3. The method of claim 1, wherein, In the regularized selection step, the preset incremental rule is specifically that the newly powered-on node device sets its initial to-be-assigned CAN ID as the start address of the address pool, if it is found that the ID has been occupied or the node device experiences arbitration failure in the cross-layer coordination step, then the to-be-assigned CAN ID of the node device is incremented by one, and the newly generated ID value is taken as the to-be-assigned CAN ID of the node device, and the operation is repeatedly performed until address allocation is completed.
4. The method of claim 1, wherein, After the newly powered-on node device completes address allocation, a stable state maintenance step is further included, in which the node device continuously broadcasts a periodic heartbeat message containing its own assigned CAN ID to the CAN bus network at a fixed sending period.
5. The method of claim 4, wherein, The method further includes a dynamic address recycling step performed by a monitoring end, which continuously listens to periodic heartbeat messages of all assigned CAN IDs in the network, and maintains an independent timeout timer for each assigned CAN ID.
6. The method of claim 5, wherein, In the dynamic address recycling step, the monitoring end determines the timeout state according to the following rules: if no periodic heartbeat message from a preset CAN ID is received within a preset timeout period , the node device occupying the preset CAN ID is determined to have been disconnected, wherein, , is the sending period of the periodic heartbeat message, is an integer in the range of 3 to 5 preset according to the bus load and communication reliability requirements.
7. The method of claim 6, wherein, After the monitoring end determines that a node device occupying the preset CAN ID has been offline, the monitoring end removes an entry corresponding to the preset CAN ID from an online device list maintained in the monitoring end, and marks the preset CAN ID as a free address available for allocation.
8. The method of claim 1, wherein, The address pool is a continuous address space defined by a start address and an end address, a master device in the CAN bus network occupies a fixed address outside the address pool, and all slave node devices perform dynamic address allocation in the address pool by the method.
9. The method of claim 1, wherein, The method further includes, if the newly powered node device fails to become the only winner within the first contention window, the node device automatically enters a next contention window with the same duration as the first contention window, and repeats the regularized selection step and the cross-layer coordination step.
Citation Information
Patent Citations
A method for displaying a dynamic MAC address table in a distributed OLT system
CN104994181B