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

📄 typetransformer.java

📁 初始化传感器节点
💻 JAVA
字号:
package com.mars.tools;

import com.mars.net.MotePacket;
import java.util.*;

public class TypeTransformer {
	
	public static String getStringPacket(MotePacket packet){
		
		String packetStr="";
		int len=packet.getSize();
		for(int i=0;i<len;i++){
			int temp=packet.getPacketElement(i).intValue();//获得一个包元的byte值
			int high=temp>>>4;//获得包元高4位的值
			int low=temp&0x0F;//获得包元低4位的值

			packetStr=packetStr+getString(high)+getString(low)+" ";
		}
		
		return packetStr;
	}
	
	private static String getString(int index){
		
		String[] chart=new String[]{"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"};
		
		return chart[index];
	}
	
	public static LinkedList<Integer> getBytePacket(String command){
		
		LinkedList<Integer> packetByte=new LinkedList<Integer>();
		
		byte[] chart=new byte[]{0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F};
		String indexStr="0123456789ABCDEF";
		
		byte high=0;
		byte low=0;
		
		for(int i=0;i<command.length();i++){
			String tempStr=command.substring(i, i+1);
			int index=indexStr.indexOf(tempStr.toUpperCase());
			if(i%2==0){
				high=chart[index];
			}
			else{
				low=chart[index];
				int highInt=high<<4;
//				high=new Integer(highInt).byteValue();
				int elem=highInt+low;
				Integer elemByte=new Integer(elem);
				packetByte.add(elemByte);
			}
			
		}
		
		return packetByte;
	}
	
}

⌨️ 快捷键说明

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