yzt
2023-05-05 4c558c77a6a9d23f057f094c4dc3e315eabef497
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
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);
            // }
        }
    }
}