A network address allocation method and apparatus

The message of assigned addresses and the slave selection confirmation mechanism of the master device broadcasts the master device, which solves the problem of slave address conflict in the Modbus protocol, simplifies the construction process and reduces the deployment cost.

CN113395366BActive Publication Date: 2025-08-05HUAWEI TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202010176511.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-03-13
Publication Date
2025-08-05
Estimated Expiration
2040-03-13

AI Technical Summary

Technical Problem

In the master-slave network architecture of the Modbus protocol, the existing technology cannot effectively solve the problem of network address allocation conflicts of slave devices, resulting in increased construction complexity and increased deployment costs.

Method used

The master device periodically broadcasts messages including assigned network addresses. The slave device selects unassigned network addresses based on the address list in the message, and confirms the allocation by confirming the message. The master device allocates an identifier to the slave device to identify the assigned state.

Benefits of technology

Through the periodic broadcast of the master device and the slave device selection confirmation mechanism, conflicts in the slave device network address are avoided, construction process is simplified, and deployment costs are reduced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113395366B_ABST
    Figure CN113395366B_ABST
Patent Text Reader

Abstract

The embodiment of the present application discloses a network address allocation method and device, specifically, a master device broadcasts a first message to a slave device, the first message includes an address list, and the address list includes N allocated network addresses. For a newly added slave device, after receiving the first message, it determines the unallocated first network address based on the address list in the first message, and sends the first network address to the master device through a second message. After receiving the second message, the master device confirms that the first network address can be allocated, and sends a third message to the slave device so that the slave device confirms the allocated first network address based on the third message. It can be seen that through the allocation method provided by the implementation of the present application, when the slave device selects a network address, it can determine the unallocated network address based on the address list sent by the master device, thereby avoiding the problem of conflicts in the allocated network addresses.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of communication technology, and in particular to a method and device for allocating network addresses. Background Art

[0002] The Modbus protocol is a serial communication protocol primarily used in master / slave network architectures. In a master / slave architecture, one node is designated as the master, while other nodes that communicate using the Modbus protocol are designated as slaves. Each slave node is configured with a unique address. The master sends a request message to the slave device with which it wishes to communicate. After receiving the request message, the slave device sends a response message containing the slave device's address, allowing the master to determine the responding slave device. However, the current method of allocating addresses between master and slave nodes fails to resolve address conflicts. Summary of the Invention

[0003] The embodiments of the present application provide a network address allocation method and apparatus, which help to avoid address conflicts of slave devices.

[0004] In the first aspect, an embodiment of the present application provides a network address allocation method, which can be executed by a master device, wherein the master device broadcasts a first message, wherein the first message includes an address list, and the address list includes N allocated network addresses, where N is an integer greater than or equal to 1. For a newly added slave device, after it receives the first message, it uses an unassigned network address as the first network address according to the address list in the first message, and sends a second message including the first network address to the master device. After receiving the second message sent by the slave device, the master device can learn the first network address selected by the slave device according to the second message, and send a third message to the slave device to confirm the first network address allocated to the slave device using the third message. It can be seen that, by utilizing the technical solution in the embodiment of the present application, when the slave device selects a network address, it can determine the unassigned network address according to the address list sent by the master device, thereby avoiding the problem of conflicts in the network addresses allocated by the master device to the slave device.

[0005] In one possible implementation, before sending the third message, the master device may confirm, based on the first network address and the address list in the second message, that the first network address is unassigned, thereby allocating the first network address to the slave device. Furthermore, the master device may also assign a corresponding identifier to the first network address. The master device generates the third message based on the first network address and the corresponding identifier.

[0006] In one possible implementation, to indicate that a network address has been allocated, the master device may further configure a corresponding identifier for the allocated network address, thereby using this identifier to indicate that the network address has been allocated. Specifically, the third message includes the first network address and an identifier corresponding to the first network address, with the identifier corresponding to the first network address being used to indicate that the first network address has been allocated. Upon receiving the third message, the slave device can not only confirm the allocated first network address but also obtain the identifier corresponding to the first network address.

[0007] In one possible implementation, when corresponding identifiers are configured for allocated network addresses, the N allocated network addresses include N network addresses and N identifiers, wherein a network address in the N network addresses corresponds one-to-one to an identifier in the N identifiers, and an identifier corresponding to a network address in the N network addresses is used to identify that the corresponding network address has been allocated. That is, each network address in the N allocated network addresses corresponds to an identifier.

[0008] In a possible implementation, in order for the slave device to know the master device that allocates the network address to it, the first message may further include an identifier of the master device, where the identifier of the master device is used to identify the master device that broadcasts the N allocated network addresses.

[0009] In one possible implementation, the third message further includes an identifier of the master device, which is used to identify the master device that assigned the first network address. When the slave device receives the third message, it can determine the master device that assigned the first network address based on the identifier of the master device.

[0010] In one possible implementation, before broadcasting the first message, the master device pre-acquires an address list. Specifically, the master device broadcasts a fourth message, which is used to query for assigned network addresses. The master device then obtains N assigned network addresses from N slave devices, where each slave device in the N slave devices corresponds one-to-one to an assigned network address in the N assigned network addresses. The master device then obtains an address list based on the N assigned network addresses. In this implementation, the master device can obtain the network addresses assigned to each slave device that currently has an assigned network address by broadcasting the fourth message, thereby obtaining an address list based on the network addresses assigned to each slave device.

[0011] In one possible implementation, when the master device can configure a corresponding identifier for the assigned network address, when the master device obtains the network addresses assigned to each of the N slave devices, the master device can also send an identifier corresponding to the network address assigned to any of the N slave devices, wherein the identifier corresponding to the network address of any slave device is used to identify that the network address of the slave device is assigned.

[0012] In the second aspect, an embodiment of the present application provides a network address allocation method, which is executed by a slave device, specifically, the slave device receives a first message broadcast by a master device, the first message including an address list, the address list including N allocated network addresses, wherein N is an integer greater than or equal to 1. The slave device determines an unallocated network address based on the address list, and uses one of the unallocated network addresses as the first network address. The slave device sends a second message including the first network address to the master device, so that the master device can obtain the first network address determined by the slave device, and sends a third message to the slave device. The slave device confirms that the master device allocates the first network address to it based on the third message sent by the master device. It can be seen that, using the technical solution in the embodiment of the present application, when selecting a network address, the slave device can determine the unallocated network address based on the address list sent by the master device, thereby avoiding the problem of conflict between the network addresses allocated by the master device to the slave device.

[0013] In one possible implementation, to indicate that a network address has been allocated, the master device may further configure a corresponding identifier for the allocated network address, thereby using the identifier to confirm that the network address has been allocated. Specifically, the third message includes the first network address and an identifier corresponding to the first network address, where the identifier corresponding to the first network address is used to indicate that the first network address has been allocated.

[0014] In a possible implementation, after receiving the third message, the slave device may store the first network address and the identifier corresponding to the first network address in the third message.

[0015] In one possible implementation, when corresponding identifiers are configured for allocated network addresses, the N allocated network addresses include N network addresses and N identifiers, wherein one of the N network addresses corresponds to one of the N identifiers, and the identifier corresponding to one of the N network addresses is used to identify that the network address corresponding to it is allocated.

