jiazx0107@163.com
2023-05-17 620eab6cca2bc9ef9ea6d3067a0a5ba1deadbd1c
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
package com.ld.igds.protocol.gps;
 
import com.ld.igds.io.RemoteGpsMacService;
import com.ld.igds.io.constant.OrderRespEnum;
import com.ld.igds.io.request.GpsMacRequest;
import com.ld.igds.io.response.ProtocolResponse;
import com.ld.igds.oa.dto.GpsData;
import com.ld.igds.protocol.utl.GpsUtils;
import com.ld.igds.util.BytesUtil;
import com.ld.io.api.InvokeResult;
 
import lombok.extern.slf4j.Slf4j;
 
import org.springframework.stereotype.Component;
 
/**
 * GPS-808协议实现
 * 
 * @author Andy
 *
 */
@Slf4j
@Component(RemoteGpsMacServiceImpl.BEAN_ID)
public class RemoteGpsMacServiceImpl implements RemoteGpsMacService {
 
    public static final String BEAN_ID = "gps.remoteGpsMacServiceImpl";
 
    @Override
    public String getProtocol() {
        return "GPS_808_PROTOCOL";
    }
 
    /**
     * 查询位置请求
     *
     * @param param
     * @return
     */
    @Override
    public ProtocolResponse<GpsData> queryLocation(GpsMacRequest param) {
        // 7E 80 01 00 3C 01 38 20 03 63 16 00 01 D3 7E
        String msg = "";
        // 消息头信息(消息ID+消息体属性+手机卡号+消息流水号)
        msg += GpsUtils.MSG_33;
        msg += "0000";
        msg += param.getPhone();
        msg += "0001";
 
        // 获取校验码
        String checkCode = GpsUtils.checkCode(msg);
        msg += checkCode;
 
        // 对消息整体转义:7D-->7D01,7E-->7D02
        msg = GpsUtils.escapeCode1(msg);
 
        // 首尾添加标识符
        msg = GpsUtils.addIdentifier(msg);
 
        byte[] mess = BytesUtil.hexStrToBytes(msg);
        InvokeResult result = Gps808ServerEngine.push(param.getIp(),
                param.getPort(), mess);
 
        log.debug("发送结果:{}", result.toString());
 
        if (!InvokeResult.SUCCESS.getCode().equals(result.getCode())) {
            return new ProtocolResponse<GpsData>(OrderRespEnum.MSG_ERROR,
                    "命令执行异常:" + result.getMessage());
        }
        return new ProtocolResponse<GpsData>(OrderRespEnum.ORDER_SUCCESS,
                "命令发送完成,等待结果!");
    }
 
}