Address allocation method, apparatus, device, and storage medium
By sending broadcast frames from the master device and allocating addresses based on the responses from slave devices, a binary tree search algorithm is used to solve the problems of low efficiency and inflexibility in device address allocation, thus achieving efficient and flexible address allocation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-24
- Publication Date
- 2026-03-27
AI Technical Summary
In existing technologies, device address allocation is inefficient and inflexible. Hardware allocation methods increase costs, and sequential allocation methods require prior knowledge of the slave device type, resulting in a fixed allocation method that cannot add or replace slave devices.
The master device sends a broadcast frame by acquiring the serial number string and mask. Each slave device matches the frame and sends back a response frame. The master device allocates device addresses based on the response frames. A binary tree search algorithm is used to process address scanning and allocation, reducing hardware dependency.
It improves the accuracy and efficiency of device address allocation, reduces hardware dependence, and increases the flexibility of address allocation.
Smart Images

Figure CN121396952B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of address allocation, and particularly relates to an address allocation method and device, equipment and a storage medium. BACKGROUND
[0002] At present, in solving the problem of bus type control, one control multi is a relatively popular control mode at present, and has good performance. However, with the increase of networking, the complexity of the problem of corresponding slave node address setting and master-slave address matching gradually highlights, and in the prior art, the slave address needs to be manually set by a person, or the slave address is allocated one by one in a slave series communication, thereby occupying unnecessary resources.
[0003] In the address allocation mode of the related art, the hardware address allocation mode needs to increase hardware cost and is not flexible in address allocation mode; in the sequential allocation mode, the type of the slave device needs to be known in advance, so that the slave device is fixed and cannot be increased or replaced.
[0004] Therefore, how to improve the efficiency and flexibility of device address allocation is a problem to be solved at present.
[0005] The above content is only used to assist in understanding the technical solutions of the present application, and does not represent the acknowledgement of the above content as prior art. SUMMARY
[0006] The main purpose of the present application is to provide an address allocation method, device, equipment and storage medium, and aims to solve the technical problem of how to improve the efficiency and flexibility of device address allocation.
[0007] To achieve the above purpose, the present application provides an address allocation method, which comprises the following steps:
[0008] The master device acquires a first serial number string and a first mask;
[0009] The master device sends a first broadcast frame based on the first serial number string and the first mask, wherein if the first serial number of a first slave device in the slave device matches the received first broadcast frame, the first slave device feeds back a first response frame;
[0010] When the second response frame is received, the master device allocates a device address to the slave device corresponding to the second response frame.
[0011] In an embodiment, the master device sends a first broadcast frame based on the first serial number string and the first mask, wherein if the first serial number of a first slave device in the slave device matches the received first broadcast frame, the first slave device feeds back a first response frame, and the step comprises:
[0012] The master device sends a first broadcast frame based on a first serial number string and a first mask, wherein the first slave device obtains the first serial number string and the first mask corresponding to the first broadcast frame, and obtains first to-be-matched information by calculating data of first preset bits in the first serial number and the first mask, and if the first to-be-matched information is consistent with the first serial number string, the first slave device feeds back a first response frame based on the first serial number.
[0013] In an embodiment, when the second response frame is received, the step of the master device allocating a device address for the slave device corresponding to the second response frame comprises:
[0014] The master device determines whether the second response frame is a normal response frame.
[0015] If the second response frame is a normal response frame, the master device obtains a second serial number in the second response frame, and sends an address allocation frame to the slave device corresponding to the second response frame based on the second serial number.
[0016] In an embodiment, the step of the master device determining whether the second response frame is a normal response frame comprises:
[0017] If the second response frame is a conflict response frame, the master device obtains a second serial number string and a second mask.
[0018] The master device sends a second broadcast frame based on the second serial number string and the second mask, wherein if a third serial number of a second slave device in the slave devices matches the received second broadcast frame, the second slave device feeds back a third response frame.
[0019] When the fourth response frame is received, the master device allocates a device address for the slave device corresponding to the fourth response frame.
[0020] In an embodiment, the step of the master device sending a second broadcast frame based on the second serial number string and the second mask, wherein if a third serial number of a second slave device in the slave devices matches the received second broadcast frame, the second slave device feeds back a third response frame comprises:
[0021] The master device sends a second broadcast frame based on the second serial number string and the second mask, wherein the second slave device obtains the second serial number string and the second mask corresponding to the second broadcast frame, and obtains second to-be-matched information by calculating data of second preset bits in the third serial number and the second mask, and if the second to-be-matched information is consistent with the second serial number string, the second slave device feeds back a third response frame based on the third serial number.
[0022] In an embodiment, after the step of sending the first broadcast frame based on the first sequence number string and the first mask, the address allocation method further comprises:
[0023] If the first slave device does not receive the address allocation frame sent by the master device within a first preset time period after feeding back the first response frame, the first slave device feeds back the first response frame.
[0024] In an embodiment, after the step of sending the first broadcast frame based on the first sequence number string and the first mask, the address allocation method further comprises:
[0025] If the second response frame fed back by the slave device is not received within a second preset time period after sending the first broadcast frame, the step of obtaining the first sequence number string and the first mask by the master device is executed.
[0026] In addition, to achieve the above-mentioned purpose, the present application further provides an address allocation device, which comprises:
[0027] The obtaining module is configured to obtain a first sequence number string and a first mask;
[0028] The sending module is configured to send a first broadcast frame based on the first sequence number string and the first mask, wherein if the first sequence number of a first slave device in the slave devices matches the received first broadcast frame, the first slave device feeds back a first response frame;
[0029] The allocation module is configured to allocate a device address to the slave device corresponding to the second response frame when the second response frame is received.
[0030] In addition, to achieve the above-mentioned purpose, the present application further provides an address allocation device, which comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, and the computer program is configured to implement the steps of the above-mentioned address allocation method.
[0031] In addition, to achieve the above-mentioned purpose, the present application further provides a storage medium, which is a computer readable storage medium, and the storage medium stores a computer program, and the computer program is executed by a processor to implement the steps of the above-mentioned address allocation method.
[0032] The one or more technical solutions provided by the present application have at least the following technical effects:
[0033] The first slave device that matches the first broadcast frame with its own second manufacturer code feeds back a first response frame, and the master device allocates a device address to the slave device corresponding to the second response frame when the second response frame is received, so as to realize accurate allocation of device address allocation, process the address scanning and allocation process from the pure software perspective, reduce the hardware dependence in the device address allocation process, and improve the efficiency and flexibility of the device address allocation. BRIEF DESCRIPTION OF DRAWINGS
[0034] The accompanying drawings incorporated in and forming a part of the specification illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the application.
[0035] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the accompanying drawings needed to be used in the embodiments or prior art description will be briefly introduced. Obviously, those skilled in the art can obtain other drawings from these drawings without any creative effort.
[0036] Figure 1 A flowchart provided by an embodiment of the address allocation method of the present application;
[0037] Figure 2 A module structure diagram of the address allocation device of the embodiment of the present application;
[0038] Figure 3 A device structure diagram of the hardware running environment involved in the address allocation method in the embodiment of the present application.
[0039] The object implementation, functional features and advantages of the present application will be further explained with reference to the embodiments and the accompanying drawings. DETAILED DESCRIPTION
[0040] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application, and are not used to limit the present application.
[0041] In order to better understand the technical solutions of the present application, the following will be described in detail in combination with the drawings in the specification and specific embodiments.
[0042] The main solution of the embodiment of the present application is that the master device obtains a first sequence number string and a first mask; the master device sends a first broadcast frame based on the first sequence number string and the first mask, wherein if the first sequence number of a first slave device in the slave devices matches the received first broadcast frame, the first slave device feeds back a first response frame; when the second response frame is received, the master device allocates a device address to the slave device corresponding to the second response frame.
[0043] In the present embodiment, for the sake of description, the following is described with the identification address allocation device as the execution subject.
[0044] At present, in solving the problem of bus type control, one control multi has become a relatively popular control mode at present, and has good performance. However, with the increase of networking, the complexity of the problem of corresponding slave node address setting and master-slave address matching gradually highlights, and in the prior art, the slave address needs to be manually set by man, or the slave address is allocated one by one in a slave series communication, occupying unnecessary resources.
[0045] In the address allocation mode of the related art, the hardware address allocation mode needs to increase hardware cost and its address allocation mode is not flexible; in the sequential allocation mode, the type of the slave device needs to be known in advance, resulting in fixed slave devices and inability to increase or replace the slave devices.
[0046] In Chinese Patent Application CN116016447A, the master sends a broadcast instruction to start address allocation, and the slave responds to the instruction and prepares to compete for the address according to the UUID bit. After receiving the first U instruction, the bit competition mechanism is entered; every time a U instruction is responded to, the slave with a smaller UUID value remains to continue competing for the address, and the larger one is pushed out. Finally, only the slave with the smallest UUID among all the slaves is left, thereby completing the allocation of the first address. Subsequent allocation of the second address is performed according to the allocation mode of the first place, and the allocation of all addresses is completed. However, the communication interface defined therein is a 485 bus, and the 485 state needs to be controlled by software to cooperate with the address allocation. Each slave has a unique UUID, which is composed of 10 bytes of data, a total of 80 bits, a fixed length, a maximum of 254 logical addresses, 0 is a broadcast address, and the available address is [1, 0xff]; the address size is fixed.
[0047] In Chinese Patent Application CN112929465A, the master broadcasts an address allocation data frame to the bus, and the configuration address data frame includes a to-be-allocated address; the slave without an allocated address competes for the to-be-allocated address, and the slave that wins the to-be-allocated address replies to the master; after receiving the reply of the slave, the master uses a calling data frame to call the slave to judge whether the to-be-allocated address is successfully allocated. However, the master address allocation is allocated according to the address segment, and the address segment is bound with the address random number, a random delay time number needs to be generated, which may consume too much time for a low-performance MCU, and the address allocation is periodically allocated, and if the address segment allocation period is missed, the next address segment is directly allocated.
[0048] In Chinese patent application CN111371659A, a master device and a plurality of slave devices are included, the master device and the slave devices both contain RS485 interface modules, the slave devices are connected with the master device through the RS485 interface modules; the master device sends a query frame to the slave devices; the slave devices send an information frame of the slave device to the master device after receiving the query frame; the master device receives the information frame fed back by the slave device, and then sends a confirmation frame to the slave device; after receiving the confirmation frame, the slave device matches the confirmation frame with the ID information of the slave device itself, if the ID information is consistent, the slave device uses the address in the confirmation frame, if the ID information is inconsistent, the slave device selects a new address from the address pool in the confirmation frame, and sends a new information frame to the master device again. However, when receiving the information confirmation frame sent by the master device, the slave device also selects a new address from the address pool if the ID is inconsistent, which improves the address allocation speed but may cause communication conflict and confusion, and the address mapping table maintained by the master device is out of touch with the actual topology. In advanced protocols such as I3C that support dynamic address allocation and hot joining, the bus topology management of the master device will be seriously interfered, causing address allocation confusion.
[0049] Therefore, how to improve the efficiency and flexibility of device address allocation is a problem to be solved at present.
[0050] The application provides a solution, the master device sends a first broadcast frame in the local area network based on a first serial number string and a first mask, each slave device matches the first broadcast frame with its own second manufacturer code, the first slave device that matches successfully feeds back a first response frame, and the master device allocates a device address to the slave device corresponding to the second response frame when receiving the second response frame, so as to realize accurate allocation of device address allocation, process the address scanning and allocation process from the pure software point of view, reduce the hardware dependence in the device address allocation process, and improve the efficiency and flexibility of device address allocation.
[0051] It should be noted that the execution subject of the embodiment can be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device, an address allocation device, etc. capable of realizing the above functions. The address allocation device is taken as an example to illustrate the embodiment and the following embodiments.
[0052] Based on this, the application embodiment provides an address allocation method, referring to Figure 1 , Figure 1 The flowchart of an embodiment of the address allocation method of the application is shown.
[0053] In the embodiment, the address allocation method includes steps S110-S140:
[0054] In step S110, the master device obtains a first serial number string and a first mask;
[0055] It should be noted that the master device can be any one of the devices, and the master device and each slave device can communicate through a 485 / 232 / I2c / I3c bus to support address allocation of various data buses, and also support one-to-many or many-to-many master-slave communication.
[0056] In this embodiment, when the device address is allocated, the master device obtains a first serial number string UID and a first mask, and the first mask is a bit mask BitMask. The master device obtains the first serial number string UID and the first mask by using a binary tree search algorithm, for example, the master device searches a corresponding binary tree according to a first preset bit to obtain the first serial number string UID and the first mask. The length of the first serial number string UID and the length of the first mask are consistent with the length of the first preset bit.
[0057] In step S120, the master device sends a first broadcast frame based on the first serial number string and the first mask. If the first serial number of a first slave device among the slave devices matches the received first broadcast frame, the first slave device feeds back a first response frame.
[0058] In this embodiment, after obtaining the first serial number string and the first mask, the master device sends a first broadcast frame. Specifically, the master device generates a first broadcast frame based on the first serial number string and the first mask, and broadcasts the first broadcast frame in a local area network. Each slave device can receive the first broadcast frame through the local area network. The slave device that receives the first broadcast frame matches its own first serial number SN (Serial Number) with the received first broadcast frame. The first slave device that matches successfully feeds back a first response frame. The serial number SN can include at least one of a manufacturer code of the slave device, a device type of the slave device, and a hardware version of the slave device. The serial number SN can also include date and serial number information.
[0059] Further, in a possible implementation, step S120 can include step A110:
[0060] In step A110, the master device sends a first broadcast frame based on the first serial number string and the first mask. The first slave device obtains the first serial number string and the first mask corresponding to the first broadcast frame, and calculates the first preset bit data in the first serial number and the first mask to obtain first matching information. If the first matching information is consistent with the first serial number string, the first slave device feeds back a first response frame based on the first serial number.
[0061] In the embodiment of the present application, when the first broadcast frame is broadcasted, each slave device receives the first broadcast frame, and obtains the first serial number string and the first mask by analyzing the first broadcast frame, and obtains the first serial number corresponding to the slave device. The slave device calculates the first serial number SN and the first mask to obtain the first matching information, for example, the first matching information = first serial number & first mask.
[0062] For each slave device, after obtaining the first matching information, the slave device determines whether the first matching information is consistent with the first serial number string. If the first matching information is consistent with the first serial number string, the slave device determines that the first matching information matches the first serial number string, and the slave device is the first slave device that matches successfully. Then, the first slave device feeds back the first response frame based on the first serial number. Specifically, the first slave device generates the first response frame based on the first serial number SN, carries the first serial number SN in the first response frame, and broadcasts the first response frame carrying the first serial number SN in the local area network.
[0063] The first preset bit can be reasonably set according to the length of the serial number of each slave device, for example, the first preset bit can be the highest bit, the highest two bits or the highest multiple bits in the serial number, so that the length of the first serial number and the first mask can be reasonably adjusted.
[0064] Step S130, when the second response frame is received, the master device allocates a device address to the slave device corresponding to the second response frame.
[0065] In the embodiment, when the second response frame is received, the master device allocates a device address to the slave device corresponding to the second response frame. Specifically, the master device allocates a device address to the slave device corresponding to the second response frame according to whether the second response frame is normal, for example, when the second response frame is normal, the master device directly allocates a device address to the slave device corresponding to the second response frame.
[0066] It can be understood that after the first slave device feeds back the first response frame, the master device can receive the first response frame through the local area network. If the first slave device that feeds back the first response frame is one, the second response frame is the first response frame of the first slave device. If the first slave device that feeds back the first response frame is multiple, that is, there are multiple first slave devices that feed back the first response frame, for example, there are multiple slave devices belonging to the same manufacturer when the serial number SN includes manufacturer information. Since the response time of each first slave device is basically unified or slightly delayed, the data of each first response frame in the bus may conflict, resulting in that the second response frame received by the master device may be a conflict response frame of random code information.
[0067] Further, in a possible implementation, step S130 can include steps S131-S132:
[0068] Step S131, the master device determines whether the second response frame is a normal response frame;
[0069] Step S132, if the second response frame is a normal response frame, the master device acquires a second sequence number in the second response frame, and sends an address allocation frame to the slave device corresponding to the second response frame based on the second sequence number.
[0070] In the embodiment, after receiving the second response frame, the master device determines whether the received second response frame is a normal response frame, to determine whether the second response frame is a first response frame including one first slave device or a first response frame including multiple first slave devices.
[0071] If the second response frame is a normal response frame, i.e., the second response frame is a first response frame of one first slave device, the master device acquires a second sequence number in the second response frame, where the second sequence number is the same as the first sequence number of the first slave device, and then the master device allocates a device address to the slave device corresponding to the second response frame based on the first sequence number SN.
[0072] Specifically, the master device acquires the device address corresponding to the first sequence number SN. For example, the master device acquires the device address corresponding to the first sequence number SN in the device address pool by using an algorithm in the related art, and then the master device generates an address allocation frame based on the acquired device address and the first sequence number SN, and broadcasts the address allocation frame. Each slave device can acquire the address allocation frame in the local area network, and parse the address allocation frame to obtain the device address and the first sequence number SN, and then determine whether the parsed first sequence number SN is the same as its own sequence number SN. If they are the same, the parsed device address is taken as its own device address, and a communication link is established with the master device through the device address.
[0073] It should be noted that since the address allocation frame is generated by the sequence number SN of the first slave device, only the sequence number SN of the first slave device is the same as the parsed first sequence number SN, and then the first slave device takes the parsed device address as its own device address, while the sequence number SN of other slave devices is not the same as the parsed first sequence number SN, and thus no response frame is sent.
[0074] In the embodiment, the device address of the first slave device can be accurately allocated through the second response frame, to realize accurate allocation of device address allocation, to process the address scanning and allocation process from the pure software perspective, to reduce the hardware dependence in the device address allocation process, and to improve the efficiency and flexibility of the device address allocation.
[0075] Further, in a feasible implementation, after step S131, the address allocation method can further include steps S133-S135:
[0076] In step S133, if the second response frame is a collision response frame, the master device acquires a second serial number string and a second mask.
[0077] In step S134, the master device sends a second broadcast frame based on the second serial number string and the second mask, wherein if a third serial number of a second slave device among the slave devices matches the received second broadcast frame, the second slave device feeds back a third response frame.
[0078] In step S135, when a fourth response frame is received, the master device allocates a device address to the slave device corresponding to the fourth response frame.
[0079] In the embodiment, if the second response frame is a collision response frame, it is determined that the second response frame includes the first response frames of the plurality of first slave devices, and the device acquires a second serial number string and a second mask.
[0080] For example, the master device searches the corresponding binary tree according to the second preset bit and the first serial number string to obtain a second serial number string UID and a second mask, wherein the length of the second serial number string UID and the length of the second mask are consistent with the length of the second preset bit, the length of the second preset bit can be the same as or different from the length of the first preset bit, and the position of the second preset bit in the serial number of the slave device is different from the position of the first preset bit in the serial number of the slave device.
[0081] After the second serial number string and the second mask are acquired, the master device sends a second broadcast frame based on the second serial number string and the second mask. Specifically, the master device generates a second broadcast frame based on the second serial number string and the second mask, and broadcasts the second broadcast frame in the local area network. Each slave device can receive the second broadcast frame through the local area network, and the slave device receiving the second broadcast frame matches the received second broadcast frame through its own first serial number SN. The second slave device that matches successfully feeds back a third response frame.
[0082] Further, in a feasible implementation, step S134 can include step B110:
[0083] In step B110, the master device sends a second broadcast frame based on the second serial number string and the second mask, wherein the second slave device acquires a second serial number string and a second mask corresponding to the second broadcast frame, and calculates the data of the second preset bit in the third serial number and the second mask to obtain second matching information, and if the second matching information is consistent with the second serial number string, the second slave device feeds back a third response frame based on the third serial number.
[0084] In this embodiment of the application, when broadcasting the second broadcast frame, and after each slave device receives the second broadcast frame, it obtains the second sequence number string and the second mask by parsing the second broadcast frame, and at the same time obtains the third sequence number corresponding to the slave device itself. The slave device calculates the third sequence number SN and the second mask to obtain the second matching information. For example, the second matching information = third sequence number & second mask.
[0085] For each slave device, after obtaining the second matching information, the slave device determines whether the second matching information is consistent with the second sequence number string. If the second matching information is consistent with the second sequence number string, the slave device determines that the second matching information matches the second sequence number string, and the slave device is the second slave device that has successfully matched. Then, the second slave device feeds back a third response frame based on the third sequence number. Specifically, the second slave device generates the third response frame based on the third sequence number SN, so as to carry the third sequence number SN in the third response frame, and broadcasts the third response frame carrying the third sequence number SN in the local area network.
[0086] The second preset bit can be reasonably set according to the length of the serial number of each slave device. For example, the second preset bit can be the least significant bit, the least two bits, or the least multiple bits in the serial number, so that the length of the second serial number and the second mask can be reasonably adjusted.
[0087] It is understandable that after the second slave device sends out the third response frame, the master device can receive the third response frame through the local area network. If there is only one second slave device sending out the third response frame, then the third response frame is the third response frame of that second slave device. If there are multiple second slave devices sending out the third response frame, that is, there are multiple second slave devices sending out the third response frame, the various third response frames in the bus may conflict with each other, which may cause the fourth response frame received by the master device to be a conflict response frame with garbled information.
[0088] In this embodiment, when the fourth response frame is received, the master device allocates a device address to the slave device corresponding to the fourth response frame. Specifically, the master device allocates a device address to the slave device based on whether the fourth response frame is normal. For example, when the fourth response frame is normal, the master device directly allocates a device address to the slave device corresponding to the fourth response frame.
[0089] It should be noted that if the fourth response frame is a conflict response frame, the master device continues to update the sequence number string and the mask, and continues to send broadcast frames according to the updated sequence number string and the mask. The slave device performs matching according to the new preset bits. The processing is similar to the above implementation methods.
[0090] If the fourth response frame is a collision response frame, the master device acquires a target sequence number string and a target mask, and sends a target broadcast frame based on the target sequence number string and the target mask. The slave device acquires a target sequence number string and a target mask corresponding to the target broadcast frame, and calculates target to-be-matched information by performing calculation on data of a target preset bit in the target sequence number and the target mask. If the target to-be-matched information is consistent with the target sequence number string, the slave device feeds back a target response frame based on the target sequence number. If the response frame currently received by the master device is a normal response frame, the master device allocates a device address to the corresponding slave device. If the response frame currently received by the master device is a collision response frame, the master device returns to the step of acquiring the target sequence number string and the target mask until the master device receives a normal response frame. The target preset bit corresponds to the target sequence number string in a one-to-one manner.
[0091] Further, in a feasible implementation, after step S120, the address allocation method further includes step C110:
[0092] In step C110, if the first slave device does not receive the address allocation frame sent by the master device within a first preset time period after feeding back the first response frame, the first slave device feeds back the first response frame.
[0093] In the embodiment of the application, the response mode adopts non-master-slave response. The first slave device starts timing after feeding back the first response frame. If the first slave device does not receive the address allocation frame sent by the master device within the first preset time period, the first slave device feeds back the first response frame. If there is a bus conflict, the master device cannot send the address allocation frame. At this time, the plurality of first slave devices continuously feed back the first response frame to the master device at intervals of the first preset time period, so that the master device can finally receive the complete response frame of a certain first slave device. At this time, the master device allocates a device address to the first slave device of the response frame, and the other first slave devices that have not been allocated continue to feed back the first response frame to the master device until the plurality of first slave devices all receive the address allocation frame sent by the master device, and the address allocation of the plurality of first slave devices is completed.
[0094] The first preset time period can be reasonably set.
[0095] Further, in a feasible implementation, after step S120, the address allocation method further includes step C120:
[0096] In step C120, if the second slave device does not receive the second response frame fed back by the slave device within a second preset time period after sending the first broadcast frame, the master device returns to the step of acquiring the first sequence number string and the first mask.
[0097] In the embodiment, the master device counts time within the second preset time period after sending the first broadcast frame, and if the second response frame fed back by the slave device is not received within the second preset time period, the master device returns to the step of obtaining the first serial number string and the first mask, so as to allocate the device address to the slave device again by using the newly obtained first serial number string and the first mask.
[0098] The second preset time period can be reasonably set.
[0099] It should be noted that in other embodiments, any device on the bus device can actively send frame information, such as actively sending the SN of the device by using the frame information, and other devices on the bus device can select whether to establish a connection and communicate with the device corresponding to the frame information according to the requirement. In the embodiment, the address allocation method is compatible with star topology, bus topology and mesh topology from the aspect of topology structure, and through the introduction of the processing mode of data conflict, the bus conflict is caused when multiple devices respond, and through the detection from the manufacturer code to the device serial code, the device address can be accurately allocated to the devices of the same manufacturer. In other embodiments, hierarchical detection can also be introduced, for example, a detection module is added to detect the slave device from the aspects of manufacturer code, device type, SN, software and hardware version, so as to accelerate the detection process and improve the efficiency of device address allocation.
[0100] In the embodiment of the application, the master device obtains the first serial number string and the first mask; the master device sends a first broadcast frame based on the first serial number string and the first mask, wherein if the first serial number of the first slave device in the slave device matches the received first broadcast frame, the first slave device feeds back a first response frame; when the second response frame is received, the master device allocates a device address to the slave device corresponding to the second response frame. The master device sends the first broadcast frame in the local area network based on the first serial number string and the first mask, each slave device matches the first broadcast frame with the second manufacturer code of the slave device, the first slave device that matches successfully feeds back the first response frame, and the master device allocates a device address to the slave device corresponding to the second response frame when the second response frame is received, so as to realize accurate allocation of the device address allocation, process the address scanning and allocation process from the pure software point of view, reduce the hardware dependence in the device address allocation process, and improve the efficiency and flexibility of the device address allocation.
[0101] It should be noted that the above examples are only used for understanding the application and do not constitute a limitation on the address allocation method of the application, and more forms of simple transformation based on the technical concept are within the protection scope of the application.
[0102] The core innovation and advantage of the application lies in that it systematically solves the main defects of the existing decentralized, randomized or periodic allocation method, by:
[0103] Centralized control: The address allocation authority is centralized in the master device, realizing the controllability and knowability of the topology.
[0104] Deterministic algorithm: The efficient binary tree search algorithm is used to replace random delay or competition, and the allocation process is fast and predictable.
[0105] High compatibility and flexibility: Support multiple protocols and variable-length UID, adapt to complex scenarios.
[0106] Enhanced reliability: Through hierarchical conflict processing and identity authentication, ensure that the allocation result is 100% correct and improve system security.
[0107] Simplified implementation: No clock synchronization, random number generation or complex timing, reducing the hardware and software requirements of the slave device and facilitating porting.
[0108]
[0109] The application also provides an address allocation device, please refer to Figure 2 , the address allocation device comprises:
[0110] The acquisition module 10 is used for acquiring a first serial number string and a first mask;
[0111] The sending module 20 is used for sending a first broadcast frame based on the first serial number string and the first mask, wherein if the first serial number of a first slave device in the slave device matches the received first broadcast frame, the first slave device feeds back a first response frame;
[0112] The allocation module 30 is used for allocating a device address to the slave device corresponding to the second response frame when the second response frame is received.
[0113] The address allocation device provided by the application adopts the address allocation method in the above-mentioned embodiments, which can solve the technical problems of how to improve the efficiency and flexibility of device address allocation. Compared with the prior art, the address allocation device provided by the application has the same beneficial effects as the address allocation method provided by the above-mentioned embodiments, and the other technical features in the address allocation device are the same as the features disclosed in the above-mentioned embodiments, which will not be repeated here.
[0114] The application provides an address allocation device, which comprises at least one processor and a memory in communication connection with the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the address allocation method in the above-mentioned embodiment one.
[0115] The following refers to Figure 3The diagram illustrates a structural schematic of an address allocation device suitable for implementing embodiments of this application. The address allocation device in these embodiments may include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Description), PMPs (Portable Media Players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. Figure 3 The address allocation device shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.
[0116] like Figure 3 As shown, the address allocation device may include a processing unit 1001 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 1002 or a program loaded from storage device 1003 into random access memory (RAM) 1004. The RAM 1004 also stores various programs and data required for the operation of the address allocation device. The processing unit 1001, ROM 1002, and RAM 1004 are interconnected via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to the I / O interface 1006: input devices 1007 including, for example, touchscreens, touchpads, keyboards, mice, image sensors, microphones, accelerometers, gyroscopes, etc.; output devices 1008 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 1003 including, for example, magnetic tapes, hard disks, etc.; and communication devices 1009. Communication device 1009 allows the address allocation device to communicate wirelessly or wiredly with other devices to exchange data. Although the figure shows address allocation devices with various systems, it should be understood that implementation or possession of all the systems shown is not required. More or fewer systems may be implemented alternatively.
[0117] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product comprising a computer program carried on a computer readable medium, the computer program containing program codes for executing the method shown in the flowchart. In such embodiments, the computer program can be downloaded and installed from a network through a communication device, or installed from the storage device 1003, or installed from the ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiments disclosed in the present application are executed.
[0118] The address allocation device provided by the present application adopts the address allocation method in the above-mentioned embodiments, and can solve the technical problem of how to improve the efficiency and flexibility of device address allocation. Compared with the prior art, the address allocation device provided by the present application has the same beneficial effects as the address allocation method provided by the above-mentioned embodiments, and other technical features in the address allocation device are the same as the features disclosed in the previous embodiment method, which will not be repeated here.
[0119] It should be understood that various parts of the present application can be realized by hardware, software, firmware or a combination thereof. In the description of the above-mentioned embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0120] The above is merely specific embodiments of the present application, but the protection scope of the present application is not limited thereto, and any person skilled in the art can easily think of changes or replacements within the technical scope disclosed in the present application, which should be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
[0121] The present application provides a computer readable storage medium having stored thereon computer readable program instructions (i.e. computer program) for executing the address allocation method in the above-mentioned embodiments.
[0122] The computer readable storage medium provided in the present application may, for example, be a U disk, but is not limited to an electric, magnetic, optical, electromagnetic, infrared, or semiconductor system, system, or device, or any combination of the above. More specific examples of the computer readable storage medium may include, but are not limited to, an electric connection with one or more conductive wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present embodiment, the computer readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, system, or device. The program code contained on the computer readable storage medium can be transmitted by any suitable medium, including but not limited to an electric wire, an optical cable, an RF (Radio Frequency), and the like, or any suitable combination of the above.
[0123] The above computer readable storage medium may be contained in the address allocation device, or may exist separately without being assembled into the address allocation device.
[0124] The above computer readable storage medium carries one or more programs, which, when executed by the address allocation device, cause the address allocation device to: a master device acquires a first serial number string and a first mask; the master device sends a first broadcast frame based on the first serial number string and the first mask, wherein if a first serial number of a first slave device among the slave devices matches the received first broadcast frame, the first slave device feeds back a first response frame; when a second response frame is received, the master device allocates a device address to a slave device corresponding to the second response frame.
[0125] Computer program code for carrying out operations of the present application can be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C++ or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code can execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or the connection can be made to an external computer (for example, through the Internet using an Internet Service Provider).
[0126] The flow diagrams and the block diagrams in the drawings are illustrations of architectures, functionalities, and operations of possible implementations of systems, methods, and computer program products according to various embodiments of the present application. In this regard, each block in the flow diagrams or block diagrams can represent a module, a segment, or a portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that in some alternative implementations, the functions noted in the blocks can occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently or the blocks may
[0127] The modules involved in the embodiments of the present application can be implemented in the form of software or in the form of hardware. In some cases, the name of the module does not constitute a limitation on the module itself.
[0128] The readable storage medium provided by the present application is a computer readable storage medium, which stores computer readable program instructions (i.e. computer program) for executing the address allocation method described above, and can solve the technical problem of how to improve the efficiency and flexibility of device address allocation. Compared with the prior art, the computer readable storage medium provided by the present application has the same beneficial effects as the address allocation method provided by the above embodiments, which will not be described here.
[0129] The application further provides a computer program product comprising a computer program which, when executed by a processor, implements the steps of the address allocation method as described above.
[0130] The computer program product provided by the application can solve the technical problem of how to improve the efficiency and flexibility of device address allocation. Compared with the prior art, the beneficial effects of the computer program product provided by the application are the same as those of the address allocation method provided by the above-mentioned embodiments, and are not described here.
[0131] The above only describes some embodiments of the application, and does not limit the patent scope of the application. Any equivalent structural transformation, direct / indirect application in other related technical fields, or direct / indirect application in other related technical fields based on the technical concept of the application and the content of the specification and drawings are included in the patent protection scope of the application.
Claims
1. An address allocation method, characterized in that, The address allocation method includes: The master device obtains the first serial number string and the first mask; The master device sends a first broadcast frame based on the first serial number string and the first mask. If the first serial number of the first slave device matches the received first broadcast frame, the first slave device sends back a first response frame. Upon receiving the second response frame, the master device assigns a device address to the slave device corresponding to the second response frame; The master device sends a first broadcast frame based on the first sequence number string and the first mask. The step of the first slave device sending back a first response frame if the first sequence number of the first slave device matches the received first broadcast frame includes: The master device sends a first broadcast frame based on a first serial number string and a first mask. The first slave device obtains the first serial number string and the first mask corresponding to the first broadcast frame, and calculates the data of the first preset bit in the first serial number and the first mask to obtain first matching information. If the first matching information is consistent with the first serial number string, the first slave device feeds back a first response frame based on the first serial number. The first preset bit is the highest bit or the two highest bits in the serial number. When the second response frame is received, the step of the master device allocating a device address to the slave device corresponding to the second response frame includes: The master device determines whether the second response frame is a normal response frame; If the second response frame is a conflict response frame, the master device obtains the second sequence number string and the second mask; The master device sends a second broadcast frame based on the second serial number string and the second mask. The second slave device obtains the second serial number string and the second mask corresponding to the second broadcast frame, and calculates the second matching information by using the data of the second preset bit in the third serial number of the second slave device and the second mask. If the second matching information is consistent with the second serial number string, the second slave device feeds back a third response frame based on the third serial number. The second preset bit is the least significant bit or the two least significant bits in the serial number. Upon receiving the fourth response frame, the master device assigns a device address to the slave device corresponding to the fourth response frame.
2. The address allocation method as described in claim 1, characterized in that, After the master device determines whether the second response frame is a normal response frame, the method further includes: If the second response frame is a normal response frame, the master device obtains the second sequence number in the second response frame and sends an address allocation frame to the slave device corresponding to the second response frame based on the second sequence number.
3. The address allocation method as described in claim 2, characterized in that, After the step of the master device sending the first broadcast frame based on the first sequence number string and the first mask, the address allocation method further includes: If the first slave device does not receive an address allocation frame from the master device within a first preset time period after sending back the first response frame, then the first slave device sends back the first response frame.
4. The address allocation method as described in any one of claims 1 to 3, characterized in that, After the step of the master device sending the first broadcast frame based on the first sequence number string and the first mask, the address allocation method further includes: If no second response frame is received from the slave device within a second preset time period after the first broadcast frame is sent, the process returns to the step of the master device obtaining the first serial number string and the first mask.
5. An address allocation device, characterized in that, The address allocation device includes: The acquisition module is used to acquire the first sequence number string and the first mask; The sending module is configured to send a first broadcast frame based on the first sequence number string and the first mask, wherein if the first sequence number of the first slave device in the slave device matches the received first broadcast frame, the first slave device sends back a first response frame. The allocation module is used to allocate a device address to the slave device corresponding to the second response frame when the second response frame is received; The sending module is further configured to: send a first broadcast frame based on a first sequence number string and a first mask, wherein the first slave device obtains the first sequence number string and the first mask corresponding to the first broadcast frame, and calculates the data of the first preset bit in the first sequence number and the first mask to obtain first matching information; if the first matching information is consistent with the first sequence number string, the first slave device feeds back a first response frame based on the first sequence number, wherein the first preset bit is the highest bit or the highest two bits in the sequence number; The allocation module is further configured to: Determine whether the second response frame is a normal response frame; If the second response frame is a conflict response frame, then obtain the second sequence number string and the second mask; Based on the second sequence number string and the second mask, a second broadcast frame is sent. The second slave device in the slave device obtains the second sequence number string and the second mask corresponding to the second broadcast frame, and calculates the data of the second preset bit in the third sequence number of the second slave device and the second mask to obtain the second matching information. If the second matching information is consistent with the second sequence number string, the second slave device feeds back a third response frame based on the third sequence number. The second preset bit is the least significant bit or the two least significant bits in the sequence number. Upon receiving the fourth response frame, a device address is assigned to the slave device corresponding to the fourth response frame.
6. An address allocation device, characterized in that, The device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the address allocation method as described in any one of claims 1 to 4.
7. A storage medium, characterized in that, The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, it implements the steps of the address allocation method as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Method for automatically allocating RS485 slave device addresses
CN111371659A
Bus address allocation method and bus system
CN112929465A
Efficient and repeatable RS-485 bus address allocation method based on bit competition mechanism
CN116016447A
Multi-device address allocation method, system and device
CN117499368A