Commit b213484f authored by p x's avatar p x
Browse files

avp模拟服务

parent d3e221c7
...@@ -21,7 +21,7 @@ package com.sd.cavphmi.bean ...@@ -21,7 +21,7 @@ package com.sd.cavphmi.bean
// val data: VehData // val data: VehData
//) //)
class CarVehicle { class CarVehBak {
var businessStatus: String = "" var businessStatus: String = ""
// val progress: Any = "" // val progress: Any = ""
...@@ -30,4 +30,7 @@ class CarVehicle { ...@@ -30,4 +30,7 @@ class CarVehicle {
//vehiclePos 里面分别是 经度、纬度、航向角 //vehiclePos 里面分别是 经度、纬度、航向角
var vehiclePos: List<Double>? = null var vehiclePos: List<Double>? = null
//车辆行驶当前位置,用于吃掉小地图路径
var carPos = 0
} }
\ No newline at end of file
package com.inzy.wsmock.bean package com.inzy.wsmock.bean
/***车辆位姿*/ /***车辆位姿*/
class CarVeh { class RouteCarVeh {
/**业务状态 park call park_com call_com**/ /**业务状态 park call park_com call_com**/
var status = "park" var status = "park"
/***车辆行驶的点位**/ /***车辆行驶的点位**/
......
...@@ -4,18 +4,19 @@ import com.alibaba.fastjson2.JSON ...@@ -4,18 +4,19 @@ import com.alibaba.fastjson2.JSON
import com.alibaba.fastjson2.JSONObject import com.alibaba.fastjson2.JSONObject
import com.inzy.wsmock.ChannelManager import com.inzy.wsmock.ChannelManager
import com.inzy.wsmock.RequestParamHandler import com.inzy.wsmock.RequestParamHandler
import com.inzy.wsmock.bean.CarVeh import com.inzy.wsmock.bean.RouteCarVeh
import com.inzy.wsmock.bean.ParkPath import com.inzy.wsmock.bean.ParkPath
import com.inzy.wsmock.bean.V2xStartBean import com.inzy.wsmock.bean.V2xStartBean
import com.inzy.wsmock.bean.VObject import com.inzy.wsmock.bean.VObject
import com.inzy.wsmock.utils.FileIoUtil import com.inzy.wsmock.utils.FileIoUtil
import com.inzy.wsmock.utils.MyMapUtils import com.inzy.wsmock.utils.MyMapUtils
import com.sd.cavphmi.bean.CarVehicle import com.sd.cavphmi.bean.CarVehBak
import io.netty.channel.Channel import io.netty.channel.Channel
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame import io.netty.handler.codec.http.websocketx.TextWebSocketFrame
import jakarta.annotation.PostConstruct import jakarta.annotation.PostConstruct
import jakarta.annotation.PreDestroy import jakarta.annotation.PreDestroy
import kotlinx.coroutines.* import kotlinx.coroutines.*
import kotlinx.coroutines.time.delay
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import org.springframework.core.io.ResourceLoader import org.springframework.core.io.ResourceLoader
import org.springframework.stereotype.Component import org.springframework.stereotype.Component
...@@ -35,16 +36,19 @@ class AvpPushTask( ...@@ -35,16 +36,19 @@ class AvpPushTask(
// 注入ChannelManager单例 // 注入ChannelManager单例
private val channelManager = ChannelManager.instance private val channelManager = ChannelManager.instance
//车辆位姿
private var carBak = CarVehBak()
//车辆位姿,泊车 //车辆位姿,泊车
// private var carDstPark = mutableListOf<String>() // private var carDstPark = mutableListOf<String>()
private var carVehPark: CarVeh? = null private var carVehPark: RouteCarVeh? = null
//车辆位姿,倒车入库
//倒车路径 //倒车路径
private var parkPath: ParkPath? = null private var parkPath: ParkPath? = null
//车辆位姿,召车 //车辆位姿,召车
// private var carDstCall = mutableListOf<String>() private var carVehCall: RouteCarVeh? = null
private var carVehCall: CarVeh? = null
//车辆行驶的位置 //车辆行驶的位置
private var carIndex = 0 private var carIndex = 0
...@@ -67,7 +71,7 @@ class AvpPushTask( ...@@ -67,7 +71,7 @@ class AvpPushTask(
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
//读取泊车数据 //读取泊车数据
val parkStr = FileIoUtil.getFileDate(classpathResource.inputStream) val parkStr = FileIoUtil.getFileDate(classpathResource.inputStream)
carVehPark = JSON.parseObject(parkStr, CarVeh::class.java) carVehPark = JSON.parseObject(parkStr, RouteCarVeh::class.java)
//计算航向角 //计算航向角
carVehPark!!.rs?.forEachIndexed { i, doubles -> carVehPark!!.rs?.forEachIndexed { i, doubles ->
if (i > 0) { if (i > 0) {
...@@ -90,7 +94,7 @@ class AvpPushTask( ...@@ -90,7 +94,7 @@ class AvpPushTask(
//读取召车数据 //读取召车数据
classpathResource = resourceLoader.getResource("classpath:avpm/Car_fangzhen_call.txt") classpathResource = resourceLoader.getResource("classpath:avpm/Car_fangzhen_call.txt")
val callStr = FileIoUtil.getFileDate(classpathResource.inputStream) val callStr = FileIoUtil.getFileDate(classpathResource.inputStream)
carVehCall = JSON.parseObject(callStr, CarVeh::class.java) carVehCall = JSON.parseObject(callStr, RouteCarVeh::class.java)
//计算航向角 //计算航向角
carVehCall!!.rs?.forEachIndexed { i, doubles -> carVehCall!!.rs?.forEachIndexed { i, doubles ->
if (i > 0) { if (i > 0) {
...@@ -140,75 +144,86 @@ class AvpPushTask( ...@@ -140,75 +144,86 @@ class AvpPushTask(
} }
} }
private var carVehicle = CarVehicle()
/** /**
* 推送车辆位姿 * 推送车辆位姿
*/ */
private fun pushCarPos(channel: Channel) { private fun pushCarPos(channel: Channel) {
CoroutineScope(Dispatchers.Default).launch { CoroutineScope(Dispatchers.Default).launch {
delay(12000) delay(18000)
if (carVehPark?.rs?.count() == 0 || carVehCall?.rs?.count() == 0) if (carVehPark?.rs?.count() == 0 || carVehCall?.rs?.count() == 0)
return@launch return@launch
status = "park" status = "park"
//开始推送泊车 //开始推送泊车
carVehicle.businessStatus = status carBak.businessStatus = status
carVehPark!!.status = status carVehPark!!.status = status
carVehPark!!.rs?.forEachIndexed { i, doubles -> carVehPark!!.rs?.forEachIndexed { i, doubles ->
carIndex++ carIndex++
carVehicle.vehiclePos = doubles carBak.vehiclePos = doubles
sendMsg(channel, JSON.toJSONString(carVehPark)) carBak.carPos = i
sendMsg(channel, JSON.toJSONString(carBak))
delay(300) delay(300)
} }
//开始倒车入库 //开始倒车入库
status = "parking" status = "parking"
carVehicle.businessStatus = status carBak.businessStatus = status
carBak.carPos = -1
//开始后退 //开始后退
var forword = parkPath!!.result.routes.find { it.gear == 1 } val forback = parkPath!!.result.routes.find { it.gear == 1 }
forword?.polyline?.forEachIndexed { index, doubles -> forback?.polyline?.forEachIndexed { index, doubles ->
carIndex++ carIndex++
carVehicle.vehiclePos = listOf<Double>(doubles[0], doubles[1], doubles[3]) carBak.vehiclePos = listOf<Double>(doubles[0], doubles[1], doubles[3])
sendMsg(channel, JSON.toJSONString(carVehicle)) sendMsg(channel, JSON.toJSONString(carBak))
delay(300) delay(300)
} }
//泊车完成 //泊车完成
status = "park_com" status = "park_com"
carVehicle.businessStatus = status carBak.businessStatus = status
carVehicle.vehiclePos = emptyList() carBak.vehiclePos = emptyList()
//泊车完成消息 //泊车完成消息
sendMsg(channel, JSON.toJSONString(carVehPark)) sendMsg(channel, JSON.toJSONString(carBak))
delay(3000) delay(3000)
//开始推送召车
status = "call" status = "call"
/* //开始推送召车 carBak.businessStatus = status
carVehCall!!.status = status
carVehCall!!.rs?.forEachIndexed { i, doubles -> carVehCall!!.rs?.forEachIndexed { i, doubles ->
carIndex = i carIndex++
carVehCall?.carPos = i carBak.vehiclePos = doubles
sendMsg(channel, JSON.toJSONString(carVehCall)) carBak.carPos = i
sendMsg(channel, JSON.toJSONString(carBak))
delay(300) delay(300)
} }
delay(1000)
//召车完成 //召车完成
status = "call_com" status = "call_com"
carVehCall?.apply { carBak.businessStatus = status
status = this@AvpPushTask.status carBak.vehiclePos = emptyList()
carPos = 0
rs = listOf()
}
//发送召车完成消息 //发送召车完成消息
sendMsg(channel, JSON.toJSONString(carVehCall)) sendMsg(channel, JSON.toJSONString(carBak))
//全部完成 //全部完成
carIndex = 0 carIndex = 0
status = "" status = ""
carVehCall?.apply { carBak.businessStatus = status
this.status = this@AvpPushTask.status carBak.carPos = 0
carPos = 0 carBak.vehiclePos = emptyList()
rs = listOf() sendMsg(channel, JSON.toJSONString(carBak))
} /* carVehCall?.apply {
sendMsg(channel, JSON.toJSONString(carVehCall))*/ this.status = this@AvpPushTask.status
carPos = 0
rs = listOf()
}
sendMsg(channel, JSON.toJSONString(carVehCall))*/
} }
} }
private fun pushPark() {
}
/**感知物**/ /**感知物**/
private fun pushPre(channel: Channel) { private fun pushPre(channel: Channel) {
CoroutineScope(Dispatchers.Default).launch { CoroutineScope(Dispatchers.Default).launch {
...@@ -228,11 +243,14 @@ class AvpPushTask( ...@@ -228,11 +243,14 @@ class AvpPushTask(
CoroutineScope(Dispatchers.Default).launch { CoroutineScope(Dispatchers.Default).launch {
while (isActive) { while (isActive) {
// carPos = 0 // carPos = 0
// println("-------------carIndex = ${carIndex}") val carPos = carBak.carPos
if (carIndex == 0 || status.equals("")) // println("----------carPos ${carPos} status ${status}")
if (carPos == 0 || status.equals("")) {
delay(100)
continue continue
}
if (status.equals("park")) { if (status.equals("park")) {
when (carIndex) { when (carPos) {
8 -> {//紧急制动预警 8 -> {//紧急制动预警
// val v2x = V2xStartBean().apply { // val v2x = V2xStartBean().apply {
// type = 6 // type = 6
...@@ -262,7 +280,7 @@ class AvpPushTask( ...@@ -262,7 +280,7 @@ class AvpPushTask(
} }
} else if (status.equals("call")) { } else if (status.equals("call")) {
when (carIndex) { when (carPos) {
70 -> {//盲区预警 70 -> {//盲区预警
/* val v2x = V2xStartBean().apply { /* val v2x = V2xStartBean().apply {
type = 4 type = 4
......
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