¶Ô±ÈÐÂÎļþ |
| | |
| | | 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; |
| | | } |
| | | |
| | | } |