ID distribution method and system, node equipment and computer readable storage medium
By sending and receiving the start message when the node device receives the trigger signal, the node device can independently determine whether it is a starting node, thereby solving the problem of device ID allocation dependence on a single node in the prior art, realizing decentralization Device identification and communication mechanisms improve system flexibility and scalability.
Patent Information
- Application Number
- CN202411504999.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-25
- Publication Date
- 2025-02-18
AI Technical Summary
In the prior art, the device ID allocation process has a high degree of dependence on a single node. When the master node fails, the entire communication system will not be able to complete the device ID allocation, resulting in the system being unable to operate normally.
By sending and receiving the start message when the node device receives the trigger signal, the node device can intelligently determine whether it is the starting node in the network, thereby independently deciding whether to initiate the ID allocation or receive the ID assigned by the superior node.
A decentralized device identification and communication mechanism is realized, reducing dependence on a single node, improving system flexibility and scalability, and ensuring efficient and stable communication between devices.
Smart Images

Figure CN119484670A_ABST
Abstract
Description
[Technical field]
[0001] The present invention relates to the field of ID allocation, and in particular to an ID allocation method, system, node device and computer-readable storage medium. [Background technology]
[0002] In traditional multi-node device communication systems, the allocation and management of device IDs is a crucial step because it ensures that data can be accurately sent to the correct device. However, this process usually relies on a centralized mechanism, which, while it works in some cases, has its inherent limitations when faced with the needs of modern communication systems.
[0003] In the process of implementing the present invention, the inventors found that the prior art has at least the following technical problems: In a centralized system, the allocation of device IDs is usually based on a master node device initiating data communication, or a specific signal triggers the master node device, and the master node device initiates communication with the subordinate node devices. As a result, the ID allocation process is too dependent on a single node. When the master node fails, the entire communication system will not be able to complete the allocation of device IDs, which will cause the system to fail to operate normally.
[0004] Therefore, how to reduce the dependence of ID allocation on a single node is a technical problem that needs to be solved in this field. [Summary of the invention]
[0005] In order to effectively solve the problem in the prior art that ID allocation is too highly dependent on a single node, the present invention provides an ID allocation method.
[0006] A method for allocating an ID, comprising:
[0007] For each of the node devices in the multi-node device, when the node device receives a trigger signal, the node device sends a first startup message through the first interface;
[0008] Detecting whether the second interface receives a second startup message within a preset time; the second startup message is the first startup message sent by the upper node device;
[0009] If not, the initial ID is confirmed as the device ID of the current node device, and a first ID allocation message is generated;
[0010] Sending the first ID allocation message through the first interface, so that the lower-level node device determines the ID to be allocated obtained from the first ID allocation message as the device ID of the lower-level node device;
[0011] If so, a second ID allocation message sent by the upper node device is received through the second interface, and the ID to be allocated obtained from the second ID allocation message is determined as the device ID of the current node device.
[0012] Optionally, after sending the first ID allocation message through the first interface, the method further includes:
[0013] Determine the first allocated ID information according to the device ID of the current node device;
[0014] Sending first query information through the first interface polling, and receiving second allocated ID information returned by the lower-level node device;
[0015] Determining whether the second allocated ID information is the same as the first allocated ID information;
[0016] If not, the first allocated ID information is updated to the second allocated ID information, and the step of sending the first query information through the first interface polling and receiving the second allocated ID information returned by the lower node device is returned;
[0017] If yes, determining whether the number of times the second allocated ID information is received exceeds a threshold;
[0018] If the number of receptions does not exceed the threshold, returning to the step of sending the first query information through the first interface polling and receiving the second allocated ID information returned by the lower-level node device;
[0019] If the number of receptions exceeds a threshold, an end message is sent through the first interface, so that the lower-level node device forwards the end message and enters a data communication state.
[0020] Optionally, after determining the ID to be allocated obtained from the second ID allocation message as the device ID of the current node device, the method further includes:
[0021] Updating the ID to be allocated in the second ID allocation message;
[0022] The updated second ID allocation message is sent through the first interface.
[0023] Optionally, after sending the updated second ID allocation message through the first interface, the method further includes:
[0024] Determine the third allocated ID information according to the device ID of the current node device;
[0025] Sending second query information through the first interface polling;
[0026] Determine whether the fourth allocated ID information returned by the subordinate node device of the current node device is received;
[0027] If yes, updating the third allocated ID information to the fourth allocated ID information;
[0028] When the third query information sent by the upper node device is received through the second interface, the updated third allocated ID information is sent to the upper node device through the second interface.
[0029] Optionally, after sending the updated third allocated ID information to the upper-level node device through the second interface, the method further includes:
[0030] When the end message sent by the upper node device is received through the second interface, the current node device is controlled to enter the data communication state, and the end message is sent through the first interface.
[0031] Optionally, the second ID allocation message also includes communication parameters;
[0032] After receiving the second ID allocation message sent by the upper node device through the second interface, the method further includes:
[0033] Acquire the communication parameters from the second ID allocation message;
[0034] The current node device is set according to the communication parameters.
[0035] A system for ID allocation, the system comprising at least two node devices, wherein:
[0036] Each of the node devices has a first interface and a second interface;
[0037] For each of the node devices in the multi-node device, the second interface of the node device is connected to the first interface of the upper node device, and the first interface of the node device is connected to the second interface of the lower node device;
[0038] The node device is used to send a first startup message through the first interface when receiving a trigger signal; detect whether the second interface receives a second startup message within a preset time; the second startup message is the first startup message sent by the upper-level node device; if not, confirm the initial ID as the device ID of the current node device, and generate a first ID allocation message; send the first ID allocation message through the first interface, so that the lower-level node device determines the ID to be allocated obtained from the first ID allocation message as the device ID of the lower-level node device; if so, receive the second ID allocation message sent by the upper-level node device through the second interface, and determine the ID to be allocated obtained from the second ID allocation message as the device ID of the current node device.
[0039] A node device, comprising:
[0040] A processor and a memory, wherein the memory is used to store at least one instruction, and when the instruction is loaded and executed by the processor, the method for ID allocation as described in any one of the above items is implemented.
[0041] A computer-readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements any one of the above-mentioned methods for allocating IDs.
[0042] The ID allocation method provided by the embodiment of the present invention has at least the following beneficial effects:
[0043] The present invention sends a first startup message through the first interface when the node device receives a trigger signal; detects whether the second startup message is received by the second interface within a preset time; if not, confirms the initial ID as the device ID of the current node device, and generates a first ID allocation message; sends the first ID allocation message through the first interface; if yes, receives the second ID allocation message sent by the upper node device through the second interface, and determines the ID to be allocated obtained from the second ID allocation message as the device ID of the current node device. The present invention implements a decentralized device identification and communication mechanism, allowing each device in the network to automatically participate in the ID allocation process when receiving a trigger signal, which can reduce the dependence on a single node and improve the flexibility and scalability of the system. By sending and receiving startup messages through the first and second interfaces of the device within a preset time, the node device can intelligently determine whether it is the starting node in the network, thereby autonomously deciding whether to initiate ID allocation or receive the ID allocated by the upper node, which not only simplifies the wiring requirements of the network and avoids additional bus or loop design, but also reduces the possibility of communication conflicts by eliminating the dependence on device delay, ensuring efficient and stable communication between devices.
Brief Description of the Drawings
[0044] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0045] Figure 1 A flowchart of a first ID allocation method provided by an embodiment of the present invention;
[0046] Figure 2 A structural framework diagram of a communication system provided by an embodiment of the present invention;
[0047] Figure 3 A flowchart of a second ID allocation method provided by an embodiment of the present invention;
[0048] Figure 4 This is a flow chart of a third ID allocation method provided by an embodiment of the present invention. [Specific implementation method]
[0049] In order to better understand the technical solution of the present invention, the embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0050] It should be clear that the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0051] The terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit the present invention. The singular forms "a", "said" and "the" used in the embodiments of the present invention and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings.
[0052] It should be understood that the term "and / or" used in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.
[0053] In traditional multi-node device communication systems, the allocation and management of device IDs is a crucial step because it ensures that data can be accurately sent to the correct device. However, this process usually relies on a centralized mechanism, which, while it works in some cases, has its inherent limitations when faced with the needs of modern communication systems.
[0054] In the process of implementing the present invention, the inventors found that the prior art has at least the following technical problems: for cost-saving considerations, all node devices in the communication system are connected in a certain order to form a linear chain structure. Data transmission has a clear path and does not require complex routing decisions. However, if any node device in the chain fails, the entire communication chain may be interrupted because the data cannot bypass the failed node. The allocation of device IDs is usually based on a master node device initiating data communication, or a specific signal triggers the master node device to initiate communication with the subordinate node devices through the master node device. This results in the ID allocation process being too dependent on a single node. When the master node fails, the entire communication system will not be able to complete the allocation of device IDs, which will cause the system to fail to operate normally.
[0055] Moreover, in the current technical solution, the subordinate node device notifies the main node device of the assigned ID through bus or line feedback, which requires additional communication line design in line design, resulting in increased costs, system complexity, and extended system deployment time.
[0056] In addition, some of the current technical solutions utilize delay circuits / signals between nodes. In actual usage scenarios, especially software delays, absolute delay differences cannot be guaranteed. If the device delay times are the same, communication conflicts will occur.
[0057] Therefore, the present invention provides a first ID allocation method to solve the above problem.
[0058] Please refer to Figure 1 , which is a flow chart of a first ID allocation method provided by an embodiment of the present invention, comprising the following steps:
[0059] Step S01: for each node device in the multi-node device, when the node device receives a trigger signal, the node device sends a first startup message through a first interface.
[0060] Please refer to Figure 2 , is a structural framework diagram of a communication system provided by an embodiment of the present invention. Figure 2 As shown, in this embodiment, each node device includes a first interface and a second interface. Each node device is connected through the first interface or the second interface. The first interface is responsible for initiating communication access with the lower-level node device, and the second interface is responsible for replying to the access information sent by the upper-level node device. Bidirectional data transmission can be achieved between the first interface and the second interface, and a cascade structure is formed between multiple node devices.
[0061] In some embodiments, when any node device receives a trigger signal, it automatically sends a predefined first startup message through its first communication interface. The first startup message may contain system information, such as device identification, status, and a signal requesting synchronization, so as to announce its participation in the network and trigger subsequent communication and configuration processes. This is done to ensure that the node device can be quickly identified by the network and is ready to receive instructions from the upper node or start allocating the device ID of the lower node, thereby achieving automatic organization of the network and effective communication between devices.
[0062] In this embodiment, in order to initialize the network connection and determine the communication order between devices, when the node device receives the trigger signal, each device node actively polls and sends the first startup message to notify the lower-level node device of the existence of the upper-level node device. If a node device receives the first startup message sent from the upper-level node device, it knows that it is not the starting device in the current network. Therefore, in the subsequent address allocation stage, it only needs to wait and respond to the allocation address signal sent by the upper-level node device to obtain its own device ID. On the contrary, if the device node does not receive any first startup message within the preset time, it will identify itself as the starting device and be responsible for starting the device ID allocation process in the entire network, ensuring that each node device can obtain a unique identifier, thereby maintaining the effective organization and communication of the network.
[0063] In some embodiments, there may be multiple types of trigger signals, such as button signals or software control signals. The present application does not specifically limit the types of trigger signals.
[0064] Step S02: Detect whether the second interface receives a second startup message within a preset time.
[0065] If not, execute step S03; if so, execute step S05.
[0066] In this embodiment, the second startup message is the first startup message sent by the upper node device. After receiving the trigger signal, each device node will listen through its second interface to check whether it has received the second startup message sent by the upper node device within a specific preset time, and then identify the current node device as the starting node or the slave node in the network.
[0067] In some embodiments, after receiving the trigger signal and sending the first startup message, each node device will enter a listening state for a preset time. During the preset time, the node device will detect whether there is a second startup message through its second interface. For example, the node device can continuously monitor the network traffic of the second interface to see if there are messages that conform to the predefined format and destination address. If the second startup message is received within the preset time, this indicates that an upper-level node device exists. The current node device will configure itself as a slave node and prepare to receive further instructions from the upper-level node; if the second startup message is not received after the preset time, the current node device will consider itself to be the starting node in the network, and then start the device ID allocation process. This process is automated and is designed to ensure that each device in the network can determine its position and role in the communication chain without human intervention.
[0068] Step S03: confirm the initial ID as the device ID of the current node device, and generate a first ID allocation message.
[0069] In this embodiment, when a node device fails to receive the second startup message sent from the upper node device through its second interface within a preset time, the node device will confirm that it is the starting device in the network, that is, the master node or root node in the network. The current node device will use a predefined initial ID as its own device ID, which is usually preset when the device is manufactured or automatically generated when the system starts. Once its identity is determined, the node device will generate and send a first ID allocation message, which contains the ID information assigned to the lower node device. The purpose of this is to start the device ID allocation process for the entire network, ensuring that each device in the network can eventually obtain a unique identifier, thereby ensuring the orderly conduct of network communication. This mechanism is automated, which reduces the need for manual configuration and improves the efficiency and reliability of network deployment.
[0070] In some embodiments, after confirming that it is the starting device in the network, the current node device will generate an initial ID from its internal storage or through an algorithm. This ID is unique and is used to identify the current node device in the communication network. Once the initial ID is confirmed, the node device will construct a first ID allocation message. The first ID allocation message contains its own device ID and possible other relevant information, such as network parameters or configuration data. Then, the current node device sends the first ID allocation message to the lower-level node device through its first interface. The sending of the first ID allocation message marks the beginning of the device ID allocation process, ensuring that each device in the network can obtain a unique identifier, thereby maintaining the organizational structure and communication efficiency of the network.
[0071] Step S04: sending a first ID allocation message through the first interface, so that the lower-level node device determines the ID to be allocated obtained from the first ID allocation message as the device ID of the lower-level node device.
[0072] In some embodiments, when an upper-level node device completes its own device ID confirmation, it will send a first ID allocation message containing the ID to be assigned through its first interface, and the first ID allocation message can be recognized and parsed by the lower-level node device. For example, assuming that the current node device in a production line automation system assigns a device ID of "001" to itself after determining that it is the starting device, and then creates a first ID allocation message containing the next available device ID "002", and sends it to the second interface of the lower-level node device through the first interface. After receiving the first ID allocation message, the lower-level node device will read the ID to be assigned "002" in the first ID allocation message and set it as its own device ID. In this way, the lower-level node device has a unique identifier and can be correctly identified and communicated with by other node devices in the system.
[0073] In this embodiment, after the current node device confirms that it is the starting device in the network, it will send the generated first ID allocation message to the lower-level node device using the first interface, that is, the device connected to the current node device and waiting for the ID to be allocated. After receiving the first ID allocation message, the lower-level node device will extract the ID to be allocated from it and set it as its own device ID, thereby establishing a unique identifier in the network to ensure that each node device in the network has a unique ID, which helps to ensure that data can be transmitted between devices accurately and without error, and also facilitates network management and fault diagnosis. This process is automated, which can effectively expand the network and reduce the need for manual configuration.
[0074] Step S05: receiving a second ID allocation message sent by the upper node device through the second interface, and determining the ID to be allocated obtained from the second ID allocation message as the device ID of the current node device.
[0075] In this embodiment, the second ID allocation message is an ID allocation message generated or updated by the upper node device. When the upper node device is a starting device in the network, the second ID allocation message received by the current node device through the second interface is the first ID allocation message generated by the upper node device; when the upper node device is a non-starting device in the network, the second ID allocation message received by the current node device through the second interface is the second ID allocation message obtained after the upper node device updates the second ID allocation message it received.
[0076] In some embodiments, when a node device receives a second startup message sent by an upper node device within a preset time, it will receive the arrival of the second ID allocation message through its second interface and parse the ID to be allocated contained in the second ID allocation message. Subsequently, the current node device will set the ID to be allocated as its own device ID, thereby establishing its own identity in the network.
[0077] In this embodiment, if the node device detects a second startup message sent from an upper-level node device through its second interface within a preset time, it indicates that the current node device is not the starting device in the network, but is subordinate to the upper-level node device, that is, the current node device will receive the second ID allocation message sent by the upper-level node device, and use the ID to be allocated contained in the second ID allocation message as its own device ID, thereby establishing a unique identity in the network to ensure that each device in the network can automatically obtain a unique ID that will not conflict with other devices, thereby maintaining orderly communication and device management of the network. The entire process does not require human intervention, thereby improving the efficiency and reliability of network deployment.
[0078] In some embodiments, in order to optimize the initialization and operation process of the communication network and improve the stability and reliability of the system, communication parameters may be added to the second ID allocation message so that all node devices can exchange data according to a unified communication standard, thereby improving the compatibility and efficiency of the entire network. That is, the second ID allocation message may also include communication parameters; after executing step S05 and receiving the second ID allocation message sent by the upper node device through the second interface, the method may also include:
[0079] Acquire communication parameters from the second ID allocation message;
[0080] Set the current node device according to the communication parameters.
[0081] In this embodiment, the communication parameters may include baud rate, communication protocol, frequency, etc. After receiving the second ID allocation message, the node device will extract the communication parameters from the message and configure its own communication settings accordingly to ensure that all node devices can exchange data according to a unified communication standard, thereby improving the compatibility and efficiency of the entire network; at the same time, the automated parameter configuration reduces the need for manual settings, reduces operational complexity, and improves deployment speed, so that new devices can be quickly integrated into the existing network without complex reconfiguration, thereby enhancing the flexibility and scalability of the network.
[0082] Based on the above technical solution, the present invention realizes a decentralized device identification and communication mechanism, allowing each device in the network to automatically participate in the ID allocation process when receiving a trigger signal, which can reduce the dependence on a single node and improve the flexibility and scalability of the system. By sending and receiving startup messages through the first and second interfaces of the device within a preset time, the node device can intelligently determine whether it is the starting node in the network, and thus independently decide whether to initiate ID allocation or receive the ID allocated by the superior node. This not only simplifies the wiring requirements of the network and avoids additional bus or loop design, but also reduces the possibility of communication conflicts by eliminating the dependence on device delays, ensuring efficient and stable communication between devices.
[0083] Please refer to Figure 3 , which is a flow chart of a second ID allocation method provided by an embodiment of the present invention. Based on the above embodiments, in some embodiments, in order to ensure the correct allocation of device IDs between multi-node devices and enable the network to enter a stable communication state after confirmation, so as to improve the reliability and efficiency of the entire system, the following can also be performed. Figure 3 Steps shown:
[0084] Step S11: for each node device in the multi-node device, when the node device receives a trigger signal, the node device sends a first startup message through the first interface.
[0085] Step S12, detecting whether the second interface receives the second startup message within a preset time.
[0086] If not, execute step S13.
[0087] Step S13: confirm the initial ID as the device ID of the current node device, and generate a first ID allocation message.
[0088] Step S14: Send a first ID allocation message through the first interface.
[0089] Step S15: determining the first allocated ID information according to the device ID of the current node device.
[0090] In this embodiment, the first allocated ID information is the detailed information about the allocated ID recorded after confirming its own device ID when the current node device is the starting device. The first allocated ID information is used to track and confirm how many device IDs have been allocated in the network. For example, if the device ID of the current node device is "001", then the first allocated ID information is determined to be "001" at this time.
[0091] Step S16, sending the first query information through the first interface polling, and receiving the second allocated ID information returned by the lower node device.
[0092] In this embodiment, the first query information is the query information sent by the current node device for querying the second allocated ID information, and the second allocated ID information is the detailed information about the allocated ID recorded by the subordinate node device of the current node device after confirming its own device ID. The second allocated ID information is also used to track and confirm how many device IDs have been allocated in the network, and is used to update the first allocated ID information when it is different from the first allocated ID information. For example, if the device ID of the subordinate node device of the current node device is "002", then the second allocated ID information is determined to be "002" at this time.
[0093] Step S17, determining whether the second allocated ID information is the same as the first allocated ID information.
[0094] If not, execute step S18; if so, execute step S19.
[0095] In this embodiment, when the second allocated ID information is different from the first allocated ID information, it means that the second allocated ID information has been updated, that is, the device ID allocation of the proof node device has not yet been completed and the allocation of the device ID is still continuing. At this time, step S18 is executed to update the first allocated ID information to the second allocated ID information, so that the starting device can obtain the latest allocated ID information in real time.
[0096] In some embodiments, whether the second allocated ID information is updated depends on whether the subsequent node device has allocated a device ID. If the subsequent node device has allocated a device ID, the second allocated ID information will be updated accordingly based on the allocated ID information fed back by the subsequent node device. The update process is the same as the update process of the first allocated ID information, and will not be repeated here.
[0097] Step S18: Update the first allocated ID information to the second allocated ID information.
[0098] In this embodiment, after the first allocated ID information is updated according to the second allocated ID information, the process returns to step S16, continues to send the first query information through the first interface polling, and receives the second allocated ID information returned by the lower node device. When the second allocated ID information is no longer updated, it can be determined that the device ID allocation of all node devices has been completed.
[0099] Step S19, determining whether the number of times the second allocated ID information is received exceeds a threshold;
[0100] If the number of reception times exceeds the threshold, step S110 is executed.
[0101] When the second allocated ID information is the same as the first allocated ID information, the system cannot determine whether the second allocated ID information is not updated due to factors such as network fluctuations, so it is determined whether the number of receptions of the second allocated ID information after the second allocated ID information is the same as the first allocated ID information exceeds the threshold. If it exceeds the threshold, it proves that the second allocated ID information is not updated because a new device ID is not generated, that is, it indicates that the device ID allocation of all node devices in the system has been completed, and step S110 is executed at this time to send an end message through the first interface so that the lower-level node device forwards the end message and enters the data communication state.
[0102] If the number of times the second allocated ID information is received does not exceed the threshold, the system cannot determine whether the second allocated ID information is not updated due to factors such as network fluctuations, and then returns to step S16, continues to send the first query information through the first interface polling, and receives the second allocated ID information returned by the lower node device. Continue to execute step S110 until the number of times the second allocated ID information is received exceeds the threshold.
[0103] Step S110, sending an end message through the first interface, so that the lower-level node device forwards the end message and enters a data communication state.
[0104] Based on the above technical solution, in this embodiment, after the current node device sends the first ID allocation message through its first interface, in order to ensure the correct allocation of the device ID and the synchronization of the network, the current node device will determine the first allocated ID information according to the device ID assigned to it. Then, it will poll and send query information, and receive the second allocated ID information returned by the lower node device through the first interface. By comparing the first and second allocated ID information, the node device can verify the consistency of the ID allocation. If the two are inconsistent, the node device will update its own allocated ID information. If they are consistent, but the number of receptions does not exceed the preset threshold, the node device will continue to poll and query to ensure the accuracy of the information. Once the number of receptions exceeds the threshold, indicating that the current ID allocation has stabilized, the node device will send an end message, triggering the lower node device to forward the message, and announce that the entire network has entered a data communication state to ensure the accuracy of the device ID allocation and the stability of the network. At the same time, by setting the threshold, infinite loop queries are avoided, thereby improving the efficiency and response speed of the network.
[0105] Please refer to Figure 4 , which is a flow chart of a third ID allocation method provided by an embodiment of the present invention. Based on the above embodiments, in some embodiments, in order to ensure the correct configuration and synchronization of each node in the network, thereby improving the stability and efficiency of the entire communication system, the following may also be performed. Figure 4 Steps shown:
[0106] Step S21: for each node device in the multi-node device, when the node device receives a trigger signal, the node device sends a first startup message through the first interface.
[0107] Step S22, detecting whether the second interface receives the second startup message within a preset time.
[0108] If yes, execute step S23.
[0109] Step S23: receiving a second ID allocation message sent by the upper node device through the second interface, and determining the ID to be allocated obtained from the second ID allocation message as the device ID of the current node device.
[0110] In this embodiment, the current node device monitors and waits for the second ID allocation message from the upper node device through the second interface. Once the second ID allocation message is received, the node device extracts the ID to be allocated therefrom and sets it as its own device ID.
[0111] Step S24: updating the ID to be allocated in the second ID allocation message.
[0112] In this embodiment, to ensure the continuity and uniqueness of the device ID in the network, after the current node device obtains an ID to be allocated from the second ID allocation message sent by the upper node, it will set this ID as its own device ID. Subsequently, in order to prepare for the allocation of the next device ID, the current node device will update the ID to be allocated in the second ID allocation message to ensure that the lower node device can obtain a new unique ID that does not conflict with other devices in the network, so as to maintain the ID allocation order and consistency of the entire network, and ensure that each newly added device can successfully obtain a unique identifier, thereby supporting effective network management and communication.
[0113] For example, assuming that the ID to be allocated obtained by the current node device from the second ID allocation message is "002", then the device ID of the current node device is determined to be "002", and the ID to be allocated in the second ID allocation message is updated to "003", so that the ID to be allocated obtained by the lower-level node device from the updated second ID allocation message is "003".
[0114] Step S25: Send the updated second ID allocation message through the first interface.
[0115] In this embodiment, the current node sends the updated second ID allocation message through the first interface to notify the lower-level node device that the current node has successfully allocated an ID and provides an updated ID to be allocated for use by the lower-level node device.
[0116] Step S26: determine the third allocated ID information according to the device ID of the current node device.
[0117] In this embodiment, the third allocated ID information is the detailed information about the allocated ID recorded after confirming its own device ID when the current node device is not the starting device. The third allocated ID information is also used to track and confirm how many device IDs have been allocated in the network. For example, if the device ID of the current node device is "002", then the third allocated ID information is determined to be "002".
[0118] Step S27: sending second query information through the first interface polling.
[0119] In this embodiment, the second query information is query information sent by the current node device for querying the fourth allocated ID information.
[0120] Step S28, determining whether the fourth allocated ID information returned by the subordinate node device of the current node device is received.
[0121] If yes, execute step S29.
[0122] In this embodiment, the fourth allocated ID information is the detailed information about the allocated ID recorded by the subordinate node device of the current node device after confirming its own device ID. If the fourth allocated ID information returned by the subordinate node device of the current node device is received, it proves that the current node device has a subordinate node device. At this time, the third allocated ID information is updated according to the fourth allocated ID information to ensure that the third allocated ID information stored in the current node device is the latest allocated ID information.
[0123] When the fourth allocated ID information returned by the subordinate node device of the current node device is not received, it proves that the current node device has no subordinate node device, and no operation is required at this time.
[0124] Step S29: Update the third allocated ID information to the fourth allocated ID information.
[0125] Step S210: When receiving the third query information sent by the upper node device through the second interface, the updated third allocated ID information is sent to the upper node device through the second interface.
[0126] In this embodiment, the third query information is query information sent by the upper node device for querying the third allocated ID information. When the current node device receives the third query information, it sends the updated third allocated ID information to the upper node device through the second interface to ensure that the allocated ID information queried by the upper node device is the latest allocated ID information, thereby facilitating the starting device to confirm whether the allocation of the device ID is completed based on whether the allocated ID information is updated.
[0127] Step S211, when receiving an end message sent by an upper node device through the second interface, controlling the current node device to enter a data communication state, and sending an end message through the first interface.
[0128] In this embodiment, the current node device receives an end message from the upper node through the second interface, which marks the end of the device ID allocation process. At this time, the current node device will perform a state transition and enter a state ready for data communication. At the same time, in order to ensure that all relevant devices in the network are aware of the completion of the ID allocation process, the current node device will also forward the end message through the first interface. The reason for doing this is to ensure synchronization and consistency in the network, so that all devices can recognize the end of ID allocation at the same time point and start subsequent data communication processes. This step is crucial to ensure the orderly operation of the network and coordination between devices.
[0129] Based on the above technical scheme, the embodiment of the present invention ensures the accurate allocation and update of the device ID through a series of refined steps, and improves the synchronization and reliability of the network. First, by updating and resending the second ID allocation message, the real-time and accuracy of the ID to be allocated are ensured. Then, by polling to send query information and receiving the allocated ID information of the lower-level node device, the dynamic tracking and verification of the ID status of the entire network device is realized. In addition, when the query information of the upper-level node is received, the latest allocated ID information can be fed back in time, further strengthening the communication and coordination between the levels. Finally, by receiving the end message and controlling the node device to enter the data communication state, it marks the smooth completion of the entire ID allocation process, laying a solid foundation for the stable operation of the network and efficient data transmission. These measures work together to optimize the scalability and maintainability of the network, reduce communication failures caused by ID conflicts or incorrect allocations, and improve the intelligence level of the entire system and the user's operating experience.
[0130] An embodiment of the present invention provides a system for ID allocation, the system comprising at least two node devices, wherein:
[0131] Each of the node devices has a first interface and a second interface;
[0132] For each of the node devices in the multi-node device, the second interface of the node device is connected to the first interface of the upper node device, and the first interface of the node device is connected to the second interface of the lower node device;
[0133] The node device is used to send a first startup message through the first interface when receiving a trigger signal; detect whether the second interface receives a second startup message within a preset time; the second startup message is the first startup message sent by the upper-level node device; if not, confirm the initial ID as the device ID of the current node device, and generate a first ID allocation message; send the first ID allocation message through the first interface, so that the lower-level node device determines the ID to be allocated obtained from the first ID allocation message as the device ID of the lower-level node device; if so, receive the second ID allocation message sent by the upper-level node device through the second interface, and determine the ID to be allocated obtained from the second ID allocation message as the device ID of the current node device.
[0134] Based on the above embodiment, in some embodiments, after sending the first ID allocation message through the first interface, the node device is further used to:
[0135] Determine the first allocated ID information according to the device ID of the current node device;
[0136] Sending first query information through the first interface polling, and receiving second allocated ID information returned by the lower node device;
[0137] Determining whether the second allocated ID information is the same as the first allocated ID information;
[0138] If not, the first allocated ID information is updated to the second allocated ID information, and the step of returning to execute the step of sending the first query information through the first interface polling and receiving the second allocated ID information returned by the lower node device;
[0139] If so, determining whether the number of times the second allocated ID information is received exceeds a threshold;
[0140] If the number of receptions does not exceed the threshold, returning to the step of sending the first query information through the first interface polling and receiving the second allocated ID information returned by the lower node device;
[0141] If the number of receptions exceeds the threshold, an end message is sent through the first interface, so that the lower-level node device forwards the end message and enters a data communication state.
[0142] Based on the above embodiment, in some embodiments, after determining the ID to be allocated obtained from the second ID allocation message as the device ID of the current node device, the node device is further used to:
[0143] Updating the ID to be allocated in the second ID allocation message;
[0144] The updated second ID allocation message is sent through the first interface.
[0145] Based on the above embodiment, in some embodiments, after sending the updated second ID allocation message through the first interface, the node device is further used to:
[0146] Determine the third allocated ID information according to the device ID of the current node device;
[0147] Sending second query information through the first interface polling;
[0148] Determine whether the fourth allocated ID information returned by the subordinate node device of the current node device is received;
[0149] If yes, then updating the third allocated ID information to the fourth allocated ID information;
[0150] When the third query information sent by the upper node device is received through the second interface, the updated third allocated ID information is sent to the upper node device through the second interface.
[0151] Based on the above embodiment, in some embodiments, after sending the updated third allocated ID information to the upper-level node device through the second interface, the node device is further used to:
[0152] When receiving the end message sent by the upper node device through the second interface, the current node device is controlled to enter the data communication state, and the end message is sent through the first interface.
[0153] Based on the above embodiment, in some embodiments, the second ID allocation message also includes communication parameters;
[0154] After receiving the second ID allocation message sent by the upper node device through the second interface, the node device is further used to:
[0155] Acquire communication parameters from the second ID allocation message;
[0156] Set the current node device according to the communication parameters.
[0157] An embodiment of the present invention provides a node device, including a processor and a memory, the memory is used to store at least one instruction, and when the instruction is loaded and executed by the processor, the above-mentioned ID allocation method is implemented. Its execution method and beneficial effects are similar and will not be repeated here.
[0158] An embodiment of the present invention provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the above-mentioned ID allocation method is implemented. Its execution method and beneficial effects are similar and will not be repeated here.
[0159] It should be noted that although the above describes the various steps in a specific order, it does not mean that the various steps must be executed in the above specific order. In fact, some of these steps can be executed concurrently or even in a different order as long as the required functions can be achieved.
[0160] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A method for ID allocation, characterized in that: include: For each of the node devices in the multi-node device, when the node device receives a trigger signal, the node device sends a first startup message through the first interface; Detecting whether the second interface receives a second startup message within a preset time; the second startup message is the first startup message sent by the upper node device; If not, the initial ID is confirmed as the device ID of the current node device, and a first ID allocation message is generated; Sending the first ID allocation message through the first interface, so that the lower-level node device determines the ID to be allocated obtained from the first ID allocation message as the device ID of the lower-level node device; If so, a second ID allocation message sent by the upper node device is received through the second interface, and the ID to be allocated obtained from the second ID allocation message is determined as the device ID of the current node device.
2. The method according to claim 1, characterized in that After sending the first ID allocation message through the first interface, the method further includes: Determine the first allocated ID information according to the device ID of the current node device; Sending first query information through the first interface polling, and receiving second allocated ID information returned by the lower-level node device; Determining whether the second allocated ID information is the same as the first allocated ID information; If not, the first allocated ID information is updated to the second allocated ID information, and the step of sending the first query information through the first interface polling and receiving the second allocated ID information returned by the lower node device is returned; If yes, determining whether the number of times the second allocated ID information is received exceeds a threshold; If the number of receptions does not exceed the threshold, returning to the step of sending the first query information through the first interface polling and receiving the second allocated ID information returned by the lower-level node device; If the number of receptions exceeds a threshold, an end message is sent through the first interface, so that the lower-level node device forwards the end message and enters a data communication state.
3. The method according to claim 1, characterized in that After determining the ID to be allocated obtained from the second ID allocation message as the device ID of the current node device, the method further includes: Updating the ID to be allocated in the second ID allocation message; The updated second ID allocation message is sent through the first interface.
4. The method according to claim 3, characterized in that After sending the updated second ID allocation message through the first interface, the method further includes: Determine the third allocated ID information according to the device ID of the current node device; Sending second query information through the first interface polling; Determine whether the fourth allocated ID information returned by the subordinate node device of the current node device is received; If yes, updating the third allocated ID information to the fourth allocated ID information; When the third query information sent by the upper node device is received through the second interface, the updated third allocated ID information is sent to the upper node device through the second interface.
5. The method according to claim 4, characterized in that After sending the updated third allocated ID information to the upper-level node device through the second interface, the method further includes: When the end message sent by the upper node device is received through the second interface, the current node device is controlled to enter the data communication state, and the end message is sent through the first interface.
6. The method according to claim 1, characterized in that The second ID allocation message also includes communication parameters; After receiving the second ID allocation message sent by the upper node device through the second interface, the method further includes: Acquire the communication parameters from the second ID allocation message; The current node device is set according to the communication parameters.
7. A system for ID allocation, characterized in that: The system comprises at least two node devices, wherein: Each of the node devices has a first interface and a second interface; For each of the node devices in the multi-node device, the second interface of the node device is connected to the first interface of the upper node device, and the first interface of the node device is connected to the second interface of the lower node device; The node device is used to send a first startup message through the first interface when receiving a trigger signal; detect whether the second interface receives a second startup message within a preset time; the second startup message is the first startup message sent by the upper-level node device; if not, confirm the initial ID as the device ID of the current node device, and generate a first ID allocation message; send the first ID allocation message through the first interface, so that the lower-level node device determines the ID to be allocated obtained from the first ID allocation message as the device ID of the lower-level node device; if so, receive the second ID allocation message sent by the upper-level node device through the second interface, and determine the ID to be allocated obtained from the second ID allocation message as the device ID of the current node device.
8. A node device, characterized in that: include: A processor and a memory, wherein the memory is used to store at least one instruction, and when the instruction is loaded and executed by the processor, the method for ID allocation as described in any one of claims 1 to 6 is implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method for allocating IDs as described in any one of claims 1 to 6 is implemented.