A sensor terminal node upgrade method and system in Modbus TCP network scenario
By subcontracting and frame encapsulation in the Modbus TCP network, upgrading firmware, and performing identity authentication and serial number verification, the problem that the traditional Modbus protocol cannot ensure firmware integrity is solved, and the security and reliability of sensor terminal nodes under the Modbus TCP network is achieved. Firmware upgrades reduce maintenance costs and development difficulties.
Patent Information
- Application Number
- CN202211367134.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-02
- Publication Date
- 2024-11-22
- Estimated Expiration
- 2042-11-02
AI Technical Summary
In the Modbus TCP network scenario, during the version upgrade of the sensor terminal node, the traditional Modbus protocol cannot ensure the integrity and reliability of the firmware, resulting in upgrade failure and equipment crash, increasing maintenance costs.
Upgrade firmware by subcontracting and frame encapsulation in Modbus TCP network, and authenticating between the server and the terminal node, ensuring the integrity and security of data transmission, using the serial number verification mechanism to ensure data coherence, and using the Bootloader program Carry out firmware upgrades to reduce manual maintenance costs.
It realizes the safe and reliable firmware upgrade of sensor terminal nodes under the Modbus TCP network, avoids equipment failures and factory repairs, reduces maintenance and development difficulties, and improves upgrade efficiency.
Smart Images

Figure CN115766444B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of Modbus TCP network, and in particular relates to a sensor terminal node upgrading method and system in a Modbus TCP network scenario. Background Art
[0002] Driven by national policies and the transformation and upgrading of manufacturing technology, China's intelligent manufacturing industry has developed rapidly, and industrial automation has leapt to a new stage. A complete set of industrial control systems can perform automatic measurement, control and movement. As a network communication protocol for managing and controlling automation equipment, MODBUS TCP communication protocol is widely used in industrial sites as a link. It connects the control gateway and a single decentralized sensor network terminal node to form a network system that can communicate information with each other and jointly complete automatic control tasks, realizing two-way serial multi-node digital communication. The sensor network constructed by the MODBUS TCP communication protocol has the advantages of decentralized control, simple system structure, and saving hardware equipment. However, in actual application scenarios, the sensor network terminal nodes need to be upgraded or maintained in the design and development process due to the lack of or changes in the previous demand analysis and the technical capabilities of developers. However, the terminal nodes are generally distributed over a wide range, with a large number and many types, and the complexity of the on-site production environment brings considerable difficulties to maintenance and upgrading. The need for manual firmware upgrades at the terminal nodes will increase the cost.
[0003] Therefore, it is necessary to use the Modbus protocol to transmit the upgrade firmware under the MODBUS TCP network, upgrade the firmware in the terminal node device, achieve the effect of remote upgrade, and thus reduce the labor cost brought by maintenance and upgrade. However, the traditional Modbus protocol directly used as a file transfer protocol will bring inconvenience to the upgrade process, because the traditional Modbus protocol cannot ensure the integrity and reliability of the upgrade firmware. And the terminal node to be upgraded has strict requirements for the upgraded firmware. The firmware after transmission must be able to run normally under the sensor terminal node. If the firmware that cannot run normally is started, the terminal node will freeze and need to be returned to the factory for repair, which greatly increases the cost of maintenance. Therefore, the present invention provides a sensor terminal node upgrade method and system under a Modbus TCP network scenario to ensure the correctness and integrity of the firmware upgraded by the device and avoid the situation of running freezes. Summary of the invention
[0004] In order to solve the above problems, the present invention provides a method and system for upgrading sensor terminal nodes in a Modbus TCP network scenario, which can transmit the upgrade file to the specified terminal node through the entire network, and perform version upgrades in accordance with the transmission protocol of the Modbus TCP network, thereby reducing maintenance costs and development difficulties. The specific technical solution is as follows:
[0005] A method for upgrading a sensor terminal node in a Modbus TCP network scenario comprises the following steps:
[0006] Step S1, the administrator uploads the upgrade firmware to the server through the web front end, and the server divides the upgrade firmware into packages and frames;
[0007] Step S2, the server sends an identity authentication instruction, and the sensor terminal node confirms that the server's identity is legitimate, then the server completes the identity authentication and obtains the Bootloader program permission to enter the sensor terminal node. If the server's identity is not legitimate, the server cannot obtain the Bootloader program permission to enter the sensor terminal node;
[0008] Step S3, the server sends an upgrade request to the sensor terminal node through the Modbus protocol, allowing the sensor terminal node to enter the Bootloader program, and the sensor terminal node enters the Bootloader program and waits for file transmission;
[0009] Step S4, the server sends a start frame of file transfer to the sensor terminal node, the sensor terminal node is ready to receive the upgraded firmware, the start frame sends the size of the upgraded firmware to the sensor terminal node, and the sensor terminal node sends a response signal of the start frame to the server;
[0010] Step S5, the server sends several transmission frames to the sensor terminal node; the sensor terminal node starts to receive and splices, assembles and stores the upgraded firmware in the order of the frames;
[0011] Step S6: After the server completes the data transmission, it sends an end frame to end the transmission of the upgrade firmware. After receiving the end frame, the sensor terminal node starts to run the new version of the upgrade firmware.
[0012] Preferably, in step S1, the administrator counts the firmware versions running on each sensor terminal node through the serial number of the sensor terminal node, classifies different sensor terminal nodes through a graphical interface, selects the sensor terminal nodes that need to be upgraded from the classification, and can select different versions of firmware to upgrade, thereby completing the management of upgraded firmware.
[0013] Preferably, in step S1, the server divides the upgraded firmware into several parts according to 128 bytes to meet the size of the transmission frame transmission data. If the size of the last packet is less than 128 bytes, 0x1A is used to fill it to 128 bytes. Finally, the server encapsulates all data packets according to the file transfer protocol and waits for sending.
[0014] Preferably, in step S2, the server and the sensor terminal node pre-save the same key for identity authentication, and the sensor terminal node determines whether the server's identity is legal by comparing the key sent by the server; specifically, a random number, a device serial number and a digital summary calculated using the SHA256 algorithm are used as the key.
[0015] Preferably, the step S3 also includes:
[0016] Before the sensor terminal node enters the Bootloader program, it will check whether the upgrade flag is set to upgrade. If the upgrade flag is set to upgrade, the sensor terminal node starts waiting for the server to send the upgrade firmware; if the upgrade flag is not set to upgrade and the sensor terminal node stores an APP program, it will jump to the APP program.
[0017] Preferably, the next 4 bytes of the function code of the start frame in step S4 are a positive sequence number and a reverse sequence number. In the start frame, the positive sequence number is 0x0000 and the reverse sequence number is 0xffff. During the entire transmission process, the sequence number will increase incrementally following the sequence number of the start frame; the start frame is responsible for transmitting the file size, converting the number of bytes of the file size according to ASCII code, converting it into hexadecimal data of the corresponding number of bytes according to the number of bits, and storing it in the data content of the 128 bytes after the sequence number. If the size of the data content is less than 128 bytes, the remaining part of the data content is filled with 0.
[0018] Preferably, the step S4 further includes:
[0019] After receiving the start frame, the sensor terminal node first checks the function code of the start frame and performs the corresponding function according to the content of the function code. If the function code does not exist in the Bootloader program, it will return a response of the function code error and wait for the server to send the correct function code;
[0020] After the function code is verified correctly, the positive sequence number and the reverse sequence number will be checked to determine whether they are equal to 0x0000 and 0xffff respectively. If the positive sequence number or the reverse sequence number does not match the value, a sequence number error response will be returned and the server will wait for the server to resend the start frame.
[0021] After the serial number is correctly determined, the sensor terminal node will convert the ASCII code representing the file size into an integer, and then start to compare whether the file size is larger than the remaining space of the sensor terminal node. If it is larger than the remaining space of the sensor terminal node, it means that the firmware is too large, and an error response of inappropriate file size is returned. It is necessary to wait for the server to resend the firmware with the appropriate size and send the start frame of the firmware that meets the requirements.
[0022] When the start frame is processed, wait for the server to send a transmission frame.
[0023] Preferably, the step S5 specifically includes:
[0024] After receiving the transmission frame, the sensor terminal node will first determine whether the function code is correct. If the function code is incorrect, it will return to step S4 and wait for the server to send a start frame again;
[0025] After the function code is judged to be correct, it is judged whether the start frame is completed. If not, a response with a sequence number error is returned, and the process returns to step S4 to wait for the server to resend the start frame.
[0026] After receiving the transmission frame, the sensor terminal node will determine whether it can receive the complete firmware based on the sequence number. This is achieved by comparing the positive sequence number and the reverse sequence number of each transmission frame. If the sequence number is disordered or missing, it will return to step S4 and wait for the start frame to be sent again.
[0027] When the sensor terminal node receives a transmission frame, if it does not receive the transmission frame within the set time, it will return to step S4 and wait for the start frame to be sent again;
[0028] When the server receives a transmission frame response, if it does not receive a transmission frame response within the set time, it will resend the start frame and retransmit the firmware.
[0029] Preferably, the step S6 specifically includes:
[0030] When the sensor terminal node receives the end frame, it first determines whether the reception of the upgraded firmware is completed. If the sensor terminal node has not received a firmware of sufficient size when receiving the end frame, the firmware has not been received and the process returns to step S4 to wait for the start frame to be sent again.
[0031] Then determine whether the sequence number is the sequence number of the end frame. If the sequence number does not belong to the sequence number of the end frame, an error response will be returned, and return to step S4 to wait for the start frame to be sent;
[0032] After the sensor terminal node completes the judgment, it returns the correct end frame response to the server, and then runs the new version of the firmware to complete the upgrade;
[0033] After the sensor terminal node receives the firmware, if the end frame is not received within the set time, it returns to step S4 and waits for the start frame to be sent again;
[0034] If the server does not receive the end frame response within the set time, the sensor terminal node sends a startup success message to the server when starting up with the new version of the firmware, notifying the server that the upgrade is complete.
[0035] A sensor terminal node upgrade system in a Modbus TCP network scenario, applied to the upgrade method, includes a server, several serial port to network interface modules, and several sensor terminal nodes;
[0036] The server is respectively connected to a number of serial port to network interface modules, and a number of the serial port to network interface modules are respectively connected to a number of sensor terminal nodes; the server communicates with the serial port to network interface module through the Modbus protocol, and the serial port to network interface module and the sensor terminal node transmit data through the serial port; the server is used to subpack and encapsulate the upgrade firmware, and transmit the upgrade firmware to the serial port to the network interface module through the Modbus protocol, and the serial port to the network interface module is used to convert the upgrade firmware transmitted by the server through the Modbus protocol into a serial port and transmit it to the sensor terminal node, and the sensor terminal node has a Bootloader program and an APP program, and the Bootloader program is used to receive the upgrade firmware sent by the server according to the file transfer protocol, and after the sensor terminal node completes the reception, it runs the new version of the firmware; the APP program is used to respond to relevant service requests from the server.
[0037] The beneficial effects of the present invention are as follows: the method provided by the present invention can transmit the upgrade file to the designated sensor terminal node through the entire network, and perform version upgrades in accordance with the transmission protocol of the Modbus TCP network, thereby reducing maintenance costs and development difficulty.
[0038] The MODBUS TCP network is based on the Modbus bus protocol transmission and follows the master-slave mode. For the traditional Modbus protocol, the present invention adds the serial number of each frame during the file transmission process, which can ensure that the upgraded firmware is coherent during the transmission process. After receiving the data, the sensor terminal node can splice the received upgraded firmware into a complete upgraded firmware in sequence, and check the continuity of the serial number, so as to avoid equipment failure caused by upgrade failure and increase labor costs for returning to the factory for repair.
[0039] Taking into account the different transmission bandwidths, the upgraded firmware will be divided into 128 bytes in the server. Therefore, the present invention can be applied to sensor terminal nodes with different performances to ensure that the transmission devices used can transmit information. The upgraded firmware is divided into 128 bytes to ensure that the sensor terminal nodes can receive it.
[0040] In the present invention, in order to prevent others from maliciously upgrading the firmware of the slave device at will, the server must obtain the identity authentication of the sensor terminal node before upgrading the sensor terminal node. The server needs to use the key obtained in advance, use the SHA256 algorithm to calculate the digital summary, and verify it with the digital summary calculated by the sensor terminal node. Only the server that has passed the verification can upgrade the sensor terminal node, and the server that has not passed the verification will be rejected by the sensor terminal node. This ensures the security of the sensor terminal node upgrade and avoids the upgrade error that requires the factory to repair and increase labor costs.
[0041] The system of the present invention adopts a combination of a serial port to network module and a sensor terminal node, which can ensure that the sensor terminal node with too low performance can also complete the firmware upgrade using the method of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following is a brief introduction to the drawings required for the specific embodiments or the description of the prior art. In all the drawings, similar elements or parts are generally identified by similar reference numerals. In the drawings, the elements or parts are not necessarily drawn according to the actual scale.
[0043] Figure 1 is a flow chart of the method of the present invention;
[0044] Figure 2 is a file transmission flow chart of the present invention;
[0045] Figure 3 This is a structural diagram of the file transmission frame format provided by an embodiment of the present invention.
[0046] Figure 4 This is a structural diagram of the correct corresponding frame format provided by an embodiment of the present invention.
[0047] Figure 5 This is a structural diagram of the error response frame format provided by an embodiment of the present invention.
[0048] Figure 6 It is a system principle diagram of the present invention. DETAILED DESCRIPTION
[0049] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0050] It should be understood that when used in this specification and the appended claims, the terms "include" and "comprises" indicate the presence of described features, integers, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or combinations thereof.
[0051] It should also be understood that the terms used in the present specification are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the present specification and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.
[0052] It should be further understood that the term "and / or" used in the present description and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
[0053] like Figure 1 As shown, the specific implementation of the present invention provides a sensor terminal node upgrade method in a Modbus TCP network scenario. The upgrade process needs to jump from the APP program to the Bootloader program, so step S1 is performed in the server, steps S2 and S3 are run in the APP program, and steps S4, S5, and S6 are run in the Bootloader program. Specifically, the following steps are included:
[0054] Step S1: The administrator uploads the upgrade firmware to the server through the web front end, and the server divides the upgrade firmware into packages and frames. Specifically, it includes:
[0055] The administrator can count the firmware versions running on each sensor terminal node through the serial number of the sensor terminal node, classify different sensor terminal nodes through a graphical interface, select the sensor terminal nodes that need to be upgraded from the classification, and select different versions of firmware to upgrade to complete the management of firmware upgrade. In this way, the specified sensor terminal node can be upgraded, the upgrade efficiency can be improved, and the upgrade cost can be reduced.
[0056] The server divides the firmware upgrade into 128 bytes, and divides it into several parts that meet the size of the transmission frame transmission data. If the size of the last packet is less than 128 bytes, 0x1A is used for padding to make it 128 bytes. Finally, the server encapsulates all the data packets according to the file transfer protocol and waits for sending. The server divides the firmware upgrade into 128 bytes, which can adapt to different transmission bandwidths and ensure that the sensor terminal node can receive it. Therefore, the present invention can be applied to slave devices with different performances to ensure that the transmission devices used can transmit information.
[0057] Step S2, the server sends an identity authentication instruction, and the sensor terminal node confirms that the server's identity is legal. The server completes the identity authentication and obtains the Bootloader program permission to enter the sensor terminal node. If the server's identity is illegal, the server cannot obtain the Bootloader program permission to enter the sensor terminal node.
[0058] Specifically, the server and the slave sensor terminal node save the same key for identity authentication. Identity authentication specifically uses the SHA256 algorithm to calculate the digital digest for comparison. The SHA256 algorithm can calculate a fixed-length 32-byte digital digest from a variable-length parameter.
[0059] Specifically, identity authentication is performed by the server and the sensor terminal node using random numbers, device serial numbers, keys and other parameters, respectively, using the SHA256 algorithm to calculate digital summaries. By comparing the digital summaries of the server and the sensor terminal node, it is determined whether the server's identity to the sensor terminal node is legal. A server whose identity is confirmed to be legal by the terminal node can enter the Bootloader program of the sensor terminal node, allowing the sensor terminal node to be upgraded.
[0060] Step S3: the server sends an upgrade request to the sensor terminal node through the Modbus protocol, allowing the sensor terminal node to enter the Bootloader program. The sensor terminal node enters the Bootloader program and waits for file transmission.
[0061] In order to prevent accidental restart, which may cause the sensor terminal node to be unable to run the APP program normally and get stuck in the Bootloader program, the sensor terminal node will check whether the upgrade flag is set to upgrade before entering the Bootloader program. If the upgrade flag is set to upgrade, the sensor terminal node starts waiting for the server to send the upgrade firmware; if the upgrade flag is not set to upgrade and the sensor terminal node has the APP program stored in it, it will jump to the APP program.
[0062] Specifically, the server will use the Modbus protocol to transmit the upgrade request, the function code is 0x06, and write the upgrade flag in the upgrade flag register, so that the sensor terminal node will perform a program jump, run the Bootloader program, identify the upgrade flag in the Bootloader program, and wait for the server to transmit the upgrade firmware. If the sensor terminal node does not pass the server's identity authentication, the server sends a request to enter the Bootloader program, and the sensor terminal node will return a response that the identity card has not been passed, and will not enter the Bootloader program.
[0063] like Figure 2 As shown, steps S4, S5, and S6 constitute the completed file transfer process, and the file transfer frame structure sent by the server is as follows: Figure 3 As shown. Figure 4 , Figure 5 As shown, the frame formats are respectively the correct and incorrect frame formats returned by the sensor terminal node in response to the file transmission data sent by the server.
[0064] Step S4, the server sends a start frame of file transfer to the sensor terminal node, the sensor terminal node is ready to receive the upgraded firmware, the start frame sends the size of the upgraded firmware to the sensor terminal node, and the sensor terminal node sends a response signal of the start frame to the server.
[0065] The start frame is the first step of the entire transmission process, ensuring that the sensor terminal node can match the attribute information of the firmware before transmission. Only after the firmware attributes and the sensor terminal node match, can the subsequent transmission be carried out. The function code used by the start frame is 0x45. The 4 bytes following the function code of the start frame are the positive sequence number and the reverse sequence number. In the start frame, the positive sequence number is 0x0000 and the reverse sequence number is 0xffff. During the entire transmission process, the positive sequence number will increase with the sequence number of the start frame, and the reverse sequence number will decrease with the sequence number of the start frame; the start frame is responsible for transmitting the file size, converting the number of bytes of the file size according to the ASCII code, converting it into hexadecimal data corresponding to the number of bytes according to the number of bits, and storing it in the data content of the 128 bytes after the sequence number. If the size of the data content is less than 128 bytes, the remaining part of the data content is filled with 0.
[0066] After receiving the start frame, the sensor terminal node first checks the function code of the start frame and performs the corresponding function according to the content of the function code. If the function code does not exist in the Bootloader program, it will return a response of the function code error and wait for the server to send the correct function code;
[0067] After the function code is verified correctly, the positive sequence number and the reverse sequence number will be checked to determine whether they are equal to 0x0000 and 0xffff respectively. If the positive sequence number or the reverse sequence number does not match the value, a sequence number error response will be returned and the server will wait for the server to resend the start frame.
[0068] After the serial number is correctly determined, the sensor terminal node will convert the ASCII code representing the file size into an integer, and then start to compare whether the file size is larger than the remaining space of the sensor terminal node. If it is larger than the remaining space of the sensor terminal node, it means that the firmware is too large, and an error response of inappropriate file size is returned. It is necessary to wait for the server to resend the firmware with the appropriate size and send the start frame of the firmware that meets the requirements.
[0069] When the start frame is processed, wait for the server to send a transmission frame.
[0070] In step S5, the server sends several transmission frames to the sensor terminal node. The transmission information is the 128-byte content of the upgrade firmware. Several frames need to be sent to complete the transmission of the entire upgrade firmware. The sensor terminal node starts to receive and splice, assemble and store the upgrade firmware in the order of the frames.
[0071] Specifically, the server sends several transmission frames carrying firmware information in sequence, and the sensor terminal node continuously receives the firmware information to form a complete firmware. The function code of the transmission frame is 0x46. In terms of sequence number, the transmission frame starts with the positive sequence number 0x0001 and the reverse sequence number starts with 0xfffe. The sequence is sorted in order, the positive sequence number starts to increase, and the reverse sequence number starts to decrease. Each transmission frame is filled with the upgraded firmware that has been divided into packages, and the size is 128 bytes. Assuming that the size of the upgraded firmware is not a multiple of 128 bytes, the data segment of the last frame of the transmission frame will be less than 128 bytes, and 0x1A will be used to fill the remaining content.
[0072] After receiving the transmission frame, the sensor terminal node will first determine whether the function code is 0x46. If the function code is incorrect, it will return to step S4 and wait for the server to send a start frame again;
[0073] After the function code is judged to be correct, it is judged whether the start frame is completed. If not, a response with a sequence number error is returned, and the process returns to step S4 to wait for the server to resend the start frame.
[0074] After receiving the transmission frame, the sensor terminal node will determine whether it can receive the complete firmware based on the sequence number. This is achieved by comparing the positive sequence number and the reverse sequence number of each transmission frame. If the sequence number is disordered or missing, it will return to step S4 and wait for the start frame to be sent again.
[0075] When the sensor terminal node receives a transmission frame, if it does not receive the transmission frame within the set time, it will return to step S4 and wait for the start frame to be sent again;
[0076] When the server receives a transmission frame response, if it does not receive a transmission frame response within the set time, it will resend the start frame and retransmit the firmware.
[0077] Step S6: After the server completes the data transmission, it sends an end frame to end the transmission of the upgrade firmware. After receiving the end frame, the sensor terminal node starts to run the new version of the upgrade firmware.
[0078] After receiving the response of the last transmission frame, the server will send an end frame. After receiving the end frame, the sensor terminal node will send an end frame response and start running the firmware. The function code of the end frame is 0x47, the positive sequence number is 0xffff, and the reverse sequence number is 0x0000; the data content of the middle 128 bytes is all 0.
[0079] When the sensor terminal node receives the end frame, it first determines whether the reception of the upgraded firmware is completed. If the sensor terminal node has not received a firmware of sufficient size when receiving the end frame, the firmware has not been received and the process returns to step S4 to wait for the start frame to be sent again.
[0080] Then determine whether the sequence number is the sequence number of the end frame. If the sequence number does not belong to the sequence number of the end frame, an error response will be returned, and return to step S4 to wait for the start frame to be sent;
[0081] After the sensor terminal node completes the judgment, it returns the correct end frame response to the server, and then runs the new version of the firmware to complete the upgrade;
[0082] After the sensor terminal node receives the firmware, if the end frame is not received within the set time, it returns to step S4 and waits for the start frame to be sent again;
[0083] If the server does not receive the end frame response within the set time, the sensor terminal node sends a startup success message to the server when starting up with the new version of the firmware, notifying the server that the upgrade is complete.
[0084] like Figure 6 As shown, the specific implementation of the present invention also provides a sensor terminal node upgrade system in a Modbus TCP network scenario, which is applied to the upgrade method, including a server, a plurality of serial port to network interface modules, and a plurality of sensor terminal nodes;
[0085] The server is respectively connected to a number of serial port to network interface modules, and a number of the serial port to network interface modules are respectively connected to a number of sensor terminal nodes; the server communicates with the serial port to network interface module through the Modbus protocol, and the serial port to network interface module and the sensor terminal node transmit data through the serial port; the server is used to subpack and encapsulate the upgrade firmware, and transmit the upgrade firmware to the serial port to the network interface module through the Modbus protocol, and the serial port to the network interface module is used to convert the upgrade firmware transmitted by the server through the Modbus protocol into a serial port and transmit it to the sensor terminal node, and the sensor terminal node has a Bootloader program and an APP program, and the Bootloader program is used to receive the upgrade firmware sent by the server according to the file transfer protocol, and after the sensor terminal node completes the reception, it runs the new version of the firmware; the APP program is used to respond to relevant service requests from the server.
[0086] The system of the present invention follows a master-slave mode, where a master device server sends a request and a slave device sensor terminal node responds according to the request.
[0087] The server can manage the sensor terminal nodes of the entire Modbus TCP network. Specifically, the administrator uses the front-end webpage graphical interface to perform operation management, which is convenient for the administrator to use the front-end webpage to monitor the data and upgrade the firmware of the sensor terminal nodes. Among them, the firmware upgrade management means that the administrator uploads the firmware to be upgraded to the server through the front-end webpage, and counts the firmware version running on each terminal node through the serial number of the sensor terminal node, and sends the upgraded firmware to the specified terminal node through the server Modbus TCP transmission, and completes the upgrade through interaction.
[0088] The serial port to network interface module converts the data transmitted by the server through Modbus TCP into RS485 bus transmission, and needs to configure the baud rate, data bit, check bit and stop bit that match the sensor terminal node. The sensor terminal node is connected to the serial port to network interface module using the UART serial port, communicates with the server through the Modbus protocol, and responds to the request sent by the server.
[0089] Those of ordinary skill in the art will appreciate that the units of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition of each example has been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0090] In the embodiments provided in the present application, it should be understood that the division of units is merely a logical function division, and there may be other division methods in actual implementation, for example, multiple units may be combined into one unit, one unit may be split into multiple units, or some features may be ignored.
[0091] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein by equivalents. These modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present invention, and they should all be included in the scope of the claims and specification of the present invention.
Claims
1. A sensor terminal node upgrade method in a Modbus TCP network scenario, It is characterized in that The following steps are involved: Step S1, the administrator uploads the upgrade firmware to the server through the web front end, and the server divides the upgrade firmware into packages and frames; Step S2, the server sends an identity authentication instruction, and the sensor terminal node confirms that the server's identity is legitimate, then the server completes the identity authentication and obtains the Bootloader program permission to enter the sensor terminal node. If the server's identity is not legitimate, the server cannot obtain the Bootloader program permission to enter the sensor terminal node; Step S3, the server sends an upgrade request to the sensor terminal node through the Modbus protocol, allowing the sensor terminal node to enter the Bootloader program, and the sensor terminal node enters the Bootloader program and waits for file transmission; Step S4, the server sends a start frame of file transfer to the sensor terminal node, the sensor terminal node is ready to receive the upgraded firmware, the start frame sends the size of the upgraded firmware to the sensor terminal node, and the sensor terminal node sends a response signal of the start frame to the server; Step S5, the server sends several transmission frames to the sensor terminal node; the sensor terminal node starts to receive and splices, assembles and stores the upgraded firmware in the order of the frames; Step S6, after the server completes the data transmission, it sends an end frame to end the transmission of the upgrade firmware, and the sensor terminal node starts running the new version of the upgrade firmware after receiving the end frame; In step S1, the administrator counts the firmware versions running on each sensor terminal node by the serial number of the sensor terminal node, classifies the different sensor terminal nodes through a graphical interface, selects the sensor terminal nodes that need to be upgraded from the classification, and can select different versions of firmware to upgrade, thereby completing the management of the upgraded firmware; The next 4 bytes of the function code of the start frame in step S4 are a positive sequence number and a reverse sequence number. In the start frame, the positive sequence number is 0x0000 and the reverse sequence number is 0xffff. During the entire transmission process, the sequence number will be incremented following the sequence number of the start frame; the start frame is responsible for transmitting the file size, converting the number of bytes of the file size according to the ASCII code, converting it into hexadecimal data of the corresponding number of bytes according to the number of bits, and storing it in the data content of the 128 bytes after the sequence number. If the size of the data content is less than 128 bytes, the remaining part of the data content is filled with 0; The step S4 also includes: After receiving the start frame, the sensor terminal node first checks the function code of the start frame and performs the corresponding function according to the content of the function code. If the function code does not exist in the Bootloader program, it will return a response of the function code error and wait for the server to send the correct function code; After the function code is verified correctly, the positive sequence number and the reverse sequence number will be checked to determine whether they are equal to 0x0000 and 0xffff respectively. If the positive sequence number or the reverse sequence number does not match the value, a sequence number error response will be returned and the server will wait for the server to resend the start frame. After the serial number is correctly determined, the sensor terminal node will convert the ASCII code representing the file size into an integer number, and then start to compare whether the file size is larger than the remaining space of the sensor terminal node. If it is larger than the remaining space of the sensor terminal node, it means that the upgrade firmware is too large, and an error response of inappropriate file size is returned. It is necessary to wait for the server to resend the firmware with the appropriate size and send the start frame of the firmware that meets the requirements; When the start frame is processed, wait for the server to send a transmission frame.
2. According to claim 1, a sensor terminal node upgrade method in a Modbus TCP network scenario, It is characterized in that In step S1, the server divides the upgraded firmware into several parts according to 128 bytes, which are in line with the size of the transmission frame transmission data. If the size of the last packet is less than 128 bytes, 0x1A is used to fill it to 128 bytes. Finally, the server encapsulates all data packets according to the file transfer protocol and waits for sending.
3. According to a method for upgrading a sensor terminal node in a Modbus TCP network scenario according to claim 1, It is characterized in that In step S2, the server and the sensor terminal node pre-store the same key for identity authentication, and the sensor terminal node determines whether the server's identity is legitimate by comparing the key sent by the server; specifically, a random number, a device serial number, and a digital summary calculated using the SHA256 algorithm are used as the key.
4. According to claim 1, a sensor terminal node upgrade method in a Modbus TCP network scenario, It is characterized in that The step S3 also includes: Before the sensor terminal node enters the Bootloader program, it will check whether the upgrade flag is set to upgrade. If the upgrade flag is set to upgrade, the sensor terminal node starts waiting for the server to send the upgrade firmware; if the upgrade flag is not set to upgrade and the sensor terminal node stores an APP program, it will jump to the APP program.
5. According to a method for upgrading a sensor terminal node in a Modbus TCP network scenario according to claim 1, It is characterized in that The step S5 specifically includes: After receiving the transmission frame, the sensor terminal node will first determine whether the function code is correct. If the function code is incorrect, it will return to step S4 and wait for the server to send a start frame again; After the function code is judged to be correct, it is judged whether the start frame is completed. If not, a response with a sequence number error is returned, and the process returns to step S4 to wait for the server to resend the start frame. After receiving the transmission frame, the sensor terminal node will determine whether it can receive the complete firmware based on the sequence number. This is achieved by comparing the positive sequence number and the reverse sequence number of each transmission frame. If the sequence number is disordered or missing, it will return to step S4 and wait for the start frame to be sent again. When the sensor terminal node receives a transmission frame, if it does not receive the transmission frame within the set time, it will return to step S4 and wait for the start frame to be sent again; When the server receives a transmission frame response, if it does not receive a transmission frame response within the set time, it will resend the start frame and retransmit the firmware.
6. According to claim 1, a sensor terminal node upgrade method in a Modbus TCP network scenario, It is characterized in that The step S6 specifically includes: When the sensor terminal node receives the end frame, it first determines whether the reception of the upgraded firmware is completed. If the sensor terminal node has not received a firmware of sufficient size when receiving the end frame, the firmware reception is not completed, and the process returns to step S4 to wait for the start frame to be sent again. Then determine whether the sequence number is the sequence number of the end frame. If the sequence number does not belong to the sequence number of the end frame, an error response will be returned, and return to step S4 to wait for the start frame to be sent; After the sensor terminal node completes the judgment, it returns the correct end frame response to the server, and then runs the new version of the firmware to complete the upgrade; After the sensor terminal node receives the firmware, if the end frame is not received within the set time, it returns to step S4 and waits for the start frame to be sent again; If the server does not receive the end frame response within the set time, the sensor terminal node sends a startup success message to the server when starting up with the new version of the firmware, notifying the server that the upgrade is complete.
7. A sensor terminal node upgrade system in a Modbus TCP network scenario, It is characterized in that The upgrade method applied to any one of claims 1 to 6 comprises a server, a plurality of serial port to network interface modules, and a plurality of sensor terminal nodes; The server is respectively connected to a number of serial port to network interface modules, and a number of the serial port to network interface modules are respectively connected to a number of sensor terminal nodes; the server communicates with the serial port to network interface module through the Modbus protocol, and the serial port to network interface module and the sensor terminal node transmit data through the serial port; the server is used to subpack and encapsulate the upgrade firmware, and transmit the upgrade firmware to the serial port to the network interface module through the Modbus protocol, and the serial port to the network interface module is used to convert the upgrade firmware transmitted by the server through the Modbus protocol into a serial port and transmit it to the sensor terminal node, and the sensor terminal node has a Bootloader program and an APP program, and the Bootloader program is used to receive the upgrade firmware sent by the server according to the file transfer protocol, and after the sensor terminal node completes the reception, it runs the new version of the firmware; the APP program is used to respond to relevant service requests from the server.
Citation Information
Patent Citations
Method and system for upgrading software versions of passive optical network unit in batch
CN102104810A
Method and system for upgrading display firmware
CN106657233A
Terminal upgrade method and related device
US20170214568A1
