% Installation package for E1100 Firmware 
% Application: MasterSlave	
% Date:    12.01.2006
% Copyright 2004-2006, NTI Ltd.

[D
	
   /Main [B
    
   'PackInst' import

	% Application Definitions
	/ApplCaption 'MasterSlave' def
	/ApplSWFile 'ApplSW1100MasterSlave_' def
	/ApplSWVersion $3 def
	/ApplSWSubVersion $5 def
	/ApplSWBetaInfo  'b1' def
	/ApplTreeFile 'ApplTr1100MasterSlave_' def
	/ApplTreeVersion $3 def
	/ApplTreeSubVersion $5 def
	/ApplTreeBetaInfo  'b1' def
	    
    /ReadyForStopDlg [P
		[A ]
	    	/Result #0 def		
	    	/ReadyDlg 'Ready for Download' 400 150 Create:Form def
	    	
	    	'Label1' '' 'The System is ready for downloading the application.' 17 19 ReadyDlg.AddLabel
	    	'Label2' '' 'The download procedure will erase all former application layer 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]

	    	/AbortDlg 'Abort' 218 150 Create:Form def
	    	
   	    	'AbortLbl' '' 'Installation aborted!' 17 19 AbortDlg.AddLabel
   	    	'AbortMsg' '' Msg 17 49 AbortDlg.AddLabel
	    	   	
	    	% add ok button
    		75 25 AbortDlg.SetButtonSize
    		'Ok' '' 'Ok' 1 71 80 AbortDlg.AddButton
			AbortDlg.Execute
		[A ]
	] def

    /SuccessDlg [P
		[A Msg]

	    	/SuccessDlg 'Success' 218 140 Create:Form def
	    	
   	    	'SuccessLbl' '' 'Installation successfully completed!' 17 19 SuccessDlg.AddLabel
   	    	   	
	    	% add ok button
    		75 25 SuccessDlg.SetButtonSize
    		'Ok' '' 'Ok' 1 71 70 SuccessDlg.AddButton
			SuccessDlg.Execute
		[A ]
	] def

   /ResetDevice [B 
      TalkIntf.ResetDevice
      TalkIntf.GetResult 0 ne
      [B 'TalkError: ' TalkIntf.GetResult cvs add raisese ] if
   ] def


    /LoadAppl [P
    	[A /LoadFlag]
     		/Result #1 def
   			/MissingFile '' def	
			
			/SWFile ApplSWFile '_V' add ApplSWVersion cvs add 'S' add ApplSWSubVersion cvs add def 
			ApplSWBetaInfo '' ne [B
				/SWFile SWFile '_' add ApplSWBetaInfo add def
			] if
			/SWFile SWFile '.HX2' add def

			/TreeFile ApplTreeFile '_V' add ApplTreeVersion cvs add 'S' add ApplTreeSubVersion cvs add def 
			ApplTreeBetaInfo '' ne [B
				/TreeFile TreeFile '_' add ApplTreeBetaInfo add def
			] if
			/TreeFile TreeFile '.HX2' add def

			/DefaultParFile ApplTreeFile '_V' add ApplTreeVersion cvs add 'S' add ApplTreeSubVersion cvs add def 
			ApplTreeBetaInfo '' ne [B
				/DefaultParFile DefaultParFile '_' add ApplTreeBetaInfo add def
			] if
			/DefaultParFile DefaultParFile '.GR3' add def

			% check if files are existing
			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
  				'Stopping Firmware...' log
   				PackInst:StopProgram		

				'Erasing application firmware sector...' log     
				4 TalkIntf.ClearInstanceAll
				'Downloading application software...' log
		    	SWFile dup loadobj exch PackInst:DownloadHX2File
				'Downloading application parameter tree...' log     		
		    	TreeFile dup loadobj exch PackInst:DownloadHX2File		
				'Updating UPID list...' log
		    	TalkIntf.UpdateUPIDList       
				'Downloading application default parameters...' log
				DefaultParFile dup loadobj exch PackInst:DownloadGR3File					
			] if
	   	[A /MissingFile /Result]
   ] def
    
    
	/InstallProc [B
		'Installing ' ApplCaption add ' Application' add log
      	'' log
		'Checking files...'  log	
		#0 LoadAppl [B
			'...all necessary files have been found.' log				
			ReadyForStopDlg [B							
				'Starting download procedure...' log
				'' log
				#1 LoadAppl [B
					/MissingFile exch def
					'' log
					'Reset Device. Please wait...' log
	   	      		ResetDevice                                                                                            
    				6000 wait

					'' log
					'Installation successfully completed!' log
					SuccessDlg
				][B
					/MissingFile exch def
					'Installation aborted! ' log												
					'File not found: ' MissingFile add log
					'File not found: ' MissingFile add AbortDlg								
				] 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								
	] def



   /InitPackInst [B
      /DeviceName gknown [B
         /Device Create:Device def
         DeviceName Device.AssignDevice
         /PortName 'PortName' Device.GetDeviceVar def
         Device.DestroyDevice
         'PortName' PortName 1 DeviceName 'LinMotOnline' Device.CreateDevice
         DeviceName /PackInst:OnMessageCallback PackInst:Init
      ] [B
         /PackInst:OnMessageCallback PackInst:InitNew
         /Device PIVar:Device def
         /PortName 'PortName' Device.GetDeviceVar def
      ] ifelse
      [B
         /TalkIntf PIVar:TalkIntf def
         /log [B 'LogTxt' exch PackInst:OnMessageCallback ] def
         #1
      ] [B
         #0
      ] ifelse
   ] def

   PackInst:Exit

]


]