[0016] In one possible implementation, the slave device may determine the first network address according to the following two methods: one is that the slave device obtains the first network address that is not included in the N allocated network addresses according to the address list, wherein the N allocated network addresses do not include an identifier corresponding to the first network address. When the N allocated network addresses include N network addresses and N identifiers, when the slave device determines the first network address according to the address list, the identifier corresponding to the determined first network address does not exist in the N allocated network addresses, thereby ensuring that the determined first network address is an unallocated network address. Another is that the first message also includes the identifier of the master device. When the slave device determines that the N allocated network addresses include the second network address of the slave device and the identifier corresponding to the second network address, and the identifier of the master device is different from the identifier of the master device corresponding to the second network address, the slave device obtains the first network address that is not included in the N allocated network addresses according to the address list. That is, when the newly added slave device itself stores the second network address and the identifier corresponding to the second network address, the slave device determines, based on the address list, that the N allocated network addresses include the second network address and the identifier corresponding to the second network address stored in itself, but the identifier of the master device that allocates the second network address is different from the identifier of the master device in the first message, indicating that the second network address has been allocated, and then determines, based on the address list, an unallocated network address as the first network address.

[0017] In one possible implementation, the slave device can determine the first network address in the following two ways: one is that the slave device selects a network address as the first network address based on the first random number and the address list, where the first network address is not included in the N allocated network addresses. That is, when determining the first network address, the slave device uses the first random number. This implementation can be applied to a scenario where multiple slave devices determine their respective network addresses based on the address list. Each slave device selects a network address from the unallocated network addresses as the first network address using its corresponding different random number. By utilizing the randomness of the random number, conflicts among the network addresses determined by multiple slave devices are avoided.

[0018] Another method is to select a network address that is not included in the N allocated network addresses based on the first random number and the address list, when the first message also includes the identifier of the master device, and when the slave device determines that the N allocated network addresses include the second network address of the slave device and the identifier corresponding to the second network address, and the identifier of the master device included in the first message is different from the identifier of the master device corresponding to the second network address, the slave device selects a network address as the first network address based on the first random number and the address list, where the first network address is not included in the N allocated network addresses. In other words, when a newly added slave device stores the second network address and the identifier corresponding to the second network address, the slave device determines based on the address list that the N allocated network addresses include the second network address and the identifier corresponding to the second network address stored in the slave device, but the identifier of the master device that allocated the second network address is different from the identifier of the master device in the first message, indicating that the second network address has been allocated. The slave device then determines an unallocated network address as the first network address based on the first random number and the address list. This implementation method can be applied to scenarios where there are multiple slave devices that determine their respective network addresses based on an address list. Each slave device selects an unassigned network address as the first network address by using its corresponding different random number. By utilizing the randomness of the random number, the problem of conflicts among the network addresses determined by multiple slave devices is avoided.

[0019] In one possible implementation, when a slave device sends a second message to a master device, it can also determine a sending time based on a second random number, and then send the second message to the master device based on the sending time. This implementation can be applied to scenarios where multiple slave devices need to send messages to a master device. Given the limited processing power of the master device, to reduce the load on the master device, each slave device can determine the sending time of its message based on its corresponding random number, thereby preventing multiple slave devices from sending messages to the master device simultaneously.

[0020] In a third aspect, an embodiment of the present application provides a network address allocation device, which is provided in a master device and includes: a broadcast unit, a first receiving unit, and a first sending unit. The broadcast unit is configured to broadcast a first message, wherein the first message includes an address list, wherein the address list includes N allocated network addresses, where N is an integer greater than or equal to 1; the first receiving unit is configured to receive a second message sent by a slave device, wherein the second message includes a first network address, wherein the first network address is an unallocated address determined according to the address list; and the first sending unit is configured to send a third message to the slave device, wherein the third message is configured to confirm the allocation of the first network address.

[0021] In one possible implementation, the apparatus further includes: a confirmation unit and an allocation unit. The confirmation unit is configured to confirm, based on the first network address in the second message and the address list, that the first network address is an unallocated network address, so as to allocate the first network address to the slave device; and the allocation unit is configured to allocate a corresponding identifier to the first network address.

[0022] In a possible implementation, the device further includes a generating unit configured to generate a third message according to the first network address and an identifier corresponding to the first network address.

[0023] In a possible implementation, the third message includes the first network address and an identifier corresponding to the first network address, and the identifier corresponding to the first network address is used to identify that the first network address is allocated.

[0024] In one possible implementation, the N allocated network addresses include N network addresses and N identifiers, the network addresses in the N network addresses correspond one-to-one to the identifiers in the N identifiers, and the identifier corresponding to one of the N network addresses is used to identify that the network address corresponding to it is allocated.

[0025] In a possible implementation, the first message further includes an identifier of the master device, where the identifier of the master device is used to identify the master device that broadcasts the N allocated network addresses.

[0026] In a possible implementation, the third message further includes an identifier of the master device, where the identifier of the master device is used to identify the master device that allocates the first network address.

[0027] In one possible implementation, the apparatus further includes: a first acquisition unit and a second acquisition unit. The broadcast unit is further configured to broadcast a fourth message before broadcasting the first message, the fourth message being used to query the allocated network addresses; the first acquisition unit is configured to acquire the N allocated network addresses from N slave devices, wherein a slave device in the N slave devices corresponds one-to-one to an allocated network address in the N allocated network addresses; and the second acquisition unit is configured to acquire the address list based on the N allocated network addresses.

[0028] In a possible implementation, the apparatus further includes: a second sending unit configured to send, to any slave device among the N slave devices, an identifier corresponding to the network address allocated to the any slave device.

[0029] In a fourth aspect, an embodiment of the present application provides a network address allocation device, which is provided in a slave device and includes: a second receiving unit, a determining unit, a third sending unit, and a third receiving unit. The second receiving unit is configured to receive a first broadcast message, wherein the first message includes an address list, wherein the address list includes N allocated network addresses, where N is an integer greater than or equal to 1; the determining unit is configured to determine a first network address based on the address list, wherein the first network address is an unallocated address determined based on the address list; the third sending unit is configured to send a second message to the master device, wherein the second message includes the first network address; and the third receiving unit is configured to receive a third message sent by the master device, wherein the third message is configured to confirm the allocation of the first network address.

[0030] In a possible implementation, the third message includes the first network address and an identifier corresponding to the first network address, and the identifier corresponding to the first network address is used to identify that the first network address is allocated.

[0031] In a possible implementation manner, the device may further include a storage unit configured to store the first network address in the third message and an identifier corresponding to the first network address.

[0032] In one possible implementation, the N allocated network addresses include N network addresses and N identifiers, one of the N network addresses corresponds to one of the N identifiers, and the identifier corresponding to one of the N network addresses is used to identify that the network address corresponding to it is allocated.

