Commit 9d8a25ea authored by p x's avatar p x
Browse files

模拟录一波

parent 9edf44f0
This diff is collapsed.
......@@ -28,5 +28,5 @@ class CarVehicle {
val spaceName: String = ""
//vehiclePos 里面分别是 经度、纬度、航向角
val vehiclePos: List<Double>? = null
var vehiclePos: List<Double>? = null
}
\ No newline at end of file
......@@ -48,6 +48,12 @@ class TileJsonBean {
"/data/avp/04jianzhu/tileset.json"
)
// var tiles3d = listOf(
// "/data/adas/LanePolygon/tileset.json",
// "/data/adas/RoadSection/tileset.json",
// "/data/adas/Yizhuang_Unicom_ground1018/tileset.json"
// )
//方本地的
/* var host = "http://192.168.60.164:5003"
var host = "http://192.168.60.73:5003"
......
......@@ -154,7 +154,8 @@ class MainActivity : BaseActivity<ActivityMainBinding, MyBaseViewModel>() {
mockVM.mMineMap = mineMap
mineMap?.setZoomLevel(14f)
//设置中心点
val point = Tools.latLngToPoint(LatLng(39.80913878, 116.50166926))
// val point = Tools.latLngToPoint(LatLng(39.80913878, 116.50166926))
val point = Tools.latLngToPoint(LatLng(39.809135, 116.502434))
mineMap?.setPointToCenter(point.x, point.y)
}
})
......@@ -163,10 +164,10 @@ class MainActivity : BaseActivity<ActivityMainBinding, MyBaseViewModel>() {
override fun getToData() {
//开启websocket
getTarget()
getV2x()
// getV2x()
//开启2个HTTP sse
getCarVehicle()
getAvpStatus()
// getCarVehicle()
// getAvpStatus()
//获取车位占用情况
// getSpaceInfo()
}
......@@ -302,7 +303,7 @@ class MainActivity : BaseActivity<ActivityMainBinding, MyBaseViewModel>() {
//显示车辆位姿UI
private fun showVehicle(car: CarVehicle) {
if (car.vehiclePos == null || car.vehiclePos.getOrNull(2) == null) {
if (car.vehiclePos == null || car.vehiclePos?.getOrNull(2) == null) {
//隐藏小车
return
}
......@@ -317,9 +318,9 @@ class MainActivity : BaseActivity<ActivityMainBinding, MyBaseViewModel>() {
// println("----car.heading ${car.heading}")
//刷新主车位置
HighMapApi.setCarPosition(
car.vehiclePos.get(2),
car.vehiclePos.get(1),
car.vehiclePos.get(0),
car.vehiclePos!!.get(2),
car.vehiclePos!!.get(1),
car.vehiclePos!!.get(0),
20.80189
// car.elevation
)
......@@ -328,13 +329,16 @@ class MainActivity : BaseActivity<ActivityMainBinding, MyBaseViewModel>() {
//联网车辆感知物
private fun getTarget() {
mainVm.subTarget().observe(this) {it->
if (it.isEmpty()) {
HighMapApi.clearPtcData()
mainVm.subTarget().observe(this) { it ->
if (it.getOrNull(0) == null) {
return@observe
}
var parts = it.flatMap { it.participants }
if (parts.count() == 0) {
HighMapApi.clearPtcData()
return@observe
}
var ptcList = parts.map {
var unityPtc = UnityPtc().apply {
lat = it.latitude
......
......@@ -69,7 +69,9 @@ class CarPanelFragment : BaseFragment<FragmentCarPanelBinding, MyBaseViewModel>(
}
override fun getToData() {
// carPanelVM.mock()
if (mainVm.isMock){
carPanelVM.mock()
}
}
companion object {
......
......@@ -110,7 +110,7 @@ class UnityFragment : Fragment() {
// HighMapApi.setCameraAngle(90f)
// HighMapApi.setCameraDistance(80f)
HighMapApi.setCameraAngle(30f)
HighMapApi.setCameraDistance(3f)
HighMapApi.setCameraDistance(5f)
// } catch (e: Exception) {
// }
// }, 300)
......
......@@ -7,9 +7,8 @@ object MyContants {
/**全局预警持续时间 5秒*/
const val WARNINGTIME = 5000L
//测试环境
// var HOST = "https://itg-dev.cu-sc.com:19443/"
//HTTP地址
//HTTP地址 //测试环境
const val HOST = "https://172.24.124.130:19443"
//智网生产环境地址用于拼接3dtile.json
......
......@@ -30,6 +30,7 @@ class CarPanelVM @Inject constructor() : MyBaseViewModel() {
//航向角
carPanelBean.heading.set(dynamic.speed.toInt())
//档位
var gearType = dynamic.gearType
when (gearType) {
......@@ -57,11 +58,21 @@ class CarPanelVM @Inject constructor() : MyBaseViewModel() {
fun mock() {
//速度
carPanelBean.speed.set(30)
//驾驶模式
carPanelBean.driveMode.set(AvpContants.DRIVE_MODE_AUTOMATIC)
//航向角
carPanelBean.heading.set(0)
//电量
carPanelBean.remainSoc.set(100)
//档位
carPanelBean.tapPos.set(2)
// changeMockHeading()
changeMockDriveMode()
// changeMockDriveMode()
// changeMockLight()
// changeMockPro()
changeMockGear()
// changeMockGear()
// changeMockSpeed()
}
......
......@@ -33,6 +33,7 @@ import com.sd.cavphmi.net.RequestBodyUtil
import com.sd.cavphmi.net.SimpleSSEClient
import com.sd.cavphmi.repositorys.AvpDataRepo
import com.sd.cavphmi.utils.FileIoUtils
//import com.sd.cavphmi.utils.FileIoUtils
import com.sd.cavphmi.utils.MyContants
import com.sd.cavphmi.utils.MyContants.HTTP_TOKEN
import com.sd.cavphmi.utils.MyMapUtils
......@@ -40,6 +41,7 @@ import com.sd.cavphmi.utils.ToastHelper
import com.sd.cavphmi.websockets.FeelTargetWSClient
import com.sd.cavphmi.websockets.V2xWSClient
import com.sd.cavphmi.websockets.VecLocWSClient
import commons.stand.FileSdCardUtils
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.delay
......@@ -100,7 +102,7 @@ class MainVm @Inject constructor(
lateinit var mockVM: MockVM
//是否需要模拟
var isMock = true
var isMock = false
//车辆位姿数据
// var carVehicle = MutableLiveData<CarVehicle>()
......@@ -215,7 +217,7 @@ class MainVm @Inject constructor(
viewModelScope.launch {
if (data.isNotEmpty()) {
// println("-------AVP状态 = ${data}")
FileIoUtils.writeToFile(data, "avp_status.txt")
FileSdCardUtils.writeFileToDownload(data, "avp_status.txt")
try {
var result = gson.fromJson<AvpStatuBean>(data, AvpStatuBean::class.java)
avpStatu.emit(result)
......@@ -227,7 +229,7 @@ class MainVm @Inject constructor(
}
override fun onError(throwable: Throwable) {
println("------开启AVP状态连接断开 ${throwable} 3秒后重连")
println("------AVP状态连接断开 ${throwable} 3秒后重连")
viewModelScope.launch {
delay(3000)
getAvpStatus()
......@@ -244,7 +246,8 @@ class MainVm @Inject constructor(
*/
fun subVehicle(): StateFlow<CarVehicle> {
if (isMock) {
mockVM.subVehicle(carVehicle)
// mockVM.subVehicle(carVehicle)
mockVM.onVehicleMock(carVehicle)
} else {
var url = "${MyContants.HOST}/api/avpweb/hmi/monitor/v1/monitorDrivenStatus"
carCb.url = url
......@@ -267,7 +270,7 @@ class MainVm @Inject constructor(
viewModelScope.launch {
if (data.isNotEmpty()) {
// println("-----车辆位姿 = ${data}")
FileIoUtils.writeToFile(data, "CarVehicle.txt")
FileSdCardUtils.writeFileToDownload(data, "CarVehicle.txt")
try {
var result = gson.fromJson<CarVehicle>(data, CarVehicle::class.java)
carVehicle.value = result
......@@ -312,9 +315,13 @@ class MainVm @Inject constructor(
viewModelScope.launch {
//下载到sd卡下面的DownLoad文件夹下面
if (str.isNotEmpty()) {
FileIoUtils.writeToFile(str, "PerTarget.txt")
FileSdCardUtils.writeFileToDownload(str, "PerTarget.txt")
try {
var bean = gson.fromJson(str, PerceptionBean::class.java)
targetPre.postValue(bean)
} catch (e: JsonSyntaxException) {
e.printStackTrace()
}
}
}
}
......@@ -336,7 +343,7 @@ class MainVm @Inject constructor(
*/
fun subStartV2x(): LiveData<V2xStartBean> {
if (isMock) {
mockVM.onV2xMock(v2xStartBean)
// mockVM.onV2xMock(v2xStartBean)
} else {
try {
v2xWSClient.onWebSocketCb = object : OnWebSocketCb {
......@@ -350,10 +357,15 @@ class MainVm @Inject constructor(
override fun onMsg(str: String) {
viewModelScope.launch {
if (str.isNotEmpty()) {
FileIoUtils.writeToFile(str, "avp_v2x.txt")
FileSdCardUtils.writeFileToDownload(str, "avp_v2x.txt")
}
try {
var bean = gson.fromJson(str, V2xStartBean::class.java)
v2xStartBean.postValue(bean)
} catch (e: JsonSyntaxException) {
e.printStackTrace()
}
}
}
}
......
......@@ -127,7 +127,7 @@ class MapOpt @Inject constructor(
if (mMineMap != null && car.vehiclePos != null) {
if (mSmallMapCar == null) {
var point =
LatLng(car.vehiclePos.get(1), car.vehiclePos.get(0))
LatLng(car.vehiclePos?.get(1)?:0.0, car.vehiclePos?.get(0)?:0.0)
mSmallMapCar = MyLocationStyle("res/icons/carIconInSmallMap.png", true)
mSmallMapCar?.myLocationType(MyLocationStyle.LOCATION_TYPE_EXTERNAL)
val scaleFactor = -
......@@ -149,8 +149,8 @@ class MapOpt @Inject constructor(
if (carVehicle.vehiclePos == null)
return
synchronized(NativeEnv.SyncObject) {
var ndsLatLng = LatLng(carVehicle.vehiclePos.get(1), carVehicle.vehiclePos.get(0))
var tHead = carVehicle.vehiclePos.get(2).toFloat()
var ndsLatLng = LatLng(carVehicle.vehiclePos?.get(1)?:0.0, carVehicle.vehiclePos?.get(0)?:0.0)
var tHead = carVehicle.vehiclePos!!.get(2).toFloat()
//刷新小地图自车位置
if (mSmallMapCar != null) {
// mSmallMapCar!!.orientAngle((heading + 40) % 360)
......
......@@ -20,6 +20,7 @@ import com.minedata.minenavi.mapdal.NdsPoint
import com.minedata.minenavi.util.Tools
import com.sd.cavphmi.R
import com.sd.cavphmi.bean.AvpStatuBean
import com.sd.cavphmi.bean.CarPanelBean
import com.sd.cavphmi.bean.CarVehicle
import com.sd.cavphmi.bean.PerceptionBean
import com.sd.cavphmi.bean.V2xStartBean
......@@ -71,7 +72,7 @@ class MockVM @Inject constructor(
* @param binding 里的速度
* **/
fun onVehicleMock(
carVehicle: MutableLiveData<CarVehicle>
carVehicle: MutableStateFlow<CarVehicle>
) {
// HighMapApi.setCameraAngle(30f)
viewModelScope.launch {
......@@ -117,14 +118,15 @@ class MockVM @Inject constructor(
)
}
cCar = CarVehicle().apply {
var temps = this.vehiclePos?.toMutableList()
if ((head - oldHead).absoluteValue < 45) {
temps?.set(2, head)
}
temps?.set(0, it[0])
temps?.set(1, it[1])
// var temps = this.vehiclePos?.toMutableList()
// if ((head - oldHead).absoluteValue < 45) {
// temps?.set(2, head)
// }
// temps?.set(0, it[0])
// temps?.set(1, it[1])
// latitude = it[1]
// longitude = it[0]
this.vehiclePos = listOf(it[0], it[1], head)
}
oldHead = head
......@@ -135,10 +137,10 @@ class MockVM @Inject constructor(
Tools.latLngToNdsPoint(
LatLng(
cCar.vehiclePos!!.get(1),
cCar.vehiclePos.get(0)
cCar.vehiclePos!!.get(0)
)
),
cCar.vehiclePos.get(2).toFloat()
cCar.vehiclePos!!.get(2).toFloat()
)
//更新小地图路径
upSmallLine(index, mRoutes)
......@@ -166,13 +168,11 @@ class MockVM @Inject constructor(
var forword = parkPath.result.routes.find { it.gear == 3 }
forword?.polyline?.forEach { poly ->
cCar = CarVehicle().apply {
var temps = this.vehiclePos?.toMutableList()
temps?.set(0, poly.get(0))
temps?.set(1, poly.get(1))
temps?.set(2, poly.get(3))
// latitude = poly.get(1)
// longitude = poly.get(0)
// heading = poly.get(3)
// this.vehiclePos = this.vehiclePos?.toMutableList()
// vehiclePos?.set(0, poly.get(0))
// vehiclePos?.set(1, poly.get(1))
// vehiclePos?.set(2, poly.get(3))
this.vehiclePos = listOf(poly.get(0), poly.get(1), poly.get(3))
}
//更新主车位置
carVehicle.value = cCar
......@@ -181,10 +181,10 @@ class MockVM @Inject constructor(
Tools.latLngToNdsPoint(
LatLng(
cCar.vehiclePos!!.get(1),
cCar.vehiclePos.get(0)
cCar.vehiclePos!!.get(0)
)
),
cCar.vehiclePos.get(2).toFloat()
cCar.vehiclePos!!.get(2).toFloat()
)
delay(300)
}
......@@ -198,14 +198,17 @@ class MockVM @Inject constructor(
//改变镜头角度
HighMapApi.setCameraAngle(90f)
HighMapApi.setCameraDistance(20f)
//挂倒挡
CarPanelBean.instance.tapPos.set(3)
//开始后退
var fBack = parkPath.result.routes.find { it.gear == 1 }
fBack?.polyline?.forEach { poly ->
cCar = CarVehicle().apply {
var temps = this.vehiclePos?.toMutableList()
temps?.set(0, poly.get(0))
temps?.set(1, poly.get(1))
temps?.set(2, poly.get(3))
// var temps = this.vehiclePos?.toMutableList()
// temps?.set(0, poly.get(0))
// temps?.set(1, poly.get(1))
// temps?.set(2, poly.get(3))
this.vehiclePos = listOf(poly.get(0), poly.get(1), poly.get(3))
}
//更新主车位置
carVehicle.value = cCar
......@@ -214,7 +217,7 @@ class MockVM @Inject constructor(
Tools.latLngToNdsPoint(
LatLng(
cCar.vehiclePos!!.get(1),
cCar.vehiclePos.get(0)
cCar.vehiclePos!!.get(0)
)
),
cCar.vehiclePos!!.get(1).toFloat()
......@@ -226,6 +229,9 @@ class MockVM @Inject constructor(
deleteNavingCar()
//关闭流光效果
HighMapApi.parkRoundLight("")
//挂P档
CarPanelBean.instance.tapPos.set(1)
CarPanelBean.instance.speed.set(0)
//结束泊车
HighMapApi.setParkComplete(true)
//降地锁
......@@ -249,7 +255,7 @@ class MockVM @Inject constructor(
try {
temp = str
val cCar = gson.fromJson<CarVehicle>(str, CarVehicle::class.java)
if (cCar !=null || cCar?.vehiclePos != null) {
if (cCar != null || cCar?.vehiclePos != null) {
// carLiveData.postValue(cCar)
carLiveData.value = cCar
delay(100)
......@@ -370,15 +376,17 @@ class MockVM @Inject constructor(
fun onSubTargetMock(targetPre: MutableLiveData<PerceptionBean>) {
viewModelScope.launch {
val parts = mutableListOf<String>()
FileIoUtils.getAssetMock(context, "mock/shiche/PerTarget.txt", parts)
FileIoUtils.getAssetMock(context, "mock/PerTarget.txt", parts)
var temp = ""
parts.forEach { str ->
if (!str.isNullOrEmpty()) {
temp = str
var bean = parseDataBean(str, PerceptionBean::class.java)
// var bean = gson.fromJson<PerceptionBean>(str, PerceptionBean::class.java)
if (bean!=null){
if (bean != null) {
targetPre.value = bean
delay(5000)
delay(4500)
}
}
}
}
......@@ -391,7 +399,7 @@ class MockVM @Inject constructor(
FileIoUtils.getAssetMock(context, "mock/avp_v2x.txt", parts)
parts.forEach { str ->
var bean = parseDataBean(str, V2xStartBean::class.java)
if (bean!=null){
if (bean != null) {
targetPre.value = bean
delay(2000)
}
......@@ -454,7 +462,7 @@ class MockVM @Inject constructor(
FileIoUtils.getAssetMock(context, "mock/shiche/avp_status_park.txt", datas)
datas.forEach {
val statu = gson.fromJson<AvpStatuBean>(it, AvpStatuBean::class.java)
if (statu!=null){
if (statu != null) {
avp.emit(statu)
delay(2000)
}
......
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<!-- <import type="android.view.View" />-->
<!-- <variable-->
<!-- name="vm"-->
<!-- type="com.sd.cavphmi.viewmodels.MainVm" />-->
<!-- <variable-->
<!-- name="vm"-->
<!-- type="com.sd.cavphmi.viewmodels.MainVm" />-->
</data>
......@@ -58,18 +58,16 @@
<LinearLayout
android:id="@+id/ll_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="25dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:src="#907867"
android:visibility="gone">
<TextView
android:id="@+id/bt_vehicle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:background="@color/text_blue"
android:paddingVertical="5dp"
android:text="车辆位姿"
android:textColor="@color/white" />
......@@ -77,20 +75,18 @@
<TextView
android:id="@+id/bt_target"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_height="match_parent"
android:layout_marginLeft="3dp"
android:background="@color/text_blue"
android:paddingVertical="5dp"
android:text="感知物"
android:textColor="@color/white" />
<TextView
android:id="@+id/bt_v2x"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:background="@color/text_blue"
android:paddingVertical="5dp"
android:text="V2X预警开始"
android:textColor="@color/white" />
......@@ -98,28 +94,26 @@
<TextView
android:id="@+id/bt_avpStatu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:background="@color/text_blue"
android:paddingVertical="5dp"
android:text="AVP状态"
android:textColor="@color/white" />
<TextView
android:id="@+id/bt_vehinfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:background="@color/text_blue"
android:paddingVertical="5dp"
android:text="车辆详情"
android:visibility="gone"
android:textColor="@color/white" />
android:textColor="@color/white"
android:visibility="gone" />
<TextView
android:id="@+id/bt_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:text="网联车辆状态"
android:visibility="gone" />
......@@ -127,23 +121,23 @@
<TextView
android:id="@+id/bt_parkround"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:text="车位四周流光"
android:visibility="gone" />
<TextView
android:id="@+id/bt_parkstatu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:text="停车位绘制(占用)"
android:visibility="gone" />
<TextView
android:id="@+id/bt_lock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:text="地锁绘制"
android:visibility="visible" />
android:visibility="gone" />
<!-- <Button-->
<!-- android:id="@+id/bt_move"-->
......@@ -153,20 +147,18 @@
<TextView
android:id="@+id/warn_car"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:background="@color/text_blue"
android:paddingVertical="5dp"
android:text="预警车"
android:textColor="@color/white" />
<TextView
android:id="@+id/warn_peo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:background="@color/text_blue"
android:paddingVertical="5dp"
android:text="预警人"
android:textColor="@color/white" />
......
......@@ -7,7 +7,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
tools:context=".ui.fragment.DistantTipFragment">
tools:context=".ui.fragment.DistantTipFragment"
android:visibility="gone">
<ImageView
android:layout_width="@dimen/dp_30"
......
......@@ -8,6 +8,7 @@
<dimen name="dp_20">20dp</dimen>
<dimen name="dp_25">25dp</dimen>
<dimen name="dp_30">30dp</dimen>
<dimen name="dp_35">35dp</dimen>
<dimen name="dp_40">40dp</dimen>
<dimen name="dp_45">45dp</dimen>
<dimen name="dp_50">50dp</dimen>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment