package com.ld.igds.protocol.gps;
|
|
import com.ld.igds.protocol.gps.analysis.AnalysisAuthInfo;
|
import com.ld.igds.protocol.gps.analysis.AnalysisLocationInfo;
|
import com.ld.igds.protocol.gps.analysis.AnalysisRegisterInfo;
|
import com.ld.igds.protocol.utl.GpsUtils;
|
import com.ld.igds.util.BytesUtil;
|
import com.ld.io.api.IoSession;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
/***
|
* 解析GPS信息类型
|
*
|
* @author:
|
* @description:
|
* @version:
|
* @data:
|
*
|
*/
|
@Slf4j
|
@Component(AnalysisInvoker.BEAN_ID)
|
public class AnalysisInvoker {
|
|
public static final String BEAN_ID = "zxlk.gpsAnalysisInvoker";
|
|
@Autowired
|
private AnalysisRegisterInfo analysisRegisterInfo;
|
@Autowired
|
private AnalysisAuthInfo analysisAuthInfo;
|
@Autowired
|
private AnalysisLocationInfo analysisLocationInfo;
|
|
/**
|
* 注册:7E 0100 0031 013820036316 0002 0000000000000000004632303028464C592D44725370292D56322E3933303033363331363131332E3130362E39332E3530 3A 7E
|
* 7E 0100 0021 015294626226 001B 002C012F37303131314135452D385720203030303030303001D4C1423838383838 C3 7E
|
* 鉴权:7E 0102 0006 013820036316 0182 013820036316 86 7E
|
* 7E 0102 0006 015294626226 001C 015294626226 19 7E
|
* 心跳:7E 0002 0000 013820036316 0021 4C 7E
|
* 7E 0002 0000 015294626226 002B C8 7E
|
* 位置主动汇报:7E 0200 0022 013820036316 000A 00000000 00000002 0212EA33 06C46ED6 0000 0000 0131 200827150858 010400000001 8A 7E
|
* 7E 0200 0073 015294626226 001E 00000000 00000003 018C4466 06BFB5E0 00B6 000A 015D 200829113327 010400000000EB4F0004002D100400060089FFFFFFFF000300A864002400A901CC0006E3D081DC10E3D0808F19E3D0AA3E16E3D081E615E3D03B4E14E3D06F7411000C00B289860444011890150426000600C5FFFFFFEFEC7E
|
*
|
* 位置查询应答:7E 0201 0024 013820036316 000F 0001 00000000 00000002 0212EA33 06C46ED6 0000 0000 003D 200827150953 010400000001 8E 7E
|
* 7E 0201 00E7 015294626226 00A7 0001 00000000 00000003 018C4424 06BFB5C0 00B0 0000 00D1 200829115127 010400000000EBC10004002D0FFA00060089FFFFFFFF000300A863002400A901CC0006E3D081DC2AE3D06F741CE3D07FFA17E3D081DE12E3D081DD0FE3D080900D000C00B289860444011890150426007000B90530343A38383A35663A38343A32303A62352C2D36362C31383A36393A64613A37323A63613A39362C2D36372C64303A63373A63303A65633A39623A36652C2D37332C37383A61313A30363A33633A37383A34382C2D37382C39343A64393A62333A62663A35323A36652C2D3831000600C5FFFFFFEFFE7E
|
*
|
* 7E07040078015294626226002600010100730000000000000003018C442406BFB5C0000000000000200829124211010400000000EB4F0004002D102C00060089FFFFFFFF000300A864002400A901CC0006E3D081DC1AE3D06F7414E3D07FFA13E3D081E612E3D0AA3E0EE3D03B4E0E000C00B289860444011890150426000600C5FFFFFFEBCD7E
|
*/
|
public void analysis(IoSession ioSession, String ip, Integer port, byte[] bytes) {
|
|
try {
|
//接收消息时:验证消息头尾标识-->转义还原-->验证校验码-->解析消息
|
String strMsg = BytesUtil.bytesToString(bytes);
|
|
//验证消息标识符
|
if(! strMsg.substring(0,2).equals(GpsUtils.MSG) ||
|
! strMsg.substring(strMsg.length()-2,strMsg.length()).equals(GpsUtils.MSG)){
|
log.debug("消息标识符错误,消息不进行处理!");
|
return;
|
}
|
|
//去除标识符
|
strMsg = GpsUtils.delIdentifier(strMsg);
|
//对消息转义还原:7D02-->7E,7D01-->7D
|
strMsg = GpsUtils.escapeCode2(strMsg);
|
|
//对消息校验码进行校验
|
String msg = strMsg.substring(0, strMsg.length() - 2);
|
String msgCheckCode = strMsg.substring(strMsg.length() - 2, strMsg.length());
|
String checkCode = GpsUtils.checkCode(msg);
|
if (!checkCode.equalsIgnoreCase(msgCheckCode)) {
|
log.debug("消息校验码错误,消息不进行处理!");
|
return;
|
}
|
|
//截取消息ID,并判断消息类型
|
String msgId = strMsg.substring(0, 4);
|
//注册
|
if (GpsUtils.MSG_01.equals(msgId)) {
|
analysisRegisterInfo.analysisRegisterInfo(ip, port, strMsg);
|
}
|
//鉴权
|
if (GpsUtils.MSG_02.equals(msgId)) {
|
analysisAuthInfo.analysisAuthInfo(ioSession, ip, port, strMsg);
|
log.debug("GPS设备登录成功");
|
}
|
//位置信息
|
if (GpsUtils.MSG_03.equals(msgId) || GpsUtils.MSG_333.equals(msgId)) {
|
log.debug("开始解析位置信息:" + strMsg);
|
analysisLocationInfo.analysisLocationInfo(ip, port, strMsg);
|
log.debug("位置信息解析成功!");
|
}
|
} catch (Exception e) {
|
log.error("GPS信息解析出现异常,异常信息:{}", e);
|
}
|
}
|
|
}
|