% Installation package for EasySteps 
% Date:    04.12.2009
% Copyright 2005-2009, NTI AG.

[D
	
	%/Main [B
	
	/FirmwareScriptVer 2
	
	/Init [B     
		/ProgFlag exch def    
		/FilePath '' def	    
		
		'PackInst' nknown not [B 'PackInst' import ] if     
		
		/ApplicationsDir '..\..\Applications' def
		/ApplLoaderFile 'ApplLoader' def
		/ApplLoadSW [B ApplLoader:LoadSW ] def		
		
		%Applications
		/EasySteps [D
			/Name 'EasySteps'
			/Caption 'EasySteps'			
			/Description 'Easy Steps Application'
			/ApplSWVersion 3 
			/ApplSWSubVersion 11
			/ApplSWBetaInfo 'b01'
			/ApplTreeVersion 3
			/ApplTreeSubVersion 11
			/ApplTreeBetaInfo 'b01'
			/ApplDir	'..\EasySteps'
			/ApplSWFileName 'ApplSWEasySteps_'
			/ApplTreeFileName 'ApplTrEasySteps_'			
		] def			
		
		/Controllers [A
			% E1200 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
			
			%E1200GPUC
			[D
				/Name 'E1200-GP-UC'
				/TypeID $961
				/TypeSupported 1	
				/SupportedHWVersions [A
					$0104
					$0105
				]
				/SupportedDSWVersions [A
					$20
				]		   		 
				/PowerExtension 'UC'  
				/EloTypeExt 'E1200'
				/EasyStepsParExt ''
				/Applications [A
					EasySteps
				]			   	
			]
			
			
			%E1250PLUC
			[D
				/Name 'E1250-PL-UC'
				/TypeID $901
				/TypeSupported 1	
				/SupportedHWVersions [A
					$0104
					$0105
				]
				/SupportedDSWVersions [A
					$20
				]		   		 
				/PowerExtension 'UC'  
				/EloTypeExt 'E1200'
				/EasyStepsParExt ''
				/Applications [A
					None
					EasySteps
				]			   	
			]
			
			
			%E1250ECUC
			[D
				/Name 'E1250-EC-UC'
				/TypeID $911
				/TypeSupported 1	
				/SupportedHWVersions [A
					$0104
					$0105
				]
				/SupportedDSWVersions [A
					$20
				]		   		 
				/PowerExtension 'UC'  
				/EloTypeExt 'E1200'
				/EasyStepsParExt ''
				/Applications [A
					EasySteps
				]			   	
			]
			
			%E1230DPUC
			[D
				/Name 'E1230-DP-UC'
				/TypeID $951
				/TypeSupported 1	
				/SupportedHWVersions [A		
					$0104
					$0105
				]
				/SupportedDSWVersions [A
					$20
				]		   		 
				/PowerExtension 'UC'  
				/EloTypeExt 'E1200'
				/EasyStepsParExt ''
				/Applications [A
					EasySteps
				]			   	
			]
			
			%E1200GPHV
			[D
				/Name 'E1200-GP-HV'
				/TypeID $9E1
				/TypeSupported 1	
				/SupportedHWVersions [A
					$0104
					$0105
				]
				/SupportedDSWVersions [A
					$20
				]		   		 
				/PowerExtension 'HV'  
				/EloTypeExt 'E1200'
				/EasyStepsParExt ''
				/Applications [A
					EasySteps
				]			   	
			]
			
			%E1250PLHV
			[D
				/Name 'E1250-PL-HV'
				/TypeID $981
				/TypeSupported 1	
				/SupportedHWVersions [A
					$0104
					$0105
				]
				/SupportedDSWVersions [A
					$20
				]		   		 
				/PowerExtension 'HV'  
				/EloTypeExt 'E1200'
				/EasyStepsParExt ''
				/Applications [A
					EasySteps
				]			   	
			]
			
			
			%E1250ECHV
			[D
				/Name 'E1250-EC-HV'
				/TypeID $991
				/TypeSupported 1	
				/SupportedHWVersions [A
					$0104
					$0105
				]
				/SupportedDSWVersions [A
					$20
				]		   		 
				/PowerExtension 'HV'  
				/EloTypeExt 'E1200'
				/EasyStepsParExt ''
				/Applications [A
					EasySteps
				]			   	
			]
			
			%E1230DPHV
			[D
				/Name 'E1230-DP-HV'
				/TypeID $9D1
				/TypeSupported 1	
				/SupportedHWVersions [A		
					$0104
					$0105
				]
				/SupportedDSWVersions [A
					$20
				]		   		 
				/PowerExtension 'HV'  
				/EloTypeExt 'E1200'
				/EasyStepsParExt ''
				/Applications [A
					EasySteps
				]			   	
			]
			
			%E1400GP
			[D
				/Name 'E1400-GP'
				/TypeID $C01
				/TypeSupported 1	
				/SupportedHWVersions [A		
					$0101
					$0102
				]
				/SupportedDSWVersions [A
					$30
				]		   		 
				/PowerExtension ''  
				/EloTypeExt 'E1400'
				/EasyStepsParExt ''
				/Applications [A
					EasySteps
				]			   	
			]
			
			
		] def
		
		/WriteStringToElo [P
			%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
			% This procedure writes an string value of the  %
			% protected block to the ELO          %
			%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
			[A /Address /InString ]
			
			/StrLength InString length def
			0 2 StrLength 2 sub [B
				/TmpIndex exch def
				/TmpAddr Address TmpIndex add def
				/TmpData InString TmpIndex 1 getsubstr ord def
				/TmpIndex TmpIndex 1 add def
				TmpIndex StrLength lt [B
					/TmpData TmpData InString TmpIndex 1 getsubstr ord 256 mul add def
				] if 
				TmpAddr TmpData WriteWordToElo
			] for
			
			[A ]
		] def
		
		/WriteWordToElo [B
			TalkIntf.WriteMemory
		] def
		
		/ReadMemory [B 
			TalkIntf.ReadMemory     
			TalkIntf.GetResult 0 eq 
			[B TalkIntf.GetData ]
			[B 'TalkError: ' TalkIntf.GetResult cvs add raisese ] ifelse
		] def
		
		/StartProgram [B 
			TalkIntf.StartProgram
			TalkIntf.GetResult 0 ne
			[B 'TalkError: ' TalkIntf.GetResult cvs add raisese ] if
		] def
		
		/ResetDevice [B 
			TalkIntf.ResetDevice
			TalkIntf.GetResult 0 ne
			[B 'TalkError: ' TalkIntf.GetResult cvs add raisese ] if
		] def
		
		/RebootDevice [B 
			TalkIntf.RebootDevice
			TalkIntf.GetResult 0 ne
			[B 'TalkError: ' TalkIntf.GetResult cvs add raisese ] if
		] def
		
		
		/GetEloType [B
			Offset $680 add ReadMemory
		] def
		
		/GetEloVersion [B
			Offset $682 add ReadMemory
		] def
		
		/GetEloSWVersion [B
			Offset $102A add ReadMemory	
		] def
		
		/GetEloTypeStr [P
			[A ]
			/EloName '' def 
			/StringEndFound #0 def 
			Offset $690 add 2 Offset $69E add [B
				/WordAddr exch def
				StringEndFound not [B
					/Value WordAddr ReadMemory def
					Value $FF and 0 ne [B	
						/EloName EloName Value $FF and chr add def
						Value 8 shr 0 ne [B
							/EloName EloName Value 8 shr chr add def              
						]
						[B
							/StringEndFound #1 def
						] ifelse
					]	
					[B
						/StringEndFound #1 def
					] ifelse
				]if
			] for 
			
			[A EloName]
		] def
		
		/CheckEloIsKnown [P
			[A Type]
			/IsKnown False def
			Controllers [B
				/TempEloDict exch def
				TempEloDict.TypeID Type eq [B
					/IsKnown True def
				] if 
			] forall		
			[A IsKnown]
		] def
		
		/CheckHWVersionCompatible [P
			[A HWVersion Controller]
			/Result #0 def
			/Msg '' def		
			Controller /SupportedHWVersions known [B
				Controller.SupportedHWVersions [B
					HWVersion eq [B
						/Result #1 def
						exitloop	
					] if 
				] forall
			] if		
			Controller /NotSupportedHWVersion known [B
				Controller.NotSupportedHWVersion [B
					/TempDict exch def
					TempDict.HWVersion HWVersion eq [B
						/Msg TempDict.LastReleaseName def
						exitloop	
					] if 
				] forall
			] if		
			[A Result Msg ]
		] def
		
		/CheckEloSWVersionCompatible [P
			[A EloSWVersion Controller]
			/Result #0 def		
			Controller /SupportedDSWVersions known [B
				Controller.SupportedDSWVersions [B
					EloSWVersion eq [B
						/Result #1 def	
					] if 
				] forall
			] if		
			[A Result]
		] def
		
		/GetEloDict [P
			[A Type]
			/EloDict Controllers 0 get def	% changed from 1 to 0, Ro, 20090324
			Controllers [B
				/TempEloDict exch def
				TempEloDict.TypeID Type eq [B
					/EloDict TempEloDict def
				] if 
			] forall		
			[A EloDict]
		] def
		
		/ReadyForStopDlg [P
			[A ]
			/Result #0 def		
			/ReadyDlg 'Ready to Download' 400 150 Create:Form def
			
			'Label1' '' 'The System is ready to download the firmware.' 17 19 ReadyDlg.AddLabel
			'Label2' '' 'The download procedure will erase all former settings.' 17 32 ReadyDlg.AddLabel
			'Label3' '' 'Do you want to continue?' 17 55 ReadyDlg.AddLabel
			
			% add ok/cancel buttons
			75 25 ReadyDlg.SetButtonSize
			'Ok' '' 'Ok' 1 108 80 ReadyDlg.AddButton
			'Cancel' '' 'Cancel' 2 203 80 ReadyDlg.AddButton	
			/Result ReadyDlg.Execute 1 eq def 
			
			[A /Result]
		] def
		
		/AbortDlg [P
			[A Msg Msg2 Msg3 ]
			
			
			Msg3 '' ne [B
				/AbortDlg 'Abort' 520 180 Create:Form def
				'AbortLbl' '' 'Installation aborted!' 20 19 AbortDlg.AddLabel
				'AbortMsg' '' Msg 20 49 AbortDlg.AddLabel
				'AbortMsg2' '' Msg2 20 65 AbortDlg.AddLabel
				'AbortMsg3' '' Msg3 20 81 AbortDlg.AddLabel
				% add ok button
				75 25 AbortDlg.SetButtonSize
				'Ok' '' 'Ok' 1 235 106 AbortDlg.AddButton
			]
			[B	
				Msg2 '' ne [B
					/AbortDlg 'Abort' 450 160 Create:Form def
					'AbortLbl' '' 'Installation aborted!' 20 19 AbortDlg.AddLabel
					'AbortMsg' '' Msg 20 49 AbortDlg.AddLabel
					'AbortMsg2' '' Msg2 20 65 AbortDlg.AddLabel
					% add ok button
					75 25 AbortDlg.SetButtonSize
					'Ok' '' 'Ok' 1 185 90 AbortDlg.AddButton
				]	
				[B
					/AbortDlg 'Abort' 368 150 Create:Form def
					'AbortLbl' '' 'Installation aborted!' 92 19 AbortDlg.AddLabel
					'AbortMsg' '' Msg 92 49 AbortDlg.AddLabel
					% add ok button
					75 25 AbortDlg.SetButtonSize
					'Ok' '' 'Ok' 1 146 80 AbortDlg.AddButton
				] ifelse
			] ifelse  
			
			AbortDlg.Execute
			[A ]
		] def
		
		/SuccessDlg [P
			[A Msg]
			
			/SuccessDlg 'Success' 368 140 Create:Form def
			
			'SuccessLbl' '' 'Application installation successfully completed!' 92 19 SuccessDlg.AddLabel   	    	
			
			% add ok button
			75 25 SuccessDlg.SetButtonSize
			'Ok' '' 'Ok' 1 146 70 SuccessDlg.AddButton
			SuccessDlg.Execute
			[A ]
		] def
		
		
		
		/FileCheck [P
			[A ]
			/Result #1 def
			/MissingFile '' def
			% Application
			Result [B	
				ApplSel.Name 'None' ne [B
					/FileName FilePath ApplicationsDir add '\' add ApplLoaderFile add def
					FileName '.stx' add FileExist [B
						ApplLoaderFile nknown not [B FileName import ] if
						#0 ApplLoadSW not [B   % LoadFlag
							/Result #0 def 
							/MissingFile exch def
						] if
					][B
						/Result #0 def 
						/MissingFile FileName def
					] ifelse
				] if
			] if 			  
			
			[A /MissingFile /Result]
		] def
		
	]
	
	/InstallProc [P
		
		[A ]
		/Continue #1 def
		'Checking Servo Controller...' log
		/EloType  GetEloType def
		EloType CheckEloIsKnown [B
			/Controller EloType GetEloDict def
			%'Device Type: ' Controller.Name add log
			'Device Text: ' GetEloTypeStr add log
			'Device Type ID: 0' EloType 16 cvrs add 'h' add log
			Controller.TypeSupported 1 eq [B
				'Device Type Supported: True' log
				/EloHWVersion GetEloVersion def
				'Device HW Version: 0' EloHWVersion 16 cvrs add 'h' add log	
				EloHWVersion Controller CheckHWVersionCompatible 
				/LastCompatibleFirmware exch def
				/Compatible exch def
				Compatible [B
					'Device HW version supported: True' log	
					/EloSWVersion GetEloSWVersion def
					'Device SW Version: ' EloSWVersion cvs add log
					EloSWVersion Controller CheckEloSWVersionCompatible [B 
						'Device SW ID Supported: True' log		    
						'' log
						
						/PowerExtension Controller.PowerExtension def
						/EloTypeExt Controller.EloTypeExt def
						/EasyStepsParExt Controller.EasyStepsParExt def
						
						Continue [B
							% Applications
							Controller.Applications Count 1 eq [B
								Controller.Applications [B
									/ApplSel exch def
									ExitLoop														  							  
								] forall
								ApplSel.Name 'None' ne [B
									/Continue #1 def
								]
								[B
									/Continue #0 def    
								] ifelse	                
							][B
								/Continue #0 def
							] ifelse
						] if			
						
						Continue [B
							'' log
							'Checking files...'  log	
							
							FileCheck [B
								'...all necessary files have been found.' log	
								'' log
								'Installing Application'  log
								'' log
								
								ProgFlag not [B /Bool ReadyForStopDlg def ] [B /Bool #1 def ] 
								ifelse
								
								Bool [B					
									'Stop Firmware' log		
									PackInst:StopProgram
									'Erase Application Sector...' log
									$A0180000 PackInst:EraseFlash
									'Starting download procedure...' log
									'' log
									Continue [B
										APPLInstallValidAddr InstallationInvalid WriteWordToElo
									] if 									
									
									Continue [B
										ApplSel.Name 'None' ne [B
											#1 ApplLoadSW   %LoadFlag
											/Continue exch def
											/MissingFile exch def
											'' log
											Continue [B
												APPLInstallValidAddr InstallationValid WriteWordToElo
											] if
										] if
									] if
									
									Continue [B																		    
										
										'' log
										'Resetting Device. Please wait...' log
										ResetDevice                                                                                            
										6000 wait
										
									] if
									
									Continue not [B
										'Installation aborted! ' log
										'' '' '' AbortDlg														
									][B
										'Application installation completed!' log
										ProgFlag not [B
											SuccessDlg
										] if
									] ifelse
								][B
									'Installation aborted! ' log																				
								] ifelse						
							][B
								/MissingFile exch def
								'Installation aborted! ' log				
								
								'File not found: \' MissingFile add log
								'File not found: \' MissingFile add '' '' AbortDlg								
							] ifelse								
						] if		
						
					][B
						'Device SW ID Supported: False' log				
						'' log
						'Installation aborted! ' log
						'Device SW ID not supported!' '' '' AbortDlg
					] ifelse
				][B
					'Device HW version supported: False' log				
					'' log
					'Installation aborted! '
					'The Version ' EloHWVersion 16 cvrs add 'h' add 
					' of the Controller ' add Controller.Name add 
					' is not compatible with this firmware release!' add log 
					' Last firmware release which supports this HW version is: ' LastCompatibleFirmware '!' add add add log
					LastCompatibleFirmware '' ne [B
						'HW version not supported!' 'Last firmware version that supports this hardware: ' LastCompatibleFirmware add 
						'The corresponding installation script file can be found in the subfolder: ..\Firmware\OlderReleases\'  AbortDlg				
					]
					[B
						'HW version not supported! ' '' '' AbortDlg
					] ifelse  
				] ifelse
			][B
				'Device Type Supported: False' log	
				'' log
				'Installation aborted! '
				'The Controller ' add Controller.Name add 
				' is not compatible with this firmware release!' add log
				'Device Type not supported!' '' '' AbortDlg							
			] ifelse
		][B
			'Device Type: 0' EloType 16 cvrs add 'h' add log
			'' log
			'Installation aborted! Unknown  Device Type!' log
			'Unknown  Device Type!' '' '' AbortDlg
		] ifelse       	
		
		[A /Continue ]
		
	]
	
	
	/InitPackInst [B
		ProgFlag [B
			/DevName exch def        	        	
			/Device Create:Device def
			DevName Device.AssignDevice
			DevName /PackInst:OnMessageCallback PackInst:Init
		] [B
			/PackInst:OnMessageCallback PackInst:InitNew
			/Device PIVar:Device def
			/PortName 'PortName' Device.GetDeviceVar def
		] ifelse
		/InitResult exch def
		InitResult [B
			/TalkIntf PIVar:TalkIntf def
			/TalkVersion PIVar:TalkVersion $F0 and def
			/InstallationInvalid $ffff def
			/InstallationValid $1111 def
			TalkVersion [B
				$40 [B 
					/Offset $300000 def 
					/FWInstallValidAddr $30086A def
					/OSInstallValidAddr $30086C def
					/MCInstallValidAddr $30086E def
					/INTFInstallValidAddr $300870 def
					/APPLInstallValidAddr $300872 def
					/MACIDSourceSelAddr $300860 def
					/MACIDValueAddr $300802 def
				] %B1100
				$30 [B 
					/Offset $A2000000 def 
					/FWInstallValidAddr $A2001940 def
					/OSInstallValidAddr $A2001942 def
					/MCInstallValidAddr $A2001944 def
					/INTFInstallValidAddr $A2001946 def
					/APPLInstallValidAddr $A2001948 def
					/IPAddressAddrWorking $C0000084 def
					/NetMaskAddrWorking $C0000088 def
					/DefaultGatewayAddrWorking $C000008C def           				           				
					/IPAddressAddr $A2001840 def
					/NetMaskAddr $A2001844 def
					/DefaultGatewayAddr $A2001848 def           				
					/IPConfigModeAddr $A200184E def
				] % E1200/E1400 
				$20 [B 
					/Offset $200000 def 
					/FWInstallValidAddr $20071A def
					/OSInstallValidAddr $20073E def
					/MCInstallValidAddr $200740 def
					/INTFInstallValidAddr $200742 def
					/APPLInstallValidAddr $200744 def
				] %E1100
			]
			[B
				'Installation aborted! Unknown talk protocol version!' raisese
			] case
			/log [B 'LogTxt' exch PackInst:OnMessageCallback ] def
			#1
		] [B
			#0
		] ifelse
	]
	
	/PackInstExit [B
		PackInst:Exit
	]
	
]