package com.hxzkoa.udp;
|
|
import java.util.List;
|
|
import com.hxzkoa.json.Tag_regist_msg;
|
import com.hxzkoa.json.tb_achor;
|
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 Dell_tag_reg_ms implements Runnable {
|
Thread t = new Thread(this);
|
/** 启动线程的方法 */
|
public void startThread() {
|
t.start();
|
}
|
|
|
public void stopThread() {
|
try {
|
Thread.sleep(2000);
|
t.interrupt();
|
} catch (InterruptedException e) {
|
e.printStackTrace();
|
}
|
}
|
|
public void run() {
|
while (true) {
|
// get_ok_regs(GetNowTime.timestamp());
|
try {
|
Thread.sleep(100);
|
} catch (InterruptedException e) {
|
// TODO 自动生成的 catch 块
|
e.printStackTrace();
|
Thread.interrupted();
|
} // 休眠时间
|
}
|
}
|
|
/** 寻找有效的注册信息给到JNA处理 */
|
public void get_ok_regs(int nowtimestamp, List<Tag_regist_msg> t_r_mList, tb_achor anchor, String Zhuceanchor,
|
String udp_out, String wifi_model) {
|
if (t_r_mList.size() != 0) {
|
// 取system
|
// String url_sysSetting_bw = Config.getPostUrl() +
|
// "sysSetting_bw.do";
|
// JSONObject re_sysSetting_bw = HttpUtil.doPost(url_sysSetting_bw,
|
// "", Config.getCharset());
|
// tb_system system = (tb_system) JSONObject
|
// .toBean(JSONObject.fromObject(re_sysSetting_bw.get("result").toString()),
|
// tb_system.class);
|
|
for (int i = 0; i < t_r_mList.size(); i++) {
|
int timestamp = t_r_mList.get(i).getTimestamp();
|
|
// 如果现在的时间戳减去第一条注册信息的时间戳大于200ms
|
if (nowtimestamp - timestamp >= 200) {
|
String anchorid = t_r_mList.get(i).getAnchorid();
|
String tagid = t_r_mList.get(i).getTagid();
|
int tag_freq = t_r_mList.get(i).getTaghz();
|
|
int tagidint = 0;
|
// 如果标签ID存在字母
|
if (JugeHaveZimu.haszimu(tagid)) {
|
tagidint = ReadPeizhiMessage.decodeHEX(tagid);
|
} else {
|
tagidint = Integer.parseInt(tagid);
|
}
|
|
// 将数据给到动态库
|
int shijianpian = DellJAN.get_slotted_aloha(timestamp, tagidint, tag_freq);
|
|
// BaoWenShow.show(" 收:"+GetNowTime.timestamp2()+";
|
// ToJNA:"+timestamp+"; tagid:"+tagidint+";
|
// tag_freq:"+tag_freq+"; pian:"+shijianpian, "注册报文");
|
|
// 计算出时间片后将数据给到基站
|
byte[] byt = Read_Write_Anchor_Message.write_timestamp(tagid, tag_freq, shijianpian);
|
|
// 显示注册报文信息
|
if (anchor != null) {
|
String ip = anchor.getAnchorip();
|
|
// 如果指定了给某个基站下发注册信息
|
if (Zhuceanchor.length() > 3) {
|
anchorid = Zhuceanchor;
|
ip = anchor.getAnchorip();
|
Udp_Out.out(byt, byt.length, ip, udp_out, wifi_model);
|
|
} else if (Dell_Ip.get_ipanchor(ip) != null) {
|
Udp_Out.out(byt, byt.length, ip, udp_out, wifi_model);
|
}
|
|
// BaoWenShow.show(ip+"基站:"+anchorid+";"+BytesToHex.bytesToHex(byt),
|
// "注册报文");
|
}
|
// 删除掉该数据
|
t_r_mList.remove(t_r_mList.get(i));
|
}
|
}
|
}
|
|
}
|
|
/** 处理注册信息 */
|
public static void dellrgs(String infom, String ip) {
|
|
String[] hex = StringToHex.hex(infom);
|
String url_tag_bw = Config.getPostUrl() + "labelManagement_search.do";
|
|
String anchorid = hex[5] + hex[4];
|
String tagid = hex[7] + hex[6];
|
String tagstate = DellMessage.bytes2BinaryStr(DellMessage.HexStringToBinary(hex[8]));
|
|
// 开启振动01
|
String move_open = tagstate.substring(7, 8);
|
|
// 开启休眠01
|
String sleep_open = tagstate.substring(6, 7);
|
|
// 按键状态01表示按下
|
String button = tagstate.substring(5, 6);
|
|
// 标签版本号
|
String version = "V" + Integer.parseInt(hex[10], 16) + "." + Integer.parseInt(hex[9], 16);
|
|
// 标签的频率
|
int hz = Integer.parseInt(hex[11], 16);
|
|
// 标签的功率
|
int gonglv = Integer.parseInt(hex[12], 16);
|
|
// 标签的加速计阈值
|
int speed = Integer.parseInt((hex[14] + hex[13]), 16);
|
|
// 标签静止休眠时间
|
int sleep_time = Integer.parseInt((hex[16] + hex[15]), 16);
|
|
// 标签信号强度
|
int power = Integer.parseInt((hex[17]), 16);
|
|
// 修改基站的在线状态及IP
|
tb_achor anchor = new tb_achor();
|
anchor.setAnchorid(anchorid);
|
anchor.setAnchormode("1");
|
anchor.setAnchorip(ip);
|
// Anchor_Dell.set_anchor_mode(anchorid, "1", ip);
|
|
// 显示标签注册信息
|
// if(TcpIpManage.getStar()&&
|
// TcpIpManage.getDatatypeis().equals("注册报文")) {
|
String message = GetNowTime.timestamp2() + "收:" + "基站:" + anchorid + ", 标签:" + tagid + ", 标签状态:" + tagstate
|
+ ", 振动:" + move_open + ", 休眠:" + sleep_open + ", 版本:" + version + ", 频率:" + hz + ", 功率:" + gonglv
|
+ ", 加速计:" + speed + ", 休眠时间:" + sleep_time + ", 信号强度:" + power;
|
// TcpIpManage.get_text_area().setCaretPosition(TcpIpManage.get_text_area().getText().length());
|
// }
|
|
// 如果标签在列表中存在
|
// if(Tag_Dell.get_tag(tagid) !=null && !ToolBarModel.isAddtagzidong())
|
// {
|
// 报文显示
|
// 原始报文
|
// String postUrl = Config.getPostUrl();
|
// String yuanshiMessage = postUrl + "yuanshiMessage.do";
|
String messageJson = message;
|
// JSONObject json = JSONObject.fromObject(messageJson);
|
// HttpUtil.doPost(yuanshiMessage, json, "UTF-8");
|
String BaowenPath = Config.getBaowenConfig();
|
String baowenStatus = ModifyConfig.readData(BaowenPath, "baowenSwitch");
|
if (baowenStatus.equals("1")){
|
/* Udp_Receive.yuanshiMessage.add(messageJson); */
|
}
|
// 注册报文
|
// String zhuceMessage = postUrl + "zhuceMessage.do";
|
// JSONObject zhucejson = JSONObject.fromObject(messageJson);
|
// HttpUtil.doPost(zhuceMessage, zhucejson, "UTF-8");
|
baowenStatus = ModifyConfig.readData(BaowenPath, "baowenSwitch");
|
if (baowenStatus.equals("1")){
|
/* Udp_Receive.zhuceMessage.add(messageJson); */
|
}
|
//
|
tb_tag tag = new tb_tag();
|
tag.setTag_id(tagid);
|
tag.setPower(power + "");
|
// 更改标签的状态和电量信息
|
// Tag_Dell.set_tagpower(tagid, "100");
|
JSONObject jsonObject = JSONObject.fromObject(tag);
|
JSONObject re_tag_bw = HttpUtil.doPost(url_tag_bw, jsonObject.toString(), Config.getCharset());
|
tb_tag re_tag = (tb_tag) JSONObject.toBean(JSONObject.fromObject(re_tag_bw.get("result").toString()),
|
tb_tag.class);
|
if (re_tag != null) {
|
// 更新注册信息
|
// Tag_Dell.alert_tag(tagid, version, hz, move_open, sleep_open,
|
// button, gonglv, speed, sleep_time, power);
|
} else {
|
// 插入一条注册信息
|
Tag_regist_msg trgmes = new Tag_regist_msg();
|
trgmes.setTaghz(hz);
|
trgmes.setTagid(tagid);
|
trgmes.setPower(power);
|
trgmes.setAnchorid(anchorid);
|
trgmes.setTimestamp(GetNowTime.timestamp());
|
// 如果标签注册信息集合中信息不为空
|
// if (get_tagrgm(tagid) != null) {
|
// //如果新上来的注册信息的信号强度大于已经存在的标签信号强度
|
// int oldpower=get_tagrgm(tagid).getPower();
|
//
|
// if(power-oldpower<0) {
|
// trgmes.setAnchorid(anchorid);
|
// trgmes.setPower(power);
|
// }
|
// } else {
|
// insert_tagrgm(tagid, trgmes);
|
// }
|
}
|
}
|
}
|