⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 j_fusionsample1.java

📁 该文档是 用的摩托罗拉的Rfid API开发包做的测试程序
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
			if(switchNo == 0){//0-[Back]				
				tblProfiles.setVisible(false);
				tblMain.setVisible(true);									
				tblMain.setFocus();
				currentTable = 0;
			}else{
				if(switchNo <= (profiles.getLength())){
					try {
						//search for profile
						for(int i=0; i<profiles.getLength();i++){
					
						  if(profiles.get(i).getId().equals(tblProfiles.getItem(switchNo).getText(2))){
							  profile = profiles.get(i);
							  break;
						  }
						}
						Win32.setWaitCursor(true);
						tblProfiles.setSelection(switchNo);
						
					  	//connect to the selected profile with persistance=true
					  	profile.connect(true);
						
					} catch (WlanException e) {
			
					  e.printStackTrace();
					}
					//And go back to the main list...
					tblProfiles.setVisible(false);
					tblMain.setVisible(true);									
					tblMain.setFocus();
					currentTable = 0;
				
					try {
						updateMainList();//update main panel when return
					} catch (Exception e1) {
						e1.printStackTrace();
					}
										
					Win32.setWaitCursor(false);
				}
			}
			digitsCount = 0;
			switchNo = 0;
			lastKeyTime = 0;
			return;
				
		}else if(currentTable == 3){
			if((ke.character >= '0') && (ke.character <= '9')){
				if(digitsCount==0){
					lastKeyTime = currKeyTime;
					switchNo = (((int)(ke.character)) - 48);
					digitsCount++;
				}
				else {
				};
			}

			else{ 
				digitsCount = 0;
				switchNo = 0;
				lastKeyTime = 0;
				return;
			}
			if(switchNo == 0){//0-[Back]				
				tblAbout.setVisible(false);
				tblMain.setVisible(true);									
				tblMain.setFocus();
				currentTable = 0;
			}
			digitsCount = 0;
			switchNo = 0;
			lastKeyTime = 0;
			return;
		}
	}
	public void keyTyped(KeyEvent ke){
	
	}
	public void keyReleased(KeyEvent ke){
	
	}
	
	public void mouseUp(MouseEvent event) {
		
		Table t = (Table)event.getSource();
		
		TableItem ti = t.getItem(new Point(event.x, event.y));		
		if (ti==null){
			return;
		}

		if(t.equals(tblMain)){
			switch(t.getSelectionIndex()){
				case 0://0-[Exit]
				deleteSampleProfiles();//delete created sample profiles when exit
				adapter.removeSignalQualityListener(this);
				tblMain.removeSelectionListener(this);
				tblVersions.removeSelectionListener(this);
				tblProfiles.removeSelectionListener(this);
				tblAbout.removeSelectionListener(this);
				tblMain.removeKeyListener(this);
				tblMain.removeMouseListener(this);
				tblVersions.removeKeyListener(this);
				tblVersions.removeMouseListener(this);
				tblProfiles.removeKeyListener(this);
				tblProfiles.removeMouseListener(this);
				tblAbout.removeKeyListener(this);
				tblAbout.removeMouseListener(this);
						
				try {
					wlan.dispose();
				} catch (WlanException e) {
					e.printStackTrace();
				}

				System.exit(0);
				break;
				
				case 3://Profiles...
				updateProfileList();//update the profile list before display
				tblMain.setVisible(false);
				tblProfiles.setVisible(true);
				tblProfiles.setSelection(0);
				tblProfiles.setFocus();
				currentTable = 2;
				break;
				
				case 4://Versions...
				tblMain.setVisible(false);
				tblVersions.setVisible(true);
				tblVersions.setSelection(0);
				tblVersions.setFocus();
				currentTable = 1;
				break;
				
				case 5://About...
				tblMain.setVisible(false);
				tblAbout.setVisible(true);
				tblAbout.setSelection(0);
				tblAbout.setFocus();
				currentTable = 3;
				break;
			}
			
		}else if(t.equals(tblVersions)){
			switch(t.getSelectionIndex()){
				case 0://0-[Back]
				tblVersions.setVisible(false);
				tblMain.setVisible(true);
				tblMain.setFocus();
				currentTable = 0;
				break;
				
			}
			
		}else if(t.equals(tblProfiles)){
			if(t.getSelectionIndex()==0){//0-[Back]				
				tblProfiles.setVisible(false);
				tblMain.setVisible(true);									
				tblMain.setFocus();
				currentTable = 0;
			}else{
				try {
					//search for profile
					for(int i=0; i<profiles.getLength();i++){
					
						if(profiles.get(i).getId().equals(tblProfiles.getItem(t.getSelectionIndex()).getText(2))){
							profile = profiles.get(i);
							break;
						}
					}
					Win32.setWaitCursor(true);

					tblProfiles.setSelection(switchNo);
								
					//connect to the selected profile with persistance=true
					profile.connect(true);

				} catch (WlanException e) {
			
					e.printStackTrace();
				}
				//And go back to the main list...
				tblProfiles.setVisible(false);
				tblMain.setVisible(true);									
				tblMain.setFocus();
				currentTable = 0;
				
				try {
					updateMainList();//update main panel when return
				} catch (Exception e1) {
					e1.printStackTrace();
				}
										
				Win32.setWaitCursor(false);
				
			}
			
		}else if(t.equals(tblAbout)){
			if(t.getSelectionIndex()==0){//0-[Back]				
				tblAbout.setVisible(false);
				tblMain.setVisible(true);									
				tblMain.setFocus();
				currentTable = 0;
			}
		}
		
		digitsCount = 0;
		switchNo = 0;
		lastKeyTime = 0;			 
	}
	public void mouseDown(MouseEvent event) {
					 
	}
	public void mouseDoubleClick(MouseEvent event) {
					 
	}
	
	/**
	 * Create a properly formatted signal quality string
	 * @param quality the current signal quality
	 * @return String representing signal quality
	 */
	String getSignalQualityString(int quality){
		ResourceBundle res = ResourceBundle.getBundle("J_FusionSample1Res", new Locale("en","US"));
		String strQuality = "";
		switch(quality){
			case WlanConstants.SignalQuality.NOSIGNAL:
			strQuality+=res.getString("SIGNAL_QUALITY_NO_SIGNAL");
			break;
			case WlanConstants.SignalQuality.EXCELLENT:
			strQuality+=res.getString("SIGNAL_QUALITY_EXCELLENT");
			break;
			case WlanConstants.SignalQuality.FAIR:
			strQuality+=res.getString("SIGNAL_QUALITY_FAIR");
			break;
			case WlanConstants.SignalQuality.GOOD:
			strQuality+=res.getString("SIGNAL_QUALITY_GOOD");
			break;
			case WlanConstants.SignalQuality.POOR:
			strQuality+=res.getString("SIGNAL_QUALITY_POOR");
			break;
			case WlanConstants.SignalQuality.VERYGOOD:
			strQuality+=res.getString("SIGNAL_QUALITY_VERY_GOOD");
			break;
		}
		return strQuality;
	}
	
	/**
	 * Update the main screen with new values
	 * @throws Exception
	 */
	void updateMainList()throws Exception{
		//get ESSID
		essid = adapter.getEssId();
		
		//get adapter name
		try{
			activeProfile = adapter.getActiveProfile().getName();
		}catch(WlanException we){
			//if no profile is active, swallow the exception
		}
		
		//get signal quality
		newQuality = adapter.getSignalQuality();
		
		//get signal strength
		newStrength = adapter.getSignalStrength();
		
		try{
			display.asyncExec(new Runnable(){
				public void run() {
					//update UI with signal quality
					tblMain.getItem(1).setText(2, newStrength + " dBm, " + getSignalQualityString(newQuality));
					//tblMain.getItem(1).setText(2, newStrength + " dBm, ");
					//update UI with ESSID
					tblMain.getItem(2).setText(2,essid);
					
					//update UI with active profile
					tblMain.getItem(3).setText(2,activeProfile);
				}
			});
		}catch(Exception e){
			//handle the error
		}
		
	}
	
	/**
	 * This method creates an ad-hoc profile and an infrastructure profile sample profiles
	 * @throws Exception
	 */
	void createSampleProfiles()throws Exception{
		ResourceBundle res = ResourceBundle.getBundle("J_FusionSample1Res", new Locale("en","US"));
		boolean adhocProfileExists = false;
		boolean infrastructureProfileExists = false;
		
		//check if these profiles already exist
		for(int i=0;i<profiles.getLength();i++){
			if(profiles.get(i).getName().trim().equalsIgnoreCase(res.getString("PROFILE_NAME_ADHOC"))){
				adhocProfileExists = true;
			}
			if(profiles.get(i).getName().trim().equalsIgnoreCase(res.getString("PROFILE_NAME_INFRASTRUCTURE"))){
				infrastructureProfileExists = true;
			}
		}
		
		if(!adhocProfileExists){
			//create AdhocProfileData object
			AdhocProfileData adhocData = new AdhocProfileData();
			
			//set channel to 2412_MHZ
			adhocData.setChannel(WlanConstants.Channel.FREQUENCY_2412_MHZ);
			
			//set encryption type to NONE
			adhocData.encryption.setEncryptionType(WlanConstants.Encryption.EncryptionType.ENCRYPTION_NONE);
			
			//set addressing mode to DHCP
			adhocData.ipSettings.setAddressingMode(WlanConstants.IpSettings.NetworkAddressingMode.IPV4_DHCP);
			
			//set power mode
			adhocData.setPowerMode(WlanConstants.PowerMode.FAST_POWER_SAVE);
			
			//set profile name
			adhocData.setProfileName(res.getString("PROFILE_NAME_ADHOC"));
			
			//set SSID
			adhocData.setEssid("SMDK-J SSID");
			
			//set transmission power
			adhocData.setTransmissionPower(WlanConstants.TransmissionPower.Adhoc.IBSS_FULL);
			
			//create profile with given data
			profiles.create(adhocData);
		}
		if(!infrastructureProfileExists){
			
			//create InfrastructureProfileData object
			InfrastructureProfileData infrastructureData = new InfrastructureProfileData();
			
			//set encryption type 设置加密类型
			infrastructureData.encryption.setEncryptionType(WlanConstants.Encryption.EncryptionType.ENCRYPTION_NONE);
			
			//set addressing mode 设置寻址模式
			infrastructureData.ipSettings.setAddressingMode(WlanConstants.IpSettings.NetworkAddressingMode.IPV4_DHCP);
			
			//set power mode 设置功率模式
			infrastructureData.setPowerMode(WlanConstants.PowerMode.FAST_POWER_SAVE);
			
			//set profile name
			infrastructureData.setProfileName(res.getString("PROFILE_NAME_INFRASTRUCTURE"));
			
			//set SSID  SSID(Service Set Identifier)也可以写为ESSID, SSID 是你给自己的无线网络所取的名字
			infrastructureData.setEssid("SMDK-J SSID");
			
			//set transmission power 设置发送功率
			infrastructureData.setTransmissionPower(WlanConstants.TransmissionPower.Infrastructure.BSS_AUTO);
			
			//set suthentication type
			infrastructureData.authentication.setAuthenticationType(WlanConstants.Authentication.AuthenticationType.NONE);
			
			//create the profile with given data 创建
			profiles.create(infrastructureData);
		}
	}
	
	/**
	 * Delete created sample profiles
	 *
	 */
	void deleteSampleProfiles(){
		ResourceBundle res = ResourceBundle.getBundle("J_FusionSample1Res", new Locale("en","US"));
		try{
			//serach for profile
			for(int i=0;i<profiles.getLength();i++){
				if(profiles.get(i).getName().trim().equalsIgnoreCase(res.getString("PROFILE_NAME_ADHOC"))){
					//delete the adhoc profile
					profiles.delete(i);
				}
				if(profiles.get(i).getName().trim().equalsIgnoreCase(res.getString("PROFILE_NAME_INFRASTRUCTURE"))){
					//delete the infrastructure profile
					profiles.delete(i);
				}
			}
		}catch(WlanException fe){
			System.out.println("error code : " + fe.getErrorcode());
			System.out.println("error code : " + fe.getDescription());
			fe.printStackTrace();
		}
		
	}
	

} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -