package com.hxzkoa.udp;
|
|
import java.math.BigInteger;
|
|
import com.hxzkoa.json.tb_achor;
|
import com.hxzkoa.json.tb_person;
|
import com.hxzkoa.json.tb_system;
|
import com.hxzkoa.json.tb_tag;
|
import com.hxzkoa.util.Config;
|
import com.hxzkoa.util.HttpUtil;
|
import com.hxzkoa.util.ModifyConfig;
|
|
import net.sf.json.JSONObject;
|
|
public class DellMessage {
|
static int start = 0;
|
static String baoxu = "00";
|
static String receive_tagid0;
|
static String anchormode = "image/anchor/基站在线.png";
|
static boolean baoxuyiyang = false;
|
static int anchornum;// 和某一个标签测距的基站的数量
|
static int sleeptime = 0;
|
// static int kuadu = Integer.parseInt(Systems.sys().getRssid());// 跨度
|
static int i = 0;
|
static String postUrl = Config.getPostUrl();
|
static String url_tag_bw = postUrl + "labelManagement_search.do";
|
static String url_warning_bw = postUrl + "warningSummary_search.do";
|
static String url_realTimeWarning_bw = postUrl + "realTimeWarning_search.do";
|
static String url_person_bw = postUrl + "personManagement_search.do";
|
static String url_realAttendance_bw = postUrl + "realAttendance_search";
|
static String url_sysSetting_bw = postUrl + "sysSetting_bw.do";
|
static String url_label_bw_power = postUrl + "label_bw_power.do";
|
static String url_fenceList_bw = postUrl + "fenceList_bw.do";
|
static String url_xunjiansetList_bw = postUrl + "xunjiansetList_bw.do";
|
static String url_warning_bw_add = postUrl + "warning_bw_add.do";
|
static String url_realinwarning_bw_add = postUrl + "realinwarning_bw_add.do";
|
static String url_realinwarning_bw_remove = postUrl + "realinwarning_bw_remove.do";
|
static String url_track_bw_add = postUrl + "track_bw_add.do";
|
static String url_realAttendance_bw_add = postUrl + "realAttendance_bw_add.do";
|
static String url_xunjianset_bw_add = postUrl + "xunjianset_bw_add.do";
|
static String url_person_bw_power = postUrl + "person_bw_power.do";
|
static String url_person_bw_SOS = postUrl + "person_bw_power.do";
|
static String url_person_bw_kaoqin = postUrl + "person_bw_kaoqin.do";
|
static String url_person_bw_warning = postUrl + "person_bw_warning.do";
|
static String url_map_bw_floor = postUrl + "map_bw_floor.do";
|
static String url_anchor_bw_status = postUrl + "anchor_bw_status.do";
|
static String url_setting_bw = postUrl + "getSysSetting.do";
|
static String url_anchor_bw = postUrl + "anchorManagement_search.do";
|
private static String hexStr = "0123456789ABCDEF";
|
private static String[] binaryArray = { "0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000",
|
"1001", "1010", "1011", "1100", "1101", "1110", "1111" };
|
|
@SuppressWarnings("unused")
|
/** 处理原始测距信息 */
|
public static void dell_info(String ip, String infom, String addtime, int timestamp) {
|
|
if (infom.startsWith("55AA01")) {
|
|
// 原始数据
|
String[] hex = StringToHex.hex(infom);
|
|
// 指令类型
|
StringBuffer zhilingtype = new StringBuffer(hex[2]);
|
|
// 数据长度
|
StringBuffer lenth = new StringBuffer(String.valueOf(decodeHEX(hex[3])));
|
|
// 包序
|
StringBuffer receive_baoxu = new StringBuffer(String.valueOf(decodeHEX(hex[4])));
|
|
// 模块ID receive_tagid
|
StringBuffer receive_tagid = new StringBuffer(hex[6] + hex[5]);
|
|
// 模块ID receive_anchorid
|
StringBuffer receive_anchorid = new StringBuffer(hex[8] + hex[7]);
|
|
// 距离
|
int receive_distance = decodeHEX(hex[12] + hex[11] + hex[10] + hex[9]);
|
|
// 电量
|
StringBuffer battery = new StringBuffer(String.valueOf(decodeHEX(hex[13])));
|
|
int batteryint = decodeHEX(hex[13]);
|
|
// 按键
|
StringBuffer button = new StringBuffer(bytes2BinaryStr(HexStringToBinary(hex[14])).substring(7, 8));
|
|
// 标签静止
|
StringBuffer jingzhi = new StringBuffer(
|
bytes2BinaryStr(HexStringToBinary(infom.substring(28, 30))).substring(6, 7));
|
|
// 标签休眠
|
StringBuffer xiumian = new StringBuffer(
|
bytes2BinaryStr(HexStringToBinary(infom.substring(28, 30))).substring(5, 6));
|
|
// 信号强度1
|
StringBuffer Strong1 = new StringBuffer("-" + decodeHEX(hex[15]));
|
|
// 信号强度差
|
StringBuffer Strong2 = new StringBuffer("-" + decodeHEX(hex[16]));
|
|
// 标签频率
|
StringBuffer taghz = new StringBuffer(String.valueOf(decodeHEX(hex[17])));
|
|
int int_taghz = decodeHEX(hex[17]);
|
|
// 标签时间片
|
StringBuffer time_pian = new StringBuffer(String.valueOf(decodeHEX(hex[18])));
|
|
StringBuffer data = new StringBuffer(addtime + " 收 ip:" + ip + " 包序:" + receive_baoxu + " 标签:"
|
+ receive_tagid + " 基站:" + receive_anchorid + " 距离:" + receive_distance + " 电量:" + battery + "%"
|
+ " 按键:" + button + " 静止:" + jingzhi + " 休眠:" + xiumian + " power:" + Strong1 + " power_diff:"
|
+ Strong2 + " taghz:" + taghz + " timepian:" + time_pian);
|
|
StringBuffer huceju=new StringBuffer(GetNowTime.now2()+" 基站:"+receive_tagid+" 基站:"+receive_anchorid+" 距离:"+receive_distance+" cm");
|
|
// 低电量告警
|
if(batteryint<5) {
|
Warnig.lowpower(batteryint, receive_tagid.toString());
|
}
|
|
/** SOS告警 **/
|
Warnig.sos(button, jingzhi, xiumian, receive_tagid, addtime,
|
receive_baoxu);
|
|
|
// 互测距显示测距信息
|
String AnchorPath = Config.getAnchorConfig();
|
String beice_anchor = ModifyConfig.readData(AnchorPath, "beice_anchor");
|
if(beice_anchor!="") {
|
if(beice_anchor.equals(receive_tagid.toString())) {
|
ModifyConfig.writeData(AnchorPath, "huceju", huceju.toString());
|
}
|
}
|
//报文显示
|
// String postUrl = Config.getPostUrl();
|
// String yuanshiMessage=postUrl+"yuanshiMessage.do";
|
String messageJson = GetNowTime.timestamp2()+ " 收:" +data.toString() ;
|
// JSONObject json = JSONObject.fromObject(messageJson);
|
// HttpUtil.doPost(yuanshiMessage, json, "UTF-8");
|
String BaowenPath = Config.getBaowenConfig();
|
String baowenContent = ModifyConfig.readData(BaowenPath, "yuanshiMessage");
|
String baowenStatus = ModifyConfig.readData(BaowenPath, "baowenSwitch");
|
if (baowenStatus.equals("1")){
|
/* Udp_Receive.yuanshiMessage.add(messageJson); */
|
}
|
|
// // 更新基站状态为在线
|
// // Anchor_Dell.set_anchor_mode(receive_anchorid.toString(), "1",
|
// // ip.toString());
|
// tb_achor anchor = new tb_achor();
|
// anchor.setAnchorid(receive_anchorid.toString());
|
// anchor.setAnchormode("1");
|
// anchor.setAnchorip(battery.toString());
|
// JSONObject anchorobject = JSONObject.fromObject(anchor);
|
// HttpUtil.doPost(url_anchor_bw_status, anchorobject.toString(), Config.getCharset());
|
//
|
// // 更改标签的状态和电量信息
|
// tb_tag tag = new tb_tag();
|
// tag.setTag_id(receive_tagid.toString());
|
// tag.setPower(battery.toString());
|
// JSONObject tagobject = JSONObject.fromObject(tag);
|
// HttpUtil.doPost(url_label_bw_power, tagobject.toString(), Config.getCharset());
|
//
|
// // 修改标签的人员的SOS状态
|
// // person_Dell.alert_sos(receive_tagid.toString(),
|
// // button.toString());
|
// tb_person person = new tb_person();
|
// person.setP_tagid(receive_tagid.toString());
|
// person.setP_power(battery.toString());
|
// person.setP_sos(button.toString());
|
// JSONObject personObject = JSONObject.fromObject(person);
|
// HttpUtil.doPost(url_person_bw_SOS, personObject.toString(), Config.getCharset());
|
//
|
// // 修改人员的电量信息,
|
// // person_Dell.alert_person_power(receive_tagid.toString(),
|
// // battery.toString());
|
//
|
// HttpUtil.doPost(url_person_bw_power, personObject.toString(), Config.getCharset());
|
//
|
// //setting
|
// JSONObject re_tb_setting = HttpUtil.doPost(url_setting_bw, "", Config.getCharset());
|
// tb_system re_setting = (tb_system) JSONObject.toBean(JSONObject.fromObject(re_tb_setting.get("result").toString()),
|
// tb_system.class);
|
//
|
// //get anchor
|
// JSONObject re_tb_anchor = HttpUtil.doPost(url_anchor_bw, anchorobject.toString(), Config.getCharset());
|
// tb_achor re_anchor = (tb_achor) JSONObject.toBean(JSONObject.fromObject(re_tb_anchor.get("result").toString()),
|
// tb_system.class);
|
//
|
// /** 铁科院定制算法已知标签所在的组和需要用来计算的基站 */
|
// if(re_setting.getKnow_tag_zu().equals("1") &&
|
// Dell_usetaganchor.get_UseTagAndAnchor(receive_tagid.toString())
|
// !=null) {
|
//
|
// UseTagAndAnchor
|
// usta=Dell_usetaganchor.get_UseTagAndAnchor(receive_tagid.toString());
|
|
}
|
}
|
|
/**
|
* 数据给到JNA处理
|
*
|
* @param receive_baoxu接收到的包序
|
* @param receive_tagid接收到的标签id
|
* @param receive_anchorid接收到的基站id集合
|
* @param receive_distance接收到的距离集合
|
* @param stationary_flag
|
* 静止状态
|
* @param signal_power信号强度
|
* @param timestamp时间戳
|
* @param int_taghz标签的频率
|
*/
|
public static void dellforJNA(String ip, String receive_baoxu, String receive_tagid, String receive_anchorid,
|
String receive_distance, String stationary_flag, String signal_power, int timestamp, String sos,
|
String battery, String layer, String power, String power_diff, int int_taghz) {
|
|
Ceju cej = new Ceju();
|
cej.setCe_baoxu(receive_baoxu);
|
cej.setCe_ip(ip);
|
cej.setCe_tagid(receive_tagid);
|
cej.setCe_timestamp(timestamp);
|
cej.setCe_anchorid(receive_anchorid);
|
cej.setCe_distance(receive_distance);
|
cej.setCe_battery(battery);// 电量
|
cej.setCe_power(power);
|
cej.setCe_power_diff(power_diff);
|
cej.setCe_taghz(int_taghz);
|
cej.setCe_jingzhi(stationary_flag);
|
|
// Dell_Ceju.dell_ceju(ip,receive_tagid,cej,Integer.parseInt(receive_baoxu),receive_anchorid);
|
|
}
|
|
/** 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;
|
}
|
|
/**
|
*
|
* @param hexString
|
* @return 将十六进制转换为字节数组
|
*/
|
public static byte[] HexStringToBinary(String hexString) {
|
// hexString的长度对2取整,作为bytes的长度
|
int len = hexString.length() / 2;
|
byte[] bytes = new byte[len];
|
byte high = 0;// 字节高四位
|
byte low = 0;// 字节低四位
|
|
for (int i = 0; i < len; i++) {
|
// 右移四位得到高位
|
high = (byte) ((hexStr.indexOf(hexString.charAt(2 * i))) << 4);
|
low = (byte) hexStr.indexOf(hexString.charAt(2 * i + 1));
|
bytes[i] = (byte) (high | low);// 高地位做或运算
|
}
|
return bytes;
|
}
|
|
/**
|
*
|
* @param str
|
* @return 转换为二进制字符串
|
*/
|
public static String bytes2BinaryStr(byte[] bArray) {
|
|
String outStr = "";
|
int pos = 0;
|
for (byte b : bArray) {
|
// 高四位
|
pos = (b & 0xF0) >> 4;
|
outStr += binaryArray[pos];
|
// 低四位
|
pos = b & 0x0F;
|
outStr += binaryArray[pos];
|
}
|
return outStr;
|
|
}
|
|
}
|