A Method of Remote Multi-Machine Program Update Based on Wi-Fi Wireless LAN and CAN Bus

We provide a remote online program update method for multi-machine control system in distributed industrial control field based on WiFi Wireless LAN and CAN bus in this paper. On this basis to achieve the accurate and efficient update for remote multi-machine.


Introduction
At the present stage, program updating in complex industrial environment has many problems such as process cumbersome, poor stability, meanwhile, The increase in the number of machines poses a great challenge to the efficiency of the update.In recent years, although there are some multi-machine Application online upgrade method, but the boot program upgrade are basically a single machine update.The Application's online upgrade method is also mostly based on a single bus, so that the program update should use a dedicated adapter to connect to the bus to update the program, or cannot accurately update a specific device, or because of the huge amount of code makes the update time greatly extended.At present, as the automation and the intelligent system has gotten more and more development on the machining field, the demand for high compatibility, high reliability, low cost and compactsize has been constantly increasing [3] .According to the shortcomings of the existing technology, based on the in-depth analysis of the boot loader mechanism and develop a custom transmission communication protocol, we put forward a remote multi-machine program reliable update method based on Wi-Fi wireless LAN and CAN bus in this paper.

The structure of system
Program remote transmission system is constituted by the terminal machine, data transmission bus, data transmission and relay, data server (PC) .The hardware equipment used in the system is the communication network equipment, it mainly includes the host computer, the router, the switch, the RS485 / Ethernet converter, the RS485 / WiFi conversion module, the network cable, the data acquisition relay control board, data terminal control board and so on.The lower computer mainly through RS485, CAN and other bus way to achieve the program to be received.These two kinds of bus is commonly used in industrial communication which can be articulated many nodes, have long communication distance, high transmission rate, anti-interference ability and high reliability.WiFi wireless LAN is a industry standard for wireless network communication defined by IEEE(IEEE 802.11).It is a very low-cost and high-speed wireless air interface, because the WiFi frequency is free without any telecom operating license [1] .The WiFicommunication functions integrated in the relay control board, the board relay through WiFi wireless LAN or Ethernet via trunk routing connected to the host, based on TCP / IP [5] transmission protocol and a reliable transmission of the verification protocol data flow, to achieve the collection of procedures summary.The overall architecture of the system is shown in Fig. 1 Fig. 1.Block diagram of the distributed industrial control system 3.The design of the host computer software

The host computer handshake flow.
The host computer program is written in C# language, through the user program binary file traversal analysis, it packaged data into data frame which based on CAN bus protocol, then send it to the bootloader program of terminal machine, bootloader program will receive the data frame and store it in the designated user code area of FLASH memory.
When the host computer program is turned on, the first issue is sending the query command to get the relay control board number and its status, then select the bin file which need to be sent to start sending data frames, meanwhile deal with the failure of the frame transition and set re-transmission.When all data frames are received, send the end frame to complete the update.The host computer handshake flow is shown in Fig. 2. new start address, through the PC pointer jump to the after-reset the vector address 0X08030000.
At the same time, in the terminal APP programming, during system initialization, the program's interrupt vector start address register SCB-> VTOR is set to the new start address of the current program via the function NVIC_SetVectorTable (NVIC_VectTab_FLASH, 0x5000).

System process framework and software implementation
Multi-machine program upgrade method overall process includes the following steps.

