[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
		     /OSTreeFileName 'OSTr1100_' 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 
			   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
						 'Installation error 0x012 occurred. Please contact support.' raisese 
					 ]
					 [B
					   /SWFile SWFile '.HX3' add def		
					 ] ifelse  
			   ] ifelse
			   
	
			   /TreeFile FilePath OSDir add '\' add OSTreeFileName add EloTypeExt add '_V' add OSTreeVersion cvs add 'S' add OSTreeSubVersion cvs add def 
			   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
			   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

     				      'Downloading OS...' log
                 
									SWFile dup loadobj exch PackInst:DownloadHX3File

 	         				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
									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

               ]
               
               % E1250
               $30 [B
									PIVar:PortType 'ETH' eq [B
										/IPConfigMode IPConfigModeAddr 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 [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
								  ] if		
								  
			    				20 OSLoader:RebootWithoutStart
		    							    							    			
     			        'Erasing firmware sectors...' log     
					        $AFE00000 PackInst:EraseFlash		% CURVE
			    				%20 OSLoader:RebootWithoutStart
					        $AFE10000 PackInst:EraseFlash		% CT
			    				%20 OSLoader:RebootWithoutStart				 
					        $A0020000 PackInst:EraseFlash		
					        $A0040000 PackInst:EraseFlash		
					        $A0180000 PackInst:EraseFlash
					        $A0100000 PackInst:EraseFlash		
					        $A0080000 PackInst:EraseFlash
							
							'Downloading OS parameter tree...' log    
							TreeFile dup loadobj exch PackInst:DownloadHX2File 
    		                         
									%OSLoader:PowerUPDlg
									ResetDevice
									10000 wait
									PackInst:StopProgram
									
									'Downloading OS default parameters ...' log    
    				      DefaultParFile dup loadobj exch PackInst:DownloadGR3File
    				      
									PIVar:PortType 'ETH' eq [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
								  ] if		
    				      
     				      'Downloading OS...' log

									SWFile dup loadobj exch PackInst:DownloadHX3File
   				      
 	         				MCInstallValidAddr InstallationValid WriteWordToElo

									ResetDevice
									
     				      'Waiting for OS reply...' log     
									24000 wait			%% to be modified
									
									
									PIVar:PortType 'ETH' eq [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 mode to the old value
										IPConfigModeAddr IPConfigMode WriteWordToElo
								  ] if																				
									
	         				MCInstallValidAddr InstallationInvalid 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                        
               ]
					  ]
					  [B
					     %				
					  ] case
					
		                
			   ] if
      [A /MissingFile /Result]
   ]

]