CZT
2023-10-30 0271df79dace7b86db5e92fa73a12b24a2143aed
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
package com.ld.igds.protocol.gps.analysis;
 
import com.ld.igds.io.RemoteGpsMacService;
import com.ld.igds.io.notify.NotifyGpsMacService;
import com.ld.igds.oa.dto.GpsLocationData;
import com.ld.igds.protocol.utl.GpsUtils;
import com.ld.igds.util.BytesUtil;
 
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.text.ParseException;
import java.util.Date;
 
/**
 * GPS-808协议,位置信息解析
 */
@Component(AnalysisLocationInfo.BEAN_ID)
public class AnalysisLocationInfo {
 
    public static final String BEAN_ID = "gps.analysisLocationInfo";
    @Autowired
    private NotifyGpsMacService notifyGpsMacService;
    
    @Autowired
    private RemoteGpsMacService remoteGpsMacService;
    
    
    /**
     * 解析位置信息
     *
     * @param ip
     * @param port
     * @param message
     */
    public void analysisLocationInfo(String ip, Integer port, String message) throws ParseException {
        GpsLocationData data = new GpsLocationData();
        //位置主动汇报:0200 0022 013820036316 000A      00000000 00000002 0212EA33 06C46ED6 0000 0000 0131 200827150858 010400000001 8A
        //位置查询应答:0201 0024 013820036316 000F 0001 00000000 00000002 0212EA33 06C46ED6 0000 0000 003D 200827150953 010400000001 8E
        //消息id                                                         34.794035 113.536726
        String msgId = message.substring(0, 4);
        //手机号
        String tempPhone = message.substring(8, 20);
        data.setPhone(tempPhone);
        if(GpsUtils.MSG_333.equals(msgId)){
 
            //纬度,转10进制后除以1000000
            String tempLatitude = message.substring(40, 48);
            String latitude = String.valueOf((float)BytesUtil.hexToBigInt(tempLatitude) / 1000000);
            data.setLatitude(latitude);
 
            //经度,转10进制后除以1000000
            String tempLongitude = message.substring(48, 56);
            String longitude = String.valueOf((float)BytesUtil.hexToBigInt(tempLongitude)/1000000);
            data.setLongitude(longitude);
 
            //时间
            String tempTime = message.substring(68, 80);
            Date time = DateUtils.parseDate(tempTime, "yyMMddHHmmss");
            data.setUpdateTime(time);
        }
        if(GpsUtils.MSG_03.equals(msgId)){
 
            //纬度,转10进制后除以1000000
            String tempLatitude = message.substring(44, 52);
            String latitude = String.valueOf((float)BytesUtil.hexToBigInt(tempLatitude) / 1000000);
            data.setLatitude(latitude);
 
            //经度,转10进制后除以1000000
            String tempLongitude = message.substring(52, 60);
            String longitude = String.valueOf((float)BytesUtil.hexToBigInt(tempLongitude) / 1000000);
            data.setLongitude(longitude);
 
            //时间
            String tempTime = message.substring(72, 84);
            Date time = DateUtils.parseDate(tempTime, "yyMMddHHmmss");
            data.setUpdateTime(time);
        }
        data.setIp(ip);
        data.setPort(port);
        notifyGpsMacService.locationNotify(data);
    }
}