[0033] In one possible implementation, the determination unit is specifically configured to obtain, based on the address list, a first network address that is not included in the N allocated network addresses, and the N allocated network addresses do not include an identifier corresponding to the first network address; or, the first message also includes an identifier of the master device, and the determination unit is specifically configured to, when it is determined that the N allocated network addresses include the second network address of the slave device and an identifier corresponding to the second network address, and the identifier of the master device is different from the identifier of the master device corresponding to the second network address, select a network address as the first network address based on a first random number and the address list, and the first network address is not included in the N allocated network addresses.

[0034] In a possible implementation, the determination unit is specifically configured to select a network address as the first network address based on a first random number and the address list, where the first network address is not included in the N allocated network addresses; or, the first message further includes an identifier of the master device, and the determination unit is specifically configured to select a network address as the first network address based on the first random number and the address list when it is determined that the N allocated network addresses include the second network address of the slave device and an identifier corresponding to the second network address, and the identifier of the master device is different from the identifier of the master device corresponding to the second network address, where the first network address is not included in the N allocated network addresses.

[0035] In a possible implementation, the third sending unit includes: a determining subunit and a sending subunit. The determining subunit is configured to determine a sending time according to a second random number; and the sending subunit is configured to send the second message to the master device according to the sending time.

[0036] In an embodiment of the present application, a master device broadcasts a first message to its slave device, wherein the first message includes an address list, and the address list includes N allocated network addresses, so that the slave device can determine which network addresses are not allocated based on the address list in the first message. For a newly added slave device, after receiving the first message, it determines the unallocated first network address based on the address list in the first message, and sends the first network address to the master device through a second message. After receiving the second message, the master device can obtain the first network address selected by the slave device through the second message, and send a third message to the slave device so that the slave device confirms the allocated first network address based on the third message. It can be seen that through the network address allocation method provided by the present application, when selecting a network address, the slave device can determine the unallocated network address based on the address list sent by the master device, thereby avoiding the problem of conflicts in the network addresses allocated by the slave device. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments recorded in this application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0038] Figure 1 A schematic diagram of an application scenario provided in an embodiment of the present application;

[0039] Figure 2 A network address allocation signaling interaction diagram provided in an embodiment of the present application;

[0040] Figure 3 Another network address allocation signaling interaction diagram provided in an embodiment of the present application;

[0041] Figure 4 Another network address allocation signaling interaction diagram provided in an embodiment of the present application;

[0042] Figure 5 A schematic diagram of an application scenario provided in an embodiment of the present application;

[0043] Figure 6 A schematic diagram of the structure of a network address allocation device provided in an embodiment of the present application;

[0044] Figure 7 A schematic diagram of the structure of another network address allocation device provided in an embodiment of the present application;

[0045] Figure 8 A schematic diagram of the structure of a network device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0046] The embodiments of the present application provide a network address allocation method and apparatus for resolving the problem of slave device address conflicts.

[0047] Typically, to avoid conflicts in the network addresses assigned to slave devices in a deployed master / slave network architecture, two main methods are used for address allocation: one is to pre-write the network address before the device leaves the factory to avoid address conflicts between different slave devices. When using devices from different manufacturers to build a network topology, conflicts may arise between the pre-written network addresses of multiple slave devices. The other method is for the manufacturer to open the address writing interface of the device, and the system integrator to assign addresses to each slave device on-site by writing the address, thereby ensuring that the addresses do not conflict. However, in actual applications, on-site construction conditions may not be available, and the address writing system needs to be carried separately, which increases the construction and deployment links and deployment costs. Moreover, when the system encounters new terminal expansion and access, in addition to the terminal manufacturer, relevant support personnel are also required to provide simultaneous support and ensure the consistency of the address allocation before and after, which increases the complexity of construction.

[0048] In order to realize automatic allocation of network addresses under the Modbus protocol and avoid the problem of address conflicts, an embodiment of the present application provides a network address allocation method, wherein the master device controls the resources and address allocation authority of all addresses, and periodically broadcasts a first message so that each newly added slave device can know which network addresses have been allocated through the address list in the first message, and then select an unallocated network address, thereby ensuring that there is no conflict in the network addresses allocated by the master device to the slave device.

[0049] See also Figure 1 , which is a schematic diagram of an application scenario provided in an embodiment of the present application.

[0050] exist Figure 1 The network topology B shown includes a master device 100, a slave device 201 and a slave device 202. The slave device 201 is Figure 1 The network topology B shown already includes slave devices. Slave device 202 is a newly added Figure 1 The master device 100 is a slave device of the network topology B shown in FIG. Figure 1 In the network topology B shown, the slave device 201 is assigned a network address a1, and the address list obtained by the master device 100 includes the network address a1 of the slave device 201. The master device 100 periodically broadcasts a first message, which includes the address list. After receiving the first message, the slave device 201 can determine that it does not need to obtain a network address from the master device again based on the address list and the network address a1 stored in itself, and may not respond to the first message from the master device 100. Figure 1 The slave device 202 of the network topology B shown in FIG. 1 can obtain the addresses that are not received by the master device 100 according to the address list broadcast by the master device 100. Figure 1 The network address used by the slave device in the network topology B shown is the first network address. Slave device 202 sends the first network address to master device 100. Master device 100 sends a third message to slave device 202 to confirm the assignment of the first network address to slave device 202, thereby ensuring that the assigned network addresses do not conflict with each other.

[0051] See also Figure 2 , This figure is a network address allocation signaling interaction diagram provided by the embodiment of the present application. Figure 1 and Figure 2 , the method provided in the embodiment of the present application is described.

[0052] S201: The master device broadcasts a first message.

[0053] For example, a master device may periodically broadcast a first message in the network topology to which it belongs, the first message including an address list including N allocated network addresses, where N is an integer greater than or equal to 1. By periodically broadcasting the first message, the master device enables slave devices in the network topology to which the master device belongs to learn of the allocated network addresses, thereby avoiding address conflicts between the network address selected by a slave device newly added to the network topology and the network addresses of slave devices included in the network topology to which it belongs.

[0054] For example, the format of the first message follows the message format specified by the Modbus protocol. The message in the Modbus protocol may include fields such as an address field, a function code, data, and an error check. Among them, the address field is used for addressing. When the network address carried by the address field of a message is 0, the message is a broadcast message. When the network address carried by the address field of a message is a non-zero value, such as a specific network address, the message is a unicast message. The unicast message will be sent to the slave device corresponding to the network address in the address field. The address field can also be called an address field. The function code is used to indicate the operation to be performed. The function code is expressed in hexadecimal. For example, a function code of 0x06 indicates writing a single register. A function code of 0x10 indicates writing multiple holding registers. A function code of 0x03 indicates reading a holding register, where a holding register is a register that can be read or written.

[0055] In a specific implementation, in order to enable the master device to query the network address assigned to each slave device, a new function code, namely the address query function code, is added. The hexadecimal corresponding to the address query function code can be selected from the currently reserved hexadecimals. For example, a hexadecimal is selected from the currently reserved hexadecimals 0x16 to 0x40 as the address query function code. Specifically, when the master device queries the network address assigned to the slave device, the function code field in the fourth message it broadcasts is the address query function code. After receiving the fourth message, the slave device identifies the address query function code by parsing the fourth message and sends its own assigned network address to the master device. In other words, the master device can obtain the network address of each slave device in the current network topology by broadcasting the fourth message with the query function code.

