From 76017226c92e01ead75b24e10d36477dd631c2cd Mon Sep 17 00:00:00 2001
From: wenzheng.yang <981894274@qq.com>
Date: 星期二, 13 六月 2023 09:14:24 +0800
Subject: [PATCH] 更新

---
 src/baowen/Dell_55AA01.java |  250 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 250 insertions(+), 0 deletions(-)

diff --git a/src/baowen/Dell_55AA01.java b/src/baowen/Dell_55AA01.java
new file mode 100644
index 0000000..bfb6032
--- /dev/null
+++ b/src/baowen/Dell_55AA01.java
@@ -0,0 +1,250 @@
+package baowen;
+import java.math.BigInteger;
+
+import DataBase.DatabaseManagement;
+import data_model.Dell_door;
+import data_model.Dell_fangzhuang;
+import data_model.Dell_tag;
+import data_model.Tb_fangzhuang;
+import data_model.Tb_tag;
+import frame.Index1;
+import publicclass.GetNowTime;
+import publicclass.Shi_jian_cha_sss;
+public class Dell_55AA01 {
+	static String baotou;//包头 0x55AA 
+	static String zhilingtype;//指令类型0x01正常模式;0x02心跳包
+	static String lenth;//数据长度17 1BYTE
+	static String xuhao;//序号 1BYTE
+	static String tagid;//标签id 2BYTE
+	static String anchorid;//基站id
+	static String distance10;//10进制距离
+	static String power;//电量
+	static String button;//按键
+	static String baoliu;//保留
+	static String distanceMessage;//实时距离信息
+	static String zhiling01="01";//指令类型01代表正常模式
+	static String zhiling02="02";//指令类型02代表心跳包
+	static String zhiling03="03";//指令类型03代表参数读写模式
+	static String zhiling="";
+	static String  hexshow="";
+	static String sudu="";
+	static String baistart;//白名单起始ID
+	static String baistop;//白名单终止ID
+	static String gujiantype;//固件类型
+	static int f4gj=0;//固件类型
+	static String tag_state;//标签激活状态
+	static Tb_fangzhuang fzdata=null;
+	static StringBuffer data=new StringBuffer();
+
+
+	static int info_lenth=0;
+
+	static boolean succpeizhi=false;
+
+
+	public static void dell55aa01_start(String message,String ip,int port) {
+		if(!message.startsWith("55AA01")) {
+			return;
+		}
+		message=message.replaceAll("\r\n|\r|\n", "");//取出所有換行和回车
+		String[] aa0=message.split("55AA");
+		int size=aa0.length;
+		for(int i=0;i<size;i++) {
+			String info="55AA"+aa0[i];
+			dell55AA01(info,ip,port);
+		}
+	}
+
+	/**处理55AA01开头的测距信息
+	 * 55 AA 01 11 AF 01 00 05 00 10 02 00 00 64 00 00 00 00 00 C2 FE
+	 */
+	public static void dell55AA01(String infom,String ip,int port) {
+		int timestamp=GetNowTime.timestamp();
+		String intime=GetNowTime.timestamp2();
+		int lenth1=infom.length()/2;
+		if(lenth1>10) {
+			int size=lenth1;
+			//将信息2个字符1位保存在数组中
+			String[] hex=new String[size];
+			for(int i=0;i<size;i++) {
+				hex[i]=infom.substring(i*2, 2+i*2);
+			}
+			//指令类型
+			zhilingtype=hex[2];
+			if(!zhilingtype.equals("01")) {
+				return;
+			}
+			//数据长度
+			int datalen=decodeHEX(hex[3])+4;
+			lenth= String.valueOf(decodeHEX(hex[3]));
+			if(datalen==lenth1) {		
+				//包序
+				xuhao=String.valueOf(decodeHEX(hex[4]));
+				//模块ID tagid
+				tagid=hex[6]+hex[5];	
+				//模块ID anchorid
+				anchorid=hex[8]+hex[7];
+				/**测距距离*/
+				int dis=decodeHEX(hex[12]+hex[11]+hex[10]+hex[9]);
+				distance10=String.valueOf(dis);
+
+				/**电量*/
+				power=String.valueOf(decodeHEX(hex[13]));
+
+				/**按键*/
+				button=String.valueOf(decodeHEX(hex[14]));
+
+				/**保留位*/
+				baoliu=String.valueOf(decodeHEX(hex[15]));
+				dellceju(anchorid ,dis);
+				showdata();		
+			}else {
+				Dell_uanshi_byt.intsert(ip,infom,intime, timestamp,port);
+			}
+			hex=null;
+		}else {
+			Dell_uanshi_byt.intsert(ip,infom,intime, timestamp,port);
+		}
+		
+
+	}
+
+
+	/**报文显示调用*/
+	public static void showdata() {
+		if(Index1.getTagid().equals("原始数据")) {
+			return;
+		}
+		if(Index1.isShoware()) {
+			data.append("ID:"+tagid+",");
+			data.append("包序:"+xuhao+",");
+			data.append("电量:"+power+",");
+			data.append("编号:"+anchorid+",");
+			data.append("距离:"+distance10);			
+			String as=data.toString();	
+			if(Index1.getTagid().equals("0")) {
+				Index1.ara_show(as);
+			}else {
+				if(Index1.getTagid().equals(tagid)) {
+					Index1.ara_show(as);
+				}
+			}			
+			data.setLength(0);
+		}
+
+	}
+
+	public static String get_realldistance() {
+		return distanceMessage;
+	}
+
+	/**16进制转为10进制*/
+	public static int decodeHEX(String hexs){
+		BigInteger bigint=new BigInteger(hexs, 16);
+		int numb=bigint.intValue();
+		return numb;
+
+	}
+
+	/**32进制转为10进制*/
+	public static String change32To10(String num) {
+		int f=32;
+		int t=10;
+		return new java.math.BigInteger(num, f).toString(t);
+	}
+
+
+	/** 
+	 * 将byte[]转为各种进制的字符串 
+	 * @param bytes byte[] 
+	 * @param radix 基数可以转换进制的范围,从Character.MIN_RADIX到Character.MAX_RADIX,超出范围后变为10进制 
+	 * @return 转换后的字符串 
+	 */ 
+	public static String binary(byte[] bytes, int radix){  
+		return new BigInteger(1, bytes).toString(radix);// 这里的1代表正数  
+	} 
+
+
+	private static final char[] HEXES = {
+			'0', '1', '2', '3',
+			'4', '5', '6', '7',
+			'8', '9', 'a', 'b',
+			'c', 'd', 'e', 'f'
+	};
+
+	/**
+	 * byte数组 转换成 16进制小写字符串
+	 */
+	public static String bytes2Hex(byte[] bytes) {
+		if (bytes == null || bytes.length == 0) {
+			return null;
+		}
+
+		StringBuilder hex = new StringBuilder();
+
+		for (byte b : bytes) {
+			hex.append(HEXES[(b >> 4) & 0x0F]);
+			hex.append(HEXES[b & 0x0F]);
+		}
+
+		return hex.toString();
+	}
+
+
+
+
+
+	/**截取指定长度的BYTE数组
+	 * @param src原字节数组
+	 * @param 开始位置
+	 * @param 截取长度*/
+	public static byte[] subBytes(byte[] src, int begin, int count) {
+		byte[] bs = new byte[count];
+		System.arraycopy(src, begin, bs, 0, count);
+		return bs;
+	}
+
+	/**处理测距数据方法*/
+	public static void dellceju(String anchorid ,int dis) {
+		fzdata=Dell_fangzhuang.get_anchor(anchorid);
+		if(fzdata !=null) {
+			int dis0=Integer.parseInt(fzdata.getFzDis());//防撞距离
+			String door=fzdata.getDoor();
+			if(!(dis0<dis)) {//如果防撞距离不大于设定为距离
+				Tb_tag tag =Dell_tag.get_tag(tagid);
+				if(tag ==null) {//插入数据库
+					indatabase(anchorid,dis+"", power+"");
+				}else {
+					String time=tag.getTime();
+					boolean aa=Shi_jian_cha_sss.shijiancha(time,300);
+					if(aa) {//插入数据库
+						indatabase(anchorid,dis+"", power+"");
+					}
+				}
+				Dell_tag.addtagoraler(tagid, anchorid, door);
+			}			
+		}
+	}
+
+	//将数据插入数据库
+	public static void indatabase(String anchorid,String distance, String power) {
+		if (power.equals("0")) {
+			power="1";
+		}
+		Dell_door.insert_tbdoor(tagid,anchorid,distance,power,GetNowTime.now());
+		
+//		String[]  ziduan= {"tagid","anchorid","distance","power","addtime"};
+//		String[] zhi= {tagid,anchorid,distance ,power,GetNowTime.now()};
+//		DatabaseManagement.insertfast("tb_door", ziduan, zhi);
+	}
+	public static String[] hex(String message) {
+		int size=message.length()/2;		
+		String[] hex=new String[size];
+		for(int i=0;i<size;i++) {
+			hex[i]=message.substring(i*2, 2+i*2);
+		}
+
+		return hex;
+	}
+
+}

--
Gitblit v1.9.3