[D
	
	
	/PowerUPDlg [P
		[A ]
		
		/PowerUPDlg 'Power UP' 368 140 Create:Form def
		'PowerUPLbl' '' 'Please power cycle the controller, then press OK!' 92 19 PowerUPDlg.AddLabel
		% add ok button
		75 25 PowerUPDlg.SetButtonSize
		'Ok' '' 'Ok' 1 146 70 PowerUPDlg.AddButton
		PowerUPDlg.Execute
		[A ]
	] 
	
	/RebootWithoutStart [P
		[A counts ]
		1 RebootDevice
		2000 wait
		/Stopped #0 def
		counts [B 
			PIVar:TalkIntf.StopProgram
			PIVar:TalkIntf.GetResult 0 eq PIVar:TalkIntf.GetResult $DA eq or [B 
				/Stopped #1 def
				ExitLoop 
			] if
		] repeat 
		Stopped not [B
			'StopProgram' '' PIVar:TalkIntf.GetResult PackInst:_RaiseTalkError           
		] if
		[A ]   
	]
	
	
	/LoadSW [P
		[A LoadFlag ]	% LoadFlag = False -> Check only if Files exist 	
		/OSSWFileName 'UPOS_' def
		
		/Result #1 def
		/MissingFile '' def
		
		%/SWFile FilePath OSDir add '\' add OSSWFileName add EloTypeExt add '_V' add OSSWVersion cvs add 'S' add OSSWSubVersion cvs add def 
		UPOSExt '' ne [B
			/SWFile FilePath OSDir add '\' add OSSWFileName add UPOSExt add '_V' add OSSWVersion cvs add 'S' add OSSWSubVersion cvs add def 
		]
		[B
			/SWFile FilePath OSDir add '\' add OSSWFileName add EloTypeExt add '_V' add OSSWVersion cvs add 'S' add OSSWSubVersion cvs add def 
		] ifelse  

		OSSWBetaInfo '' ne [B
			/SWFile SWFile '_' add OSSWBetaInfo add def
		] if
		
		PIVar:TalkVersion $20 eq [B
			/SWFile SWFile '.HX2' add def		
		] 
		[B
			PIVar:TalkVersion $40 eq [B
				ProgFlag [B
				     /SWFile SWFile '.HX2' add def 
				] [B
					'Installation error 0x012 occurred. Please contact support.' raisese 
				] ifelse
			]
			[B
				/SWFile SWFile '.HX3' add def		
			] ifelse  
		] ifelse
		
		OSTypeExt '' ne [B
		  /TreeFile FilePath OSDir add '\' add OSTreeFileName add OSTypeExt add '_V' add OSTreeVersion cvs add 'S' add OSTreeSubVersion cvs add def 		
		]
		[B
		  /TreeFile FilePath OSDir add '\' add OSTreeFileName add EloTypeExt add '_V' add OSTreeVersion cvs add 'S' add OSTreeSubVersion cvs add def 
		] ifelse  
		OSTreeBetaInfo '' ne [B
			/TreeFile TreeFile '_' add OSTreeBetaInfo add def
		] if
		/TreeFile TreeFile '.HX2' add def
		
		%/DefaultParFile FilePath OSDir add '\' add OSTreeFileName add EloTypeExt add '_V' add OSTreeVersion cvs add 'S' add OSTreeSubVersion cvs add def
		OSTypeExt '' ne [B
		  /DefaultParFile FilePath OSDir add '\' add OSTreeFileName add OSTypeExt add '_V' add OSTreeVersion cvs add 'S' add OSTreeSubVersion cvs add def 		
		]
		[B
		  /DefaultParFile FilePath OSDir add '\' add OSTreeFileName add EloTypeExt add '_V' add OSTreeVersion cvs add 'S' add OSTreeSubVersion cvs add def 
		] ifelse  
		OSTreeBetaInfo '' ne [B
			/DefaultParFile DefaultParFile '_' add OSTreeBetaInfo add def
		] if
		/DefaultParFile DefaultParFile '.Gr3' add def				
		
		Result [B
			SWFile FileExist not [B
				/Result #0 def 
				/MissingFile SWFile def
			] if
		] if
		
		Result [B
			TreeFile FileExist not [B
				/Result #0 def 
				/MissingFile TreeFile def
			] if
		] if
		
		Result [B
			DefaultParFile FileExist not [B
				/Result #0 def 
				/MissingFile DefaultParFile def
			] if
		] if
		
		
		Result LoadFlag and [B
			
			PIVar:TalkVersion $F0 and [B
				% B1100
				$40 [B
					%ResetDevice
					PIVar:PortType 'CAN' eq [B
						/MACIDSourceSel MACIDSourceSelAddr ReadMemory def
						/MACIDValue MACIDValueAddr ReadMemory def
					] if	
					
					
					PackInst:StopProgram	
					
					'Erasing firmware sectors...' log     
					$C04000 PackInst:EraseFlash
					$C06000 PackInst:EraseFlash
					$C08000 PackInst:EraseFlash
					$C10000 PackInst:EraseFlash
					
%					'Resetting Device...' log     			
%					ResetDevice
%					1000 Wait
%					PackInst:StopProgram	
				
					'Downloading OS...' log
					
					ProgFlag PIVar:TalkVersion $0F and $00 eq and [B
						SWFile dup loadobj exch PackInst:DownloadHX2File		
					] [B
						SWFile dup loadobj exch PackInst:DownloadHX3File
					] ifelse
					
					MCInstallValidAddr InstallationValid WriteWordToElo
					
					%PIVar:TalkVersion $0F and $00 eq [B
					%SWFile dup loadobj exch PackInst:DownloadHX2File		
					%] [B
					%SWFile dup loadobj exch PackInst:DownloadHX3File		
					%] ifelse
					
					'Resetting Device...' log     			
					ResetDevice
					1000 Wait
					PackInst:StopProgram	
					
					$0 StartProgram
					%'Waiting for OS reply...' log     
					%[B
					%		2000 Wait      
					%		$0 ReadMemory 0 eq [B 
					%      '...OS started...' log
					%      exitloop 
					%   ] if	     
					%] loop 
					
					
					'Waiting until OS is ready...' log
					15000 wait
%					5000 wait		% extra wait for ML8050
					PackInst:StopProgram
					
					MCInstallValidAddr InstallationInvalid WriteWordToElo
					
					%PackInst:StopProgram		
					'Erasing OS updater ...' log     
					$C08000 PackInst:EraseFlash		
					%5000 wait						  
					$C10000 PackInst:EraseFlash		
					%5000 wait						  
					
					'Downloading OS default parameters ...' log    
					DefaultParFile dup loadobj exch PackInst:DownloadGR3File
					
					
					PIVar:PortType 'CAN' eq [B
						MACIDSourceSelAddr MACIDSourceSel WriteWordToElo
						MACIDValueAddr MACIDValue WriteWordToElo
					] if	
					
					'Resetting Device...' log
					ResetDevice                                                                                            
					1000 Wait
					
					'Clearing Parameter Sections...' log
					/ClearFile FilePath OSDir add '\' add 'B1100_ParaClear.HX2' add def
					ClearFile dup loadobj exch PackInst:DownloadHX2File			

					'Resetting Device...' log
					ResetDevice                                                                                            
					1000 Wait
					
				]
				
				% E1250 / E1450 / B8050 / MB8050
				$30 [B
					/OSInstallCommandAddress	$D000181E	def
					PIVar:PortType 'ETH' eq ProgFlag not and [B
						/IPConfigMode IPConfigModeAddr ReadMemory def
						/DefGWConfigMode DefGWConfigModeAddr ReadMemory def
						% read the static IP address, network mask and gateway
						/IPAddressLo IPAddressAddr ReadMemory def
						/IPAddressHi IPAddressAddr 2 add ReadMemory def
						/NetMaskLo NetMaskAddr ReadMemory def
						/NetMaskHi NetMaskAddr 2 add ReadMemory def		
						/DefaultGatewayLo DefaultGatewayAddr ReadMemory def
						/DefaultGatewayHi DefaultGatewayAddr 2 add ReadMemory def										    																			
						% read the working IP address, network mask and gateway
						/IPAddressWorkLo IPAddressAddrWorking ReadMemory def
						/IPAddressWorkHi IPAddressAddrWorking 2 add ReadMemory def
						/NetMaskWorkLo NetMaskAddrWorking ReadMemory def
						/NetMaskWorkHi NetMaskAddrWorking 2 add ReadMemory def		
						/DefaultGatewayWorkLo DefaultGatewayAddrWorking ReadMemory def
						/DefaultGatewayWorkHi DefaultGatewayAddrWorking 2 add ReadMemory def										    
					] if	
					
					PIVar:PortType 'ETH' eq ProgFlag not and [B
						IPAddressAddr IPAddressWorkLo WriteWordToElo
						IPAddressAddr 2 add IPAddressWorkHi WriteWordToElo
						NetMaskAddr NetMaskWorkLo WriteWordToElo
						NetMaskAddr 2 add NetMaskWorkHi WriteWordToElo
						DefaultGatewayAddr DefaultGatewayWorkLo WriteWordToElo
						DefaultGatewayAddr 2 add DefaultGatewayWorkHi WriteWordToElo
						% set the config mode to static
						IPConfigModeAddr 2 WriteWordToElo
						DefGWConfigModeAddr 1 WriteWordToElo
					] if		
					
					20 OSLoader:RebootWithoutStart
					
					'Erasing firmware sectors...' log     
					$AFE00000 PackInst:EraseFlash % CURVE
					$AFE10000 PackInst:EraseFlash % CT		 
					$A0020000 PackInst:EraseFlash % MC and INTF Tree		
					$A0040000 PackInst:EraseFlash % INTF
					$A0180000 PackInst:EraseFlash % APPL
					$A0100000 PackInst:EraseFlash % MCSW			
					
					'Downloading OS...' log
					
					SWFile dup loadobj exch PackInst:DownloadHX3File % Load OS Updater 
									
					MCInstallValidAddr InstallationValid WriteWordToElo
					
					ResetDevice % AutoStart OS Updater after reset
					
					'Waiting for OS reply...' log     
					55000 wait	% to be modified
					
					'Downloading OS default parameters ...' log    
					DefaultParFile dup loadobj exch PackInst:DownloadGR3File
					
					PIVar:PortType 'ETH' eq ProgFlag not and [B
						IPAddressAddr IPAddressLo WriteWordToElo
						IPAddressAddr 2 add IPAddressHi WriteWordToElo
						NetMaskAddr NetMaskLo WriteWordToElo
						NetMaskAddr 2 add NetMaskHi WriteWordToElo
						DefaultGatewayAddr DefaultGatewayLo WriteWordToElo
						DefaultGatewayAddr 2 add DefaultGatewayHi WriteWordToElo
						% set the config modes to the old values
						IPConfigModeAddr IPConfigMode WriteWordToElo
						DefGWConfigModeAddr DefGWConfigMode WriteWordToElo
					] if																				
					
					MCInstallValidAddr InstallationInvalid WriteWordToElo
					
					'Clearing Parameter Sections...' log
					2 PIVar:TalkIntf.ClearInstancePar
					3 PIVar:TalkIntf.ClearInstancePar
					4 PIVar:TalkIntf.ClearInstancePar	
					
					% Write new Firmware message to controller
					/OSInstallCommand OSInstallCommandAddress ReadMemory def
					/OSInstallCommand OSInstallCommand $0001 or def
					OSInstallCommandAddress OSInstallCommand WriteWordToElo				
					
				]
				
				% A1100, C1100
				$50 [B
					/SystemStartupDelayAddress	$300906	def
					/OSInstallCommandAddress	$00F82E	def
					
					'Erasing firmware sectors...' log     
					
					0 1 3 [B
						/SectorIndex exch def
						$D80000 $1000 SectorIndex mul add PackInst:EraseFlash	% CT
					] for	
					0 1 7 [B
						/SectorIndex exch def
						$D88000 $1000 SectorIndex mul add PackInst:EraseFlash	% CURVE
					] for						
					0 1 63 [B
						/SectorIndex exch def
						$C40000 $1000 SectorIndex mul add PackInst:EraseFlash	% MC
					] for	
					0 1 63 [B
						/SectorIndex exch def
						$C80000 $1000 SectorIndex mul add PackInst:EraseFlash	% Intf
					] for	
					0 1 59 [B
						/SectorIndex exch def
						$CC0000 $1000 SectorIndex mul add PackInst:EraseFlash	% App
					] for	
					
					'Downloading OS...' log					
					SWFile dup loadobj exch PackInst:DownloadHX3File % Load OS Updater 
						
					SystemStartupDelayAddress 0 WriteWordToElo						
					MCInstallValidAddr InstallationValid WriteWordToElo

					ResetDevice % AutoStart OS Updater after reset
					'Waiting for OS reply...' log     
					10000 wait	% to be modified
					
					StartProgram
  
					55000 wait	% to be modified
					
					'Downloading OS default parameters ...' log    
					DefaultParFile dup loadobj exch PackInst:DownloadGR3File
					
					MCInstallValidAddr InstallationInvalid WriteWordToElo
					
					'Clearing MC Parameter Section...' log
					2 PIVar:TalkIntf.ClearInstancePar
					'Clearing Intf Parameter Section...' log
					3 PIVar:TalkIntf.ClearInstancePar
					'Clearing Appl Parameter Section...' log
					4 PIVar:TalkIntf.ClearInstancePar	
					
					% Write new Firmware message to controller
					/OSInstallCommand OSInstallCommandAddress ReadMemory def
					/OSInstallCommand OSInstallCommand $0001 or def
					OSInstallCommandAddress OSInstallCommand WriteWordToElo				
				]

				% C1250
				$60 [B
					/OSInstallCommandAddress	$D000181E	def
					
					PIVar:PortType 'ETH' eq ProgFlag not and [B
						/IPConfigMode IPConfigModeAddr ReadMemory def
						/DefGWConfigMode DefGWConfigModeAddr ReadMemory def
						% read the static IP address, network mask and gateway
						/IPAddressLo IPAddressAddr ReadMemory def
						/IPAddressHi IPAddressAddr 2 add ReadMemory def
						/NetMaskLo NetMaskAddr ReadMemory def
						/NetMaskHi NetMaskAddr 2 add ReadMemory def		
						/DefaultGatewayLo DefaultGatewayAddr ReadMemory def
						/DefaultGatewayHi DefaultGatewayAddr 2 add ReadMemory def										    																			
						% read the working IP address, network mask and gateway
						/IPAddressWorkLo IPAddressAddrWorking ReadMemory def
						/IPAddressWorkHi IPAddressAddrWorking 2 add ReadMemory def
						/NetMaskWorkLo NetMaskAddrWorking ReadMemory def
						/NetMaskWorkHi NetMaskAddrWorking 2 add ReadMemory def		
						/DefaultGatewayWorkLo DefaultGatewayAddrWorking ReadMemory def
						/DefaultGatewayWorkHi DefaultGatewayAddrWorking 2 add ReadMemory def										    
					] if	
					
					PIVar:PortType 'ETH' eq ProgFlag not and [B
						IPAddressAddr IPAddressWorkLo WriteWordToElo
						IPAddressAddr 2 add IPAddressWorkHi WriteWordToElo
						NetMaskAddr NetMaskWorkLo WriteWordToElo
						NetMaskAddr 2 add NetMaskWorkHi WriteWordToElo
						DefaultGatewayAddr DefaultGatewayWorkLo WriteWordToElo
						DefaultGatewayAddr 2 add DefaultGatewayWorkHi WriteWordToElo
						% set the config mode to static
						IPConfigModeAddr 2 WriteWordToElo
						DefGWConfigModeAddr 1 WriteWordToElo
					] if		
					
					20 OSLoader:RebootWithoutStart
					10000 wait
					
					'Erasing firmware sectors...' log     
					$AF000000 PackInst:EraseFlash % CURVE
					$AF080000 PackInst:EraseFlash % CT		 
					$80020000 PackInst:EraseFlash % MC Tree and INTF Tree		 
					$80040000 PackInst:EraseFlash % INTF
					$80180000 PackInst:EraseFlash % APPL
					$801C0000 PackInst:EraseFlash % APPL
					$80100000 PackInst:EraseFlash % MCSW  	 		
					$80140000 PackInst:EraseFlash % MCSW 			
					
					'Downloading OS...' log
					
					20 OSLoader:RebootWithoutStart
					10000 wait
					
					SWFile dup loadobj exch PackInst:DownloadHX3File % Load OS Updater 
									
					MCInstallValidAddr InstallationValid WriteWordToElo
					
					ResetDevice % AutoStart OS Updater after reset
										
					'Waiting for OS reply...' log     
					65000 wait	% to be modified
					
					'Downloading OS default parameters ...' log    
					DefaultParFile dup loadobj exch PackInst:DownloadGR3File
					
					PIVar:PortType 'ETH' eq ProgFlag not and [B
						IPAddressAddr IPAddressLo WriteWordToElo
						IPAddressAddr 2 add IPAddressHi WriteWordToElo
						NetMaskAddr NetMaskLo WriteWordToElo
						NetMaskAddr 2 add NetMaskHi WriteWordToElo
						DefaultGatewayAddr DefaultGatewayLo WriteWordToElo
						DefaultGatewayAddr 2 add DefaultGatewayHi WriteWordToElo
						% set the config modes to the old values
						IPConfigModeAddr IPConfigMode WriteWordToElo
						DefGWConfigModeAddr DefGWConfigMode WriteWordToElo
					] if																				
					
					MCInstallValidAddr InstallationInvalid WriteWordToElo
					
					'Clearing Parameter Sections...' log
					2 PIVar:TalkIntf.ClearInstancePar
					3 PIVar:TalkIntf.ClearInstancePar
					4 PIVar:TalkIntf.ClearInstancePar	
					
					% Write new Firmware message to controller
					/OSInstallCommand OSInstallCommandAddress ReadMemory def
					/OSInstallCommand OSInstallCommand $0001 or def
					OSInstallCommandAddress OSInstallCommand WriteWordToElo				
				]
				
				% E1100
				$20 [B
					ResetDevice
					15000 wait
					ResetDevice
					1000 wait
					PackInst:StopProgram		
					
					'Erasing firmware sectors...' log     
					$10000 PackInst:EraseFlash		
					$30000 PackInst:EraseFlash		
					$40000 PackInst:EraseFlash						
					$D0000 PackInst:EraseFlash		
					$E0000 PackInst:EraseFlash		
					$F0000 PackInst:EraseFlash		
					
					'Downloading OS...' log
					PIVar:TalkVersion $0F and $00 eq [B
						SWFile dup loadobj exch PackInst:DownloadHX2File		
					] [B
						SWFile dup loadobj exch PackInst:DownloadHX3File		
					] ifelse
					
					MCInstallValidAddr InstallationValid WriteWordToElo
					
					%PIVar:TalkVersion $0F and $00 eq [B
					%SWFile dup loadobj exch PackInst:DownloadHX2File
					%] [B
					%SWFile dup loadobj exch PackInst:DownloadHX3File
					%] ifelse
					'Resetting Device...'log     			
					ResetDevice
					15000 Wait
					
					'Starting OS...' log
					$10000 StartProgram
					'Waiting for OS reply...' log     
					[B
						2000 Wait      
						0 ReadMemory 0 eq [B 
							'...OS started...' log
							exitloop 
						] if	     
					] loop 
					'Waiting until OS is ready...' log
					5000 wait
					
					[B
						2000 Wait
						$A2FE ReadMemory 0 eq  [B 
							'...OS is ready' log
							exitloop 
						] if	     
					] loop
					
					MCInstallValidAddr InstallationInvalid WriteWordToElo
					
					'Erasing OS parameter sector...' log     
					$C0000 PackInst:EraseFlash		
					'Downloading OS parameter tree...' log    
					TreeFile dup loadobj exch PackInst:DownloadHX2File                
					
					ResetDevice
					8000 Wait
					
					'Downloading OS default parameters ...' log    
					DefaultParFile dup loadobj exch PackInst:DownloadGR3File
					
					'Resetting Device...' log
					ResetDevice                                                                                            
					
					[B
						3000 Wait
						$A2FE ReadMemory 0 eq  [B 
							'...OS is ready' log
							exitloop 
						] if	     
					] loop     

					'Clearing Parameter Sections...' log
					2 PIVar:TalkIntf.ClearInstancePar
					3 PIVar:TalkIntf.ClearInstancePar
					4 PIVar:TalkIntf.ClearInstancePar					
				]
			]
			[B
				%				
			] case
			
			
		] if
		[A /MissingFile /Result]
	]
	
]
