7.8
15832144755
2021-07-08 2080267e3245f0df9efc621c279922dc5ebb7c8e
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
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;
 
    }
 
}