package com.mq.mylibrary.rfid.io.service;

public class NdefText {

	static String MB = "1"; //说明这是首记录10010001
	static String ME = "0";//说明这是首记录(说明消息只有一个记录)
	static String CF = "0"; //说明记录未被切块
	static String SR = "1";//说明这是短记录，PAYLOAD_LENGTH 占1字节
	static String IL = "0";//说明没有 ID_LENGTH 和 ID 域
	static String TNF = "001"; //TNf占三个位
	
	String ndefText = "NfcDemo";
	
	private  byte FirstByte = Tools.hexStringToBytes(Integer.toHexString(Integer.parseInt(MB+ME+CF+SR+IL+TNF, 2)))[0];;
	private  byte TYPE_LENGTH = 0x01;// 类型的长度
	private  byte PAYLOAD_LENGTH;  //payload的长度
	private  byte TYPE = Tools.hexStringToBytes(Tools.str2HexStr("T"))[0];;  //payload的类型
	private  byte[] NDEF_TEXT; //payload的内容
	private  byte[] textSyntax = Tools.hexStringToBytes("02656E");
	
	public  byte[] getNdefText(){
		
		byte[] ndefTextData;
		NDEF_TEXT = Tools.hexStringToBytes(Tools.str2HexStr(ndefText));
		PAYLOAD_LENGTH = (byte)(NDEF_TEXT.length+textSyntax.length);
		ndefTextData = new byte[NDEF_TEXT.length+7];
		ndefTextData[0] = FirstByte;
		ndefTextData[1] = TYPE_LENGTH;
		ndefTextData[2] = PAYLOAD_LENGTH;
		ndefTextData[3] = TYPE;
		ndefTextData[4] = textSyntax[0];
		ndefTextData[5] = textSyntax[1];
		ndefTextData[6] = textSyntax[2];
		
		for(int i = 0;i<NDEF_TEXT.length;i++){
			ndefTextData[i+7] = NDEF_TEXT[i];
		}
		return ndefTextData;
	}
	
	
}
