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);
|
}
|
}
|