[0056] For example, before the master device broadcasts the first message, the master device broadcasts the fourth message, which is used to query the allocated network address; the master device obtains N allocated network addresses from N slave devices, and the slave devices in the N slave devices correspond one-to-one to the allocated network addresses in the N allocated network addresses. For example, the N slave devices include a first slave device and a second slave device, and the N allocated network addresses include the network address assigned to the first slave device and the network address assigned to the second slave device; the master device obtains an address list based on the N allocated network addresses, that is, the master device adds the network addresses corresponding to the N slave devices obtained to the address list.

[0057] S202: The slave device determines a first network address according to the address list, where the first network address is an unassigned address determined according to the address list.

[0058] For example, the slave device determines an unassigned network address based on the address list in the first message and uses it as the first network address. In this embodiment, the slave device that determines the first network address based on the address list is a slave device that has newly joined the network topology. The slave device can determine the first network address according to a pre-set rule, for example, the first network address among the unassigned network addresses is determined as the first network address; or the first network address can be selected from the unassigned network addresses using a first random number. The address list in the embodiment of the present application may also include multiple unassigned addresses. The slave device selects a network address that matches the first random number as the first network address based on the first random number and the address list, which helps to reduce the probability of address conflicts with other slave devices. The network address that matches the first random number can be the order of the network address selected by the first random number in the unassigned network addresses (the unassigned network addresses included in the address list).

[0059] S203: The slave device sends a second message to the master device, where the second message includes the first network address.

[0060] For example, the slave device generates a second message according to the first network address, the second message including the first network address, and sends the second message to the master device.

[0061] exist Figure 1 In the illustrated scenario, if network topology B includes multiple newly joined slave devices, each of these newly joined slave devices sends its selected network address to the master device. The multiple newly joined slave devices include slave device 202, which can use the second random number to determine the time to send its selected network address. Slave device 202 sends its selected network address to master device 100 based on the determined sending time, thereby improving processing efficiency of master device 100.

[0062] S204: The master device sends a third message to the slave device, where the third message is used to confirm the allocated first network address.

[0063] For example, if the master device confirms that the first network address of the second message can be assigned to the slave device, it sends a third message to the slave device. The destination address of the third message is the first network address. The third message also includes an identifier that matches the first network address.

[0064] For example, a method for obtaining a first network address from a newly added device in a network topology may include the following three scenarios:

[0065] In the first scenario, the slave device newly added to the network topology does not store or configure any network address. Figure 1 After the network topology B is shown, the first network address is determined according to the address list.

[0066] In the second scenario, a slave device newly added to the network topology is configured with an initialized network address, i.e., the second network address, after initialization. The slave device determines whether the second network address has been adopted by other slave devices based on the address list included in the first message. If the second network address has not been adopted by other slave devices, the slave device uses the second network address as the first network address. If the second network address has been allocated, the slave device determines the first network address based on the address list. Specifically, when the slave device determines whether the second network address has been allocated, it can determine whether the second network address exists in the address list. If not, it indicates that the second network address has not been allocated. If the second network address exists in the address list, it only indicates that the second network address has been allocated, so it is impossible to confirm whether the second network address has been allocated to the slave device or to other slave devices.

[0067] Based on this, the master device can configure a corresponding identifier for each allocated network address. The identifier corresponding to the network address is used to identify that the corresponding network address has been allocated. Specifically, when the master device obtains the address list, the master device sends the identifier corresponding to the network address allocated to any of the N slave devices to the slave device. For the N allocated network addresses included in the address list, the N allocated network addresses include N network addresses and N identifiers. The network addresses in the N network addresses correspond one-to-one with the identifiers in the N identifiers. The identifier corresponding to one of the N network addresses is used to identify that the corresponding network address has been allocated. The identifier can be a serial number, a sequence code, or other information that can be used to identify the allocation of a network address, which is not limited in the implementation of this application. For example, the master device 100 obtains the network address a2 selected by the slave device 202 and assigns the corresponding identifier b2 to the network address a2. The master device 100 sends the network address a2 and the identifier b2 to the slave device 202, so that the slave device 202 confirms that it has been allocated the network address a2 based on the identifier b2 and stores the identifier b2.

[0068] Based on the second scenario, the slave device determines the first network address according to the address list as follows: after the slave device receives the first message, it determines whether the second network address exists in the address list. If the second network address exists in the address list but the slave device does not store an identifier corresponding to the second network address, it indicates that the second network address has been allocated to other slave devices in the current network topology. The newly added slave device determines the first network address according to the address list. Specifically, the slave device can determine the first network address in the following ways: one is that the slave device obtains a first network address that is not included in the N allocated network addresses according to the address list, and the N allocated network addresses do not include an identifier corresponding to the first network address; the other is that the slave device selects a network address as the first network address according to the first random number and the address list, and the first network address is not included in the N allocated network addresses. If the second network address does not exist in the address list, it indicates that the second network address is not allocated, and it is used as the first network address.

[0069] The third scenario is that the new network topology ( Figure 1 The slave device of the network topology B shown is a slave device that is transferred from other network topologies to this network topology. The slave device newly added to the network topology stores the network address obtained from other network topologies, the identifier corresponding to its network address, and the identifier of the master device (the master device in the other network topology) that assigned the network address. If the network address obtained from other network topologies and the identifier corresponding to its network address stored by the slave device newly added to the network topology are included in the N allocated network addresses in the address list, the slave device newly added to the network topology structure believes that there is no address conflict, but in fact it is not the network address and the identifier corresponding to its network address assigned to it by the master device in the newly added network topology. For example, slave device 202 was originally deployed in network topology A, and it was assigned network address a1 and the network address a1 corresponds to identifier b1. At this time, due to business needs, slave device 202 will be deployed in network topology B, and slave device 201 in network topology B has been assigned network address a1 and the identifier b1 corresponding to the network address a1. The address list broadcast by the master device 100 in network topology B includes network address a1 and identifier b1. Slave device 202, added to network topology B, determines not to select a new network address based on the address list, network address a1, and identifier b1. However, an address conflict exists between slave device 201 and slave device 202. Both network topologies A and B have a master / slave network structure. Network topologies A and B are physically separated. The address pool corresponding to network topology A and the address pool corresponding to network topology B can be completely identical or partially identical. In other words, the multiple network addresses that can be assigned by the master device in network topology A and the multiple network addresses that can be assigned by the master device in network topology B share the same network address.

[0070] In the third scenario, when assigning a network address to a slave device, the master device sends its own identifier to the slave device, so that the slave device can determine the master device that assigned the network address based on the master device's identifier. When the slave device determines that its network address and the identifier corresponding to the network address are included in the address list broadcast by the master device, the slave device can further determine whether the identifier of the master device that assigned the network address is identical to the identifier of the master device that broadcast the address list. If they are not identical, an address conflict is determined, and the slave device must select a first network address from the address list received via broadcast. Optionally, the first message can also include the identifier of the master device, which is used to identify the master device that broadcasts the N assigned network addresses. After receiving the first message, the slave device determines whether the address list included in the first message contains the stored network address and the identifier corresponding to the network address, and further determines whether the identifier of the master device included in the first message is identical to the stored identifier of the master device. If they are identical, the slave device does not select a new network address. If they are not identical, the slave device determines the first network address based on the address list. The method for determining the first network address based on the address list by the slave device can be found in the method for determining the first network address by the slave device described above and will not be further described here. In the third scenario, the third message sent by the master device to the slave device further includes an identifier of the master device, where the identifier of the master device is used to identify the master device that allocates the first network address.

[0071] Figure 3 Another network address allocation signaling interaction diagram provided in an embodiment of the present application. During this interaction, the address list includes N allocated network addresses, each of which includes N network addresses and N identifiers. This embodiment illustrates the interaction between the master device and the slave device in the second scenario described above.

[0072] S301: The master device broadcasts a first message to the slave device, wherein the first message includes an address list including N allocated network addresses.

[0073] For details, please refer to Figure 2 The corresponding S201 in the embodiment.

[0074] S302: The slave device determines whether there is a conflict in the second network address according to the first message. If there is a network address conflict, execute S303; otherwise, execute S304.

[0075] For a slave device newly added to the network topology, upon receiving the first message, it is determined whether its currently stored second network address is in the address list. If the second network address of the newly added slave device is in the address list, but the address list does not include an identifier corresponding to the second network address, indicating that the second network address has been allocated to another slave device, the process then proceeds to S303. If the second network address of the newly added slave device is not in the address list, indicating that the second network address has not been allocated, the process then proceeds to S304.

[0076] S303: The slave device determines, according to the address list, an unassigned network address as the first network address.

[0077] The specific implementation of the slave device determining the first network address according to the address list can be referred to the implementation of S202, which will not be described in detail in this embodiment.

[0078] S304: The slave device determines the second network address as the first network address.

[0079] S305: The slave device sends a second message to the master device, where the second message includes the first network address.

[0080] For the specific implementation of sending the second message from the device, please refer to the corresponding content of S203.

[0081] S306: The master device allocates a corresponding identifier to the first network address according to the second message.

[0082] For example, after receiving the second message sent by the slave device, the master device assigns a corresponding identifier to the first network address in the second message. The identifier corresponding to the first network address can be a serial number, a sequence code, or other forms that can identify the allocation of the first network address.

[0083] Optionally, after the master device assigns a corresponding identifier to the first network address, it may also record the first network address and the corresponding identifier in an address list. Since the master device can periodically broadcast the first message, when the next broadcast period arrives, the master device rebroadcasts the first message, and the address list included in the first message includes the first network address and the identifier corresponding to the first network address.

[0084] S307: The master device sends a third message to the slave device, where the third message includes the first network address and an identifier corresponding to the first network address.

[0085] For the implementation of the master device sending the third message, please refer to the corresponding content of S204.

[0086] S308: The slave device obtains an identifier corresponding to the first network address according to the third message.

[0087] For example, the slave device obtains the first network address and the identifier corresponding to the first network address from the third message, thereby avoiding address conflicts. Optionally, the slave device may store the first network address and the identifier corresponding to the first network address.

[0088] Figure 4 This embodiment provides another network address allocation signaling interaction diagram for an embodiment of the present application. This embodiment includes two slave devices, such as a first slave device and a second slave device, and there is an address conflict between the addresses of the two slave devices. This embodiment illustrates the interaction between the slave device and the master device in the third scenario described above.

[0089] S401: The master device broadcasts a first message, wherein the first message includes an address list and a master device identifier, and the address list includes N allocated network addresses.

[0090] The specific implementation of the master device broadcasting the first message can be found in Figure 3 The corresponding embodiment is S301.

[0091] S402: When the first slave device determines that there is a conflict in the second network address according to the first message, it determines the first network address according to the first random number and the address list, and determines the first sending time according to the second random number, and then executes S404.

[0092] For the first slave device that has newly joined the network topology, after receiving the first message, it determines that its currently stored second network address and the identifier corresponding to the second network address are included in the address list, and the identifier of the master device included in the first message is different from the stored identifier of the master device, indicating that the second network address has been assigned to other slave devices. The first network address is then determined based on the first random number and the address list, and the time to send the second message is determined based on the second random number.

[0093] For example, the first slave device can generate two random numbers, namely a first random number and a second random number. The first slave device first determines an unassigned network address based on the address list, and then uses the first random number to select a network address from the unassigned network addresses as the first network address. The first slave device can determine a first duration based on the second random number and a delay function. For example, the second random number is used as the independent variable of the delay function to obtain the first duration, and then the first sending time is obtained based on the first duration and the current time (the time when the first slave device determines the first network address).

[0094] S403: When the second slave device determines that there is a conflict in the fourth network address according to the first message, it determines the third network address according to the third random number and the address list, and determines the second sending time according to the fourth random number, and then executes S408.

[0095] For the second slave device that has newly joined the network topology, after receiving the first message, when it determines that its currently stored fourth network address and the identifier corresponding to the fourth network address are included in the address list, and the identifier of the master device included in the first message is different from the stored identifier of the master device, it indicates that the fourth network address has been assigned to other slave devices, then the third network address is determined according to the third random number and the address list, and the second sending time of sending the fifth message is determined according to the fourth random number.

[0096] For example, the second slave device can generate two random numbers, namely a third random number and a fourth random number. The second slave device first determines an unassigned network address based on the address list, and then uses the third random number to determine a network address from the unassigned network addresses as the third network address. The second slave device can determine a second duration based on the fourth random number and a delay function, and then obtain a second sending time based on the second duration and the current time (the time when the second slave device determines the third network address).

[0097] It should be noted that, in specific implementation, the execution order of S402 and S403 is not subject to the above limitation, and S403 may be executed first and then S402, or S402 and S403 may be executed simultaneously.

[0098] The first slave device and the second slave device use different random numbers generated by each to determine their respective selected network addresses from the unassigned network addresses, utilizing the principle of randomness to prevent the two from selecting the same network address. The first random number used by the first slave device to determine the first network address is different from the third random number used by the second slave device to determine the third network address. The second random number used by the first slave device to determine the first sending time is different from the fourth random number used by the second slave device to determine the second sending time. The following explanation uses the example of the first sending time being earlier than the second sending time.

[0099] S404: The first slave device sends a second message to the master device according to the first sending time.

[0100] For example, the first slave device generates a second message based on the first network address, where the source address of the second message is the first network address. The first slave device sends the second message to the master device at the first sending time. For the specific implementation of the first slave device sending the second message to the master device, please refer to the corresponding content of S305.

[0101] S405: The master device allocates a first identifier to the first network address.

[0102] For example, the master device can confirm that a first network address can be assigned to a first slave device based on N assigned network addresses in the address list. The master device assigns a corresponding first identifier to the first network address. The specific implementation of the master device assigning the first identifier to the first network address can be found in the implementation of S306 in the above-mentioned method embodiment, and will not be further described in this embodiment.

[0103] S406: The master device sends a third message to the first slave device.

[0104] For example, the master device generates a third message based on the first network address, the first identifier, and the identifier of the master device, and the destination address of the third message is the first network address. For the method of the master device sending the third message to the slave device, see the corresponding content of S307.

[0105] S407: The first slave device obtains the identifier of the master device, the first network address, and the first identifier from the third message, and then ends the process of the first slave device obtaining the network address.

[0106] For example, the first slave device may store the identifier of the master device, the first network address, and the first identifier obtained from the third message.

[0107] S408: The second slave device sends a fifth message to the master device according to the second sending time.

[0108] For example, the second slave device generates a fifth message based on the third network address, where the source address of the fifth message is the third network address. At the second sending time, the second slave device sends the fifth message to the master device. For details on how the second slave device sends the fifth message to the master device, see the details on how the second message is sent in S305.

[0109] S409: The master device allocates a corresponding second identifier to the third network address.

[0110] For example, based on the address list and the third network address, the master device confirms that the third network address can be assigned to the second slave device. The master device assigns a corresponding second identifier to the third network address. The specific implementation of the master device assigning the second identifier to the third network address can be found in the implementation of S306 in the above-mentioned method embodiment, and will not be further described in this embodiment.

[0111] S410: The master device sends a sixth message to the second slave device.

[0112] For example, the master device generates a sixth message based on the third network address, the second identifier, and the master device identifier. The destination address of the sixth message is the third network address. The manner in which the master device sends the sixth message to the second slave device can be referred to as the manner in which the master device sends the third message to the slave device in S307 above.

[0113] S411: The second slave device obtains the identifier of the master device, the third network address, and the second identifier from the sixth message.

[0114] For example, the second slave device may store the master device identifier, the third network address, and the second identifier obtained from the sixth message.

[0115] That is, when multiple slave devices need to be assigned network addresses, each slave device can use its own corresponding random number to select a network address, thereby avoiding conflicts in the network addresses selected by the slave devices. At the same time, to reduce the load on the master device, each slave device can use its own corresponding random number to determine the time to send a message, so that the master device can process them separately.

[0116] In this embodiment, the method for the master device to acquire N allocated network addresses in the address list by broadcasting the fourth message can be found in Figure 2 The corresponding contents in the corresponding embodiments will not be repeated here.

[0117] The technical solution provided by the embodiment of the present application can be applied to various application scenarios involving network address allocation, such as smart light pole scenarios, etc. The following will be described using a smart light pole as an example.

[0118] See also Figure 5 The schematic diagram of a smart light pole application scenario shows that the smart light pole's gateway not only connects to the light pole's environmental sensors, but also can connect to other sensors via RS485, such as water pollution detection sensors, water level detection sensors, and manhole cover detection sensors. The RS485 connection method refers to the use of a bus to connect various devices in series. Currently, sensors use a preset write method to avoid address conflicts. However, when a new sensor is added to a light pole, a network address must be configured for the newly added sensor to facilitate communication. At this point, it is necessary to query the assigned network addresses of the existing sensors. If, for various reasons, the network addresses assigned to the existing sensors are not recorded, a site visit is required to query them. Alternatively, the network address cannot be configured for the newly added sensor due to reasons such as insufficient on-site configuration conditions. Using the method provided in the embodiments of the present application, the light pole can configure a master device through the gateway and assign the various connected sensors or RF terminals as slave devices. The master device then uniformly manages the network address allocation for each slave device. For devices newly added to the network topology, such as sensors and RF terminals, the master device can use the network address allocation method provided in the embodiments of the present application to assign them network addresses, enabling flexible network address configuration and avoiding address conflicts.

[0119] Any network address mentioned in the above embodiments of the present application is a modbus address.

[0120] Based on the network address allocation method provided in the above embodiment, the embodiment of the present application also provides a corresponding device, which will be described below with reference to the accompanying drawings.

[0121] See also Figure 6 , which is a schematic diagram of the structure of a network address allocation device provided by the embodiment. Figure 6 As shown, the apparatus is applied to a master device, and the apparatus 600 may include: a broadcast unit 601, a first receiving unit 602, and a first sending unit 603. The broadcast unit 601 is used to execute S201 in the above method embodiment, the first receiving unit 602 is used to receive the second message sent by the slave device in S203, and the first sending unit 603 is used to execute S204 in the above method embodiment.

[0122] Specifically, the broadcast unit 601 is configured to broadcast a first message by the master device, where the first message includes an address list, where the address list includes N allocated network addresses, where N is an integer greater than or equal to 1;

[0123] a first receiving unit 602, configured to receive a second message sent by the slave device, where the second message includes a first network address, where the first network address is an unassigned address determined according to the address list;

[0124] The first sending unit 603 is configured to send a third message to the slave device, where the third message is used to confirm allocation of the first network address.

[0125] In one possible implementation, the apparatus further includes: a confirmation unit 604 and an allocation unit 605. The confirmation unit 604 is configured to confirm, based on the first network address in the second message and the address list, that the first network address is an unallocated network address, so as to allocate the first network address to the slave device; and the allocation unit 605 is configured to allocate a corresponding identifier to the first network address.

[0126] In a possible implementation, the device may further include: a recording unit (not shown in Figure 6 The recording unit is connected to the allocating unit 605 and is configured to record the first network address and the identifier allocated by the allocating unit 605 to the first network address in the address list.

[0127] In a possible implementation, the device may further include a generating unit ( Figure 6 (not shown). The generating unit may generate a third message according to the first network address confirmed by the confirming unit 604 and the identifier corresponding to the first network address allocated by the allocating unit 605.

[0128] In a possible implementation, the third message includes the first network address and an identifier corresponding to the first network address, and the identifier corresponding to the first network address is used to identify that the first network address is allocated.

[0129] In one possible implementation, the N allocated network addresses include N network addresses and N identifiers, one of the N network addresses corresponds to one of the N identifiers, and the identifier corresponding to one of the N network addresses is used to identify that the network address corresponding to it is allocated.

[0130] In a possible implementation, the first message further includes an identifier of the master device, where the identifier of the master device is used to identify the master device that broadcasts the N allocated network addresses.

[0131] In a possible implementation, the third message further includes an identifier of the master device, where the identifier of the master device is used to identify the master device that allocates the first network address.

[0132] In a possible implementation, the apparatus further includes:

[0133] The broadcast unit is further configured to broadcast a fourth message before broadcasting the first message, wherein the fourth message is used to query the allocated network address;

[0134] A first acquiring unit, configured to acquire the N allocated network addresses from N slave devices;

[0135] The second acquiring unit is configured to acquire the address list according to the N allocated network addresses.

[0136] In a possible implementation, the apparatus further includes:

[0137] The second sending unit is configured to send, to any slave device among the N slave devices, an identifier corresponding to the network address allocated to the any slave device.

[0138] In this embodiment, the implementation of each unit can refer to the specific implementation process of the main device in the above method embodiment, which will not be repeated here.

[0139] See also Figure 7, which is a schematic diagram of the structure of another network address allocation device provided in an embodiment of the present application. The device is applied to a slave device. Specifically, the allocation device 700 may include: a second receiving unit 701, a confirmation unit 702, a third sending unit 703, and a third receiving unit 704. The second receiving unit 701 is used to receive the first message broadcast by the master device in S201, the determination unit 702 is used to execute S202 in the above method embodiment, the third sending unit is used to execute S203 in the above method embodiment, and the third receiving unit is used to receive the third message sent by the master device in S204 in the above method embodiment.

[0140] The second receiving unit 701 is configured to receive a first broadcast message, where the first message includes an address list, where the address list includes N allocated network addresses, where N is an integer greater than or equal to 1;

[0141] a determining unit 702, configured to determine a first network address according to the address list, where the first network address is an unassigned address determined according to the address list;

[0142] A third sending unit 703 is configured to send a second message to the master device, where the second message includes the first network address;

[0143] The third receiving unit 704 is configured to receive a third message sent by the master device, where the third message is used to confirm the allocation of the first network address.

[0144] In a possible implementation, the third message includes the first network address and an identifier corresponding to the first network address, and the identifier corresponding to the first network address is used to identify that the first network address is allocated.

[0145] In a possible implementation, the apparatus may further include a storage unit 705. The storage unit 705 is configured to store the first network address in the third message and an identifier corresponding to the first network address.

[0146] In one possible implementation, the N allocated network addresses include N network addresses and N identifiers, one of the N network addresses corresponds to one of the N identifiers, and the identifier corresponding to one of the N network addresses is used to identify that the network address corresponding to it is allocated.

[0147] In a possible implementation, the determining unit is specifically configured to, when the network address stored by the slave device is included in the address list and no identifier corresponding to the network address is stored, obtain, by the slave device, according to the address list, a first network address that is not included in the N allocated network addresses, the N allocated network addresses not including the identifier corresponding to the first network address; or

[0148] The first message also includes an identifier of the master device. When the network address stored in the slave device and the identifier corresponding to the network address are included in the address list and the identifier of the master device corresponding to the network address is different from the identifier of the master device in the first message, the slave device selects a network address as the first network address based on the first random number and the address list, and the first network address is not included in the N allocated network addresses.

[0149] In a possible implementation, the determining unit is specifically configured to, when the network address stored by the slave device is included in the address list and no identifier corresponding to the network address is stored, select, by the slave device, a network address as the first network address according to the first random number and the address list, where the first network address is not included in the N allocated network addresses; or

[0150] The first message also includes an identifier of the master device. When the network address stored in the slave device and the identifier corresponding to the network address are included in the address list and the identifier of the master device corresponding to the network address is different from the identifier of the master device in the first message, the slave device selects a network address as the first network address based on the first random number and the address list, and the first network address is not included in the N allocated network addresses.

[0151] Specifically, the determining unit may execute S303 or S402 in the above method embodiment.

[0152] In a possible implementation, the third sending unit includes:

[0153] a determination subunit, configured to determine a sending time according to a second random number;

[0154] The sending subunit is used to send the second message to the master device according to the sending time.

[0155] Specifically, the third sending unit may execute S402 and S404 in the above method example.

[0156] In this embodiment, the implementation of each unit can refer to the specific implementation process of the slave device in the above method embodiment, which will not be repeated here.

[0157] The hardware structure of the aforementioned apparatus 600 and apparatus 700 may be as follows: Figure 8 The structure shown, Figure 8 A schematic diagram of the structure of a device provided in an embodiment of the present application.

[0158] See also Figure 8 As shown, the device 800 includes: a processor 810, a communication interface 820 and a memory 830. The number of the processor 810 in the device 800 can be one or more. Figure 8 In the embodiment of the present application, the processor 810, the communication interface 820 and the memory 830 may be connected via a bus system or other means, wherein: Figure 8 The connection via bus system 840 is taken as an example.

[0159] The processor 810 may be a central processing unit (CPU), a network processor (NP), or a combination of a CPU and an NP. The processor 810 may further include a hardware chip. The hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.

[0160] The memory 830 may include a volatile memory (English: volatile memory), such as a random-access memory (RAM); the memory 830 may also include a non-volatile memory (English: non-volatile memory), such as a flash memory (English: flash memory), a hard disk drive (HDD) or a solid-state drive (SSD); the memory 830 may also include a combination of the above types of memory.

[0161] Optionally, the memory 830 stores an operating system and programs, executable modules or data structures, or subsets thereof, or extended sets thereof, wherein the programs may include various operating instructions for implementing various operations. The operating system may include various system programs for implementing various basic services and processing hardware-based tasks. The processor 810 may read the programs in the memory 830 to implement the network address allocation method provided in the embodiment of the present application.

[0162] The bus system 840 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The bus system 840 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 8 Only one thick line is used in the diagram, but this does not mean that there is only one bus or one type of bus.

[0163] An embodiment of the present application further provides a computer-readable storage medium, comprising instructions or a computer program, which, when executed on a computer, enables the computer to execute the method for network address allocation provided in the above embodiment.

[0164] The embodiments of the present application also provide a computer program product comprising instructions or a computer program, which, when executed on a computer, enables the computer to execute the method for network address allocation provided in the above embodiments.

[0165] The terms "first," "second," "third," "fourth," and so on (if any) in the specification and claims of this application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or apparatus that includes a series of steps or elements is not necessarily limited to those steps or elements explicitly listed, but may include other steps or elements not explicitly listed or inherent to such process, method, product, or apparatus.

[0166] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0167] In the several embodiments provided in this application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of units is only a logical business division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interface, device or unit, which can be electrical, mechanical or other forms.

[0168] Units described as separate components may or may not be physically separate, and components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.

[0169] In addition, each business unit in each embodiment of the present application can be integrated into a processing unit, each unit can exist physically separately, or two or more units can be integrated into a single unit. The above-mentioned integrated units can be implemented in the form of hardware or software business units.

[0170] If the integrated unit is implemented in the form of a software business unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0171] Those skilled in the art will appreciate that, in one or more of the above examples, the services described herein can be implemented using hardware, software, firmware, or any combination thereof. When implemented using software, these services can be stored on a computer-readable medium or transmitted as one or more instructions or codes on a computer-readable medium. Computer-readable media include computer storage media and communication media, including any medium that facilitates the transmission of computer programs from one location to another. Storage media can be any available medium that can be accessed by a general-purpose or special-purpose computer.

[0172] The above specific implementation methods further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above are only specific implementation methods of the present invention.

[0173] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A network address allocation method, characterized in that: include: The master device broadcasts a first message, the first message including an address list and an identifier of the master device, the address list including N allocated network addresses and corresponding N identifiers, where N is an integer greater than or equal to 1, and the identifier of the master device included in the first message is used to identify the master device that broadcasts the N allocated network addresses, so that the slave device receives the first message, and when it is determined that the N allocated network addresses include a second network address of the slave device and an identifier corresponding to the second network address, and that the identifier of the master device is different from the identifier of the master device corresponding to the second network address, determines the first network address according to the address list; The master device receives a second message sent by the slave device, where the second message includes a first network address, where the first network address is an unassigned address determined according to the address list; The master device sends a third message to the slave device, where the third message is used to confirm allocation of the first network address.

2. The method according to claim 1, characterized in that The third message includes the first network address and an identifier corresponding to the first network address, and the identifier corresponding to the first network address is used to identify that the first network address is allocated.

3. The method according to claim 1 or 2, characterized in that The N allocated network addresses include N network addresses and N identifiers, the network addresses in the N network addresses correspond one-to-one to the identifiers in the N identifiers, and the identifier corresponding to the network address in the N network addresses is used to identify that the corresponding network address is allocated.

4. The method according to any one of claims 1 to 2, characterized in that: The third message further includes an identifier of the master device, where the identifier of the master device is used to identify the master device that allocates the first network address.

5. The method according to any one of claims 1 to 2, characterized in that: Before the master device broadcasts the first message, the method further includes: The master device broadcasts a fourth message, where the fourth message is used to query the allocated network address; The master device obtains the N allocated network addresses from N slave devices, wherein the slave devices in the N slave devices correspond one to one to the allocated network addresses in the N allocated network addresses; The master device obtains the address list according to the N allocated network addresses.

6. The method according to claim 5, characterized in that The method further comprises: The master device sends an identifier corresponding to the network address allocated to any slave device among the N slave devices.

7. A network address allocation method, characterized in that: include: The slave device receives a first message broadcast by a master device, the first message including an address list and an identifier of the master device, the address list including N allocated network addresses and corresponding N identifiers, where N is an integer greater than or equal to 1, and the identifier of the master device included in the first message is used to identify the master device broadcasting the N allocated network addresses; When the slave device determines that the N allocated network addresses include the second network address of the slave device and an identifier corresponding to the second network address, and the identifier of the master device is different from the identifier of the master device corresponding to the second network address, the slave device determines a first network address according to the address list, where the first network address is an unallocated address determined according to the address list; The slave device sends a second message to the master device, where the second message includes the first network address; The slave device receives a third message sent by the master device, where the third message is used to confirm allocation of the first network address.

8. The method according to claim 7, characterized in that The third message includes the first network address and an identifier corresponding to the first network address, and the identifier corresponding to the first network address is used to identify that the first network address is allocated.

9. The method according to claim 7 or 8, characterized in that The N allocated network addresses include N network addresses and N identifiers, one of the N network addresses corresponds to one of the N identifiers, and the identifier corresponding to one of the N network addresses is used to identify that the network address corresponding to it is allocated.

10. The method according to any one of claims 7 to 8, characterized in that: The slave device determining the first network address according to the address list includes: The slave device obtains a first network address that is not included in the N allocated network addresses according to the address list, and the N allocated network addresses do not include an identifier corresponding to the first network address.

11. The method according to any one of claims 7 to 8, characterized in that: The slave device determining the first network address according to the address list includes: The slave device selects a network address as a first network address according to the first random number and the address list, where the first network address is not included in the N allocated network addresses.

12. The method according to any one of claims 7 to 8, characterized in that: The slave device sending the second message to the master device includes: The slave device determines a sending time according to a second random number; The slave device sends the second message to the master device according to the sending time.

13. A network address allocation device, characterized in that: The device is provided in the main equipment and includes: a broadcast unit configured to broadcast a first message, the first message including an address list and an identifier of the master device, the address list including N allocated network addresses and N corresponding identifiers, where N is an integer greater than or equal to 1, the identifier of the master device included in the first message being used to identify the master device broadcasting the N allocated network addresses, so that a slave device receiving the first message, upon determining that the N allocated network addresses include a second network address of the slave device and an identifier corresponding to the second network address, and that the identifier of the master device is different from the identifier of the master device corresponding to the second network address, determines the first network address according to the address list; a first receiving unit, configured to receive a second message sent from the device, where the second message includes a first network address, where the first network address is an unassigned address determined according to the address list; The first sending unit is configured to send a third message to the slave device, where the third message is used to confirm allocation of the first network address.

14. The device according to claim 13, characterized in that The third message includes the first network address and an identifier corresponding to the first network address, and the identifier corresponding to the first network address is used to identify that the first network address is allocated.

15. The device according to claim 13 or 14, characterized in that The N allocated network addresses include N network addresses and N identifiers, the network addresses in the N network addresses correspond one-to-one to the identifiers in the N identifiers, and the identifier corresponding to one of the N network addresses is used to identify that the corresponding network address is allocated.

16. The device according to any one of claims 13 to 14, characterized in that The third message further includes an identifier of the master device, where the identifier of the master device is used to identify the master device that allocates the first network address.

17. The device according to any one of claims 13 to 14, characterized in that The device further comprises: The broadcast unit is further configured to broadcast a fourth message before broadcasting the first message, wherein the fourth message is used to query the allocated network address; A first acquiring unit is configured to acquire the N allocated network addresses from N slave devices, wherein the slave devices in the N slave devices correspond one to one to the allocated network addresses in the N allocated network addresses; The second acquiring unit is configured to acquire the address list according to the N allocated network addresses.

18. The device according to claim 17, characterized in that The device further comprises: The second sending unit is configured to send, to any slave device among the N slave devices, an identifier corresponding to the network address allocated to the any slave device.

19. A network address allocation device, characterized in that: The device is provided in a slave device and includes: a second receiving unit, configured to receive a first message broadcast by a master device, the first message including an address list and an identifier of the master device, the address list including N allocated network addresses and corresponding N identifiers, where N is an integer greater than or equal to 1, and the identifier of the master device included in the first message is used to identify the master device broadcasting the N allocated network addresses; a determining unit, configured to, when the slave device determines that the N allocated network addresses include the second network address of the slave device and an identifier corresponding to the second network address, and the identifier of the master device is different from the identifier of the master device corresponding to the second network address, determine a first network address according to the address list, the first network address being an unallocated address determined according to the address list; a third sending unit, configured to send a second message to the master device, where the second message includes the first network address; The third receiving unit is configured to receive a third message sent by the master device, where the third message is used to confirm the allocation of the first network address.

20. The device according to claim 19, characterized in that The third message includes the first network address and an identifier corresponding to the first network address, and the identifier corresponding to the first network address is used to identify that the first network address is allocated.

21. The device according to claim 19 or 20, characterized in that The N allocated network addresses include N network addresses and N identifiers, one of the N network addresses corresponds to one of the N identifiers, and the identifier corresponding to one of the N network addresses is used to identify that the network address corresponding to it is allocated.

22. The device according to any one of claims 19 to 20, characterized in that The determining unit is specifically configured to obtain, according to the address list, a first network address that is not included in the N allocated network addresses, where the N allocated network addresses do not include an identifier corresponding to the first network address.

23. The device according to any one of claims 19 to 20, characterized in that The determining unit is specifically configured to select a network address as a first network address according to the first random number and the address list, where the first network address is not included in the N allocated network addresses.

24. The device according to any one of claims 19 to 20, characterized in that The third sending unit includes: a determination subunit, configured to determine a sending time according to a second random number; The sending subunit is used to send the second message to the master device according to the sending time.

Citation Information

Patent Citations

  • RS485 automatic address distribution method, device and system

    CN105847456A