Application program update flow.
Step 1: After the system is powered on, the online ala number will be displayed in the host.User will decide to update part or all of terminal machine under this relay.If the current state is changed into the upgrade mode, the terminal machine under relay will receive the upgrade order sent by host.
Step 2: User select the appropriate file copy to the host to decide whether update the part or total application, or update the bootloader program.In order to shorten the application update time, usually some of the relatively independent and read-only high-volume data of application will be allocated in a stable address range, named as block A, and other program data and code is allocated in another address range, named as block B. If the application is updated once, the follow-up program update can modify the program only choose to update B part of the program.
Step 3: All the terminal machine automatically enter the bootloader and verify the application after powered-on, if pass the check, bootloader jump into the application's start address, otherwise wait for re-update.
Step 4: When the terminal machine is running the application, if the host has performed steps 1 and 2, it will receive the update command forwarded by the relay, reset itself automatically and enter the bootloader, wait for the update.When the terminal receives the host command to prepare update, it will compare the program's own check code and the update program check code, if the two check codes are inconsistent, means the reset command is ready to be updated.If two checksums are equal, indicating that the terminal has upgraded the program, the update command will not executed.So that user can avoid update the machine which has been updated under the same relay, reduce the programming times of terminal machine's program memory .Step 5: After the update starts, the host will split the program into multiple data to be sent, each segment the relay received will be verified.If the verification is wrong, then relay will request the host to re-send this segment, otherwise the program will be sent to the terminal machine under this board through the CAN bus.verified, if the verification is wrong, then request to re-send this segment, otherwise the program will be written to the terminal machine, then request to send next segment.
Step 7: Host determines whether the application has been totally sent, if done then send the end command of update, otherwise repeat steps 5 and 6.
Step 8: When relay receives the end command, it will reset and turn to work mode, meanwhile, the terminal machine verify all the code again, then jump to the start address if the verification is passed, otherwise report the corresponding terminal machine number to the host, repeat steps 1 to 7. The total program segment transmission flow is shown in Fig. 5.

Bootloader own program update flow.
As shown in Fig. 6,the bootloader update flow has follow steps.Step 1: Firstly, user need to update the terminal machine application to a specific bootloader write program.This program is similar to the normal bootloader program, but its program addresses are different from where normal application program stored.The normal bootloader program address range named segment A, normal application program address range named segment B. The bootloader write program address will be saved into segment B, update the application program(the new bootloader program)will be saved intosegment A. Afterselectingthe bootloader write program file in step 2, follow steps 3 through 8 to complete the update.After the flow is complete, the terminal machine will start the bootloader write program, continue to wait for the new bootloader program update.

Fig.6: Bootloader update flowchart
Step 2: Update the real bootloader program, then select the new bootloader program update file, repeat steps 3 to 8 operations to complete the update .
Step 3: After completing bootloader program update, user will need to update the user application of the terminal machine again.

Workshop specific operation flow
In the workshop debugging, according to the needs of client and workshop conditions, the terminal machine should be connected through the CAN bus as the units under relays.Place the industrial wireless router at the right place on the workshop and connect all WiFi launcher of relays to it.While the router connected to the Internet, the host which connected to the router will be enable to update the program of terminal machines.

User application update.
After the system is powered on, open the update client program in the host, the online relay number will be displayed to the online list, according to the needs, user select the units to update, the selected units will suspension of the current work and turn to update mode, At the same time the Firstly, user need to first update the terminal machine application to a specific bootloader writer program.After the update is complete, the terminal machine will start the bootloader write program, continue to wait for the new bootloader program update.The bootloader update mode interface is shown in Figure 10.Then, select the bin file of new bootloader program, repeat the update process steps to complete the bootloader program upgrade.
Finally, after the completion of the bootloader program upgrade, if user want to let the terminal machine turn to working mode, repeat the application update process.

Conclusion
The characteristics of multi-machine program update technology enabled users to update application program of part or all the units in long distancethrough Internet remote rather than staying in the workshop, facilitates the management and upgrading of discrete distributed systems, saves the maintenance costs.The use of relay and the terminal machine double-check mode, ensured the accuracy of high-volume data transmission.The system can re-update a separate unit which has transmission error, to avoid the situation that other unit repeat the flow.Using sub-section update method, which can solve the problem that the application program size beyond the terminal machine memory capacity so that it can not be updated at one time.The use of program segment design, segmented the terminal storage area, only to update modified part, to avoid the same content is updated several times, greatly improving the efficiency and success rate of the update.

Fig. 5 .
Fig.5.Program segment transmission flow chartStep 6: When the terminal machine receives the data, each segment sent from relay will be

2 .
Fig.7 Before then the h multi-segm in Fig.8.The term should be s terminal m Fig.9 sh segments d whether th