CAN gateway dynamic addressing processing method and device
By using a dynamic addressing method that coordinates CAN gateways and terminals, the inefficiency and complex operation and maintenance of traditional CAN networks in dynamic and large-scale scenarios are solved, enabling efficient automatic address allocation for CAN terminals and flexible network expansion.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-02
- Publication Date
- 2026-03-10
AI Technical Summary
Traditional CAN network addressing methods are inefficient, complex to operate and maintain, and lack flexibility in dynamic and large-scale scenarios, and cannot support plug-and-play and dynamic addition of terminals.
A dynamic addressing method is adopted, in which the CAN gateway and the terminal work together. The terminal generates a random short address request, and the gateway performs arbitration and conflict resolution to achieve fully automatic address allocation. The availability of the address is ensured by combining a short address list and network detection.
It achieves efficient dynamic allocation of short addresses during the CAN terminal activation process, reduces labor costs, supports smooth network expansion and flexible adjustment, and improves network scalability and operation and maintenance efficiency.
Smart Images

Figure CN121644529A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application relates to the field of CAN communication technology, in particular to a CAN gateway dynamic addressing processing method and device. BACKGROUND
[0002] In the process of CAN terminal opening in campus and small and medium-sized enterprise informatization, the following two kinds mainly exist in the traditional addressing mode: Hardware addressing: before network deployment, a unique physical address is set for each node through manual configuration (such as code switch, jumper cap). The address is hard-coded in the communication message as a static identifier of the node.
[0003] Addressing card addressing: a dedicated physical or logical "addressing card" is used as a medium, and the address is "injected" into the terminal through close-range interaction (such as card swiping, code scanning) when the terminal is opened. This is essentially a standardized and reusable hardware addressing method.
[0004] Although the above methods are feasible in simple and static small networks, their inherent limitations are increasingly prominent in the development of modern informationization scenarios that are dynamic and large-scale: Low deployment efficiency: relying on manual setting one by one, the opening speed is slow, the labor cost is high, and it cannot adapt to the large-scale deployment demand of the large number of terminals and the scattered location.
[0005] Complex operation and management: the address is strongly bound to the physical device or the addressing medium, and when the terminal needs to be replaced, expanded or adjusted in network position, physical configuration must be performed again, the process is cumbersome, and the maintenance cost is high.
[0006] Poor flexibility and scalability: the network topology structure is fixed, it is difficult to support plug-and-play and dynamic joining of terminals, which seriously restricts the smooth expansion and flexible adjustment of the network.
[0007] In order to fundamentally overcome these bottlenecks, dynamic addressing technology emerges as the times require and becomes an inevitable choice for the development of modern CAN network. CN 201910979964.8 proposes a self-organizing network method, when the intelligent gateway is powered on first and the intelligent device end is powered on later, the intelligent device end is powered on and initialized, reads the short address and sends the short address to the intelligent gateway; the intelligent gateway receives the short address and analyzes whether the address needs to be allocated; if the short address needs to be allocated, the intelligent gateway sends data to the intelligent device end for short address allocation. However, In order to solve the above problems, people have been seeking an ideal technical solution. SUMMARY
[0008] Therefore, it is necessary to provide a CAN gateway dynamic addressing processing method and device in view of the above technical problems.
[0009] To achieve the above objectives, the first aspect of the present invention provides: a dynamic addressing processing method for a CAN gateway, applied to a CAN gateway, comprising the following steps: The short address acquisition request initiated by the CAN terminal is obtained through the CAN port. The short address acquisition request includes a random short address generated by the CAN terminal after startup. Check if a short address list has been generated for the current CAN port. If not, generate a short address list. Otherwise, check if the short address list already contains a short address corresponding to the CAN terminal. If the short address corresponding to the CAN terminal already exists in the short address list, send the corresponding short address to the CAN terminal; otherwise, check if there is a free short address in the short address list under the current CAN port. If a free short address is available, a free short address is randomly selected and sent to the CAN terminal; if no free short address is available, the availability of the random short address is checked. When a random short address is available, assign a random short address to the CAN terminal; When a random short address is unavailable, a new random address is actively generated and it is determined whether the new random address is greater than or equal to a limit value; if the new random address is less than the limit value, the new random address is assigned to the CAN terminal.
[0010] Further, verifying the availability of the random short address includes: Check if the random short address is within the valid range; at the same time, check if the address is smaller than the set security limit. If all conditions are met, then check if the random short address is in the short address list under the current CAN port; If it is in the short address list, then it is further determined whether the random short address has been assigned to other CAN terminals. If it has not been assigned to other CAN terminals, then the random short address is determined to be available. If it has been assigned to other CAN terminals, then the random short address is determined to be unavailable. If the address is not in the short address list, an address probe packet is sent and a conflict report is waited for. If a conflict report is received from an existing CAN terminal in the network within a preset time, the random short address is determined to be unavailable; otherwise, the random short address is determined to be available.
[0011] To achieve the above objectives, a second aspect of the present invention provides a CAN gateway dynamic addressing processing apparatus, comprising: The CAN gateway has multiple CAN ports, and each CAN port is connected to at least one CAN terminal; The CAN gateway also includes a web-based visual management page and a dynamic addressing module; The dynamic addressing module is used to obtain a short address acquisition request initiated by the CAN terminal through the CAN port. The short address acquisition request includes a random short address generated by the CAN terminal after startup. Check if a short address list has been generated for the current CAN port. If not, generate a short address list. Otherwise, check if the short address list already contains a short address corresponding to the CAN terminal. If the short address corresponding to the CAN terminal already exists in the short address list, send the corresponding short address to the CAN terminal; otherwise, check if there is a free short address in the short address list under the current CAN port. If a free short address is available, a free short address is randomly selected and sent to the CAN terminal; if no free short address is available, the availability of the random short address is checked. When a random short address is available, assign a random short address to the CAN terminal; When a random short address is unavailable, a new random address is actively generated and it is determined whether the new random address is greater than or equal to a limit value; if the new random address is less than the limit value, the new random address is assigned to the CAN terminal.
[0012] To achieve the above objectives, a third aspect of the present invention provides a computer device, characterized in that it includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; the memory is used to store computer programs; and the processor, when executing the program stored in the memory, implements the CAN gateway dynamic addressing processing method as described above.
[0013] To achieve the above objectives, a fourth aspect of the present invention provides a computer-readable storage medium having instructions stored thereon that, when executed by one or more processors, cause the processors to perform the CAN gateway dynamic addressing processing method as described above.
[0014] To achieve the above objectives, a fifth aspect of the present invention provides a computer program product, including a computer program that, when executed by a processor, implements the above-described CAN gateway dynamic addressing processing method.
[0015] The beneficial effects of this invention are as follows: In the CAN terminal activation process, the CAN gateway and the terminal work together to achieve dynamic addressing. After startup, the terminal program generates a random short address and sends a request to the CAN gateway based on this address. Upon receiving the request, the CAN gateway determines whether the requested short address is available. The entire activation process only requires correct wiring and power-on to efficiently and dynamically allocate short addresses for each CAN terminal. Attached Figure Description
[0016] Figure 1This is a flowchart illustrating the CAN gateway dynamic addressing processing method of the present invention; Figure 2 This is a schematic diagram of the CAN gateway dynamic addressing processing device of the present invention. Detailed Implementation
[0017] The technical solution of the present invention will be further described in detail below through specific embodiments.
[0018] Example 1 This embodiment proposes a dynamic addressing processing method for CAN gateways, applied to CAN gateways, such as... Figure 1 As shown, it includes the following steps: The CAN terminal obtains a short address request through the CAN port. The short address request includes a random short address generated by the CAN terminal after startup. Further, the CAN terminal generates a random short address based on the long address of the CAN terminal; or the CAN terminal directly uses the lower two bits of the long address of the CAN terminal as the random short address. This method can reduce address conflicts.
[0019] Check if a short address list has been generated for the current CAN port. If not, generate a short address list; otherwise, check if the short address list already contains a short address corresponding to the CAN terminal.
[0020] If a short address corresponding to the CAN terminal already exists in the short address list, the corresponding short address is sent to the CAN terminal; otherwise, it is checked whether there is a free short address in the short address list of the current CAN port.
[0021] If a free short address is available, a free short address is randomly selected and sent to the CAN terminal; if no free short address is available, the availability of a random short address is checked.
[0022] When a random short address is available, assign a random short address to the CAN terminal.
[0023] When a random short address is unavailable, a new random address is actively generated and it is determined whether the new random address is greater than or equal to a limit value; if the new random address is less than the limit value, the new random address is assigned to the CAN terminal.
[0024] The above scheme adopts a hybrid architecture of terminal proposal and gateway arbitration, consisting of a CAN terminal, a CAN gateway, and an upper-layer application. The CAN terminal is responsible for generating random address proposals, while the CAN gateway is responsible for address arbitration and conflict resolution. The two work together to achieve fully automatic address allocation.
[0025] Specifically, the workflow is as follows: Phase 1: Terminal initialization and address generation; After the terminal device is powered on, it first attempts to read the historical address stored in the non-volatile memory. If no historical address is found, it starts a random address generation algorithm to generate a random short address.
[0026] Specifically, high-quality random numbers can be generated by combining multiple entropy sources such as device MAC address, hardware clock count, and analog noise sources, producing candidate addresses within a predefined address range (e.g., 0x0100 to 0xFFFE). Alternatively, the lower two bits of the long address of the CAN terminal can be used directly as the short random address.
[0027] Phase Two: CAN Gateway Arbitration Decision; After receiving a short address acquisition request from a CAN terminal, the CAN gateway initiates a three-level decision-making process: Identity recovery check: The CAN gateway checks whether there is already a short address corresponding to the CAN terminal in the short address list. If there is, it directly sends the corresponding short address to the CAN terminal.
[0028] Short address list priority allocation: For a new CAN terminal, if there is no corresponding short address in the short address list, an available address will be randomly selected from the short address list first.
[0029] It is understandable that the addresses in the short address list are managed using consecutive address segments to ensure the orderly and efficient allocation of addresses.
[0030] Intelligent random allocation: When the free addresses in the short address list are exhausted, the CAN gateway first verifies the availability of the random short address proposed by the terminal. If the random short address is available, it is directly confirmed; if there is an address conflict, the CAN gateway actively generates a new short address and verifies its availability. The availability can be retried up to 3 times to avoid infinite loops.
[0031] Phase 3: Lightweight Conflict Protection; All dynamically allocated addresses (including those proposed by terminals and generated by the gateway) must pass a lightweight collision detection process. The CAN gateway broadcasts address probe packets to the network and listens for collision responses within a preset timeout period, such as 50ms. If a collision is detected, the problematic address is immediately marked and a reallocation process is triggered. If no collision is detected, the address is then distributed.
[0032] Further, verifying the availability of the random short address includes: Check if the random short address is within the valid range; at the same time, check if the address is less than the set security limit value; for example, the valid range is 0x0001 to 0xFFFE, which can be adjusted according to system capacity and protocol in practice; if the security limit value is 0x0100 and the random short address is 0x0055, then check if 0x0055 is within the valid range, and at the same time check if 0x0055 is less than 0x0100; it should be noted that the security limit value is essentially a security threshold or partition boundary, and its core purpose is to prevent uncontrollable random short addresses generated by the CAN terminal from intruding into the reserved address range that the CAN gateway must protect; If all conditions are met, then check if the random short address is in the short address list under the current CAN port; If it is in the short address list, then it is further determined whether the random short address has been assigned to other CAN terminals. If it has not been assigned to other CAN terminals, then the random short address is determined to be available. If it has been assigned to other CAN terminals, then the random short address is determined to be unavailable. If the address is not in the short address list, an address probe packet is sent and a conflict report is waited for. If a conflict report is received from an existing CAN terminal in the network within a preset time, the random short address is determined to be unavailable; otherwise, the random short address is determined to be available.
[0033] The above scheme employs a dual verification mechanism: first, a quick check is performed using the short address list of the CAN gateway; if the short address list cannot be determined, real-time verification is performed through network detection.
[0034] Furthermore, during the time between the gateway sending a probe packet and making a judgment, other terminals may be requesting the same random address in parallel. For example, CAN terminal A generates a random address 0x1234 and requests it from the CAN gateway. Almost simultaneously, CAN terminal B also generates the same random address 0x1234 and requests it from the CAN gateway. When the CAN gateway processes terminal A's request, it finds that 0x1234 is not in the short address list and begins sending probe packets. While the CAN gateway waits for a probe response, CAN terminal B's request also arrives at the gateway. Since address 0x1234 has not yet been officially assigned, the CAN gateway may consider both requests valid, resulting in double allocation.
[0035] To prevent this from happening, the random short address is added to the short address list and marked as pending allocation before sending the address probe packet; During the detection period, if a short address acquisition request containing the same random short address is received from another CAN terminal, the short address acquisition request will be rejected directly. When the probe times out and no conflict is reported, the pending allocation status is changed to allocated; if a conflict is received, the pending allocation status is cleared.
[0036] Understandably, after completing address allocation, the CAN gateway updates its local short address list and persistently stores the allocation results to ensure rapid recovery after the CAN terminal restarts. Simultaneously, the CAN gateway periodically cleans up expired addresses to maintain the effective utilization of address resources.
[0037] Finally, when a CAN terminal under a CAN gateway needs to be replaced with another CAN gateway, clear the CAN terminal's SN information on the current CAN gateway's management page; or, when multiple CAN terminals under the same CAN gateway need to be replaced with other CAN gateways, restart the CAN gateway.
[0038] It should be understood that although the steps in the flowcharts of the above embodiments are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the above embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0039] Example 2 Based on the same inventive concept, this application also provides a CAN gateway dynamic addressing processing device for implementing the CAN gateway dynamic addressing processing method described above. The solution provided by this device is similar to the implementation described in the above method; therefore, the specific limitations in one or more CAN gateway dynamic addressing processing device embodiments provided below can be found in the limitations of the CAN gateway dynamic addressing processing method described above, and will not be repeated here.
[0040] Specifically, the CAN gateway dynamic addressing processing device, such as Figure 2 As shown, it includes: The CAN gateway has multiple CAN ports, and each CAN port is connected to at least one CAN terminal; The CAN gateway also includes a web-based visual management page and a dynamic addressing module; The dynamic addressing module is used to obtain a short address acquisition request initiated by the CAN terminal through the CAN port. The short address acquisition request includes a random short address generated by the CAN terminal after startup. Check if a short address list has been generated for the current CAN port. If not, generate a short address list. Otherwise, check if the short address list already contains a short address corresponding to the CAN terminal. If the short address corresponding to the CAN terminal already exists in the short address list, send the corresponding short address to the CAN terminal; otherwise, check if there is a free short address in the short address list under the current CAN port. If a free short address is available, a free short address is randomly selected and sent to the CAN terminal; if no free short address is available, the availability of the random short address is checked. When a random short address is available, assign a random short address to the CAN terminal; When a random short address is unavailable, a new random address is actively generated and it is determined whether the new random address is greater than or equal to a limit value; if the new random address is less than the limit value, the new random address is assigned to the CAN terminal.
[0041] Example 3 This embodiment provides a computer device, which includes a processor, a memory, an input / output interface, a communication interface, a display unit, and an input device. The processor, memory, and input / output interface are connected via a system bus, and the communication interface, display unit, and input device are also connected to the system bus via the input / output interface. The processor provides computing and control capabilities. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The input / output interface is used for exchanging information between the processor and external devices. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, NFC (Near Field Communication), or other technologies. When the computer program is executed by the processor, it implements the CAN gateway dynamic addressing processing method described in Embodiment 1. The display unit of the computer device forms a visually visible image and can be a display screen, a projection device, or a virtual reality imaging device. The display screen can be an LCD screen or an e-ink screen. The input device of the computer device can be a touch layer covering the display screen, or buttons, trackballs, or touchpads set on the casing of the computer device, or external keyboards, touchpads, or mice, etc.
[0042] Example 4 Based on the above embodiments, this embodiment provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the CAN gateway dynamic addressing processing method described in Embodiment 1.
[0043] Example 5 Based on the above embodiments, this embodiment provides a computer program product, including a computer program that, when executed by a processor, implements the CAN gateway dynamic addressing processing method described in Embodiment 1.
[0044] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit them; although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications can still be made to the specific implementation of the present invention or equivalent substitutions can be made to some technical features without departing from the spirit of the technical solutions of the present invention, and all such modifications and substitutions should be covered within the scope of the technical solutions claimed in the present invention.
Claims
1. A CAN gateway dynamic addressing processing method, applied to a CAN gateway, and characterized in that, The method comprises the following steps: obtaining a short address application initiated by a CAN terminal through a CAN port, the short address application comprising a random short address generated by the CAN terminal after startup; checking whether a short address list has been generated by the current CAN port, and if not, generating the short address list, otherwise, checking whether the short address list already has a short address corresponding to the CAN terminal; when the short address list already has a short address corresponding to the CAN terminal, issuing the corresponding short address to the CAN terminal, otherwise, checking whether there is a free short address in the short address list under the current CAN port; if there is a free short address, randomly selecting a free short address and issuing it to the CAN terminal, if there is no free short address, checking whether the random short address is available; when the random short address is available, assigning the random short address to the CAN terminal; when the random short address is not available, generating a new random address and checking whether the new random address is greater than or equal to a limit value, and when the new random address is less than the limit value, assigning the new random address to the CAN terminal.
2. The CAN gateway dynamic addressing processing method according to claim 1, characterized in that, checking whether the random short address is available comprises: checking whether the random short address is within a valid range, and checking whether the address is less than a set safety limit value; if both conditions are met, checking whether the random short address is in the short address list under the current CAN port; if it is in the short address list, further checking whether the random short address has been assigned to other CAN terminals, if not, judging that the random short address is available, if it has been assigned to other CAN terminals, judging that the random short address is not available; if it is not in the short address list, sending an address probe packet and waiting for a conflict report, if a conflict report returned by an existing CAN terminal in the network is received within a preset time, judging that the random short address is not available, otherwise, judging that the random short address is available.
3. The CAN gateway dynamic addressing processing method according to claim 1 or 2, characterized in that, before sending the address probe packet, adding the random short address to the short address list and marking it as a pending allocation state; during the probe, if a short address application initiated by other CAN terminals containing the same random short address is received, directly rejecting the short address application; when the probe times out and no conflict report is received, changing the pending allocation state to an allocated state, if a conflict report is received, clearing the pending allocation state.
4. The CAN gateway dynamic addressing processing method according to claim 1, characterized in that, when a CAN terminal under a CAN gateway needs to be replaced with another CAN gateway, clearing the sn information of the CAN terminal on the management page of the current CAN gateway, or when multiple CAN terminals under the same CAN gateway need to be replaced with another CAN gateway, restarting the CAN gateway.
5. A CAN gateway dynamic addressing processing device, characterized in that: the CAN gateway has multiple CAN ports, each CAN port being connected to at least one CAN terminal; the CAN gateway further comprises a web visual management page and a dynamic addressing module; the dynamic addressing module is configured to obtain a short address application initiated by a CAN terminal through a CAN port, the short address application comprising a random short address generated by the CAN terminal after startup; Check whether the current CAN port has generated a short address list, if not, generate a short address list, otherwise, check whether the short address list has a short address corresponding to the CAN terminal; When the short address list has a short address corresponding to the CAN terminal, the corresponding short address is issued to the CAN terminal, otherwise, check whether there is a free short address in the short address list under the current CAN port; If there is a free short address, randomly select a free short address and issue it to the CAN terminal; if there is no free short address, check whether the random short address is available; When the random short address is available, assign the random short address to the CAN terminal; When the random short address is not available, a new random address is generated and it is judged whether the new random address is greater than or equal to a limit value; when the new random address is less than the limit value, the new random address is assigned to the CAN terminal.
6. The CAN gateway dynamic addressing processing apparatus according to claim 5, wherein: The CAN terminal includes at least one of a water control terminal, an electric control terminal, a gas control terminal, a monitoring terminal, and a lighting control terminal.
7. The CAN gateway dynamic addressing processing apparatus of claim 6, wherein: The web visualization management page is used to query and clear the existing short address information.
8. A computer device, comprising: The computer device includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory complete mutual communication through the communication bus; The memory is used to store a computer program; The processor is used to execute the program stored on the memory, and realize the CAN gateway dynamic addressing processing method in any one of claims 1 to 4.
9. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to realize the CAN gateway dynamic addressing processing method in any one of claims 1 to 4.
10. A computer program product comprising a computer program, characterized in that, The computer program is executed by the processor to realize the CAN gateway dynamic addressing processing method in any one of claims 1 to 4.
Citation Information
Patent Citations
Wired smart home system with ad hoc network and ad hoc network method thereof
CN110572306A