[dev_arch_opt_3.0]

[Change]
[
1、修复在斑马线修改了高德坐标系的自车位置导致,其它地方监听异常。
]

Signed-off-by: donghongyu <donghongyu@zhidaoauto.com>
This commit is contained in:
donghongyu
2023-03-17 18:00:04 +08:00
parent 8988688660
commit ef80aa8281
4 changed files with 80 additions and 58 deletions

View File

@@ -324,6 +324,50 @@ public class MogoLocation implements Cloneable {
return this;
}
public MogoLocation copy(MogoLocation lastLocation, double longitude, double latitude) {
MogoLocation mogoLocation = new MogoLocation();
mogoLocation.accuracy = lastLocation.accuracy;
mogoLocation.adCode = lastLocation.adCode;
mogoLocation.address = lastLocation.address;
mogoLocation.aoiName = lastLocation.aoiName;
mogoLocation.buildingId = lastLocation.buildingId;
mogoLocation.cityCode = lastLocation.cityCode;
mogoLocation.cityName = lastLocation.cityName;
mogoLocation.description = lastLocation.description;
mogoLocation.district = lastLocation.district;
mogoLocation.errorCode = lastLocation.errorCode;
mogoLocation.errorInfo = lastLocation.errorInfo;
mogoLocation.floor = lastLocation.floor;
mogoLocation.gpsAccuracyStatus = lastLocation.gpsAccuracyStatus;
mogoLocation.lastReceiveTime = lastLocation.lastReceiveTime;
mogoLocation.locationDetail = lastLocation.locationDetail;
mogoLocation.locType = lastLocation.locType;
mogoLocation.poiName = lastLocation.poiName;
mogoLocation.provider = lastLocation.provider;
mogoLocation.province = lastLocation.province;
mogoLocation.satellite = lastLocation.satellite;
mogoLocation.street = lastLocation.street;
mogoLocation.streetNum = lastLocation.streetNum;
MessagePad.GnssInfo gnssInfo =
MessagePad.GnssInfo.newBuilder()
.setLongitude(longitude) //经度
.setLatitude(latitude)//纬度
.setAltitude(lastLocation.gnssInfo.getAltitude()) //海拔
.setHeading(lastLocation.gnssInfo.getHeading()) //航向角
.setAcceleration(lastLocation.gnssInfo.getAcceleration()) //加速度
.setYawRate(lastLocation.gnssInfo.getYawRate()) //曲率
.setGnssSpeed(lastLocation.gnssInfo.getGnssSpeed()) //惯导车速 m/s
.setVehicleSpeed(lastLocation.gnssInfo.getVehicleSpeed()) //车辆车速 m/s
.setSatelliteTime(lastLocation.gnssInfo.getSatelliteTime()) //gps时间 单位秒s
.setSystemTime(lastLocation.gnssInfo.getSystemTime()) //系统时间 单位秒s
.build();
mogoLocation.gnssInfo = gnssInfo;
return mogoLocation;
}
public long getLastReceiveTime() {
return lastReceiveTime;
}

View File

@@ -18,7 +18,7 @@ object CallerChassisLocationGCJ02ListenerManager : CallerBase<IMoGoChassisLocati
private const val TAG = "CallerChassisLocationGCJ20ListenerManager"
@Volatile
private var mGnssInfo: MogoLocation? = null
private var mGnssInfo: MogoLocation = MogoLocation()
/**
* 添加监听并指定回掉频率
@@ -35,8 +35,8 @@ object CallerChassisLocationGCJ02ListenerManager : CallerBase<IMoGoChassisLocati
setListenerHz(tag, callBackHz)
}
fun getChassisLocationGCJ02(): MogoLocation? {
return mGnssInfo
fun getChassisLocationGCJ02(): MogoLocation {
return mGnssInfo.clone()
}
/**
@@ -46,46 +46,42 @@ object CallerChassisLocationGCJ02ListenerManager : CallerBase<IMoGoChassisLocati
@Synchronized
fun invokeChassisLocationGCJ02(gnssInfo: MogoLocation?, sourceType: DataSourceType) {
gnssInfo?.let {
// 克隆定位数据,防止原数据被篡改导致位置跳变
mGnssInfo = gnssInfo.clone()
// 转换 WGS84-->GCJ02 坐标
val gcj20Location =
CoordinateTransform.WGS84ToGCJ02(gnssInfo.longitude, gnssInfo.latitude)
mGnssInfo?.let {
mGnssInfo!!.longitude = gcj20Location[0]
mGnssInfo!!.latitude = gcj20Location[1]
// 克隆定位数据,防止原数据被篡改导致位置跳变
mGnssInfo = gnssInfo.copy(gnssInfo, gcj20Location[0], gcj20Location[1])
M_LISTENERS.forEach {
val tag = it.key
// 获取数据监听需要的HZ
val hz = M_LISTENERS_HZ[tag]
if (hz != null && hz > 0) {
val hzTime = (1.0 / hz.toDouble()) * 1000
// 获取最后一次回调的时间
val hzLastSendTime = M_LISTENERS_HZ_LAST_SEND_TIME[tag]
if (hzLastSendTime != null && hzLastSendTime > 0) {
// 计算是否进入下一次回调周期
val nowTime = TimeUtils.getNowMills()
if (nowTime - hzLastSendTime > hzTime) {
syncLocationCallback(tag, it, mGnssInfo!!, sourceType)
}
} else {
syncLocationCallback(tag, it, mGnssInfo!!, sourceType)
M_LISTENERS.forEach {
val tag = it.key
// 获取数据监听需要的HZ
val hz = M_LISTENERS_HZ[tag]
if (hz != null && hz > 0) {
val hzTime = (1.0 / hz.toDouble()) * 1000
// 获取最后一次回调的时间
val hzLastSendTime = M_LISTENERS_HZ_LAST_SEND_TIME[tag]
if (hzLastSendTime != null && hzLastSendTime > 0) {
// 计算是否进入下一次回调周期
val nowTime = TimeUtils.getNowMills()
if (nowTime - hzLastSendTime > hzTime) {
syncLocationCallback(tag, it, mGnssInfo, sourceType)
}
} else {
//Logger.d(TAG, "没设置监听频率使用默认5HZ")
val hzTime = (1.0 / 5) * 1000
// 获取最后一次回调的时间
val hzLastSendTime = M_LISTENERS_HZ_LAST_SEND_TIME[tag]
if (hzLastSendTime != null && hzLastSendTime > 0) {
// 计算是否进入下一次回调周期
val nowTime = TimeUtils.getNowMills()
if (nowTime - hzLastSendTime > hzTime) {
syncLocationCallback(tag, it, mGnssInfo!!, sourceType)
}
} else {
syncLocationCallback(tag, it, mGnssInfo!!, sourceType)
syncLocationCallback(tag, it, mGnssInfo, sourceType)
}
} else {
//Logger.d(TAG, "没设置监听频率使用默认5HZ")
val hzTime = (1.0 / 5) * 1000
// 获取最后一次回调的时间
val hzLastSendTime = M_LISTENERS_HZ_LAST_SEND_TIME[tag]
if (hzLastSendTime != null && hzLastSendTime > 0) {
// 计算是否进入下一次回调周期
val nowTime = TimeUtils.getNowMills()
if (nowTime - hzLastSendTime > hzTime) {
syncLocationCallback(tag, it, mGnssInfo, sourceType)
}
} else {
syncLocationCallback(tag, it, mGnssInfo, sourceType)
}
}
}

View File

@@ -17,7 +17,7 @@ object CallerChassisLocationWGS84ListenerManager : CallerBase<IMoGoChassisLocati
private var mGnssInfo: MogoLocation = MogoLocation()
fun getChassisLocationWGS84(): MogoLocation {
return mGnssInfo
return mGnssInfo.clone()
}
/**