package com.hxzkoa.udp; import java.math.BigInteger; import java.util.List; import java.util.Vector; import com.hxzkoa.json.tb_tag; /** 该类用于控制标签相关参数 */ public class ControTag { /** * 下发标签振动 * * @param time * 需要振动的时间0-255秒 * @param tagid需要下发的标签ID */ public static int set_tag_zhendong(int time, String tagid, List tagList, String port, String wifi_mode) { int succ = 0; // 4.下发标签振动 byte[] byt; if (("ALL").equals(tagid)) { byt = Read_Write_Anchor_Message.write_taghz(time, tagzu(tagList), (byte) 0x10); } else { byt = Read_Write_Anchor_Message.write_one_taghz(time, tagid, (byte) 0x10); } Dell_Ip.alert_all_ip(byt,port,wifi_mode); byt = null; return succ; } /** * 修改标签休眠时间 * * @param time * 需要休眠的时间 * @param tagid需要下发的标签ID */ public static int set_tag_sleep_time(int sleeptime, String tagid, List tagList, String port, String wifi_mode) { int succ = 0; // 2.修改标签休眠时间 byte[] byt; if (("ALL").equals(tagid)) { byt = Read_Write_Anchor_Message.write_taghz(sleeptime, ControTag.tagzu(tagList), (byte) 0x3a); } else { byt = Read_Write_Anchor_Message.write_one_taghz(sleeptime, tagid, (byte) 0x3a); } Dell_Ip.alert_all_ip(byt,port,wifi_mode); byt = null; return succ; } /** * 开启或者关闭标签休眠 * * @param time * 开启或者关闭 * @param tagid需要下发的标签ID */ public static int set_tag_sleep_open(int sleep_open, String tagid, List tagList, String port, String wifi_mode) { int succ = 0; // 1.开启或者关闭标签休眠 byte[] byt; if (("ALL").equals(tagid)) { // 标签是否开启休眠 byt = Read_Write_Anchor_Message.write_taghz(sleep_open, ControTag.tagzu(tagList), (byte) 0x3e); } else { byt = Read_Write_Anchor_Message.write_one_taghz(sleep_open, tagid, (byte) 0x3e); } Dell_Ip.alert_all_ip(byt,port,wifi_mode); return succ; } /** * 修改标签的功率 * * @param time * 开启或者关闭 * @param tagid需要下发的标签ID */ public static int set_tag_gonglv(int gonglv, String tagid, List tagList, String port, String wifi_mode) { int succ = 0; // 3.修改标签的功率 byte[] byt; if (("ALL").equals(tagid)) { byt = Read_Write_Anchor_Message.write_taghz(gonglv, ControTag.tagzu(tagList), (byte) 0x36); } else { byt = Read_Write_Anchor_Message.write_one_taghz(gonglv, tagid, (byte) 0x36); } Dell_Ip.alert_all_ip(byt,port,wifi_mode); byt = null; return succ; } /** 修改标签的频率 */ public static int set_tag_hz(String pinlv, String tagid, List tagList, String port, String wifi_mode) { int succ = 0; // 5.修改标签的频率 int hz = 1000; if (pinlv.equals("2")) { hz = 500; } else if (pinlv.equals("4")) { hz = 250; } else if (pinlv.equals("5")) { hz = 200; } else if (pinlv.equals("8")) { hz = 125; } else if (pinlv.equals("10")) { hz = 100; } else if (pinlv.equals("20")) { hz = 50; } else if (pinlv.equals("25")) { hz = 40; } else if (pinlv.equals("50")) { hz = 20; } byte[] byt; if (("ALL").equals(tagid)) { byt = Read_Write_Anchor_Message.write_taghz(hz, tagzu(tagList), (byte) 0x06); } else { byt = Read_Write_Anchor_Message.write_one_taghz(hz, tagid, (byte) 0x06); } Dell_Ip.alert_all_ip(byt,port,wifi_mode); byt = null; return succ; } /** * 修改加速度计阈值 * * @param time * 开启或者关闭 * @param tagid需要下发的标签ID */ public static int set_tag_jiasu(int yuzhi, String tagid, List tagList, String port, String wifi_mode) { int succ = 0; // 6.修改加速度计阈值 byte[] byt; if (("ALL").equals(tagid)) { byt = Read_Write_Anchor_Message.write_taghz(yuzhi, tagzu(tagList), (byte) 0x38); } else { byt = Read_Write_Anchor_Message.write_one_taghz(yuzhi, tagid, (byte) 0x38); } Dell_Ip.alert_all_ip(byt,port,wifi_mode); byt = null; return succ; } /** * 修改静止时间 * * @param time * @param tagid需要下发的标签ID */ public static int set_tag_jingzhi(int time, String tagid, List tagList, String port, String wifi_mode) { int succ = 0; // 7.修改静止时间 byte[] byt; if (("ALL").equals(tagid)) { byt = Read_Write_Anchor_Message.write_taghz(time, tagzu(tagList), (byte) 0x14); } else { byt = Read_Write_Anchor_Message.write_one_taghz(time, tagid, (byte) 0x14); } Dell_Ip.alert_all_ip(byt,port,wifi_mode); byt = null; return succ; } /** 开启或者关闭标签振动功能 */ public static int set_tag_move(int jck_move, String tagid, List tagList, String port, String wifi_mode) { int succ = 0; // 8.开启或者关闭标签振动功能 byte[] byt; if (("ALL").equals(tagid)) { byt = Read_Write_Anchor_Message.write_taghz(jck_move, tagzu(tagList), (byte) 0x3C); } else { byt = Read_Write_Anchor_Message.write_one_taghz(jck_move, tagid, (byte) 0x3C); } Dell_Ip.alert_all_ip(byt,port,wifi_mode); byt = null; return succ; } /** 获取标签组 */ public static Vector tagzu(List tagList) { Vector zu = new Vector(); int size = tagList.size(); if (size > 1) { // 将第一个标签ID加入集合,也就是最大的ID加入集合 zu.add(tagList.get(size - 1).getTag_id()); // 将16进制的a转为10进制 for (int i = size - 1; i > 0; i--) { String aa = tagList.get(i).getTag_id(); String bb = tagList.get(i - 1).getTag_id(); int a = decodeHEX(aa); int b = decodeHEX(bb); int result = a - b; if (result != 1) { zu.add(aa); zu.add(bb); } } zu.add(tagList.get(0).getTag_id()); } else if (size == 1) { zu.add(tagList.get(0).getTag_id()); zu.add(tagList.get(0).getTag_id()); } return zu; } /** 16进制转为10进制 */ public static int decodeHEX(String hexs) { BigInteger bigint = new BigInteger(hexs, 16); int numb = bigint.intValue(); return numb; } }